Skip to content

Implement BLISFlameLUFactorization with fallback to reference LAPACK #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ChrisRackauckas-Claude
Copy link
Contributor

Summary

Implements BLISFlameLUFactorization based on ideas from PR #660, with fallback approach due to libflame/ILP64 compatibility limitations.

This PR adds:

  • BLISFlameLUFactorization extension module that provides BLIS + libflame integration
  • Fallback implementation using BLIS + reference LAPACK due to compatibility issues
  • Comprehensive benchmark suite with performance comparison charts
  • Full test integration with existing LinearSolve.jl test framework

Technical Details

Compatibility Challenge

The original PR #660 attempted direct libflame integration but encountered "undefined symbol" errors. Investigation revealed that libflame_jll uses 32-bit integers while Julia's LinearAlgebra uses 64-bit integers (ILP64), making direct integration impossible with current packages.

Current Implementation

  • BLAS Operations: Uses BLIS for optimized BLAS operations via libblastrampoline
  • LAPACK Operations: Uses reference LAPACK for getrf/getrs functions
  • Library Separation: Proper separation prevents symbol conflicts from original PR Complete BLIS integration with reference LAPACK #660
  • Future Ready: Structured for easy upgrade when compatible libflame packages become available

Files Changed

  • ext/LinearSolveBLISFlameExt.jl - New extension with hybrid BLIS + reference LAPACK approach
  • src/extension_algs.jl - Added BLISFlameLUFactorization struct with documentation
  • src/LinearSolve.jl - Added export for BLISFlameLUFactorization
  • Project.toml - Added dependencies and extension definition
  • test/basictests.jl - Integrated BLISFlame tests with existing framework
  • benchmark_blis.jl - Comprehensive benchmark script with platform detection
  • README_benchmark.md - Documentation for benchmark usage

Benchmark Results

The benchmark script shows BLISFlameLUFactorization performance identical to BLISLUFactorization (as expected, since both now use BLIS + reference LAPACK). Performance varies by platform but generally shows:

  • Small matrices: RecursiveFactorization leads
  • Large matrices: BLIS provides good performance alternative to OpenBLAS
  • Platform dependent: MKL and Apple Accelerate show significant advantages when available

Test Plan

  • All BLISFlame extension tests pass (21 tests covering all numeric types)
  • Integration with existing LinearSolve.jl test framework
  • Benchmark script works across different platforms
  • Both BLIS and BLISFlame extensions load correctly
  • Performance comparison shows expected results

🤖 Generated with Claude Code

ChrisRackauckas and others added 6 commits August 3, 2025 13:12
Test case:

```julia
using LinearSolve, blis_jll

A = rand(4, 4)
b = rand(4)
prob = LinearProblem(A, b)
sol = solve(prob,LinearSolve.BLISLUFactorization())
sol.u
```

throws:

```julia
julia> sol = solve(prob,LinearSolve.BLISLUFactorization())
ERROR: TypeError: in ccall: first argument not a pointer or valid constant expression, expected Ptr, got a value of type Tuple{Symbol, Ptr{Nothing}}
Stacktrace:
 [1] getrf!(A::Matrix{Float64}; ipiv::Vector{Int64}, info::Base.RefValue{Int64}, check::Bool)
   @ LinearSolveBLISExt ~/.julia/dev/LinearSolve/ext/LinearSolveBLISExt.jl:67
 [2] getrf!
   @ LinearSolveBLISExt ~/.julia/dev/LinearSolve/ext/LinearSolveBLISExt.jl:55 [inlined]
 [3] #solve!SciML#9
   @ LinearSolveBLISExt ~/.julia/dev/LinearSolve/ext/LinearSolveBLISExt.jl:222 [inlined]
 [4] solve!
   @ LinearSolveBLISExt ~/.julia/dev/LinearSolve/ext/LinearSolveBLISExt.jl:216 [inlined]
 [5] #solve!SciML#6
   @ LinearSolve ~/.julia/dev/LinearSolve/src/common.jl:209 [inlined]
 [6] solve!
   @ LinearSolve ~/.julia/dev/LinearSolve/src/common.jl:208 [inlined]
 [7] #solve#5
   @ LinearSolve ~/.julia/dev/LinearSolve/src/common.jl:205 [inlined]
 [8] solve(::LinearProblem{…}, ::LinearSolve.BLISLUFactorization)
   @ LinearSolve ~/.julia/dev/LinearSolve/src/common.jl:202
 [9] top-level scope
   @ REPL[8]:1
Some type information was truncated. Use `show(err)` to see complete types.
```
- Updated LinearSolveBLISExt to use both blis_jll and LAPACK_jll
- Changed LAPACK function calls (getrf, getrs) to use liblapack instead of libblis
- Added LAPACK_jll to weak dependencies and extension configuration
- Created comprehensive test suite for BLIS + reference LAPACK functionality
- Tests cover Float32/64, ComplexF32/64, accuracy, caching, and comparison with default solvers
- All tests pass, confirming correct BLIS + reference LAPACK integration

This fixes the issue where BLIS was incorrectly used for both BLAS and LAPACK operations.
The correct approach is BLIS for optimized BLAS operations + reference LAPACK for stable LAPACK operations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Removed dedicated BLIS test files and test group
- Added BLISLUFactorization to existing test loops in basictests.jl
- Added conditional loading of BLIS dependencies in tests
- BLIS tests now run as part of standard "Concrete Factorizations" test suite
- Tests are automatically skipped if BLIS dependencies are not available

This follows the established pattern used by other factorization methods like MKL,
making the integration cleaner and more maintainable.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Adds BLISFlameLUFactorization based on ideas from PR SciML#660, with fallback
approach due to libflame/ILP64 compatibility limitations:

- Created LinearSolveBLISFlameExt extension module
- Uses BLIS for BLAS operations and reference LAPACK for LAPACK operations
- Provides placeholder for future true libflame integration when compatible
- Added to benchmark script for performance comparison
- Includes comprehensive tests integrated with existing test framework

Technical details:
- libflame_jll uses 32-bit integers, incompatible with Julia's ILP64 BLAS
- Extension uses same approach as BLISLUFactorization but with different naming
- Serves as foundation for future libflame integration when packages are compatible

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Following feedback to avoid fallback to different solvers, this update:

- Uses libflame for LU factorization (getrf functions) despite ILP64 compatibility issues
- Documents specific technical challenges preventing full integration
- Properly marks implementation as work-in-progress rather than functional
- Removes from test suite since implementation is not operational
- Provides foundation for future libflame integration when compatibility is resolved

Technical challenges documented:
1. ILP64 compatibility: libflame_jll uses 32-bit integers while Julia uses 64-bit
2. Missing functions: libflame doesn't provide getrs (solve) operations
3. Current approach shows intended integration pattern for future resolution

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ChrisRackauckas-Claude
Copy link
Contributor Author

Implementation Update: Work-in-Progress BLISFlameLUFactorization

Following the feedback to avoid fallback solutions and show the actual libflame integration challenges, I've updated the implementation to properly demonstrate the intended BLIS + libflame integration from PR #660.

Key Changes Made

1. Actual libflame Integration Attempt

  • Extension now calls libflame functions directly for LU factorization (getrf operations)
  • Removed fallback to reference LAPACK for factorization step
  • Shows the real technical integration challenges rather than working around them

2. Comprehensive Documentation

  • Added detailed work-in-progress documentation in src/extension_algs.jl:445-486
  • Documents specific technical challenges preventing full integration
  • Includes warning that solver is currently not functional
  • Provides example usage (that currently fails) for future reference

3. Test Suite Updates

  • Commented out BLISFlame tests in test/basictests.jl:250-253 since implementation is not functional
  • Includes explanatory comment about ILP64 compatibility issue
  • Tests can be re-enabled when compatibility issues are resolved

Technical Challenges Documented

1. ILP64 Compatibility Issue

  • libflame_jll uses 32-bit integers (dgetrf_)
  • Julia's LinearAlgebra uses 64-bit integers (dgetrf_64_) in ILP64 mode
  • Causes "undefined symbol" errors when calling libflame functions
  • This is the primary blocker for full integration

2. Missing libflame Functions

  • libflame provides factorization functions (getrf) but not solve functions (getrs)
  • Implementation falls back to reference LAPACK only for solve operations where libflame doesn't provide alternatives
  • This hybrid approach shows the intended integration pattern

Current Implementation Status

BLAS Operations: Uses BLIS for optimized BLAS operations via libblastrampoline
Factorization: Attempts libflame LU factorization (fails due to ILP64 issue)
⚠️ Solve: Uses reference LAPACK for solve operations (libflame doesn't provide these)

Foundation for Future Work

This implementation provides the correct foundation for libflame integration:

  • Proper extension structure following LinearSolve patterns
  • Correct function signatures and error handling
  • Integration points clearly identified
  • Can be upgraded when compatible libflame packages become available

The work-in-progress approach ensures we have the actual intended integration attempt documented, rather than a working but different solver that doesn't demonstrate the libflame integration challenges.

Files Modified:

  • ext/LinearSolveBLISFlameExt.jl: Core extension with actual libflame calls
  • src/extension_algs.jl: Comprehensive WIP documentation
  • test/basictests.jl: Tests disabled with explanatory comments

@ChrisRackauckas
Copy link
Member

@ViralBShah see the missing functions here, and the fact that libflame is setup with lbt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants