FastDeploy  latest
Fast & Easy to Deploy!
runtime.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 
21 #pragma once
22 #include "fastdeploy/runtime/backends/backend.h"
23 #include "fastdeploy/core/fd_tensor.h"
25 #include "fastdeploy/utils/perf.h"
26 #ifdef ENABLE_ENCRYPTION
27 #include "fastdeploy/encryption/include/decrypt.h"
28 #endif
29 
33 namespace fastdeploy {
34 
37 struct FASTDEPLOY_DECL Runtime {
38  public:
40  bool Init(const RuntimeOption& _option);
41 
48  bool Infer(std::vector<FDTensor>& input_tensors,
49  std::vector<FDTensor>* output_tensors);
50 
55  bool Infer();
56 
59  int NumInputs() { return backend_->NumInputs(); }
62  int NumOutputs() { return backend_->NumOutputs(); }
65  TensorInfo GetInputInfo(int index);
68  TensorInfo GetOutputInfo(int index);
71  std::vector<TensorInfo> GetInputInfos();
74  std::vector<TensorInfo> GetOutputInfos();
77  void BindInputTensor(const std::string& name, FDTensor& input);
78 
82  void BindOutputTensor(const std::string& name, FDTensor& output);
83 
86  FDTensor* GetOutputTensor(const std::string& name);
87 
93  Runtime* Clone(void* stream = nullptr, int device_id = -1);
94 
95  void ReleaseModelMemoryBuffer();
96 
97  RuntimeOption option;
98 
104  bool Compile(std::vector<std::vector<FDTensor>>& prewarm_tensors);
107  double GetProfileTime() {
108  return backend_->benchmark_result_.time_of_runtime;
109  }
110 
111  private:
112  void CreateOrtBackend();
113  void CreatePaddleBackend();
114  void CreateTrtBackend();
115  void CreateOpenVINOBackend();
116  void CreateLiteBackend();
117  void CreateRKNPU2Backend();
118  void CreateSophgoNPUBackend();
119  void CreatePorosBackend();
120  std::unique_ptr<BaseBackend> backend_;
121  std::vector<FDTensor> input_tensors_;
122  std::vector<FDTensor> output_tensors_;
123 };
124 } // namespace fastdeploy
Runtime object used to inference the loaded model on different devices.
Definition: runtime.h:37
int NumOutputs()
Get number of outputs.
Definition: runtime.h:62
Option object used when create a new Runtime object.
Definition: runtime_option.h:40
A brief file description. More details.
FDTensor object used to represend data matrix.
Definition: fd_tensor.h:31
double GetProfileTime()
Get profile time of Runtime after the profile process is done.
Definition: runtime.h:107
Information of Tensor.
Definition: backend.h:31
int NumInputs()
Get number of inputs.
Definition: runtime.h:59
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16