|
|
|
@ -996,16 +996,8 @@ 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto &root_model = iter->second;
|
|
|
|
|
const auto &weight_buffer = root_model->GetWeight();
|
|
|
|
|
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;
|
|
|
|
@ -1013,18 +1005,20 @@ Status HybridModelBuilder::InitWeights() {
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
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,
|
|
|
|
|
hybrid_model_.weight_buffer_->GetSize(),
|
|
|
|
|
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,
|
|
|
|
|
hybrid_model_.weight_buffer_->GetSize());
|
|
|
|
|
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;
|
|
|
|
@ -1061,6 +1055,7 @@ Status HybridModelBuilder::InitWeights() {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|