Avoid atomics for CUDA elementwise shadow updates#2
Closed
minansys wants to merge 1 commit into
Closed
Conversation
Owner
Author
|
Superseded by #3, which implements the repeated CUDA global-load root fix instead of the earlier elementwise atomic approach. |
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.
Summary
This centralizes Enzyme's reverse-mode shadow accumulation atomic decision in
DiffeGradientUtils::shouldUseAtomicShadowUpdateand makes the CUDA elementwise-read optimization explicit.For
enzyme_elementwise_readfunctions, each CUDA work item is expected to accumulate into a distinct shadow location, so Enzyme can emit a normal load/add/store instead of a generatedatomicrmw fadd. Conservative cases still keep atomics, including unannotated CUDA paths, shared-memory reductions, and unknown aliasing cases.Changes
cuda-elementwise-atomic.llto check both sides of the behavior:atomicrmwatomicrmw faddValidation
/home/minxu/code/enzyme/.tools/bin/clang-format-16.cmake --build build/enzyme-llvmorg-19.1.7 -- -j 8python3 deps/llvm-project/llvm/utils/lit/lit.py -sv build/enzyme-llvmorg-19.1.7/test --filter 'Enzyme/ReverseMode/cuda-elementwise-atomic\\.ll$'elementwise-read.ll: noatomicrmwcuda.ll:atomicrmw faddpresentsharedmem.ll:atomicrmw faddpresentatomicfadd.ll:atomicrmw volatile faddpresentsm_86:scripts/build_enzyme_cuda.sh --skip-checkout --skip-build --skip-enzyme-testsn=4194304 reps=50 atomic_ms=0.592671 elementwise_ms=0.572068 speedup=1.036xn=4194304 reps=50 atomic_ms=0.590989 elementwise_ms=0.546058 speedup=1.082xNotes
check-enzymetarget is misconfigured in this workspace and invokes/llvm-lit, which does not exist.FileCheckinto the LLVM install prefix, a broad.lllit attempt with--max-failures=20still failed on existing LLVM 19 opaque-pointer FileCheck spelling mismatches and a missingnothelper in the local lit environment. The new regression passed independently.