Skip to content

ILGPU V2.0: Accumulation Members for the Float16 Vector Types - #1697

Open
m4rs-mt wants to merge 3 commits into
cpu_shared_memory_refsfrom
half_accumulation_types
Open

m4rs-mt wants to merge 3 commits into
cpu_shared_memory_refsfrom
half_accumulation_types

Conversation

@m4rs-mt

@m4rs-mt m4rs-mt commented Oct 30, 2026

Copy link
Copy Markdown
Owner

Builds on #1696. The Float16 vector types gain the accumulation API of the Float32 vector types, Float32 and Float64
vectors accumulate Float16 vectors, and the atomic additions of all vector types compile in kernels.

Float16x8.AtomicAdd(ref sums[0], value);            // from many threads
var average = value.ComputeAverage((Half)8);
Float32x4.AtomicAdd(ref wide[0], halfQuad);         // accumulate halves in single precision

A note on authorship

This PR was done with AI-assistant pair programming (Claude via Claude Code). The commits carry a
Co-Authored-By: Claude trailer.

What's in this PR

1. Atomic additions of all vector types in kernels (Src/ILGPU/Vectors/VectorTypes.tt)

  • The vector AtomicAdd members address their elements with Unsafe.Add instead of UIntPtr byte offsets, so
    Float32xN.AtomicAdd, Int32xN.AtomicAdd and the other accumulation types compile in kernels.

2. Accumulation members for Float16x2, Float16x4 and Float16x8 (Src/ILGPU/Vectors/VectorTypes.tt)

  • Float16xN implements IAccumulationVectorType for Float16xN, UInt8xN and Int8xN: AtomicAdd,
    ComputeAverage (long, Half, byte, sbyte), and mixed +/- with the byte vectors.
  • Float32xN and Float64xN accumulate Float16xN values (+, -, AtomicAdd, ComputeAverage(Half)), so long
    sums of half values can be kept in single or double precision; the Float16 types document this.
  • AtomicAdd on Float16 vectors updates each pair of elements with one 32-bit compare-and-swap loop through
    Atomic.MakeAtomic, which every accelerator supports, and compares bits so NaN values end the loop.

3. Tests (Src/ILGPUC.Tests/)

  • HalfPrecisionExecutionTests.HalfVectorAccumulation_ProducesCorrectOutput (TestPrograms/HalfPrecision/HalfVectorAccumulation.cs):
    atomic additions from 256 threads to Float16x8/x4/x2, Int8x4, UInt8x2 and Float32x4 views, mixed operators,
    averages and the generic accumulation interface, compared with .NET.
  • HalfPrecisionExecutionTests.HalfVectorViews_ProducesCorrectOutput (TestPrograms/HalfPrecision/HalfVectorViews.cs):
    Float16x8 arithmetic, decrement, magnitude functions, classification predicates and random vectors; Float16 vectors
    in views, as uniform kernel parameters and through VectorView<Half> single vector views, compared with .NET.

Depends on

#1696 (based on its head; the base is retargeted once it merges).

Testing

Suite This PR
Full test suite, Apple Silicon (CPU, Metal, compile-only for all backends) 11099 passed, 2083 skipped, 0 failed
CUDA backend tests with nvcc, NVIDIA GB10 1137 passed, 0 failed
CUDA execution tests, NVIDIA GB10 506 passed, 3 skipped, 0 failed
Release build with TreatWarningsAsErrors 0 errors
Every commit of the PR builds

🤖 Generated with Claude Code

m4rs-mt and others added 3 commits October 25, 2026 17:47
…ng their elements without UIntPtr offsets.

Co-Authored-By: Claude <noreply@anthropic.com>
…ic additions through 32-bit compare-and-swap loops, and let the Float32 and Float64 vector types accumulate Float16 vectors.

Co-Authored-By: Claude <noreply@anthropic.com>
…edicates, decrements, random vectors, views of Float16 vectors, uniform Float16 vector parameters and single vector views.

Co-Authored-By: Claude <noreply@anthropic.com>

This branch has not been deployed

No deployments
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