-
Notifications
You must be signed in to change notification settings - Fork 74
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
A binary linked against cudart/curand exits immediately shuts down on windows, if no cuda is available on the system #2341
Comments
Hi @ichinii, If yes, then linking dynamically with libcudart.so or statically with libcudart.a is necessary. If you want to build a binary that uses CUDA only if it's available, I think you need to split the functionality in separate shared libraries and load them at runtime, allowing for it to fail if CUDA is not available. This is not specific to Alpaka - though I'm not sure if the Alpaka CMake rules help or hinder in this respect. |
As @fwyzard said to ship a binary that can be executed even if you do not have all CUDA libs available you must provide a coda path for CUDA in a shared library. Take care if you use shared library under windows and you have a singelton in your application the singelton instance in the shared library is not equal to the instance in the main binary. |
Thanks for your advice. At least on linux i am pretty convinced, that a cuda compiled application does not load cuda shared libraries right away, but loads them on demand.
I am hoping that this is the same for windows. |
How did you build By default |
Sorry, long post. Jump to the end if you just want to wrap up on the original concern
// main.cu
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
return 0;
} nvcc main.cu -o try_cuda
I think you are right, that per default, cuda is linked statically. nm try_cuda | grep cuda | head -n 5
9:0000000000057ad0 T cudaArrayGetInfo
10:0000000000057f00 T cudaArrayGetMemoryRequirements
11:0000000000057d10 T cudaArrayGetPlane
12:00000000000582e0 T cudaArrayGetSparseProperties
13:000000000004d3a0 T cudaChooseDevice and libcuda then gets loaded at runtime. Though my guess was right, that it only gets loaded as soon as cuda code is invoked. If the application does not make use of cuda code, then libcuda wont be loaded. I tested this by printing loaded shared libraries at runtime using // audit.cpp
#include <iostream>
#include <link.h>
// ignore this function
unsigned int la_version(unsigned int version) {
if (version == 0) { return version; }
return LAV_CURRENT;
}
char *la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag) {
// print dynamically loaded libs
std::cout << name << std::endl;
return const_cast<char*>(name);
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
return 0;
} g++ -fPIC -shared -O3 -g -o auditlib.so audit.cpp //main.cu
#include <iostream>
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
std::cout << "main()" << std::endl;
// invoke cuda function conditionally
if (1 < argc) {
int* a;
cudaMalloc(&a, 4);
}
return 0;
} nvcc src/main.cu -o try_cuda # here we dont invode cuda functions
LD_AUDIT=auditlib.so ./try_cuda
libstdc++.so.6
/usr/lib/libstdc++.so.6
libm.so.6
/usr/lib/libm.so.6
libgcc_s.so.1
/usr/lib/libgcc_s.so.1
libc.so.6
/usr/lib/libc.so.6
main() as seen, no libcuda is loaded # this time we invoke cuda functions
LD_AUDIT=auditlib.so ./try_cuda alpaka is awesome
libstdc++.so.6
/usr/lib/libstdc++.so.6
libm.so.6
/usr/lib/libm.so.6
libgcc_s.so.1
/usr/lib/libgcc_s.so.1
libc.so.6
/usr/lib/libc.so.6
main()
libcuda.so.1
/usr/lib/libcuda.so.1
libdl.so.2
/usr/lib/libdl.so.2
libpthread.so.0
/usr/lib/libpthread.so.0
librt.so.1
/usr/lib/librt.so.1
libcrypto.so.3
/usr/lib/libcrypto.so.3 as soon as we use Guess in the end its a design decision, of wether Just came across this and wanted to share with you :) |
Hi @ichinii, Can you check if #2342 fixes the issue for you?
|
IMHO linking the CUDA runtime library statically by default is an even worse choice.
What about the people that have an AMD graphics card ?
Sure, I agree. Personally, I think that it is more robust to implement the logic to check if CUDA is available in the application, rather than relying on the static linking of |
By the way, the fact that alpaka does not include an example of this approach is indeed something that we should fix 🤷🏻♂️ ! |
I am not sure if this is a real issue. Feel free to close it, if it's not of interest.
We had a nasty situation where in our github CI (windows-latest), the binary immediately shut down with exit code 1, before reaching the main function.
Reason for that is, that the binary links against cudart/curand because alpaka does interface those libraries in cmake. Using the flag
-Dalpaka_DISABLE_VENDOR_RNG=ON
fixed the issue.This problem does not occur when using github CI (ubuntu-latest).
You might ask, why one would one compile with cuda, but not use it. Reason is, that we want to ship a release with the ability to run code on the GPU, without forcing on the user the necessity of having a nvidia video card.
The 'issue' with this is, that this is so nasty
The text was updated successfully, but these errors were encountered: