Skip to content

在使用 Clang 编译 CUDA 文件时无法检测 flags #7077

@OpportunityLiu

Description

@OpportunityLiu

Xmake 版本

3.0.5+20251129

操作系统版本和架构

ubuntu 20.04

描述问题

使用 clang-18 / CUDA-12.9

所有 flags 检测失败,单独运行检测指令输出如下:

root@38dcb593c78d:/app/app/app# clang "-fdiagnostics-color=always" "-Qunused-arguments" "--cuda-path=/usr/local/cuda" src/main.cu -o main.o -c -S
clang: warning: CUDA version is newer than the latest supported version 12.3 [-Wunknown-cuda-version]
clang: error: cannot specify -o when generating multiple output files
clang: error: GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda is ; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'

期待的结果

可以正常检测

考虑检测 *.cu 时移除 -S 并为 CUDA>=12 添加 --cuda-gpu-arch=sm_75

工程配置

xmake create -l cuda 创建的默认工程,修改 xmake.lua 使用 clang 编译

add_rules("mode.debug", "mode.release")
set_toolchains("clang")
set_toolset("cu", "clang")

target("app")
    set_kind("binary")
    add_files("src/*.cu")

    -- generate SASS code for SM architecture of current host
    add_cugencodes("native")

    -- generate PTX code for the virtual architecture to guarantee compatibility
    add_cugencodes("compute_35")

    -- -- generate SASS code for each SM architecture
    -- add_cugencodes("sm_35", "sm_37", "sm_50", "sm_52", "sm_60", "sm_61", "sm_70", "sm_75")

    -- -- generate PTX code from the highest SM architecture to guarantee forward-compatibility
    -- add_cugencodes("compute_75")

附加信息和错误日志

root@38dcb593c78d:/app/app/app# xmake -rvD -P .
checking for platform ... linux
checking for architecture ... x86_64
checking for gcc ... /usr/bin/gcc
checkinfo: cannot runv(nim --version), No such file or directory
checking for nim ... no
checking for Cuda SDK directory ... /usr/local/cuda
checking for clang ... /usr/bin/clang
checking for nvcc ... /usr/local/cuda/bin/nvcc
checking for cuda devices
checking for flags (-fPIC) ... no
> clang "-fPIC" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: clang: warning: CUDA version is newer than the latest supported version 12.3 [-Wunknown-cuda-version]
clang: error: cannot specify -o when generating multiple output files
clang: error: GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda is ; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1125]:
    [@programdir/core/sandbox/modules/os.lua:273]: in function 'runv'
    [@programdir/modules/core/tools/gcc/has_flags.lua:43]:
checking for flags (-O3) ... ok
> clang "-O3" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
checking for flags (--cuda-gpu-arch=sm_35) ... no
> clang "--cuda-gpu-arch=sm_35" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: clang: warning: CUDA version is newer than the latest supported version 12.3 [-Wunknown-cuda-version]
clang: error: cannot specify -o when generating multiple output files
clang: error: GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda is ; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1125]:
    [@programdir/core/sandbox/modules/os.lua:273]: in function 'runv'
    [@programdir/modules/core/tools/gcc/has_flags.lua:43]:
checking for flags (-DNDEBUG) ... ok
> clang "-DNDEBUG" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
[ 19%]: compiling.release src/main.cu
clang -c -Qunused-arguments --cuda-path=/usr/local/cuda -fvisibility=hidden -O3 -I/usr/local/cuda/include -m64 -fcuda-rdc -DNDEBUG -o build/.objs/app/linux/x86_64/release/src/main.cu.o src/main.cu
checking for flags (-MMD -MF) ... ok
> clang "-MMD" "-MF" "/dev/null" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
checking for flags (-fdiagnostics-color=always) ... no
> clang "-fdiagnostics-color=always" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
checkinfo: @programdir/core/sandbox/modules/os.lua:273: clang: warning: CUDA version is newer than the latest supported version 12.3 [-Wunknown-cuda-version]
clang: error: cannot specify -o when generating multiple output files
clang: error: GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda is ; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'

stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1125]:
    [@programdir/core/sandbox/modules/os.lua:273]: in function 'runv'
    [@programdir/modules/core/tools/gcc/has_flags.lua:43]:
checking for flags (-fcolor-diagnostics) ... ok
> clang "-fcolor-diagnostics" "-Qunused-arguments" "--cuda-path=/usr/local/cuda"
error: @programdir/core/main.lua:274: @programdir/actions/build/main.lua:161: @programdir/modules/async/runjobs.lua:261: @programdir/modules/private/action/build/object.lua:100: @programdir/modules/core/tools/gcc.lua:1047: clang: warning: CUDA version is newer than the latest supported version 12.3 [-Wunknown-cuda-version]
clang: error: GPU arch sm_35 is supported by CUDA versions between 7.0 and 11.8 (inclusive), but installation at /usr/local/cuda is ; use '--cuda-path' to specify a different CUDA install, pass a different GPU arch with '--cuda-gpu-arch', or pass '--no-cuda-version-check'
stack traceback:
    [C]: in function 'error'
    [@programdir/core/base/os.lua:1125]:
    [@programdir/modules/core/tools/gcc.lua:1047]: in function 'catch'
    [@programdir/core/sandbox/modules/try.lua:123]: in function 'try'
    [@programdir/modules/core/tools/gcc.lua:988]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:260]:
    [@programdir/core/tool/compiler.lua:285]: in function 'compile'
    [@programdir/modules/private/action/build/object.lua:100]: in function 'script'
    [@programdir/modules/private/action/build/object.lua:131]: in function 'build_object'
    [@programdir/modules/private/action/build/object.lua:171]: in function 'job_func'
    [@programdir/modules/async/runjobs.lua:432]:
    [C]: in function 'xpcall'
    [@programdir/core/base/utils.lua:260]: in function 'trycall'
    [@programdir/core/sandbox/modules/try.lua:117]: in function 'try'
    [@programdir/modules/async/runjobs.lua:401]: in function 'cotask'
    [@programdir/core/base/scheduler.lua:514]:

stack traceback:
        [C]: in function 'error'
        @programdir/core/base/os.lua:1125: in function 'base/os.raiselevel'
        (...tail calls...)
        @programdir/core/main.lua:274: in upvalue 'cotask'
        @programdir/core/base/scheduler.lua:514: in function <@programdir/core/base/scheduler.lua:507>
warning: failed to find cuda devices: cudaErrorInsufficientDriver (CUDA driver version is insufficient for CUDA runtime version)
warning: add_cuflags("--cuda-gpu-arch=sm_35") is ignored, please pass `{force = true}` or call `set_policy("check.auto_ignore_flags", false)` if you want to set it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions