首页 文章

关于nvcc使用compute_和sm_ compile选项的错误代码“无效的设备功能”

提问于
浏览
0

我希望你能帮助我找出以下卡片所需的正确编译器选项:

> ./deviceQuery Starting...
> 
>  CUDA Device Query (Runtime API) version (CUDART static linking)
> 
> Detected 1 CUDA Capable device(s)
> 
> Device 0: "GeForce GTX 780 Ti"   
> CUDA Driver Version / Runtime Version 7.0 / 6.5
> CUDA Capability Major/Minor version number:    3.5  
> Total amount of global memory:                 3072 MBytes (3220897792
> bytes)
> (15) Multiprocessors, (192) CUDA Cores/MP:
>     2880 CUDA Cores   
> GPU Clock rate:                                1020 MHz (1.02GHz)
> Memory Clock rate:                             3500 Mhz  
> Memory Bus Width:                              384-bit
> L2 Cache Size:                                 1572864 bytes
...
  Maximum Texture
> Dimension Size (x,y,z)         1D=(65536), 2D=(65536, 65536),
> 3D=(4096, 4096, 4096)   Maximum Layered 1D Texture Size, (num) layers 
> 1D=(16384), 2048 layers   Maximum Layered 2D Texture Size, (num)
> layers  2D=(16384, 16384), 2048 layers   Total amount of constant
> memory:               65536 bytes   Total amount of shared memory per
> block:       49152 bytes   Total number of registers available per
> block: 65536   Warp size:                                     32  
> Maximum number of threads per multiprocessor:  2048   Maximum number
> of threads per block:           1024   Max dimension size of a thread
> block (x,y,z): (1024, 1024, 64)   Max dimension size of a grid size   
> (x,y,z): (2147483647, 65535, 65535)   Maximum memory pitch:           
> 2147483647 bytes   Texture alignment:                             512
> 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   Device supports Unified Addressing (UVA):      Yes   Device
> PCI Bus ID / PCI location ID:           3 / 0   Compute Mode:
>      < Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >
> 
> deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 7.0, CUDA
> Runtime Version = 6.5, NumDevs = 1, Device0 = GeForce GTX 780 Ti
> Result = PASS

我有一块cuda代码并使用nvcc(CUDA 6.5)进行调试 . 当我添加这些选项时:

-arch compute_20 -code sm_20

然后程序给了我这个错误:

错误代码无效的设备功能

如果我删除这些选项(nvcc source -o exe),程序运行正常 . 任何人都可以通过查看./deviceQuery的输出来帮助我找出哪个compute_和sm_适合我的卡?我从nvidia手册中读到,使用compute_和sm_的正确选项可以显着提高卡的速度 . 有没有人在数量上观察到这种加速?

谢谢

1 回答

  • 1

    CUDA中的“无效设备功能”错误通常意味着您编译的GPU架构设置与您运行的GPU不匹配或不兼容 .

    解决此问题的一般过程是在GPU上运行 deviceQuery 示例代码,从输出中确定主要和次要版本的计算能力,并使用它来为GPU选择编译体系结构设置 .

    如果你的GPU是架构计算能力X.Y,那么一个非常简单的选择是:

    -arch=sm_XY
    

    任何人都可以通过查看./deviceQuery的输出来帮助我找出哪个compute_和sm_适合我的卡?

    按照您的示例,GTX 780 Ti的正确设置为:

    -arch compute_35 -code sm_35
    

    以上将生成将在cc3.5设备上运行的代码(仅限) . 我认为最好只指定:

    -arch=sm_35
    

    这是一个稍微复杂的版本的简写:

    -gencode arch=compute_35,code=sm_35 -gencode arch=compute_35,code=compute_35
    

    这将生成将在cc3.5 or newer 设备上运行的代码 . 3.5 / 35数字来自deviceQuery输出中的这一行:

    Capability Major/Minor version number: 3.5
    

    如果您想更好地了解开关选项/差异,建议您查看nvcc manualthis question/answer .

    有关 -arch 开关行为的更多说明,请参见here .

相关问题