diff --git a/ge/graph/load/new_model_manager/davinci_model.cc b/ge/graph/load/new_model_manager/davinci_model.cc index 720c3c28..e1ebf216 100755 --- a/ge/graph/load/new_model_manager/davinci_model.cc +++ b/ge/graph/load/new_model_manager/davinci_model.cc @@ -970,7 +970,7 @@ Status DavinciModel::InitDataOp(const NodePtr &node, uint32_t &data_op_index, ma uint32_t parent_index = 0; // Ignore subgraph Data Node. if (AttrUtils::GetInt(op_desc, ATTR_NAME_PARENT_NODE_INDEX, parent_index)) { GELOGI("Init zero copy by subgraph Data node: %s.", op_desc->GetName().c_str()); - return InitInputBatchLabel(node); + return SUCCESS; } data_op_list_.push_back(op_desc); @@ -1011,10 +1011,6 @@ Status DavinciModel::InitDataOp(const NodePtr &node, uint32_t &data_op_index, ma } data_op_index++; - if (InitInputZeroCopyNodes(node) != SUCCESS) { - GELOGE(PARAM_INVALID, "Input zero copy nodes init failed!"); - return PARAM_INVALID; - } return SUCCESS; } @@ -1036,39 +1032,6 @@ void DavinciModel::AdjustDataOpList(const map &data_by_inde } } -/// -/// @ingroup ge -/// @brief input zero copy node Initialize. -/// @param [in] NodePtr: Data Op. -/// @return Status -/// -Status DavinciModel::InitInputZeroCopyNodes(const NodePtr &node) { - auto out_data_anchor = node->GetOutDataAnchor(kDataIndex); - if (out_data_anchor == nullptr) { - GELOGE(FAILED, "Out data anchor is nullptr"); - return FAILED; - } - for (auto &peer_in_data_anchor : out_data_anchor->GetPeerInDataAnchors()) { - auto node = peer_in_data_anchor->GetOwnerNode(); - auto op_desc = node->GetOpDesc(); - if (op_desc == nullptr) { - GELOGE(FAILED, "Op desc is nullptr"); - return FAILED; - } - string batch_label; - (void)ge::AttrUtils::GetStr(op_desc, ATTR_NAME_BATCH_LABEL, batch_label); - if (batch_label.empty()) { - batch_label = kDefaultBatchLable; - } - if (zero_copy_op_id_batch_label_.find(op_desc->GetId()) == zero_copy_op_id_batch_label_.end()) { - zero_copy_op_id_batch_label_.emplace(pair(op_desc->GetId(), batch_label)); - GELOGD("Init input zero copy nodes success, op name:%s, op id: %ld, batch label: %s.", op_desc->GetName().c_str(), - op_desc->GetId(), batch_label.c_str()); - } - } - return SUCCESS; -} - bool DavinciModel::IsGetNextSinkDynamic(const OpDescPtr &op_desc) { bool getnext_sink_dynamic = false; if (ge::AttrUtils::GetBool(op_desc, ATTR_GETNEXT_SINK_DYNMAIC, getnext_sink_dynamic) && getnext_sink_dynamic) { @@ -1094,7 +1057,7 @@ Status DavinciModel::InitNetOutput(const NodePtr &node) { if (owner_graph->GetParentGraph() != nullptr) { GELOGI("Init zero copy by subgraph NetOutput node: %s.", op_desc->GetName().c_str()); op_list_.erase(op_desc->GetId()); - return InitOutputBatchLabel(node); + return SUCCESS; } output_op_list_.push_back(op_desc); @@ -1146,8 +1109,6 @@ Status DavinciModel::InitNetOutput(const NodePtr &node) { } } - GE_IF_BOOL_EXEC(InitOutputZeroCopyNodes(node) != SUCCESS, - GELOGE(PARAM_INVALID, "Output zero copy nodes init failed!"); return PARAM_INVALID;); GetAllGearsInfo(node); if (is_getnext_sink_dynamic_) { GE_IF_BOOL_EXEC(GetGetDynamicDimsNodeInfo(node) != SUCCESS, @@ -1343,121 +1304,6 @@ void DavinciModel::ParseDynamicOutShape(const std::vector &str_info } } -/// -/// @ingroup ge -/// @brief output zero copy node Initialize. -/// @param [in] NodePtr: netoutput Op. -/// @return Status -/// -Status DavinciModel::InitOutputZeroCopyNodes(const NodePtr &node) { - set nodes_need_record; - for (auto &in_data_anchor : node->GetAllInDataAnchors()) { - auto peer_out_data_anchor = in_data_anchor->GetPeerOutAnchor(); - if (peer_out_data_anchor == nullptr) { - continue; - } - auto peer_node = peer_out_data_anchor->GetOwnerNode(); - nodes_need_record.emplace(peer_node); - - // Merge node output multiplexed input, upstream nodes need to be considered in multiple batch scenarios - if (peer_node->GetType() == MERGE) { - for (const auto &merge_peer_in_data_anchor : peer_node->GetAllInDataAnchors()) { - auto merge_peer_out_data_anchor = merge_peer_in_data_anchor->GetPeerOutAnchor(); - if (merge_peer_out_data_anchor == nullptr) { - continue; - } - auto merge_peer_node = merge_peer_out_data_anchor->GetOwnerNode(); - nodes_need_record.emplace(merge_peer_node); - } - } else { - for (const auto &other_in_data_anchor : peer_out_data_anchor->GetPeerInDataAnchors()) { - auto other_in_node = other_in_data_anchor->GetOwnerNode(); - if (other_in_node->GetType() != NETOUTPUT) { - nodes_need_record.emplace(other_in_node); - } - } - } - } - - for (const auto &node_need_record : nodes_need_record) { - auto op_desc = node_need_record->GetOpDesc(); - GE_CHECK_NOTNULL(op_desc); - string batch_label; - (void)ge::AttrUtils::GetStr(op_desc, ATTR_NAME_BATCH_LABEL, batch_label); - if (batch_label.empty()) { - batch_label = kDefaultBatchLable; - } - if (zero_copy_op_id_batch_label_.find(op_desc->GetId()) == zero_copy_op_id_batch_label_.end()) { - zero_copy_op_id_batch_label_.emplace(pair(op_desc->GetId(), batch_label)); - GELOGD("Init Output zero copy nodes success, op name:%s, op id: %ld, batch label: %s.", - op_desc->GetName().c_str(), op_desc->GetId(), batch_label.c_str()); - } - } - return SUCCESS; -} - -/// -/// @ingroup ge -/// @brief input zero copy node Initialize. -/// @param [in] NodePtr: Data Op. -/// @return Status -/// -Status DavinciModel::InitInputBatchLabel(const NodePtr &node) { - string batch_label; - if (!AttrUtils::GetStr(node->GetOpDesc(), ATTR_NAME_BATCH_LABEL, batch_label)) { - return SUCCESS; // Not Multi-batch. - } - - const auto &out_data_anchor = node->GetOutDataAnchor(kDataIndex); - GE_CHECK_NOTNULL(out_data_anchor); - - for (const auto &peer_in_data_anchor : out_data_anchor->GetPeerInDataAnchors()) { - const auto &node = peer_in_data_anchor->GetOwnerNode(); - const auto &op_desc = node->GetOpDesc(); - GE_CHECK_NOTNULL(op_desc); - - if (zero_copy_op_id_batch_label_.find(op_desc->GetId()) == zero_copy_op_id_batch_label_.end()) { - zero_copy_op_id_batch_label_[op_desc->GetId()] = batch_label; - GELOGD("Init input zero copy nodes success, op name: %s, op id: %ld, batch label: %s", op_desc->GetName().c_str(), - op_desc->GetId(), batch_label.c_str()); - } - } - - return SUCCESS; -} - -/// -/// @ingroup ge -/// @brief output zero copy node Initialize for Case. -/// @param [in] NodePtr: netoutput Op. -/// @return Status -/// -Status DavinciModel::InitOutputBatchLabel(const NodePtr &node) { - string batch_label; - if (!AttrUtils::GetStr(node->GetOpDesc(), ATTR_NAME_BATCH_LABEL, batch_label)) { - return SUCCESS; // Not Multi-batch. - } - - for (const auto &in_data_anchor : node->GetAllInDataAnchors()) { - const auto &peer_out_data_anchor = in_data_anchor->GetPeerOutAnchor(); - if (peer_out_data_anchor == nullptr) { - continue; - } - - const auto &peer_node = peer_out_data_anchor->GetOwnerNode(); - const auto &op_desc = peer_node->GetOpDesc(); - GE_CHECK_NOTNULL(op_desc); - - if (zero_copy_op_id_batch_label_.find(op_desc->GetId()) == zero_copy_op_id_batch_label_.end()) { - zero_copy_op_id_batch_label_[op_desc->GetId()] = batch_label; - GELOGD("Init Output zero copy nodes success, op name: %s, op id: %ld, batch label: %s", - op_desc->GetName().c_str(), op_desc->GetId(), batch_label.c_str()); - } - } - - return SUCCESS; -} - /// @ingroup ge /// @brief LabelSet Op Initialize. /// @param [in] op_desc: LabelSet Op descriptor. @@ -3264,27 +3110,20 @@ void DavinciModel::SetZeroCopyAddr(const OpDescPtr &op_desc, const std::vector(args) + offset + i * kAddrLen; - SetBatchLabelAddr(op_desc, reinterpret_cast(args_val)); - } + input_outside.SetOutsideAddrsValue(zero_copy_task, outside_addrs[i], args, offset + i * kAddrLen); } for (auto &output_outside_addrs : new_output_outside_addrs_) { ZeroCopyOffset &output_outside = output_outside_addrs.second; - bool ret = output_outside.SetOutsideAddrsValue(zero_copy_task, outside_addrs[i], args, offset + i * kAddrLen); - if (ret) { - void *args_val = static_cast(args) + offset + i * kAddrLen; - SetBatchLabelAddr(op_desc, reinterpret_cast(args_val)); - } + output_outside.SetOutsideAddrsValue(zero_copy_task, outside_addrs[i], args, offset + i * kAddrLen); } } - auto it = zero_copy_op_id_batch_label_.find(op_desc->GetId()); - if (it == zero_copy_op_id_batch_label_.end()) { + + string batch_label; + if (!AttrUtils::GetStr(op_desc, ATTR_NAME_BATCH_LABEL, batch_label) || batch_label.empty()) { zero_copy_task.SetBatchLabel(kDefaultBatchLable); } else { - zero_copy_task.SetBatchLabel(it->second); + zero_copy_task.SetBatchLabel(batch_label); } std::lock_guard lock(outside_addrs_mutex_); @@ -3294,27 +3133,6 @@ void DavinciModel::SetZeroCopyAddr(const OpDescPtr &op_desc, const std::vectorGetId()); - if (it == zero_copy_op_id_batch_label_.end()) { - return; - } - - const string &batch_label = it->second; - auto iter = zero_copy_batch_label_addrs_.find(batch_label); - if (iter != zero_copy_batch_label_addrs_.end()) { - iter->second.insert(addr); - GELOGD("[ZCPY] Set zero copy batch label and addrs success, batch label: %s, op name:%s.", batch_label.c_str(), - op_desc->GetName().c_str()); - } else { - set addrs = {addr}; - zero_copy_batch_label_addrs_.emplace(pair>(batch_label, addrs)); - GELOGD("[ZCPY] New added zero copy batch label and addrs success, batch label: %s, op name:%s.", - batch_label.c_str(), op_desc->GetName().c_str()); - } -} - /// /// @ingroup ge /// @brief Copy Check input size and model op size. @@ -3448,15 +3266,15 @@ Status DavinciModel::UpdateIoTaskArgs(const std::map & void *addr = data.second.GetDataInfo().at(count).second; void *buffer_addr = reinterpret_cast(reinterpret_cast(buffer.data) + data.second.GetRelativeOffset().at(count)); - GELOGI("[ZCPY] Copy %s blobs_index %u, virtual_addr: %p, size: %ld, user_data_addr: %p", input_or_output.c_str(), - data.first, addr, size, buffer_addr); + GELOGI("[ZCPY] Copy %s blobs_index %u, virtual_addr: %p, size: %ld, user_data_addr: %p, batch_label: %s", + input_or_output.c_str(), data.first, addr, size, buffer_addr, batch_label.c_str()); // For input data, just copy for rts task. for (ZeroCopyTask &task : zero_copy_tasks_) { if (task.GetBatchLabel() != kDefaultBatchLable && task.GetBatchLabel() != batch_label) { continue; } uintptr_t addr_val = reinterpret_cast(addr); - if (task.UpdateTaskParam(addr_val, buffer_addr, zero_copy_batch_label_addrs_, batch_label) != SUCCESS) { + if (task.UpdateTaskParam(addr_val, buffer_addr) != SUCCESS) { return FAILED; } } @@ -3818,9 +3636,6 @@ Status DavinciModel::NnExecute(rtStream_t stream, bool async_mode, const InputDa GELOGD("Model Run begin, model id:%u, data index:%u, flag:%d.", model_id_, input_data.index, is_async_mode_); GE_CHK_STATUS_RET(InitModelStream(stream), "Init model stream failed."); is_dynamic_ = input_data.is_dynamic_batch; - if (!is_dynamic_) { - zero_copy_batch_label_addrs_.clear(); - } GE_IF_BOOL_EXEC(ProfilingManager::Instance().ProfilingModelExecuteOn(), SetProfileTime(MODEL_PRE_PROC_START)); Status ret = CopyModelData(input_data, output_data, is_dynamic_); diff --git a/ge/graph/load/new_model_manager/davinci_model.h b/ge/graph/load/new_model_manager/davinci_model.h index 27bd4de5..4c507662 100755 --- a/ge/graph/load/new_model_manager/davinci_model.h +++ b/ge/graph/load/new_model_manager/davinci_model.h @@ -537,15 +537,6 @@ class DavinciModel { struct timeInfo time_info_; int32_t dataInputTid; - /// - /// @ingroup ge - /// @brief Save Batch label Info. - /// @param [in] const OpDescPtr &op_desc - /// @param [in] uintptr_t addr: address value in args block. - /// @return None. - /// - void SetBatchLabelAddr(const OpDescPtr &op_desc, uintptr_t addr); - /// /// @ingroup ge /// @brief Copy Check input size and model op size. @@ -657,14 +648,6 @@ class DavinciModel { /// void AdjustDataOpList(const map &data_by_index); - /// - /// @ingroup ge - /// @brief input zero copy node Initialize. - /// @param [in] NodePtr: Data Op. - /// @return Status - /// - Status InitInputZeroCopyNodes(const NodePtr &node); - /// /// @ingroup ge /// @brief NetOutput Op Initialize. @@ -673,30 +656,6 @@ class DavinciModel { /// Status InitNetOutput(const NodePtr &node); - /// - /// @ingroup ge - /// @brief output zero copy node Initialize. - /// @param [in] NodePtr: Data Op. - /// @return Status - /// - Status InitOutputZeroCopyNodes(const NodePtr &node); - - /// - /// @ingroup ge - /// @brief input zero copy node Initialize for Case. - /// @param [in] NodePtr: Data Op. - /// @return Status - /// - Status InitInputBatchLabel(const NodePtr &node); - - /// - /// @ingroup ge - /// @brief output zero copy node Initialize for Case. - /// @param [in] NodePtr: netoutput Op. - /// @return Status - /// - Status InitOutputBatchLabel(const NodePtr &node); - /// /// @ingroup ge /// @brief Constant Op Init. @@ -922,11 +881,6 @@ class DavinciModel { std::vector zero_copy_tasks_; // Task used Data or NetOutput addr. std::set copy_only_addrs_; // Address need copy to original place. - // {op_id, batch_label} - std::map zero_copy_op_id_batch_label_; - // {batch_label, addrs} - std::map> zero_copy_batch_label_addrs_; - std::vector task_list_; // rt_moodel_handle rtModel_t rt_model_handle_; diff --git a/ge/graph/load/new_model_manager/zero_copy_offset.cc b/ge/graph/load/new_model_manager/zero_copy_offset.cc index 9cd3f30b..f27d862d 100644 --- a/ge/graph/load/new_model_manager/zero_copy_offset.cc +++ b/ge/graph/load/new_model_manager/zero_copy_offset.cc @@ -183,22 +183,18 @@ void ZeroCopyOffset::SetOutputOutsideAddrs(const int64_t &input_offset, const bo addr_count_ = out_count; } -bool ZeroCopyOffset::SetOutsideAddrsValue(ZeroCopyTask &zero_copy_task, void *outside_addr, void *args, size_t offset) { +void ZeroCopyOffset::SetOutsideAddrsValue(ZeroCopyTask &zero_copy_task, void *outside_addr, void *args, size_t offset) { const auto addr_val = reinterpret_cast(outside_addr); - bool set_batch_label_flag = false; for (uint32_t out_count = 0; out_count < GetAddrCount(); ++out_count) { - auto &addrs_mapping_list = GetOutsideAddrs(); - auto args_addrs = addrs_mapping_list[out_count].find(outside_addr); - if (args_addrs != addrs_mapping_list[out_count].end()) { + auto args_addrs = outside_addrs_[out_count].find(outside_addr); + if (args_addrs != outside_addrs_[out_count].end()) { GE_CHK_STATUS(zero_copy_task.SetTaskArgsOffset(addr_val, offset), "Input args invalid."); void *args_val = static_cast(args) + offset; args_addrs->second.push_back(args_val); GELOGD("[ZCPY] set copy input: virtual_addr: 0x%lx, task_addr: %p, args: %p, offset: %zu.", addr_val, args_val, args, offset); - set_batch_label_flag = true; } } - return set_batch_label_flag; } } // namespace ge diff --git a/ge/graph/load/new_model_manager/zero_copy_offset.h b/ge/graph/load/new_model_manager/zero_copy_offset.h index fa80f28b..8ead742d 100644 --- a/ge/graph/load/new_model_manager/zero_copy_offset.h +++ b/ge/graph/load/new_model_manager/zero_copy_offset.h @@ -51,7 +51,7 @@ class ZeroCopyOffset { const OpDescPtr &op_desc, const size_t &idx, bool &fusion_flag); void SetOutputOutsideAddrs(const int64_t &input_offset, const bool &fusion_flag, void *addr, std::vector &tensor_addrs); - bool SetOutsideAddrsValue(ZeroCopyTask &zero_copy_task, void *outside_addr, void *args, size_t offset); + void SetOutsideAddrsValue(ZeroCopyTask &zero_copy_task, void *outside_addr, void *args, size_t offset); // basic_addr of l2-fusion void *GetBasicAddr() const { return basic_addr_; } diff --git a/ge/graph/load/new_model_manager/zero_copy_task.cc b/ge/graph/load/new_model_manager/zero_copy_task.cc index 2609cb4b..7c6b3963 100755 --- a/ge/graph/load/new_model_manager/zero_copy_task.cc +++ b/ge/graph/load/new_model_manager/zero_copy_task.cc @@ -66,68 +66,23 @@ void ZeroCopyTask::SetOriginalArgs(const void *info, size_t size) { const uint8_t *data = static_cast(info); args_info_.assign(data, data + size); - GELOGI("[ZCPY] %s set info from virtual_addr: %p, args_addr: %p, args size: %zu, info size: %zu", name_.c_str(), info, + GELOGI("[ZCPY] %s set original args info: %p, args_addr: %p, args size: %zu, info size: %zu", name_.c_str(), info, args_addr_, args_size_, size); } -/** - * @ingroup ge - * @brief Check is dynamic batch node. - * @param [in] addr: virtual address value from Op. - * @param [in] data: data buffer from user. - * @param [in] batch_addrs: dynamic batch addr info. - * @param [in] batch_label: batch label. - * @return: true / false - */ -bool ZeroCopyTask::CheckDynamicBatch(const map> &batch_addrs, const string &batch_label, - uintptr_t addr) { - // Used for dynamic batch / resolution scene - set dynamic_input_addrs; - auto dynamic_input_iter = batch_addrs.find(batch_label); - if (dynamic_input_iter != batch_addrs.end()) { - dynamic_input_addrs = dynamic_input_iter->second; - } - - set fix_input_addrs; - auto fix_input_iter = batch_addrs.find(kDefaultBatchLable); - if (fix_input_iter != batch_addrs.end()) { - fix_input_addrs = fix_input_iter->second; - } - - if (fix_input_addrs.empty()) { - if (!dynamic_input_addrs.empty() && dynamic_input_addrs.find(addr) == dynamic_input_addrs.end()) { - return false; - } - } else { - if (!dynamic_input_addrs.empty() && dynamic_input_addrs.find(addr) == dynamic_input_addrs.end() && - fix_input_addrs.find(addr) == fix_input_addrs.end()) { - return false; - } - } - - return true; -} - /** * @ingroup ge * @brief Set user data addr to Task param. * @param [in] addr: virtual address value from Op. * @param [in] buffer_addr: real_data_buffer_addr from user. - * @param [in] batch_addrs: dynamic batch addr info. - * @param [in] batch_label: batch label. * @return: void */ -Status ZeroCopyTask::UpdateTaskParam(uintptr_t addr, void *buffer_addr, const map> &batch_addrs, - const string &batch_label) { +Status ZeroCopyTask::UpdateTaskParam(uintptr_t addr, void *buffer_addr) { auto iter = task_addr_offset_.find(addr); if (iter != task_addr_offset_.end()) { auto &cur_pair = *iter; uint8_t *args_info = args_info_.data(); for (auto offset : cur_pair.second) { - if (!CheckDynamicBatch(batch_addrs, batch_label, reinterpret_cast(args_addr_ + offset))) { - continue; - } - auto dst_addr = static_cast(buffer_addr); GELOGI("[ZCPY] %s update task, args_addr: %p, size: %zu, offset: %zu, virtual_addr: 0x%lx, user_data_addr: %p", name_.c_str(), args_addr_, args_size_, offset, addr, buffer_addr); diff --git a/ge/graph/load/new_model_manager/zero_copy_task.h b/ge/graph/load/new_model_manager/zero_copy_task.h index d0bb2b6d..efabc814 100644 --- a/ge/graph/load/new_model_manager/zero_copy_task.h +++ b/ge/graph/load/new_model_manager/zero_copy_task.h @@ -67,12 +67,9 @@ class ZeroCopyTask { * @brief Set user data addr to Task param. * @param [in] addr: virtual address value from Op. * @param [in] buffer_addr: data buffer_addr from user. - * @param [in] batch_addrs: dynamic batch addr info. - * @param [in] batch_label: batch label. * @return: 0 SUCCESS / others FAILED */ - ge::Status UpdateTaskParam(uintptr_t addr, void *buffer_addr, const map> &batch_addrs, - const string &batch_label); + ge::Status UpdateTaskParam(uintptr_t addr, void *buffer_addr); /** * @ingroup ge @@ -91,9 +88,6 @@ class ZeroCopyTask { return batch_label_; } - protected: - bool CheckDynamicBatch(const map> &batch_addrs, const string &batch_label, uintptr_t addr); - private: const string name_;