-
Notifications
You must be signed in to change notification settings - Fork 19
aa wrapper and KLU migration to PNM for PFs #302
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
jd-lara
wants to merge
15
commits into
main
Choose a base branch
from
jd/AA_wrapper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 14 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
0b0f41d
WIP use AA natively
jd-lara 847c169
WIP use AA natively
jd-lara e318278
Merge branch 'jd/AA_wrapper' of https://github.com/NREL-Sienna/PowerN…
jd-lara 09f9cd4
assess copilot's comments and simplifications
jd-lara eb24e85
use AA by default in apple
jd-lara b1651ac
encapsulate better
jd-lara c3d1f9f
enable AA on all matrices
jd-lara 3151464
improve indexing performance
jd-lara cd6dd10
add testing for other matrices
jd-lara 3fe6b15
extend KLU wrapper for Int32
jd-lara b7a11d6
resolve PR comments
jd-lara bba375e
fix docstring creation
jd-lara 164c28d
add a fix for documentation
jd-lara 1dc0889
Review comments fixes
jd-lara f73b6fd
generalize refinement
jd-lara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| """ | ||
| AccelerateWrapper | ||
|
|
||
| A small, allocation-aware wrapper over Apple's `libSparse.dylib` | ||
| (`/System/Library/Frameworks/Accelerate.framework/.../libSparse.dylib`) | ||
| designed for the access patterns of `PowerNetworkMatrices`: | ||
|
|
||
| - Cache the symbolic and numeric factorizations of a symmetric sparse matrix | ||
| (LDLT by default) and reuse them across many solves. | ||
| - Refresh the numeric factor (`numeric_refactor!`) while keeping the symbolic | ||
| analysis, without re-allocating the structural arrays. | ||
| - Solve dense and **sparse** right-hand sides in place, with the sparse path | ||
| packing only non-empty RHS columns into a bounded scratch block. | ||
| - Compute `A·X` and `A·x` directly via libSparse's `SparseMultiply`. | ||
|
|
||
| This module is intentionally lighter than the upstream `AppleAccelerate.jl` | ||
| package: it owns no high-level Julia wrappers over libSparse, exposes the | ||
| symbolic/numeric split directly, binds only the entry points used by PNM, | ||
| and is compile-gated to macOS so non-Apple builds never codegen the | ||
| `@ccall` sites. | ||
| """ | ||
| module AccelerateWrapper | ||
|
|
||
| import SparseArrays | ||
| import SparseArrays: SparseMatrixCSC, getcolptr, rowvals, nonzeros, nzrange | ||
| import LinearAlgebra | ||
|
|
||
| export AAFactorCache, | ||
| aa_factorize, | ||
| symbolic_factor!, | ||
| numeric_refactor!, | ||
| full_factor!, | ||
| full_refactor!, | ||
| solve!, | ||
| solve_sparse!, | ||
| solve_sparse, | ||
| is_factored, | ||
| aa_spmm!, | ||
| aa_spmv! | ||
|
|
||
| @static if Sys.isapple() | ||
| include("libsparse_bindings.jl") | ||
| include("aa_cache.jl") | ||
| include("solve_dense.jl") | ||
| include("solve_sparse_rhs.jl") | ||
| include("spmm.jl") | ||
| else | ||
| # Stub layer. Non-Apple builds never bind libSparse symbols, never codegen | ||
| # the `@ccall` sites, and never instantiate `SparseOpaqueFactorization`. | ||
| # The whole submodule reduces to these short bodies on Linux/Windows. | ||
| struct AAFactorCache end | ||
|
|
||
| _unavailable() = error( | ||
| "AccelerateWrapper is macOS-only (Sys.isapple() returned false). " * | ||
| "Use the KLU backend on non-Apple platforms.", | ||
| ) | ||
|
|
||
| AAFactorCache(args...; kwargs...) = _unavailable() | ||
| aa_factorize(args...; kwargs...) = _unavailable() | ||
| symbolic_factor!(args...) = _unavailable() | ||
| numeric_refactor!(args...) = _unavailable() | ||
| full_factor!(args...) = _unavailable() | ||
| full_refactor!(args...) = _unavailable() | ||
| solve!(args...) = _unavailable() | ||
| solve_sparse!(args...; kwargs...) = _unavailable() | ||
| solve_sparse(args...; kwargs...) = _unavailable() | ||
| is_factored(::AAFactorCache) = false | ||
| aa_spmm!(args...) = _unavailable() | ||
| aa_spmv!(args...) = _unavailable() | ||
| end | ||
|
|
||
| end # module |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit confused why we are wrapping this. KLU's internals weren't very thread-safe, which made it a clearer case until that can be fixed upstream, but I thought AppleAccelerate.jl was a bit better now?