Repository navigation
Add native and half math - #644
Open
oscardssmith wants to merge 3 commits into
Open
oscardssmith wants to merge 3 commits into
oscardssmith wants to merge 3 commits into
Conversation
Add the OpenCL native_* functions (cos, divide, exp, exp2, exp10, log, log2, log10, powr, recip, rsqrt, sin, sqrt, tan) for Float32 and Float16, and route Base.FastMath's exp/log/div/inv/trig variants to them, like CUDA.jl's fast intrinsics. Without this, @fastmath falls back to the correctly rounded builtins. The Float16 native cos/sin/tan go through Float32: PoCL lacks the half versions, and on an Intel Arc B390 the detour is within 7% of the half natives (both 2.8-3.5x faster than the accurate Float16 builtins). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the OpenCL half_* functions (Float32 with at most 8192 ulp error) for completeness. They are not faster than native_*: on an Intel Arc B390, half_exp and half_log2 compile to the native instructions, while half_sin, half_tan and half_powr take the correctly rounded paths (as slow as the accurate builtins). @fastmath keeps using native_*. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The native_* results differ from Base's fast variants, so overlay them with
plain `@overlay` rather than `@device_override`'s consistent overlay. They go in
their own `fastmath_overrides` table, which OpenCL leaves out of the stack on the
OpenCL C source path: spirv2clc fails on the native_* extended instructions
("UNIMPLEMENTED extended instruction"), which broke `@fastmath` kernels there.
Tests: keep log inputs away from 1, and cover @fastmath sincos/inv, Float16,
and the spirv2clc path.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Last time I tried this some of these are slower. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #644 +/- ##
==========================================
- Coverage 90.26% 88.06% -2.20%
==========================================
Files 18 18
Lines 1684 1684
==========================================
- Hits 1520 1483 -37
- Misses 164 201 +37 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Author
|
At least on my igpu (intel xe graphics) the native ones are all faster. |
This branch has not been deployed
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.
Add the OpenCL
native_* andhalf_* functions (cos, divide, exp, exp2, exp10, log,log2, log10, powr, recip, rsqrt, sin, sqrt, tan) for Float32 and Float16,cand route Base.FastMath's exp/log/div/inv/trig variants to them, like CUDA.jl's fast intrinsics. Without this, @fastmath falls back to the Base impls.The Float16 native cos/sin/tan go through Float32: PoCL lacks the half versions, and on an Intel Arc B390 the detour is within 7% of the half natives (both 2.8-3.5x faster than the accurate Float16 builtins).
Co-Authored-By: Claude Opus 5.5 noreply@anthropic.com