0

我已经设置了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));

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

像这样的东西:

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

1 回答 1

2

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

你可以在这里阅读更多关于它们的使用。

于 2017-01-25T18:13:55.373 回答