Skip to content

Commit e77d6eb

Browse files
committed
Bug 5207005: Append pid in shmName for Linux only as this is for MIG scenario
1 parent ac70032 commit e77d6eb

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Samples/0_Introduction/simpleIPC/simpleIPC.cu

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ static void childProcess(int id)
9999
std::vector<void *> ptrs;
100100
std::vector<cudaEvent_t> events;
101101
std::vector<char> verification_buffer(DATA_SIZE);
102-
pid_t pid;
103102
char pidString[20] = {0};
104103
char lshmName[40] = {0};
105104

105+
// Use parent process ID to create a unique shared memory name for Linux multi-process
106+
#ifdef __linux__
107+
pid_t pid;
106108
pid = getppid();
107109
snprintf(pidString, sizeof(pidString), "%d", pid);
110+
#endif
108111
strcat(lshmName, shmName);
109112
strcat(lshmName, pidString);
110113

@@ -205,12 +208,15 @@ static void parentProcess(char *app)
205208
std::vector<void *> ptrs;
206209
std::vector<cudaEvent_t> events;
207210
std::vector<Process> processes;
208-
pid_t pid;
209211
char pidString[20] = {0};
210212
char lshmName[40] = {0};
211213

214+
// Use current process ID to create a unique shared memory name for Linux multi-process
215+
#ifdef __linux__
216+
pid_t pid;
212217
pid = getpid();
213218
snprintf(pidString, sizeof(pidString), "%d", pid);
219+
#endif
214220
strcat(lshmName, shmName);
215221
strcat(lshmName, pidString);
216222

Samples/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp

+12-4
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,16 @@ static void childProcess(int devId, int id, char **argv)
310310
ipcHandle *ipcChildHandle = NULL;
311311
int blocks = 0;
312312
int threads = 128;
313-
pid_t pid;
314-
char pidString[20] = {0};
315-
char lshmName[40] = {0};
313+
char pidString[20] = {0};
314+
char lshmName[40] = {0};
316315

316+
317+
// Use parent process ID to create a unique shared memory name for Linux multi-process
318+
#ifdef __linux__
319+
pid_t pid;
317320
pid = getppid();
318321
snprintf(pidString, sizeof(pidString), "%d", pid);
322+
#endif
319323
strcat(lshmName, shmName);
320324
strcat(lshmName, pidString);
321325

@@ -431,16 +435,20 @@ static void parentProcess(char *app)
431435
volatile shmStruct *shm = NULL;
432436
sharedMemoryInfo info;
433437
std::vector<Process> processes;
434-
pid_t pid;
435438
char pidString[20] = {0};
436439
char lshmName[40] = {0};
437440

441+
// Use current process ID to create a unique shared memory name for Linux multi-process
442+
#ifdef __linux__
443+
pid_t pid;
438444
pid = getpid();
439445
snprintf(pidString, sizeof(pidString), "%d", pid);
446+
#endif
440447
strcat(lshmName, shmName);
441448
strcat(lshmName, pidString);
442449

443450
printf("PP: lshmName = %s\n", lshmName);
451+
444452
checkCudaErrors(cuDeviceGetCount(&devCount));
445453
std::vector<CUdevice> devices(devCount);
446454

0 commit comments

Comments
 (0)