Repository navigation
[MLIR] Align cacheValues and reverse-mode adjoint guards for load and store rules - #3247
agourakis82 wants to merge 13 commits into
Conversation
|
Implemented both points as suggested by @pengmai:
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Critical vector-model correctness and compilation issues remain, along with an LLVM cache-guard mismatch.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 6
Open (6)
Vector model omits required AutoDiffTypeInterface methods · New Vector model lacks autodiff support for index elements · New Vector model creates invalid tensor element types for batched vectors · New Vector model isMutable has an incompatible signature · New Vector model calls nonexistent isContainedIn interface method · New Unsupported stores leave orphaned caches · New
What changed in this PR
This PR aligns MLIR reverse-mode cache handling for load/store operations and adds vector autodiff support with regression tests.
Changes:
- Synchronizes mutable-load cache guards across LLVM, memref, and affine.
- Replaces unsafe store interface casts.
- Adds
VectorTypeautodiff behavior and regression coverage.
| File | Summary |
|---|---|
enzyme/test/MLIR/ReverseMode/load_store_cache_guards.mlir |
Adds load/store regression tests; coverage and check scoping need refinement. |
enzyme/Enzyme/MLIR/Implementations/MemRefAutoDiffOpInterfaceImpl.cpp |
Updates memref load/store guards. |
enzyme/Enzyme/MLIR/Implementations/LLVMAutoDiffOpInterfaceImpl.cpp |
Updates LLVM load/store handling; cache guarding remains incomplete. |
enzyme/Enzyme/MLIR/Implementations/BuiltinAutoDiffTypeInterfaceImpl.cpp |
Adds vector autodiff modeling, with unresolved interface and type-validity issues. |
enzyme/Enzyme/MLIR/Implementations/AffineAutoDiffOpInterfaceImpl.cpp |
Updates affine guards and removes an unused builder. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Updated with fixes addressing the review comments:
|
|
Current head |
… store rules Fixes EnzymeAD#3240. - In LLVM, MemRef, and Affine LoadOpInterfaceReverse: mirror the adjoint's !iface.isMutable() requirement into cacheValues, preventing dangling address cache pushes when loading mutable types (e.g. pointers or nested memrefs). - In LLVM, MemRef, and Affine StoreOpInterfaceReverse: use dyn_cast instead of cast for AutoDiffTypeInterface in createReverseModeAdjoint, avoiding assertion failures or popCache on empty caches when the stored type does not implement AutoDiffTypeInterface (such as VectorType). - Remove unused OpBuilder cacheBuilder in AffineStoreOpInterfaceReverse. - Add regression tests in enzyme/test/MLIR/ReverseMode/load_store_cache_guards.mlir.
…ve unsupported types
…odel - Implement missing AutoDiffTypeInterface methods: zeroInPlace, isZero, isZeroAttr - Fix isMutable parameter signature to match interface definition (bool isMutable(Type self)) - Remove call to non-existent isContainedIn interface method - Fix getShadowType to return RankedTensorType for width > 1 (batchType) avoiding invalid nested tensors - Add IntegerType and IndexType support to VectorType createNullAttr - In LLVM StoreOp::cacheValues, guard cache pushes with AutoDiffTypeInterface check matching MemRef/Affine rules - Update test cases in load_store_cache_guards.mlir with modern MLIR syntax and verify reverse vector stores for both MemRef and LLVM dialects
81b656f to
9340019
Compare
|
Quick update: I rebased this branch onto current This head keeps the fixes for the earlier review points: the VectorType model implements the required I still do not have a local |
|
I now have the local MLIR setup working. On The MLIR workflow is awaiting maintainer approval. Could someone approve the pending runs so we can check the Linux CI matrix too? Separately, the Bazel run fails before any jobs start with |
Validate active result and block-argument types before constructing their shadows, propagate failure in forward and reverse differentiation, and discard incomplete cached clones. Cover a Float8 active-store reproducer in both modes. Assisted-by: Codex
Signed-off-by: Demetrios Agourakis <demetrios@agourakis.med.br>
Integrate ad5e418 without rewriting the published reverse-cache-guard history. Preserve the active-vector preflight and diagnostic, inactive-control and raw f32 shadow-accumulation regressions. Rebuild the exact merged source with C++23 tools on the CPU cluster before publication. Keep the private LLVM construction-order SDK overlay separate from the Enzyme changes and do not claim an unmodified-SDK CI pass.
|
I've refreshed the branch against main at ad5e418 and pushed 6fbaeed. I rebuilt and tested the exact published tree on my x86_64 cluster: 213 MLIR tests passed, with 1 expected failure. Both focused regression tests passed. The Float8 and pointer-vector reproducers now emit diagnostics instead of aborting, and removing the f32 shadow accumulation makes the regression check fail as intended. One qualification: this build used the private LLVM SDK construction-order workaround described in the PR, so it doesn't replace validation against the unmodified SDK in upstream CI. The workflows are currently waiting for maintainer approval. Could you approve them when you have a chance? I'd appreciate another look at the vector interface and unsupported-active-type handling once CI has run. |
Match the four diagnostic expressions reported by the upstream format job. Only whitespace changes; conditions, string literals, and tests are unchanged. Validate all 168 files in the workflow's scope using its pinned clang-format 16.0.3 executable. Compare canonical formatting of all four modified files against 6fbaeed before publication.
|
The Julia 1.11 failure also occurs on main: earlier run and latest run both fail at Both main jobs and this PR use Julia 1.11.9 and Enzyme.jl |
|
Update: Enzyme.jl #3819 has now merged as |
Active pointer vectors still diagnose unsupported differentiation. Exercise the zero shadow and its store for the inactive value with duplicated destination. Assisted-by: OpenAI Codex

November 26 refresh and MLIR validation
Integrated upstream
mainat8fc3136ca458fff85e35b261bbdbddd8d6924513(mergeeb4bc456) and rebuilt the exact candidate against the LLVM/MLIR revision pinned by the current Enzyme MLIR workflow,8823cdce1b565e01cb47f89c30f51a0e0ec32d6a(LLVM 24). The SDK source was clean before and after the build. The private SDK overlay used for the October validation was not needed.The first test run on the refreshed merge revealed a regression in the existing
unsupported_active_store.mlirtest: an inactive LLVM pointer-vector value stored into duplicated memory could reach the vector null-value builder, which asserted. The follow-up commitbca98b9amaterializes this null shadow asllvm.mlir.zeroand adds a FileCheck assertion for the zero and its store. The active-pointer-vector diagnostic and inactive controls remain in the test. This preserves the intended distinction between active values requiring a differentiation model and constant values requiring a zero shadow.Current validation
On x86-64 Linux, Ubuntu Clang 18.1.3, CMake 3.28.3, Release, assertions enabled in the LLVM/MLIR SDK:
mlir-opt,FileCheck,mlir-translate,enzymemlir-opt,enzymemlir-translate, andenzymemlir-type-tree-test.load_store_cache_guards.mlirandunsupported_active_store.mlir(89 excluded by the filter).cmake --build /work/enzyme-build --parallel 6 --target check-enzymemlir: 244 passed, 1 expected failure, 1 unsupported, 0 unexpected failures, 246 discovered.git diff --checkpassed, and the deployed candidate and two follow-up files were verified by SHA-256. The original unmodified-SDK failure and final passing logs were retained locally.The local build enables MLIR and disables Clang integration, the bitcode loader, and Flang integration. A task-local linker search path supplied the system zlib runtime because the container lacked the development symlink. This is a native MLIR validation against the unmodified pinned SDK, not a substitute for the full upstream CI matrix. Hosted Actions and maintainer review remain pending.
OpenAI Codex assisted with the integration, build diagnosis, follow-up fix, tests, and description update. The previous October validation below is retained as historical context.
Fixes #3240.
Align the forward cache guards with the reverse load/store rules for LLVM, memref, and affine operations. Loads of mutable types no longer leave unused caches behind.
Register vector differentiation for supported numeric element types. Reject unsupported active vector elements before shadow creation, report a diagnostic, and propagate differentiation failure instead of asserting or silently omitting a derivative. Constant values remain exempt from this active-type check.
The regression tests cover cache guards, raw f32 shadow accumulation, unsupported Float8 and pointer vectors, and inactive controls.
Validation
The refreshed branch includes upstream
ad5e418d157eb03094829230c80ddc06fb9198a3. Commit6fbaeed9was rebuilt and validated on the x86_64 cluster on October 10. The subsequent formatting-only update preserves its C++ token sequence:Validation used LLVM/MLIR
62e30e3326d9b4e3948d242ccfee7aa4fc030ef3with a private SDK overlay moving theOneShotAnalysisStateconstructor after its nested cache definitions. These results are not an unmodified-SDK CI pass. Upstream CI and maintainer review remain pending.