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

ld cannot find related library when build cuda program #5317

Closed
ArberSephirotheca opened this issue Jul 8, 2024 · 5 comments
Closed

ld cannot find related library when build cuda program #5317

ArberSephirotheca opened this issue Jul 8, 2024 · 5 comments
Labels
Milestone

Comments

@ArberSephirotheca
Copy link

Xmake Version

xmake v2.9.3+20240703

Operating System Version and Architecture

Ubuntu 22.04, Arm64

Describe Bug

When I tried to build cuda program with xmake, the linker cannot find the related library during linking.

/usr/bin/ld: cannot find -lcudart_static: No such file or directory
/usr/bin/ld: cannot find -lcudadevrt: No such file or directory

It turns out that in arm64 architecture, the cuda libraries are stored under /usr/local/cuda/lib64 instead of /usr/local/cuda/lib.
but the rpath is pointed to the later path by default, making linker unable to find the library.

Expected Behavior

The cuda program should be built successfully.

Project Configuration

add_rules("mode.debug", "mode.release")

set_languages("c++17")
set_warnings("all")
set_optimize("fastest")

add_requires("benchmark")

-- Kernels to benchmark 
target("cuda-kernels")
    set_kind("static")
    add_includedirs("$(projectdir)/include")
    add_files("src/RGBAConverter.cu")
    add_cugencodes("native")

target("bench-sycl")
    set_kind("binary")
    add_includedirs("$(projectdir)/include")
    add_files("src/main.cu")
    add_cugencodes("native")
    add_packages("benchmark")
    add_packages("oneDPL")
    add_deps("cuda-kernels")

Additional Information and Error Logs

 xmake -v
[ 87%]: linking.release bench-sycl
/usr/bin/g++ -o build/linux/arm64-v8a/release/bench-sycl build/.objs/bench-sycl/linux/arm64-v8a/release/src/main.cu.o build/.objs/bench-sycl/linux/arm64-v8a/release/rules/cuda/devlink/bench-sycl_gpucode.cu.o -L/usr/local/cuda/lib -Lbuild/linux/arm64-v8a/release -Wl,-rpath=/usr/local/cuda/lib -s -lbenchmark -lcuda-kernels -lcudart_static -lrt -lpthread -ldl -lcudadevrt
/usr/bin/ld: cannot find -lcudart_static: No such file or directory
/usr/bin/ld: cannot find -lcudadevrt: No such file or directory
collect2: error: ld returned 1 exit status
error: execv(/usr/bin/g++ -o build/linux/arm64-v8a/release/bench-sycl build/.objs/bench-sycl/linux/arm64-v8a/release/src/main.cu.o build/.objs/bench-sycl/linux/arm64-v8a/release/rules/cuda/devlink/bench-sycl_gpucode.cu.o -L/usr/local/cuda/lib -Lbuild/linux/arm64-v8a/release -Wl,-rpath=/usr/local/cuda/lib -s -lbenchmark -lcuda-kernels -lcudart_static -lrt -lpthread -ldl -lcudadevrt) failed(1)
@waruqi
Copy link
Member

waruqi commented Jul 9, 2024

try this patch. #5319

xmake update -s github:xmake-io/xmake#cuda

@ArberSephirotheca
Copy link
Author

@waruqi Thanks for the help! That patch does not fix, I tried to change the line 108 to

    elseif is_host("linux") and is_arch("x86_64", "arm64-v8a") then

It fixes the problem.

@waruqi
Copy link
Member

waruqi commented Jul 10, 2024

Strange, why would it be arm64-v8a?

Can you run

xmake l os.arch
uname -a
xmake f -cvD
xmake -rv

and provide all logs? I need to check your machine arch.

@waruqi
Copy link
Member

waruqi commented Jul 10, 2024

try it again, I have fixed arm64 arch name. #5319

@waruqi waruqi added this to the v2.9.4 milestone Jul 10, 2024
@ArberSephirotheca
Copy link
Author

@waruqi The problem now is resolved. Thanks!

waruqi added a commit that referenced this issue Jul 10, 2024
improve to find cuda for linux arm64 #5317
@waruqi waruqi closed this as completed Jul 10, 2024
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

2 participants