From 32d8a58f18f8aff1967efded78b60f85d2be20c9 Mon Sep 17 00:00:00 2001 From: Rahul Garg Date: Fri, 10 Mar 2017 23:45:28 +0530 Subject: [PATCH] IPC supported using ROCR APIs Change-Id: I0a353b1240098f4b20fa266a871f5f5826290af9 --- include/hip/hcc_detail/hip_runtime_api.h | 7 ++++++- src/hip_hcc.h | 6 +++--- src/hip_memory.cpp | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/hip/hcc_detail/hip_runtime_api.h b/include/hip/hcc_detail/hip_runtime_api.h index fb8535cfec..080f82d9ed 100644 --- a/include/hip/hcc_detail/hip_runtime_api.h +++ b/include/hip/hcc_detail/hip_runtime_api.h @@ -62,7 +62,12 @@ typedef struct ihipStream_t *hipStream_t; #define hipIpcMemLazyEnablePeerAccess 0 -typedef struct ihipIpcMemHandle_t *hipIpcMemHandle_t; +#define HIP_IPC_HANDLE_SIZE 64 + +typedef struct hipIpcMemHandle_st +{ + char reserved[HIP_IPC_HANDLE_SIZE]; +}hipIpcMemHandle_t; //TODO: IPC event handle currently unsupported struct ihipIpcEventHandle_t; diff --git a/src/hip_hcc.h b/src/hip_hcc.h index 105eef6bb8..b23aead072 100644 --- a/src/hip_hcc.h +++ b/src/hip_hcc.h @@ -36,7 +36,7 @@ THE SOFTWARE. #error("This version of HIP requires a newer version of HCC."); #endif -#define USE_IPC 0 +#define USE_IPC 1 //--- // Environment variables: @@ -326,15 +326,15 @@ const hipStream_t hipStreamNull = 0x0; /** * HIP IPC Handle Size */ -#define HIP_IPC_HANDLE_SIZE 64 +#define HIP_IPC_RESERVED_SIZE 24 class ihipIpcMemHandle_t { public: #if USE_IPC hsa_amd_ipc_memory_t ipc_handle; ///< ipc memory handle on ROCr #endif - char reserved[HIP_IPC_HANDLE_SIZE]; size_t psize; + char reserved[HIP_IPC_RESERVED_SIZE]; }; diff --git a/src/hip_memory.cpp b/src/hip_memory.cpp index 29315fa09d..df11205344 100644 --- a/src/hip_memory.cpp +++ b/src/hip_memory.cpp @@ -1143,7 +1143,7 @@ hipError_t hipMemGetAddressRange ( hipDeviceptr_t* pbase, size_t* psize, hipDevi } else hipStatus = hipErrorInvalidDevicePointer; - return hipStatus; + return ihipLogStatus(hipStatus); } @@ -1162,25 +1162,25 @@ hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr){ } else hipStatus = hipErrorInvalidResourceHandle; - + ihipIpcMemHandle_t* iHandle = (ihipIpcMemHandle_t*) handle; // Save the size of the pointer to hipIpcMemHandle - (*handle)->psize = psize; + iHandle->psize = psize; #if USE_IPC // Create HSA ipc memory hsa_status_t hsa_status = - hsa_amd_ipc_memory_create(devPtr, psize, &(*handle)->ipc_handle); + hsa_amd_ipc_memory_create(devPtr, psize, (hsa_amd_ipc_memory_t*) &(iHandle->ipc_handle)); if(hsa_status!= HSA_STATUS_SUCCESS) hipStatus = hipErrorMemoryAllocation; #else hipStatus = hipErrorRuntimeOther; #endif - return hipStatus; + return ihipLogStatus(hipStatus); } hipError_t hipIpcOpenMemHandle(void** devPtr, hipIpcMemHandle_t handle, unsigned int flags){ -// HIP_INIT_API ( devPtr, handle.handle , flags); + HIP_INIT_API ( devPtr, &handle , flags); hipError_t hipStatus = hipSuccess; #if USE_IPC @@ -1190,15 +1190,16 @@ hipError_t hipIpcOpenMemHandle(void** devPtr, hipIpcMemHandle_t handle, unsigned if(!agent) return hipErrorInvalidResourceHandle; + ihipIpcMemHandle_t* iHandle = (ihipIpcMemHandle_t*) &handle; //Attach ipc memory hsa_status_t hsa_status = - hsa_amd_ipc_memory_attach(&handle->ipc_handle, handle->psize, 1, agent, devPtr); + hsa_amd_ipc_memory_attach((hsa_amd_ipc_memory_t*)&(iHandle->ipc_handle), iHandle->psize, 1, agent, devPtr); if(hsa_status != HSA_STATUS_SUCCESS) hipStatus = hipErrorMapBufferObjectFailed; #else hipStatus = hipErrorRuntimeOther; #endif - return hipStatus; + return ihipLogStatus(hipStatus); } hipError_t hipIpcCloseMemHandle(void *devPtr){ @@ -1213,7 +1214,7 @@ hipError_t hipIpcCloseMemHandle(void *devPtr){ #else hipStatus = hipErrorRuntimeOther; #endif - return hipStatus; + return ihipLogStatus(hipStatus); } // hipError_t hipIpcOpenEventHandle(hipEvent_t* event, hipIpcEventHandle_t handle){