| 336 | } |
| 337 | |
| 338 | ir::Graph *CompiledProgramPrivate::ApplyMemoryOptimizePass(ir::Graph *graph) { |
| 339 | std::vector<ir::LastLiveOpsOfVars> last_live_ops_of_vars; |
| 340 | size_t max_memory_size = static_cast<size_t>(GetEagerDeletionThreshold()); |
| 341 | |
| 342 | for (size_t i = 0; i < places_.size(); ++i) { |
| 343 | auto &place = places_[i]; |
| 344 | if (gcs_.count(place) > 0) { |
| 345 | continue; |
| 346 | } |
| 347 | std::unique_ptr<GarbageCollector> gc; |
| 348 | if (phi::is_gpu_place(place)) { |
| 349 | #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) |
| 350 | if (IsFastEagerDeletionModeEnabled()) { |
| 351 | gc = std::make_unique<UnsafeFastGPUGarbageCollector>(place, |
| 352 | max_memory_size); |
| 353 | } else { |
| 354 | gc = std::make_unique<StreamGarbageCollector>(place, max_memory_size); |
| 355 | } |
| 356 | VLOG(10) << "Created " << i << "-th GarbageCollector at " << place; |
| 357 | #else |
| 358 | PADDLE_THROW(common::errors::PermissionDenied( |
| 359 | "Paddle can't use CUDA device since it's not compiled with CUDA," |
| 360 | "Please recompile or reinstall Paddle with GPU support.")); |
| 361 | #endif |
| 362 | } else if (phi::is_xpu_place(place)) { |
| 363 | #if defined(PADDLE_WITH_XPU) |
| 364 | gc = std::make_unique<XPUGarbageCollector>(place, max_memory_size); |
| 365 | VLOG(10) << "Created " << i << "-th GarbageCollector at " << place; |
| 366 | #else |
| 367 | PADDLE_THROW(common::errors::PermissionDenied( |
| 368 | "Paddle can't use XPU device since it's not compiled with XPU," |
| 369 | "Please recompile or reinstall Paddle with XPU support.")); |
| 370 | #endif |
| 371 | } else if (phi::is_ipu_place(place)) { |
| 372 | #if defined(PADDLE_WITH_IPU) |
| 373 | gc = std::make_unique<IPUGarbageCollector>(place, max_memory_size); |
| 374 | VLOG(10) << "Created " << i << "-th GarbageCollector at " << place; |
| 375 | #else |
| 376 | PADDLE_THROW(common::errors::PermissionDenied( |
| 377 | "Paddle can't use IPU device since it's not compiled with IPU," |
| 378 | "Please recompile or reinstall Paddle with IPU support.")); |
| 379 | #endif |
| 380 | } else if (phi::is_custom_place(place)) { |
| 381 | #if defined(PADDLE_WITH_CUSTOM_DEVICE) |
| 382 | if (IsFastEagerDeletionModeEnabled()) { |
| 383 | gc = std::make_unique<CustomDeviceUnsafeFastGarbageCollector>( |
| 384 | place, max_memory_size); |
| 385 | } else { |
| 386 | gc = std::make_unique<CustomStreamGarbageCollector>(place, |
| 387 | max_memory_size); |
| 388 | } |
| 389 | VLOG(10) << "Created " << i << "-th GarbageCollector at " << place; |
| 390 | #else |
| 391 | PADDLE_THROW(common::errors::PermissionDenied( |
| 392 | "Paddle can't use custom device since it's not compiled with " |
| 393 | "CustomDevice," |
| 394 | "Please recompile or reinstall Paddle with CustomDevice support.")); |
| 395 | #endif |
no test coverage detected