Fix allocation tests on Julia >= 1.13 - #536
Merged
Merged
Conversation
OpenLibm is a `Libdl.LazyLibrary` on Julia >= 1.13. Its `ccall` targets are resolved on first use and cached per callsite, and resolving one allocates 16 bytes. Each test measured a single call of a newly created closure, into which the `ccall` is inlined by constant propagation. So every measurement included the 16 bytes of resolving a fresh callsite. Affected are the paths that call `gamma` (`1 <= a <= 20`) or `erfc` (`a == 0.5`). Now each closure is called twice and only the second measurement is used. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #536 +/- ##
=======================================
Coverage 94.28% 94.28%
=======================================
Files 14 14
Lines 3026 3026
=======================================
Hits 2853 2853
Misses 173 173
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
GPU compatibilitytests intest/gamma_inc.jlfail on Julia 1.13 (12 failures, 4 code paths x 3 float types), e.g.OpenLibm is a
Libdl.LazyLibraryon Julia >= 1.13, so accallinto it can no longer be bound at compile time. Its target is resolved on first use and cached per callsite, and resolving one allocates 16 bytes.Each test measured a single call of a newly created closure, and since the arguments are literals constant propagation inlines the
ccallinto that closure -code_typed(FT -> gamma_inc(FT(1.7), FT(2.5)))containsSo every measurement included the 16 bytes of resolving a fresh callsite. Only the paths that reach a
ccallare affected:gamma(a)inrgammaxfor1 <= a <= 20, anderfcfora == 0.5. The other paths take thestirling_error(a > 20) orrgamma1pm1(a < 1) branches and are pure Julia, which is why they pass.Warming up with a separate call does not help, because the lazy binding is cached per callsite and not per callee. So this now calls each closure twice and only asserts on the second measurement.
test/gamma_inc.jlpasses on 1.10.11, 1.12.6 and 1.14.0-DEV (1.13.0-rc1 was unavailable locally, nightly reproduces the failure identically). A negative controlrun_twice(FT -> @allocated(sum(zeros(FT, 100))), FT)still reports 912/928, 480/512 and 256/272 bytes, so the tests still detect real allocations.Note this is unrelated to #535 - the same failures are on the master push run 27935023667 and on #534.
🤖 Generated with Claude Code