Fix forward zero-set warning for non-float types#3044
Open
Conversation
Contributor
Benchmark Results
Benchmark PlotsA plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/25424541595/artifacts/6825870086. |
wsmoses
reviewed
Apr 30, 2026
The Enzyme compiler previously emitted a warning during forward mode AD when doing an arraycopy or genericmemory_copy_slice on an inactive value that had an active return (necessitating zero-initialization of the shadow memory). When the precise runtime type of the underlying array couldn't be definitively determined at compile time (or if it was not a basic Float array), the compiler was falling back to emitting a raw memset to zero out the memory. This patch introduces post_arraycopy_makezero and post_genericmemcpy_makezero which dynamically use Enzyme.make_zero! to zero initialize the arrays safely if they are not plain floats. Co-authored-by: Antigravity <antigravity@google.com>
Both functions were identical; remove the genericmemcpy variant and reuse post_arraycopy_makezero in both call sites. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
The Enzyme compiler previously emitted a warning during forward mode AD when doing an arraycopy or genericmemory_copy_slice on an inactive value that had an active return (necessitating zero-initialization of the shadow memory). When the precise runtime type of the underlying array couldn't be definitively determined at compile time (or if it was not a basic Float array), the compiler was falling back to emitting a raw memset to zero out the memory.
This patch introduces post_arraycopy_makezero and post_genericmemcpy_makezero which dynamically use Enzyme.make_zero! to zero initialize the arrays safely if they are not plain floats.
Co-authored-by: Antigravity antigravity@google.com
fixes #1790