【问题标题】:CUDA Error on cudaBindTexturecudaBindTexture 上的 CUDA 错误
【发布时间】:2013-06-13 14:50:11
【问题描述】:

我遇到了与帖子中描述的完全相同的问题: CUDA Error on cudaBindTexture2D

我什至有以下错误:

错误 18:无效的纹理参考。”并且还遇到了“不会 在 cudaMalloc 上抛出错误,但仅限于 cudaBindTexture

不幸的是,发帖人 (Anton Roth) 回答他自己的问题的方式对于像我这样刚开始使用 CUDA 的人来说有点过于神秘:

答案在 cmets 中,我使用了我的 GPU 没有的 sm 兼容。

“与 GPU 不兼容”是有道理的,因为示例程序 FluidsGL(在 NVIDIA CUDA 示例浏览器中称为“Fluids(OpenGL 版本)”)在我的笔记本电脑上失败,但在我的工作桌面上运行良好。不幸的是,我仍然不知道“in the cmets”指的是什么,甚至不知道如何检查 GPU SM 兼容性。

这是似乎导致问题的代码:

#define DIM 512

main:

setupTexture(DIM, DIM);
bindTexture();

fluidsGL_kernels.cu:

texture<float2, 2> texref;
static cudaArray *array = NULL;

void setupTexture(int x, int y)
{
    // Wrap mode appears to be the new default
    texref.filterMode = cudaFilterModeLinear;
    cudaChannelFormatDesc desc = cudaCreateChannelDesc<float2>();

    cudaMallocArray(&array, &desc, y, x);
    getLastCudaError("cudaMalloc failed");
}

void bindTexture(void)
{
    cudaBindTextureToArray(texref, array);//this function itself doesn't throw the error but error 18 is caught by the function below
    getLastCudaError("cudaBindTexture failed");
}

硬件信息

这是deviceQuery的输出:

Device 0: "GeForce 9800M GS"
  CUDA Driver Version / Runtime Version          5.0 / 5.0
  CUDA Capability Major/Minor version number:    1.1
  Total amount of global memory:                 1024 MBytes (1073741824 bytes)
  ( 8) Multiprocessors x (  8) CUDA Cores/MP:    64 CUDA Cores
  GPU Clock rate:                                1325 MHz (1.32 GHz)
  Memory Clock rate:                             799 Mhz
  Memory Bus Width:                              256-bit
  Max Texture Dimension Size (x,y,z)             1D=(8192), 2D=(65536,32768), 3D
=(2048,2048,2048)
  Max Layered Texture Size (dim) x layers        1D=(8192) x 512, 2D=(8192,8192)
 x 512
  Total amount of constant memory:               65536 bytes
  Total amount of shared memory per block:       16384 bytes
  Total number of registers available per block: 8192
  Warp size:                                     32
  Maximum number of threads per multiprocessor:  768
  Maximum number of threads per block:           512
  Maximum sizes of each dimension of a block:    512 x 512 x 64
  Maximum sizes of each dimension of a grid:     65535 x 65535 x 1
  Maximum memory pitch:                          2147483647 bytes
  Texture alignment:                             256 bytes
  Concurrent copy and kernel execution:          Yes with 1 copy engine(s)
  Run time limit on kernels:                     Yes
  Integrated GPU sharing Host Memory:            No
  Support host page-locked memory mapping:       Yes
  Alignment requirement for Surfaces:            Yes
  Device has ECC support:                        Disabled
  CUDA Device Driver Mode (TCC or WDDM):         WDDM (Windows Display Driver Mo
del)
  Device supports Unified Addressing (UVA):      No
  Device PCI Bus ID / PCI location ID:           8 / 0
  Compute Mode:
     < Default (multiple host threads can use ::cudaSetDevice() with device simu
ltaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 5.0, CUDA Runtime Versi
on = 5.0, NumDevs = 1, Device0 = GeForce 9800M GS

我知道我的 GPU 有点老了,但它仍然可以很好地运行大多数示例。

【问题讨论】:

  • 你有一个 CC 1.1 GPU(参见这条线CUDA Capability Major/Minor version number)。主要问题是:你是如何编译你的代码的?你能粘贴你使用的命令吗?你在用-gencode arch=compute_11,code=sm_11吗?此外,fluidsGL 应该可以在您的硬件上正常运行,因为最低 SM 版本显然是 1.0。
  • 它实际上编译得很好(我使用的是 Microsoft Visual Studio 2010 示例项目,未经修改)。预编译的可执行文件与我在笔记本电脑上编译和调试时出现相同的错误,但在桌面上运行良好。
  • 类似的东西连续两次以稍微不同的形式出现:-gencode=arch=compute_20,code=\"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30 \"
  • 在编译过程中你不会看到任何错误,只有在执行过程中。如果你阅读nvcc的帮助(nvcc --help),你会看到-code用于指定nVidia gpus的名称以生成代码-arch用于指定必须为其编译 cuda 输入文件的 nVidia GPU 架构类的名称。如果您没有设置正确的架构,则在 GPU 不足的情况下运行代码时可能会发生错误。如果你只编译 compute/sm_20compute/sm_30,你的代码将在你的 GPU 上失败(因此我的第一条评论)。
  • 缩短:"...\5_Simulations\fluidsGLfromwork>"...\NVIDIA GPU Computing Toolkit\CUDA\v5.0\bin\nvcc.exe" -gencode=arch=compute_20,code= \"sm_20,compute_20\" -gencode=arch=compute_30,code=\"sm_30,compute_30\" --use-local-env --cl-version 2010 -ccbin "...Visual Studio 10.0\VC\bin" -I"./" -I"../../common/inc" -I"./" -I"../../common/inc" -I"...\CUDA\v5.0 \include" -I"...\CUDA\v5.0\include" -G --keep-dir "调试" -maxrregcount=0 --machine 32 --compile -g -DWIN32 -DWIN32 -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MTd " -o "Win32/Debug/fluidsGL_kernels.cu.obj" "...\fluidsGL_kernels.cu"

标签: cuda


【解决方案1】:

您需要为正确的架构编译代码(如您链接的帖子中所述)。

由于您拥有 CC 1.1 设备,请使用以下 nvcc 编译选项:

-gencode arch=compute_11,code=sm_11

默认的 Visual Studio 项目或 Makefile 可能无法针对正确的体系结构进行编译,因此请务必确保这样做。

对于 Visual Studio,请参考这个答案:https://stackoverflow.com/a/14413360/1043187

对于 Makefile,这取决于。 CUDA SDK 示例通常有一个您可以修改的GENCODE_FLAGS 变量。

【讨论】:

    猜你喜欢
    • 2016-03-06
    • 1970-01-01
    • 2017-09-27
    • 1970-01-01
    • 1970-01-01
    • 2013-04-12
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多