Cmake 找不到 cuda.h 文件



我的项目只有扩展名为*.cpp或*.h的源文件。但其中一些文件调用cuda主机函数并使用cublas库。使用enable_language(CUDA)后,cmake可以在配置阶段找到nvcc:

-- The CUDA compiler identification is NVIDIA 8.0.61
-- Check for working CUDA compiler: /gpfs/share/software/cuda/cuda-8.0/bin/nvcc
-- Check for working CUDA compiler: /gpfs/share/software/cuda/cuda-8.0/bin/nvcc -- works
-- Detecting CUDA compiler ABI info
-- Detecting CUDA compiler ABI info - done

然而,在编译这些源文件时,我得到了以下错误:

fatal error: cuda.h: No such file or directory

cmake选择的编译器仍然是/usr/bin/c++,而不是nvcc。如何处理这个错误?我必须将这些源文件重命名为.cu.cuh吗?

否,您需要将CUDA标头包含在include_directories()中。应来自CUDA_INCLUDE_DIRS变量。

让C++文件使用CUDA头是完全可以的,但您需要像添加任何其他库一样添加include。

相关内容

最新更新