Differentiate HLFIR, currently matmul - #2990
Draft
vchuravy wants to merge 3 commits into
Draft
Conversation
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
July 23, 2026 13:21
598f5cc to
c202c33
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
2 times, most recently
from
July 23, 2026 15:41
07ed5fc to
5027fab
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
3 times, most recently
from
July 23, 2026 16:17
9307049 to
c50dbb9
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
July 26, 2026 21:16
c50dbb9 to
1d96a01
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
2 times, most recently
from
July 27, 2026 06:22
5722186 to
2141864
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
July 27, 2026 06:50
2141864 to
96245b6
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
July 27, 2026 08:19
96245b6 to
1e77c13
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
July 27, 2026 09:18
1e77c13 to
ffff38c
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
July 27, 2026 12:21
ffff38c to
13457fd
Compare
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
August 3, 2026 13:38
13457fd to
d124c63
Compare
Differentiates the Fortran MATMUL intrinsic while it is still a first-class
hlfir.matmul op, on top of the !fir.ref by-reference autodiff layer:
* HLFIRAutoDiffOpInterfaceImpl.cpp -- !hlfir.expr AutoDiffTypeInterface
(elementwise shadow/add/zero via hlfir.elemental) and the hlfir.matmul
rules: forward tangent d(A·B) = dA·B + A·dB, and reverse adjoints
Ā += Ḡ·Bᵀ, B̄ += Aᵀ·Ḡ (via hlfir.matmul_transpose / hlfir.transpose).
Added to the flang-dependent MLIREnzymeHLFIRImplementations library and
registered by registerHLFIRDialectAutoDiffInterface.
* fir-enzyme-opt and the FlangEnzymeMLIR plugin now also attach the HLFIR
array-intrinsic models.
* Tests: matmul_fwd.mlir, matmul_rev.mlir (the op rules), and fortran_matmul.f90
(end-to-end: Flang lowers MATMUL to hlfir.matmul, fir-enzyme-opt differentiates).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BkvJByk8nTti2GiF4RudNG
…ayer This entry point is implemented and used by this layer (HLFIRAutoDiffOpInterfaceImpl.cpp, fir-enzyme-opt, HLFIRFlangPluginRegistration), so declare it here rather than in the base plugin header. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fold registerHLFIRDialectAutoDiffInterface into the shared Fortran registration next to the FIR one, instead of calling both from the flang plugin. The fir-opt plugin (enzyme-fir-plugin.cpp) only ever calls registerEnzymeFortranInterfaces, so registering there is what gives it the hlfir.matmul rules and !hlfir.expr's AutoDiffTypeInterface; both vehicles now register the same set, as that entry point promises. Point the three matmul tests at the FIREnzyme plugin (%firenzyme, firenzyme_plugin) the way the rest of test/MLIR/FIR now does -- they required the nonexistent fir_enzyme_opt feature and so never ran. All twelve FIR tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
vchuravy
force-pushed
the
flang-hlfir-matmul
branch
from
August 4, 2026 12:41
d124c63 to
c52e4fe
Compare
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.
Differentiates the Fortran MATMUL intrinsic while it is still a first-class
hlfir.matmul op, on top of the !fir.ref by-reference autodiff layer:
(elementwise shadow/add/zero via hlfir.elemental) and the hlfir.matmul
rules: forward tangent d(A·B) = dA·B + A·dB, and reverse adjoints
Ā += Ḡ·Bᵀ, B̄ += Aᵀ·Ḡ (via hlfir.matmul_transpose / hlfir.transpose).
Added to the flang-dependent MLIREnzymeHLFIRImplementations library and
registered by registerHLFIRDialectAutoDiffInterface.
array-intrinsic models.
(end-to-end: Flang lowers MATMUL to hlfir.matmul, fir-enzyme-opt differentiates).
Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
Stack created with GitHub Stacks CLI • Give Feedback 💬