| 432 | } |
| 433 | |
| 434 | static void parentProcess(char *app) |
| 435 | { |
| 436 | int devCount, i, nprocesses = 0; |
| 437 | volatile shmStruct *shm = NULL; |
| 438 | sharedMemoryInfo info; |
| 439 | std::vector<Process> processes; |
| 440 | char pidString[20] = {0}; |
| 441 | char lshmName[40] = {0}; |
| 442 | |
| 443 | // Use current process ID to create a unique shared memory name for Linux multi-process |
| 444 | #ifdef __linux__ |
| 445 | pid_t pid; |
| 446 | pid = getpid(); |
| 447 | snprintf(pidString, sizeof(pidString), "%d", pid); |
| 448 | #endif |
| 449 | strcat(lshmName, shmName); |
| 450 | strcat(lshmName, pidString); |
| 451 | |
| 452 | printf("PP: lshmName = %s\n", lshmName); |
| 453 | |
| 454 | checkCudaErrors(cuDeviceGetCount(&devCount)); |
| 455 | std::vector<CUdevice> devices(devCount); |
| 456 | |
| 457 | if (sharedMemoryCreate(lshmName, sizeof(*shm), &info) != 0) { |
| 458 | printf("Failed to create shared memory slab\n"); |
| 459 | exit(EXIT_FAILURE); |
| 460 | } |
| 461 | |
| 462 | shm = (volatile shmStruct *)info.addr; |
| 463 | memset((void *)shm, 0, sizeof(*shm)); |
| 464 | |
| 465 | for (i = 0; i < devCount; i++) { |
| 466 | checkCudaErrors(cuDeviceGet(&devices[i], i)); |
| 467 | } |
| 468 | |
| 469 | std::vector<CUcontext> ctxs; |
| 470 | std::vector<unsigned char> selectedDevices; |
| 471 | |
| 472 | // Pick all the devices that can access each other's memory for this test |
| 473 | // Keep in mind that CUDA has minimal support for fork() without a |
| 474 | // corresponding exec() in the child process, but in this case our |
| 475 | // spawnProcess will always exec, so no need to worry. |
| 476 | for (i = 0; i < devCount; i++) { |
| 477 | bool allPeers = true; |
| 478 | int deviceComputeMode; |
| 479 | int deviceSupportsIpcHandle; |
| 480 | int attributeVal = 0; |
| 481 | |
| 482 | checkCudaErrors(cuDeviceGet(&devices[i], i)); |
| 483 | checkCudaErrors(cuDeviceGetAttribute(&deviceComputeMode, CU_DEVICE_ATTRIBUTE_COMPUTE_MODE, devices[i])); |
| 484 | checkCudaErrors( |
| 485 | cuDeviceGetAttribute(&attributeVal, CU_DEVICE_ATTRIBUTE_VIRTUAL_ADDRESS_MANAGEMENT_SUPPORTED, devices[i])); |
| 486 | #if defined(__linux__) || defined(__QNX__) |
| 487 | checkCudaErrors(cuDeviceGetAttribute( |
| 488 | &deviceSupportsIpcHandle, CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR_SUPPORTED, devices[i])); |
| 489 | #else |
| 490 | checkCudaErrors(cuDeviceGetAttribute( |
| 491 | &deviceSupportsIpcHandle, CU_DEVICE_ATTRIBUTE_HANDLE_TYPE_WIN32_HANDLE_SUPPORTED, devices[i])); |
no test coverage detected