From: @zhangxiaokun9 Reviewed-by: @xchu42,@ji_chen Signed-off-by: @ji_chentags/v1.3.0
@@ -31,6 +31,7 @@ | |||
#include "common/scope_guard.h" | |||
#include "common/thread_pool.h" | |||
#include "framework/common/debug/ge_log.h" | |||
#include "framework/common/util.h" | |||
#include "graph/common/ge_call_wrapper.h" | |||
#include "graph/compute_graph.h" | |||
#include "graph/debug/ge_attr_define.h" | |||
@@ -297,6 +298,11 @@ void DavinciModel::ReleaseTask() { | |||
GE_CHK_STATUS(task->Release(), "Release task failed."); | |||
} | |||
} | |||
for (auto &item : label_goto_args_) { | |||
GE_FREE_RT_LOG(item.second.first); | |||
} | |||
label_goto_args_.clear(); | |||
} | |||
Status DavinciModel::Assign(const GeModelPtr &ge_model) { | |||
@@ -1334,6 +1340,39 @@ void DavinciModel::ParseDynamicOutShape(const std::vector<std::string> &str_info | |||
} | |||
} | |||
Status DavinciModel::GetLabelGotoAddr(uint32_t label_index, rtMemType_t mem_type, void *&arg_addr, uint32_t &arg_size) { | |||
std::lock_guard<std::mutex> lock(label_args_mutex_); | |||
auto it = label_goto_args_.find(label_index); | |||
if (it != label_goto_args_.end()) { | |||
arg_addr = it->second.first; | |||
arg_size = it->second.second; | |||
return SUCCESS; | |||
} | |||
if (label_index >= label_list_.size()) { | |||
GELOGE(INTERNAL_ERROR, "Invalid label id:%u, label size:%zu", label_index, label_list_.size()); | |||
return INTERNAL_ERROR; | |||
} | |||
GE_CHECK_NOTNULL(label_list_[label_index]); | |||
vector<rtLabel_t> label_used = { label_list_[label_index] }; | |||
arg_size = label_used.size() * sizeof(rtLabelDevInfo); | |||
rtError_t rt_ret = rtMalloc(&arg_addr, arg_size, mem_type); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(RT_FAILED, "Call rtMalloc failed, error: %#x", rt_ret); | |||
return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
} | |||
label_goto_args_[label_index] = { arg_addr, arg_size }; | |||
rt_ret = rtLabelListCpy(label_used.data(), label_used.size(), arg_addr, arg_size); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(RT_FAILED, "Call rtLabelListCpy failed, error: %#x", rt_ret); | |||
return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
} | |||
return SUCCESS; | |||
} | |||
/// @ingroup ge | |||
/// @brief LabelSet Op Initialize. | |||
/// @param [in] op_desc: LabelSet Op descriptor. | |||
@@ -273,6 +273,8 @@ class DavinciModel { | |||
const vector<rtLabel_t> &GetLabelList() const { return label_list_; } | |||
Status GetLabelGotoAddr(uint32_t label_index, rtMemType_t memory_type, void *&addr, uint32_t &size); | |||
Status DestroyThread(); | |||
// get Op | |||
@@ -930,6 +932,9 @@ class DavinciModel { | |||
vector<rtLabel_t> label_list_; | |||
set<uint32_t> label_id_indication_; | |||
mutex label_args_mutex_; | |||
map<uint32_t, pair<void *, uint32_t>> label_goto_args_; | |||
mutex outside_addrs_mutex_; | |||
vector<ZeroCopyTask> zero_copy_tasks_; // Task used Data or NetOutput addr. | |||
set<const void *> copy_only_addrs_; // Address need copy to original place. | |||
@@ -22,7 +22,7 @@ namespace ge { | |||
constexpr uint8_t kGotoBranchMax = 1; | |||
LabelGotoExTaskInfo::~LabelGotoExTaskInfo() { | |||
GE_FREE_RT_LOG(args_); | |||
args_ = nullptr; | |||
GE_FREE_RT_LOG(index_value_); | |||
} | |||
@@ -49,30 +49,12 @@ Status LabelGotoExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *da | |||
return INTERNAL_ERROR; | |||
} | |||
const vector<rtLabel_t> &label_list = davinci_model->GetLabelList(); | |||
if (label_index >= label_list.size()) { | |||
GELOGE(PARAM_INVALID, "LabelGotoExTaskInfo: Invalid label id:%u, label size:%zu", label_index, label_list.size()); | |||
return INTERNAL_ERROR; | |||
} | |||
GE_CHECK_NOTNULL(label_list[label_index]); | |||
vector<rtLabel_t> label_used = { label_list[label_index] }; | |||
rtMemType_t memory_type = op_desc->HasAttr(ATTR_NAME_MEMORY_TYPE_RANGE) ? RT_MEMORY_TS_4G : RT_MEMORY_HBM; | |||
GELOGI("memory_type: %u", memory_type); | |||
args_size_ = kGotoBranchMax * sizeof(rtLabelDevInfo); | |||
rtError_t rt_ret = rtMalloc(&args_, args_size_, memory_type); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(RT_FAILED, "Call rtMalloc failed, error: %#x", rt_ret); | |||
return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
} | |||
rt_ret = rtLabelListCpy(label_used.data(), label_used.size(), args_, args_size_); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(RT_FAILED, "Call rtLabelListCpy failed, error: %#x", rt_ret); | |||
return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
} | |||
GE_CHK_STATUS_RET_NOLOG(davinci_model->GetLabelGotoAddr(label_index, memory_type, args_, args_size_)); | |||
rt_ret = rtMalloc(&index_value_, sizeof(uint64_t), memory_type); | |||
rtError_t rt_ret = rtMalloc(&index_value_, sizeof(uint64_t), memory_type); | |||
if (rt_ret != RT_ERROR_NONE) { | |||
GELOGE(RT_FAILED, "Call rtMalloc failed, error: %#x", rt_ret); | |||
return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
@@ -85,7 +67,7 @@ Status LabelGotoExTaskInfo::Init(const domi::TaskDef &task_def, DavinciModel *da | |||
return RT_ERROR_TO_GE_STATUS(rt_ret); | |||
} | |||
GELOGI("LabelGotoExTaskInfo Init Success, label id:%u, label:%p.", label_index, label_list[label_index]); | |||
GELOGI("LabelGotoExTaskInfo Init Success, label id:%u", label_index); | |||
return SUCCESS; | |||
} | |||