mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-05 16:48:03 +08:00
68 lines
2.5 KiB
C++
68 lines
2.5 KiB
C++
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
#pragma once
|
|
#include "fastdeploy/fastdeploy_runtime.h"
|
|
|
|
namespace fastdeploy {
|
|
|
|
class FASTDEPLOY_DECL FastDeployModel {
|
|
public:
|
|
virtual std::string ModelName() const { return "NameUndefined"; };
|
|
|
|
virtual bool InitRuntime();
|
|
virtual bool CreateCpuBackend();
|
|
virtual bool CreateGpuBackend();
|
|
virtual bool Infer(std::vector<FDTensor>& input_tensors,
|
|
std::vector<FDTensor>* output_tensors);
|
|
|
|
RuntimeOption runtime_option;
|
|
std::vector<Backend> valid_cpu_backends = {Backend::ORT};
|
|
std::vector<Backend> valid_gpu_backends = {Backend::ORT};
|
|
std::vector<Backend> valid_external_backends;
|
|
bool initialized = false;
|
|
virtual int NumInputsOfRuntime() { return runtime_->NumInputs(); }
|
|
virtual int NumOutputsOfRuntime() { return runtime_->NumOutputs(); }
|
|
virtual TensorInfo InputInfoOfRuntime(int index) {
|
|
return runtime_->GetInputInfo(index);
|
|
}
|
|
virtual TensorInfo OutputInfoOfRuntime(int index) {
|
|
return runtime_->GetOutputInfo(index);
|
|
}
|
|
virtual bool Initialized() const {
|
|
return runtime_initialized_ && initialized;
|
|
}
|
|
|
|
virtual void EnableDebug();
|
|
virtual bool DebugEnabled();
|
|
|
|
private:
|
|
Runtime* runtime_ = nullptr;
|
|
bool runtime_initialized_ = false;
|
|
bool debug_ = false;
|
|
};
|
|
|
|
#define TIMERECORD_START(id) \
|
|
TimeCounter tc_##id; \
|
|
tc_##id.Start();
|
|
|
|
#define TIMERECORD_END(id, prefix) \
|
|
if (DebugEnabled()) { \
|
|
tc_##id.End(); \
|
|
FDLogger() << __FILE__ << "(" << __LINE__ << "):" << __FUNCTION__ << " " \
|
|
<< prefix << " duration = " << tc_##id.Duration() << "s." \
|
|
<< std::endl; \
|
|
}
|
|
|
|
} // namespace fastdeploy
|