[PATCH] D49763: [CUDA] Call atexit() for CUDA destructor early on.

Artem Belevich via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 24 16:11:15 PDT 2018


tra added a comment.

In https://reviews.llvm.org/D49763#1174283, @joerg wrote:

> Can this ever end up in a shared library? If yes, please use the normal logic for creating a global destructor. atexit is not very friendly to dlopen...


Yes, it can end up in a shared library. What would be the normal logic in this case?

We used to use regular global destructor, but has even worse issues. Alas, NVIDIA provides no documentation to how compiler-generated glue is expected to interact with CUDA runtime, so we need to guess what it wants.
NVCC-generated glue generates call to atexit(). If we use global destructors, then by the time they are executed, nvidia's runtime has already been deinitialized and our attempt to call it causes the crash.
Deregistering fatbin from atexit() works better, but apparently we still race with the runtime. calling atexit() before we register the fatbin appears to work for all combinations of {static/dynamic, kernel/runtime}.


https://reviews.llvm.org/D49763





More information about the cfe-commits mailing list