Files
leleka/scripts/cuda-stubs/cuda_fp16.h
T
Pavlo RatushnyiandClaude Sonnet 5.5 2ab3a8ca48 test(cuda): run the stub pass through clang's CUDA frontend (host/device call legality, __shared__ rules, <<<>>>); fix qsa variants block_q4_0 packing, de-duplicate native_head_native.cu
- check-cu.py now defaults to clang -x cuda --cuda-host-only with real qualifiers; --plain keeps the C++-only pass.
- qsa_prompt_attention_variants.cu: block_q4_0 under pack(1) as in kv_q4.hpp (cu_pin refreshed).
- native_head_native.cu: orphan copy had __launch_bounds__ before extern "C" __global__ (never nvcc-built); now the sealed twin's text.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-14 16:56:45 +02:00

106 lines
6.0 KiB
C

// Stub of <cuda_fp16.h>: the class shape of the real __half / __half2 (implicit float conversions, so the same
// overload ambiguities as nvcc), the conversion and arithmetic intrinsics the sources use. Numerics are NOT modelled.
#pragma once
#include "cuda_stub.h"
#ifndef LELEKA_CUDA_STUB_FP16
#define LELEKA_CUDA_STUB_FP16
#if defined(__CUDA__)
#pragma clang force_cuda_host_device begin
#endif
struct __half_raw { unsigned short x; };
struct __half2_raw { unsigned short x, y; };
struct __half {
unsigned short __x;
__half() = default;
__half(const __half_raw& r) : __x(r.x) {}
__half(float f);
__half(double f);
__half(short v);
__half(unsigned short v);
__half(int v);
__half(unsigned int v);
__half(long long v);
__half(unsigned long long v);
operator __half_raw() const { return __half_raw{__x}; }
operator float() const;
operator short() const;
operator unsigned short() const;
operator int() const;
operator unsigned int() const;
operator long long() const;
operator unsigned long long() const;
operator char() const;
operator signed char() const;
operator unsigned char() const;
explicit operator bool() const;
__half& operator=(const __half_raw& r) { __x = r.x; return *this; }
__half& operator=(float f);
__half& operator=(double f);
__half& operator=(short v);
__half& operator=(unsigned short v);
__half& operator=(int v);
__half& operator=(unsigned int v);
__half& operator=(long long v);
__half& operator=(unsigned long long v);
__half& operator+=(const __half&); __half& operator-=(const __half&); __half& operator*=(const __half&); __half& operator/=(const __half&);
__half& operator++(); __half& operator--(); __half operator++(int); __half operator--(int);
};
typedef __half half;
struct __attribute__((aligned(4))) __half2 {
__half x, y;
__half2() = default;
__half2(const __half& a, const __half& b) : x(a), y(b) {}
__half2(const __half2_raw& r);
operator __half2_raw() const;
__half2& operator=(const __half2_raw&);
__half2& operator+=(const __half2&); __half2& operator-=(const __half2&); __half2& operator*=(const __half2&); __half2& operator/=(const __half2&);
};
typedef __half2 half2;
__half operator+(const __half&, const __half&); __half operator-(const __half&, const __half&);
__half operator*(const __half&, const __half&); __half operator/(const __half&, const __half&);
__half operator+(const __half&); __half operator-(const __half&);
bool operator==(const __half&, const __half&); bool operator!=(const __half&, const __half&);
bool operator<(const __half&, const __half&); bool operator>(const __half&, const __half&);
bool operator<=(const __half&, const __half&); bool operator>=(const __half&, const __half&);
__half2 operator+(const __half2&, const __half2&); __half2 operator-(const __half2&, const __half2&);
__half2 operator*(const __half2&, const __half2&); __half2 operator/(const __half2&, const __half2&);
__half __float2half(float); __half __float2half_rn(float); __half __float2half_rz(float); __half __float2half_rd(float); __half __float2half_ru(float);
__half __double2half(double);
float __half2float(__half);
__half2 make_half2(__half, __half);
__half2 __float2half2_rn(float); __half2 __floats2half2_rn(float, float); __half2 __halves2half2(__half, __half);
float2 __half22float2(__half2); __half2 __float22half2_rn(float2);
float __low2float(__half2); float __high2float(__half2); __half __low2half(__half2); __half __high2half(__half2);
__half2 __low2half2(__half2); __half2 __high2half2(__half2); __half2 __lows2half2(__half2, __half2); __half2 __highs2half2(__half2, __half2);
__half2 __half2half2(__half); __half2 __lowhigh2highlow(__half2);
short __half2short_rn(__half); int __half2int_rn(__half); int __half2int_rz(__half); unsigned __half2uint_rn(__half);
__half __int2half_rn(int); __half __short2half_rn(short); __half __uint2half_rn(unsigned);
short __half_as_short(__half); unsigned short __half_as_ushort(__half);
__half __short_as_half(short); __half __ushort_as_half(unsigned short);
int __half2_as_int(__half2); unsigned __half2_as_uint(__half2); __half2 __int_as_half2(int); __half2 __uint_as_half2(unsigned);
__half __hadd(__half, __half); __half __hsub(__half, __half); __half __hmul(__half, __half); __half __hdiv(__half, __half);
__half __hadd_rn(__half, __half); __half __hmul_rn(__half, __half); __half __hsub_rn(__half, __half); __half __hadd_sat(__half, __half);
__half __hfma(__half, __half, __half); __half __hfma_rn(__half, __half, __half); __half __hneg(__half); __half __habs(__half);
__half __hmax(__half, __half); __half __hmin(__half, __half);
bool __heq(__half, __half); bool __hne(__half, __half); bool __hlt(__half, __half); bool __hle(__half, __half);
bool __hgt(__half, __half); bool __hge(__half, __half); bool __hisnan(__half); bool __hisinf(__half);
__half2 __hadd2(__half2, __half2); __half2 __hsub2(__half2, __half2); __half2 __hmul2(__half2, __half2); __half2 __h2div(__half2, __half2);
__half2 __hfma2(__half2, __half2, __half2); __half2 __hneg2(__half2); __half2 __habs2(__half2);
__half2 __hadd2_rn(__half2, __half2); __half2 __hmul2_rn(__half2, __half2); __half2 __hsub2_rn(__half2, __half2);
__half2 __hmax2(__half2, __half2); __half2 __hmin2(__half2, __half2);
bool __hbeq2(__half2, __half2); bool __hbne2(__half2, __half2);
__half2 __heq2(__half2, __half2); __half2 __hlt2(__half2, __half2);
__half hexp(__half); __half hlog(__half); __half hsqrt(__half); __half hrsqrt(__half); __half hrcp(__half);
__half hexp2(__half); __half hsin(__half); __half hcos(__half); __half hfloor(__half); __half hceil(__half); __half htrunc(__half); __half hrint(__half);
__half2 h2exp(__half2); __half2 h2sqrt(__half2); __half2 h2rsqrt(__half2); __half2 h2rcp(__half2); __half2 h2exp2(__half2);
__half __shfl_sync(unsigned, __half, int, int = 32);
__half2 __shfl_sync(unsigned, __half2, int, int = 32);
__half2 __ldg(const __half2*); __half __ldg(const __half*);
void atomicAdd(__half*, __half);
__half2 atomicAdd(__half2*, __half2);
#if defined(__CUDA__)
#pragma clang force_cuda_host_device end
#endif
#endif