22 #include "fastdeploy/core/fd_tensor.h" 23 #include "fastdeploy/core/fd_type.h" 25 #include "fastdeploy/benchmark/benchmark.h" 36 friend std::ostream& operator<<(std::ostream& output,
38 output <<
"TensorInfo(name: " << info.
name <<
", shape: [";
39 for (
size_t i = 0; i < info.
shape.size(); ++i) {
40 if (i == info.
shape.size() - 1) {
41 output << info.
shape[i];
43 output << info.
shape[i] <<
", ";
46 output <<
"], dtype: " << Str(info.
dtype) <<
")";
53 bool initialized_ =
false;
56 virtual ~BaseBackend() =
default;
58 virtual bool Initialized()
const {
return initialized_; }
61 FDERROR <<
"Not Implement for " 62 << option.backend <<
" in " 63 << option.device <<
"." 69 virtual int NumInputs()
const = 0;
71 virtual int NumOutputs()
const = 0;
73 virtual TensorInfo GetInputInfo(
int index) = 0;
75 virtual TensorInfo GetOutputInfo(
int index) = 0;
77 virtual std::vector<TensorInfo> GetInputInfos() = 0;
79 virtual std::vector<TensorInfo> GetOutputInfos() = 0;
83 virtual bool Infer(std::vector<FDTensor>& inputs,
84 std::vector<FDTensor>* outputs,
85 bool copy_to_fd =
true) = 0;
88 virtual std::unique_ptr<BaseBackend> Clone(
RuntimeOption& runtime_option,
89 void* stream =
nullptr,
91 FDERROR <<
"Clone no support " << runtime_option.backend <<
" " << stream <<
" " << device_id << std::endl;
95 benchmark::BenchmarkOption benchmark_option_;
151 #define RUNTIME_PROFILE_LOOP_BEGIN(base_loop) \ 152 __RUNTIME_PROFILE_LOOP_BEGIN(benchmark_option_, (base_loop)) 153 #define RUNTIME_PROFILE_LOOP_END \ 154 __RUNTIME_PROFILE_LOOP_END(benchmark_result_) 155 #define RUNTIME_PROFILE_LOOP_H2D_D2H_BEGIN \ 156 __RUNTIME_PROFILE_LOOP_H2D_D2H_BEGIN(benchmark_option_, 1) 157 #define RUNTIME_PROFILE_LOOP_H2D_D2H_END \ 158 __RUNTIME_PROFILE_LOOP_H2D_D2H_END(benchmark_result_) Option object used when create a new Runtime object.
Definition: runtime_option.h:40
A brief file description. More details.
std::string name
Name of tensor.
Definition: backend.h:32
Information of Tensor.
Definition: backend.h:31
FDDataType dtype
Data type of tensor.
Definition: backend.h:34
std::vector< int > shape
Shape of tensor.
Definition: backend.h:33
All C++ FastDeploy APIs are defined inside this namespace.
Definition: option.h:16
Result object used to record the time of runtime after benchmark profiling is done.
Definition: results.h:21