Skip to content
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

libSparse direct solving methods and matrix arithmetic #79

Closed

Conversation

luke-kiernan
Copy link
Collaborator

@luke-kiernan luke-kiernan commented Jan 22, 2025

libSparse/wrappers.jl contains wrappers for the classes in libSparse, calling the Objective-C functions with @ccall as if they're C. This has its challenges--e.g. Julia doesn't recognize Objective-C's os_log_error--but so far, I've been able to work around them. I matched up the mangled and de-mangled functions via a dyld extractor and llvm-cxxfilt, as suggested on Discourse.

The AASparseMatrix{T} struct is a wrapper for Apple's SparseMatrix_{Float/Double}. I've implemented the supported matrix arithmetic operations the AASparseMatrix class: * for Apple's SparseMultiply and muladd! for Apple's SparseMultiplyAdd.

Likewise, AAFactorization{T} is a wrapper for Apple's SparseOpaqueFactorization_{Float/Double}. Unlike Julia, you need to explicitly construct the factorization object, and provide it the first argument to solve (or ldiv!). You can do things like

using SparseArrays, AppleAccelerate
N = 10
jlM = sprand(N, N, .4)
aaM = AASparseMatrix(jlM)
f = AAFactorization(aaM) 
b = rand(N)
@assert f \ b ≈ jlM \ b # this will error if jlM is singular.

Places where this could use some work:

  1. My way of attaching a Julia function to each C function is very copy-paste heavy. Writing a macro is probably a better way to go, but a bit beyond my skills at this point.
  2. I'm hard-coding in the mangled names. Those very well could change at some point in the future: add guardrails so that it's an informative error if things do break. Or better yet, automate the de-mangling.
  3. Bring the interface of AAFactorization more in line with Julia's LinearAlgebra.
  4. Expand functionality, beyond direct methods and Cholesky/QR factorizations.

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 0% with 147 lines in your changes missing coverage. Please review.

Project coverage is 0.51%. Comparing base (9874fe4) to head (1e4b9f8).

Files with missing lines Patch % Lines
src/libSparse/wrappers.jl 0.00% 61 Missing ⚠️
src/libSparse/AASparseMatrices.jl 0.00% 50 Missing ⚠️
src/libSparse/AAFactorizations.jl 0.00% 36 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##           master     #79      +/-   ##
=========================================
- Coverage    0.84%   0.51%   -0.33%     
=========================================
  Files           4       7       +3     
  Lines         238     385     +147     
=========================================
  Hits            2       2              
- Misses        236     383     +147     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ViralBShah
Copy link
Contributor

Nice work. Happy to give you commit access. Please let me know.

@luke-kiernan
Copy link
Collaborator Author

Sure! Should I make this a feature branch, or close merge it into main? I see I can now the close PR. I'm relatively new to Julia and to GitHub collaboration, so I'm not sure what level of fit and finish is "good enough."

@ViralBShah
Copy link
Contributor

ViralBShah commented Jan 23, 2025

The important thing is to have tests and make sure CI passes. You can then merge to master and eventually tag a release.

Invited you for write access: https://github.com/JuliaLinearAlgebra/AppleAccelerate.jl/invitations

@luke-kiernan
Copy link
Collaborator Author

I've accepted the invite and added libSparse as a new branch.

@luke-kiernan luke-kiernan deleted the libSparse branch January 23, 2025 20:45
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