我正在关注 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
时,它会按预期编译和执行。
问题:
- 为什么我编译这段微不足道的代码会失败?
最佳答案
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/