Clarify or fix urInit
and urTeardown
behavior
#714
Labels
Milestone
urInit
and urTeardown
behavior
#714
During the discussion on #220, it was established that current global state initialization and destruction with the use of
urInit
andurTearDown
are, at best poorly documented, and at worst, they might prevent the correct use of Unified Runtime in two independent modules in the same process.The current documentation for
urInit
states thatThe application may call this function multiple times with different flags or environment variables enabled.
andThe implementation of this function must be thread-safe for scenarios where multiple libraries may initialize the adapter(s) simultaneously.
. These two requirements can only be fulfilled together if thedifferent flags or environment variables
in all calls after the first one are entirely ignored. This might be misleading, especially if some library that uses UR doesn't take into account that it might be used in a process where UR is already initialized - this might be a relevant consideration for the design of theONEAPI_DEVICE_SELECTOR
(#220) feature or the loader config implementation (#681). In other words, software currently has no guarantees whetherurInit
does anything, but the documentation makes it seem as if it does.The
urTearDown
function documentation doesn't specify whether it can be called multiple times. Current adapter implementations cannot. This creates a problemfor scenarios where multiple libraries may initialize the adapter(s) simultaneously.
, because those libraries would require an external mechanism to coordinate callingurTearDown
. This might not be practical.In previous discussions, a proposal was made to create a separate reference-counted object on which
urInit
andurTearDown
operate. In addition to helping clarify the global state lifetime, it would also address several other API issues as outlined in #220 (comment).The text was updated successfully, but these errors were encountered: