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 
17 #include "fastdeploy/core/fd_type.h"
18 #include <iostream>
19 #include <memory>
20 #include <string>
21 #include <vector>
22 #include "fastdeploy/runtime/backends/tensorrt/option.h"
23 
24 
25 namespace fastdeploy {
26 
29 struct IpuOption {
46 };
47 
52  bool enable_log_info = false;
54  bool enable_mkldnn = true;
56  bool enable_trt = false;
58  bool enable_memory_optimize = true;
60  bool switch_ir_debug = false;
61 
62  /*
63  * @brief IPU option, this will configure the IPU hardware, if inference model in IPU
64  */
65  IpuOption ipu_option;
66 
68  bool collect_trt_shape = false;
70  int mkldnn_cache_size = -1;
72  int gpu_mem_init_size = 100;
74  bool enable_fixed_size_opt = false;
75 
77  void DisableTrtOps(const std::vector<std::string>& ops) {
78  trt_disabled_ops_.insert(trt_disabled_ops_.end(), ops.begin(), ops.end());
79  }
80 
82  void DeletePass(const std::string& pass_name) {
83  delete_pass_names.push_back(pass_name);
84  }
85 
86  void SetIpuConfig(bool enable_fp16, int replica_num,
87  float available_memory_proportion,
88  bool enable_half_partial) {
89  ipu_option.ipu_enable_fp16 = enable_fp16;
90  ipu_option.ipu_replica_num = replica_num;
92  available_memory_proportion;
93  ipu_option.ipu_enable_half_partial = enable_half_partial;
94  }
95 
96  // The belowing parameters may be removed, please do not
97  // read or write them directly
98  TrtBackendOption trt_option;
99  bool enable_pinned_memory = false;
100  void* external_stream_ = nullptr;
101  Device device = Device::CPU;
102  int device_id = 0;
103  std::vector<std::string> trt_disabled_ops_{};
104  int cpu_thread_num = 8;
105  std::vector<std::string> delete_pass_names = {};
106  std::string model_file = ""; // Path of model file
107  std::string params_file = ""; // Path of parameters file, can be empty
108 
109  // load model and paramters from memory
110  bool model_from_memory_ = false;
111 };
112 } // namespace fastdeploy
void DisableTrtOps(const std::vector< std::string > &ops)
Disable type of operators run on TensorRT.
Definition: option.h:77
void DeletePass(const std::string &pass_name)
Delete pass by name.
Definition: option.h:82
float ipu_available_memory_proportion
the available memory proportion for matmul/conv
Definition: option.h:43
Option object to configure Paddle Inference backend.
Definition: option.h:50
bool ipu_enable_fp16
enable fp16
Definition: option.h:39
bool ipu_enable_pipelining
enable pipelining
Definition: option.h:35
int ipu_micro_batch_size
the batch size in the graph, only work when graph has no batch shape info
Definition: option.h:33
bool ipu_enable_half_partial
enable fp16 partial for matmul, only work with fp16
Definition: option.h:45
int ipu_device_num
IPU device id.
Definition: option.h:31
int ipu_batches_per_step
the number of batches per run in pipelining
Definition: option.h:37
int ipu_replica_num
the number of graph replication
Definition: option.h:41
Option object to configure TensorRT backend.
Definition: option.h:26
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
Option object to configure GraphCore IPU.
Definition: option.h:29