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