|
|
@ -32,6 +32,7 @@
|
|
|
|
#include "graph/common/ge_call_wrapper.h"
|
|
|
|
#include "graph/common/ge_call_wrapper.h"
|
|
|
|
#include "register/op_registry.h"
|
|
|
|
#include "register/op_registry.h"
|
|
|
|
#include "common/ge/tbe_plugin_manager.h"
|
|
|
|
#include "common/ge/tbe_plugin_manager.h"
|
|
|
|
|
|
|
|
#include "common/util/error_manager/error_manager.h"
|
|
|
|
#include "toolchain/plog.h"
|
|
|
|
#include "toolchain/plog.h"
|
|
|
|
|
|
|
|
|
|
|
|
using domi::OpRegistry;
|
|
|
|
using domi::OpRegistry;
|
|
|
@ -79,6 +80,8 @@ Status CheckOptionsValid(const std::map<string, string> &options) {
|
|
|
|
// Initialize GE, prepare for execution, call GELib::Initialize
|
|
|
|
// Initialize GE, prepare for execution, call GELib::Initialize
|
|
|
|
Status GEInitializeImpl(const std::map<string, string> &options) {
|
|
|
|
Status GEInitializeImpl(const std::map<string, string> &options) {
|
|
|
|
GELOGT(TRACE_INIT, "GEInitialize start");
|
|
|
|
GELOGT(TRACE_INIT, "GEInitialize start");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
// 0.check init status
|
|
|
|
// 0.check init status
|
|
|
|
if (g_ge_initialized) {
|
|
|
|
if (g_ge_initialized) {
|
|
|
|
GELOGW("GEInitialize is called more than once");
|
|
|
|
GELOGW("GEInitialize is called more than once");
|
|
|
@ -157,6 +160,8 @@ Status GEInitialize(const std::map<AscendString, AscendString> &options) {
|
|
|
|
// GE finalize, releasing all resources
|
|
|
|
// GE finalize, releasing all resources
|
|
|
|
Status GEFinalize() {
|
|
|
|
Status GEFinalize() {
|
|
|
|
GELOGT(TRACE_INIT, "GEFinalize start");
|
|
|
|
GELOGT(TRACE_INIT, "GEFinalize start");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
// check init status
|
|
|
|
// check init status
|
|
|
|
if (!g_ge_initialized) {
|
|
|
|
if (!g_ge_initialized) {
|
|
|
|
GELOGW("GEFinalize is called before GEInitialize");
|
|
|
|
GELOGW("GEFinalize is called before GEInitialize");
|
|
|
@ -202,9 +207,19 @@ Status GEFinalize() {
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string GEGetErrorMsg() {
|
|
|
|
|
|
|
|
return ErrorManager::GetInstance().GetErrorMessage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::string GEGetWarningMsg() {
|
|
|
|
|
|
|
|
return ErrorManager::GetInstance.GetWarningMessage();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize session,which calls innerSession
|
|
|
|
// Initialize session,which calls innerSession
|
|
|
|
Session::Session(const std::map<string, string> &options) {
|
|
|
|
Session::Session(const std::map<string, string> &options) {
|
|
|
|
GELOGT(TRACE_INIT, "Session Constructor start");
|
|
|
|
GELOGT(TRACE_INIT, "Session Constructor start");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
// check init status
|
|
|
|
// check init status
|
|
|
|
sessionId_ = 0;
|
|
|
|
sessionId_ = 0;
|
|
|
|
if (!g_ge_initialized) {
|
|
|
|
if (!g_ge_initialized) {
|
|
|
@ -235,6 +250,8 @@ Session::Session(const std::map<string, string> &options) {
|
|
|
|
|
|
|
|
|
|
|
|
Session::Session(const std::map<AscendString, AscendString> &options) {
|
|
|
|
Session::Session(const std::map<AscendString, AscendString> &options) {
|
|
|
|
GELOGT(TRACE_INIT, "Session Constructor start");
|
|
|
|
GELOGT(TRACE_INIT, "Session Constructor start");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
// check init status
|
|
|
|
// check init status
|
|
|
|
sessionId_ = 0;
|
|
|
|
sessionId_ = 0;
|
|
|
|
if (!g_ge_initialized) {
|
|
|
|
if (!g_ge_initialized) {
|
|
|
@ -311,11 +328,13 @@ Session::~Session() {
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::AddGraph(uint32_t graph_id, const Graph &graph) {
|
|
|
|
Status Session::AddGraph(uint32_t graph_id, const Graph &graph) {
|
|
|
|
std::map<std::string, std::string> options;
|
|
|
|
std::map<std::string, std::string> options;
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
return AddGraph(graph_id, graph, options);
|
|
|
|
return AddGraph(graph_id, graph, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::AddGraph(uint32_t graph_id, const Graph &graph, const std::map<std::string, std::string> &options) {
|
|
|
|
Status Session::AddGraph(uint32_t graph_id, const Graph &graph, const std::map<std::string, std::string> &options) {
|
|
|
|
GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_);
|
|
|
|
GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_);
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session.");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session.");
|
|
|
@ -334,6 +353,7 @@ Status Session::AddGraph(uint32_t graph_id, const Graph &graph, const std::map<s
|
|
|
|
Status Session::AddGraph(uint32_t graph_id, const Graph &graph,
|
|
|
|
Status Session::AddGraph(uint32_t graph_id, const Graph &graph,
|
|
|
|
const std::map<AscendString, AscendString> &options) {
|
|
|
|
const std::map<AscendString, AscendString> &options) {
|
|
|
|
GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_);
|
|
|
|
GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_);
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session.");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session.");
|
|
|
@ -360,6 +380,7 @@ Status Session::AddGraph(uint32_t graph_id, const Graph &graph,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph) {
|
|
|
|
Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::map<AscendString, AscendString> options;
|
|
|
|
std::map<AscendString, AscendString> options;
|
|
|
|
return AddGraphWithCopy(graph_id, graph, options);
|
|
|
|
return AddGraphWithCopy(graph_id, graph, options);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -367,6 +388,7 @@ Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph) {
|
|
|
|
Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph,
|
|
|
|
Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph,
|
|
|
|
const std::map<AscendString, AscendString> &options) {
|
|
|
|
const std::map<AscendString, AscendString> &options) {
|
|
|
|
GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_);
|
|
|
|
GELOGT(TRACE_INIT, "Start to add graph in Session. graph_id: %u, session_id: %lu.", graph_id, sessionId_);
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session.");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "AddGraph failed in Session.");
|
|
|
@ -389,6 +411,7 @@ Status Session::AddGraphWithCopy(uint32_t graph_id, const Graph &graph,
|
|
|
|
Status Session::RemoveGraph(uint32_t graph_id) {
|
|
|
|
Status Session::RemoveGraph(uint32_t graph_id) {
|
|
|
|
GELOGT(TRACE_INIT, "Session RemoveGraph start");
|
|
|
|
GELOGT(TRACE_INIT, "Session RemoveGraph start");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
// call RemoveGraph
|
|
|
|
// call RemoveGraph
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (!instance_ptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (!instance_ptr || !instance_ptr->InitFlag()) {
|
|
|
@ -457,6 +480,7 @@ void PrintOutputResult(std::vector<Tensor> &outputs) {
|
|
|
|
Status Session::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs) {
|
|
|
|
Status Session::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, std::vector<Tensor> &outputs) {
|
|
|
|
GELOGT(TRACE_INIT, "Session RunGraph start");
|
|
|
|
GELOGT(TRACE_INIT, "Session RunGraph start");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::vector<Tensor> graph_inputs = inputs;
|
|
|
|
std::vector<Tensor> graph_inputs = inputs;
|
|
|
|
// call RunGraph
|
|
|
|
// call RunGraph
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
@ -483,10 +507,12 @@ Status Session::RunGraph(uint32_t graph_id, const std::vector<Tensor> &inputs, s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback) {
|
|
|
|
Status Session::RegisterCallBackFunc(const std::string &key, const pCallBackFunc &callback) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
return ge::GELib::GetInstance()->SessionManagerObj().RegisterCallBackFunc(sessionId_, key, callback);
|
|
|
|
return ge::GELib::GetInstance()->SessionManagerObj().RegisterCallBackFunc(sessionId_, key, callback);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback) {
|
|
|
|
Status Session::RegisterCallBackFunc(const char *key, const session::pCallBackFunc &callback) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
std::string str_key;
|
|
|
|
std::string str_key;
|
|
|
|
if (key != nullptr) {
|
|
|
|
if (key != nullptr) {
|
|
|
|
str_key = key;
|
|
|
|
str_key = key;
|
|
|
@ -495,6 +521,7 @@ Status Session::RegisterCallBackFunc(const char *key, const session::pCallBackFu
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs) {
|
|
|
|
Status Session::BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
@ -511,6 +538,7 @@ Status Session::BuildGraph(uint32_t graph_id, const std::vector<InputTensorInfo>
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::RunGraphAsync(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs,
|
|
|
|
Status Session::RunGraphAsync(uint32_t graph_id, const std::vector<InputTensorInfo> &inputs,
|
|
|
|
RunAsyncCallback callback) {
|
|
|
|
RunAsyncCallback callback) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdBySessionGraph(sessionId_, graph_id);
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
std::shared_ptr<GELib> instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
@ -529,6 +557,7 @@ Status Session::RunGraphAsync(uint32_t graph_id, const std::vector<InputTensorIn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::GetVariables(const std::vector<std::string> &var_names, std::vector<Tensor> &var_values) {
|
|
|
|
Status Session::GetVariables(const std::vector<std::string> &var_names, std::vector<Tensor> &var_values) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
auto instance_ptr = ge::GELib::GetInstance();
|
|
|
|
auto instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
@ -544,6 +573,7 @@ Status Session::GetVariables(const std::vector<std::string> &var_names, std::vec
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Status Session::GetVariables(const std::vector<AscendString> &var_names, std::vector<Tensor> &var_values) {
|
|
|
|
Status Session::GetVariables(const std::vector<AscendString> &var_names, std::vector<Tensor> &var_values) {
|
|
|
|
|
|
|
|
ErrorManager::GetInstance().GenWorkStreamIdDefault();
|
|
|
|
auto instance_ptr = ge::GELib::GetInstance();
|
|
|
|
auto instance_ptr = ge::GELib::GetInstance();
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
if (instance_ptr == nullptr || !instance_ptr->InitFlag()) {
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
|
GELOGE(GE_CLI_GE_NOT_INITIALIZED, "SessionConstructor failed");
|
|
|
|