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

if constexpr (std::is_floating_point<T>::value)

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

View

inline T tex1D(cudaTextureObject_t obj, float x)

sim only

simulator.h:3155

inline T tex1Dfetch(cudaTextureObject_t obj, int x)

Integer fetch into a linear resource: no addressing, no filtering (real tex1Dfetch is the same).

sim only

simulator.h:3117

inline T tex2D(cudaTextureObject_t obj, float x, float y)

sim only

simulator.h:3159

View

inline T tex3D(cudaTextureObject_t obj, float x, float y, float z)

sim only

simulator.h:3183

View

inline void texDenorm(const TexObj& t, float& fx, float& fy, float& fz, int dims)

Denormalise the caller’s coordinates into texel space if the texture object was created with normalizedCoords.

sim only

simulator.h:3140

inline T texPoint(const TexObj& t, float fx, float fy, float fz, int dims)

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>();