consolidate thread local storage (#915)
* all thread local access now through single struct
* clean up old commented-out code, more use of GET_TLS()
* fewer calls to GET_TLS by passing tls as a funtion argument
* revert unnecessary change to printf
* fix failing tests due to TLS change
* fix merge conflicts in ihipOccupancyMaxActiveBlocksPerMultiprocessor
[ROCm/hip commit: 1eb3dbf065]
This commit is contained in:
@@ -29,13 +29,10 @@ THE SOFTWARE.
|
||||
#include "hip_hcc_internal.h"
|
||||
#include "trace_helper.h"
|
||||
|
||||
// Stack of contexts
|
||||
thread_local std::stack<ihipCtx_t*> tls_ctxStack;
|
||||
thread_local bool tls_getPrimaryCtx = true;
|
||||
|
||||
void ihipCtxStackUpdate() {
|
||||
if (tls_ctxStack.empty()) {
|
||||
tls_ctxStack.push(ihipGetTlsDefaultCtx());
|
||||
GET_TLS();
|
||||
if (tls->ctxStack.empty()) {
|
||||
tls->ctxStack.push(ihipGetTlsDefaultCtx());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +59,8 @@ hipError_t hipCtxCreate(hipCtx_t* ctx, unsigned int flags, hipDevice_t device) {
|
||||
auto ictx = new ihipCtx_t(deviceHandle, g_deviceCnt, flags);
|
||||
*ctx = ictx;
|
||||
ihipSetTlsDefaultCtx(*ctx);
|
||||
tls_ctxStack.push(*ctx);
|
||||
tls_getPrimaryCtx = false;
|
||||
tls->ctxStack.push(*ctx);
|
||||
tls->getPrimaryCtx = false;
|
||||
deviceCrit->addContext(ictx);
|
||||
}
|
||||
|
||||
@@ -119,7 +116,7 @@ hipError_t hipCtxDestroy(hipCtx_t ctx) {
|
||||
} else {
|
||||
if (currentCtx == ctx) {
|
||||
// need to destroy the ctx associated with calling thread
|
||||
tls_ctxStack.pop();
|
||||
tls->ctxStack.pop();
|
||||
}
|
||||
{
|
||||
auto deviceHandle = ctx->getWriteableDevice();
|
||||
@@ -140,12 +137,12 @@ hipError_t hipCtxPopCurrent(hipCtx_t* ctx) {
|
||||
auto deviceHandle = currentCtx->getDevice();
|
||||
*ctx = currentCtx;
|
||||
|
||||
if (!tls_ctxStack.empty()) {
|
||||
tls_ctxStack.pop();
|
||||
if (!tls->ctxStack.empty()) {
|
||||
tls->ctxStack.pop();
|
||||
}
|
||||
|
||||
if (!tls_ctxStack.empty()) {
|
||||
currentCtx = tls_ctxStack.top();
|
||||
if (!tls->ctxStack.empty()) {
|
||||
currentCtx = tls->ctxStack.top();
|
||||
} else {
|
||||
currentCtx = deviceHandle->_primaryCtx;
|
||||
}
|
||||
@@ -159,8 +156,8 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx) {
|
||||
hipError_t e = hipSuccess;
|
||||
if (ctx != NULL) { // TODO- is this check needed?
|
||||
ihipSetTlsDefaultCtx(ctx);
|
||||
tls_ctxStack.push(ctx);
|
||||
tls_getPrimaryCtx = false;
|
||||
tls->ctxStack.push(ctx);
|
||||
tls->getPrimaryCtx = false;
|
||||
} else {
|
||||
e = hipErrorInvalidContext;
|
||||
}
|
||||
@@ -170,10 +167,10 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx) {
|
||||
hipError_t hipCtxGetCurrent(hipCtx_t* ctx) {
|
||||
HIP_INIT_API(hipCtxGetCurrent, ctx);
|
||||
hipError_t e = hipSuccess;
|
||||
if ((tls_getPrimaryCtx) || tls_ctxStack.empty()) {
|
||||
if ((tls->getPrimaryCtx) || tls->ctxStack.empty()) {
|
||||
*ctx = ihipGetTlsDefaultCtx();
|
||||
} else {
|
||||
*ctx = tls_ctxStack.top();
|
||||
*ctx = tls->ctxStack.top();
|
||||
}
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
@@ -182,11 +179,11 @@ hipError_t hipCtxSetCurrent(hipCtx_t ctx) {
|
||||
HIP_INIT_API(hipCtxSetCurrent, ctx);
|
||||
hipError_t e = hipSuccess;
|
||||
if (ctx == NULL) {
|
||||
tls_ctxStack.pop();
|
||||
tls->ctxStack.pop();
|
||||
} else {
|
||||
ihipSetTlsDefaultCtx(ctx);
|
||||
tls_ctxStack.push(ctx);
|
||||
tls_getPrimaryCtx = false;
|
||||
tls->ctxStack.push(ctx);
|
||||
tls->getPrimaryCtx = false;
|
||||
}
|
||||
return ihipLogStatus(e);
|
||||
}
|
||||
@@ -251,7 +248,7 @@ hipError_t hipCtxGetSharedMemConfig(hipSharedMemConfig* pConfig) {
|
||||
|
||||
hipError_t hipCtxSynchronize(void) {
|
||||
HIP_INIT_API(hipCtxSynchronize, 1);
|
||||
return ihipLogStatus(ihipSynchronize()); // TODP Shall check validity of ctx?
|
||||
return ihipLogStatus(ihipSynchronize(tls)); // TODO Shall check validity of ctx?
|
||||
}
|
||||
|
||||
hipError_t hipCtxGetFlags(unsigned int* flags) {
|
||||
|
||||
مرجع در شماره جدید
Block a user