mirror of
https://github.com/PaddlePaddle/FastDeploy.git
synced 2025-10-06 17:17:14 +08:00
@@ -27,19 +27,7 @@ SophgoBackend::~SophgoBackend() { bm_dev_free(handle_); }
|
||||
bool SophgoBackend::GetSDKAndDeviceVersion() { return true; }
|
||||
|
||||
/***************************************************************
|
||||
* @name BuildOption
|
||||
* @brief save option
|
||||
* @param SOPHGOTPU2BackendOption
|
||||
* @note None
|
||||
***************************************************************/
|
||||
void SophgoBackend::BuildOption(const SophgoBackendOption& option) {
|
||||
// this->option_ = option;
|
||||
// save cpu_name
|
||||
// this->option_.cpu_name = option.cpu_name;
|
||||
}
|
||||
|
||||
/***************************************************************
|
||||
* @name InitFromSophgo
|
||||
* @name Init
|
||||
* @brief Initialize Sophgo model
|
||||
* @param model_file: Binary data for the Sophgo model.
|
||||
* params_file: None
|
||||
@@ -47,8 +35,26 @@ void SophgoBackend::BuildOption(const SophgoBackendOption& option) {
|
||||
* @return bool
|
||||
* @note None
|
||||
***************************************************************/
|
||||
bool SophgoBackend::InitFromSophgo(const std::string& model_file,
|
||||
const SophgoBackendOption& option) {
|
||||
bool SophgoBackend::Init(const RuntimeOption& option) {
|
||||
if (option.model_from_memory_) {
|
||||
FDERROR << "SophgoBackend doesn't support load model from memory, please "
|
||||
"load model from disk."
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
if (option.model_format != ModelFormat::SOPHGO) {
|
||||
FDERROR << "SophgoBackend only supports model format SOPHGO, but now it's "
|
||||
<< option.model_format << "." << std::endl;
|
||||
return false;
|
||||
}
|
||||
if (option.device != Device::SOPHGOTPUD) {
|
||||
FDERROR << "SophgoBackend only supports device::SOPHGOTPUD, but now it's "
|
||||
<< option.device << "." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string model_file = option.model_file;
|
||||
|
||||
// LoadModel
|
||||
if (!this->LoadModel((char*)model_file.data())) {
|
||||
FDERROR << "load model failed" << std::endl;
|
||||
@@ -61,9 +67,6 @@ bool SophgoBackend::InitFromSophgo(const std::string& model_file,
|
||||
return false;
|
||||
}
|
||||
|
||||
// BuildOption
|
||||
this->BuildOption(option);
|
||||
|
||||
// GetModelInputOutputInfos
|
||||
if (!this->GetModelInputOutputInfos()) {
|
||||
FDERROR << "get model input output infos failed" << std::endl;
|
||||
|
@@ -30,12 +30,7 @@ class SophgoBackend : public BaseBackend {
|
||||
public:
|
||||
SophgoBackend() = default;
|
||||
virtual ~SophgoBackend();
|
||||
bool LoadModel(void* model);
|
||||
bool GetSDKAndDeviceVersion();
|
||||
bool GetModelInputOutputInfos();
|
||||
void BuildOption(const SophgoBackendOption& option);
|
||||
bool InitFromSophgo(const std::string& model_file,
|
||||
const SophgoBackendOption& option = SophgoBackendOption());
|
||||
bool Init(const RuntimeOption& option);
|
||||
|
||||
int NumInputs() const override {
|
||||
return static_cast<int>(inputs_desc_.size());
|
||||
@@ -54,6 +49,10 @@ class SophgoBackend : public BaseBackend {
|
||||
bool copy_to_fd = true) override;
|
||||
|
||||
private:
|
||||
bool LoadModel(void* model);
|
||||
bool GetSDKAndDeviceVersion();
|
||||
bool GetModelInputOutputInfos();
|
||||
|
||||
std::vector<TensorInfo> inputs_desc_;
|
||||
std::vector<TensorInfo> outputs_desc_;
|
||||
std::string net_name_;
|
||||
|
@@ -356,18 +356,8 @@ void Runtime::CreateRKNPU2Backend() {
|
||||
|
||||
void Runtime::CreateSophgoNPUBackend() {
|
||||
#ifdef ENABLE_SOPHGO_BACKEND
|
||||
auto sophgo_option = SophgoBackendOption();
|
||||
FDASSERT(option.model_from_memory_ == false,
|
||||
"SophgoBackend don't support to load model from memory");
|
||||
FDASSERT(option.device == Device::SOPHGOTPUD,
|
||||
"Backend::SOPHGO only supports Device::SOPHGO");
|
||||
FDASSERT(option.model_format == ModelFormat::SOPHGO,
|
||||
"SophgoBackend only support model format of ModelFormat::SOPHGO");
|
||||
auto sophgo_option = SophgoBackendOption();
|
||||
backend_ = utils::make_unique<SophgoBackend>();
|
||||
auto casted_backend = dynamic_cast<SophgoBackend*>(backend_.get());
|
||||
FDASSERT(casted_backend->InitFromSophgo(option.model_file, sophgo_option),
|
||||
"Load model from nb file failed while initializing LiteBackend.");
|
||||
FDASSERT(backend_->Init(option), "Failed to initialize Sophgo backend.");
|
||||
#else
|
||||
FDASSERT(false,
|
||||
"SophgoBackend is not available, please compiled with "
|
||||
|
Reference in New Issue
Block a user