2

I'm using the following configuration: CUDA 11.4, CMake 3.21.3, Visual Studio 16.11.5, Windows 10.

I've used CMake to successfully generate a VS2019 solution. Here's the CMakeLists.txt file in its entirety (also found here):

cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
project(cmake_and_cuda LANGUAGES CXX CUDA)

include(CTest)

add_library(particles STATIC
  randomize.cpp
  randomize.h
  particle.cu
  particle.h
  v3.cu
  v3.h
  )

# Request that particles be built with -std=c++11
# As this is a public compile feature anything that links to particles
# will also build with -std=c++11
target_compile_features(particles PUBLIC cxx_std_11)

# We need to explicitly state that we need all CUDA files in the particle
# library to be built with -dc as the member functions could be called by
# other libraries and executables
set_target_properties( particles
                       PROPERTIES CUDA_SEPARABLE_COMPILATION ON
                      )

if(BUILD_TESTING)

  add_executable(particle_test test.cu)

  set_target_properties(particle_test PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
  target_link_libraries(particle_test PRIVATE particles)

  add_test(NAME particles_10k COMMAND particle_test 10000 )
  add_test(NAME particles_256k COMMAND particle_test 256000 )

  if(APPLE)
    # We need to add the default path to the driver (libcuda.dylib) as an rpath,
    # so that the static cuda runtime can find it at runtime.
    set_property(TARGET particle_test PROPERTY BUILD_RPATH ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
  endif()
endif()

When I try to build the solution, it fails. Looking at the output, I get the following error: nvcc fatal : A single input file is required for a non-link phase when an outputfile is specified. This is one of the nvcc commands it tried to run:

"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\bin\nvcc.exe"
-gencode=arch=compute_52,code=\"compute_52,compute_52\"
-gencode=arch=compute_52,code=\"sm_52,compute_52\"
--use-local-env
-ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64"
-x cu
-rdc=true
-I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\include"
--keep-dir x64\Debug
-maxrregcount=0
--machine 64
--compile
-cudart static
-std=c++14
-Xcompiler="/EHsc -Zi -Ob0" -g  -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\""
-D_MBCS -DWIN32 -D_WINDOWS -D"CMAKE_INTDIR=\"Debug\""
-Xcompiler "/EHsc /W3 /nologo /Od /Fd"C:\Users\firstname lastname\Documents\Github\code-samples\posts\cmake\build\Debug\particles.pdb" /FS /Zi /RTC1 /MDd /GR"
-o particles.dir\Debug\particle.obj
"C:\Users\firstname lastname\Documents\Github\code-samples\posts\cmake\particle.cu"

I can't quite tell, but I think it's having a hard time with the nested quotes in the second -Xcompiler option.

Is there anything wrong with the CMakeLists.txt file? Does this nvcc command look right? Why does nvcc think I'm trying to give it multiple input files?

Justin
  • 1,881
  • 4
  • 20
  • 40

1 Answers1

2

So, it looks like that's a CMake bug that OP has now filed: issue 22786.

einpoklum
  • 118,144
  • 57
  • 340
  • 684