Repository navigation
GPU: Uint8ClampedArray/Float16Array kernel args, f16 promotion fix, and the first run on an Intel GPU - #1108
Merged
Merged
Conversation
…n integer is an f16 The two typed arrays the default library makes as ConvertingTypedArray<S> around a TypedArray<S> are taken by a launch, gpuReduce, gpuBatch and a CPU call as the inner TypedArray's view: a Float16Array's u16 store seen as f16[], a Uint8ClampedArray's as u8[]. A kernel's Uint8ClampedArray parameter keeps JavaScript's rule: each write to its elements (=, +=..., ++/--, the postfix's value the element before) goes through ToUint8Clamp (a generic source helper, .u8_clamp: into 0..255, half to even, NaN 0); Atomics on one is an error, as in JavaScript. Language fix found on the way: the promotion ladder had f16 below s32, so `f16 * 2` was an s32 multiply (0.3 * 2 was 0). f16 now sits with f32, above the 32-bit integers: an f16 with an integer is an f16, as a float is a float. 00f16_conversions.ts checks it. gpu_clamped_half.ts runs each kernel on the GPU and on the CPU (the default library's typed arrays) and they agree: ties, ends, NaN, ++ at 255, binary16 rounding, overflow to Infinity, gpuReduce and gpuBatch; RTX 5080, JIT and exe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rs no longer hang, warps of 16, exact float sqrt and ceil First run on an Intel GPU (Core Ultra 9 285K's integrated one, Level Zero on Windows). 19 of the 26 GPU programs passed; these fixes make all 26 pass, as executables and under the JIT, and the 11 fault cases: - Shared-memory kernels did not load: the barrier guard asks to_local(p), and the Intel driver has no to_local for the pointer types the backend gives it. After O3 a pointer followed to its object is known (shared, or not); one known only on the GPU is checked against the shared arrays of the kernels that reach it. - Barrier kernels hung: O3's loop unswitching and jump threading copied OpenCL's barrier, a plain function to them, into branches a block's threads take apart, and an Intel subgroup waits at one copy for its lanes at the other. Every device function is now convergent, as clang has a CUDA or OpenCL one (NVIDIA's bar.sync counts threads, so it ran there). - gpuWarpSize() differed between kernels (the driver picks 8, 16 or 32 per kernel): each Intel kernel's subgroup is pinned at 16 (intel_reqd_sub_group_size), which every Intel GPU has. - A float's sqrt was not correctly rounded (OpenCL allows 3 ulps): the module is built with -cl-fp32-correctly-rounded-divide-sqrt. - Math.ceil of a v in (-1, -0] gave 0, not -0: copysign(ceil(v), v), exact on every GPU. NVIDIA rerun: all 26 programs pass, JIT and exe. GPU and f16 ctests pass (90). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Uint8ClampedArrayandFloat16Arraycan now be kernel arguments.What changes
ConvertingTypedArray<S>wrapping aTypedArray<S>.gpuLaunch,gpuReduce,gpuBatchand CPU calls pass the innerTypedArray's view:Float16Array's u16 store becomesf16[];Uint8ClampedArraybecomesu8[].Uint8ClampedArrayparameter's elements are clamped, as you ruled:=, the compound assignments, and++/--. Each goes through ToUint8Clamp, a generic source helper.u8_clamp: values go into 0..255, ties round to even, and NaN becomes 0. A postfix expression's value is the element before the write.Uint8ClampedArrayis a compile error, as in JavaScript.Language fix: f16 with an integer is f16
The numeric promotion ladder ranked f16 below s32, so
f16 * 2was an s32 multiply:0.3 * 2gave0. f16 now sits next to f32, above the 32-bit integers, so an f16 combined with an integer is an f16, the same as other floats. New asserts in00f16_conversions.tscover this.Intel: first run on hardware
The Intel iGPU (Core Ultra 9 285K, Level Zero on Windows) ran the GPU programs for the first time. 19 of 26 passed; the fixes below (a47cf73) make all 26 pass, as executables and under the JIT, and all 11 fault cases.
to_local(p)has no Intel driver builtin for the pointer types the SPIR-V backend produces.barrier()into branches that threads take differently, and an Intel subgroup then waits forever at one copy.convergent, as clang does for CUDA and OpenCL.bar.synccounts threads, which is why it worked there.gpuWarpSize()differed between kernels. The driver picks 8, 16 or 32 lanes for each kernel, so each Intel kernel is now pinned to 16 (intel_reqd_sub_group_size).sqrtwasn't correctly rounded. OpenCL allows an error of up to 3 ulps, so modules are now built with-cl-fp32-correctly-rounded-divide-sqrt.Math.ceilof a value in (-1, -0] gave 0 instead of -0. It is nowcopysign(ceil(v), v), which is exact on every GPU.Tests
gpu_clamped_half.ts. Runs each kernel on the GPU and on the CPU (the default library's typed arrays), and checks that the two agree. It covers:++at 255;gpuReduceandgpuBatch.compile/clamped_half.tschecks the launch kinds and the clamp calls on every GPU target.compile/clamped_atomics.tschecks the Atomics error.docs/gpu.mdhas a new section on these arrays.Verified
🤖 Generated with Claude Code