yuqli
yuqli

Reputation: 5171

CMake cannot find CUDA: "Could not find cmake module file: CMakeDetermineCUDACompiler.cmake"

I'm trying to write a CMake file which needs cuda functionalities. Consulting this answer, I added this line to my CMakeLists.txt:

set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.2/bin/nvcc)

But when using cmake command it still complains:

yuqiong@yuqiong-G7-7588:/media/yuqiong/DATA/alexnet/src/cpp/train$ cmake .
CMake Error: Could not find cmake module file: CMakeDetermineCUDACompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CUDA_COMPILER_ENV_VAR
CMake Error: Could not find cmake module file: /media/yuqiong/DATA/alexnet/src/cpp/train/CMakeFiles/3.5.1/CMakeCUDACompiler.cmake
CMake Error: Could not find cmake module file: CMakeCUDAInformation.cmake
CMake Error: Could not find cmake module file: CMakeTestCUDACompiler.cmake
-- Configuring incomplete, errors occurred!
See also "/media/yuqiong/DATA/alexnet/src/cpp/train/CMakeFiles/CMakeOutput.log".

Which seems confusing, as I don't know where else to set the environment variable? Any idea why the set command does not help cmake find the nvcc compiler?

Just in case helpful, here is my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.2/bin/nvcc)

project(train LANGUAGES CXX CUDA)

set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )


add_executable(train train.cu)
target_link_libraries( train ${OpenCV_LIBS} )

Upvotes: 0

Views: 6007

Answers (2)

yuqli
yuqli

Reputation: 5171

For anyone stumbled upon this question, here is the final CMakeLists.txt file I've used:

cmake_minimum_required(VERSION 3.5.1)
set(CMAKE_CUDA_COMPILER  /usr/local/cuda-9.2/bin/nvcc)

project(train)
include(FindCUDA)

set(CMAKE_CXX_STANDARD 14)
find_package( OpenCV REQUIRED )
find_package(CUDA REQUIRED)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -gencode arch=compute_30,code=sm_30)

include_directories( ${OpenCV_INCLUDE_DIRS} )

cuda_add_executable(train train.cu)
target_link_libraries( train ${OpenCV_LIBS} )

Upvotes: 1

Matthieu Brucher
Matthieu Brucher

Reputation: 22043

Actually, you need CMake 3.8 on Linux to use project(train LANGUAGES CUDA). Before, you need the old way with:

FindPackage(CUDA)

And manually add the libraries.

The failure is because there is no native support for CUDA in your CMake version, use the old method.

Upvotes: 2

Related Questions