Skip to content

Intrinsics

Portalez Régis edited this page May 11, 2026 · 1 revision

Intrinsics

Packed half-precision math via half2 and [HybridArithmeticFunction]. CUDA's half2 packs two FP16 lanes into a single 32-bit operation; [HybridArithmeticFunction] is a hint to hybridizer that the function should be specialized for arithmetic types like half2.

Source: src/1.Simple/Intrinsics/Program.cs

[HybridArithmeticFunction]
public static half2 exp(half2 x)
{
    return ((((((((((((((getHalf2(15.0F) + x)
        * x + getHalf2(210.0F))
        ... // Taylor polynomial
        * x + getHalf2(1307674368000.0F))
        * x * getHalf2(7.6471637318198164759011319857881e-13F);
}

[EntryPoint]
public static void Compute(half2[] input, int N)
{
    Parallel.For(0, N, i => { input[i] = exp12(input[i]); });
}

The .csproj also passes --additional-jit-headers "cuda_fp16.h=$(CUDA_PATH)/include;cuda_fp16.hpp=$(CUDA_PATH)/include" so the JIT compile can find CUDA's half-precision headers.

Clone this wiki locally