Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #include "ccu_registered_ctx_mgr.h"
12 : #include "ins_exe_que.h"
13 : #include "internal_exception.h"
14 :
15 : namespace Hccl {
16 :
17 : // 输入ccuIns和resPack,输出执行Id,判断对应指令是否注册过
18 3 : bool RegisteredCcuCtxMgr::HasRegistered(const CcuCtxSignature& ctxSignature, const uintptr_t& resPackId, u64& execId)
19 : {
20 : // 查询是否注册过
21 3 : if (registeredIds.find(ctxSignature) != registeredIds.end()
22 3 : && registeredIds[ctxSignature].find(resPackId) != registeredIds[ctxSignature].end()) {
23 1 : execId = registeredIds[ctxSignature][resPackId];
24 1 : return true;
25 : }
26 2 : return false;
27 : }
28 :
29 2 : u64 RegisteredCcuCtxMgr::Register(
30 : std::unique_ptr<CcuCtxGroup> ccuCtxGroupPtr, const CcuCtxSignature& ctxSignature, const uintptr_t& resPackId,
31 : bool isFuncBlock)
32 : {
33 2 : CHECK_NULLPTR(ccuCtxGroupPtr, "[RegisteredCcuCtxMgr::Register] ccuCtxGroupPtr is nullptr!");
34 : // 注册
35 2 : InsExeQue::ExtInsExeEntityId execId = 0;
36 2 : InsExeQue::ExtInsExeEntity entity;
37 2 : entity.isFuncBlock = isFuncBlock; // 是否需要将ctxGroup翻译为FuncBlock
38 2 : entity.ctxGroup = std::move(*ccuCtxGroupPtr);
39 2 : HcclResult res = InsExeQue::RegisterExtendInstruction(devLogicId, entity, execId);
40 2 : if (res != HcclResult::HCCL_SUCCESS) {
41 0 : THROW<InternalException>(
42 0 : StringFormat("[RegisteredCcuCtxMgr::%s] errNo[0x%016llx] Register fail.", __func__, HCCL_ERROR_CODE(res)));
43 : }
44 :
45 : // 保存execId
46 2 : registeredIds[ctxSignature][resPackId] = static_cast<u64>(execId);
47 :
48 6 : HCCL_INFO(
49 : "[RegisteredCcuCtxMgr::%s] register ctxSignature[%s] resPackId[%u] end, execId[%llu].", __func__,
50 : ctxSignature.Describe().c_str(), resPackId, execId);
51 2 : return execId;
52 2 : }
53 :
54 265 : RegisteredCcuCtxMgr::~RegisteredCcuCtxMgr()
55 : {
56 795 : HCCL_INFO("[RegisteredCcuCtxMgr::%s] start.", __func__);
57 :
58 268 : for (auto& registeredId : registeredIds) {
59 6 : for (auto& execIdInfo : registeredId.second) {
60 3 : InsExeQue::ExtInsExeEntityId entityId = static_cast<InsExeQue::ExtInsExeEntityId>(execIdInfo.second);
61 3 : InsExeQue::DeregisterExtendInstruction(devLogicId, entityId);
62 9 : HCCL_INFO("[RegisteredCcuCtxMgr:%s]Destroy execId[%u]", __func__, entityId);
63 : }
64 : }
65 :
66 265 : registeredIds.clear();
67 795 : HCCL_INFO("[RegisteredCcuCtxMgr::%s] end.", __func__);
68 265 : }
69 :
70 : } // namespace Hccl
|