From 066a072226fa4ea5eb7c61291fcc1d98c1911bcf Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 24 Apr 2018 16:49:38 -0400 Subject: [PATCH] P4 to Git Change 1545859 by cpaquot@cpaquot-ocl-lc-lnx on 2018/04/24 16:44:17 SWDEV-145570 - [HIP] Get hipCtx_simple to pass Implemented hipCtxGetDevice hipCtxCreate must push the created context onto the context stack hipCtxDestroy must check if the top of the stack is the context being destroy and not just pop the top of the stack w/o checking. Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_context.cpp#8 edit [ROCm/hip commit: d2fbde728c3227c586166dd91a6a664c08e2cd30] --- projects/hip/api/hip/hip_context.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/projects/hip/api/hip/hip_context.cpp b/projects/hip/api/hip/hip_context.cpp index 2e189f1351..e25a87bde8 100644 --- a/projects/hip/api/hip/hip_context.cpp +++ b/projects/hip/api/hip/hip_context.cpp @@ -71,6 +71,7 @@ hipError_t hipCtxCreate(hipCtx_t *ctx, unsigned int flags, hipDevice_t device) // Increment ref count for device primary context g_devices[device]->retain(); + g_ctxtStack.push(g_devices[device]); return hipSuccess; } @@ -122,7 +123,7 @@ hipError_t hipCtxDestroy(hipCtx_t ctx) { } // Need to remove the ctx of calling thread if its the top one - if (g_context == amdContext) { + if (!g_ctxtStack.empty() && g_ctxtStack.top() == amdContext) { g_ctxtStack.pop(); } @@ -188,7 +189,16 @@ hipError_t hipDriverGetVersion(int* driverVersion) { hipError_t hipCtxGetDevice(hipDevice_t* device) { HIP_INIT_API(device); - assert(0 && "Unimplemented"); + if (device != nullptr) { + for (unsigned int i = 0; i < g_devices.size(); i++) { + if (g_devices[i] == g_context) { + *device = static_cast(i); + return hipSuccess; + } + } + } else { + return hipErrorInvalidValue; + } return hipErrorUnknown; } @@ -279,4 +289,4 @@ hipError_t hipDevicePrimaryCtxSetFlags(hipDevice_t dev, unsigned int flags) { assert(0 && "Unimplemented"); return hipErrorUnknown; -} \ No newline at end of file +}