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

Method Init

paddle/fluid/inference/api/api_impl.cc:62–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60}
61
62bool NativePaddlePredictor::Init(
63 std::shared_ptr<framework::Scope> parent_scope) {
64 VLOG(3) << "Predictor::init()";
65 if (FLAGS_profile) {
66 LOG(WARNING) << "Profiler is activated, might affect the performance";
67 LOG(INFO) << "You can turn off by set gflags '-profile false'";
68
69 auto tracking_device = config_.use_gpu ? platform::ProfilerState::kAll
70 : platform::ProfilerState::kCPU;
71 platform::EnableProfiler(tracking_device);
72 }
73
74 // no matter with or without OneDNN
75 paddle::platform::SetNumThreads(config_.cpu_math_library_num_threads());
76
77 if (config_.use_gpu) {
78 PADDLE_ENFORCE_EQ(config_.use_xpu,
79 false,
80 common::errors::InvalidArgument(
81 "Only one choice can be made between CPU and XPU."));
82 place_ = phi::GPUPlace(config_.device);
83 } else if (config_.use_xpu) {
84 place_ = phi::XPUPlace(config_.device);
85 } else {
86 place_ = phi::CPUPlace();
87 }
88 if (parent_scope) {
89 scope_ = parent_scope;
90 sub_scope_ = &(parent_scope->NewScope());
91 PADDLE_ENFORCE_NOT_NULL(sub_scope_,
92 common::errors::PreconditionNotMet(
93 "The sub_scope should not be nullptr."));
94 } else {
95 paddle::framework::InitMemoryMethod();
96 paddle::framework::InitDevices();
97 paddle::framework::InitDefaultKernelSignatureMap();
98 scope_ = std::make_unique<paddle::framework::Scope>();
99 }
100
101 executor_ = std::make_unique<paddle::framework::Executor>(place_);
102
103 // Initialize the inference program
104 if (!config_.model_dir.empty()) { // NOLINT
105 // Parameters are saved in separate files sited in
106 // the specified `dirname`.
107 inference_program_ = paddle::inference::Load(
108 executor_.get(), scope_.get(), config_.model_dir);
109 } else if (!config_.prog_file.empty() && !config_.param_file.empty()) {
110 // All parameters are saved in a single file.
111 // The file names should be consistent with that used
112 // in Python API `fluid.io.save_inference_model`.
113 inference_program_ = paddle::inference::Load(
114 executor_.get(), scope_.get(), config_.prog_file, config_.param_file);
115 } else {
116 LOG(ERROR) << "fail to load inference model from " << config_.model_dir;
117 return false;
118 }
119

Callers 2

CloneMethod · 0.45
kNative>Method · 0.45

Calls 13

EnableProfilerFunction · 0.85
SetNumThreadsFunction · 0.85
GPUPlaceClass · 0.85
InitMemoryMethodFunction · 0.85
XPUPlaceClass · 0.50
CPUPlaceClass · 0.50
InitDevicesFunction · 0.50
LoadFunction · 0.50
emptyMethod · 0.45
getMethod · 0.45
PrepareMethod · 0.45

Tested by

no test coverage detected