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 : #ifndef CCU_INS_PREPROCESSOR_H
12 : #define CCU_INS_PREPROCESSOR_H
13 :
14 : #include "ccu_ins.h"
15 : #include "ins_queue.h"
16 : #include "ccu_ctx_mgr.h"
17 : #include "ccu_respack_mgr.h"
18 : #include "ccu_communicator.h"
19 :
20 : namespace Hccl {
21 :
22 : class CcuInsPreprocessor {
23 : public:
24 : using InsIterator = HierarchicalQueue<Instruction, InsQueue>::UnConstIterator;
25 :
26 261 : explicit CcuInsPreprocessor(CommunicatorImpl* comm) : ccuComm(comm) {}
27 :
28 : ~CcuInsPreprocessor();
29 :
30 : void Preprocess(std::shared_ptr<InsQueue>& insQueue, bool isMc2 = false);
31 :
32 : CcuCommunicator* GetCcuComm();
33 : HcclResult
34 : RecoverCcuTransportCtx(const std::vector<LinkData>& links, vector<std::pair<LinkGroup, u32>> linkGroupPair);
35 : HcclResult RecoverCcuTransportConfirm();
36 :
37 : void PrepareCcuCtx(std::shared_ptr<InsQueue>& insQueue, bool isMc2);
38 : void RegisterCtx(bool isFuncBlock);
39 : bool IsRollback() const;
40 :
41 : private:
42 : CcuCommunicator ccuComm;
43 : vector<u32> resPackIdxs; // 用于注册需要ins对应的ResPackMgr中resPack的索引
44 : vector<CcuCtxSignature> ctxSignatures; // 用于注册需要ins对应的CcuCtxSignature
45 : vector<InsIterator> insPtrs; // 用于注册时需要setExecId提供ins迭代器
46 : unordered_map<CcuCtxSignature, unordered_map<u32, std::unique_ptr<CcuCtxGroup>>>
47 : ccuCtxGroups; // 用于注册需要ins对应的ccuCtxGroup
48 :
49 : bool needHandShake{false}; // true: 有没注册的ctx则需要握手
50 : bool resAllocSuccess{true}; // true: 本地资源申请成功(包括connection\transport\transportGrp\ctx)
51 : bool isRollback{false}; // true: 资源申请失败,尝试回退
52 :
53 : void InsPreprocess(InsIterator& insIter, u32 resPackIndex, bool isMc2);
54 : void
55 : CreateCcuCtxGroup(const CcuInstruction& ccuIns, std::unique_ptr<CcuCtxGroup>& ccuCtxGroupPtr, bool& createStatus);
56 : std::unique_ptr<CcuContext> CreateCcuCtx(const CcuInstruction& ccuInst, bool& createStatus);
57 : bool CheckCtxTransportStatus(bool resAllocSuccess);
58 : void Fallback();
59 : void Confirm();
60 : void ClearTmpResRecords();
61 : };
62 :
63 : } // namespace Hccl
64 :
65 : #endif // CCU_INS_PREPROCESSOR_H
|