Use of undeclared identifier ‘cudaSetDevice’
使用 cudaSetDevice(0);
用于指定GPU设备时报错:
Use of undeclared identifier 'cudaSetDevice'
可能是两种情况
1.未包含必要的头文件:
代码中包含了#include <cuda_runtime.h>,这个头文件包含了CUDA运行时库的函数声明,包括cudaSetDevice。
2.未链接CUDA库:
在编译时需要链接CUDA库。在 CMakelists.txt
里面添加:
find_package(CUDA REQUIRED)
include_directories(
${CUDA_INCLUDE_DIRS}
)