Skip to content

Add dense BLAS matmul atoms for dense constant matrices#48

Open
Transurgeon wants to merge 3 commits intomainfrom
dense-blas-matmul
Open

Add dense BLAS matmul atoms for dense constant matrices#48
Transurgeon wants to merge 3 commits intomainfrom
dense-blas-matmul

Conversation

@Transurgeon
Copy link
Collaborator

@Transurgeon Transurgeon commented Mar 7, 2026

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.

Issue link: #45

Transurgeon and others added 3 commits March 6, 2026 23:50
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>
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.

1 participant