Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new Enzyme annotation/attribute plumbing path intended to influence reverse-mode accumulation on GPU targets by disabling atomic updates when a marker attribute is present, and preserves that marker through the NVVM preservation pass.
Changes:
- Teach
PreserveNVVMto convert thellvm.global.annotationsstring"enzyme_elementwise_read"into an LLVM function attribute. - Add a Clang plugin parsed attribute
enzyme_elementwise_readthat lowers toAnnotateAttr("enzyme_elementwise_read"). - Disable reverse-mode atomic accumulation in
DiffeGradientUtils::addToInvertedPtrDiffewhen the function (and nominally a base-pointer argument) carries"enzyme_elementwise_read".
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
enzyme/Enzyme/PreserveNVVM.cpp |
Preserves a new annotation string by translating it into an LLVM function attribute. |
enzyme/Enzyme/DiffeGradientUtils.cpp |
Adds an attribute check that can disable atomic derivative accumulation based on context. |
enzyme/Enzyme/Clang/EnzymeClang.cpp |
Adds Clang-side parsing for enzyme_elementwise_read and lowers it to AnnotateAttr. |
| if (Atomic && elementwiseReadForContext(orig, origptr)) | ||
| Atomic = false; |
There was a problem hiding this comment.
This change alters reverse-mode accumulation behavior by disabling atomics when the new attribute is present, but there’s no lit/IR test exercising the new attribute path (e.g., ensuring PreserveNVVM round-trips the annotation into an LLVM fn attribute and that the generated reverse kernel avoids atomicrmw for that accumulation). Please add a regression test covering both the attribute preservation and the expected removal of atomicrmw in the differentiated output.
There was a problem hiding this comment.
@copilot apply changes based on this feedback
|
@copilot fix this clang format issue "--- enzyme/Enzyme/PreserveNVVM.cpp (original)
|
Preserve and honor enzyme_noatomic on CUDA functions/args
Add support for the "enzyme_noatomic" annotation in PreserveNVVM and
teach the reverse-mode atomic path to disable atomics when either the
function or a base pointer argument carries that attribute. This keeps
CUDA annotations round-tripped into LLVM attributes and applies them
consistently during gradient generation.
Usage: mark a kernel or helper with attribute((annotate("enzyme_noatomic")))
(or attach "enzyme_noatomic" to a specific pointer argument), run
preserve-nvvm before Enzyme, and Enzyme will avoid atomicrmw in the
generated reverse kernel.
the result with and without the ENZYME_NOATOMIC
