From eac431380a48ff459a48dcda344e39bcffa7498b Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Wed, 28 Jul 2021 00:03:29 -0400 Subject: [PATCH] SWDEV-294591 - Fix hipEventIpc failure on NV make hipIpcOpenEventHandle has the same behavour of cudaIpcOpenEventHandle. Change-Id: I3fe6dbc35a7b14ba9119df297b7885df83d28149 [ROCm/clr commit: c87a352288897edc77194bc5af7e154536b2fa37] --- projects/clr/hipamd/src/hip_event.cpp | 10 ++++++++++ projects/clr/hipamd/src/hip_event.hpp | 1 + 2 files changed, 11 insertions(+) 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];