Skip to content

Fix forward zero-set warning for non-float types#3044

Open
vchuravy wants to merge 3 commits intomainfrom
vc/fix_todo
Open

Fix forward zero-set warning for non-float types#3044
vchuravy wants to merge 3 commits intomainfrom
vc/fix_todo

Conversation

@vchuravy
Copy link
Copy Markdown
Member

@vchuravy vchuravy commented Apr 23, 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

fixes #1790

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 23, 2026

Benchmark Results

main ce9a41d... main / ce9a41d...
basics/make_zero/namedtuple 0.0561 ± 0.0075 μs 0.0567 ± 0.0067 μs 0.991 ± 0.18
basics/make_zero/struct 0.245 ± 0.0097 μs 0.256 ± 0.0072 μs 0.958 ± 0.047
basics/overhead 4.32 ± 0.001 ns 3.17 ± 0.018 ns 1.36 ± 0.0077
basics/remake_zero!/namedtuple 0.229 ± 0.014 μs 0.222 ± 0.0091 μs 1.03 ± 0.074
basics/remake_zero!/struct 0.223 ± 0.012 μs 0.225 ± 0.013 μs 0.993 ± 0.079
fold_broadcast/multidim_sum_bcast/1D 10.8 ± 1.3 μs 10.9 ± 1.2 μs 0.994 ± 0.17
fold_broadcast/multidim_sum_bcast/2D 12.1 ± 0.34 μs 12.1 ± 0.36 μs 0.999 ± 0.041
time_to_load 1.05 ± 0.011 s 1.06 ± 0.018 s 0.992 ± 0.02

Benchmark Plots

A plot of the benchmark results has been uploaded as an artifact at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/25424541595/artifacts/6825870086.

@vchuravy vchuravy requested a review from wsmoses April 23, 2026 20:01
@vchuravy vchuravy closed this Apr 28, 2026
@vchuravy vchuravy reopened this Apr 28, 2026
Comment thread src/rules/llvmrules.jl Outdated
vchuravy and others added 2 commits May 5, 2026 10:27
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix "TODO forward zero-set of arraycopy used memset rather than runtime type "

2 participants