From 2d0867f228867c2eacabb39caf20452818ed465b Mon Sep 17 00:00:00 2001
From: foreman
Date: Fri, 4 May 2018 14:13:13 -0400
Subject: [PATCH] P4 to Git Change 1550486 by cpaquot@cpaquot-ocl-lc-lnx on
2018/05/04 14:00:33
SWDEV-145570 - [HIP] Fix multithread init
Make the g_ihipInitialized variable per thread
And make sure to assign a default g_context
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#10 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#9 edit
[ROCm/hip commit: 9129aa17f6d6f6a95294aca43726027fe8746e4c]
---
projects/hip/api/hip/hip_context.cpp | 3 +--
projects/hip/api/hip/hip_internal.hpp | 17 ++++++++++-------
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/projects/hip/api/hip/hip_context.cpp b/projects/hip/api/hip/hip_context.cpp
index 46e4c864ff..dfeacdc924 100644
--- a/projects/hip/api/hip/hip_context.cpp
+++ b/projects/hip/api/hip/hip_context.cpp
@@ -28,12 +28,12 @@ THE SOFTWARE.
#include
std::vector g_devices;
-std::once_flag g_ihipInitialized;
namespace hip {
thread_local amd::Context* g_context = nullptr;
thread_local std::stack g_ctxtStack;
+std::once_flag g_ihipInitialized;
std::map g_nullStreams;
@@ -53,7 +53,6 @@ void init() {
context->release();
} else {
g_devices.push_back(context);
- g_context = context;
}
}
}
diff --git a/projects/hip/api/hip/hip_internal.hpp b/projects/hip/api/hip/hip_internal.hpp
index 489b8b620f..099aa6ca25 100644
--- a/projects/hip/api/hip/hip_internal.hpp
+++ b/projects/hip/api/hip/hip_internal.hpp
@@ -28,26 +28,29 @@ THE SOFTWARE.
#include
#define HIP_INIT() \
- std::call_once(g_ihipInitialized, hip::init);
-
+ std::call_once(hip::g_ihipInitialized, hip::init); \
+ assert(g_devices.size() > 0); \
+ if (hip::g_context == nullptr) { \
+ hip::g_context = g_devices[0]; \
+ }
// This macro should be called at the beginning of every HIP API.
#define HIP_INIT_API(...) \
- HIP_INIT(); \
- \
amd::Thread* thread = amd::Thread::current(); \
if (!CL_CHECK_THREAD(thread)) { \
return hipErrorOutOfMemory; \
- }
+ } \
+ HIP_INIT();
namespace hc {
class accelerator;
class accelerator_view;
};
-extern std::once_flag g_ihipInitialized;
-
namespace hip {
+ extern std::once_flag g_ihipInitialized;
+ extern thread_local amd::Context* g_context;
+
extern void init();
extern amd::Context* getCurrentContext();