Texture fetches#
Integer fetch into a linear resource: no addressing, no filtering (real tex1Dfetch is the same).
Defined in code/simulator.h.
This page documents 7 symbols: 7 functions.
Functions#
Signature |
Description |
Availability |
Location |
Example |
|---|---|---|---|---|
|
Linear filtering is modelled only for a float return type (real hardware also only filters into floats); everything else is point-sampled. |
sim only |
simulator.h:3167 |
|
|
sim only |
simulator.h:3155 |
||
|
Integer fetch into a linear resource: no addressing, no filtering (real tex1Dfetch is the same). |
sim only |
simulator.h:3117 |
|
|
sim only |
simulator.h:3159 |
||
|
sim only |
simulator.h:3183 |
||
|
Denormalise the caller’s coordinates into texel space if the texture object was created with normalizedCoords. |
sim only |
simulator.h:3140 |
|
|
sim only |
simulator.h:3148 |
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.
constexpr (test_llmc_matmul_backward_bias.cu:392)
382 for (int k = block_d; k < x128::size; k += blockDim.z) {
383 float a = 0.f;
384 for (int r = warp_d; r < blockDim.z; r += bdx) {
385 float v = sub_results[k][r][warp_c];
386 v += __shfl_down_sync(0xffffffff, v, 1, 4);
387 v += __shfl_down_sync(0xffffffff, v, 2, 4);
388 a += v;
389 }
390 if(warp_d == 0 && global_oc < OC) {
391 // coalesced, but not cacheline-sized
392 if constexpr (!Atomic) {
393 dbias[global_oc + k] = (OutFloat)(a + (float)dbias[global_oc + k]);
394 } else {
395 atomicAdd(dbias + global_oc + k, a);
396 }
397 }
398 }
399}
400
401// Like kernel 8, but instead of accumulating to the auxiliary buffer, it writes
402// multiple values that need to be summed up in a separate kernel call.
403// If UseAuxBuffer is false, gridDim.y has to be one, and results are added directly
tex2D (test_web_cs_boxfilter.cu:142)
132// ---- texture row pass (verbatim) --------------------------------------------
133// texture fetches automatically clamp to edge of image
134__global__ void d_boxfilter_x_tex(float* od, int w, int h, int r, cudaTextureObject_t tex) {
135 float scale = 1.0f / (float)((r << 1) + 1);
136 unsigned int y = blockIdx.x * blockDim.x + threadIdx.x;
137
138 float t = 0.0f;
139
140 for (int x = -r; x <= r; x++) {
141 t += tex2D<float>(tex, (float)x, (float)y);
142 }
143
144 od[y * w] = t * scale;
145
146 for (int x = 1; x < w; x++) {
147 t += tex2D<float>(tex, (float)(x + r), (float)y);
148 t -= tex2D<float>(tex, (float)(x - r - 1), (float)y);
149 od[y * w + x] = t * scale;
150 }
151}
tex3D (test_web_cs_simpletexture3d.cu:63)
53// ---- verbatim kernel from the sample ---------------------------------------
54__global__ void d_render(uint* d_output, uint imageW, uint imageH, float w,
55 cudaTextureObject_t texObj) {
56 uint x = __umul24(blockIdx.x, blockDim.x) + threadIdx.x;
57 uint y = __umul24(blockIdx.y, blockDim.y) + threadIdx.y;
58
59 float u = x / (float)imageW;
60 float v = y / (float)imageH;
61 // read from 3D texture
62 float voxel = tex3D<float>(texObj, u, v, w);
63
64 if ((x < imageW) && (y < imageH)) {
65 // write output color
66 uint i = __umul24(y, imageW) + x;
67 d_output[i] = voxel * 255;
68 }
69}
70
71// ---- host setup, from the sample's initCuda() -------------------------------
72static void initCuda(const VolumeType* h_volume, cudaExtent volumeSize) {
73 cudaChannelFormatDesc channelDesc = cudaCreateChannelDesc<VolumeType>();