P4 to Git Change 1736033 by kjayapra@9_HIPWS_IPCCHKIN on 2019/01/25 17:44:48

SWDEV-145570 - IPC Mem Handle Changes for HIP.

Affected files ...

... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#20 edit
... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#43 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#330 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#112 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.hpp#33 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.cpp#42 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocmemory.hpp#13 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#108 edit


[ROCm/clr commit: c22af4142d]
This commit is contained in:
foreman
2019-01-25 19:18:53 -05:00
والد 6fba0b7aaf
کامیت 33214c5e42
2فایلهای تغییر یافته به همراه90 افزوده شده و 12 حذف شده
@@ -31,6 +31,16 @@ THE SOFTWARE.
#include <stack>
#include <mutex>
/*! IHIP IPC MEMORY Structure */
#define IHIP_IPC_MEM_HANDLE_SIZE 32
#define IHIP_IPC_MEM_RESERVED_SIZE LP64_SWITCH(28,24)
typedef struct ihipIpcMemHandle_st {
char ipc_handle[IHIP_IPC_MEM_HANDLE_SIZE]; ///< ipc memory handle on ROCr
size_t psize;
char reserved[IHIP_IPC_MEM_RESERVED_SIZE];
} ihipIpcMemHandle_t;
#define HIP_INIT() \
std::call_once(hip::g_ihipInitialized, hip::init); \
if (hip::g_context == nullptr && g_devices.size() > 0) { \
@@ -1249,28 +1249,96 @@ hipError_t hipMemsetD8(hipDeviceptr_t dst, unsigned char value, size_t sizeBytes
HIP_RETURN(hipSuccess);
}
hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* devPtr) {
HIP_INIT_API(handle, devPtr);
hipError_t hipIpcGetMemHandle(hipIpcMemHandle_t* handle, void* dev_ptr) {
HIP_INIT_API(handle, dev_ptr);
assert(0 && "Unimplemented");
size_t offset = 0;
amd::Memory* amd_mem_obj = nullptr;
device::Memory* dev_mem_obj = nullptr;
ihipIpcMemHandle_t* ihandle = nullptr;
HIP_RETURN(hipErrorUnknown);
if ((handle == nullptr) || (dev_ptr == nullptr)) {
HIP_RETURN(hipErrorInvalidValue);
}
/* Get AMD::Memory object corresponding to this pointer */
amd_mem_obj = getMemoryObject(dev_ptr, offset);
if (amd_mem_obj == nullptr) {
HIP_RETURN(hipErrorInvalidDevicePointer);
}
/* Get Device::Memory object pointer */
dev_mem_obj = amd_mem_obj->getDeviceMemory(*hip::getCurrentContext()->devices()[0],false);
if (dev_mem_obj == nullptr) {
HIP_RETURN(hipErrorInvalidDevicePointer);
}
/* Create an handle for IPC. Store the memory size inside the handle */
ihandle = reinterpret_cast<ihipIpcMemHandle_t *>(handle);
dev_mem_obj->IpcCreate(offset, &(ihandle->psize), &(ihandle->ipc_handle));
HIP_RETURN(hipSuccess);
}
hipError_t hipIpcOpenMemHandle(void** devPtr, hipIpcMemHandle_t handle, unsigned int flags) {
HIP_INIT_API(devPtr, &handle, flags);
hipError_t hipIpcOpenMemHandle(void** dev_ptr, hipIpcMemHandle_t handle, unsigned int flags) {
HIP_INIT_API(dev_ptr, &handle, flags);
assert(0 && "Unimplemented");
amd::Memory* amd_mem_obj = nullptr;
amd::Device* device = nullptr;
ihipIpcMemHandle_t* ihandle = nullptr;
HIP_RETURN(hipErrorUnknown);
if (dev_ptr == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
/* Call the IPC Attach from Device class */
device = hip::getCurrentContext()->devices()[0];
ihandle = reinterpret_cast<ihipIpcMemHandle_t *>(&handle);
amd_mem_obj = device->IpcAttach(&(ihandle->ipc_handle), ihandle->psize, flags, dev_ptr);
if (amd_mem_obj == nullptr) {
HIP_RETURN(hipErrorInvalidDevicePointer);
}
/* Add the memory to the MemObjMap */
amd::MemObjMap::AddMemObj(*dev_ptr, amd_mem_obj);
HIP_RETURN(hipSuccess);
}
hipError_t hipIpcCloseMemHandle(void* devPtr) {
HIP_INIT_API(devPtr);
hipError_t hipIpcCloseMemHandle(void* dev_ptr) {
HIP_INIT_API(dev_ptr);
assert(0 && "Unimplemented");
size_t offset = 0;
amd::Device* device = nullptr;
amd::Memory* amd_mem_obj = nullptr;
HIP_RETURN(hipErrorUnknown);
hip::syncStreams();
hip::getNullStream()->finish();
if (dev_ptr == nullptr) {
HIP_RETURN(hipErrorInvalidValue);
}
/* Get the amd::Memory object */
amd_mem_obj = getMemoryObject(dev_ptr, offset);
if (amd_mem_obj == nullptr) {
HIP_RETURN(hipErrorInvalidDevicePointer);
}
/* Call IPC Detach from Device class */
device = hip::getCurrentContext()->devices()[0];
if (device == nullptr) {
HIP_RETURN(hipErrorNoDevice);
}
/* Remove the memory from MemObjMap */
amd::MemObjMap::RemoveMemObj(amd_mem_obj);
/* detach the memory */
device->IpcDetach(*amd_mem_obj);
HIP_RETURN(hipSuccess);
}
hipChannelFormatDesc hipCreateChannelDesc(int x, int y, int z, int w, hipChannelFormatKind f) {