FastDeploy  latest
Fast & Easy to Deploy!
enum_variables.h
Go to the documentation of this file.
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 
21 #pragma once
22 #include "fastdeploy/utils/utils.h"
23 #include <ostream>
24 #include <map>
25 
26 namespace fastdeploy {
27 
28 
30 enum Backend {
32  ORT, //< ONNX Runtime, support Paddle/ONNX format model,
33  //< CPU/ Nvidia GPU DirectML
34  TRT,
38  LITE,
41 };
42 
46 FASTDEPLOY_DECL std::vector<Backend> GetAvailableBackends();
47 
51 FASTDEPLOY_DECL bool IsBackendAvailable(const Backend& backend);
52 
53 
54 enum FASTDEPLOY_DECL Device {
55  CPU,
56  GPU,
57  RKNPU,
58  IPU,
59  TIMVX,
60  KUNLUNXIN,
61  ASCEND,
62  SOPHGOTPUD,
63  DIRECTML
64 };
65 
70  ONNX,
71  RKNN,
74 };
75 
77 static std::map<ModelFormat, std::vector<Backend>>
78  s_default_backends_by_format = {
80  Backend::ORT, Backend::OPENVINO, Backend::TRT}},
81  {ModelFormat::ONNX, {Backend::ORT, Backend::OPENVINO, Backend::TRT}},
85 };
86 
88 static std::map<Device, std::vector<Backend>>
89  s_default_backends_by_device = {
90  {Device::CPU, {Backend::LITE, Backend::PDINFER, Backend::ORT,
92  {Device::GPU, {Backend::PDINFER, Backend::ORT, Backend::TRT, Backend::POROS}},
93  {Device::RKNPU, {Backend::RKNPU2}},
94  {Device::IPU, {Backend::PDINFER}},
95  {Device::TIMVX, {Backend::LITE}},
96  {Device::KUNLUNXIN, {Backend::LITE}},
97  {Device::ASCEND, {Backend::LITE}},
98  {Device::SOPHGOTPUD, {Backend::SOPHGOTPU}},
99  {Device::DIRECTML, {Backend::ORT}}
100 };
101 
102 inline bool Supported(ModelFormat format, Backend backend) {
103  auto iter = s_default_backends_by_format.find(format);
104  if (iter == s_default_backends_by_format.end()) {
105  FDERROR << "Didn't find format is registered in " <<
106  "s_default_backends_by_format." << std::endl;
107  return false;
108  }
109  for (size_t i = 0; i < iter->second.size(); ++i) {
110  if (iter->second[i] == backend) {
111  return true;
112  }
113  }
114  std::string msg = Str(iter->second);
115  FDERROR << backend << " only supports " << msg << ", but now it's "
116  << format << "." << std::endl;
117  return false;
118 }
119 
120 inline bool Supported(Device device, Backend backend) {
121  auto iter = s_default_backends_by_device.find(device);
122  if (iter == s_default_backends_by_device.end()) {
123  FDERROR << "Didn't find device is registered in " <<
124  "s_default_backends_by_device." << std::endl;
125  return false;
126  }
127  for (size_t i = 0; i < iter->second.size(); ++i) {
128  if (iter->second[i] == backend) {
129  return true;
130  }
131  }
132  std::string msg = Str(iter->second);
133  FDERROR << backend << " only supports " << msg << ", but now it's "
134  << device << "." << std::endl;
135  return false;
136 }
137 
138 FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& o, const Backend& b);
139 FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& o, const Device& d);
140 FASTDEPLOY_DECL std::ostream& operator<<(std::ostream& o, const ModelFormat& f);
141 } // namespace fastdeploy
Model with SOPHGO format.
Definition: enum_variables.h:73
Paddle Inference, support Paddle format model, CPU / Nvidia GPU.
Definition: enum_variables.h:35
Auto recognize the model format by model file name.
Definition: enum_variables.h:68
ModelFormat
Definition: enum_variables.h:67
Backend
Definition: enum_variables.h:30
Poros, support TorchScript format model, CPU / Nvidia GPU.
Definition: enum_variables.h:36
TensorRT, support Paddle/ONNX format model, Nvidia GPU only.
Definition: enum_variables.h:34
RKNPU2, support RKNN format model, Rockchip NPU only.
Definition: enum_variables.h:39
Model with RKNN format.
Definition: enum_variables.h:71
bool IsBackendAvailable(const Backend &backend)
Check if the inference backend available.
Definition: enum_variables.cc:119
Paddle Lite, support Paddle format model, ARM CPU only.
Definition: enum_variables.h:38
Intel OpenVINO, support Paddle/ONNX format, CPU only.
Definition: enum_variables.h:37
SOPHGOTPU, support SOPHGO format model, Sophgo TPU only.
Definition: enum_variables.h:40
Model with ONNX format.
Definition: enum_variables.h:70
Model with paddlepaddle format.
Definition: enum_variables.h:69
Model with TorchScript format.
Definition: enum_variables.h:72
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
Unknown inference backend.
Definition: enum_variables.h:31
std::vector< Backend > GetAvailableBackends()
Get all the available inference backend in FastDeploy.
Definition: enum_variables.cc:90