Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add_requires("cuda", {configs = {shared = true}}) 编译命令里会同时链接cudart和cudart_static #5855

Open
KkemChen opened this issue Nov 28, 2024 · 6 comments
Labels

Comments

@KkemChen
Copy link
Contributor

Xmake 版本

2.9.6

操作系统版本和架构

Ubuntu20.04

描述问题

在使用 add_requires("cuda", {configs = {shared = true}}),然后add_packages("cuda") 时,编译命令里生成的链接命令 同时链接了动态库和静态库
-lcudart -lcudart_static

I{ X4P_P$N1DB0@J WUOVRC

期待的结果

修复

工程配置

add_requires("cuda", {configs = {shared = true}})

target("test")
-- ......
add_packages("cuda")

附加信息和错误日志

[ 97%]: devlinking.release hmp_gpucode.cu.o
/usr/local/cuda/bin/nvcc -o build/.objs/hmp/linux/x86_64/release/rules/cuda/devlink/hmp_gpucode.cu.o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/tensor_factory.cu.o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/unary_ops.cu.o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/imgproc.cu.o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/binary_ops.cu.o -L/root/.xmake/packages/s/spdlog/v1.8.5/3a3f65b0f20c48c7b6fdfd82308d5423/lib -L/root/.xmake/packages/f/fmt/7.1.3/5cdcf5de2a9347a5812f5aab9e771ee8/lib -L/usr/local/cuda/lib64 -lspdlog -lfmt -lcudart -lcudadevrt -lcudart_static -lrt -lpthread -ldl -lm -m64 -gencode arch=compute_75,code=sm_75 -dlink -shared
@KkemChen KkemChen added the bug label Nov 28, 2024
@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Xmake version

2.9.6

Operating system version and architecture

Ubuntu20.04

Describe the problem

When using add_requires("cuda", {configs = {shared = true}}) and then add_packages("cuda"), the link command generated in the compilation command links both the dynamic library and the static library
-lcudart -lcudart_static

![I{

Expected results

repair

Project configuration

add_requires("cuda", {configs = {shared = true}})

target("test")
--......
add_packages("cuda")

Additional information and error logs

[97%]: devlinking.release hmp_gpucode.cu.o
/usr/local/cuda/bin/nvcc -o build/.objs/hmp/linux/x86_64/release/rules/cuda/devlink/hmp_gpucode.cu.o build/.objs/hmp/linux/x86_64/release/hml /src/kernel/cuda/tensor_factory.cu.o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/unary_ops.cu.o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/imgproc.cu .o build/.objs/hmp/linux/x86_64/release/hml/src/kernel/cuda/binary_ops.cu.o -L/root/.xmake/packages/s/spdlog/v1.8.5/3a3f65b0f20c48c7b6fdfd82308d5423/lib -L/root/.xmake/packages/f/fmt/7.1.3/5cdcf5de2a9347a5812f5aab9e771ee8/lib -L/usr/local/cuda/lib64 -lspdlog -lfmt -lcudart -lcudadevrt -lcudart_static -lrt -lpthread -ldl -lm - m64-gencode arch=compute_75,code=sm_75 -dlink -shared

@star-hengxing
Copy link
Contributor

xmake cuda rule:

local cudart = false
for _, link in ipairs(table.join(target:get("links") or {}, target:get("syslinks"))) do
    if link == "cudart" or link == "cudart_static" then
        cudart = true
        break
    end
end
if not cudart then
    target:add("syslinks", "cudart_static")
end

所以先不要用 add_requires("cuda") ,只需要正常 add_files("**.cu")add_links("") 就行

@KkemChen
Copy link
Contributor Author

是不是 add_files 里面 有 .cu 文件,就会自动添加 add_rules("cuda") 🤔

@star-hengxing
Copy link
Contributor

是不是 add_files 里面 有 .cu 文件,就会自动添加 add_rules("cuda") 🤔

Yes https://github.com/xmake-io/xmake/blob/2c97dacfe8490643fe6c8f488fea72350aa64945/xmake/rules/cuda/xmake.lua#L23

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


Is there a .cu file in add_files, it will automatically add add_rules("cuda") 🤔

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically.


If there is a .cu file in add_files, it will automatically add add_rules("cuda") 🤔

Yes https://github.com/xmake-io/xmake/blob/2c97dacfe8490643fe6c8f488fea72350aa64945/xmake/rules/cuda/xmake.lua#L23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants