'CUDA_ARCHITECTURES is empty for target "cmTC_28d80"

I made a new CUDA executable project in CLion and when it opened I got CMake error:

CUDA_ARCHITECTURES is empty for target "cmTC_908f4".

CMakeLists.txt:

cmake_minimum_required(VERSION 3.19)
project(test CUDA)

set(CMAKE_CUDA_STANDARD 14)

add_executable(test main.cu)

set_target_properties(
        test
        PROPERTIES
        CUDA_SEPARABLE_COMPILATION ON)

I tried searching for this error on internet but not much success. I only tried to set

set_target_properties(test PROPERTIES CUDA_ARCHITECTURES "35;50;72")

but that didn't help. At this point I don't know what to do anymore.



Solution 1:[1]

Although I am 9 months late to this, I think I actually solved it. I just stumbled across (what I believe to be) exactly the same problem. It occurred while trying to set up a new CUDA Project in CLion, and I got the same error.

I have now contacted the JetBrains support for CLion, and they pointed me to the solution of this problem.

If you have the same problem, you should see an auto-detected "x86" architecture under "Settings/Preferences > Build, Execution, Deployment > Toolchains > [the toolchain you are using for this project]". Simply manually select "amd64" instead (or, I suppose, whatever arch your system is running on), and then the CMake build should run fine, and a simple Hello World should also compile and run without problems.

Version Data:

  • CLion 2021.3.4
  • CMake 3.21.1 (bundled with CLion)
  • CUDA Toolkit 11.6
  • MSVC 2022 / Version 17.0
  • Windows 11 Pro

Solution 2:[2]

I wonder if the order matters, e.g. set Cuda architecture before compile features. My CMakeLists that works (and didn't before adding the CUDA_ARCHITECTURE line) is:

cmake_minimum_required(VERSION 3.16)
project(myTarget LANGUAGES CXX CUDA)

# Locate sources and headers for this project
include_directories(${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include /usr/local/cuda/include )

file(GLOB sources ${PROJECT_SOURCE_DIR}/*.cc ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/*.h ${PROJECT_SOURCE_DIR}/include/*.h)
file(GLOB cuda_sources ${PROJECT_SOURCE_DIR}/src/*.cu)

# Add the executable, and link 
add_executable(myTarget ${sources} ${cuda_sources} ${headers})
target_link_libraries(myTarget pthread z)

# Compile Info
set_target_properties(myTarget PROPERTIES CUDA_ARCHITECTURES "35;50;72")
target_compile_features(myTarget PUBLIC cxx_std_11)
target_compile_features(myTarget PUBLIC cuda_std_11)

Solution 3:[3]

Try setting your DCMAKE_CUDA_COMPILER as described here: https://www.jetbrains.com/help/clion/cuda-projects.html#set-nvcc - add your nvcc path in settings for CMake. Remember to put full path to executable - not only bin folder

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Raphael Tarita
Solution 2 MiloNC
Solution 3