@@ -731,6 +731,23 @@ Status GeExecutor::GetAippType(uint32_t model_id, uint32_t index, InputAippType | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status GeExecutor::GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) { | |||||
GELOGI("Begin to get op attr."); | |||||
if (!isInit_) { | |||||
GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "[Init][GeExecutor]Ge executor not inited yet!"); | |||||
REPORT_INNER_ERROR("E19999", "Ge executor not inited yet!"); | |||||
return ACL_ERROR_GE_EXEC_NOT_INIT; | |||||
} | |||||
Status ret = GraphExecutor::GetOpAttr(model_id, op_name, attr_name, attr_value); | |||||
if (ret != SUCCESS) { | |||||
GELOGE(ret, "[Get][OpAttr]Get op:%s attr:%s failed.", op_name.c_str(), attr_name.c_str()); | |||||
REPORT_CALL_ERROR("E19999", "Get op:%s attr:%s failed.", op_name.c_str(), attr_name.c_str()); | |||||
return ret; | |||||
} | |||||
return SUCCESS; | |||||
} | |||||
Status GeExecutor::GetModelAttr(uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info) { | Status GeExecutor::GetModelAttr(uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info) { | ||||
if (!isInit_) { | if (!isInit_) { | ||||
GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); | GELOGE(ACL_ERROR_GE_EXEC_NOT_INIT, "not inited yet!"); | ||||
@@ -637,6 +637,19 @@ Status GraphExecutor::GetCurShape(const uint32_t model_id, std::vector<int64_t> | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status GraphExecutor::GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) { | |||||
auto model_manager = ge::ModelManager::GetInstance(); | |||||
GE_CHECK_NOTNULL(model_manager); | |||||
Status ret = model_manager->GetOpAttr(model_id, op_name, attr_name, attr_value); | |||||
if (ret != SUCCESS) { | |||||
GELOGE(ret, "[Get][OpAttr]Get op:%s attr:%s failed.", op_name.c_str(), attr_name.c_str()); | |||||
REPORT_CALL_ERROR("E19999", "Get op:%s attr:%s failed.", op_name.c_str(), attr_name.c_str()); | |||||
return ret; | |||||
} | |||||
return SUCCESS; | |||||
} | |||||
Status GraphExecutor::GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info) { | Status GraphExecutor::GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info) { | ||||
auto model_manager = ge::ModelManager::GetInstance(); | auto model_manager = ge::ModelManager::GetInstance(); | ||||
GE_CHECK_NOTNULL(model_manager); | GE_CHECK_NOTNULL(model_manager); | ||||
@@ -108,6 +108,9 @@ class GraphExecutor { | |||||
static Status GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type); | static Status GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type); | ||||
static Status GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value); | |||||
static Status GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info); | static Status GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info); | ||||
static Status GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info); | static Status GetOrigInputInfo(uint32_t model_id, uint32_t index, OriginInputInfo &orig_input_info); | ||||
@@ -743,6 +743,19 @@ Status DavinciModel::Init(void *dev_ptr, size_t mem_size, void *weight_ptr, size | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
// save specify attr values of op, such as ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES | |||||
// it will save more attr values in the future | |||||
void DavinciModel::SaveSpecifyAttrValues(const OpDescPtr &op_desc) { | |||||
std::vector<std::string> value; | |||||
if (AttrUtils::GetListStr(op_desc, ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, value)) { | |||||
std::map<std::string, std::vector<std::string>> attr_name_to_value; | |||||
attr_name_to_value[ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES]= value; | |||||
op_name_to_attrs_[op_desc->GetName()] = attr_name_to_value; | |||||
GELOGD("Get op:%s attr:%s success.", op_desc->GetName().c_str(), ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES.c_str()); | |||||
} | |||||
return; | |||||
} | |||||
Status DavinciModel::ReportProfilingData() { | Status DavinciModel::ReportProfilingData() { | ||||
ProfilingManager::Instance().ReportProfilingData(model_id_, GetTaskDescInfo()); | ProfilingManager::Instance().ReportProfilingData(model_id_, GetTaskDescInfo()); | ||||
GE_CHK_STATUS(SinkModelProfile(), "Sink model profiler failed."); | GE_CHK_STATUS(SinkModelProfile(), "Sink model profiler failed."); | ||||
@@ -846,7 +859,7 @@ Status DavinciModel::InitNodes(const ComputeGraphPtr &compute_graph) { | |||||
const auto &node = nodes.at(i); | const auto &node = nodes.at(i); | ||||
const auto &op_desc = node->GetOpDesc(); | const auto &op_desc = node->GetOpDesc(); | ||||
GE_CHECK_NOTNULL(op_desc); | GE_CHECK_NOTNULL(op_desc); | ||||
SaveSpecifyAttrValues(op_desc); | |||||
op_list_[op_desc->GetId()] = op_desc; | op_list_[op_desc->GetId()] = op_desc; | ||||
GE_TIMESTAMP_RESTART(LoadTBEKernelBinToOpDesc); | GE_TIMESTAMP_RESTART(LoadTBEKernelBinToOpDesc); | ||||
@@ -2056,6 +2069,25 @@ void DavinciModel::GetCurShape(std::vector<int64_t> &batch_info, int32_t &dynami | |||||
dynamic_type = dynamic_type_; | dynamic_type = dynamic_type_; | ||||
} | } | ||||
Status DavinciModel::GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) const { | |||||
auto itr = op_name_to_attrs_.find(op_name); | |||||
if (itr == op_name_to_attrs_.end()) { | |||||
GELOGW("Did not save op:%s attr", op_name.c_str()); | |||||
return SUCCESS; | |||||
} | |||||
auto attr_itr = itr->second.find(attr_name); | |||||
if (attr_itr == itr->second.end()) { | |||||
GELOGW("Did not save attr:%s of op:%s", attr_name.c_str(), op_name.c_str()); | |||||
return SUCCESS; | |||||
} | |||||
for (const auto &name : attr_itr->second) { | |||||
attr_value += "[" + std::to_string(name.size()) + "]" + name; | |||||
} | |||||
GELOGD("Get attr:%s of op:%s success, attr value:%s", attr_name.c_str(), op_name.c_str(), attr_value.c_str()); | |||||
return SUCCESS; | |||||
} | |||||
void DavinciModel::GetModelAttr(vector<string> &out_shape_info) const { | void DavinciModel::GetModelAttr(vector<string> &out_shape_info) const { | ||||
out_shape_info.insert(out_shape_info.end(), dynamic_output_shape_info_.begin(), dynamic_output_shape_info_.end()); | out_shape_info.insert(out_shape_info.end(), dynamic_output_shape_info_.begin(), dynamic_output_shape_info_.end()); | ||||
} | } | ||||
@@ -361,6 +361,8 @@ class DavinciModel { | |||||
void GetCurShape(vector<int64_t> &batch_info, int32_t &dynamic_type) const; | void GetCurShape(vector<int64_t> &batch_info, int32_t &dynamic_type) const; | ||||
Status GetOpAttr(const std::string &op_name, const std::string &attr_name, std::string &attr_value) const; | |||||
void GetModelAttr(vector<string> &dynamic_output_shape_info) const; | void GetModelAttr(vector<string> &dynamic_output_shape_info) const; | ||||
/// | /// | ||||
@@ -474,6 +476,8 @@ class DavinciModel { | |||||
int64_t GetLoadEndTime() { return load_end_time_; } | int64_t GetLoadEndTime() { return load_end_time_; } | ||||
void SaveSpecifyAttrValues(const OpDescPtr &op_desc); | |||||
Status ReportProfilingData(); | Status ReportProfilingData(); | ||||
void SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op, uint32_t task_id, uint32_t stream_id) { | void SaveDumpOpInfo(const RuntimeParam &model_param, const OpDescPtr &op, uint32_t task_id, uint32_t stream_id) { | ||||
@@ -1096,6 +1100,9 @@ class DavinciModel { | |||||
// known shape node for dump | // known shape node for dump | ||||
void *known_shape_global_step_; | void *known_shape_global_step_; | ||||
// op name to attrs mapping | |||||
std::map<std::string, std::map<std::string, std::vector<std::string>>> op_name_to_attrs_; | |||||
}; | }; | ||||
} // namespace ge | } // namespace ge | ||||
#endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_DAVINCI_MODEL_H_ | #endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_DAVINCI_MODEL_H_ |
@@ -1045,6 +1045,21 @@ Status ModelManager::GetCurShape(const uint32_t model_id, std::vector<int64_t> & | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status ModelManager::GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) { | |||||
auto davinci_model = GetModel(model_id); | |||||
if (davinci_model != nullptr) { | |||||
return davinci_model->GetOpAttr(op_name, attr_name, attr_value); | |||||
} | |||||
std::shared_ptr<hybrid::HybridDavinciModel> hybrid_davinci_model = GetHybridModel(model_id); | |||||
if (hybrid_davinci_model != nullptr) { | |||||
return hybrid_davinci_model->GetOpAttr(op_name, attr_name, attr_value); | |||||
} | |||||
GELOGE(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "[Get][Model]Get model failed, invalid model id:%u.", model_id); | |||||
REPORT_INNER_ERROR("E19999", "Get model failed, invalid model id:%u.", model_id); | |||||
return ACL_ERROR_GE_EXEC_MODEL_ID_INVALID; | |||||
} | |||||
Status ModelManager::GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info) { | Status ModelManager::GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info) { | ||||
std::shared_ptr<hybrid::HybridDavinciModel> hybrid_davinci_model = GetHybridModel(model_id); | std::shared_ptr<hybrid::HybridDavinciModel> hybrid_davinci_model = GetHybridModel(model_id); | ||||
if (hybrid_davinci_model != nullptr) { | if (hybrid_davinci_model != nullptr) { | ||||
@@ -246,6 +246,9 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager { | |||||
ge::Status GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type); | ge::Status GetCurShape(const uint32_t model_id, std::vector<int64_t> &batch_info, int32_t &dynamic_type); | ||||
ge::Status GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value); | |||||
ge::Status GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info); | ge::Status GetModelAttr(uint32_t model_id, std::vector<string> &dynamic_output_shape_info); | ||||
ge::Status SetDynamicSize(uint32_t model_id, const std::vector<uint64_t> &batch_num, int32_t dynamic_type); | ge::Status SetDynamicSize(uint32_t model_id, const std::vector<uint64_t> &batch_num, int32_t dynamic_type); | ||||
@@ -126,6 +126,11 @@ class HybridDavinciModel::Impl { | |||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
Status GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) { | |||||
return model_.GetOpAttr(op_name, attr_name, attr_value); | |||||
} | |||||
private: | private: | ||||
std::shared_ptr<ModelListener> listener_; | std::shared_ptr<ModelListener> listener_; | ||||
HybridModel model_; | HybridModel model_; | ||||
@@ -273,5 +278,11 @@ bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpD | |||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
Status HybridDavinciModel::GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) const { | |||||
GE_CHECK_NOTNULL(impl_); | |||||
return impl_->GetOpAttr(op_name, attr_name, attr_value); | |||||
} | |||||
} // namespace hybrid | } // namespace hybrid | ||||
} // namespace ge | } // namespace ge |
@@ -84,6 +84,8 @@ class HybridDavinciModel { | |||||
bool GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const; | bool GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const; | ||||
Status GetOpAttr(const std::string &op_name, const std::string &attr_name, std::string &attr_value) const; | |||||
private: | private: | ||||
HybridDavinciModel() = default; | HybridDavinciModel() = default; | ||||
class Impl; | class Impl; | ||||
@@ -107,5 +107,9 @@ Status HybridDavinciModel::SetRunAsyncListenerCallback(const RunAsyncCallback &c | |||||
bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const { | bool HybridDavinciModel::GetOpDescInfo(uint32_t stream_id, uint32_t task_id, OpDescInfo &op_desc_info) const { | ||||
return true; | return true; | ||||
} | } | ||||
Status HybridDavinciModel::GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) const { | |||||
return UNSUPPORTED; | |||||
} | |||||
} // namespace hybrid | } // namespace hybrid | ||||
} // namespace ge | } // namespace ge |
@@ -48,6 +48,7 @@ Status HybridModel::Init(bool is_single_op) { | |||||
} else { | } else { | ||||
GE_CHK_STATUS_RET(HybridModelBuilder(*this).Build(), "[Build][HybridModel] failed."); | GE_CHK_STATUS_RET(HybridModelBuilder(*this).Build(), "[Build][HybridModel] failed."); | ||||
} | } | ||||
SaveSpecifyAttrValues(); | |||||
GELOGD("HybridModel initialized successfully."); | GELOGD("HybridModel initialized successfully."); | ||||
return SUCCESS; | return SUCCESS; | ||||
} | } | ||||
@@ -409,5 +410,45 @@ TensorBuffer *HybridModel::GetModelWeight(const string &subgraph_name) const { | |||||
} | } | ||||
return it->second.get(); | return it->second.get(); | ||||
} | } | ||||
// save specify attr values of op, such as ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES | |||||
// it will save more attr values in the future | |||||
void HybridModel::SaveSpecifyAttrValues() { | |||||
for (const auto &node : root_graph_->GetAllNodes()) { | |||||
if (node == nullptr) { | |||||
continue; | |||||
} | |||||
auto op_desc = node->GetOpDesc(); | |||||
if (op_desc == nullptr) { | |||||
continue; | |||||
} | |||||
std::vector<std::string> value; | |||||
if (AttrUtils::GetListStr(op_desc, ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, value)) { | |||||
std::map<std::string, std::vector<std::string>> attr_name_to_value; | |||||
attr_name_to_value[ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES] = value; | |||||
op_name_to_attrs_[op_desc->GetName()] = attr_name_to_value; | |||||
GELOGD("Get op:%s attr:%s success.", op_desc->GetName().c_str(), ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES.c_str()); | |||||
} | |||||
} | |||||
return; | |||||
} | |||||
Status HybridModel::GetOpAttr(const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value) const { | |||||
auto itr = op_name_to_attrs_.find(op_name); | |||||
if (itr == op_name_to_attrs_.end()) { | |||||
GELOGW("Did not save op:%s attr", op_name.c_str()); | |||||
return SUCCESS; | |||||
} | |||||
auto attr_itr = itr->second.find(attr_name); | |||||
if (attr_itr == itr->second.end()) { | |||||
GELOGW("Did not save attr:%s of op:%s", attr_name.c_str(), op_name.c_str()); | |||||
return SUCCESS; | |||||
} | |||||
for (const auto &name : attr_itr->second) { | |||||
attr_value += "[" + std::to_string(name.size()) + "]" + name; | |||||
} | |||||
GELOGD("Get attr:%s of op:%s success, attr value:%s", attr_name.c_str(), op_name.c_str(), attr_value.c_str()); | |||||
return SUCCESS; | |||||
} | |||||
} // namespace hybrid | } // namespace hybrid | ||||
} // namespace ge | } // namespace ge |
@@ -131,6 +131,9 @@ class HybridModel { | |||||
void SetInputDimsAndShapeRangesInfo(const vector<int64_t> &model_input_dims, | void SetInputDimsAndShapeRangesInfo(const vector<int64_t> &model_input_dims, | ||||
std::vector<std::pair<int64_t, int64_t>> &shape_ranges, | std::vector<std::pair<int64_t, int64_t>> &shape_ranges, | ||||
InputOutputDescInfo &input); | InputOutputDescInfo &input); | ||||
void SaveSpecifyAttrValues(); | |||||
Status GetOpAttr(const std::string &op_name, const std::string &attr_name, std::string &attr_value) const; | |||||
private: | private: | ||||
friend class HybridModelBuilder; | friend class HybridModelBuilder; | ||||
@@ -165,6 +168,8 @@ class HybridModel { | |||||
RuntimeParam root_runtime_param_; | RuntimeParam root_runtime_param_; | ||||
string om_name_; | string om_name_; | ||||
std::unique_ptr<TensorBuffer> global_step_; | std::unique_ptr<TensorBuffer> global_step_; | ||||
// op name to attrs mapping | |||||
std::map<std::string, std::map<std::string, std::vector<std::string>>> op_name_to_attrs_; | |||||
}; | }; | ||||
} // namespace hybrid | } // namespace hybrid | ||||
} // namespace ge | } // namespace ge | ||||
@@ -153,6 +153,10 @@ class GE_FUNC_VISIBILITY GeExecutor { | |||||
const kAippDynamicPara &aippParms); | const kAippDynamicPara &aippParms); | ||||
ge::Status GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info); | ge::Status GetAIPPInfo(uint32_t model_id, uint32_t index, AippConfigInfo &aipp_info); | ||||
ge::Status GetOpAttr(uint32_t model_id, const std::string &op_name, const std::string &attr_name, | |||||
std::string &attr_value); | |||||
ge::Status GetModelAttr(uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info); | ge::Status GetModelAttr(uint32_t model_id, std::vector<std::string> &dynamic_output_shape_info); | ||||
ge::Status GetAippType(uint32_t model_id, uint32_t index, InputAippType &type, size_t &aipp_index); | ge::Status GetAippType(uint32_t model_id, uint32_t index, InputAippType &type, size_t &aipp_index); | ||||
@@ -34,6 +34,7 @@ | |||||
#include "common/types.h" | #include "common/types.h" | ||||
#include "graph/load/graph_loader.h" | #include "graph/load/graph_loader.h" | ||||
#include "graph/load/model_manager/davinci_model.h" | #include "graph/load/model_manager/davinci_model.h" | ||||
#include "hybrid/hybrid_davinci_model.h" | |||||
#include "graph/load/model_manager/model_manager.h" | #include "graph/load/model_manager/model_manager.h" | ||||
#include "graph/load/model_manager/task_info/kernel_task_info.h" | #include "graph/load/model_manager/task_info/kernel_task_info.h" | ||||
#include "graph/load/model_manager/task_info/kernel_ex_task_info.h" | #include "graph/load/model_manager/task_info/kernel_ex_task_info.h" | ||||
@@ -190,4 +191,37 @@ TEST_F(UtestGeExecutor, kernel_ex_InitDumpTask) { | |||||
kernel_ex_task_info.davinci_model_ = &model; | kernel_ex_task_info.davinci_model_ = &model; | ||||
kernel_ex_task_info.InitDumpTask(nullptr, op_desc); | kernel_ex_task_info.InitDumpTask(nullptr, op_desc); | ||||
} | } | ||||
TEST_F(UtestGeExecutor, get_op_attr) { | |||||
shared_ptr<DavinciModel> model = MakeShared<DavinciModel>(1, g_label_call_back); | |||||
model->SetId(1); | |||||
model->om_name_ = "testom"; | |||||
model->name_ = "test"; | |||||
shared_ptr<hybrid::HybridDavinciModel> hybrid_model = MakeShared<hybrid::HybridDavinciModel>(); | |||||
model->SetId(2); | |||||
model->om_name_ = "testom_hybrid"; | |||||
model->name_ = "test_hybrid"; | |||||
std::shared_ptr<ModelManager> model_manager = ModelManager::GetInstance(); | |||||
model_manager->InsertModel(1, model); | |||||
model_manager->InsertModel(2, hybrid_model); | |||||
OpDescPtr op_desc = CreateOpDesc("test", "test"); | |||||
std::vector<std::string> value{"test"}; | |||||
ge::AttrUtils::SetListStr(op_desc, ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, value); | |||||
model->SaveSpecifyAttrValues(op_desc); | |||||
GeExecutor ge_executor; | |||||
GeExecutor::isInit_ = true; | |||||
std::string attr_value; | |||||
auto ret = ge_executor.GetOpAttr(1, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
EXPECT_EQ(ret, SUCCESS); | |||||
EXPECT_EQ(attr_value, "[4]test"); | |||||
ret = ge_executor.GetOpAttr(2, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
EXPECT_EQ(ret, UNSUPPORTED); | |||||
ret = ge_executor.GetOpAttr(3, "test", ge::ATTR_NAME_DATA_DUMP_ORIGIN_OP_NAMES, attr_value); | |||||
EXPECT_EQ(ret, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID); | |||||
} | |||||
} | } |