Skip to content

Mark functions with an easy rule as enzyme_easy_rule - #3731

Merged
wsmoses merged 1 commit into
mainfrom
wm/easy-rule-attr
Oct 1, 2026
Merged

wsmoses merged 1 commit into
mainfrom
wm/easy-rule-attr

Conversation

@wsmoses

@wsmoses wsmoses commented Oct 1, 2026

Copy link
Copy Markdown
Member

Companion to EnzymeAD/Enzyme#3352, which stops DetectReadonlyOrThrow from inferring writeonly or readnone on the pointer parameters of a function whose derivative comes from a custom rule (enzyme_math=enzyme_custom): the rule may read a parameter the body never reads.

A rule written with @easy_rule only combines the inputs the way the body does, so those functions can keep that inference. This adds an enzyme_easy_rule function attribute at the two places that already add enzyme_LocalReadOnlyOrThrow for cached_has_easy_rule, and the core change exempts functions carrying it (tested there in readonlyorthrow_custom_rule.ll).

Checked with the core branch built for Julia 1.11: rules/internal_rules/bigfloat, rules/easyrules and rules/rrules pass (116 tests). Harmless with a libEnzyme that predates #3352, which ignores the attribute.

🤖 Generated with Claude Code

https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb

@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.10%. Comparing base (28512d8) to head (f5a4ee7).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #3731       +/-   ##
===========================================
+ Coverage   46.45%   80.10%   +33.65%     
===========================================
  Files          58       71       +13     
  Lines       22740    24172     +1432     
===========================================
+ Hits        10563    19363     +8800     
+ Misses      12177     4809     -7368     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

EnzymeAD/Enzyme#3352 stops Enzyme's DetectReadonlyOrThrow from inferring
writeonly or readnone on the pointer parameters of a function whose
derivative comes from a custom rule, since the rule may read a parameter
the body never reads, unless the function is marked
enzyme_custom_full_attributes to state that its rule accesses no more
than the body does. A rule written with @easy_rule only combines the
inputs the way the body does, so set that attribute next to the
enzyme_LocalReadOnlyOrThrow such functions already get.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01G84mmXoaait2MBqCH5BKNb
@wsmoses
wsmoses force-pushed the wm/easy-rule-attr branch from e683953 to f5a4ee7 Compare October 1, 2026 02:42
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Benchmark Results

main f5a4ee7... main / f5a4ee7...
basics/make_zero/namedtuple 0.0523 ± 0.0021 μs 0.0527 ± 0.002 μs 0.992 ± 0.055
basics/make_zero/struct 0.277 ± 0.0063 μs 0.277 ± 0.0061 μs 0.997 ± 0.032
basics/overhead 4.94 ± 0.92 ns 4.03 ± 0.01 ns 1.23 ± 0.23
basics/remake_zero!/namedtuple 0.223 ± 0.006 μs 0.223 ± 0.0057 μs 0.998 ± 0.037
basics/remake_zero!/struct 0.232 ± 0.011 μs 0.232 ± 0.0096 μs 1 ± 0.061
fold_broadcast/multidim_sum_bcast/1D 0.5 ± 0.0061 μs 0.504 ± 0.006 μs 0.992 ± 0.017
fold_broadcast/multidim_sum_bcast/2D 0.383 ± 0.0062 μs 0.375 ± 0.0042 μs 1.02 ± 0.02
inline_abi/call 16.4 ± 0.049 ns 16.7 ± 0.05 ns 0.981 ± 0.0042
inline_abi/call_alloc 0.0482 ± 0.0012 μs 0.0449 ± 0.0011 μs 1.07 ± 0.037
inline_abi/loop 4.01 ± 0.0043 μs 4.01 ± 0.0043 μs 1 ± 0.0015
time_to_load 1.52 ± 0.0093 s 1.53 ± 0.0087 s 0.995 ± 0.0083

Benchmark Plots

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

@wsmoses
wsmoses merged commit 84799ae into main Oct 1, 2026
101 of 108 checks passed
@wsmoses
wsmoses deleted the wm/easy-rule-attr branch October 1, 2026 02:52
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.

1 participant