| 304 | } |
| 305 | |
| 306 | static 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)); |
no test coverage detected