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 MC2_COMPONT_H
12 : #define MC2_COMPONT_H
13 :
14 : #include <memory>
15 : #include "communicator_impl.h"
16 : #include "ins_exe_que.h"
17 : #include "mc2_type.h"
18 : #include "task_param.h"
19 :
20 : namespace Hccl {
21 :
22 : struct HcclAlgoInfo {
23 : uint32_t opType;
24 : uint8_t algorithmType;
25 : };
26 :
27 : class Mc2Compont {
28 : public:
29 256 : explicit Mc2Compont(CommunicatorImpl* comm) : comm(comm) {}
30 : ~Mc2Compont();
31 : Mc2Compont(const Mc2Compont& that) = delete;
32 : Mc2Compont& operator=(const Mc2Compont& that) = delete;
33 : Mc2Compont(Mc2Compont&& that) = delete;
34 : Mc2Compont& operator=(Mc2Compont&& that) = delete;
35 :
36 : void AllocCommResource(void* mc2Tiling, void** commContext);
37 : std::vector<CcuTaskParam> GetCcuTaskInfo(void* tilingData);
38 : std::vector<CcuTaskParam> GetAlgoCcuTaskInfo(InsExeQue::ExtInsExeEntityId execId) const;
39 : u32 GetCcuMc2ServerNum();
40 :
41 : private:
42 : void Alloc();
43 : void AllocV2();
44 : void GenerateCcuServer(const std::unordered_set<uint64_t>& algoTemplateRequire);
45 : bool
46 : FindCcuServer(const std::unordered_set<uint64_t>& algoTemplateRequire, InsExeQue::ExtInsExeEntityId& execId) const;
47 : void GenerateAlgoTemplates(Mc2Tiling* mc2TilingPtr, std::unordered_set<uint64_t>& algoTemplateRequire);
48 : void
49 : GenerateAlgoTemplatesV2(const Mc2InitTilingInner* mc2TilingPtr, std::unordered_set<uint64_t>& algoTemplateRequire);
50 : void FillCollOperator(const Mc2CommConfig& config);
51 : void FillCollOperatorV2(const Mc2CcTilingInner& config);
52 : uint64_t GetTemplateSignature(const Mc2CommConfig& config) const;
53 : uint64_t GetTemplateSignatureV2(const Mc2CcTilingInner& config) const;
54 : void SaveMc2DfxTaskInfo(const CcuTaskParam& ccuTaskParam, uint64_t execId) const;
55 : bool CompareMissionMap(
56 : const std::map<uint8_t, std::map<uint32_t, uint32_t>>& mapA,
57 : const std::map<uint8_t, std::map<uint32_t, uint32_t>>& mapB) const;
58 : void MC2Orchestrate(const CollAlgParams& params, std::shared_ptr<InsQueue>& insQueue, uint8_t commEngine) const;
59 : void MC2AllocCommRes(const CollAlgParams& params, std::shared_ptr<InsQueue>& insQueue, uint8_t commEngine) const;
60 : void SaveAlgoInfo(uint32_t index, uint64_t templateSign, uint32_t opType, uint8_t algorithmType);
61 :
62 : private:
63 : const uint32_t dataCount = 1024;
64 : CommunicatorImpl* comm;
65 : // algoTemplateMap已经生成的算子集合; key:签名, value: taskParam
66 : std::unordered_map<uint64_t, std::vector<std::vector<CcuTaskParam>>> algoTemplateMap;
67 : std::unordered_map<uint64_t, HcclAlgoInfo> algoInfoMap_;
68 : // ccuServer已经生成的server集合; key:execId, value:该server支持的算子签名
69 : std::unordered_map<InsExeQue::ExtInsExeEntityId, std::unordered_set<uint64_t>> ccuServerMap;
70 :
71 : std::shared_ptr<DevBuffer> workspaceBuffer{nullptr};
72 : std::shared_ptr<DevBuffer> combinOpParamBuffer{nullptr};
73 : std::shared_ptr<DevBuffer> comParamBuffer{nullptr};
74 : std::shared_ptr<DevBuffer> comSyncBuffer{nullptr};
75 : CcuResPack ccuResPack;
76 : InsExeQue::ExtInsExeEntityId curExecId{0};
77 : uint64_t tokenInfo{0};
78 : std::shared_ptr<DevBuffer> inputMem{nullptr};
79 :
80 : std::vector<u64> dataCounts;
81 : std::vector<u64> displs;
82 :
83 : HcclCombinOpParam combinOpParam{};
84 : bool ccuResourceAlloced{false}; // 标记通信域粒度资源已经申请过了
85 : };
86 : } // namespace Hccl
87 : #endif // MC2_COMPONT_H
|