Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.

refactor: compile-time BLAS ILP64/LP64 selection and external pointer mode#469

Merged
shinaoka merged 11 commits intomainfrom
468-use-cblas-interface
Oct 29, 2025
Merged

refactor: compile-time BLAS ILP64/LP64 selection and external pointer mode#469
shinaoka merged 11 commits intomainfrom
468-use-cblas-interface

Conversation

@shinaoka
Copy link
Member

@shinaoka shinaoka commented Oct 29, 2025

This PR refactors BLAS integration to use compile-time ILP64/LP64 selection and properly handle external function pointer mode.

Changes

  • Made BLAS mandatory: BLAS is now always enabled (removed SPARSEIR_USE_BLAS option)
  • Removed unused LAPACKE option: Removed SPARSEIR_USE_LAPACKE option as it was not being used
  • Unified ILP64 option naming: Renamed SPARSEIR_USE_ILP64 to SPARSEIR_USE_BLAS_ILP64 for clarity
  • Compile-time ILP64/LP64 selection: Uses #ifdef SPARSEIR_USE_BLAS_ILP64 for interface type selection (replacing dynamic symbol resolution)
  • External function pointer mode: When SPARSEIR_USE_EXTERN_FBLAS_PTR is enabled, skips find_package(BLAS) and BLAS linking
  • Combined registration functions: Introduced spir_register_dgemm_zgemm_lp64 and spir_register_dgemm_zgemm_ilp64 to register both dgemm and zgemm together
  • Conditional C-API declarations: Registration functions in sparseir.h are conditionally declared based on build configuration
  • Updated Python bindings: Modified core.py to use the new combined registration function
  • Test automation: Added run_tests.sh script in python/ directory for automated testing with cleanup
  • Workflow cleanup: Removed obsolete SPARSEIR_USE_BLAS references from GitHub workflows and pyproject.toml
  • Removed linker workaround: Removed --no-as-needed linker option (no longer needed with compile-time approach)

Technical Details

  • Two BLAS modes:

    1. Link-time BLAS (default): BLAS library is linked at build time. Uses compile-time #ifdef to select ILP64 (64-bit) or LP64 (32-bit) integer types based on SPARSEIR_USE_BLAS_ILP64.
    2. Runtime BLAS registration: Enabled with SPARSEIR_USE_EXTERN_FBLAS_PTR. No BLAS linking, function pointers registered at runtime via C-API.
  • Implementation split:

    • gemm_link.impl: Direct BLAS linking implementation
    • gemm_external.impl: External function pointer implementation
    • Both files are conditionally included based on SPARSEIR_USE_EXTERN_FBLAS_PTR
  • CMake changes:

    • SPARSEIR_USE_EXTERN_FBLAS_PTR=ON: Skips find_package(BLAS) and BLAS linking
    • SPARSEIR_USE_BLAS_ILP64=ON: Sets BLA_SIZEOF_INTEGER=8 and adds compile definition for ILP64 interface

Testing

All existing tests pass with the new implementation.

@shinaoka shinaoka linked an issue Oct 29, 2025 that may be closed by this pull request
- Make BLAS mandatory: Remove SPARSEIR_USE_BLAS option
- Remove unused LAPACKE option: Remove SPARSEIR_USE_LAPACKE option
- Implement dynamic Fortran BLAS symbol resolution at runtime
- Add ILP64/LP64 support with automatic detection (prioritize ILP64)
- Add combined registration functions: spir_register_dgemm_zgemm_lp64/ilp64
- Update Python bindings to use new combined registration
- Remove unused FindLAPACKE.cmake and morse_LICENCE.txt
- Add run_tests.sh script for automated Python testing
- Add test-cxx-backend-ilp64 job to test ILP64 BLAS interface
- Install libopenblas64-0 and libopenblas64-dev on Ubuntu
- Build with -DSPARSEIR_USE_BLAS_ILP64=ON flag
- Update rollup job to include ILP64 test results
- Change BLAS linking back to PRIVATE (proper encapsulation)
- Add LINKER:--no-as-needed flag to prevent linker from dropping BLAS dependency
- This ensures BLAS symbols are available for dlopen/dlsym at runtime
- Avoids unnecessary dependency propagation to consumers
- Fixes "zgemm symbol not found" errors while maintaining clean design
…_PTR

- Wrap spir_register_dgemm_zgemm_* declarations in sparseir.h with #ifdef
- Add clarifying comments about no BLAS symbols in external mode
- Ensures registration functions are only available when needed
- Fix duplicate #else/#endif blocks in gemm.hpp
- Wrap all integer type declarations with #ifdef SPARSEIR_USE_ILP64 blocks
- Move #include statements inside namespace sparseir {} in gemm.cpp
- Remove duplicate alpha/beta declaration lines
- Ensures my_dgemm/my_zgemm functions are properly defined in namespace
- Remove #ifdef SPARSEIR_USE_BLAS from gemm.cpp
- BLAS support is mandatory, so no conditional compilation needed
- Fixes undefined symbol errors for my_dgemm/my_zgemm
- Rename SPARSEIR_USE_ILP64 to SPARSEIR_USE_BLAS_ILP64 for clarity
- Skip BLAS detection when SPARSEIR_USE_EXTERN_FBLAS_PTR is enabled
- Update sparseir.h to conditionally declare registration functions
- Remove obsolete SPARSEIR_USE_BLAS references from workflows and pyproject.toml
- Remove --no-as-needed linker option (no longer needed)
- Update README to reflect compile-time ILP64/LP64 selection
@shinaoka shinaoka changed the title feat: dynamic Fortran BLAS symbol resolution and ILP64/LP64 support refactor: compile-time BLAS ILP64/LP64 selection and external pointer mode Oct 29, 2025
- Add BLA_SIZEOF_INTEGER setting in capi_test/CMakeLists.txt based on SPARSEIR_USE_BLAS_ILP64 env var
- Update test_with_cxx_backend.sh and run_sample.sh to support ILP64 via environment variable
- Set SPARSEIR_USE_BLAS_ILP64=1 in ILP64 test workflow steps
- Add parallel execution (-j) and timeout for ILP64 tests
- Remove macOS Accelerate framework linking from capi_test (no longer needed)
- Set default build type to Release in CMakeLists.txt if not specified
- Remove obsolete SPARSEIR_USE_BLAS option from build_capi_with_tests.sh
- This ensures Release mode is used by default instead of Debug
@shinaoka shinaoka merged commit de05df6 into main Oct 29, 2025
15 checks passed
@shinaoka shinaoka deleted the 468-use-cblas-interface branch October 29, 2025 12:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use CBLAS interface

1 participant