diff --git a/projects/clr/hipamd/src/hip_event.cpp b/projects/clr/hipamd/src/hip_event.cpp index 9fe34f4652..d6de3703f5 100755 --- a/projects/clr/hipamd/src/hip_event.cpp +++ b/projects/clr/hipamd/src/hip_event.cpp @@ -21,6 +21,9 @@ #include #include "hip_event.hpp" +#if !defined(_MSC_VER) +#include +#endif void ipcEventCallback(hipStream_t stream, hipError_t status, void* user_data) { @@ -413,6 +416,8 @@ hipError_t hipIpcGetEventHandle(hipIpcEventHandle_t* handle, hipEvent_t event) { if (!createIpcEventShmemIfNeeded(e->ipc_evt_)) { HIP_RETURN(hipErrorInvalidConfiguration); } + e->ipc_evt_.ipc_shmem_->owners_device_id = e->deviceId(); + e->ipc_evt_.ipc_shmem_->owners_process_id = getpid(); ihipIpcEventHandle_t* iHandle = reinterpret_cast(handle); memset(iHandle->shmem_name, 0, HIP_IPC_HANDLE_SIZE); e->ipc_evt_.ipc_name_.copy(iHandle->shmem_name, std::string::npos); @@ -443,6 +448,11 @@ hipError_t hipIpcOpenEventHandle(hipEvent_t* event, hipIpcEventHandle_t handle) HIP_RETURN(hipErrorInvalidValue); } + if (getpid() == ipc_evt.ipc_shmem_->owners_process_id.load()) { + // If this is in the same process, return error. + HIP_RETURN(hipErrorInvalidContext); + } + ipc_evt.ipc_shmem_->owners += 1; e->setDeviceId(ipc_evt.ipc_shmem_->owners_device_id.load()); diff --git a/projects/clr/hipamd/src/hip_event.hpp b/projects/clr/hipamd/src/hip_event.hpp index f1380cf4ca..dc96cbd629 100644 --- a/projects/clr/hipamd/src/hip_event.hpp +++ b/projects/clr/hipamd/src/hip_event.hpp @@ -58,6 +58,7 @@ public: typedef struct ihipIpcEventShmem_s { std::atomic owners; std::atomic owners_device_id; + std::atomic owners_process_id; std::atomic read_index; std::atomic write_index; std::atomic signal[IPC_SIGNALS_PER_EVENT];