compiler-errors - CUDA 在编译期间无法识别 nvcuda 命名空间

标签 compiler-errors compilation cuda

我正在关注 CUDA tutorial关于使用 V100 张量核心。我的 MWE 代码:

$ cat src/wmma.cu
#include <cuda_runtime_api.h>
#include <mma.h>
using namespace nvcuda;
int main(void){
    return 0;
} 

用CUDA 9.0编译,

$ nvcc src/wmma.cu
src/wmma.cu(10): error: name must be a namespace name

1 error detected in the compilation of "/gpfs0/scratch/1430008/tmpxft_0002054c_00000000-8_wmma.cpp1.ii".

如果我添加选项 --gpu-architecture=compute_62,我仍然会遇到同样的错误。 CPATH 设置为 /opt/cuda/9.0/include:,因此我相信我可以轻松找到头文件。

当我注释掉 using namespace nvcuda 时,它会按预期编译和执行。

问题:

  1. 为什么我编译这段微不足道的代码会失败?

最佳答案

Why is my compilation of this trivial code failing?

因为你必须指定一个支持这些特性的编译架构,否则它们是未定义的:

$ cat nvnvnv.cu 
#include <cuda_runtime_api.h>
#include <mma.h>
using namespace nvcuda;
int main(void){
    return 0;
} 


$ nvcc nvnvnv.cu 
nvnvnv.cu(3): error: name must be a namespace name

1 error detected in the compilation of "/tmp/tmpxft_00005444_00000000-8_nvnvnv.cpp1.ii".

在我使用的编译器 (CUDA 9.2) 上,默认编译架构是 sm_30。指定正确的架构会使错误消失:

$ nvcc -arch=sm_70 nvnvnv.cu 

$

向您介绍(非常有用的)CUDA tag wiki :

If you are finding that you are getting syntax errors on CUDA keywords when compiling device code, make sure you are compiling using nvcc and that your source file has the expected .cu extension. If you find that CUDA device functions or feature namespaces you expect to work are not found (atomic functions, warp voting functions, half-precision arithmetic, cooperative groups, etc.), ensure that you are explicitly passing compilation arguments which enable architecture settings which support those features.

关于compiler-errors - CUDA 在编译期间无法识别 nvcuda 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53634287/

相关文章:

C STRUCT strcopy EASY BEGINNER PROGRAM - 无法修复编译错误

python - 这些networkx错误表示在 Pandas 数据帧上设置过滤器后得到什么?

python - 是否可以编译用 Python 编写的程序?

image - Cuda 图像平均滤波器

c++ - 程序不会编译

c - 高科技C编译器: #define: "taking the address of this object is illegal"

compilation - Caffe 用 cudnn 编译得很好,但是 runtest 失败,错误 : CUDNN_STATUS_ARCH_MISMATCH

c - 编译器中哪个函数负责接受main()的返回值

windows-7 - 在没有显卡的情况下编程 CUDA?有(好的)模拟器吗?

c++ - 计算数组 CUDA 中的值