cmake config_error ai_generated true

CMake Error: CUDA_ARCHITECTURES is empty for target "mycudatarget"

ID: cmake/cuda-architectures-empty

Also available as: JSON · Markdown · 中文
90%Fix Rate
88%Confidence
1Evidence
2023-12-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CMake 3.18 active
CMake 3.19 active
CMake 3.20 active

Root Cause

CMake 3.18+ requires CUDA_ARCHITECTURES to be set for all CUDA-enabled targets; an empty value or unset variable triggers this error to prevent unsupported architecture code.

generic

中文

CMake 3.18+ 要求为所有启用 CUDA 的目标设置 CUDA_ARCHITECTURES;空值或未设置变量会触发此错误,以防止不支持的架构代码。

Official Documentation

https://cmake.org/cmake/help/latest/prop_tgt/CUDA_ARCHITECTURES.html

Workarounds

  1. 90% success set_target_properties(mycudatarget PROPERTIES CUDA_ARCHITECTURES "75;80") # Or use the native arch detection: set(CMAKE_CUDA_ARCHITECTURES "native")
    set_target_properties(mycudatarget PROPERTIES CUDA_ARCHITECTURES "75;80")
    # Or use the native arch detection:
    set(CMAKE_CUDA_ARCHITECTURES "native")
  2. 85% success set(CMAKE_CUDA_ARCHITECTURES "75;80") add_library(mycudatarget CUDA mycuda.cu)
    set(CMAKE_CUDA_ARCHITECTURES "75;80")
    add_library(mycudatarget CUDA mycuda.cu)

中文步骤

  1. set_target_properties(mycudatarget PROPERTIES CUDA_ARCHITECTURES "75;80")
    # Or use the native arch detection:
    set(CMAKE_CUDA_ARCHITECTURES "native")
  2. set(CMAKE_CUDA_ARCHITECTURES "75;80")
    add_library(mycudatarget CUDA mycuda.cu)

Dead Ends

Common approaches that don't work:

  1. 100% fail

    CMake interprets OFF as an empty string, still triggering the error.

  2. 100% fail

    An empty string is still empty; CMake requires a non-empty list of architectures.