From efd28cf092d3ec3fed814da87b94b8aacd441f86 Mon Sep 17 00:00:00 2001
From: foreman
Date: Wed, 22 Aug 2018 18:42:22 -0400
Subject: [PATCH] P4 to Git Change 1597160 by cpaquot@cpaquot-ocl-lc-lnx on
2018/08/22 18:31:15
SWDEV-145570 - [HIP] Implemented hipSurfaceCreate/Destroy APIs.
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_surface.cpp#4 edit
---
hipamd/api/hip/hip_surface.cpp | 26 ++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/hipamd/api/hip/hip_surface.cpp b/hipamd/api/hip/hip_surface.cpp
index 2c1f2b9132..2323209cae 100644
--- a/hipamd/api/hip/hip_surface.cpp
+++ b/hipamd/api/hip/hip_surface.cpp
@@ -30,16 +30,16 @@ namespace hip {
static amd::Monitor surfaceLock("Guards surface objects");
struct hipSurface {
- hipSurface(const hipResourceDesc* pResDesc): array(0)
+ hipSurface(const hipResourceDesc* pResDesc): array(nullptr)
{
- memcpy((void*)&resDesc, (void*)pResDesc, sizeof(hipResourceDesc));
+ memcpy(&resDesc, pResDesc, sizeof(hipResourceDesc));
}
hipArray* array;
hipResourceDesc resDesc;
};
-static std::map surfaceHash;
+static std::unordered_map surfaceHash;
};
@@ -59,11 +59,20 @@ hipError_t hipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject,
default:
break;
}
- unsigned int* surfObj;
- hipMalloc((void**)&surfObj, sizeof(hipArray));
- hipMemcpy(surfObj, (void*)pResDesc->res.array.array, sizeof(hipArray),
+ hipSurfaceObject_t surfObj;
+ hipError_t err = hipMalloc(reinterpret_cast(&surfObj), sizeof(hipArray));
+ if (err != hipSuccess) {
+ delete pSurface;
+ HIP_RETURN(hipErrorOutOfMemory);
+ }
+ err = hipMemcpy(reinterpret_cast(surfObj), reinterpret_cast(pResDesc->res.array.array), sizeof(hipArray),
hipMemcpyHostToDevice);
- *pSurfObject = (hipSurfaceObject_t)surfObj;
+ if (err != hipSuccess) {
+ delete pSurface;
+ hipFree(reinterpret_cast(surfObj));
+ HIP_RETURN(err);
+ }
+ *pSurfObject = surfObj;
amd::ScopedLock lock(surfaceLock);
surfaceHash[*pSurfObject] = pSurface;
@@ -80,7 +89,8 @@ hipError_t hipDestroySurfaceObject(hipSurfaceObject_t surfaceObject) {
if (pSurface != nullptr) {
delete pSurface;
surfaceHash.erase(surfaceObject);
+ HIP_RETURN(hipFree(reinterpret_cast(surfaceObject)));
}
- HIP_RETURN(hipSuccess);
+ HIP_RETURN(hipErrorUnknown);
}