- 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>
584 lines
37 KiB
C++
584 lines
37 KiB
C++
// Host-only CUDA stand-in for SYNTAX / SEMANTICS checking of the ported .cu sources on a machine without nvcc.
|
|
//
|
|
// scripts/cuda-stubs/check-cu.py [--list] [file.cu ...] (default: every crates/cuda-driver/src/*.cu)
|
|
//
|
|
// What this proves: the file parses as C++17 and every identifier, overload, template argument and operand type that the
|
|
// device code uses resolves against a CUDA-shaped API (dim3/threadIdx, the vector types, __half/__nv_bfloat16, warp
|
|
// shuffle / vote, atomics, fast-math and rounding intrinsics, __dp4a and the SIMD-in-register family, cooperative
|
|
// groups, cp.async helpers, cudaFuncSetAttribute ...). Inline PTX (`asm volatile`) is NOT parsed: check-cu.py rewrites
|
|
// every asm statement into a call that still type-checks the operand expressions.
|
|
// What it does NOT prove: that nvcc accepts it (real __half has stricter conversion rules, texture/driver APIs and
|
|
// template deduction corner cases differ), PTX validity, register/smem limits, or any numerics. A pass here is
|
|
// necessary, not sufficient.
|
|
#pragma once
|
|
#ifndef LELEKA_CUDA_STUB_H
|
|
#define LELEKA_CUDA_STUB_H
|
|
|
|
// What <cuda_runtime.h> really drags in; the sources must name every other standard header themselves.
|
|
#include <stddef.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <math.h>
|
|
#include <time.h>
|
|
#include <stdint.h> // cuda_fp16.hpp/cuda_bf16.hpp and crt/*.h pull <stdint.h> in transitively on every supported host
|
|
#include <cmath>
|
|
#include <limits>
|
|
#include <type_traits>
|
|
#include <utility>
|
|
|
|
#ifndef __CUDA_ARCH__
|
|
#define __CUDA_ARCH__ 1200 // the device-compilation pass of -arch=sm_120 (the code the PTX is generated from)
|
|
#endif
|
|
#ifndef __CUDACC__
|
|
#define __CUDACC__ 1
|
|
#endif
|
|
#define __CUDACC_VER_MAJOR__ 13
|
|
#define __CUDACC_VER_MINOR__ 0
|
|
#define CUDART_VERSION 13000
|
|
#define CUDA_VERSION 13000
|
|
#define __CUDA_ARCH_LIST__ 1200
|
|
|
|
// ---------------------------------------------------------------------------------------------------- qualifiers
|
|
#if defined(__CUDA__)
|
|
// clang's CUDA frontend (check-cu.py --cuda): the qualifiers are real, so host/device call legality, __shared__ rules and
|
|
// the <<<>>> syntax are checked by the compiler itself. Everything below is declared __host__ __device__ (the region ends
|
|
// at the bottom of this file); the builtin variables and the libm overloads are __device__.
|
|
#define __global__ __attribute__((global))
|
|
#define __device__ __attribute__((device))
|
|
#define __host__ __attribute__((host))
|
|
#define __shared__ __attribute__((shared))
|
|
#define __constant__ __attribute__((constant))
|
|
#define __managed__ __attribute__((managed))
|
|
#define __forceinline__ __inline__ __attribute__((always_inline))
|
|
#define __launch_bounds__(...) __attribute__((launch_bounds(__VA_ARGS__)))
|
|
#define __grid_constant__ __attribute__((grid_constant))
|
|
#define CUDA_STUB_DEVVAR __device__
|
|
#else
|
|
#define __global__
|
|
#define __device__
|
|
#define __host__
|
|
#define __forceinline__ inline
|
|
#define __noinline__
|
|
#define __shared__
|
|
#define __constant__
|
|
#define __managed__
|
|
#define __launch_bounds__(...)
|
|
#define __grid_constant__
|
|
#define CUDA_STUB_DEVVAR
|
|
#endif
|
|
#define __restrict__ __restrict
|
|
#define __align__(n) __attribute__((aligned(n)))
|
|
#define __builtin_align__(n) __attribute__((aligned(n)))
|
|
#define __maxnreg__(n)
|
|
#define __cluster_dims__(...)
|
|
#define __builtin_assume(x) ((void) 0)
|
|
#if defined(__CUDA__)
|
|
#pragma clang force_cuda_host_device begin
|
|
#endif
|
|
|
|
// ---------------------------------------------------------------------------------------------------- vector types
|
|
#define CUDA_STUB_VEC1(T, N) struct N##1 { T x; }; static inline N##1 make_##N##1(T x) { return N##1{x}; }
|
|
#define CUDA_STUB_VEC2(T, N) struct N##2 { T x, y; }; static inline N##2 make_##N##2(T x, T y) { return N##2{x, y}; }
|
|
#define CUDA_STUB_VEC3(T, N) struct N##3 { T x, y, z; }; static inline N##3 make_##N##3(T x, T y, T z) { return N##3{x, y, z}; }
|
|
#define CUDA_STUB_VEC4(T, N) struct alignas(16) N##4 { T x, y, z, w; }; static inline N##4 make_##N##4(T x, T y, T z, T w) { return N##4{x, y, z, w}; }
|
|
#define CUDA_STUB_VEC_ALL(T, N) CUDA_STUB_VEC1(T, N) CUDA_STUB_VEC3(T, N)
|
|
CUDA_STUB_VEC_ALL(signed char, char)
|
|
CUDA_STUB_VEC_ALL(unsigned char, uchar)
|
|
CUDA_STUB_VEC_ALL(short, short)
|
|
CUDA_STUB_VEC_ALL(unsigned short, ushort)
|
|
CUDA_STUB_VEC_ALL(int, int)
|
|
CUDA_STUB_VEC_ALL(unsigned int, uint)
|
|
CUDA_STUB_VEC_ALL(long, long)
|
|
CUDA_STUB_VEC_ALL(unsigned long, ulong)
|
|
CUDA_STUB_VEC_ALL(long long, longlong)
|
|
CUDA_STUB_VEC_ALL(unsigned long long, ulonglong)
|
|
CUDA_STUB_VEC_ALL(float, float)
|
|
CUDA_STUB_VEC_ALL(double, double)
|
|
struct alignas(2) char2 { signed char x, y; };
|
|
static inline char2 make_char2(signed char x, signed char y) { return char2{x, y}; }
|
|
struct alignas(4) char4 { signed char x, y, z, w; };
|
|
static inline char4 make_char4(signed char x, signed char y, signed char z, signed char w) { return char4{x, y, z, w}; }
|
|
struct alignas(2) uchar2 { unsigned char x, y; };
|
|
static inline uchar2 make_uchar2(unsigned char x, unsigned char y) { return uchar2{x, y}; }
|
|
struct alignas(4) uchar4 { unsigned char x, y, z, w; };
|
|
static inline uchar4 make_uchar4(unsigned char x, unsigned char y, unsigned char z, unsigned char w) { return uchar4{x, y, z, w}; }
|
|
struct alignas(4) short2 { short x, y; };
|
|
static inline short2 make_short2(short x, short y) { return short2{x, y}; }
|
|
struct alignas(8) short4 { short x, y, z, w; };
|
|
static inline short4 make_short4(short x, short y, short z, short w) { return short4{x, y, z, w}; }
|
|
struct alignas(4) ushort2 { unsigned short x, y; };
|
|
static inline ushort2 make_ushort2(unsigned short x, unsigned short y) { return ushort2{x, y}; }
|
|
struct alignas(8) ushort4 { unsigned short x, y, z, w; };
|
|
static inline ushort4 make_ushort4(unsigned short x, unsigned short y, unsigned short z, unsigned short w) { return ushort4{x, y, z, w}; }
|
|
struct alignas(8) int2 { int x, y; };
|
|
static inline int2 make_int2(int x, int y) { return int2{x, y}; }
|
|
struct alignas(16) int4 { int x, y, z, w; };
|
|
static inline int4 make_int4(int x, int y, int z, int w) { return int4{x, y, z, w}; }
|
|
struct alignas(8) uint2 { unsigned x, y; };
|
|
static inline uint2 make_uint2(unsigned x, unsigned y) { return uint2{x, y}; }
|
|
struct alignas(16) uint4 { unsigned x, y, z, w; };
|
|
static inline uint4 make_uint4(unsigned x, unsigned y, unsigned z, unsigned w) { return uint4{x, y, z, w}; }
|
|
struct alignas(16) long2 { long x, y; };
|
|
struct alignas(16) ulong2 { unsigned long x, y; };
|
|
struct alignas(16) longlong2 { long long x, y; };
|
|
static inline longlong2 make_longlong2(long long x, long long y) { return longlong2{x, y}; }
|
|
struct alignas(16) ulonglong2 { unsigned long long x, y; };
|
|
static inline ulonglong2 make_ulonglong2(unsigned long long x, unsigned long long y) { return ulonglong2{x, y}; }
|
|
struct alignas(8) float2 { float x, y; };
|
|
static inline float2 make_float2(float x, float y) { return float2{x, y}; }
|
|
struct alignas(16) float4 { float x, y, z, w; };
|
|
static inline float4 make_float4(float x, float y, float z, float w) { return float4{x, y, z, w}; }
|
|
struct alignas(16) double2 { double x, y; };
|
|
static inline double2 make_double2(double x, double y) { return double2{x, y}; }
|
|
#undef CUDA_STUB_VEC1
|
|
#undef CUDA_STUB_VEC2
|
|
#undef CUDA_STUB_VEC3
|
|
#undef CUDA_STUB_VEC4
|
|
#undef CUDA_STUB_VEC_ALL
|
|
|
|
// ---------------------------------------------------------------------------------------------------- builtin variables
|
|
struct dim3 {
|
|
unsigned int x, y, z;
|
|
constexpr dim3(unsigned int vx = 1, unsigned int vy = 1, unsigned int vz = 1) : x(vx), y(vy), z(vz) {}
|
|
constexpr dim3(uint3 v) : x(v.x), y(v.y), z(v.z) {}
|
|
constexpr operator uint3() const { return uint3{x, y, z}; }
|
|
};
|
|
extern CUDA_STUB_DEVVAR const uint3 threadIdx;
|
|
extern CUDA_STUB_DEVVAR const uint3 blockIdx;
|
|
extern CUDA_STUB_DEVVAR const dim3 blockDim;
|
|
extern CUDA_STUB_DEVVAR const dim3 gridDim;
|
|
extern CUDA_STUB_DEVVAR const int warpSize;
|
|
|
|
// ---------------------------------------------------------------------------------------------------- errors / runtime API
|
|
typedef int cudaError_t;
|
|
typedef void* cudaStream_t;
|
|
typedef void* cudaEvent_t;
|
|
typedef void* cudaGraph_t;
|
|
typedef void* cudaGraphExec_t;
|
|
typedef void* CUstream;
|
|
typedef void* CUfunction;
|
|
typedef void* CUmodule;
|
|
typedef int CUresult;
|
|
enum { cudaSuccess = 0, cudaErrorInvalidValue = 1 };
|
|
enum cudaMemcpyKind { cudaMemcpyHostToHost, cudaMemcpyHostToDevice, cudaMemcpyDeviceToHost, cudaMemcpyDeviceToDevice, cudaMemcpyDefault };
|
|
enum cudaFuncAttribute { cudaFuncAttributeMaxDynamicSharedMemorySize = 8, cudaFuncAttributePreferredSharedMemoryCarveout = 9 };
|
|
enum cudaFuncCache { cudaFuncCachePreferNone, cudaFuncCachePreferShared, cudaFuncCachePreferL1 };
|
|
struct cudaFuncAttributes { size_t sharedSizeBytes; size_t constSizeBytes; size_t localSizeBytes; int maxThreadsPerBlock; int numRegs; int ptxVersion; int binaryVersion; int maxDynamicSharedSizeBytes; };
|
|
enum cudaLaunchAttributeID { cudaLaunchAttributeProgrammaticStreamSerialization = 5 };
|
|
union cudaLaunchAttributeValue { int programmaticStreamSerializationAllowed; };
|
|
struct cudaLaunchAttribute { cudaLaunchAttributeID id; cudaLaunchAttributeValue val; };
|
|
struct cudaLaunchConfig_t { dim3 gridDim, blockDim; size_t dynamicSmemBytes; cudaStream_t stream; cudaLaunchAttribute* attrs; unsigned numAttrs; };
|
|
template <class... Args, class... Params> cudaError_t cudaLaunchKernelEx(const cudaLaunchConfig_t*, void (*)(Params...), Args&&...);
|
|
struct cudaDeviceProp { char name[256]; int major, minor, multiProcessorCount, warpSize, maxThreadsPerBlock; size_t totalGlobalMem, sharedMemPerBlock, sharedMemPerBlockOptin; };
|
|
const char* cudaGetErrorString(cudaError_t);
|
|
cudaError_t cudaGetLastError();
|
|
cudaError_t cudaPeekAtLastError();
|
|
cudaError_t cudaDeviceSynchronize();
|
|
cudaError_t cudaStreamSynchronize(cudaStream_t);
|
|
cudaError_t cudaMalloc(void**, size_t);
|
|
cudaError_t cudaFree(void*);
|
|
cudaError_t cudaMemcpy(void*, const void*, size_t, cudaMemcpyKind);
|
|
cudaError_t cudaMemcpyAsync(void*, const void*, size_t, cudaMemcpyKind, cudaStream_t = nullptr);
|
|
cudaError_t cudaMemsetAsync(void*, int, size_t, cudaStream_t = nullptr);
|
|
cudaError_t cudaGetDevice(int*);
|
|
cudaError_t cudaGetDeviceProperties(cudaDeviceProp*, int);
|
|
cudaError_t cudaDeviceGetAttribute(int*, int, int);
|
|
cudaError_t cudaFuncGetAttributes(cudaFuncAttributes*, const void*);
|
|
cudaError_t cudaFuncSetAttribute(const void*, cudaFuncAttribute, int);
|
|
template <class T> cudaError_t cudaFuncSetAttribute(T* f, cudaFuncAttribute a, int v) { return cudaFuncSetAttribute((const void*) f, a, v); }
|
|
enum { cudaEventDisableTiming = 2, cudaEventDefault = 0, cudaStreamNonBlocking = 1, cudaStreamDefault = 0 };
|
|
cudaError_t cudaGridDependencySynchronize();
|
|
cudaError_t cudaTriggerProgrammaticLaunchCompletion();
|
|
cudaError_t cudaEventCreateWithFlags(cudaEvent_t*, unsigned);
|
|
cudaError_t cudaEventCreate(cudaEvent_t*);
|
|
cudaError_t cudaEventDestroy(cudaEvent_t);
|
|
cudaError_t cudaEventRecord(cudaEvent_t, cudaStream_t = nullptr);
|
|
cudaError_t cudaEventSynchronize(cudaEvent_t);
|
|
cudaError_t cudaEventElapsedTime(float*, cudaEvent_t, cudaEvent_t);
|
|
cudaError_t cudaStreamWaitEvent(cudaStream_t, cudaEvent_t, unsigned = 0);
|
|
cudaError_t cudaStreamCreateWithFlags(cudaStream_t*, unsigned);
|
|
cudaError_t cudaStreamCreate(cudaStream_t*);
|
|
cudaError_t cudaStreamDestroy(cudaStream_t);
|
|
cudaError_t cudaSetDevice(int);
|
|
cudaError_t cudaGetDeviceCount(int*);
|
|
cudaError_t cudaMemGetInfo(size_t*, size_t*);
|
|
cudaError_t cudaMallocHost(void**, size_t);
|
|
cudaError_t cudaFreeHost(void*);
|
|
cudaError_t cudaMemset(void*, int, size_t);
|
|
// driver API / cuBLAS names that ggml-cuda/common.cuh mentions in host helpers
|
|
CUresult cuGetErrorString(CUresult, const char**);
|
|
const char* cublasGetStatusString(int);
|
|
cudaError_t cudaLaunchKernel(const void*, dim3, dim3, void**, size_t, cudaStream_t);
|
|
|
|
// ---------------------------------------------------------------------------------------------------- integer / float intrinsics
|
|
// min / max exactly as crt/math_functions.hpp offers them (the mixed signed / unsigned overloads are real).
|
|
static inline int min(int a, int b) { return a < b ? a : b; }
|
|
static inline int max(int a, int b) { return a < b ? b : a; }
|
|
static inline unsigned min(unsigned a, unsigned b) { return a < b ? a : b; }
|
|
static inline unsigned max(unsigned a, unsigned b) { return a < b ? b : a; }
|
|
static inline unsigned min(int a, unsigned b) { return (unsigned) a < b ? (unsigned) a : b; }
|
|
static inline unsigned min(unsigned a, int b) { return a < (unsigned) b ? a : (unsigned) b; }
|
|
static inline unsigned max(int a, unsigned b) { return (unsigned) a < b ? b : (unsigned) a; }
|
|
static inline unsigned max(unsigned a, int b) { return a < (unsigned) b ? (unsigned) b : a; }
|
|
static inline long long min(long long a, long long b) { return a < b ? a : b; }
|
|
static inline long long max(long long a, long long b) { return a < b ? b : a; }
|
|
static inline unsigned long long min(unsigned long long a, unsigned long long b) { return a < b ? a : b; }
|
|
static inline unsigned long long max(unsigned long long a, unsigned long long b) { return a < b ? b : a; }
|
|
static inline unsigned long long min(long long a, unsigned long long b) { return (unsigned long long) a < b ? (unsigned long long) a : b; }
|
|
static inline unsigned long long min(unsigned long long a, long long b) { return a < (unsigned long long) b ? a : (unsigned long long) b; }
|
|
static inline unsigned long long max(long long a, unsigned long long b) { return (unsigned long long) a < b ? b : (unsigned long long) a; }
|
|
static inline unsigned long long max(unsigned long long a, long long b) { return a < (unsigned long long) b ? (unsigned long long) b : a; }
|
|
static inline long min(long a, long b) { return a < b ? a : b; }
|
|
static inline long max(long a, long b) { return a < b ? b : a; }
|
|
static inline unsigned long min(unsigned long a, unsigned long b) { return a < b ? a : b; }
|
|
static inline unsigned long max(unsigned long a, unsigned long b) { return a < b ? b : a; }
|
|
static inline float min(float a, float b) { return fminf(a, b); }
|
|
static inline float max(float a, float b) { return fmaxf(a, b); }
|
|
static inline double min(double a, double b) { return fmin(a, b); }
|
|
static inline double max(double a, double b) { return fmax(a, b); }
|
|
static inline double min(float a, double b) { return fmin((double) a, b); }
|
|
static inline double min(double a, float b) { return fmin(a, (double) b); }
|
|
static inline double max(float a, double b) { return fmax((double) a, b); }
|
|
static inline double max(double a, float b) { return fmax(a, (double) b); }
|
|
|
|
static inline int __isnanf(float x) { return std::isnan(x); }
|
|
static inline int __isinff(float x) { return std::isinf(x); }
|
|
static inline int __finitef(float x) { return std::isfinite(x); }
|
|
static inline float rsqrtf(float x) { return 1.0f / sqrtf(x); }
|
|
static inline double rsqrt(double x) { return 1.0 / sqrt(x); }
|
|
static inline float rcbrtf(float x) { return 1.0f / cbrtf(x); }
|
|
static inline float exp10f(float x) { return powf(10.0f, x); }
|
|
static inline void sincosf(float x, float* s, float* c) { *s = sinf(x); *c = cosf(x); }
|
|
static inline float __expf(float x) { return expf(x); }
|
|
static inline float __logf(float x) { return logf(x); }
|
|
static inline float __log2f(float x) { return log2f(x); }
|
|
static inline float __log10f(float x) { return log10f(x); }
|
|
static inline float __sinf(float x) { return sinf(x); }
|
|
static inline float __cosf(float x) { return cosf(x); }
|
|
static inline float __tanf(float x) { return tanf(x); }
|
|
static inline float __powf(float x, float y) { return powf(x, y); }
|
|
static inline float __fdividef(float x, float y) { return x / y; }
|
|
static inline double __ddiv_rn(double x, double y) { return x / y; }
|
|
static inline float __saturatef(float x) { return x < 0.f ? 0.f : (x > 1.f ? 1.f : x); }
|
|
static inline float __frcp_rn(float x) { return 1.0f / x; }
|
|
static inline float __frcp_rz(float x) { return 1.0f / x; }
|
|
static inline float __frsqrt_rn(float x) { return 1.0f / sqrtf(x); }
|
|
static inline float __fsqrt_rn(float x) { return sqrtf(x); }
|
|
static inline float __fsqrt_rz(float x) { return sqrtf(x); }
|
|
static inline float __fdiv_rn(float x, float y) { return x / y; }
|
|
static inline float __fdiv_rz(float x, float y) { return x / y; }
|
|
static inline float __fadd_rn(float x, float y) { return x + y; }
|
|
static inline float __fadd_rz(float x, float y) { return x + y; }
|
|
static inline float __fadd_rd(float x, float y) { return x + y; }
|
|
static inline float __fadd_ru(float x, float y) { return x + y; }
|
|
static inline float __fsub_rn(float x, float y) { return x - y; }
|
|
static inline float __fsub_rz(float x, float y) { return x - y; }
|
|
static inline float __fmul_rn(float x, float y) { return x * y; }
|
|
static inline float __fmul_rz(float x, float y) { return x * y; }
|
|
static inline float __fmaf_rn(float x, float y, float z) { return fmaf(x, y, z); }
|
|
static inline float __fmaf_rz(float x, float y, float z) { return fmaf(x, y, z); }
|
|
static inline float __fmaf_rd(float x, float y, float z) { return fmaf(x, y, z); }
|
|
static inline float __fmaf_ru(float x, float y, float z) { return fmaf(x, y, z); }
|
|
static inline double __dadd_rn(double x, double y) { return x + y; }
|
|
static inline double __dmul_rn(double x, double y) { return x * y; }
|
|
static inline double __fma_rn(double x, double y, double z) { return fma(x, y, z); }
|
|
static inline double __dsqrt_rn(double x) { return sqrt(x); }
|
|
static inline float __double2float_rn(double x) { return (float) x; }
|
|
static inline float __double2float_rz(double x) { return (float) x; }
|
|
static inline int __float2int_rn(float x) { return (int) nearbyintf(x); }
|
|
static inline int __float2int_rz(float x) { return (int) x; }
|
|
static inline int __float2int_rd(float x) { return (int) floorf(x); }
|
|
static inline int __float2int_ru(float x) { return (int) ceilf(x); }
|
|
static inline unsigned __float2uint_rn(float x) { return (unsigned) nearbyintf(x); }
|
|
static inline unsigned __float2uint_rz(float x) { return (unsigned) x; }
|
|
static inline unsigned __float2uint_rd(float x) { return (unsigned) floorf(x); }
|
|
static inline unsigned __float2uint_ru(float x) { return (unsigned) ceilf(x); }
|
|
static inline long long __float2ll_rn(float x) { return (long long) nearbyintf(x); }
|
|
static inline long long __float2ll_rz(float x) { return (long long) x; }
|
|
static inline unsigned long long __float2ull_rz(float x) { return (unsigned long long) x; }
|
|
static inline unsigned long long __float2ull_rn(float x) { return (unsigned long long) nearbyintf(x); }
|
|
static inline long long __double2ll_rn(double x) { return (long long) nearbyint(x); }
|
|
static inline long long __double2ll_rz(double x) { return (long long) x; }
|
|
static inline int __double2int_rn(double x) { return (int) nearbyint(x); }
|
|
static inline int __double2int_rz(double x) { return (int) x; }
|
|
static inline float __int2float_rn(int x) { return (float) x; }
|
|
static inline float __int2float_rz(int x) { return (float) x; }
|
|
static inline float __uint2float_rn(unsigned x) { return (float) x; }
|
|
static inline float __uint2float_rz(unsigned x) { return (float) x; }
|
|
static inline float __ll2float_rn(long long x) { return (float) x; }
|
|
static inline float __ull2float_rn(unsigned long long x) { return (float) x; }
|
|
static inline double __int2double_rn(int x) { return (double) x; }
|
|
static inline double __uint2double_rn(unsigned x) { return (double) x; }
|
|
static inline double __ll2double_rn(long long x) { return (double) x; }
|
|
static inline int __float_as_int(float x) { int r; memcpy(&r, &x, 4); return r; }
|
|
static inline unsigned __float_as_uint(float x) { unsigned r; memcpy(&r, &x, 4); return r; }
|
|
static inline float __int_as_float(int x) { float r; memcpy(&r, &x, 4); return r; }
|
|
static inline float __uint_as_float(unsigned x) { float r; memcpy(&r, &x, 4); return r; }
|
|
static inline long long __double_as_longlong(double x) { long long r; memcpy(&r, &x, 8); return r; }
|
|
static inline double __longlong_as_double(long long x) { double r; memcpy(&r, &x, 8); return r; }
|
|
static inline int __double2hiint(double x) { long long r = __double_as_longlong(x); return (int) (r >> 32); }
|
|
static inline int __double2loint(double x) { long long r = __double_as_longlong(x); return (int) r; }
|
|
static inline double __hiloint2double(int hi, int lo) { return __longlong_as_double(((long long) hi << 32) | (unsigned) lo); }
|
|
static inline int __popc(unsigned x) { return __builtin_popcount(x); }
|
|
static inline int __popcll(unsigned long long x) { return __builtin_popcountll(x); }
|
|
static inline int __clz(int x) { return x ? __builtin_clz((unsigned) x) : 32; }
|
|
static inline int __clzll(long long x) { return x ? __builtin_clzll((unsigned long long) x) : 64; }
|
|
static inline int __ffs(int x) { return __builtin_ffs(x); }
|
|
static inline int __ffsll(long long x) { return __builtin_ffsll(x); }
|
|
static inline unsigned __brev(unsigned x) { unsigned r = 0; for (int i = 0; i < 32; ++i) r |= ((x >> i) & 1u) << (31 - i); return r; }
|
|
static inline unsigned __byte_perm(unsigned x, unsigned y, unsigned s) {
|
|
const unsigned long long v = ((unsigned long long) y << 32) | x; unsigned r = 0;
|
|
for (int i = 0; i < 4; ++i) r |= (unsigned) ((v >> (8 * ((s >> (4 * i)) & 7))) & 0xffu) << (8 * i);
|
|
return r;
|
|
}
|
|
static inline unsigned __funnelshift_l(unsigned lo, unsigned hi, unsigned s) { s &= 31; return s ? (hi << s) | (lo >> (32 - s)) : hi; }
|
|
static inline unsigned __funnelshift_lc(unsigned lo, unsigned hi, unsigned s) { s = s > 32 ? 32 : s; return s == 0 ? hi : (s == 32 ? lo : (hi << s) | (lo >> (32 - s))); }
|
|
static inline unsigned __funnelshift_r(unsigned lo, unsigned hi, unsigned s) { s &= 31; return s ? (lo >> s) | (hi << (32 - s)) : lo; }
|
|
static inline unsigned __umulhi(unsigned a, unsigned b) { return (unsigned) (((unsigned long long) a * b) >> 32); }
|
|
static inline int __mulhi(int a, int b) { return (int) (((long long) a * b) >> 32); }
|
|
static inline unsigned long long __umul64hi(unsigned long long a, unsigned long long b) { return (unsigned long long) (((__uint128_t) a * b) >> 64); }
|
|
static inline int __mul24(int a, int b) { return a * b; }
|
|
static inline unsigned __umul24(unsigned a, unsigned b) { return (a & 0xffffffu) * (b & 0xffffffu); }
|
|
static inline int __sad(int a, int b, unsigned c) { return (a > b ? a - b : b - a) + (int) c; }
|
|
static inline unsigned __usad(unsigned a, unsigned b, unsigned c) { return (a > b ? a - b : b - a) + c; }
|
|
static inline int __dp4a(int a, int b, int c) {
|
|
for (int i = 0; i < 4; ++i) c += (int) (signed char) (a >> (8 * i)) * (int) (signed char) (b >> (8 * i));
|
|
return c;
|
|
}
|
|
static inline unsigned __dp4a(unsigned a, unsigned b, unsigned c) {
|
|
for (int i = 0; i < 4; ++i) c += ((a >> (8 * i)) & 0xffu) * ((b >> (8 * i)) & 0xffu);
|
|
return c;
|
|
}
|
|
static inline int __dp4a(int a, unsigned b, int c) {
|
|
for (int i = 0; i < 4; ++i) c += (int) (signed char) (a >> (8 * i)) * (int) ((b >> (8 * i)) & 0xffu);
|
|
return c;
|
|
}
|
|
static inline int __dp4a(unsigned a, int b, int c) { return __dp4a(b, a, c); }
|
|
static inline int __dp2a_lo(int a, int b, int c) { return c + (short) a * (signed char) b + (short) (a >> 16) * (signed char) (b >> 8); }
|
|
#define CUDA_STUB_SIMD4(name) static inline unsigned name(unsigned a, unsigned b) { unsigned r = 0; for (int i = 0; i < 4; ++i) { (void) i; } return a ^ b ^ r; }
|
|
CUDA_STUB_SIMD4(__vadd4) CUDA_STUB_SIMD4(__vsub4) CUDA_STUB_SIMD4(__vcmpeq4) CUDA_STUB_SIMD4(__vcmpne4)
|
|
CUDA_STUB_SIMD4(__vcmpgtu4) CUDA_STUB_SIMD4(__vcmpltu4) CUDA_STUB_SIMD4(__vcmpleu4) CUDA_STUB_SIMD4(__vcmpgeu4)
|
|
CUDA_STUB_SIMD4(__vcmpgts4) CUDA_STUB_SIMD4(__vcmplts4) CUDA_STUB_SIMD4(__vcmples4) CUDA_STUB_SIMD4(__vcmpges4)
|
|
CUDA_STUB_SIMD4(__vabsdiffu4) CUDA_STUB_SIMD4(__vabsdiffs4) CUDA_STUB_SIMD4(__vmaxu4) CUDA_STUB_SIMD4(__vminu4)
|
|
CUDA_STUB_SIMD4(__vmaxs4) CUDA_STUB_SIMD4(__vmins4) CUDA_STUB_SIMD4(__vsubss4) CUDA_STUB_SIMD4(__vaddss4)
|
|
CUDA_STUB_SIMD4(__vsubus4) CUDA_STUB_SIMD4(__vaddus4) CUDA_STUB_SIMD4(__vavgu4) CUDA_STUB_SIMD4(__vhaddu4)
|
|
#undef CUDA_STUB_SIMD4
|
|
static inline unsigned __vabs4(unsigned a) { return a; }
|
|
static inline unsigned __vneg4(unsigned a) { return a; }
|
|
static inline unsigned __vnegss4(unsigned a) { return a; }
|
|
static inline unsigned __vsads4(unsigned a, unsigned b) { return a ^ b; }
|
|
static inline unsigned __vsadu4(unsigned a, unsigned b) { return a ^ b; }
|
|
static inline int __viaddmax_s32(int a, int b, int c) { return max(a + b, c); }
|
|
static inline int __vimax_s32(int a, int b) { return max(a, b); }
|
|
static inline int __vimin_s32(int a, int b) { return min(a, b); }
|
|
|
|
// ---------------------------------------------------------------------------------------------------- synchronisation, warp, memory
|
|
#if !defined(__CUDA__)
|
|
void __syncthreads();
|
|
#endif
|
|
int __syncthreads_count(int);
|
|
int __syncthreads_and(int);
|
|
int __syncthreads_or(int);
|
|
void __syncwarp(unsigned mask = 0xffffffffu);
|
|
void __threadfence();
|
|
void __threadfence_block();
|
|
void __threadfence_system();
|
|
void __nanosleep(unsigned);
|
|
long long clock64();
|
|
void __trap();
|
|
void __brkpt();
|
|
unsigned __activemask();
|
|
unsigned __ballot_sync(unsigned, int);
|
|
int __any_sync(unsigned, int);
|
|
int __all_sync(unsigned, int);
|
|
unsigned __match_any_sync(unsigned, unsigned);
|
|
unsigned __match_any_sync(unsigned, int);
|
|
unsigned __match_any_sync(unsigned, float);
|
|
unsigned __match_all_sync(unsigned, unsigned, int*);
|
|
template <class T> T __shfl_sync(unsigned, T, int, int = 32);
|
|
template <class T> T __shfl_up_sync(unsigned, T, unsigned, int = 32);
|
|
template <class T> T __shfl_down_sync(unsigned, T, unsigned, int = 32);
|
|
template <class T> T __shfl_xor_sync(unsigned, T, int, int = 32);
|
|
template <class T> T __reduce_add_sync(unsigned, T);
|
|
template <class T> T __reduce_max_sync(unsigned, T);
|
|
template <class T> T __reduce_min_sync(unsigned, T);
|
|
template <class T> T __ldg(const T*);
|
|
template <class T> T __ldcg(const T*);
|
|
template <class T> T __ldca(const T*);
|
|
template <class T> T __ldcs(const T*);
|
|
template <class T> T __ldlu(const T*);
|
|
template <class T> T __ldcv(const T*);
|
|
template <class T> void __stcg(T*, T);
|
|
template <class T> void __stcs(T*, T);
|
|
template <class T> void __stwb(T*, T);
|
|
template <class T> void __stwt(T*, T);
|
|
void __prefetch_global_l1(const void*);
|
|
void __prefetch_global_l2(const void*);
|
|
bool __isShared(const void*);
|
|
bool __isGlobal(const void*);
|
|
bool __isConstant(const void*);
|
|
bool __isLocal(const void*);
|
|
unsigned long long __cvta_generic_to_shared(const void*);
|
|
unsigned long long __cvta_generic_to_global(const void*);
|
|
void* __cvta_shared_to_generic(unsigned long long);
|
|
void* __cvta_global_to_generic(unsigned long long);
|
|
|
|
int atomicAdd(int*, int);
|
|
unsigned atomicAdd(unsigned*, unsigned);
|
|
unsigned long long atomicAdd(unsigned long long*, unsigned long long);
|
|
float atomicAdd(float*, float);
|
|
double atomicAdd(double*, double);
|
|
int atomicSub(int*, int);
|
|
unsigned atomicSub(unsigned*, unsigned);
|
|
int atomicExch(int*, int);
|
|
unsigned atomicExch(unsigned*, unsigned);
|
|
unsigned long long atomicExch(unsigned long long*, unsigned long long);
|
|
float atomicExch(float*, float);
|
|
int atomicMin(int*, int);
|
|
unsigned atomicMin(unsigned*, unsigned);
|
|
unsigned long long atomicMin(unsigned long long*, unsigned long long);
|
|
long long atomicMin(long long*, long long);
|
|
int atomicMax(int*, int);
|
|
unsigned atomicMax(unsigned*, unsigned);
|
|
unsigned long long atomicMax(unsigned long long*, unsigned long long);
|
|
long long atomicMax(long long*, long long);
|
|
unsigned atomicInc(unsigned*, unsigned);
|
|
unsigned atomicDec(unsigned*, unsigned);
|
|
int atomicCAS(int*, int, int);
|
|
unsigned atomicCAS(unsigned*, unsigned, unsigned);
|
|
unsigned long long atomicCAS(unsigned long long*, unsigned long long, unsigned long long);
|
|
unsigned short atomicCAS(unsigned short*, unsigned short, unsigned short);
|
|
int atomicAnd(int*, int);
|
|
unsigned atomicAnd(unsigned*, unsigned);
|
|
unsigned long long atomicAnd(unsigned long long*, unsigned long long);
|
|
int atomicOr(int*, int);
|
|
unsigned atomicOr(unsigned*, unsigned);
|
|
unsigned long long atomicOr(unsigned long long*, unsigned long long);
|
|
int atomicXor(int*, int);
|
|
unsigned atomicXor(unsigned*, unsigned);
|
|
unsigned long long atomicXor(unsigned long long*, unsigned long long);
|
|
|
|
// ---------------------------------------------------------------------------------------------------- inline PTX
|
|
// check-cu.py turns `asm volatile("..." : outs : ins : clobbers)` into cuda_stub_asm(op0, op1, ...) so the operand
|
|
// expressions are still type-checked; the PTX text itself is never examined.
|
|
template <class... T> inline void cuda_stub_asm(T&&...) {}
|
|
// check-cu.py turns `K<<<grid, block, smem, stream>>>(args)` into (cuda_stub_cfg(grid, block, smem, stream), K(args)).
|
|
struct cuda_stub_cfg_t {};
|
|
template <class A, class B> cuda_stub_cfg_t cuda_stub_cfg(A&&, B&&) { return {}; }
|
|
template <class A, class B, class C> cuda_stub_cfg_t cuda_stub_cfg(A&&, B&&, C&&) { return {}; }
|
|
template <class A, class B, class C, class D> cuda_stub_cfg_t cuda_stub_cfg(A&&, B&&, C&&, D&&) { return {}; }
|
|
|
|
#if defined(__CUDA__)
|
|
#pragma clang force_cuda_host_device end
|
|
#endif
|
|
#if defined(__CUDA__)
|
|
extern "C" unsigned __cudaPushCallConfiguration(dim3, dim3, size_t = 0, void* = nullptr);
|
|
extern "C" int cudaConfigureCall(dim3, dim3, size_t = 0, void* = nullptr); // older toolkit spelling, clang looks for either
|
|
#endif
|
|
// ---- device libm: __host__ __device__ statics so device code resolves expf(x) etc. (clang's own wrappers do the same)
|
|
#if defined(__CUDA__)
|
|
static __device__ inline float sinf(float x) { return __builtin_sinf(x); }
|
|
static __device__ inline float cosf(float x) { return __builtin_cosf(x); }
|
|
static __device__ inline float tanf(float x) { return __builtin_tanf(x); }
|
|
static __device__ inline float asinf(float x) { return __builtin_asinf(x); }
|
|
static __device__ inline float acosf(float x) { return __builtin_acosf(x); }
|
|
static __device__ inline float atanf(float x) { return __builtin_atanf(x); }
|
|
static __device__ inline float sinhf(float x) { return __builtin_sinhf(x); }
|
|
static __device__ inline float coshf(float x) { return __builtin_coshf(x); }
|
|
static __device__ inline float tanhf(float x) { return __builtin_tanhf(x); }
|
|
static __device__ inline float asinhf(float x) { return __builtin_asinhf(x); }
|
|
static __device__ inline float acoshf(float x) { return __builtin_acoshf(x); }
|
|
static __device__ inline float atanhf(float x) { return __builtin_atanhf(x); }
|
|
static __device__ inline float expf(float x) { return __builtin_expf(x); }
|
|
static __device__ inline float exp2f(float x) { return __builtin_exp2f(x); }
|
|
static __device__ inline float expm1f(float x) { return __builtin_expm1f(x); }
|
|
static __device__ inline float logf(float x) { return __builtin_logf(x); }
|
|
static __device__ inline float log2f(float x) { return __builtin_log2f(x); }
|
|
static __device__ inline float log10f(float x) { return __builtin_log10f(x); }
|
|
static __device__ inline float log1pf(float x) { return __builtin_log1pf(x); }
|
|
static __device__ inline float sqrtf(float x) { return __builtin_sqrtf(x); }
|
|
static __device__ inline float cbrtf(float x) { return __builtin_cbrtf(x); }
|
|
static __device__ inline float fabsf(float x) { return __builtin_fabsf(x); }
|
|
static __device__ inline float floorf(float x) { return __builtin_floorf(x); }
|
|
static __device__ inline float ceilf(float x) { return __builtin_ceilf(x); }
|
|
static __device__ inline float roundf(float x) { return __builtin_roundf(x); }
|
|
static __device__ inline float rintf(float x) { return __builtin_rintf(x); }
|
|
static __device__ inline float truncf(float x) { return __builtin_truncf(x); }
|
|
static __device__ inline float nearbyintf(float x) { return __builtin_nearbyintf(x); }
|
|
static __device__ inline float erff(float x) { return __builtin_erff(x); }
|
|
static __device__ inline float erfcf(float x) { return __builtin_erfcf(x); }
|
|
static __device__ inline float lgammaf(float x) { return __builtin_lgammaf(x); }
|
|
static __device__ inline float tgammaf(float x) { return __builtin_tgammaf(x); }
|
|
static __device__ inline float logbf(float x) { return __builtin_logbf(x); }
|
|
static __device__ inline float atan2f(float x, float y) { return __builtin_atan2f(x, y); }
|
|
static __device__ inline float powf(float x, float y) { return __builtin_powf(x, y); }
|
|
static __device__ inline float fmaxf(float x, float y) { return __builtin_fmaxf(x, y); }
|
|
static __device__ inline float fminf(float x, float y) { return __builtin_fminf(x, y); }
|
|
static __device__ inline float fmodf(float x, float y) { return __builtin_fmodf(x, y); }
|
|
static __device__ inline float copysignf(float x, float y) { return __builtin_copysignf(x, y); }
|
|
static __device__ inline float hypotf(float x, float y) { return __builtin_hypotf(x, y); }
|
|
static __device__ inline float remainderf(float x, float y) { return __builtin_remainderf(x, y); }
|
|
static __device__ inline float nextafterf(float x, float y) { return __builtin_nextafterf(x, y); }
|
|
static __device__ inline float fdimf(float x, float y) { return __builtin_fdimf(x, y); }
|
|
static __device__ inline double sin(double x) { return __builtin_sin(x); }
|
|
static __device__ inline double cos(double x) { return __builtin_cos(x); }
|
|
static __device__ inline double tan(double x) { return __builtin_tan(x); }
|
|
static __device__ inline double asin(double x) { return __builtin_asin(x); }
|
|
static __device__ inline double acos(double x) { return __builtin_acos(x); }
|
|
static __device__ inline double atan(double x) { return __builtin_atan(x); }
|
|
static __device__ inline double sinh(double x) { return __builtin_sinh(x); }
|
|
static __device__ inline double cosh(double x) { return __builtin_cosh(x); }
|
|
static __device__ inline double tanh(double x) { return __builtin_tanh(x); }
|
|
static __device__ inline double exp(double x) { return __builtin_exp(x); }
|
|
static __device__ inline double exp2(double x) { return __builtin_exp2(x); }
|
|
static __device__ inline double expm1(double x) { return __builtin_expm1(x); }
|
|
static __device__ inline double log(double x) { return __builtin_log(x); }
|
|
static __device__ inline double log2(double x) { return __builtin_log2(x); }
|
|
static __device__ inline double log10(double x) { return __builtin_log10(x); }
|
|
static __device__ inline double log1p(double x) { return __builtin_log1p(x); }
|
|
static __device__ inline double sqrt(double x) { return __builtin_sqrt(x); }
|
|
static __device__ inline double cbrt(double x) { return __builtin_cbrt(x); }
|
|
static __device__ inline double fabs(double x) { return __builtin_fabs(x); }
|
|
static __device__ inline double floor(double x) { return __builtin_floor(x); }
|
|
static __device__ inline double ceil(double x) { return __builtin_ceil(x); }
|
|
static __device__ inline double round(double x) { return __builtin_round(x); }
|
|
static __device__ inline double rint(double x) { return __builtin_rint(x); }
|
|
static __device__ inline double trunc(double x) { return __builtin_trunc(x); }
|
|
static __device__ inline double nearbyint(double x) { return __builtin_nearbyint(x); }
|
|
static __device__ inline double erf(double x) { return __builtin_erf(x); }
|
|
static __device__ inline double erfc(double x) { return __builtin_erfc(x); }
|
|
static __device__ inline double lgamma(double x) { return __builtin_lgamma(x); }
|
|
static __device__ inline double tgamma(double x) { return __builtin_tgamma(x); }
|
|
static __device__ inline double atan2(double x, double y) { return __builtin_atan2(x, y); }
|
|
static __device__ inline double pow(double x, double y) { return __builtin_pow(x, y); }
|
|
static __device__ inline double fmax(double x, double y) { return __builtin_fmax(x, y); }
|
|
static __device__ inline double fmin(double x, double y) { return __builtin_fmin(x, y); }
|
|
static __device__ inline double fmod(double x, double y) { return __builtin_fmod(x, y); }
|
|
static __device__ inline double copysign(double x, double y) { return __builtin_copysign(x, y); }
|
|
static __device__ inline double hypot(double x, double y) { return __builtin_hypot(x, y); }
|
|
static __device__ inline double remainder(double x, double y) { return __builtin_remainder(x, y); }
|
|
static __device__ inline float fmaf(float x, float y, float z) { return __builtin_fmaf(x, y, z); }
|
|
static __device__ inline double fma(double x, double y, double z) { return __builtin_fma(x, y, z); }
|
|
static __device__ inline float ldexpf(float x, int e) { return __builtin_ldexpf(x, e); }
|
|
static __device__ inline float frexpf(float x, int* e) { return __builtin_frexpf(x, e); }
|
|
static __device__ inline float scalbnf(float x, int e) { return __builtin_scalbnf(x, e); }
|
|
static __device__ inline long lroundf(float x) { return __builtin_lroundf(x); }
|
|
static __device__ inline long lrintf(float x) { return __builtin_lrintf(x); }
|
|
static __device__ inline int abs(int x) { return x < 0 ? -x : x; }
|
|
static __device__ inline long long llabs(long long x) { return x < 0 ? -x : x; }
|
|
static __device__ inline bool isnan(float x) { return __builtin_isnan(x); }
|
|
static __device__ inline bool isinf(float x) { return __builtin_isinf(x); }
|
|
static __device__ inline bool isfinite(float x) { return __builtin_isfinite(x); }
|
|
static __device__ inline bool isnan(double x) { return __builtin_isnan(x); }
|
|
static __device__ inline bool isinf(double x) { return __builtin_isinf(x); }
|
|
static __device__ inline bool isfinite(double x) { return __builtin_isfinite(x); }
|
|
static __device__ inline void* memcpy(void* d, const void* s, size_t n) { return __builtin_memcpy(d, s, n); }
|
|
static __device__ inline void* memset(void* d, int c, size_t n) { return __builtin_memset(d, c, n); }
|
|
static __device__ inline void* memmove(void* d, const void* s, size_t n) { return __builtin_memmove(d, s, n); }
|
|
static __device__ inline int memcmp(const void* a, const void* b, size_t n) { return __builtin_memcmp(a, b, n); }
|
|
extern "C" __device__ int vprintf(const char*, const char*);
|
|
template <class... A> __device__ inline int cuda_stub_printf(const char*, A...) { return 0; } // check-cu.py rewrites printf( call sites to it
|
|
static __device__ inline bool signbit(float x) { return __builtin_signbit(x); }
|
|
#endif
|
|
#endif
|