|
|
|
@ -209,34 +209,20 @@ bool IsDynmaicDimsSizeMatchModel(const vector<uint64_t> cur_dynamic_dims,
|
|
|
|
|
|
|
|
|
|
namespace ge {
|
|
|
|
|
bool GeExecutor::isInit_ = false;
|
|
|
|
|
|
|
|
|
|
static void InitOpsProtoManger() {
|
|
|
|
|
string opsproto_path;
|
|
|
|
|
const char *path_env = std::getenv("ASCEND_OPP_PATH");
|
|
|
|
|
if (path_env != nullptr) {
|
|
|
|
|
string path = path_env;
|
|
|
|
|
string file_path = RealPath(path.c_str());
|
|
|
|
|
if (file_path.empty()) {
|
|
|
|
|
GELOGE(FAILED, "File path %s is invalid.", path.c_str());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
opsproto_path = (path + "/op_proto/custom/" + ":") + (path + "/op_proto/built-in/");
|
|
|
|
|
GELOGI("Get opsproto so path from env : %s", path.c_str());
|
|
|
|
|
} else {
|
|
|
|
|
string path_base = PluginManager::GetPath();
|
|
|
|
|
GELOGI("path_base is %s", path_base.c_str());
|
|
|
|
|
path_base = path_base.substr(0, path_base.rfind('/'));
|
|
|
|
|
path_base = path_base.substr(0, path_base.rfind('/') + 1);
|
|
|
|
|
opsproto_path = (path_base + "ops/op_proto/custom/" + ":") + (path_base + "ops/op_proto/built-in/");
|
|
|
|
|
class ModelListenerAdapter : public ModelListener {
|
|
|
|
|
public:
|
|
|
|
|
domi::Status OnComputeDone(uint32_t model_id, uint32_t dataIndex, uint32_t resultCode,
|
|
|
|
|
std::vector<ge::OutputTensorInfo> &outputs) {
|
|
|
|
|
if (listener == nullptr) {
|
|
|
|
|
GELOGE(ge::FAILED, "listener is null.");
|
|
|
|
|
return FAILED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GELOGI("Get opsproto path is %s", opsproto_path.c_str());
|
|
|
|
|
OpsProtoManager *manager = OpsProtoManager::Instance();
|
|
|
|
|
map<string, string> option_tmp;
|
|
|
|
|
option_tmp.emplace(std::pair<string, string>(string("ge.opsProtoLibPath"), opsproto_path));
|
|
|
|
|
(void)manager->Initialize(option_tmp);
|
|
|
|
|
return listener->OnComputeDone(model_id, dataIndex, resultCode, outputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ge::ModelListener> listener;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
GeExecutor::GeExecutor() {}
|
|
|
|
|
|
|
|
|
|
Status GeExecutor::Initialize() {
|
|
|
|
@ -246,16 +232,6 @@ Status GeExecutor::Initialize() {
|
|
|
|
|
return ge::SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpTilingManager::GetInstance().LoadSo();
|
|
|
|
|
|
|
|
|
|
Status initHostCpuEngineStatus = HostCpuEngine::GetInstance().Initialize();
|
|
|
|
|
if (initHostCpuEngineStatus != SUCCESS) {
|
|
|
|
|
GELOGE(initHostCpuEngineStatus, "Failed to initialize HostCpuEngine");
|
|
|
|
|
return initHostCpuEngineStatus;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InitOpsProtoManger();
|
|
|
|
|
|
|
|
|
|
std::vector<rtMemType_t> mem_type(1, RT_MEMORY_HBM);
|
|
|
|
|
mem_type.push_back(RT_MEMORY_P2P_DDR);
|
|
|
|
|
auto ret = MemManager::Instance().Initialize(mem_type);
|
|
|
|
@ -560,6 +536,60 @@ Status GeExecutor::SetDynamicAippData(uint32_t model_id, void *dynamic_input_add
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Load model
|
|
|
|
|
Status GeExecutor::LoadModelOffline(uint32_t &model_id, const std::string &path, const std::string &key,
|
|
|
|
|
int32_t priority, std::shared_ptr<ge::ModelListener> listener) {
|
|
|
|
|
GELOGI("load model offline begin.");
|
|
|
|
|
if (!isInit_) {
|
|
|
|
|
GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
|
|
|
|
|
return ACL_ERROR_GE_EXEC_NOT_INIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string filePath = RealPath(path.c_str());
|
|
|
|
|
if (filePath.empty()) {
|
|
|
|
|
GELOGE(ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID,
|
|
|
|
|
"File path is invalid. please check your text file '%s'.", path.c_str());
|
|
|
|
|
return ACL_ERROR_GE_EXEC_MODEL_PATH_INVALID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ModelListenerAdapter> listener_adapter = MakeShared<ModelListenerAdapter>();
|
|
|
|
|
if (listener_adapter == nullptr) {
|
|
|
|
|
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelListenerAdapter make shared failed!");
|
|
|
|
|
return ACL_ERROR_GE_MEMORY_ALLOCATION;
|
|
|
|
|
}
|
|
|
|
|
listener_adapter->listener = listener;
|
|
|
|
|
|
|
|
|
|
Status ret = GraphLoader::LoadModelFromFile(path, key, priority, listener_adapter, model_id);
|
|
|
|
|
if (ret != SUCCESS) {
|
|
|
|
|
GELOGE(ret, "[GeExecutor] LoadModelFromFile failed");
|
|
|
|
|
return ACL_ERROR_GE_LOAD_MODEL;
|
|
|
|
|
}
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Status GeExecutor::LoadModel(uint32_t &model_id, const ModelData &model_data,
|
|
|
|
|
std::shared_ptr<ge::ModelListener> listener) {
|
|
|
|
|
GELOGI("Load model begin.");
|
|
|
|
|
if (!isInit_) {
|
|
|
|
|
GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
|
|
|
|
|
return ACL_ERROR_GE_EXEC_NOT_INIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<ModelListenerAdapter> listener_adapter = MakeShared<ModelListenerAdapter>();
|
|
|
|
|
if (listener_adapter == nullptr) {
|
|
|
|
|
GELOGE(ACL_ERROR_GE_MEMORY_ALLOCATION, "ModelListenerAdapter make shared failed!");
|
|
|
|
|
return ACL_ERROR_GE_MEMORY_ALLOCATION;
|
|
|
|
|
}
|
|
|
|
|
listener_adapter->listener = listener;
|
|
|
|
|
|
|
|
|
|
Status ret = GraphLoader::LoadModel(model_data, listener_adapter, model_id);
|
|
|
|
|
if (ret != SUCCESS) {
|
|
|
|
|
GELOGE(ret, "[GeExecutor] LoadModel failed.");
|
|
|
|
|
return ACL_ERROR_GE_LOAD_MODEL;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Status GeExecutor::UnloadModel(uint32_t model_id) {
|
|
|
|
|
GELOGD("unload model %u begin.", model_id);
|
|
|
|
|
if (!isInit_) {
|
|
|
|
@ -592,6 +622,21 @@ Status GeExecutor::UnloadModel(uint32_t model_id) {
|
|
|
|
|
return SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Status GeExecutor::RunModel(const ge::RunModelData &input_data, ge::RunModelData &output_data) {
|
|
|
|
|
GELOGI("run model begin.");
|
|
|
|
|
if (!isInit_) {
|
|
|
|
|
GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "GeExecutor has not been initialized!");
|
|
|
|
|
return ACL_ERROR_GE_EXEC_NOT_INIT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InputData inputs;
|
|
|
|
|
GetDomiInputData(input_data, inputs);
|
|
|
|
|
OutputData outputs;
|
|
|
|
|
GetDomiOutputData(output_data, outputs);
|
|
|
|
|
|
|
|
|
|
return GraphExecutor::DataInput(inputs, outputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get input and output descriptor
|
|
|
|
|
Status GeExecutor::GetModelDescInfo(uint32_t model_id, std::vector<ge::TensorDesc> &input_desc,
|
|
|
|
|
std::vector<ge::TensorDesc> &output_desc, bool new_model_desc) {
|
|
|
|
|