FastDeploy  latest
Fast & Easy to Deploy!
option.h
1 // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 #include "fastdeploy/core/fd_type.h"
17 #include <iostream>
18 #include <map>
19 #include <string>
20 #include <vector>
21 
22 namespace fastdeploy {
23 
28  size_t max_batch_size = 32;
29 
31  size_t max_workspace_size = 1 << 30;
32 
34  bool enable_log_info = false;
35 
36 
38  bool enable_fp16 = false;
39 
47  void SetShape(const std::string& tensor_name,
48  const std::vector<int32_t>& min,
49  const std::vector<int32_t>& opt,
50  const std::vector<int32_t>& max) {
51  min_shape[tensor_name].clear();
52  max_shape[tensor_name].clear();
53  opt_shape[tensor_name].clear();
54  min_shape[tensor_name].assign(min.begin(), min.end());
55  if (opt.size() == 0) {
56  opt_shape[tensor_name].assign(min.begin(), min.end());
57  } else {
58  opt_shape[tensor_name].assign(opt.begin(), opt.end());
59  }
60  if (max.size() == 0) {
61  max_shape[tensor_name].assign(min.begin(), min.end());
62  } else {
63  max_shape[tensor_name].assign(max.begin(), max.end());
64  }
65  }
67  std::string serialize_file = "";
68 
69  // The below parameters may be removed in next version, please do not
70  // visit or use them directly
71  std::map<std::string, std::vector<int32_t>> max_shape;
72  std::map<std::string, std::vector<int32_t>> min_shape;
73  std::map<std::string, std::vector<int32_t>> opt_shape;
74  bool enable_pinned_memory = false;
75  void* external_stream_ = nullptr;
76  int gpu_id = 0;
77  std::string model_file = ""; // Path of model file
78  std::string params_file = ""; // Path of parameters file, can be empty
79  // format of input model
80  ModelFormat model_format = ModelFormat::AUTOREC;
81 };
82 
83 
84 } // namespace fastdeploy
bool enable_log_info
Enable log while converting onnx model to tensorrt.
Definition: option.h:34
std::string serialize_file
Set cache file path while use TensorRT backend. Loadding a Paddle/ONNX model and initialize TensorRT ...
Definition: option.h:67
Auto recognize the model format by model file name.
Definition: enum_variables.h:68
void SetShape(const std::string &tensor_name, const std::vector< int32_t > &min, const std::vector< int32_t > &opt, const std::vector< int32_t > &max)
Set shape range of input tensor for the model that contain dynamic input shape while using TensorRT b...
Definition: option.h:47
ModelFormat
Definition: enum_variables.h:67
size_t max_workspace_size
max_workspace_size for TensorRT
Definition: option.h:31
size_t max_batch_size
max_batch_size, it&#39;s deprecated in TensorRT 8.x
Definition: option.h:28
Option object to configure TensorRT backend.
Definition: option.h:26
bool enable_fp16
Enable half precison inference, on some device not support half precision, it will fallback to float3...
Definition: option.h:38
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16