Skip to content

Add linalg support via GPUArrays extension#3148

Open
rsenne wants to merge 3 commits into
EnzymeAD:mainfrom
rsenne:gpuarrays-linalg-rules
Open

Add linalg support via GPUArrays extension#3148
rsenne wants to merge 3 commits into
EnzymeAD:mainfrom
rsenne:gpuarrays-linalg-rules

Conversation

@rsenne

@rsenne rsenne commented Jun 6, 2026

Copy link
Copy Markdown

Resolves #3122.

Adds custom rules for matmul/dot/sum on GPU arrays.

This came up while building GPU MCMC in ParallelMCMC.jl#32, where @wsmoses suggested overloading matmul for GPU arrays directly in Enzyme as an extension rather than keeping per-package wrappers.

@wsmoses

wsmoses commented Jun 7, 2026

Copy link
Copy Markdown
Member

@kshyatt can you help review?

Comment thread ext/EnzymeGPUArraysCoreExt.jl
Comment thread ext/EnzymeGPUArraysCoreExt.jl Outdated
func::Const{typeof(mul!)},
RT::Type{<:Annotation},
C::Annotation{<:AbstractGPUArray},
A::Annotation,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if A and B are actually CPU arrays?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now restricted it to gpu array types

@rsenne rsenne requested a review from kshyatt June 8, 2026 00:19
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.95745% with 111 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.80%. Comparing base (179b608) to head (a173344).
⚠️ Report is 207 commits behind head on main.

Files with missing lines Patch % Lines
ext/EnzymeGPUArraysCoreExt.jl 40.95% 111 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3148      +/-   ##
==========================================
+ Coverage   66.76%   73.80%   +7.04%     
==========================================
  Files          65       66       +1     
  Lines       21522    22611    +1089     
==========================================
+ Hits        14369    16689    +2320     
+ Misses       7153     5922    -1231     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rsenne

rsenne commented Jun 17, 2026

Copy link
Copy Markdown
Author

anything else I can do on this?

@wsmoses

wsmoses commented Jun 25, 2026

Copy link
Copy Markdown
Member

bump @kshyatt

rsenne added 3 commits June 25, 2026 11:50
Extend the GPUArrays matmul rules to cover UpperTriangular, LowerTriangular,
Symmetric, and Hermitian operands. The primal already dispatches to the
specialized BLAS kernel (trmm/symm/hemm); the reverse pass now projects the
dense cotangent onto each wrapper's stored entries via _accumulate_operand!.
UnitTriangular is excluded since its fixed diagonal cannot carry a tangent.

Verified against finite differences on JLArrays and CUDA.
@kshyatt kshyatt force-pushed the gpuarrays-linalg-rules branch from bacc98b to a173344 Compare June 25, 2026 15:50
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.

GPU matmul rules in Enzyme CUDA extension

3 participants