cuda - 使用 cc 更改 Rust 传递给 nvcc 的编译参数

标签 cuda linker rust ffi nvcc

我正在使用 cc 将用 C 编写的 CUDA 内核链接到 Rust。 这是我的 build.rs 文件:

extern crate cc;

fn main() {
    cc::Build::new()
        .cuda(true)
        .flag("-cudart=shared")
        .flag("-gencode")
        .flag("arch=compute_61,code=sm_61")
        .file("kernel/kernel.cu")
        .compile("kernel/kernel.a");
}

我有这个错误:

running: "nvcc" "-ccbin=c++" "-O0" "-Xcompiler" "-ffunction-sections" "-Xcompiler" "-fdata-sections" "-Xcompiler" "-fPIC" "-G" "-Xcompiler" "-g" "-m64" "-Xcompiler" "-Wall" "-Xcompiler" "-Wextra" "-cudart=shared" "-gencode" "arch=compute_61,code=sm_61" "-o" "/home/ltei/Dev/Workspaces/rust_cudnn/target/debug/build/rust_cudnn-df924982e63c2363/out/kernel/kernel.o" "-c" "kernel/kernel.cu" cargo:warning=In file included from /usr/include/cuda_runtime.h:78:0, cargo:warning= from :0: cargo:warning=/usr/include/host_config.h:119:2: error: #error -- unsupported GNU version! gcc versions later than 5 are not supported! cargo:warning= #error -- unsupported GNU version! gcc versions later than 5 are not supported! cargo:warning= ^~~~~ exit code: 1

我知道如果我可以将命令中的 -ccbin=c++ 更改为 -ccbin=clang-3.8 就可以了,但我不知道如何做吧。

我还可以安装另一个版本的 GCC,但我更喜欢第一个解决方案。

最佳答案

您可以将 CXX 环境变量设置为您想要的任何值。

CXX=this-is-my-cpp-compiler cargo build

这将用作 ccbin 的参数:

"nvcc" "-ccbin=this-is-my-cpp-compiler" "-O0" "-Xcompiler" "-ffunction-sections" "-Xcompiler" "-fdata-sections" "-Xcompiler" "-fPIC" "-G" "-Xcompiler" "-g" "-m64" "-Xcompiler" "-Wall" "-Xcompiler" "-Wextra" "-cudart=shared" "-gencode" "arch=compute_61,code=sm_61" "-o" "/private/tmp/c/target/debug/build/c-67ec4fdcff2f35d1/out/kernel/kernel.o" "-c" "kernel/kernel.cu"

关于cuda - 使用 cc 更改 Rust 传递给 nvcc 的编译参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49342835/

相关文章:

visual-studio-2012 - NVLink : error : Undefined reference when trying to write to text file

c++ - CMake 链接到错误版本的库

linker - 如何为自动工具构建配置非标准链接器?

Xcode 有时会删除链接库

python - 与 Python 代码相比,我如何提高 Rust 代码的性能?

rust - 变异和非变异方法链

c++ - 命名空间作为 CUDA 中的模板参数

cuda - 为什么每个线程在warp中都有自己的指令地址计数器?

CUDA HOME 在 pytorch 安装

rust - 如何将以下 from_str 宏更改为 from_json?