| 426 | } |
| 427 | |
| 428 | void InitP2P(const std::vector<phi::Place> &places) { |
| 429 | #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) |
| 430 | std::call_once(p2p_init_flag, [&]() { |
| 431 | int count = places.size(); |
| 432 | if (count <= 1) return; |
| 433 | |
| 434 | std::vector<int> devices; |
| 435 | for (int i = 0; i < count; i++) { |
| 436 | if (!phi::is_gpu_place(places[i])) return; |
| 437 | |
| 438 | phi::GPUPlace device = places[i]; |
| 439 | devices.push_back(device.GetDeviceId()); |
| 440 | } |
| 441 | |
| 442 | for (int i = 0; i < count; ++i) { |
| 443 | for (int j = 0; j < count; ++j) { |
| 444 | if (devices[i] == devices[j]) continue; |
| 445 | int can_access = -1; |
| 446 | #ifdef PADDLE_WITH_HIP |
| 447 | hipError_t ret = |
| 448 | hipDeviceCanAccessPeer(&can_access, devices[i], devices[j]); |
| 449 | if (ret != hipSuccess || can_access != 1) { |
| 450 | #else |
| 451 | cudaError_t ret = |
| 452 | cudaDeviceCanAccessPeer(&can_access, devices[i], devices[j]); |
| 453 | if (ret != cudaSuccess || can_access != 1) { |
| 454 | #endif |
| 455 | LOG(WARNING) << "Cannot enable P2P access from " << devices[i] |
| 456 | << " to " << devices[j]; |
| 457 | } else { |
| 458 | platform::CUDADeviceGuard guard(devices[i]); |
| 459 | #ifdef PADDLE_WITH_HIP |
| 460 | hipDeviceEnablePeerAccess(devices[j], 0); |
| 461 | #else |
| 462 | cudaDeviceEnablePeerAccess(devices[j], 0); |
| 463 | #endif |
| 464 | } |
| 465 | } |
| 466 | } |
| 467 | VLOG(1) << "init p2p"; |
| 468 | }); |
| 469 | #endif |
| 470 | } |
| 471 | |
| 472 | CompiledProgram::CompiledProgram(const std::vector<phi::Place> &places, |
| 473 | const std::vector<std::string> &bcast_vars, |
no test coverage detected