[llvm] [Offload] Lazily initialize platforms in the Offloading API (PR #163272)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 14 10:18:04 PDT 2025


jhuber6 wrote:

Unfortunately I might need to revert this. There's some extremely weird interactions here when you *destruct* the runtime library in a global destructor like we do in the tests. Essentially, if you initialize the platform runtime *after* main has run but then call destroy it in a global destructor, some global resources may have already been freed by the time the global constructor runs.

This issue happens because if you initialize it in a global constructor it will do it lazily and the trigger the actual initialization in `main`. Because this is interacting with the underlying platform (and I know that CUDA does a lot of weird teardown magic we have no control over.) I can't imagine an easy fix to this. The only thing I can think of is if we hack a global constructor into the runtime to detect if we're firing before `main`, but that would be quite awful.

Unfortunately this puts me in an awkward place, because I was hoping for this to be a minimally invasive solution to avoiding unnecessary overhead... Honestly might just need to come down to providing a separate `olInit` variant that takes a list of desired platforms.

https://github.com/llvm/llvm-project/pull/163272


More information about the llvm-commits mailing list