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(std::unique_ptr<CcuCtxGroup> ccuCtxGroupPtr, const CcuCtxSignature &ctxSignature,
30 : const uintptr_t &resPackId, bool isFuncBlock)
31 : {
32 2 : CHECK_NULLPTR(ccuCtxGroupPtr, "[RegisteredCcuCtxMgr::Register] ccuCtxGroupPtr is nullptr!");
33 : // 注册
34 2 : InsExeQue::ExtInsExeEntityId execId = 0;
35 2 : InsExeQue::ExtInsExeEntity entity;
36 2 : entity.isFuncBlock = isFuncBlock; // 是否需要将ctxGroup翻译为FuncBlock
37 2 : entity.ctxGroup = std::move(*ccuCtxGroupPtr);
38 2 : HcclResult res = InsExeQue::RegisterExtendInstruction(devLogicId, entity, execId);
39 2 : if (res != HcclResult::HCCL_SUCCESS) {
40 0 : THROW<InternalException>(
41 0 : StringFormat("[RegisteredCcuCtxMgr::%s] errNo[0x%016llx] Register fail.", __func__, HCCL_ERROR_CODE(res)));
42 : }
43 :
44 : // 保存execId
45 2 : registeredIds[ctxSignature][resPackId] = static_cast<u64>(execId);
46 :
47 6 : HCCL_INFO("[RegisteredCcuCtxMgr::%s] register ctxSignature[%s] resPackId[%u] end, execId[%llu].",
48 : __func__, ctxSignature.Describe().c_str(), resPackId, execId);
49 2 : return execId;
50 2 : }
51 :
52 265 : RegisteredCcuCtxMgr::~RegisteredCcuCtxMgr()
53 : {
54 795 : HCCL_INFO("[RegisteredCcuCtxMgr::%s] start.", __func__);
55 :
56 268 : for (auto ®isteredId : registeredIds) {
57 6 : for (auto &execIdInfo : registeredId.second) {
58 3 : InsExeQue::ExtInsExeEntityId entityId = static_cast<InsExeQue::ExtInsExeEntityId>(execIdInfo.second);
59 3 : InsExeQue::DeregisterExtendInstruction(devLogicId, entityId);
60 9 : HCCL_INFO("[RegisteredCcuCtxMgr:%s]Destroy execId[%u]", __func__, entityId);
61 : }
62 : }
63 :
64 265 : registeredIds.clear();
65 795 : HCCL_INFO("[RegisteredCcuCtxMgr::%s] end.", __func__);
66 265 : }
67 :
68 : } // namespace Hccl
|