Browse Source

optimize model manager::ExecuteModel

pull/1960/head
medivh-x 3 years ago
parent
commit
aaee4d2034
3 changed files with 76 additions and 1 deletions
  1. +1
    -1
      ge/graph/execute/graph_execute.cc
  2. +72
    -0
      ge/graph/load/model_manager/model_manager.cc
  3. +3
    -0
      ge/graph/load/model_manager/model_manager.h

+ 1
- 1
ge/graph/execute/graph_execute.cc View File

@@ -454,7 +454,7 @@ Status GraphExecutor::ExecuteGraphWithStream(GraphId graph_id,
auto async_mode = true;
auto model_manager = ge::ModelManager::GetInstance();
GE_CHECK_NOTNULL(model_manager);
ret = model_manager->ExecuteModel(model_id, stream, async_mode, input_data, input_desc, output_data, output_desc);
ret = model_manager->ExecuteModel(model_id, stream, async_mode, input_tensor, output_tensor);
if (ret != SUCCESS) {
return ret;
}


+ 72
- 0
ge/graph/load/model_manager/model_manager.cc View File

@@ -1332,6 +1332,78 @@ Status ModelManager::ExecuteModel(uint32_t model_id, rtStream_t stream, bool asy
return status;
}

namespace {
void GetGeTensorBlobs(const std::vector<GeTensor> &tensors, std::vector<DataBuffer> &blobs) {
blobs.resize(tensors.size());
for (size_t i = 0; i < tensors.size(); i++) {
auto &tensor = tensors[i];
auto &buf = blobs[i];
buf.data = const_cast<uint8_t *>(tensor.GetData().data());
buf.length = tensor.GetData().size();
buf.isDataSupportMemShare = false;
}
}

void GetGeTensorDescs(const std::vector<GeTensor> &tensors, std::vector<GeTensorDesc> &descs) {
descs.reserve(tensors.size());
for (auto &tensor : tensors) {
descs.emplace_back(std::move(tensor.GetTensorDesc()));
}
}
}

ge::Status ExecuteModel(uint32_t model_id, rtStream_t stream, bool async_mode, const std::vector<GeTensor> &input_tensor,
std::vector<GeTensor> &output_tensor) {
InputData input_data;
input_data.index = 0;
input_data.model_id = model_id;

OutputData output_data;
output_data.index = 0;
output_data.model_id = model_id;

GetGeTensorBlobs(input_tensor, input_data.blobs);
GetGeTensorBlobs(output_tensor, output_data.blobs);

std::shared_ptr<hybrid::HybridDavinciModel> hybrid_davinci_model = GetHybridModel(model_id);
if (hybrid_davinci_model != nullptr) {
std::vector<GeTensorDesc> input_desc;
std::vector<GeTensorDesc> output_desc;
GetGeTensorDescs(input_tensor, input_desc);
GetGeTensorDescs(output_tensor, output_desc);

Status status = hybrid_davinci_model->Execute(input_data.blobs, input_desc, output_data.blobs, output_desc, stream);
if (status == SUCCESS) {
GELOGI("Execute model %u success.", model_id);
}
return status;
}

std::shared_ptr<DavinciModel> davinci_model = GetModel(model_id);
GE_CHK_BOOL_RET_STATUS(davinci_model != nullptr, ACL_ERROR_GE_EXEC_MODEL_ID_INVALID,
"[Get][Model] Invalid model id %u, check whether model has been loaded or not.", model_id);

if (davinci_model->NeedDestroyAicpuKernel()) {
GELOGI("Start to destroy specified aicpu kernel.");
// Zero copy is enabled by default, no need to judge.
uint64_t session_id_davinci = davinci_model->GetSessionId();
uint32_t model_id_davinci = davinci_model->GetModelId();
uint32_t sub_model_id = davinci_model->SubModelId();
Status status = DestroyAicpuKernel(session_id_davinci, model_id_davinci, sub_model_id);
if (status != SUCCESS) {
GELOGW("Destroy specified aicpu kernel failed, session id is %lu, model id is %u.", session_id_davinci,
model_id_davinci);
}
}

Status status = davinci_model->NnExecute(stream, async_mode, input_data, output_data);
if (status == SUCCESS) {
GELOGD("Execute model %u success.", model_id);
}

return status;
}

Status ModelManager::CreateAicpuSession(uint64_t session_id) {
std::lock_guard<std::recursive_mutex> lock(map_mutex_);
auto it = sess_ids_.find(session_id);


+ 3
- 0
ge/graph/load/model_manager/model_manager.h View File

@@ -157,6 +157,9 @@ class FMK_FUNC_HOST_VISIBILITY FMK_FUNC_DEV_VISIBILITY ModelManager {
const std::vector<GeTensorDesc> &input_desc, OutputData &output_data,
std::vector<GeTensorDesc> &output_desc);

ge::Status ExecuteModel(uint32_t model_id, rtStream_t stream, bool async_mode, const std::vector<GeTensor> &inputs,
std::vector<GeTensor> &outputs);

ge::Status SyncExecuteModel(uint32_t model_id, const std::vector<GeTensor> &inputs, std::vector<GeTensor> &outputs);

///


Loading…
Cancel
Save