modified: ge/graph/build/graph_builder.cc

modified:   ge/graph/load/model_manager/model_manager.cc
	modified:   ge/host_kernels/identity_kernel.cc
	modified:   ge/hybrid/model/hybrid_model.h
	modified:   ge/hybrid/model/hybrid_model_builder.cc
	modified:   ge/hybrid/node_executor/task_context.cc
pull/1204/head
zhaoxinxin 4 years ago
parent 80f41237c5
commit 58a3e06c17

@ -394,6 +394,10 @@ static Status InsertMemcpyNode(const ComputeGraphPtr &graph, const OutDataAnchor
}
static Status GenerateTaskForConstant(const std::shared_ptr<ComputeGraph> &graph) {
if (graph->GetGraphUnknownFlag()) {
GELOGI("Graph %s is unknown graph, ignore gen_task for constant.", graph->GetName().c_str());
return SUCCESS;
}
for (auto &node : graph->GetDirectNode()) {
// CONSTANT not generate task, so insert IDENTITY between CONSTANT and NETOUTPUT
auto op_desc = node->GetOpDesc();

@ -297,10 +297,8 @@ Status ModelManager::LoadModelOnline(uint32_t &model_id, const shared_ptr<ge::Ge
GenModelId(&model_id);
}
bool is_shape_unknown = false;
string model_name = "";
GE_CHK_STATUS_RET(ge_root_model->CheckIsUnknownShape(is_shape_unknown), "CheckIsUnknownShape failed, model id:%u",
model_id);
bool is_shape_unknown = ge_root_model->GetRootGraph()->GetGraphUnknownFlag();
if (is_shape_unknown || GetContext().GetHostExecFlag()) {
return DoLoadHybridModelOnline(model_id, model_name, ge_root_model, listener);
}

@ -61,4 +61,5 @@ Status IdentityKernel::Compute(const ge::OpDescPtr op_desc, const std::vector<ge
return SUCCESS;
}
REGISTER_KERNEL(IDENTITY, IdentityKernel);
REGISTER_KERNEL(PLACEHOLDERWITHDEFAULT, IdentityKernel);
} // namespace ge

@ -150,6 +150,7 @@ class HybridModel {
uint32_t model_id_ = 0;
uint8_t *var_mem_base_ = nullptr;
std::unique_ptr<TensorBuffer> weight_buffer_;
std::map<string, std::unique_ptr<TensorBuffer>> weight_buffer_map_;
RuntimeParam root_runtime_param_;
string om_name_;
};

@ -996,70 +996,65 @@ Status HybridModelBuilder::InitVariableTensors() {
Status HybridModelBuilder::InitWeights() {
// For constant in root graph
const auto &root_graph = ge_root_model_->GetRootGraph();
const auto &subgraph_models = ge_root_model_->GetSubgraphInstanceNameToModel();
auto iter = subgraph_models.find(root_graph->GetName());
if (iter == subgraph_models.end()) {
GELOGD("Root graph model not found");
return SUCCESS;
}
for (const auto &subgraph_model : ge_root_model_->GetSubgraphInstanceNameToModel()) {
const auto &weight_buffer = subgraph_model.second->GetWeight();
if (weight_buffer.GetSize() == 0) {
GELOGD("weight is empty");
return SUCCESS;
}
auto &root_model = iter->second;
const auto &weight_buffer = root_model->GetWeight();
if (weight_buffer.GetSize() == 0) {
GELOGD("weight is empty");
return SUCCESS;
}
auto allocator = NpuMemoryAllocator::GetAllocator();
GE_CHECK_NOTNULL(allocator);
auto sub_weight_buffer = TensorBuffer::Create(allocator, weight_buffer.size());
GE_CHECK_NOTNULL(sub_weight_buffer);
auto weight_base = reinterpret_cast<uint8_t *>(sub_weight_buffer->GetData());
GE_CHK_RT_RET(rtMemcpy(weight_base,
sub_weight_buffer->GetSize(),
weight_buffer.GetData(),
weight_buffer.GetSize(),
RT_MEMCPY_HOST_TO_DEVICE));
GELOGI("Init weight mem successfully, weight base %p, weight size = %zu",
weight_base,
sub_weight_buffer->GetSize());
auto root_graph = GraphUtils::GetComputeGraph(subgraph_model.second->GetGraph());
hybrid_model_.weight_buffer_map_.emplace(root_graph->GetName(),std::move(sub_weight_buffer));
for (auto &node : root_graph->GetDirectNode()) {
if (node->GetType() != CONSTANT) {
continue;
}
auto allocator = NpuMemoryAllocator::GetAllocator();
GE_CHECK_NOTNULL(allocator);
hybrid_model_.weight_buffer_ = TensorBuffer::Create(allocator, weight_buffer.size());
GE_CHECK_NOTNULL(hybrid_model_.weight_buffer_);
auto weight_base = reinterpret_cast<uint8_t *>(hybrid_model_.weight_buffer_->GetData());
GE_CHK_RT_RET(rtMemcpy(weight_base,
hybrid_model_.weight_buffer_->GetSize(),
weight_buffer.GetData(),
weight_buffer.GetSize(),
RT_MEMCPY_HOST_TO_DEVICE));
GELOGI("Init weight mem successfully, weight base %p, weight size = %zu",
weight_base,
hybrid_model_.weight_buffer_->GetSize());
for (auto &node : root_graph->GetDirectNode()) {
if (node->GetType() != CONSTANT) {
continue;
}
auto op_desc = node->GetOpDesc();
auto v_weights = ModelUtils::GetWeights(op_desc);
if (v_weights.empty()) {
GELOGE(INTERNAL_ERROR, "[%s] Constant has no value", node->GetName().c_str());
return INTERNAL_ERROR;
}
auto *ge_tensor = const_cast<GeTensor *>(v_weights[0].get());
GE_CHECK_NOTNULL(ge_tensor);
const GeTensorDesc &tensor_desc = ge_tensor->GetTensorDesc();
int64_t tensor_size = 0;
GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetSize(*op_desc->MutableOutputDesc(0), tensor_size),
"[%s] Failed to get tensor size",
node->GetName().c_str());
int64_t data_offset = 0;
GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetDataOffset(tensor_desc, data_offset),
"[%s] Failed to get data offset",
node->GetName().c_str());
GELOGD("[%s] Start to init Constant node [%s], size = %ld, offset = %ld",
GetGraphName(),
node->GetName().c_str(),
tensor_size,
data_offset);
auto op_desc = node->GetOpDesc();
auto v_weights = ModelUtils::GetWeights(op_desc);
if (v_weights.empty()) {
GELOGE(INTERNAL_ERROR, "[%s] Constant has no value", node->GetName().c_str());
return INTERNAL_ERROR;
auto tensor_buffer = TensorBuffer::Create(weight_base + data_offset, tensor_size);
GE_CHECK_NOTNULL(tensor_buffer);
std::unique_ptr<TensorValue> constant_tensor(new (std::nothrow)TensorValue(std::move(tensor_buffer)));
GE_CHECK_NOTNULL(constant_tensor);
constant_tensor->SetName("Constant_" + op_desc->GetName());
hybrid_model_.constant_tensors_.emplace(node, std::move(constant_tensor));
GELOGD("[%s] Constant node [%s] added, size = %ld", GetGraphName(), node->GetName().c_str(), tensor_size);
}
auto *ge_tensor = const_cast<GeTensor *>(v_weights[0].get());
GE_CHECK_NOTNULL(ge_tensor);
const GeTensorDesc &tensor_desc = ge_tensor->GetTensorDesc();
int64_t tensor_size = 0;
GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetSize(*op_desc->MutableOutputDesc(0), tensor_size),
"[%s] Failed to get tensor size",
node->GetName().c_str());
int64_t data_offset = 0;
GE_CHK_GRAPH_STATUS_RET(TensorUtils::GetDataOffset(tensor_desc, data_offset),
"[%s] Failed to get data offset",
node->GetName().c_str());
GELOGD("[%s] Start to init Constant node [%s], size = %ld, offset = %ld",
GetGraphName(),
node->GetName().c_str(),
tensor_size,
data_offset);
auto tensor_buffer = TensorBuffer::Create(weight_base + data_offset, tensor_size);
GE_CHECK_NOTNULL(tensor_buffer);
std::unique_ptr<TensorValue> constant_tensor(new (std::nothrow)TensorValue(std::move(tensor_buffer)));
GE_CHECK_NOTNULL(constant_tensor);
constant_tensor->SetName("Constant_" + op_desc->GetName());
hybrid_model_.constant_tensors_.emplace(node, std::move(constant_tensor));
GELOGD("[%s] Constant node [%s] added, size = %ld", GetGraphName(), node->GetName().c_str(), tensor_size);
}
return SUCCESS;
}

@ -236,7 +236,7 @@ Status TaskContext::AllocateOutput(int index,
ref_node->GetName().c_str(),
ref_node->GetType().c_str());
TensorValue *ref_tensor = execution_context_->model->GetVariable(ref_node->GetName());
TensorValue *ref_tensor = execution_context_->model->GetTensor(ref_node);
GE_CHECK_NOTNULL(ref_tensor);
outputs_start_[index] = *ref_tensor;
} else {

Loading…
Cancel
Save