Line data Source code
1 : /**
2 : * Copyright (c) 2026 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 HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_2DIE_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_2DIE_H_
13 :
14 : #include "template_utils.h"
15 : #include "instruction.h"
16 : #include "ins_queue.h"
17 : #include "ccu_context_utils.h"
18 : #include "ccu_ctx_signature.h"
19 : #include "ccu_ins.h"
20 : #include "ccu_rank_group.h"
21 :
22 : namespace Hccl {
23 :
24 : // 为AllToAllVMesh2Die实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAllToAllVMesh2Die : public CcuCtxArg {
26 : public:
27 0 : CcuCtxArgAllToAllVMesh2Die(
28 : const std::vector<uint32_t>& dSize, uint32_t rId, bool withMyRank, const CollAlgOperator& op,
29 : const std::vector<std::vector<RankId>>& tempVTopo, const std::vector<RankId>& rankGroup)
30 0 : : CcuCtxArg(),
31 0 : dimSize(dSize),
32 0 : rankId(rId),
33 0 : withMyRank(withMyRank),
34 0 : op(op),
35 0 : tempVTopo(tempVTopo),
36 0 : rankGroup(rankGroup)
37 0 : {}
38 :
39 0 : ~CcuCtxArgAllToAllVMesh2Die() override {}
40 :
41 0 : CcuCtxSignature GetCtxSignature() const override
42 : {
43 0 : CcuCtxSignature signature;
44 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLTOALLV_MESH_2DIE_DIRECT, op, tempVTopo);
45 0 : return signature;
46 0 : }
47 :
48 : std::vector<uint32_t> dimSize;
49 : uint32_t rankId;
50 : bool withMyRank;
51 : CollAlgOperator op;
52 : std::vector<std::vector<RankId>> tempVTopo;
53 : std::vector<RankId> rankGroup;
54 : };
55 :
56 : class CcuTaskArgAllToAllVMesh2Die : public CcuTaskArg {
57 : public:
58 0 : explicit CcuTaskArgAllToAllVMesh2Die(
59 : uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr, uint64_t token,
60 : const A2ASendRecvInfo& localSendRecvInfo)
61 0 : : inputAddr(inputAddr),
62 0 : outputAddr(outputAddr),
63 0 : scratchAddr(scratchAddr),
64 0 : token(token),
65 0 : localSendRecvInfo(localSendRecvInfo)
66 0 : {}
67 :
68 : uint64_t inputAddr;
69 : uint64_t outputAddr;
70 : uint64_t scratchAddr;
71 : uint64_t token;
72 : A2ASendRecvInfo localSendRecvInfo;
73 : };
74 :
75 : class CcuInstructionAllToAllVMesh2Die : public CcuInstruction {
76 : public:
77 0 : CcuInstructionAllToAllVMesh2Die(
78 : const CollAlgOperator& op, const std::vector<uint32_t>& dimSize,
79 : const std::vector<std::vector<RankId>>& tempVTopo)
80 0 : : CcuInstruction(),
81 0 : op_(op),
82 0 : dimSize_(dimSize),
83 0 : tempVTopo_(tempVTopo)
84 0 : {}
85 :
86 0 : void Init(
87 : uint32_t rankId, bool withMyRank, uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr, uint64_t token,
88 : const A2ASendRecvInfo& localSendRecvInfo)
89 : {
90 0 : rankId_ = rankId;
91 0 : withMyRank_ = withMyRank;
92 0 : inputAddr_ = inputAddr;
93 0 : outputAddr_ = outputAddr;
94 0 : scratchAddr_ = scratchAddr;
95 0 : token_ = token;
96 0 : localSendRecvInfo_ = localSendRecvInfo;
97 0 : return;
98 : }
99 :
100 0 : CcuInstType GetInstType() const override
101 : {
102 0 : HCCL_INFO("CcuInstructionAllToAllVMesh2Die instype is CCU_ALLTOALLV_MESH_2DIE_DIRECT.");
103 0 : return instType_;
104 : }
105 :
106 0 : std::string Describe() const override
107 : {
108 : return StringFormat(
109 0 : "CcuInstructionAllToAllVMesh2Die rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
110 : }
111 :
112 : void SetInstType(CcuInstType instType) { instType_ = instType; }
113 :
114 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
115 : {
116 0 : HCCL_INFO(
117 : "[CcuInstructionAllToAllVMesh2Die][GetCtxArg] dimSize.size[%u], rankId[%u], withMyRank[%u], "
118 : "tempVTopo.size[%u]",
119 : dimSize_.size(), rankId_, withMyRank_, tempVTopo_.size());
120 0 : return std::make_unique<CcuCtxArgAllToAllVMesh2Die>(
121 0 : dimSize_, rankId_, withMyRank_, op_, tempVTopo_, rankGroup_.GetRanks());
122 : }
123 :
124 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
125 : {
126 : // 2个Die依赖的TaskArg要一样,因为当前ccu_ins_group只会用第一个Instruction获取TaskArg
127 0 : return std::make_unique<CcuTaskArgAllToAllVMesh2Die>(
128 0 : inputAddr_, outputAddr_, scratchAddr_, token_, localSendRecvInfo_);
129 : }
130 :
131 : private:
132 : CollAlgOperator op_;
133 : std::vector<uint32_t> dimSize_;
134 : std::vector<std::vector<RankId>> tempVTopo_;
135 :
136 : CcuInstType instType_ = CcuInstType::CCU_ALLTOALLV_MESH_2DIE_DIRECT;
137 : uint32_t rankId_{0};
138 : bool withMyRank_{false};
139 : uint64_t inputAddr_{0};
140 : uint64_t outputAddr_{0};
141 : uint64_t scratchAddr_{0};
142 : uint64_t token_{0};
143 : A2ASendRecvInfo localSendRecvInfo_;
144 : };
145 :
146 : } // namespace Hccl
147 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_2DIE_H_
|