| 353 | |
| 354 | template <> |
| 355 | std::unique_ptr<PaddlePredictor> |
| 356 | CreatePaddlePredictor<NativeConfig, PaddleEngineKind::kNative>( |
| 357 | const NativeConfig &config) { |
| 358 | // TODO(NHZlX): Should add the link to the doc of |
| 359 | // paddle_infer::CreatePredictor<paddle_infer::Config> |
| 360 | VLOG(3) << "create NativePaddlePredictor"; |
| 361 | if (config.use_gpu) { |
| 362 | // 1. GPU memory |
| 363 | PADDLE_ENFORCE_GE(config.fraction_of_gpu_memory, |
| 364 | 0.f, |
| 365 | common::errors::InvalidArgument( |
| 366 | "fraction_of_gpu_memory in the config should be set " |
| 367 | "to range (0., 1.]")); |
| 368 | PADDLE_ENFORCE_GE(config.device, |
| 369 | 0, |
| 370 | common::errors::PreconditionNotMet( |
| 371 | "Invalid device id %d, the device id should be " |
| 372 | "greater than or equal to 0.", |
| 373 | config.device)); |
| 374 | std::vector<std::string> flags; |
| 375 | if (config.fraction_of_gpu_memory >= 0.0f || |
| 376 | config.fraction_of_gpu_memory <= 0.95f) { |
| 377 | std::string flag = "--fraction_of_gpu_memory_to_use=" + |
| 378 | num2str<float>(config.fraction_of_gpu_memory); |
| 379 | flags.push_back(flag); |
| 380 | VLOG(3) << "set flag: " << flag; |
| 381 | framework::InitGflags(flags); |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | std::unique_ptr<PaddlePredictor> predictor(new NativePaddlePredictor(config)); |
| 386 | PADDLE_ENFORCE_NOT_NULL( |
| 387 | dynamic_cast<NativePaddlePredictor *>(predictor.get()), |
| 388 | common::errors::PreconditionNotMet( |
| 389 | "Dynamic_cast from PaddlePredictor to NativePaddlePredictor failed")); |
| 390 | if (!dynamic_cast<NativePaddlePredictor *>(predictor.get())->Init(nullptr)) { |
| 391 | return nullptr; |
| 392 | } |
| 393 | return predictor; |
| 394 | } |
| 395 | |
| 396 | template <> |
| 397 | std::unique_ptr<PaddlePredictor> CreatePaddlePredictor<NativeConfig>( |
nothing calls this directly
no test coverage detected