【问题标题】:CMake doesn't pass CUDA arguments?CMake 不传递 CUDA 参数?
【发布时间】:2018-03-01 13:26:55
【问题描述】:

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

CMake 版本为 3.9.0 clang 版本是 3.8.1

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

不幸的是,CMake 对 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)

【问题讨论】:

    标签: cmake cuda clang


    【解决方案1】:

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

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

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

    这应该允许 CMake 将您的标志传递给 NVCC。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-11
      • 2017-04-15
      • 2023-04-05
      • 2015-09-14
      • 1970-01-01
      • 2019-12-07
      • 1970-01-01
      相关资源
      最近更新 更多