SWDEV-399098 - Change hip_init lock to use std::call_once
Updating hip_init lock to use std::call_once fixed Performance
drops in TF benchmarks for FP16
Change-Id: Ib1125ac66806b232057ba183e296ea4d0642d08d
[ROCm/clr commit: 2f83719d12]
Этот коммит содержится в:
коммит произвёл
Anusha Godavarthy Surya
родитель
7ee73c61b0
Коммит
729779a3b3
@@ -26,13 +26,13 @@
|
||||
#include "utils/versions.hpp"
|
||||
|
||||
std::vector<hip::Device*> g_devices;
|
||||
amd::Monitor g_hipInitlock{"hipInit lock"};
|
||||
std::once_flag g_ihipInitialized;
|
||||
namespace hip {
|
||||
thread_local TlsAggregator tls;
|
||||
amd::Context* host_context = nullptr;
|
||||
|
||||
//init() is only to be called from the HIP_INIT macro only once
|
||||
bool init() {
|
||||
void init(bool* status) {
|
||||
amd::IS_HIP = true;
|
||||
GPU_NUM_MEM_DEPENDENCY = 0;
|
||||
#if DISABLE_DIRECT_DISPATCH
|
||||
@@ -42,7 +42,8 @@ bool init() {
|
||||
#endif
|
||||
AMD_DIRECT_DISPATCH = flagIsDefault(AMD_DIRECT_DISPATCH) ? kDirectDispatch : AMD_DIRECT_DISPATCH;
|
||||
if (!amd::Runtime::init()) {
|
||||
return false;
|
||||
*status = false;
|
||||
return;
|
||||
}
|
||||
ClPrint(amd::LOG_INFO, amd::LOG_INIT, "Direct Dispatch: %d", AMD_DIRECT_DISPATCH);
|
||||
|
||||
@@ -52,7 +53,10 @@ bool init() {
|
||||
for (unsigned int i=0; i<devices.size(); i++) {
|
||||
const std::vector<amd::Device*> device(1, devices[i]);
|
||||
amd::Context* context = new amd::Context(device, amd::Context::Info());
|
||||
if (!context) return false;
|
||||
if (!context) {
|
||||
*status = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Enable active wait on the device by default
|
||||
devices[i]->SetActiveWait(true);
|
||||
@@ -62,14 +66,18 @@ bool init() {
|
||||
} else {
|
||||
auto device = new Device(context, i);
|
||||
if ((device == nullptr) || !device->Create()) {
|
||||
return false;
|
||||
*status = false;
|
||||
return;
|
||||
}
|
||||
g_devices.push_back(device);
|
||||
}
|
||||
}
|
||||
|
||||
amd::Context* hContext = new amd::Context(devices, amd::Context::Info());
|
||||
if (!hContext) return false;
|
||||
if (!hContext) {
|
||||
*status = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (CL_SUCCESS != hContext->create(nullptr)) {
|
||||
hContext->release();
|
||||
@@ -77,7 +85,8 @@ bool init() {
|
||||
host_context = hContext;
|
||||
|
||||
PlatformState::instance().init();
|
||||
return true;
|
||||
*status = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Device* getCurrentDevice() {
|
||||
|
||||
@@ -71,29 +71,28 @@ typedef struct ihipIpcEventHandle_st {
|
||||
|
||||
const char* ihipGetErrorName(hipError_t hip_error);
|
||||
|
||||
extern amd::Monitor g_hipInitlock;
|
||||
#define HIP_INIT(noReturn) {\
|
||||
amd::ScopedLock lock(g_hipInitlock); \
|
||||
if (!amd::Runtime::initialized()) { \
|
||||
if (!hip::init() && !noReturn) { \
|
||||
HIP_RETURN(hipErrorInvalidDevice); \
|
||||
} \
|
||||
} \
|
||||
if (hip::tls.device_ == nullptr && g_devices.size() > 0) { \
|
||||
hip::tls.device_ = g_devices[0]; \
|
||||
amd::Os::setPreferredNumaNode(g_devices[0]->devices()[0]->getPreferredNumaNode()); \
|
||||
} \
|
||||
extern std::once_flag g_ihipInitialized;
|
||||
#define HIP_INIT(noReturn) \
|
||||
{ \
|
||||
bool status = true; \
|
||||
std::call_once(g_ihipInitialized, hip::init, &status); \
|
||||
if (!status && !noReturn) { \
|
||||
HIP_RETURN(hipErrorInvalidDevice); \
|
||||
} \
|
||||
if (hip::tls.device_ == nullptr && g_devices.size() > 0) { \
|
||||
hip::tls.device_ = g_devices[0]; \
|
||||
amd::Os::setPreferredNumaNode(g_devices[0]->devices()[0]->getPreferredNumaNode()); \
|
||||
} \
|
||||
}
|
||||
|
||||
#define HIP_INIT_VOID() {\
|
||||
amd::ScopedLock lock(g_hipInitlock); \
|
||||
if (!amd::Runtime::initialized()) { \
|
||||
if (hip::init()) {} \
|
||||
} \
|
||||
if (hip::tls.device_ == nullptr && g_devices.size() > 0) { \
|
||||
hip::tls.device_ = g_devices[0]; \
|
||||
amd::Os::setPreferredNumaNode(g_devices[0]->devices()[0]->getPreferredNumaNode()); \
|
||||
} \
|
||||
#define HIP_INIT_VOID() \
|
||||
{ \
|
||||
bool status = true; \
|
||||
std::call_once(g_ihipInitialized, hip::init, &status); \
|
||||
if (hip::tls.device_ == nullptr && g_devices.size() > 0) { \
|
||||
hip::tls.device_ = g_devices[0]; \
|
||||
amd::Os::setPreferredNumaNode(g_devices[0]->devices()[0]->getPreferredNumaNode()); \
|
||||
} \
|
||||
}
|
||||
|
||||
|
||||
@@ -532,7 +531,7 @@ namespace hip {
|
||||
/// Device representing the host - for pinned memory
|
||||
extern amd::Context* host_context;
|
||||
|
||||
extern bool init();
|
||||
extern void init(bool* status);
|
||||
|
||||
extern Device* getCurrentDevice();
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user