Added logic to update primary ctx when ctx stack is empty, updated hipCtxDestroy and ctxGetCurrent functions

Change-Id: Ia0a8943c121bc1279788a1cfa9be59af614b04a6


[ROCm/hip commit: 1211cc931c]
Этот коммит содержится в:
Rahul Garg
2016-08-26 19:03:23 +05:30
родитель c0a547b3fc
Коммит 58aa4f61c2
2 изменённых файлов: 35 добавлений и 5 удалений
+2
Просмотреть файл
@@ -166,6 +166,7 @@ class ihipCtx_t;
// generate trace string that can be output to stderr or to ATP file.
#define HIP_INIT_API(...) \
std::call_once(hip_initialized, ihipInit);\
ihipCtxStackUpdate();\
API_TRACE(__VA_ARGS__);
#define ihipLogStatus(hipStatus) \
@@ -666,6 +667,7 @@ extern const char *ihipErrorString(hipError_t);
extern ihipCtx_t *ihipGetTlsDefaultCtx();
extern void ihipSetTlsDefaultCtx(ihipCtx_t *ctx);
extern hipError_t ihipSynchronize(void);
extern hipError_t ihipCtxStackUpdate();
extern ihipDevice_t *ihipGetDevice(int);
ihipCtx_t * ihipGetPrimaryCtx(unsigned deviceIndex);
+33 -5
Просмотреть файл
@@ -29,6 +29,18 @@ THE SOFTWARE.
// Stack of contexts
thread_local std::stack<ihipCtx_t *> tls_ctxStack;
hipError_t ihipCtxStackUpdate()
{
//HIP_INIT_API();
printf("Inside ihipCtxStackUpdate\n");
hipError_t e = hipSuccess;
if(tls_ctxStack.empty()) {
tls_ctxStack.push(ihipGetTlsDefaultCtx());
}
return ihipLogStatus(e);
}
hipError_t hipInit(unsigned int flags)
{
@@ -92,11 +104,20 @@ hipError_t hipCtxDestroy(hipCtx_t ctx)
{
hipError_t e = hipSuccess;
ihipCtx_t* currentCtx= ihipGetTlsDefaultCtx();
if(currentCtx == ctx) {
//need to destroy the ctx associated with calling thread
tls_ctxStack.pop();
ihipCtx_t* primaryCtx= ((ihipDevice_t*)ctx->getDevice())->_primaryCtx;
if(primaryCtx== ctx)
{
e = hipErrorInvalidValue;
}
delete ctx; //As per CUDA docs , attempting to access ctx from those threads which has this ctx as current, will result in the error HIP_ERROR_CONTEXT_IS_DESTROYED.
else
{
if(currentCtx == ctx) {
//need to destroy the ctx associated with calling thread
tls_ctxStack.pop();
}
delete ctx; //As per CUDA docs , attempting to access ctx from those threads which has this ctx as current, will result in the error HIP_ERROR_CONTEXT_IS_DESTROYED.
}
return ihipLogStatus(e);
}
@@ -135,11 +156,18 @@ hipError_t hipCtxPushCurrent(hipCtx_t ctx)
hipError_t hipCtxGetCurrent(hipCtx_t* ctx)
{
hipError_t e = hipSuccess;
#if 0
*ctx = ihipGetTlsDefaultCtx();
if(*ctx == nullptr) {
*ctx = NULL; //TODO - is it required? Can return nullptr?
}
#endif
if(!tls_ctxStack.empty()) {
*ctx= tls_ctxStack.top();
}
else {
*ctx = NULL;
}
return ihipLogStatus(e);
}