【问题标题】:Pass cuda texture variable as an argument将 cuda 纹理变量作为参数传递
【发布时间】:2023-04-05 20:03:01
【问题描述】:

我已设置cudaArray,并将其绑定到纹理:

    texture<float, 2, cudaReadModeElementType> tex;
    cudaChannelFormatDesc channelDesc =
        cudaCreateChannelDesc(32, 0, 0, 0, cudaChannelFormatKindFloat);
    cudaArray *cuArray;
    checkCudaErrors(cudaMallocArray(&cuArray,
                                    &channelDesc,
                                    width,
                                    height));
    checkCudaErrors(cudaMemcpyToArray(cuArray,
                                      0,
                                      0,
                                      hData,
                                      size,
                                      cudaMemcpyHostToDevice));

现在我想知道,如果cuArraytex 中的内容在计算过程中一直保持不变,我可以将tex 和/或cuArray 传递给另一个函数,这样我就不会'每次都要绑定吗?

类似这样的:

DoJobUsingTex(float* output, float* input, int size, texture tex)
{
   \\  do something here
}

【问题讨论】:

标签: memory cuda gpu textures cuda-arrays


【解决方案1】:

CUDA 5 和 Kepler 硬件发布时,CUDA 引入了纹理对象。这些是所谓的“无绑定”纹理,可以按值传递给内核,因此每次您想在不同的纹理数据上运行内核时都不需要重新绑定内存。

你可以阅读更多关于他们的使用here

【讨论】:

  • 如果您对读/写功能感兴趣,您可能需要查看 cuda 表面对象。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-23
  • 2018-05-25
  • 2018-02-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多