-
Notifications
You must be signed in to change notification settings - Fork 1
Left matmul 100x performance improvements #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
de23e18
test for profiling
dance858 486c03c
90 times faster sparsity pattern
dance858 f54382c
fill values without forming A kron
dance858 37fc13a
update forward pass
dance858 3bd25ce
fix test
dance858 40f85e0
ran formatter
dance858 7a1bd4e
profile forward pass
dance858 f3bd95f
ran formatter
dance858 d668708
removed kroenecker product from hessian
dance858 8259371
minor changes
dance858 6b2ae18
broadcast fix
dance858 fa947bc
ran formatter
dance858 0542a4d
improved documentation of block_left_mult
dance858 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 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 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,46 @@ | ||
| #ifndef LINALG_H | ||
| #define LINALG_H | ||
|
|
||
| /* Forward declarations */ | ||
| struct CSR_Matrix; | ||
| struct CSC_Matrix; | ||
|
|
||
| /* Compute sparsity pattern and values for the matrix-matrix multiplication | ||
| C = (I_p kron A) @ J where A is m x n, J is (n*p) x k, and C is (m*p) x k, | ||
| without relying on generic sparse matrix-matrix multiplication. Specialized | ||
| logic for this is much faster (50-100x) than generic sparse matmul. | ||
|
|
||
| * J is provided in CSC format and is split into p blocks of n rows each | ||
| * C is returned in CSC format | ||
| * Mathematically it corresponds to C = [A @ J1; A @ J2; ...; A @ Jp], | ||
| where J = [J1; J2; ...; Jp] | ||
| */ | ||
| struct CSC_Matrix *block_left_multiply_fill_sparsity(const struct CSR_Matrix *A, | ||
| const struct CSC_Matrix *J, | ||
| int p); | ||
|
|
||
| void block_left_multiply_fill_values(const struct CSR_Matrix *A, | ||
| const struct CSC_Matrix *J, | ||
| struct CSC_Matrix *C); | ||
|
|
||
| /* Compute y = kron(I_p, A) @ x where A is m x n and x is(n*p)-length vector. | ||
| The output y is m*p-length vector corresponding to | ||
| y = [A @ x1; A @ x2; ...; A @ xp] where x is divided into p blocks of n | ||
| elements. | ||
| */ | ||
| void block_left_multiply_vec(const struct CSR_Matrix *A, const double *x, double *y, | ||
| int p); | ||
|
|
||
| /* Fill values of C = A @ B where A is CSR, B is CSC. | ||
| * C must have sparsity pattern already computed. | ||
| */ | ||
| void csr_csc_matmul_fill_values(const struct CSR_Matrix *A, | ||
| const struct CSC_Matrix *B, struct CSR_Matrix *C); | ||
|
|
||
| /* C = A @ B where A is CSR, B is CSC. Result C is CSR. | ||
| * Allocates and precomputes sparsity pattern. No workspace required. | ||
| */ | ||
| struct CSR_Matrix *csr_csc_matmul_alloc(const struct CSR_Matrix *A, | ||
| const struct CSC_Matrix *B); | ||
|
|
||
| #endif /* LINALG_H */ |
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 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
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.
Uh oh!
There was an error while loading. Please reload this page.