CMake没有通过CUDA论证?

时间:2017-09-20 13:01:17

标签: cmake cuda clang

我正在尝试使用C ++和CUDA源文件编译库。我在CMake中使用GNU make。我选择的编译器是clang,因为CUDA只支持gcc到版本5,而Debian 9有gcc 6作为其最旧的版本,我必须使用由Debian 9或10存储库提供的软件。

CMake版本是3.9.0 clang版本是3.8.1

/ usr / bin中的cc和c ++正确链接到clang和clang ++ẃhich也链接到正确的文件。

不幸的是,CMake for CUDA的初始检查失败了,尽管我可以看到,所有内容似乎都已正确设置。看起来这些参数没有正确传递给CUDA编译器。

这是我项目的主要CMake文件的一部分:

cmake_minimum_required (VERSION 3.9.0 FATAL_ERROR)

project (dev)

find_package(CUDA REQUIRED)

set(CUDA_HOST_COMPILATION_CPP ON)
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Wno-deprecated-gpu-targets -ccbin clang-3.8")

库的CMake文件如下所示:

cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR)

project (libname LANGUAGES CXX CUDA)

file(GLOB SOURCES "*.cu" "*.cpp")

add_library(libname ${SOURCES})

set_target_properties(libname PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
set_target_properties(libname PROPERTIES POSITION_INDEPENDENT_CODE ON)

这是CMake的输出:

-- The C compiler identification is Clang 3.8.1
-- The CXX compiler identification is Clang 3.8.1
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found CUDA: /usr (found version "8.0") 
-- The CUDA compiler identification is unknown
-- Check for working CUDA compiler: /usr/bin/nvcc
-- Check for working CUDA compiler: /usr/bin/nvcc -- broken

CMake的CUDA / nvcc测试失败,出现以下错误:

  Change Dir: /home/user/projects/hamonIC-linux-experimental/current_state/working_copy/code/build/CMakeFiles/CMakeTmp



  Run Build Command:"/usr/bin/make" "cmTC_6d1a9/fast"

  /usr/bin/make -f CMakeFiles/cmTC_6d1a9.dir/build.make
  CMakeFiles/cmTC_6d1a9.dir/build

  make[1]: Entering directory
  '/home/user/projects/hamonIC-linux-experimental/current_state/working_copy/code/build/CMakeFiles/CMakeTmp'


  Building CUDA object CMakeFiles/cmTC_6d1a9.dir/main.cu.o

  /usr/bin/nvcc -x cu -c
  /home/user/projects/hamonIC-linux-experimental/current_state/working_copy/code/build/CMakeFiles/CMakeTmp/main.cu
  -o CMakeFiles/cmTC_6d1a9.dir/main.cu.o

  nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are
  deprecated, and may be removed in a future release (Use
  -Wno-deprecated-gpu-targets to suppress warning).

  ERROR: No supported gcc/g++ host compiler found, but clang-3.8 is
  available.

         Use 'nvcc -ccbin clang-3.8' to use that instead.

  CMakeFiles/cmTC_6d1a9.dir/build.make:65: recipe for target
  'CMakeFiles/cmTC_6d1a9.dir/main.cu.o' failed

  make[1]: *** [CMakeFiles/cmTC_6d1a9.dir/main.cu.o] Error 1

  make[1]: Leaving directory
  '/home/user/projects/hamonIC-linux-experimental/current_state/working_copy/code/build/CMakeFiles/CMakeTmp'


  Makefile:126: recipe for target 'cmTC_6d1a9/fast' failed

  make: *** [cmTC_6d1a9/fast] Error 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  hic_iplibrary/source/ciccommon/CMakeLists.txt:7 (project)

1 个答案:

答案 0 :(得分:2)

CMake中的CUDA NVCC标志必须以分号分隔,而不是以空格分隔。

更改CMakeLists.txt中的标记以使用:

set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS};-Wno-deprecated-gpu-targets;-ccbin=clang-3.8")

这应该允许CMake将你的旗帜传递给NVCC。