Repository navigation
perf(core): rebuild range-grid cell edges from a 32-bit integer on Float32 grids - #226
Merged
Merged
Conversation
…oat32 grids The range search rebuilds the cell's left edge `lo + (idx - 1)*h` from an Int64 index; on Metal the Int64 -> float conversion is emulated, which held a Float32 range lookup at 74 % of copy bandwidth. On Float32/Float16 grids the offset is now converted from `(idx - 1) % _idx_type(T)` (Int32), so Metal reaches ~100 % for every extrapolation. The index, clamps, loads and returned Int are unchanged and results are bit-identical; Float64 IR and Float32 native opcodes match master on the CPU. Float32/Float16 range grids are limited to typemax(Int32) ÷ 2 points so the narrowing is always exact (Int grids skip the check at compile time).
Contributor
FastInterpolations.jl Benchmarks
All benchmarks (71 total, click to expand)
This comment was automatically generated by Benchmark workflow. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #226 +/- ##
=======================================
Coverage 96.38% 96.38%
=======================================
Files 176 176
Lines 15810 15816 +6
=======================================
+ Hits 15239 15245 +6
Misses 571 571
🚀 New features to boost your workflow:
|
Open
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.
Follow-up to #224.
Summary
Problem: on Metal, linear interpolation on a Float32 range grid ran at 74 % of copy bandwidth (a hand-written kernel reaches 100 %).
lo + (idx − 1)·his rebuilt from anInt64index, and 64-bit integer ↔ float conversions are costly on Metal. In isolation, an Int64 round trip measured 10× an Int32 one.Fix: on Float32/Float16 grids the left edge is rebuilt from
(idx − 1) % Int32. The index itself, the clamps, the loads and the returnedIntare unchanged, and results are bit-identical to master.InBounds(),ClampExtrap()FillExtrap,ExtendExtrap(),NoExtrap()Changes
_idx_type(T):Int32for Float32/Float16 grids,Intotherwise. It is used at the 8 left-edge rebuild sites of the range searches:muladd((idx - 1) % _idx_type(T), h, lo).typemax(Int32) ÷ 2(≈ 1.07e9) points (ArgumentError), so the narrowing is always exact.Performance
Not covered
Tests
test/test_range_cell_index.jl:Intchain (Float32/Float16 grids, Float64/Dual queries, at the length limit);