MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / Init

Method Init

paddle/fluid/inference/api/analysis_predictor.cc:431–584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431bool 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_) {

Callers 2

kAnalysis>Method · 0.45
CloneMethod · 0.45

Calls 15

NvprofEnableRecordEventFunction · 0.85
EnableProfilerFunction · 0.85
SetNumThreadsFunction · 0.85
InstanceFunction · 0.85
TryShrinkMemoryFunction · 0.85
DisplayMemoryInfoFunction · 0.85
using_bufferMethod · 0.80
get_buffer_sizeMethod · 0.80
set_host_bufferMethod · 0.80
SetProgFileMethod · 0.80
CudaProfilerStartFunction · 0.50

Tested by

no test coverage detected