From e77d6eb5abe0b2635821f257cfd455d0b0ad789a Mon Sep 17 00:00:00 2001 From: shawnz Date: Mon, 7 Apr 2025 17:17:17 +0800 Subject: [PATCH] Bug 5207005: Append pid in shmName for Linux only as this is for MIG scenario --- Samples/0_Introduction/simpleIPC/simpleIPC.cu | 10 ++++++++-- .../3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Samples/0_Introduction/simpleIPC/simpleIPC.cu b/Samples/0_Introduction/simpleIPC/simpleIPC.cu index b921cbb1..ab59fc4d 100644 --- a/Samples/0_Introduction/simpleIPC/simpleIPC.cu +++ b/Samples/0_Introduction/simpleIPC/simpleIPC.cu @@ -99,12 +99,15 @@ static void childProcess(int id) std::vector ptrs; std::vector events; std::vector verification_buffer(DATA_SIZE); - pid_t pid; char pidString[20] = {0}; char lshmName[40] = {0}; + // Use parent process ID to create a unique shared memory name for Linux multi-process +#ifdef __linux__ + pid_t pid; pid = getppid(); snprintf(pidString, sizeof(pidString), "%d", pid); +#endif strcat(lshmName, shmName); strcat(lshmName, pidString); @@ -205,12 +208,15 @@ static void parentProcess(char *app) std::vector ptrs; std::vector events; std::vector processes; - pid_t pid; char pidString[20] = {0}; char lshmName[40] = {0}; + // Use current process ID to create a unique shared memory name for Linux multi-process +#ifdef __linux__ + pid_t pid; pid = getpid(); snprintf(pidString, sizeof(pidString), "%d", pid); +#endif strcat(lshmName, shmName); strcat(lshmName, pidString); diff --git a/Samples/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp b/Samples/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp index 06a6661b..0fe208d2 100644 --- a/Samples/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp +++ b/Samples/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp @@ -310,12 +310,16 @@ static void childProcess(int devId, int id, char **argv) ipcHandle *ipcChildHandle = NULL; int blocks = 0; int threads = 128; - pid_t pid; - char pidString[20] = {0}; - char lshmName[40] = {0}; + char pidString[20] = {0}; + char lshmName[40] = {0}; + + // Use parent process ID to create a unique shared memory name for Linux multi-process +#ifdef __linux__ + pid_t pid; pid = getppid(); snprintf(pidString, sizeof(pidString), "%d", pid); +#endif strcat(lshmName, shmName); strcat(lshmName, pidString); @@ -431,16 +435,20 @@ static void parentProcess(char *app) volatile shmStruct *shm = NULL; sharedMemoryInfo info; std::vector processes; - pid_t pid; char pidString[20] = {0}; char lshmName[40] = {0}; + // Use current process ID to create a unique shared memory name for Linux multi-process +#ifdef __linux__ + pid_t pid; pid = getpid(); snprintf(pidString, sizeof(pidString), "%d", pid); +#endif strcat(lshmName, shmName); strcat(lshmName, pidString); printf("PP: lshmName = %s\n", lshmName); + checkCudaErrors(cuDeviceGetCount(&devCount)); std::vector devices(devCount);