Add dense BLAS matmul atoms for dense constant matrices#48
Open
Transurgeon wants to merge 3 commits intomainfrom
Open
Add dense BLAS matmul atoms for dense constant matrices#48Transurgeon wants to merge 3 commits intomainfrom
Transurgeon wants to merge 3 commits intomainfrom
Conversation
Add new dense_left_matmul and dense_right_matmul atoms that use CBLAS (dgemv/dgemm) instead of sparse operations when the constant matrix A is dense. This avoids sparse overhead (CSR construction, per-row overlap checks in sparsity detection, sparse dot products in Jacobian evaluation) and leverages hardware-optimized BLAS routines. Key optimizations: - Forward pass: cblas_dgemv per Kronecker block - Jacobian sparsity: simplified dense block detection (if any child entry exists in a block, all m rows are nonzero) - Jacobian values: single-entry columns use fast cblas_dcopy+dscal path; multi-entry columns batched into cblas_dgemm (batch size 256) - Affine children: Jacobian computed once in init and cached - Hessian: cblas_dgemv with AT for A^T @ w dense_right_matmul is implemented as (A^T @ f(x)^T)^T via transpose + dense_left_matmul. Links BLAS via Accelerate framework on macOS, find_package(BLAS) elsewhere. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add libopenblas-dev to cmake, valgrind, and sanitizer CI workflows - Exclude dense_left_matmul.c and dense_right_matmul.c from MSVC builds (no BLAS available on Windows CI) - Guard dense matmul tests with #ifndef _MSC_VER Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add new dense_left_matmul and dense_right_matmul atoms that use CBLAS (dgemv/dgemm) instead of sparse operations when the constant matrix A is dense. This avoids sparse overhead (CSR construction, per-row overlap checks in sparsity detection, sparse dot products in Jacobian evaluation) and leverages hardware-optimized BLAS routines.
Key optimizations:
dense_right_matmul is implemented as (A^T @ f(x)^T)^T via transpose + dense_left_matmul.
Links BLAS via Accelerate framework on macOS, find_package(BLAS) elsewhere.
Issue link: #45