SWDEV-459610 - Skip destruction for the child process

Fork() duplicates all system memory resources, but runtime can't duplicate
GPU resources. Thus, avoid tearDown() calls for the child process(s).

Change-Id: Id6b12bacd5112b9ad3747c218e09cba98ea1b42c


[ROCm/clr commit: ae2992ea43]
This commit is contained in:
German Andryeyev
2024-06-05 16:02:04 -04:00
zatwierdzone przez Maneesh Gupta
rodzic 44ef705022
commit 248ea14e63
2 zmienionych plików z 10 dodań i 4 usunięć
@@ -47,6 +47,7 @@ namespace amd {
volatile bool Runtime::initialized_ = false;
bool Runtime::LibraryDetached = false;
volatile int Runtime::pid_ = 0;
bool Runtime::init() {
if (initialized_) {
@@ -80,6 +81,7 @@ bool Runtime::init() {
}
initialized_ = true;
pid_ = amd::Os::getProcessId();
ClTrace(LOG_DEBUG, LOG_INIT);
return true;
}
@@ -104,7 +106,9 @@ std::vector<ReferenceCountedObject*> RuntimeTearDown::external_;
RuntimeTearDown::~RuntimeTearDown() {
#ifndef _WIN32
if (amd::IS_HIP) {
// Only perform destruction if process matches the initialization,
// to avoid a call with the child process after fork()
if (amd::IS_HIP && amd::Os::getProcessId() == Runtime::pid()) {
for (auto it: external_) {
it->release();
}
@@ -31,12 +31,16 @@ namespace amd {
*/
class Runtime : AllStatic {
static volatile int pid_; //!< Process ID for this runtime initialization
static volatile bool initialized_;
static bool LibraryDetached;
public:
//! Return true if the OpencCL runtime is already initialized
inline static bool initialized();
inline static bool initialized() { return initialized_; }
//! Return PID if the OCL/HIP runtime was initialized in the process
inline static int pid() { return pid_; }
//! Initialize the OpenCL runtime.
static bool init();
@@ -58,8 +62,6 @@ class Runtime : AllStatic {
/*@}*/
inline bool Runtime::initialized() { return initialized_; }
class RuntimeTearDown : public HeapObject {
static std::vector<ReferenceCountedObject*> external_;