Device intrinsic host fallbacks#
Cache-hinted loads/stores are plain pointer access in the one-address-space sim; the hint (streaming / last-use / global) has no effect on correctness.
Defined in code/simulator.h.
This page documents 29 symbols: 29 functions.
Functions#
Signature |
Description |
Availability |
Location |
Example |
|---|---|---|---|---|
|
sim only |
simulator.h:792 |
||
|
sim only |
simulator.h:787 |
||
|
sim only |
simulator.h:786 |
||
|
sim only |
simulator.h:795 |
||
|
sim only |
simulator.h:764 |
||
|
sim only |
simulator.h:766 |
||
|
sim only |
simulator.h:765 |
||
|
Cache-hinted loads/stores are plain pointer access in the one-address-space sim; the hint (streaming / last-use / global) has no effect on correctness. |
sim only |
simulator.h:763 |
|
|
sim only |
simulator.h:767 |
||
|
sim only |
simulator.h:790 |
||
|
sim only |
simulator.h:789 |
||
|
sim only |
simulator.h:788 |
||
|
sim only |
simulator.h:797 |
||
|
sim only |
simulator.h:799 |
||
|
Memory fences: the sim runs one fiber at a time and (outside cooperative launch) one block at a time, so nothing can be reordered — every fence is already satisfied. |
sim only |
simulator.h:777 |
|
|
sim only |
simulator.h:785 |
||
|
sim only |
simulator.h:796 |
||
|
sim only |
simulator.h:794 |
||
|
sim only |
simulator.h:791 |
||
|
sim only |
simulator.h:770 |
||
|
sim only |
simulator.h:768 |
||
|
sim only |
simulator.h:769 |
||
|
sim only |
simulator.h:793 |
||
|
sim only |
simulator.h:778 |
||
|
sim only |
simulator.h:779 |
||
|
sim only |
simulator.h:780 |
||
|
sim only |
simulator.h:798 |
||
|
sim only |
simulator.h:784 |
||
|
Fast-math / integer intrinsics — computed exactly on the CPU (no reduced- precision device path), so the “__” fast variant equals the standard one. |
sim only |
simulator.h:783 |
Examples#
Code from the repository’s example corpus (code\*.cu); the highlighted line is the call site. These blocks are what the View links above open.
__expf (test_web_cs_imagedenoising.cu:132)
122 float fCount = 0;
123 float sumWeights = 0;
124 float3 clr = {0, 0, 0};
125 float4 clr00 = tex2D<float4>(texImage, x, y);
126
127 for (float i = -KNN_WINDOW_RADIUS; i <= KNN_WINDOW_RADIUS; i++)
128 for (float j = -KNN_WINDOW_RADIUS; j <= KNN_WINDOW_RADIUS; j++) {
129 float4 clrIJ = tex2D<float4>(texImage, x + j, y + i);
130 float distanceIJ = vecLen(clr00, clrIJ);
131
132 float weightIJ = __expf(-(distanceIJ * Noise
133 + (i * i + j * j) * INV_KNN_WINDOW_AREA));
134
135 clr.x += clrIJ.x * weightIJ;
136 clr.y += clrIJ.y * weightIJ;
137 clr.z += clrIJ.z * weightIJ;
138
139 sumWeights += weightIJ;
140 fCount += (weightIJ > KNN_WEIGHT_THRESHOLD) ? INV_KNN_WINDOW_AREA : 0;
141 }
142
143 sumWeights = 1.0f / sumWeights;
__ldcs (test_llmc_attention_backward.cu:479)
469 local_sum += att_bth[t2] * datt_bth[t2];
470 }
471
472 block_acc[warp.meta_group_rank()] = cg::reduce(warp, local_sum, cg::plus<float>{});
473 block.sync();
474 local_sum = cg::reduce(warp, block_acc[warp.thread_rank()], cg::plus<float>{});
475
476 for (int t3 = block.thread_rank(); t3 <= t; t3 += BlockSize) {
477 // don't touch the cache. Some parts will still be here from the previous loop, and
478 // we want to exploit those.
479 float acc = __ldcs(att_bth + t3) * (__ldcs(datt_bth + t3) - local_sum);
480 __stcs(dpreatt_bth + t3, scale * acc);
481 }
482 }
483}
484
485// ----------------------------------------------------------------------------
486// kernel launchers ([SIM] <<<dim3(...),block>>> -> LAUNCH(kernel, dim3(...), block, ...))
487
488void launch_softmax_1(float* dpreatt, float* datt, const float* att, int B, int T, int C, int NH, int block_size) {
489 int num_blocks = ceil_div(T, block_size);
490 LAUNCH(softmax_autoregressive_backward_kernel1, dim3(num_blocks, B*NH), block_size, dpreatt, datt, att, B, T, C, NH);
__ldg (test_web_transpose.cu:68)
58 B[ny * N + nx] = A[nx * N + ny];
59 }
60}
61
62__global__ void transpose3(const real *A, real *B, const int N)
63{
64 const int nx = blockIdx.x * blockDim.x + threadIdx.x;
65 const int ny = blockIdx.y * blockDim.y + threadIdx.y;
66 if (nx < N && ny < N)
67 {
68 B[ny * N + nx] = __ldg(&A[nx * N + ny]);
69 }
70}
71
72// CPU reference: B is the transpose of the N x N matrix A.
73static bool verify_transpose(const std::vector<real> &A, const std::vector<real> &B, int N)
74{
75 for (int i = 0; i < N; i++)
76 for (int j = 0; j < N; j++)
77 if (B[i * N + j] != A[j * N + i]) return false;
78 return true;
79}
__mul24 (test_web_cs_convtexture.cu:52)
42 if (e != cudaSuccess) {
43 std::printf("CUDA error in %s: %s\n", what, cudaGetErrorString(e));
44 g_ok = false;
45 }
46}
47
48#define KERNEL_RADIUS 8
49#define KERNEL_LENGTH (2 * KERNEL_RADIUS + 1)
50
51// ---- GPU-specific defines (verbatim) ----------------------------------------
52#define IMAD(a, b, c) (__mul24((a), (b)) + (c))
53#define UNROLL_INNER 1
54
55static inline int iDivUp(int a, int b) { return (a % b != 0) ? (a / b + 1) : (a / b); }
56
57// ---- Convolution kernel storage (verbatim) ----------------------------------
58__constant__ float c_Kernel[KERNEL_LENGTH];
59
60extern "C" void setConvolutionKernel(float* h_Kernel) {
61 cudaMemcpyToSymbol(c_Kernel, h_Kernel, KERNEL_LENGTH * sizeof(float));
62}
__powf (test_web_pcu_intrinsics.cu:70)
60{
61 int i;
62 int tid = (blockDim.x * blockIdx.x) + threadIdx.x;
63
64 if(tid == 0)
65 {
66 float tmp;
67
68 for (i = 0; i < iters; i++)
69 {
70 tmp = __powf(a, 2.0f);
71 }
72
73 *out = tmp;
74 }
75}
76
77int main(int argc, char **argv)
78{
79 (void)argc; (void)argv;
80
81 // [SIM] graceful no-GPU guard (pattern: test_vector_add.cu)
__stcs (test_llmc_attention_backward.cu:480)
470 }
471
472 block_acc[warp.meta_group_rank()] = cg::reduce(warp, local_sum, cg::plus<float>{});
473 block.sync();
474 local_sum = cg::reduce(warp, block_acc[warp.thread_rank()], cg::plus<float>{});
475
476 for (int t3 = block.thread_rank(); t3 <= t; t3 += BlockSize) {
477 // don't touch the cache. Some parts will still be here from the previous loop, and
478 // we want to exploit those.
479 float acc = __ldcs(att_bth + t3) * (__ldcs(datt_bth + t3) - local_sum);
480 __stcs(dpreatt_bth + t3, scale * acc);
481 }
482 }
483}
484
485// ----------------------------------------------------------------------------
486// kernel launchers ([SIM] <<<dim3(...),block>>> -> LAUNCH(kernel, dim3(...), block, ...))
487
488void launch_softmax_1(float* dpreatt, float* datt, const float* att, int B, int T, int C, int NH, int block_size) {
489 int num_blocks = ceil_div(T, block_size);
490 LAUNCH(softmax_autoregressive_backward_kernel1, dim3(num_blocks, B*NH), block_size, dpreatt, datt, att, B, T, C, NH);
491}
__threadfence (test_web_cbe_hashtable.cu:51)
41// [SIM] lock.h, inlined verbatim apart from HANDLE_ERROR staying local.
42struct Lock {
43 int* mutex;
44 Lock() {
45 HANDLE_ERROR(cudaMalloc((void**)&mutex, sizeof(int)));
46 HANDLE_ERROR(cudaMemset(mutex, 0, sizeof(int)));
47 }
48 __device__ void lock() {
49 while (atomicCAS(mutex, 0, 1) != 0);
50 __threadfence();
51 }
52 __device__ void unlock() {
53 __threadfence();
54 atomicExch(mutex, 0);
55 }
56};
57
58#define SIZE (64 * 1024) // [SIM] was 100*1024*1024
59#define ELEMENTS (SIZE / sizeof(unsigned int))
60#define HASH_ENTRIES 1024
__umul24 (test_web_cs_simpletexture3d.cu:57)
47 g_ok = false;
48 }
49}
50
51cudaArray* d_volumeArray = 0;
52cudaTextureObject_t tex; // 3D texture
53
54// ---- verbatim kernel from the sample ---------------------------------------
55__global__ void d_render(uint* d_output, uint imageW, uint imageH, float w,
56 cudaTextureObject_t texObj) {
57 uint x = __umul24(blockIdx.x, blockDim.x) + threadIdx.x;
58 uint y = __umul24(blockIdx.y, blockDim.y) + threadIdx.y;
59
60 float u = x / (float)imageW;
61 float v = y / (float)imageH;
62 // read from 3D texture
63 float voxel = tex3D<float>(texObj, u, v, w);
64
65 if ((x < imageW) && (y < imageH)) {
66 // write output color
67 uint i = __umul24(y, imageW) + x;
68 d_output[i] = voxel * 255;
rsqrtf (test_web_pk_nbody.cu:44)
34 __shared__ float3 shared_position[BLOCK_SIZE];
35 float4 temp_position = p[tile * blockDim.x + threadIdx.x];
36 shared_position[threadIdx.x] = make_float3(temp_position.x, temp_position.y, temp_position.z);
37 __syncthreads();
38
39 for (int j = 0; j < BLOCK_SIZE; j++) {
40 float dx = shared_position[j].x - p[i].x;
41 float dy = shared_position[j].y - p[i].y;
42 float dz = shared_position[j].z - p[i].z;
43 float distSqr = dx*dx + dy*dy + dz*dz + SOFTENING;
44 float invDist = rsqrtf(distSqr);
45 float invDist3 = invDist * invDist * invDist;
46
47 Fx += dx * invDist3; Fy += dy * invDist3; Fz += dz * invDist3;
48 }
49 __syncthreads();
50 }
51
52 v[i].x += dt*Fx; v[i].y += dt*Fy; v[i].z += dt*Fz;
53 }
54}