且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何让cmake的CUDA找到

更新时间:2021-07-25 16:12:24

cmake的提到 CUDA_TOOLKIT_ROOT_DIR 作为CMake的变量,而不是环境之一。这就是为什么当你把它变成的.bashrc不工作。如果你看看FindCUDA.cmake它清楚地说:

cmake mentioned CUDA_TOOLKIT_ROOT_DIR as cmake variable, not environment one. That's why it does not work when you put it into .bashrc. If you look into FindCUDA.cmake it clearly says that:

该脚本会提示用户指定CUDA_TOOLKIT_ROOT_DIR如果preFIX
  不能NVCC的位置,在系统路径和要求的确定
  被指定到find_package()。要使用的不同的安装版本
  工具箱设置环境变量CUDA_BIN_PATH运行cmake的前
  (例如CUDA_BIN_PATH =的/ usr /本地/ cuda1.0而不是默认的/ usr /本地/ CUDA)
  或配置之后设置CUDA_TOOLKIT_ROOT_DIR。如果更改的值
  CUDA_TOOLKIT_ROOT_DIR,依赖路径上的各种组件将
  搬迁。

The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if the prefix cannot be determined by the location of nvcc in the system path and REQUIRED is specified to find_package(). To use a different installed version of the toolkit set the environment variable CUDA_BIN_PATH before running cmake (e.g. CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default /usr/local/cuda) or set CUDA_TOOLKIT_ROOT_DIR after configuring. If you change the value of CUDA_TOOLKIT_ROOT_DIR, various components that depend on the path will be relocated.

所以把 CUDA_BIN_PATH 到.bashrc或者指定 CUDA_TOOLKIT_ROOT_DIR 来cmake的:

So put CUDA_BIN_PATH into .bashrc or specify CUDA_TOOLKIT_ROOT_DIR to cmake:

cmake -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-5.5 ..