Skip to content

Commit ad9908e

Browse files
committed
Bug4914019 & 4191696: Append pid in shmName for MIG multiple thread scenario
1 parent 952d6ed commit ad9908e

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

Samples/0_Introduction/simpleIPC/simpleIPC.cu

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,18 @@ 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;
103+
char pidString[20] = {0};
104+
char lshmName[40] = {0};
102105

103-
if (sharedMemoryOpen(shmName, sizeof(shmStruct), &info) != 0) {
106+
pid = getppid();
107+
snprintf(pidString, sizeof(pidString), "%d", pid);
108+
strcat(lshmName, shmName);
109+
strcat(lshmName, pidString);
110+
111+
printf("CP: lshmName = %s\n", lshmName);
112+
113+
if (sharedMemoryOpen(lshmName, sizeof(shmStruct), &info) != 0) {
104114
printf("Failed to create shared memory slab\n");
105115
exit(EXIT_FAILURE);
106116
}
@@ -195,10 +205,20 @@ static void parentProcess(char *app)
195205
std::vector<void *> ptrs;
196206
std::vector<cudaEvent_t> events;
197207
std::vector<Process> processes;
208+
pid_t pid;
209+
char pidString[20] = {0};
210+
char lshmName[40] = {0};
211+
212+
pid = getpid();
213+
snprintf(pidString, sizeof(pidString), "%d", pid);
214+
strcat(lshmName, shmName);
215+
strcat(lshmName, pidString);
216+
217+
printf("PP: lshmName = %s\n", lshmName);
198218

199219
checkCudaErrors(cudaGetDeviceCount(&devCount));
200220

201-
if (sharedMemoryCreate(shmName, sizeof(*shm), &info) != 0) {
221+
if (sharedMemoryCreate(lshmName, sizeof(*shm), &info) != 0) {
202222
printf("Failed to create shared memory slab\n");
203223
exit(EXIT_FAILURE);
204224
}

Samples/2_Concepts_and_Techniques/streamOrderedAllocationIPC/streamOrderedAllocationIPC.cu

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,23 @@ static void childProcess(int id)
102102
int threads = 128;
103103
cudaDeviceProp prop;
104104
std::vector<void *> ptrs;
105+
pid_t pid;
106+
char pidString[20] = {0};
107+
char lshmName[40] = {0};
105108

106109
std::vector<char> verification_buffer(DATA_SIZE);
107110

111+
pid = getppid();
112+
snprintf(pidString, sizeof(pidString), "%d", pid);
113+
strcat(lshmName, shmName);
114+
strcat(lshmName, pidString);
115+
116+
printf("CP: lshmName = %s\n", lshmName);
117+
108118
ipcHandle *ipcChildHandle = NULL;
109119
checkIpcErrors(ipcOpenSocket(ipcChildHandle));
110120

111-
if (sharedMemoryOpen(shmName, sizeof(shmStruct), &info) != 0) {
121+
if (sharedMemoryOpen(lshmName, sizeof(shmStruct), &info) != 0) {
112122
printf("Failed to create shared memory slab\n");
113123
exit(EXIT_FAILURE);
114124
}
@@ -245,14 +255,24 @@ static void parentProcess(char *app)
245255
std::vector<void *> ptrs;
246256
std::vector<Process> processes;
247257
cudaMemAllocationHandleType handleType = cudaMemHandleTypeNone;
258+
pid_t pid;
259+
char pidString[20] = {0};
260+
char lshmName[40] = {0};
261+
262+
pid = getpid();
263+
snprintf(pidString, sizeof(pidString), "%d", pid);
264+
strcat(lshmName, shmName);
265+
strcat(lshmName, pidString);
266+
267+
printf("PP: lshmName = %s\n", lshmName);
248268

249269
checkCudaErrors(cudaGetDeviceCount(&devCount));
250270
std::vector<CUdevice> devices(devCount);
251271
for (i = 0; i < devCount; i++) {
252272
cuDeviceGet(&devices[i], i);
253273
}
254274

255-
if (sharedMemoryCreate(shmName, sizeof(*shm), &info) != 0) {
275+
if (sharedMemoryCreate(lshmName, sizeof(*shm), &info) != 0) {
256276
printf("Failed to create shared memory slab\n");
257277
exit(EXIT_FAILURE);
258278
}

Samples/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,20 @@ 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};
316+
317+
pid = getppid();
318+
snprintf(pidString, sizeof(pidString), "%d", pid);
319+
strcat(lshmName, shmName);
320+
strcat(lshmName, pidString);
321+
322+
printf("CP: lshmName = %s\n", lshmName);
313323

314324
checkIpcErrors(ipcOpenSocket(ipcChildHandle));
315325

316-
if (sharedMemoryOpen(shmName, sizeof(shmStruct), &info) != 0) {
326+
if (sharedMemoryOpen(lshmName, sizeof(shmStruct), &info) != 0) {
317327
printf("Failed to create shared memory slab\n");
318328
exit(EXIT_FAILURE);
319329
}
@@ -421,11 +431,20 @@ static void parentProcess(char *app)
421431
volatile shmStruct *shm = NULL;
422432
sharedMemoryInfo info;
423433
std::vector<Process> processes;
434+
pid_t pid;
435+
char pidString[20] = {0};
436+
char lshmName[40] = {0};
437+
438+
pid = getpid();
439+
snprintf(pidString, sizeof(pidString), "%d", pid);
440+
strcat(lshmName, shmName);
441+
strcat(lshmName, pidString);
424442

443+
printf("PP: lshmName = %s\n", lshmName);
425444
checkCudaErrors(cuDeviceGetCount(&devCount));
426445
std::vector<CUdevice> devices(devCount);
427446

428-
if (sharedMemoryCreate(shmName, sizeof(*shm), &info) != 0) {
447+
if (sharedMemoryCreate(lshmName, sizeof(*shm), &info) != 0) {
429448
printf("Failed to create shared memory slab\n");
430449
exit(EXIT_FAILURE);
431450
}

0 commit comments

Comments
 (0)