From 28ce8a8a89ef4cc24d39e7b393bcc972bef8486a Mon Sep 17 00:00:00 2001 From: foreman Date: Tue, 21 Aug 2018 18:29:16 -0400 Subject: [PATCH] P4 to Git Change 1596634 by cpaquot@cpaquot-ocl-lc-lnx on 2018/08/21 18:07:55 SWDEV-145570 - [HIP] Implmented hipSurfaceCreate/Destroy APIs Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_surface.cpp#3 edit --- api/hip/hip_surface.cpp | 51 +++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/api/hip/hip_surface.cpp b/api/hip/hip_surface.cpp index 8cf7e8f35d..2c1f2b9132 100644 --- a/api/hip/hip_surface.cpp +++ b/api/hip/hip_surface.cpp @@ -25,25 +25,62 @@ THE SOFTWARE. #include "hip_internal.hpp" #include +namespace hip { + +static amd::Monitor surfaceLock("Guards surface objects"); + struct hipSurface { - hipArray* array; - hipResourceDesc resDesc; + hipSurface(const hipResourceDesc* pResDesc): array(0) + { + memcpy((void*)&resDesc, (void*)pResDesc, sizeof(hipResourceDesc)); + } + + hipArray* array; + hipResourceDesc resDesc; }; +static std::map surfaceHash; + +}; + +using namespace hip; + hipError_t hipCreateSurfaceObject(hipSurfaceObject_t* pSurfObject, const hipResourceDesc* pResDesc) { HIP_INIT_API(pSurfObject, pResDesc); - assert(0 && "Unimplemented"); + hipSurface* pSurface = new hipSurface(pResDesc); + assert(pSurface != nullptr); - HIP_RETURN(hipErrorUnknown); + switch (pResDesc->resType) { + case hipResourceTypeArray: + pSurface->array = pResDesc->res.array.array; + break; + default: + break; + } + unsigned int* surfObj; + hipMalloc((void**)&surfObj, sizeof(hipArray)); + hipMemcpy(surfObj, (void*)pResDesc->res.array.array, sizeof(hipArray), + hipMemcpyHostToDevice); + *pSurfObject = (hipSurfaceObject_t)surfObj; + + amd::ScopedLock lock(surfaceLock); + surfaceHash[*pSurfObject] = pSurface; + + HIP_RETURN(hipSuccess); } hipError_t hipDestroySurfaceObject(hipSurfaceObject_t surfaceObject) { HIP_INIT_API(surfaceObject); - assert(0 && "Unimplemented"); + amd::ScopedLock lock(surfaceLock); + hipSurface* pSurface = surfaceHash[surfaceObject]; + if (pSurface != nullptr) { + delete pSurface; + surfaceHash.erase(surfaceObject); + } - HIP_RETURN(hipErrorUnknown); -} \ No newline at end of file + HIP_RETURN(hipSuccess); +}