Merged
【PR】:RunGraphWithStreamAsync support empty outputs #3306
tang-haojieAdd on Jun 1
【PR】:RunGraphWithStreamAsync support empty outputs #3306
Merged
Merged fromtang-haojie/gememory_pool_staticintocann/gedevelop
Total: 11 files changed+417-132
| @@ -44,21 +44,16 @@ | |||
| 44 | #include "register/core_num_utils.h" | 44 | #include "register/core_num_utils.h" |
| 45 | 45 | ||
| 46 | namespace ge { | 46 | namespace ge { |
| 47 | -void CopyGeOutputsMemToUserOutputs(const aclrtStream stream, const std::vector<GeTensor> &ge_outputs, | 47 | +void CopyGeOutputsMemToUserOutputs(const std::vector<GeTensor> &ge_outputs, std::vector<Tensor> &outputs) { |
| 48 | - std::vector<Tensor> &outputs) { | 48 | + if (outputs.size() != 0U) { |
| 49 | - // if alloc output memory by external allocator, should copy to user. | ||
| 50 | - AllocatorPtr external_allocator = ExternalAllocatorManager::GetExternalAllocator(stream); | ||
| 51 | - if (external_allocator == nullptr) { | ||
| 52 | return; | 49 | return; |
| 53 | } | 50 | } |
| 54 | 51 | ||
| 55 | - if (outputs.size() == 0U) { | 52 | + outputs.reserve(ge_outputs.size()); |
| 56 | - outputs.reserve(ge_outputs.size()); | 53 | + for (size_t i = 0UL; i < ge_outputs.size(); i++) { |
| 57 | - for (size_t i = 0UL; i < ge_outputs.size(); i++) { | 54 | + outputs.emplace_back(TensorAdapter::AsTensor(ge_outputs[i])); |
| 58 | - outputs.emplace_back(TensorAdapter::AsTensor(ge_outputs[i])); | 55 | + GELOGI("Return outputs memory malloc by allocator success, mem:%p, size:%u", outputs[i].GetData(), |
| 59 | - GELOGI("Return outputs memory malloc by external allocator success, mem:%p, size:%u", outputs[i].GetData(), | 56 | + outputs[i].GetSize()); |
| 60 | - outputs[i].GetSize()); | ||
| 61 | - } | ||
| 62 | } | 57 | } |
| 63 | } | 58 | } |
| 64 | namespace { | 59 | namespace { |
| @@ -479,7 +474,7 @@ Status InnerSession::RunGraphWithStreamAsync(uint32_t graph_id, aclrtStream stre | |||
| 479 | } | 474 | } |
| 480 | 475 | ||
| 481 | // if alloc output memory by external allocator, should return to user. | 476 | // if alloc output memory by external allocator, should return to user. |
| 482 | - CopyGeOutputsMemToUserOutputs(stream, ge_outputs, outputs); | 477 | + CopyGeOutputsMemToUserOutputs(ge_outputs, outputs); |
| 483 | if (logLevel_ <= DLOG_INFO) { | 478 | if (logLevel_ <= DLOG_INFO) { |
| 484 | GELOGI("Run graph with stream async success, session id = %" PRIu64 ", graph id = %u, stream = %p.", | 479 | GELOGI("Run graph with stream async success, session id = %" PRIu64 ", graph id = %u, stream = %p.", |
| 485 | session_id_, graph_id, stream); | 480 | session_id_, graph_id, stream); |
| @@ -175,8 +175,7 @@ class InnerSession { | |||
| 175 | UserHybridGraphManagerPtr user_hybrid_graph_manager_{nullptr}; | 175 | UserHybridGraphManagerPtr user_hybrid_graph_manager_{nullptr}; |
| 176 | }; | 176 | }; |
| 177 | using SessionPtr = std::shared_ptr<InnerSession>; | 177 | using SessionPtr = std::shared_ptr<InnerSession>; |
| 178 | -void CopyGeOutputsMemToUserOutputs(const aclrtStream stream, const std::vector<GeTensor> &ge_outputs, | 178 | +void CopyGeOutputsMemToUserOutputs(const std::vector<GeTensor> &ge_outputs, std::vector<Tensor> &outputs); |
| 179 | - std::vector<Tensor> &outputs); | ||
| 180 | } // namespace ge | 179 | } // namespace ge |
| 181 | 180 | ||
| 182 | #endif // GE_SESSION_INNER_SESSION_H_ | 181 | #endif // GE_SESSION_INNER_SESSION_H_ |
| @@ -137,13 +137,31 @@ int32_t GetGraphMaxParallelModelNum() { | |||
| 137 | return max_num; | 137 | return max_num; |
| 138 | } | 138 | } |
| 139 | 139 | ||
| 140 | -Status MallocOutputMemBlock(const GraphId &graph_id, const AllocatorPtr &external_allocator, | 140 | +Status CreateHbmManager(void *block, gert::TensorOperateType operate_type, void **out) { |
| 141 | + GE_ASSERT_NOTNULL(block); | ||
| 142 | + auto mem_block = reinterpret_cast<ge::MemBlock *>(block); | ||
| 143 | + GE_ASSERT((operate_type == gert::kGetTensorAddress || operate_type == gert::kFreeTensor || | ||
| 144 | + operate_type == gert::kPlusShareCount), "Unexpected operate type %d", static_cast<int32_t>(operate_type)); | ||
| 145 | + if (operate_type == gert::kGetTensorAddress) { | ||
| 146 | + GE_ASSERT_NOTNULL(out); | ||
| 147 | + *out = mem_block->GetAddr(); | ||
| 148 | + } | ||
| 149 | + if (operate_type == gert::kFreeTensor) { | ||
| 150 | + mem_block->Free(); | ||
| 151 | + } | ||
| 152 | + if (operate_type == gert::kPlusShareCount) { | ||
| 153 | + mem_block->AddCount(); | ||
| 154 | + } | ||
| 155 | + return SUCCESS; | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | +Status MallocOutputMemBlock(const GraphId &graph_id, ge::Allocator *allocator, | ||
| 141 | const size_t tensor_size, ge::MemBlock *&mem_block) { | 159 | const size_t tensor_size, ge::MemBlock *&mem_block) { |
| 142 | - mem_block = external_allocator->Malloc(tensor_size); | 160 | + mem_block = allocator->Malloc(tensor_size); |
| 143 | - GE_ASSERT((mem_block != nullptr), "malloc output memory failed by external allocator, graph_id:%u.", graph_id); | 161 | + GE_ASSERT((mem_block != nullptr), "malloc output memory failed by allocator, graph_id:%u.", graph_id); |
| 144 | GE_ASSERT((mem_block->GetAddr() != nullptr), | 162 | GE_ASSERT((mem_block->GetAddr() != nullptr), |
| 145 | - "malloc output memory failed by external allocator, output memory addr is null, graph_id:%u.", graph_id); | 163 | + "malloc output memory failed by allocator, output memory addr is null, graph_id:%u.", graph_id); |
| 146 | - GELOGI("Alloc output memory success by external allocator, mem_block:%p, addr:%p, size:%zu.", mem_block, | 164 | + GELOGI("Alloc output memory success by allocator, mem_block:%p, addr:%p, size:%zu.", mem_block, |
| 147 | mem_block->GetAddr(), tensor_size); | 165 | mem_block->GetAddr(), tensor_size); |
| 148 | return SUCCESS; | 166 | return SUCCESS; |
| 149 | } | 167 | } |
| @@ -151,7 +169,7 @@ Status MallocOutputMemBlock(const GraphId &graph_id, const AllocatorPtr &externa | |||
| 151 | Status BindOutputMemBlock(const size_t tensor_size, ge::MemBlock *const mem_block, GeTensor &ge_tensor) { | 169 | Status BindOutputMemBlock(const size_t tensor_size, ge::MemBlock *const mem_block, GeTensor &ge_tensor) { |
| 152 | const auto deleter = [mem_block](const uint8_t *device_data) { | 170 | const auto deleter = [mem_block](const uint8_t *device_data) { |
| 153 | (void)device_data; | 171 | (void)device_data; |
| 154 | - GELOGI("Free output memory which alloc by external allocator, mem_block:%p, addr:%p.", mem_block, | 172 | + GELOGI("Free output memory which alloc by allocator, mem_block:%p, addr:%p.", mem_block, |
| 155 | mem_block->GetAddr()); | 173 | mem_block->GetAddr()); |
| 156 | mem_block->Free(); | 174 | mem_block->Free(); |
| 157 | }; | 175 | }; |
| @@ -160,12 +178,12 @@ Status BindOutputMemBlock(const size_t tensor_size, ge::MemBlock *const mem_bloc | |||
| 160 | return SUCCESS; | 178 | return SUCCESS; |
| 161 | } | 179 | } |
| 162 | } // namespace | 180 | } // namespace |
| 163 | - | ||
| 164 | Status SetNetOutputTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph_node) { | 181 | Status SetNetOutputTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph_node) { |
| 165 | if (graph_node->IsSavedNetOutputTensorInfoFlag()) { | 182 | if (graph_node->IsSavedNetOutputTensorInfoFlag()) { |
| 166 | return SUCCESS; | 183 | return SUCCESS; |
| 167 | } | 184 | } |
| 168 | auto compute_graph = graph_node->GetComputeGraph(); | 185 | auto compute_graph = graph_node->GetComputeGraph(); |
| 186 | + GE_ASSERT_NOTNULL(compute_graph, "compute graph is null, graph_id:%u.", graph_id); | ||
| 169 | auto net_output_node = compute_graph->FindFirstNodeMatchType(NETOUTPUT); | 187 | auto net_output_node = compute_graph->FindFirstNodeMatchType(NETOUTPUT); |
| 170 | GE_ASSERT_NOTNULL(net_output_node, "netoutput node null, graph_id:%u.", graph_id); | 188 | GE_ASSERT_NOTNULL(net_output_node, "netoutput node null, graph_id:%u.", graph_id); |
| 171 | 189 | ||
| @@ -181,6 +199,29 @@ Status SetNetOutputTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph | |||
| 181 | return SUCCESS; | 199 | return SUCCESS; |
| 182 | } | 200 | } |
| 183 | 201 | ||
| 202 | +Status ModelManager::GetOutputAllocator(const uint32_t model_id, const aclrtStream stream, | ||
| 203 | + ge::Allocator *&allocator_ptr) { | ||
| 204 | + AllocatorPtr allocator = ExternalAllocatorManager::GetExternalAllocator(stream); | ||
| 205 | + if (allocator != nullptr) { | ||
| 206 | + GELOGI("Get external allocator for outputs, stream:%p, model_id:%u.", stream, model_id); | ||
| 207 | + allocator_ptr = allocator.get(); | ||
| 208 | + return SUCCESS; | ||
| 209 | + } | ||
| 210 | + const std::lock_guard<std::recursive_mutex> lk(map_mutex_); | ||
| 211 | + auto iter = model_built_allocator_.find(model_id); | ||
| 212 | + if (iter == model_built_allocator_.end()) { | ||
| 213 | + iter = model_built_allocator_.try_emplace(model_id).first; | ||
| 214 | + } | ||
| 215 | + auto *allocators = iter->second.GetAllocator("", stream); | ||
| 216 | + GE_ASSERT_NOTNULL(allocators, "get built-in allocator failed, model_id:%u.", model_id); | ||
| 217 | + auto *device_allocator = allocators->GetAllocator(gert::kOnDeviceHbm, | ||
| 218 | + static_cast<size_t>(gert::AllocatorUsage::kAllocNodeOutput)); | ||
| 219 | + GE_ASSERT_NOTNULL(device_allocator, "get device allocator failed, model_id:%u.", model_id); | ||
| 220 | + GELOGI("Get built-in allocator for outputs, stream:%p, model_id:%u.", stream, model_id); | ||
| 221 | + allocator_ptr = device_allocator; | ||
| 222 | + return SUCCESS; | ||
| 223 | +} | ||
| 224 | + | ||
| 184 | Status MallocConstMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | 225 | Status MallocConstMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, |
| 185 | const AllocatorPtr external_allocator) { | 226 | const AllocatorPtr external_allocator) { |
| 186 | // If the app is set, do not use external allocator | 227 | // If the app is set, do not use external allocator |
| @@ -314,106 +355,93 @@ Status CreateGertTensor(const GeTensorDescPtr ge_tensor_desc, gert::Tensor &gert | |||
| 314 | return SUCCESS; | 355 | return SUCCESS; |
| 315 | } | 356 | } |
| 316 | 357 | ||
| 317 | -Status MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | 358 | +Status ModelManager::EnsureTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph_node, |
| 318 | - const AllocatorPtr external_allocator, std::vector<gert::Tensor> &outputs) { | 359 | + const uint32_t model_id, const aclrtStream stream, |
| 319 | - // If the app is set, do not use external allocator | 360 | + ModelOutputTensorInfo &info) { |
| 361 | + GE_ASSERT_SUCCESS(SetNetOutputTensorInfo(graph_id, graph_node)); | ||
| 362 | + info.ret_tensor_size = graph_node->GetTensorSize(); | ||
| 363 | + info.ge_tensor_descs = graph_node->GetGeTensorDescPtr(); | ||
| 364 | + GE_ASSERT((info.ret_tensor_size.size() == info.ge_tensor_descs.size()), "tensor info invalid, graph_id:%u.", graph_id); | ||
| 365 | + GE_ASSERT_SUCCESS(GetOutputAllocator(model_id, stream, info.allocator_ptr)); | ||
| 366 | + return SUCCESS; | ||
| 367 | +} | ||
| 368 | + | ||
| 369 | +Status ModelManager::MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | ||
| 370 | + const uint32_t model_id, const aclrtStream stream, | ||
| 371 | + std::vector<gert::Tensor> &outputs) { | ||
| 320 | if (graph_node->IsAppRefreshFeatureMemory() || graph_node->IsAppRefreshConstMemory()) { | 372 | if (graph_node->IsAppRefreshFeatureMemory() || graph_node->IsAppRefreshConstMemory()) { |
| 321 | GELOGI("Outputs memory base has been set by app, graph_id:%u.", graph_id); | 373 | GELOGI("Outputs memory base has been set by app, graph_id:%u.", graph_id); |
| 322 | return SUCCESS; | 374 | return SUCCESS; |
| 323 | } | 375 | } |
| 324 | - GE_ASSERT_SUCCESS(SetNetOutputTensorInfo(graph_id, graph_node)); | ||
| 325 | - auto ret_tensor_size = graph_node->GetTensorSize(); | ||
| 326 | - auto ge_tensor_descs = graph_node->GetGeTensorDescPtr(); | ||
| 327 | - GE_ASSERT((ret_tensor_size.size() == ge_tensor_descs.size()), "tensor info invalid, graph_id:%u.", graph_id); | ||
| 328 | - auto HbmManager = [](void *block, gert::TensorOperateType operate_type, void **out) -> ge::graphStatus { | ||
| 329 | - GE_ASSERT_NOTNULL(block); | ||
| 330 | - auto mem_block = reinterpret_cast<ge::MemBlock *>(block); | ||
| 331 | - GE_ASSERT((operate_type == gert::kGetTensorAddress || operate_type == gert::kFreeTensor || | ||
| 332 | - operate_type == gert::kPlusShareCount), "Unexpected operate type %d", static_cast<int32_t>(operate_type)); | ||
| 333 | - if (operate_type == gert::kGetTensorAddress) { | ||
| 334 | - GE_ASSERT_NOTNULL(out); | ||
| 335 | - *out = mem_block->GetAddr(); | ||
| 336 | - } | ||
| 337 | - if (operate_type == gert::kFreeTensor) { | ||
| 338 | - mem_block->Free(); | ||
| 339 | - } | ||
| 340 | - if (operate_type == gert::kPlusShareCount) { | ||
| 341 | - mem_block->AddCount(); | ||
| 342 | - } | ||
| 343 | - return ge::GRAPH_SUCCESS; | ||
| 344 | - }; | ||
| 345 | - // the outputs is empty | ||
| 346 | - if (outputs.size() == 0U) { | ||
| 347 | - outputs.resize(ge_tensor_descs.size()); | ||
| 348 | - for (size_t i = 0UL; i < ge_tensor_descs.size(); i++) { | ||
| 349 | - auto &gert_tensor = outputs[i]; | ||
| 350 | - CreateGertTensor(ge_tensor_descs[i], gert_tensor); | ||
| 351 | - auto mem_block = external_allocator->Malloc(ret_tensor_size[i]); | ||
| 352 | - GE_ASSERT((mem_block != nullptr), "malloc output memory failed by external allocator, graph_id:%u.", graph_id); | ||
| 353 | - GE_ASSERT((mem_block->GetAddr() != nullptr), | ||
| 354 | - "malloc output memory failed by external allocator, output memory addr is null, graph_id:%u.", graph_id); | ||
| 355 | - gert_tensor.SetData(gert::TensorData{mem_block, HbmManager, mem_block->GetSize(), gert_tensor.GetPlacement()}); | ||
| 356 | - GELOGI("Alloc output memory success by external allocator, mem_block:%p, addr:%p, size:%u.", mem_block, | ||
| 357 | - mem_block->GetAddr(), ret_tensor_size[i]); | ||
| 358 | - } | ||
| 359 | - return SUCCESS; | ||
| 360 | - } | ||
| 361 | 376 | ||
| 362 | - GE_ASSERT((ret_tensor_size.size() == outputs.size()), "tensor info invalid, graph_id:%u.", graph_id); | 377 | + ModelOutputTensorInfo info; |
| 363 | - // just device memory don't alloc | 378 | + bool ensure_tensor_info_initialized = false; |
| 379 | + auto EnsureInfo = [&]() -> Status { | ||
| 380 | + if (ensure_tensor_info_initialized) { return SUCCESS; } | ||
| 381 | + GE_ASSERT_SUCCESS(EnsureTensorInfo(graph_id, graph_node, model_id, stream, info)); | ||
| 382 | + ensure_tensor_info_initialized = true; | ||
| 383 | + return SUCCESS; | ||
| 384 | + }; | ||
| 385 | + // outputs empty, create tensor objects without allocating memory | ||
| 386 | + if (outputs.size() == 0U) { | ||
| 387 | + GE_ASSERT_SUCCESS(EnsureInfo()); | ||
| 388 | + outputs.resize(info.ge_tensor_descs.size()); | ||
| 389 | + for (size_t i = 0UL; i < info.ge_tensor_descs.size(); i++) { | ||
| 390 | + CreateGertTensor(info.ge_tensor_descs[i], outputs[i]); | ||
| 391 | + } | ||
| 392 | + } | ||
| 393 | + // check each output, skip if already has memory, allocate if not | ||
| 364 | for (size_t i = 0UL; i < outputs.size(); i++) { | 394 | for (size_t i = 0UL; i < outputs.size(); i++) { |
| 365 | - if (outputs[i].GetSize() != 0 && outputs[i].GetAddr() != nullptr) { | 395 | + if (outputs[i].GetSize() != 0 && outputs[i].GetAddr() != nullptr) { continue; } |
| 366 | - continue; | 396 | + GE_ASSERT_SUCCESS(EnsureInfo()); |
| 367 | - } | 397 | + GE_ASSERT((info.ret_tensor_size.size() == outputs.size()), "tensor info invalid, graph_id:%u.", graph_id); |
| 368 | - // for outputs not init | 398 | + |
| 369 | if (outputs[i].GetFormat().GetOriginFormat() == FORMAT_RESERVED) { | 399 | if (outputs[i].GetFormat().GetOriginFormat() == FORMAT_RESERVED) { |
| 370 | - auto &gert_tensor = outputs[i]; | 400 | + CreateGertTensor(info.ge_tensor_descs[i], outputs[i]); |
| 371 | - CreateGertTensor(ge_tensor_descs[i], gert_tensor); | ||
| 372 | } | 401 | } |
| 373 | - auto mem_block = external_allocator->Malloc(ret_tensor_size[i]); | 402 | + auto mem_block = info.allocator_ptr->Malloc(info.ret_tensor_size[i]); |
| 374 | - GE_ASSERT((mem_block != nullptr), "malloc output memory failed by external allocator, graph_id:%u.", graph_id); | 403 | + GE_ASSERT((mem_block != nullptr), "malloc output memory failed by allocator, graph_id:%u.", graph_id); |
| 375 | GE_ASSERT((mem_block->GetAddr() != nullptr), | 404 | GE_ASSERT((mem_block->GetAddr() != nullptr), |
| 376 | - "malloc output memory failed by external allocator, output memory addr is null, graph_id:%u.", graph_id); | 405 | + "malloc output memory failed by allocator, output memory addr is null, graph_id:%u.", graph_id); |
| 377 | - outputs[i].SetData(gert::TensorData{mem_block, HbmManager, mem_block->GetSize(), gert::kOnDeviceHbm}); | 406 | + outputs[i].SetData(gert::TensorData{mem_block, CreateHbmManager, mem_block->GetSize(), outputs[i].GetPlacement()}); |
| 378 | - GELOGI("Alloc output memory success by external allocator, mem_block:%p, addr:%p, size:%u.", mem_block, | 407 | + GELOGI("Alloc output memory success by allocator, mem_block:%p, addr:%p, size:%u.", mem_block, |
| 379 | - mem_block->GetAddr(), ret_tensor_size[i]); | 408 | + mem_block->GetAddr(), info.ret_tensor_size[i]); |
| 380 | } | 409 | } |
| 381 | return SUCCESS; | 410 | return SUCCESS; |
| 382 | } | 411 | } |
| 383 | 412 | ||
| 384 | -Status MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | 413 | +Status ModelManager::MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, |
| 385 | - const AllocatorPtr external_allocator, std::vector<GeTensor> &outputs) { | 414 | + const uint32_t model_id, const aclrtStream stream, |
| 386 | - // If the app is set, do not use external allocator | 415 | + std::vector<GeTensor> &outputs) { |
| 387 | if (graph_node->IsAppRefreshFeatureMemory() || graph_node->IsAppRefreshConstMemory()) { | 416 | if (graph_node->IsAppRefreshFeatureMemory() || graph_node->IsAppRefreshConstMemory()) { |
| 388 | GELOGI("Outputs memory base has been set by app, graph_id:%u.", graph_id); | 417 | GELOGI("Outputs memory base has been set by app, graph_id:%u.", graph_id); |
| 389 | return SUCCESS; | 418 | return SUCCESS; |
| 390 | } | 419 | } |
| 391 | - GE_ASSERT_SUCCESS(SetNetOutputTensorInfo(graph_id, graph_node)); | ||
| 392 | - auto ret_tensor_size = graph_node->GetTensorSize(); | ||
| 393 | - auto ge_tensor_descs = graph_node->GetGeTensorDescPtr(); | ||
| 394 | - GE_ASSERT((ret_tensor_size.size() == ge_tensor_descs.size()), "tensor info invalid, graph_id:%u.", graph_id); | ||
| 395 | 420 | ||
| 396 | - // the outputs is empty | 421 | + ModelOutputTensorInfo info; |
| 397 | - if (outputs.size() == 0U) { | 422 | + bool tensor_info_initialized = false; |
| 398 | - for (size_t i = 0UL; i < ge_tensor_descs.size(); i++) { | 423 | + auto EnsureInfo = [&]() -> Status { |
| 399 | - GeTensor ge_tensor(*(ge_tensor_descs[i])); | 424 | + if (tensor_info_initialized) { return SUCCESS; } |
| 400 | - ge::MemBlock *mem_block = nullptr; | 425 | + GE_ASSERT_SUCCESS(EnsureTensorInfo(graph_id, graph_node, model_id, stream, info)); |
| 401 | - GE_ASSERT_SUCCESS(MallocOutputMemBlock(graph_id, external_allocator, ret_tensor_size[i], mem_block)); | 426 | + tensor_info_initialized = true; |
| 402 | - GE_ASSERT_SUCCESS(BindOutputMemBlock(ret_tensor_size[i], mem_block, ge_tensor)); | ||
| 403 | - outputs.emplace_back(std::move(ge_tensor)); | ||
| 404 | - } | ||
| 405 | return SUCCESS; | 427 | return SUCCESS; |
| 406 | - } | 428 | + }; |
| 407 | - | 429 | + // outputs empty, create tensor objects without allocating memory |
| 408 | - GE_ASSERT((ret_tensor_size.size() == outputs.size()), "tensor info invalid, graph_id:%u.", graph_id); | 430 | + if (outputs.size() == 0U) { |
| 409 | - // just device memory don't alloc | 431 | + GE_ASSERT_SUCCESS(EnsureInfo()); |
| 410 | - for (size_t i = 0UL; i < outputs.size(); i++) { | 432 | + for (size_t i = 0UL; i < info.ge_tensor_descs.size(); i++) { |
| 411 | - if (outputs[i].GetData().GetSize() != 0) { | 433 | + outputs.emplace_back(GeTensor(*(info.ge_tensor_descs[i]))); |
| 412 | - continue; | ||
| 413 | } | 434 | } |
| 435 | + } | ||
| 436 | + // check each output, skip if already has memory, allocate if not | ||
| 437 | + for (size_t i = 0UL; i < outputs.size(); i++) { | ||
| 438 | + if (outputs[i].GetData().GetSize() != 0) { continue; } | ||
| 439 | + GE_ASSERT_SUCCESS(EnsureInfo()); | ||
| 440 | + | ||
| 441 | + GE_ASSERT((info.ret_tensor_size.size() == outputs.size()), "tensor info invalid, graph_id:%u.", graph_id); | ||
| 414 | ge::MemBlock *mem_block = nullptr; | 442 | ge::MemBlock *mem_block = nullptr; |
| 415 | - GE_ASSERT_SUCCESS(MallocOutputMemBlock(graph_id, external_allocator, ret_tensor_size[i], mem_block)); | 443 | + GE_ASSERT_SUCCESS(MallocOutputMemBlock(graph_id, info.allocator_ptr, info.ret_tensor_size[i], mem_block)); |
| 416 | - GE_ASSERT_SUCCESS(BindOutputMemBlock(ret_tensor_size[i], mem_block, outputs[i])); | 444 | + GE_ASSERT_SUCCESS(BindOutputMemBlock(info.ret_tensor_size[i], mem_block, outputs[i])); |
| 417 | } | 445 | } |
| 418 | return SUCCESS; | 446 | return SUCCESS; |
| 419 | } | 447 | } |
| @@ -828,6 +856,7 @@ Status ModelManager::DeleteModel(const uint32_t id) { | |||
| 828 | (void)model_aicpu_kernel_.erase(model_key); | 856 | (void)model_aicpu_kernel_.erase(model_key); |
| 829 | davinci_model_delay_destruction = it->second; | 857 | davinci_model_delay_destruction = it->second; |
| 830 | (void)model_map_.erase(it); | 858 | (void)model_map_.erase(it); |
| 859 | + (void)model_built_allocator_.erase(id); | ||
| 831 | return SUCCESS; | 860 | return SUCCESS; |
| 832 | } | 861 | } |
| 833 | 862 | ||
| @@ -835,6 +864,7 @@ Status ModelManager::DeleteModel(const uint32_t id) { | |||
| 835 | if (hybrid_model_it != hybrid_model_map_.end()) { | 864 | if (hybrid_model_it != hybrid_model_map_.end()) { |
| 836 | hybrid_davinci_model_delay_destruction = hybrid_model_it->second; | 865 | hybrid_davinci_model_delay_destruction = hybrid_model_it->second; |
| 837 | (void)hybrid_model_map_.erase(hybrid_model_it); | 866 | (void)hybrid_model_map_.erase(hybrid_model_it); |
| 867 | + (void)model_built_allocator_.erase(id); | ||
| 838 | } else { | 868 | } else { |
| 839 | REPORT_INNER_ERR_MSG("E19999", "model_id:%u does not exist in model_map, check invalid", id); | 869 | REPORT_INNER_ERR_MSG("E19999", "model_id:%u does not exist in model_map, check invalid", id); |
| 840 | GELOGE(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "model id %u does not exist.", id); | 870 | GELOGE(ACL_ERROR_GE_EXEC_MODEL_ID_INVALID, "model id %u does not exist.", id); |
| @@ -1858,15 +1888,13 @@ Status ModelManager::ExecuteModelWithStreamAsync(const uint32_t model_id, const | |||
| 1858 | if (external_allocator != nullptr) { | 1888 | if (external_allocator != nullptr) { |
| 1859 | is_refreshable = graph_node->IsFeatureBaseRefreshable(); | 1889 | is_refreshable = graph_node->IsFeatureBaseRefreshable(); |
| 1860 | if (is_refreshable) { | 1890 | if (is_refreshable) { |
| 1861 | - // malloc feature memory by external allocator | ||
| 1862 | GE_ASSERT_SUCCESS( | 1891 | GE_ASSERT_SUCCESS( |
| 1863 | MallocFeatureMemory(graph_node->GetGraphId(), model_id, graph_node, external_allocator), | 1892 | MallocFeatureMemory(graph_node->GetGraphId(), model_id, graph_node, external_allocator), |
| 1864 | "malloc feature memory failed, graph_id:%u.", graph_node->GetGraphId()); | 1893 | "malloc feature memory failed, graph_id:%u.", graph_node->GetGraphId()); |
| 1865 | } | 1894 | } |
| 1866 | - // malloc outputs memory by external allocator | ||
| 1867 | - GE_ASSERT_SUCCESS(MallocOutputsMemory(graph_node->GetGraphId(), graph_node, external_allocator, output_tensor), | ||
| 1868 | - "malloc outputs memory failed, graph_id:%u.", graph_node->GetGraphId()); | ||
| 1869 | } | 1895 | } |
| 1896 | + GE_ASSERT_SUCCESS(MallocOutputsMemory(graph_node->GetGraphId(), graph_node, model_id, stream, output_tensor), | ||
| 1897 | + "malloc outputs memory failed, graph_id:%u.", graph_node->GetGraphId()); | ||
| 1870 | // ExecuteModelWithStreamAsync: static model use default | 1898 | // ExecuteModelWithStreamAsync: static model use default |
| 1871 | Status result = ExecuteModel(model_id, stream, true, input_tensor, output_tensor); | 1899 | Status result = ExecuteModel(model_id, stream, true, input_tensor, output_tensor); |
| 1872 | if (is_refreshable) { | 1900 | if (is_refreshable) { |
| @@ -1889,14 +1917,12 @@ Status ModelManager::ExecuteModelWithStreamAsync(const uint32_t model_id, const | |||
| 1889 | if (external_allocator != nullptr) { | 1917 | if (external_allocator != nullptr) { |
| 1890 | is_refreshable = graph_node->IsFeatureBaseRefreshable(); | 1918 | is_refreshable = graph_node->IsFeatureBaseRefreshable(); |
| 1891 | if (is_refreshable) { | 1919 | if (is_refreshable) { |
| 1892 | - // malloc feature memory by external allocator | ||
| 1893 | GE_ASSERT_SUCCESS(MallocFeatureMemory(graph_node->GetGraphId(), model_id, graph_node, external_allocator), | 1920 | GE_ASSERT_SUCCESS(MallocFeatureMemory(graph_node->GetGraphId(), model_id, graph_node, external_allocator), |
| 1894 | "malloc feature memory failed, graph_id:%u.", graph_node->GetGraphId()); | 1921 | "malloc feature memory failed, graph_id:%u.", graph_node->GetGraphId()); |
| 1895 | } | 1922 | } |
| 1896 | - // malloc outputs memory by external allocator | ||
| 1897 | - GE_ASSERT_SUCCESS(MallocOutputsMemory(graph_node->GetGraphId(), graph_node, external_allocator, output_tensor), | ||
| 1898 | - "malloc outputs memory failed, graph_id:%u.", graph_node->GetGraphId()); | ||
| 1899 | } | 1923 | } |
| 1924 | + GE_ASSERT_SUCCESS(MallocOutputsMemory(graph_node->GetGraphId(), graph_node, model_id, stream, output_tensor), | ||
| 1925 | + "malloc outputs memory failed, graph_id:%u.", graph_node->GetGraphId()); | ||
| 1900 | 1926 | ||
| 1901 | Status result = ExecuteModelWithStream(model_id, stream, true, input_tensor, output_tensor); | 1927 | Status result = ExecuteModelWithStream(model_id, stream, true, input_tensor, output_tensor); |
| 1902 | if (is_refreshable) { | 1928 | if (is_refreshable) { |
| @@ -34,6 +34,7 @@ | |||
| 34 | #include "graph/manager/graph_manager_utils.h" | 34 | #include "graph/manager/graph_manager_utils.h" |
| 35 | #include "graph/load/model_manager/davinci_model.h" | 35 | #include "graph/load/model_manager/davinci_model.h" |
| 36 | #include "hybrid/hybrid_davinci_model.h" | 36 | #include "hybrid/hybrid_davinci_model.h" |
| 37 | +#include "hybrid/executor/runtime_v2/scalable_allocator_manager.h" | ||
| 37 | #include "mmpa/mmpa_api.h" | 38 | #include "mmpa/mmpa_api.h" |
| 38 | #include "runtime/context.h" | 39 | #include "runtime/context.h" |
| 39 | #include "runtime/rt.h" | 40 | #include "runtime/rt.h" |
| @@ -46,6 +47,12 @@ struct AICPUKernelHolder { | |||
| 46 | size_t launch_count; | 47 | size_t launch_count; |
| 47 | }; | 48 | }; |
| 48 | 49 | ||
| 50 | +struct ModelOutputTensorInfo { | ||
| 51 | + std::vector<size_t> ret_tensor_size; | ||
| 52 | + std::vector<GeTensorDescPtr> ge_tensor_descs; | ||
| 53 | + ge::Allocator *allocator_ptr = nullptr; | ||
| 54 | +}; | ||
| 55 | + | ||
| 49 | class ModelManager { | 56 | class ModelManager { |
| 50 | public: | 57 | public: |
| 51 | static ModelManager &GetInstance(); | 58 | static ModelManager &GetInstance(); |
| @@ -353,6 +360,21 @@ class ModelManager { | |||
| 353 | platform_bin_handle_ = bin_handle; | 360 | platform_bin_handle_ = bin_handle; |
| 354 | } | 361 | } |
| 355 | } | 362 | } |
| 363 | + Status GetOutputAllocator(const uint32_t model_id, const aclrtStream stream, | ||
| 364 | + ge::Allocator *&allocator_ptr); | ||
| 365 | + | ||
| 366 | + Status EnsureTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph_node, | ||
| 367 | + const uint32_t model_id, const aclrtStream stream, | ||
| 368 | + ModelOutputTensorInfo &info); | ||
| 369 | + | ||
| 370 | + Status MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | ||
| 371 | + const uint32_t model_id, const aclrtStream stream, | ||
| 372 | + std::vector<GeTensor> &outputs); | ||
| 373 | + | ||
| 374 | + Status MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | ||
| 375 | + const uint32_t model_id, const aclrtStream stream, | ||
| 376 | + std::vector<gert::Tensor> &outputs); | ||
| 377 | + | ||
| 356 | private: | 378 | private: |
| 357 | /// @ingroup domi_ome | 379 | /// @ingroup domi_ome |
| 358 | /// @brief constructor | 380 | /// @brief constructor |
| @@ -413,6 +435,7 @@ class ModelManager { | |||
| 413 | std::set<uint32_t> model_shared_session_; // 存在多个模型共享同一份rtSession资源场景,在此记录这些modelID | 435 | std::set<uint32_t> model_shared_session_; // 存在多个模型共享同一份rtSession资源场景,在此记录这些modelID |
| 414 | std::map<uint32_t, std::shared_ptr<DavinciModel>> model_map_; | 436 | std::map<uint32_t, std::shared_ptr<DavinciModel>> model_map_; |
| 415 | std::map<uint32_t, std::shared_ptr<hybrid::HybridDavinciModel>> hybrid_model_map_; | 437 | std::map<uint32_t, std::shared_ptr<hybrid::HybridDavinciModel>> hybrid_model_map_; |
| 438 | + std::map<uint32_t, ScalableAllocatorManager> model_built_allocator_; | ||
| 416 | std::map<std::string, std::vector<uint64_t>> model_aicpu_kernel_; | 439 | std::map<std::string, std::vector<uint64_t>> model_aicpu_kernel_; |
| 417 | std::atomic<uint32_t> max_model_id_ = 1U; | 440 | std::atomic<uint32_t> max_model_id_ = 1U; |
| 418 | std::recursive_mutex map_mutex_; | 441 | std::recursive_mutex map_mutex_; |
| @@ -463,11 +486,6 @@ Status CalcTensorSizeByShape(const GeShape &shape, DataType data_type, size_t &r | |||
| 463 | 486 | ||
| 464 | Status SetNetOutputTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph_node); | 487 | Status SetNetOutputTensorInfo(const GraphId &graph_id, const GraphNodePtr &graph_node); |
| 465 | 488 | ||
| 466 | -Status MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | ||
| 467 | - const AllocatorPtr external_allocator, std::vector<GeTensor> &outputs); | ||
| 468 | - | ||
| 469 | -Status MallocOutputsMemory(const GraphId &graph_id, const GraphNodePtr &graph_node, | ||
| 470 | - const AllocatorPtr external_allocator, std::vector<gert::Tensor> &outputs); | ||
| 471 | Status CreateGertTensor(const GeTensorDescPtr ge_tensor_desc, gert::Tensor &gert_tensor); | 489 | Status CreateGertTensor(const GeTensorDescPtr ge_tensor_desc, gert::Tensor &gert_tensor); |
| 472 | void FreeFeatureMemory(const ge::GraphNodePtr &graph_node); | 490 | void FreeFeatureMemory(const ge::GraphNodePtr &graph_node); |
| 473 | } // namespace ge | 491 | } // namespace ge |
| @@ -1079,6 +1079,7 @@ TEST_F(FmMemoryRefreshTest, fm_memory_refresh_with_check_tensor_size) { | |||
| 1079 | inputs.emplace_back(input_tensor_2); | 1079 | inputs.emplace_back(input_tensor_2); |
| 1080 | 1080 | ||
| 1081 | ge::Tensor output_tensor_1; | 1081 | ge::Tensor output_tensor_1; |
| 1082 | + output_tensor_1.SetData(reinterpret_cast<uint8_t *>(input_data_2.data()), input_data_2.size() * sizeof(bool)); | ||
| 1082 | outputs.emplace_back(output_tensor_1); | 1083 | outputs.emplace_back(output_tensor_1); |
| 1083 | dlog_setlevel(GE_MODULE_NAME, DLOG_DEBUG, 0); | 1084 | dlog_setlevel(GE_MODULE_NAME, DLOG_DEBUG, 0); |
| 1084 | EXPECT_NE(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, inputs, outputs)); | 1085 | EXPECT_NE(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, inputs, outputs)); |
| @@ -1892,4 +1892,98 @@ TEST_F(GeApiTest, QueryUnregisteredIr) { | |||
| 1892 | OutType inputs, outputs, attrs; | 1892 | OutType inputs, outputs, attrs; |
| 1893 | EXPECT_NE(GetRegisteredIrDef("QueryIrTestOpNotRegistered", inputs, outputs, attrs), SUCCESS); | 1893 | EXPECT_NE(GetRegisteredIrDef("QueryIrTestOpNotRegistered", inputs, outputs, attrs), SUCCESS); |
| 1894 | } | 1894 | } |
| 1895 | + | ||
| 1896 | +TEST_F(GeApiTest, RunGraphWithStreamAsync_builtin_allocator_output_memory) { | ||
| 1897 | + dlog_setlevel(GE_MODULE_NAME, DLOG_INFO, 0); | ||
| 1898 | + gert::GertRuntimeStub runtime_stub(false); | ||
| 1899 | + MockGenerateTask(); | ||
| 1900 | + | ||
| 1901 | + std::map<AscendString, AscendString> options; | ||
| 1902 | + options.emplace(ge::OPTION_GRAPH_RUN_MODE, AscendString("0")); | ||
| 1903 | + Session session(options); | ||
| 1904 | + | ||
| 1905 | + auto graph = BuildAddGraph(); | ||
| 1906 | + uint32_t graph_id = 1; | ||
| 1907 | + EXPECT_EQ(session.AddGraph(graph_id, graph), SUCCESS); | ||
| 1908 | + EXPECT_EQ(session.CompileGraph(graph_id), SUCCESS); | ||
| 1909 | + | ||
| 1910 | + std::vector<ge::Tensor> inputs; | ||
| 1911 | + std::vector<ge::Tensor> outputs; | ||
| 1912 | + ConstructInputOutputTensor(inputs, outputs); | ||
| 1913 | + std::vector<ge::Tensor> builtin_outputs; | ||
| 1914 | + | ||
| 1915 | + ge::diagnoseSwitch::DisableDumper(); | ||
| 1916 | + runtime_stub.Clear(); | ||
| 1917 | + EXPECT_EQ(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, inputs, builtin_outputs)); | ||
| 1918 | + | ||
| 1919 | + EXPECT_NE(builtin_outputs.size(), 0U); | ||
| 1920 | + for (size_t i = 0UL; i < builtin_outputs.size(); ++i) { | ||
| 1921 | + EXPECT_NE(builtin_outputs[i].GetData(), nullptr); | ||
| 1922 | + EXPECT_GT(builtin_outputs[i].GetSize(), 0U); | ||
| 1923 | + } | ||
| 1924 | + | ||
| 1925 | + std::vector<ge::Tensor> builtin_outputs2; | ||
| 1926 | + EXPECT_EQ(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, inputs, builtin_outputs2)); | ||
| 1927 | + EXPECT_NE(builtin_outputs2.size(), 0U); | ||
| 1928 | + for (size_t i = 0UL; i < builtin_outputs2.size(); ++i) { | ||
| 1929 | + EXPECT_NE(builtin_outputs2[i].GetData(), nullptr); | ||
| 1930 | + EXPECT_GT(builtin_outputs2[i].GetSize(), 0U); | ||
| 1931 | + } | ||
| 1932 | +} | ||
| 1933 | + | ||
| 1934 | +TEST_F(GeApiTest, ExecuteGraphWithStreamAsync_builtin_allocator_output_memory) { | ||
| 1935 | + dlog_setlevel(GE_MODULE_NAME, DLOG_INFO, 0); | ||
| 1936 | + gert::GertRuntimeStub runtime_stub(false); | ||
| 1937 | + MockGenerateTask(); | ||
| 1938 | + | ||
| 1939 | + std::map<std::string, std::string> options_init; | ||
| 1940 | + options_init.emplace(ge::OPTION_CONST_LIFECYCLE, "graph"); | ||
| 1941 | + options_init.emplace(ge::OPTION_FEATURE_BASE_REFRESHABLE, "1"); | ||
| 1942 | + options_init.emplace(ge::OPTION_GRAPH_RUN_MODE, "1"); | ||
| 1943 | + | ||
| 1944 | + std::map<AscendString, AscendString> options; | ||
| 1945 | + Session session(options_init); | ||
| 1946 | + | ||
| 1947 | + auto graph = BuildAddGraph(); | ||
| 1948 | + uint32_t graph_id = 1; | ||
| 1949 | + EXPECT_EQ(session.AddGraph(graph_id, graph), SUCCESS); | ||
| 1950 | + EXPECT_EQ(session.CompileGraph(graph_id), SUCCESS); | ||
| 1951 | + | ||
| 1952 | + options.emplace("ge.exec.frozenInputIndexes", "0,1111,10"); | ||
| 1953 | + EXPECT_EQ(SUCCESS, session.LoadGraph(graph_id, options, nullptr)); | ||
| 1954 | + | ||
| 1955 | + std::vector<int32_t> input_data_1(1 * 2 * 3 * 4, 666); | ||
| 1956 | + std::vector<int32_t> input_data_2(1 * 2 * 3 * 4, 666); | ||
| 1957 | + std::vector<gert::Tensor> gert_inputs; | ||
| 1958 | + gert_inputs.resize(2); | ||
| 1959 | + gert_inputs[0] = {{{1, 2, 3, 4}, {1, 2, 3, 4}}, | ||
| 1960 | + {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, | ||
| 1961 | + gert::kOnDeviceHbm, | ||
| 1962 | + ge::DT_INT32, | ||
| 1963 | + (void *) input_data_1.data()}; | ||
| 1964 | + gert_inputs[1] = {{{1, 2, 3, 4}, {1, 2, 3, 4}}, | ||
| 1965 | + {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, | ||
| 1966 | + gert::kOnDeviceHbm, | ||
| 1967 | + ge::DT_INT32, | ||
| 1968 | + (void *) input_data_2.data()}; | ||
| 1969 | + | ||
| 1970 | + std::vector<gert::Tensor> gert_outputs; | ||
| 1971 | + ge::diagnoseSwitch::DisableDumper(); | ||
| 1972 | + runtime_stub.Clear(); | ||
| 1973 | + EXPECT_EQ(SUCCESS, session.ExecuteGraphWithStreamAsync(graph_id, nullptr, gert_inputs, gert_outputs)); | ||
| 1974 | + | ||
| 1975 | + EXPECT_NE(gert_outputs.size(), 0U); | ||
| 1976 | + for (size_t i = 0UL; i < gert_outputs.size(); ++i) { | ||
| 1977 | + EXPECT_NE(gert_outputs[i].GetAddr(), nullptr); | ||
| 1978 | + EXPECT_GT(gert_outputs[i].GetSize(), 0U); | ||
| 1979 | + } | ||
| 1980 | + | ||
| 1981 | + std::vector<gert::Tensor> gert_outputs2; | ||
| 1982 | + EXPECT_EQ(SUCCESS, session.ExecuteGraphWithStreamAsync(graph_id, nullptr, gert_inputs, gert_outputs2)); | ||
| 1983 | + EXPECT_NE(gert_outputs2.size(), 0U); | ||
| 1984 | + for (size_t i = 0UL; i < gert_outputs2.size(); ++i) { | ||
| 1985 | + EXPECT_NE(gert_outputs2[i].GetAddr(), nullptr); | ||
| 1986 | + EXPECT_GT(gert_outputs2[i].GetSize(), 0U); | ||
| 1987 | + } | ||
| 1988 | +} | ||
| 1895 | } // namespace ge | 1989 | } // namespace ge |
| @@ -2346,4 +2346,107 @@ TEST_F(GeApiV2Test, GeSessionAddGraphFailedAfterGEFinalizeV2) { | |||
| 2346 | 2346 | ||
| 2347 | ReInitGe(); | 2347 | ReInitGe(); |
| 2348 | } | 2348 | } |
| 2349 | + | ||
| 2350 | +TEST_F(GeApiV2Test, RunGraphWithStreamAsync_builtin_allocator_output_memory) { | ||
| 2351 | + gert::GertRuntimeStub runtime_stub(false); | ||
| 2352 | + MockGenerateTask(); | ||
| 2353 | + | ||
| 2354 | + std::map<AscendString, AscendString> options; | ||
| 2355 | + options.emplace(ge::OPTION_GRAPH_RUN_MODE, AscendString("0")); | ||
| 2356 | + GeSession session(options); | ||
| 2357 | + | ||
| 2358 | + auto graph = BuildAddGraph(); | ||
| 2359 | + uint32_t graph_id = 1; | ||
| 2360 | + EXPECT_EQ(session.AddGraph(graph_id, graph), SUCCESS); | ||
| 2361 | + EXPECT_EQ(session.CompileGraph(graph_id), SUCCESS); | ||
| 2362 | + | ||
| 2363 | + std::vector<gert::Tensor> gert_inputs; | ||
| 2364 | + gert_inputs.resize(2); | ||
| 2365 | + std::vector<int32_t> input_data_1(1 * 2 * 3 * 4, 666); | ||
| 2366 | + gert_inputs[0] = {{{1, 2, 3, 4}, {1, 2, 3, 4}}, | ||
| 2367 | + {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, | ||
| 2368 | + gert::kOnDeviceHbm, | ||
| 2369 | + ge::DT_INT32, | ||
| 2370 | + (void *) input_data_1.data()}; | ||
| 2371 | + std::vector<int32_t> input_data_2(1 * 2 * 3 * 4, 666); | ||
| 2372 | + gert_inputs[1] = {{{1, 2, 3, 4}, {1, 2, 3, 4}}, | ||
| 2373 | + {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, | ||
| 2374 | + gert::kOnDeviceHbm, | ||
| 2375 | + ge::DT_INT32, | ||
| 2376 | + (void *) input_data_2.data()}; | ||
| 2377 | + | ||
| 2378 | + std::vector<gert::Tensor> gert_outputs; | ||
| 2379 | + ge::diagnoseSwitch::DisableDumper(); | ||
| 2380 | + runtime_stub.Clear(); | ||
| 2381 | + EXPECT_EQ(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, gert_inputs, gert_outputs)); | ||
| 2382 | + | ||
| 2383 | + EXPECT_NE(gert_outputs.size(), 0U); | ||
| 2384 | + for (size_t i = 0UL; i < gert_outputs.size(); ++i) { | ||
| 2385 | + EXPECT_NE(gert_outputs[i].GetAddr(), nullptr); | ||
| 2386 | + EXPECT_GT(gert_outputs[i].GetSize(), 0U); | ||
| 2387 | + } | ||
| 2388 | + | ||
| 2389 | + std::vector<gert::Tensor> gert_outputs2; | ||
| 2390 | + EXPECT_EQ(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, gert_inputs, gert_outputs2)); | ||
| 2391 | + EXPECT_NE(gert_outputs2.size(), 0U); | ||
| 2392 | + for (size_t i = 0UL; i < gert_outputs2.size(); ++i) { | ||
| 2393 | + EXPECT_NE(gert_outputs2[i].GetAddr(), nullptr); | ||
| 2394 | + EXPECT_GT(gert_outputs2[i].GetSize(), 0U); | ||
| 2395 | + } | ||
| 2396 | +} | ||
| 2397 | + | ||
| 2398 | +TEST_F(GeApiV2Test, RunGraphWithStreamAsync_builtin_allocator_output_memory_dynamic) { | ||
| 2399 | + gert::GertRuntimeStub runtime_stub(false); | ||
| 2400 | + MockGenerateTask(); | ||
| 2401 | + | ||
| 2402 | + std::map<AscendString, AscendString> options_init; | ||
| 2403 | + options_init.emplace(ge::OPTION_CONST_LIFECYCLE, "graph"); | ||
| 2404 | + options_init.emplace(ge::OPTION_FEATURE_BASE_REFRESHABLE, "1"); | ||
| 2405 | + options_init.emplace(ge::OPTION_GRAPH_RUN_MODE, "1"); | ||
| 2406 | + | ||
| 2407 | + std::map<AscendString, AscendString> options; | ||
| 2408 | + GeSession session(options_init); | ||
| 2409 | + | ||
| 2410 | + auto graph = BuildAddGraph(); | ||
| 2411 | + uint32_t graph_id = 1; | ||
| 2412 | + EXPECT_EQ(session.AddGraph(graph_id, graph), SUCCESS); | ||
| 2413 | + EXPECT_EQ(session.CompileGraph(graph_id), SUCCESS); | ||
| 2414 | + | ||
| 2415 | + options.emplace("ge.exec.frozenInputIndexes", "0,1111,10"); | ||
| 2416 | + EXPECT_EQ(SUCCESS, session.LoadGraph(graph_id, options, nullptr)); | ||
| 2417 | + | ||
| 2418 | + std::vector<int32_t> input_data_1(1 * 2 * 3 * 4, 666); | ||
| 2419 | + std::vector<int32_t> input_data_2(1 * 2 * 3 * 4, 666); | ||
| 2420 | + std::vector<gert::Tensor> gert_inputs; | ||
| 2421 | + gert_inputs.resize(2); | ||
| 2422 | + gert_inputs[0] = {{{1, 2, 3, 4}, {1, 2, 3, 4}}, | ||
| 2423 | + {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, | ||
| 2424 | + gert::kOnDeviceHbm, | ||
| 2425 | + ge::DT_INT32, | ||
| 2426 | + (void *) input_data_1.data()}; | ||
| 2427 | + gert_inputs[1] = {{{1, 2, 3, 4}, {1, 2, 3, 4}}, | ||
| 2428 | + {ge::FORMAT_ND, ge::FORMAT_FRACTAL_NZ, {}}, | ||
| 2429 | + gert::kOnDeviceHbm, | ||
| 2430 | + ge::DT_INT32, | ||
| 2431 | + (void *) input_data_2.data()}; | ||
| 2432 | + | ||
| 2433 | + std::vector<gert::Tensor> gert_outputs; | ||
| 2434 | + ge::diagnoseSwitch::DisableDumper(); | ||
| 2435 | + runtime_stub.Clear(); | ||
| 2436 | + EXPECT_EQ(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, gert_inputs, gert_outputs)); | ||
| 2437 | + | ||
| 2438 | + EXPECT_NE(gert_outputs.size(), 0U); | ||
| 2439 | + for (size_t i = 0UL; i < gert_outputs.size(); ++i) { | ||
| 2440 | + EXPECT_NE(gert_outputs[i].GetAddr(), nullptr); | ||
| 2441 | + EXPECT_GT(gert_outputs[i].GetSize(), 0U); | ||
| 2442 | + } | ||
| 2443 | + | ||
| 2444 | + std::vector<gert::Tensor> gert_outputs2; | ||
| 2445 | + EXPECT_EQ(SUCCESS, session.RunGraphWithStreamAsync(graph_id, nullptr, gert_inputs, gert_outputs2)); | ||
| 2446 | + EXPECT_NE(gert_outputs2.size(), 0U); | ||
| 2447 | + for (size_t i = 0UL; i < gert_outputs2.size(); ++i) { | ||
| 2448 | + EXPECT_NE(gert_outputs2[i].GetAddr(), nullptr); | ||
| 2449 | + EXPECT_GT(gert_outputs2[i].GetSize(), 0U); | ||
| 2450 | + } | ||
| 2451 | +} | ||
| 2349 | } // namespace ge | 2452 | } // namespace ge |
| @@ -1227,7 +1227,7 @@ TEST_F(UtestModelExecutorTest, test_run_graph_with_stream) { | |||
| 1227 | model_executor.StartRunThread(); | 1227 | model_executor.StartRunThread(); |
| 1228 | 1228 | ||
| 1229 | GraphId graph_id = 1; | 1229 | GraphId graph_id = 1; |
| 1230 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | 1230 | + auto compute_graph = CreateGraphWithConstOutput(); |
| 1231 | GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | 1231 | GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); |
| 1232 | EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | 1232 | EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); |
| 1233 | 1233 | ||
| @@ -1240,6 +1240,7 @@ TEST_F(UtestModelExecutorTest, test_run_graph_with_stream) { | |||
| 1240 | 1240 | ||
| 1241 | GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | 1241 | GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); |
| 1242 | graph_node->SetGeRootModel(ge_root_model); | 1242 | graph_node->SetGeRootModel(ge_root_model); |
| 1243 | + graph_node->SetComputeGraph(compute_graph); | ||
| 1243 | graph_node->SetLoadFlag(false); | 1244 | graph_node->SetLoadFlag(false); |
| 1244 | graph_node->SetAsync(true); | 1245 | graph_node->SetAsync(true); |
| 1245 | 1246 | ||
| @@ -1249,7 +1250,7 @@ TEST_F(UtestModelExecutorTest, test_run_graph_with_stream) { | |||
| 1249 | 1250 | ||
| 1250 | rtStream_t stream = nullptr; | 1251 | rtStream_t stream = nullptr; |
| 1251 | rtStreamCreate(&stream, 0); | 1252 | rtStreamCreate(&stream, 0); |
| 1252 | - EXPECT_EQ(model_executor.RunGraphWithStream(graph_node, graph_id, stream, inputs, outputs), 1343225857); | 1253 | + EXPECT_EQ(model_executor.RunGraphWithStream(graph_node, graph_id, stream, inputs, outputs), PARAM_INVALID); |
| 1253 | 1254 | ||
| 1254 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); | 1255 | EXPECT_EQ(model_executor.Finalize(), SUCCESS); |
| 1255 | 1256 | ||
| @@ -1263,7 +1264,7 @@ TEST_F(UtestModelExecutorTest, test_execute_graph_with_stream) { | |||
| 1263 | model_executor.StartRunThread(); | 1264 | model_executor.StartRunThread(); |
| 1264 | 1265 | ||
| 1265 | GraphId graph_id = 1; | 1266 | GraphId graph_id = 1; |
| 1266 | - auto compute_graph = MakeShared<ComputeGraph>("test_graph"); | 1267 | + auto compute_graph = CreateGraphWithConstOutput(); |
| 1267 | GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); | 1268 | GeRootModelPtr ge_root_model = MakeShared<GeRootModel>(); |
| 1268 | EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); | 1269 | EXPECT_EQ(ge_root_model->Initialize(compute_graph), SUCCESS); |
| 1269 | 1270 | ||
| @@ -1276,6 +1277,7 @@ TEST_F(UtestModelExecutorTest, test_execute_graph_with_stream) { | |||
| 1276 | 1277 | ||
| 1277 | GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); | 1278 | GraphNodePtr graph_node = MakeShared<ge::GraphNode>(graph_id); |
| 1278 | graph_node->SetGeRootModel(ge_root_model); | 1279 | graph_node->SetGeRootModel(ge_root_model); |
| 1280 | + graph_node->SetComputeGraph(compute_graph); | ||
| 1279 | graph_node->SetLoadFlag(false); | 1281 | graph_node->SetLoadFlag(false); |
| 1280 | graph_node->SetAsync(true); | 1282 | graph_node->SetAsync(true); |
| 1281 | 1283 | ||
| @@ -1294,7 +1296,7 @@ TEST_F(UtestModelExecutorTest, test_execute_graph_with_stream) { | |||
| 1294 | GeTensor tensor; | 1296 | GeTensor tensor; |
| 1295 | std::vector<GeTensor> inputs{tensor}; | 1297 | std::vector<GeTensor> inputs{tensor}; |
| 1296 | std::vector<GeTensor> outputs; | 1298 | std::vector<GeTensor> outputs; |
| 1297 | - EXPECT_EQ(model_executor.RunGraphWithStream(graph_node, graph_id, stream, inputs, outputs), 1343225857); | 1299 | + EXPECT_EQ(model_executor.RunGraphWithStream(graph_node, graph_id, stream, inputs, outputs), PARAM_INVALID); |
| 1298 | EXPECT_EQ(model_executor.ExecuteGraphWithStream(graph_node, graph_id, stream, gert_inputs, gert_outputs), ACL_ERROR_GE_EXEC_MODEL_ID_INVALID); | 1300 | EXPECT_EQ(model_executor.ExecuteGraphWithStream(graph_node, graph_id, stream, gert_inputs, gert_outputs), ACL_ERROR_GE_EXEC_MODEL_ID_INVALID); |
| 1299 | GraphNodePtr graph_node_2 = MakeShared<ge::GraphNode>(2); | 1301 | GraphNodePtr graph_node_2 = MakeShared<ge::GraphNode>(2); |
| 1300 | EXPECT_NE(model_executor.ExecuteGraphWithStream(graph_node_2, 2, stream, gert_inputs, gert_outputs), SUCCESS); | 1302 | EXPECT_NE(model_executor.ExecuteGraphWithStream(graph_node_2, 2, stream, gert_inputs, gert_outputs), SUCCESS); |
| @@ -1799,7 +1799,9 @@ TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_AppRefreshable) { | |||
| 1799 | graph_node->SetCompiledFlag(true); | 1799 | graph_node->SetCompiledFlag(true); |
| 1800 | graph_node->SetAppRefreshFeatureMemoryFlag(); | 1800 | graph_node->SetAppRefreshFeatureMemoryFlag(); |
| 1801 | std::vector<gert::Tensor> outputs_empty; | 1801 | std::vector<gert::Tensor> outputs_empty; |
| 1802 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, nullptr, outputs_empty), SUCCESS); | 1802 | + uint32_t model_id = 1; |
| 1803 | + aclrtStream stream = reinterpret_cast<aclrtStream>(1); | ||
| 1804 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs_empty), SUCCESS); | ||
| 1803 | } | 1805 | } |
| 1804 | 1806 | ||
| 1805 | TEST_F(UtestModelManagerModelManager, MallocConstMemory_AppRefreshable) { | 1807 | TEST_F(UtestModelManagerModelManager, MallocConstMemory_AppRefreshable) { |
| @@ -2156,6 +2158,7 @@ TEST_F(UtestModelManagerModelManager, test_execute_model3) { | |||
| 2156 | 2158 | ||
| 2157 | EXPECT_NE(mm.ExecuteModelWithStreamAsync(model_id, graph_node, gert_input_tensor, | 2159 | EXPECT_NE(mm.ExecuteModelWithStreamAsync(model_id, graph_node, gert_input_tensor, |
| 2158 | gert_output_tensor, stream), SUCCESS); | 2160 | gert_output_tensor, stream), SUCCESS); |
| 2161 | + ExternalAllocatorManager::DeleteExternalAllocator(stream); | ||
| 2159 | } | 2162 | } |
| 2160 | 2163 | ||
| 2161 | TEST_F(UtestModelManagerModelManager, CalcTensorSizeByShape_string) { | 2164 | TEST_F(UtestModelManagerModelManager, CalcTensorSizeByShape_string) { |
| @@ -2206,14 +2209,18 @@ TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_success) { | |||
| 2206 | output.ClearData(); | 2209 | output.ClearData(); |
| 2207 | outputs.emplace_back(std::move(output)); | 2210 | outputs.emplace_back(std::move(output)); |
| 2208 | 2211 | ||
| 2209 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs), SUCCESS); | 2212 | + uint32_t model_id = 1; |
| 2213 | + aclrtStream stream = reinterpret_cast<aclrtStream>(1); | ||
| 2214 | + ExternalAllocatorManager::SetExternalAllocator(stream, external_allocator); | ||
| 2215 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs), SUCCESS); | ||
| 2210 | EXPECT_NE(outputs[0].GetData().GetSize(), 0); | 2216 | EXPECT_NE(outputs[0].GetData().GetSize(), 0); |
| 2211 | 2217 | ||
| 2212 | uint8_t mem = 0; | 2218 | uint8_t mem = 0; |
| 2213 | const AlignedPtr::Deleter deleter = [](const uint8_t *const ptr){ (void)ptr; }; | 2219 | const AlignedPtr::Deleter deleter = [](const uint8_t *const ptr){ (void)ptr; }; |
| 2214 | outputs[0].SetData(static_cast<uint8_t *>(&mem), 10, deleter); | 2220 | outputs[0].SetData(static_cast<uint8_t *>(&mem), 10, deleter); |
| 2215 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs), SUCCESS); | 2221 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs), SUCCESS); |
| 2216 | EXPECT_EQ(outputs[0].GetData().GetSize(), 10); | 2222 | EXPECT_EQ(outputs[0].GetData().GetSize(), 10); |
| 2223 | + ExternalAllocatorManager::DeleteExternalAllocator(stream); | ||
| 2217 | } | 2224 | } |
| 2218 | 2225 | ||
| 2219 | TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_outputs_empty_success) { | 2226 | TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_outputs_empty_success) { |
| @@ -2232,8 +2239,12 @@ TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_outputs_empty_success) | |||
| 2232 | graph_manager.executor_ = &executor; | 2239 | graph_manager.executor_ = &executor; |
| 2233 | std::vector<GeTensor> outputs; | 2240 | std::vector<GeTensor> outputs; |
| 2234 | 2241 | ||
| 2235 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs), SUCCESS); | 2242 | + uint32_t model_id = 1; |
| 2243 | + aclrtStream stream = reinterpret_cast<aclrtStream>(1); | ||
| 2244 | + ExternalAllocatorManager::SetExternalAllocator(stream, external_allocator); | ||
| 2245 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs), SUCCESS); | ||
| 2236 | EXPECT_NE(outputs[0].GetData().GetSize(), 0); | 2246 | EXPECT_NE(outputs[0].GetData().GetSize(), 0); |
| 2247 | + ExternalAllocatorManager::DeleteExternalAllocator(stream); | ||
| 2237 | } | 2248 | } |
| 2238 | 2249 | ||
| 2239 | TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_success_with_gertTensor) { | 2250 | TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_success_with_gertTensor) { |
| @@ -2259,14 +2270,18 @@ TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_success_with_gertTenso | |||
| 2259 | ge::DT_FLOAT, // data type | 2270 | ge::DT_FLOAT, // data type |
| 2260 | (void *) output_data_1.data()}; | 2271 | (void *) output_data_1.data()}; |
| 2261 | 2272 | ||
| 2262 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs), SUCCESS); | 2273 | + uint32_t model_id = 1; |
| 2274 | + aclrtStream stream = reinterpret_cast<aclrtStream>(1); | ||
| 2275 | + ExternalAllocatorManager::SetExternalAllocator(stream, external_allocator); | ||
| 2276 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs), SUCCESS); | ||
| 2263 | EXPECT_EQ(outputs[0].GetSize(), 96); | 2277 | EXPECT_EQ(outputs[0].GetSize(), 96); |
| 2264 | std::vector<gert::Tensor> outputs_empty; | 2278 | std::vector<gert::Tensor> outputs_empty; |
| 2265 | outputs_empty.resize(1); | 2279 | outputs_empty.resize(1); |
| 2266 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs_empty), SUCCESS); | 2280 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs_empty), SUCCESS); |
| 2267 | EXPECT_EQ(outputs[0].GetSize(), 96); | 2281 | EXPECT_EQ(outputs[0].GetSize(), 96); |
| 2268 | graph_node->SetAppRefreshFeatureMemoryFlag(); | 2282 | graph_node->SetAppRefreshFeatureMemoryFlag(); |
| 2269 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs_empty), SUCCESS); | 2283 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs_empty), SUCCESS); |
| 2284 | + ExternalAllocatorManager::DeleteExternalAllocator(stream); | ||
| 2270 | } | 2285 | } |
| 2271 | 2286 | ||
| 2272 | TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_outputs_empty_success_with_gertTensor) { | 2287 | TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_outputs_empty_success_with_gertTensor) { |
| @@ -2285,8 +2300,12 @@ TEST_F(UtestModelManagerModelManager, MallocOutputsMemory_outputs_empty_success_ | |||
| 2285 | graph_manager.executor_ = &executor; | 2300 | graph_manager.executor_ = &executor; |
| 2286 | std::vector<gert::Tensor> outputs = {}; | 2301 | std::vector<gert::Tensor> outputs = {}; |
| 2287 | 2302 | ||
| 2288 | - EXPECT_EQ(MallocOutputsMemory(graph_id, graph_node, external_allocator, outputs), SUCCESS); | 2303 | + uint32_t model_id = 1; |
| 2304 | + aclrtStream stream = reinterpret_cast<aclrtStream>(1); | ||
| 2305 | + ExternalAllocatorManager::SetExternalAllocator(stream, external_allocator); | ||
| 2306 | + EXPECT_EQ(ModelManager::GetInstance().MallocOutputsMemory(graph_id, graph_node, model_id, stream, outputs), SUCCESS); | ||
| 2289 | EXPECT_NE(outputs[0].GetSize(), 0); | 2307 | EXPECT_NE(outputs[0].GetSize(), 0); |
| 2308 | + ExternalAllocatorManager::DeleteExternalAllocator(stream); | ||
| 2290 | } | 2309 | } |
| 2291 | 2310 | ||
| 2292 | TEST_F(UtestModelManagerModelManager, test_CreateGertTensor) { | 2311 | TEST_F(UtestModelManagerModelManager, test_CreateGertTensor) { |
| @@ -2537,4 +2556,29 @@ TEST_F(UtestModelManagerModelManager, ReadDumpDebugJsonFile_success) { | |||
| 2537 | EXPECT_EQ(json_result, expected_content); | 2556 | EXPECT_EQ(json_result, expected_content); |
| 2538 | remove(test_file.c_str()); | 2557 | remove(test_file.c_str()); |
| 2539 | } | 2558 | } |
| 2559 | + | ||
| 2560 | +TEST_F(UtestModelManagerModelManager, GetOutputAllocator_external_allocator_found) { | ||
| 2561 | + std::shared_ptr<Allocator> external_allocator = MakeShared<ExternalAllocatorUtStub>(); | ||
| 2562 | + aclrtStream stream = reinterpret_cast<aclrtStream>(0x1); | ||
| 2563 | + ExternalAllocatorManager::SetExternalAllocator(stream, external_allocator); | ||
| 2564 | + | ||
| 2565 | + uint32_t model_id = 1; | ||
| 2566 | + ge::Allocator *allocator_ptr = nullptr; | ||
| 2567 | + EXPECT_EQ(ModelManager::GetInstance().GetOutputAllocator(model_id, stream, allocator_ptr), SUCCESS); | ||
| 2568 | + EXPECT_EQ(allocator_ptr, external_allocator.get()); | ||
| 2569 | + ExternalAllocatorManager::DeleteExternalAllocator(stream); | ||
| 2570 | +} | ||
| 2571 | + | ||
| 2572 | + | ||
| 2573 | +TEST_F(UtestModelManagerModelManager, DeleteModel_erases_model_built_allocator) { | ||
| 2574 | + ModelManager mm; | ||
| 2575 | + uint32_t model_id = 42; | ||
| 2576 | + mm.model_built_allocator_[model_id]; | ||
| 2577 | + EXPECT_TRUE(mm.model_built_allocator_.find(model_id) != mm.model_built_allocator_.end()); | ||
| 2578 | + auto hybrid_model = std::make_shared<hybrid::HybridDavinciModel>(); | ||
| 2579 | + mm.hybrid_model_map_[model_id] = hybrid_model; | ||
| 2580 | + mm.DeleteModel(model_id); | ||
| 2581 | + EXPECT_TRUE(mm.model_built_allocator_.find(model_id) == mm.model_built_allocator_.end()); | ||
| 2582 | +} | ||
| 2583 | + | ||
| 2540 | } // namespace ge | 2584 | } // namespace ge |
| @@ -537,15 +537,17 @@ TEST_F(UtestInnerSession, CopyGeOutputsMemToUserOutputs_test) { | |||
| 537 | ge_tensor.SetData(mem1, size1, deleter); | 537 | ge_tensor.SetData(mem1, size1, deleter); |
| 538 | ge_outputs.emplace_back(std::move(ge_tensor)); | 538 | ge_outputs.emplace_back(std::move(ge_tensor)); |
| 539 | 539 | ||
| 540 | - CopyGeOutputsMemToUserOutputs(&stream, ge_outputs, outputs); | 540 | + CopyGeOutputsMemToUserOutputs(ge_outputs, outputs); |
| 541 | - EXPECT_EQ(outputs.size(), 0); | 541 | + EXPECT_EQ(outputs.size(), 1); |
| 542 | + EXPECT_EQ(outputs[0].GetData(), mem1); | ||
| 542 | 543 | ||
| 543 | EXPECT_EQ(inner_session.RegisterExternalAllocator(&stream, external_allocator), SUCCESS); | 544 | EXPECT_EQ(inner_session.RegisterExternalAllocator(&stream, external_allocator), SUCCESS); |
| 544 | EXPECT_EQ(ExternalAllocatorManager::GetExternalAllocator(&stream), external_allocator); | 545 | EXPECT_EQ(ExternalAllocatorManager::GetExternalAllocator(&stream), external_allocator); |
| 545 | 546 | ||
| 546 | - CopyGeOutputsMemToUserOutputs(&stream, ge_outputs, outputs); | 547 | + std::vector<ge::Tensor> outputs2; |
| 547 | - EXPECT_EQ(outputs.size(), 1); | 548 | + CopyGeOutputsMemToUserOutputs(ge_outputs, outputs2); |
| 548 | - EXPECT_EQ(outputs[0].GetData(), mem1); | 549 | + EXPECT_EQ(outputs2.size(), 1); |
| 550 | + EXPECT_EQ(outputs2[0].GetData(), mem1); | ||
| 549 | } | 551 | } |
| 550 | 552 | ||
| 551 | TEST_F(UtestInnerSession, PaRemapped_Match) { | 553 | TEST_F(UtestInnerSession, PaRemapped_Match) { |