| 429 | } |
| 430 | |
| 431 | bool AnalysisPredictor::Init( |
| 432 | const std::shared_ptr<framework::Scope> &parent_scope, |
| 433 | const std::shared_ptr<framework::ProgramDesc> &program) { |
| 434 | VLOG(3) << "Predictor::init()"; |
| 435 | |
| 436 | #if defined(PADDLE_WITH_CUDA) && !defined(PADDLE_WITH_HIP) |
| 437 | phi::sparse::ConvHostBuffer &conv_buffer_instance = |
| 438 | phi::sparse::ConvHostBuffer::getInstance(); |
| 439 | if (conv_buffer_instance.using_buffer()) { |
| 440 | int *h_buffer; |
| 441 | PADDLE_ENFORCE_GPU_SUCCESS( |
| 442 | cudaHostAlloc((void **)&h_buffer, // NOLINT |
| 443 | conv_buffer_instance.get_buffer_size() * sizeof(int), |
| 444 | cudaHostAllocDefault)); |
| 445 | conv_buffer_instance.set_host_buffer(h_buffer); |
| 446 | } |
| 447 | #endif |
| 448 | |
| 449 | if (config_.with_profile_) { |
| 450 | LOG(WARNING) << "Profiler is activated, which might affect the performance"; |
| 451 | #ifdef PADDLE_WITH_NVTX |
| 452 | platform::CudaProfilerStart(); |
| 453 | platform::NvprofEnableRecordEvent(); |
| 454 | #endif |
| 455 | platform::EnableProfiler(config_.use_gpu() ? platform::ProfilerState::kAll |
| 456 | : platform::ProfilerState::kCPU); |
| 457 | } |
| 458 | |
| 459 | if (!status_is_cloned_) { |
| 460 | root_predictor_id_ = predictor_id_; |
| 461 | } |
| 462 | |
| 463 | // no matter with or without OneDNN |
| 464 | paddle::platform::SetNumThreads(config_.cpu_math_library_num_threads()); |
| 465 | |
| 466 | std::string model_path = config_.prog_file(); |
| 467 | if (!model_path.empty()) { |
| 468 | load_pir_model_ = |
| 469 | model_path.substr(model_path.find_last_of(".") + 1) == "json"; |
| 470 | } else if (!config_.model_dir().empty()) { |
| 471 | std::string model_dir = config_.model_dir(); |
| 472 | load_pir_model_ = false; |
| 473 | for (const auto &entry : std::filesystem::directory_iterator(model_dir)) { |
| 474 | if (entry.is_regular_file() && |
| 475 | entry.path().filename() == "__model__.json") { |
| 476 | load_pir_model_ = true; |
| 477 | config_.SetProgFile(config_.model_dir() + "/__model__.json"); |
| 478 | break; |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | if (load_pir_model_) { |
| 483 | config_.use_pir_ = true; |
| 484 | config_.use_new_executor_ = true; |
| 485 | } |
| 486 | |
| 487 | // Use Optimized model to inference |
| 488 | if (config_.use_optimized_model_) { |
no test coverage detected