MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / childProcess

Function childProcess

cpp/3_CUDA_Features/memMapIPCDrv/memMapIpc.cpp:306–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

304}
305
306static void childProcess(int devId, int id, char **argv)
307{
308 volatile shmStruct *shm = NULL;
309 sharedMemoryInfo info;
310 ipcHandle *ipcChildHandle = NULL;
311 int blocks = 0;
312 int threads = 128;
313 char pidString[20] = {0};
314 char lshmName[40] = {0};
315
316
317 // Use parent process ID to create a unique shared memory name for Linux multi-process
318#ifdef __linux__
319 pid_t pid;
320 pid = getppid();
321 snprintf(pidString, sizeof(pidString), "%d", pid);
322#endif
323 strcat(lshmName, shmName);
324 strcat(lshmName, pidString);
325
326 printf("CP: lshmName = %s\n", lshmName);
327
328 checkIpcErrors(ipcOpenSocket(ipcChildHandle));
329
330 if (sharedMemoryOpen(lshmName, sizeof(shmStruct), &info) != 0) {
331 printf("Failed to create shared memory slab\n");
332 exit(EXIT_FAILURE);
333 }
334 shm = (volatile shmStruct *)info.addr;
335 int procCount = (int)shm->nprocesses;
336
337 barrierWait(&shm->barrier, &shm->sense, (unsigned int)(procCount + 1));
338
339 // Receive all allocation handles shared by Parent.
340 std::vector<ShareableHandle> shHandle(procCount);
341 checkIpcErrors(ipcRecvShareableHandles(ipcChildHandle, shHandle));
342
343 CUcontext ctx;
344 CUdevice device;
345 CUstream stream;
346 int multiProcessorCount;
347 CUctxCreateParams ctx_params = {};
348
349 checkCudaErrors(cuDeviceGet(&device, devId));
350 checkCudaErrors(cuCtxCreate(&ctx, &ctx_params, 0, device));
351 checkCudaErrors(cuStreamCreate(&stream, CU_STREAM_NON_BLOCKING));
352
353 // Obtain kernel function for the sample
354 memMapGetDeviceFunction(argv);
355
356 checkCudaErrors(cuOccupancyMaxActiveBlocksPerMultiprocessor(&blocks, _memMapIpc_kernel, threads, 0));
357 checkCudaErrors(cuDeviceGetAttribute(&multiProcessorCount, CU_DEVICE_ATTRIBUTE_MULTIPROCESSOR_COUNT, device));
358 blocks *= multiProcessorCount;
359
360 CUdeviceptr d_ptr = 0ULL;
361
362 // Reserve the required contiguous VA space for the allocations
363 checkCudaErrors(cuMemAddressReserve(&d_ptr, procCount * DATA_BUF_SIZE, DATA_BUF_SIZE, 0, 0));

Callers 1

mainFunction · 0.85

Calls 9

ipcOpenSocketFunction · 0.85
sharedMemoryOpenFunction · 0.85
barrierWaitFunction · 0.85
ipcRecvShareableHandlesFunction · 0.85
memMapGetDeviceFunctionFunction · 0.85
memMapImportAndMapMemoryFunction · 0.85
ipcCloseShareableHandleFunction · 0.85
ipcCloseSocketFunction · 0.85
memMapUnmapAndFreeMemoryFunction · 0.85

Tested by

no test coverage detected