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_MESH_1D_2DIE_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_MESH_1D_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 : class CcuCtxArgAllToAllMesh1D2Die : public CcuCtxArg {
25 : public:
26 0 : explicit CcuCtxArgAllToAllMesh1D2Die(
27 : const std::vector<uint64_t>& dimSize, uint32_t rankId, const CollAlgOperator& op,
28 : const std::vector<std::vector<RankId>>& tempVTopo, bool withMyRank, const std::vector<RankId>& rankGroup,
29 : u32 bitNum)
30 0 : : dimSize_(dimSize),
31 0 : rankId_(rankId),
32 0 : op_(op),
33 0 : tempVTopo_(tempVTopo),
34 0 : withMyRank_(withMyRank),
35 0 : rankGroup(rankGroup),
36 0 : bitNum_(bitNum)
37 0 : {}
38 0 : CcuCtxSignature GetCtxSignature() const override
39 : {
40 0 : CcuCtxSignature signature;
41 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLTOALL_MESH_1D_2DIE, op_, tempVTopo_);
42 0 : return signature;
43 0 : }
44 : std::vector<uint64_t> dimSize_;
45 : uint32_t rankId_;
46 : CollAlgOperator op_;
47 : std::vector<std::vector<RankId>> tempVTopo_;
48 : bool withMyRank_;
49 : std::vector<RankId> rankGroup;
50 : u32 bitNum_;
51 : };
52 :
53 : class CcuTaskArgAllToAllMesh1D2Die : public CcuTaskArg {
54 : public:
55 0 : explicit CcuTaskArgAllToAllMesh1D2Die(
56 : uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize, uint64_t token, uint64_t inputSliceStride,
57 : uint64_t outputSliceStride, uint64_t outBuffBaseOff)
58 0 : : inputAddr_(inputAddr),
59 0 : outputAddr_(outputAddr),
60 0 : sliceSize_(sliceSize),
61 0 : token_(token),
62 0 : inputSliceStride_(inputSliceStride),
63 0 : outputSliceStride_(outputSliceStride),
64 0 : outBuffBaseOff_(outBuffBaseOff)
65 0 : {}
66 :
67 : uint64_t inputAddr_;
68 : uint64_t outputAddr_;
69 : uint64_t sliceSize_;
70 : uint64_t token_;
71 : uint64_t inputSliceStride_;
72 : uint64_t outputSliceStride_;
73 : uint64_t outBuffBaseOff_;
74 : };
75 :
76 : class CcuInstructionAllToAllMesh1D2Die : public CcuInstruction {
77 : public:
78 0 : CcuInstructionAllToAllMesh1D2Die() : CcuInstruction() {}
79 :
80 0 : void Init(
81 : uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize, uint64_t token,
82 : uint64_t inputSliceStride, uint64_t outputSliceStride, uint64_t outBuffBaseOff, CollAlgOperator& op,
83 : std::vector<std::vector<RankId>>& tempVTopo, bool withMyRank, u32 bitNum)
84 : {
85 0 : u32 maxDimNum = 1;
86 0 : if (tempVTopo.size() != maxDimNum) {
87 0 : THROW<InvalidParamsException>(StringFormat(
88 : "[CcuInstructionAllToAllMesh1D2Die] tempVTopo size is not 1, size is [%zu].", tempVTopo.size()));
89 : }
90 0 : dimSize_.push_back(tempVTopo[0].size());
91 0 : rankId_ = rankId;
92 0 : inputAddr_ = inputAddr;
93 0 : outputAddr_ = outputAddr;
94 0 : sliceSize_ = sliceSize;
95 0 : token_ = token;
96 0 : inputSliceStride_ = inputSliceStride;
97 0 : outputSliceStride_ = outputSliceStride;
98 0 : outBuffBaseOff_ = outBuffBaseOff;
99 0 : op_ = op;
100 0 : tempVTopo_ = tempVTopo;
101 0 : withMyRank_ = withMyRank;
102 0 : bitNum_ = bitNum;
103 0 : return;
104 : }
105 :
106 0 : CcuInstType GetInstType() const override
107 : {
108 0 : HCCL_INFO("CcuInstructionAllToAllMesh1D2Die instype is CCU_ALLTOALL_MESH_1D_2DIE.");
109 0 : return instType_;
110 : }
111 :
112 0 : std::string Describe() const override
113 : {
114 : return StringFormat(
115 0 : "CcuInstructionAllToAllMesh1D2Die rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
116 : }
117 :
118 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
119 : {
120 0 : return std::make_unique<CcuCtxArgAllToAllMesh1D2Die>(
121 0 : dimSize_, rankId_, op_, tempVTopo_, withMyRank_, rankGroup_.GetRanks(), bitNum_);
122 : }
123 :
124 : void SetInstType(CcuInstType instType) { instType_ = instType; }
125 :
126 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
127 : {
128 0 : return std::make_unique<CcuTaskArgAllToAllMesh1D2Die>(
129 0 : inputAddr_, outputAddr_, sliceSize_, token_, inputSliceStride_, outputSliceStride_, outBuffBaseOff_);
130 : }
131 :
132 : private:
133 : CcuInstType instType_ = CcuInstType::CCU_ALLTOALL_MESH_1D_2DIE;
134 : std::vector<uint64_t> dimSize_;
135 : uint32_t rankId_{0};
136 : uint64_t inputAddr_{0};
137 : uint64_t outputAddr_{0};
138 : uint64_t sliceSize_{0};
139 : uint64_t token_{0};
140 : uint64_t inputSliceStride_{0};
141 : uint64_t outputSliceStride_{0};
142 : uint64_t outBuffBaseOff_{0};
143 : CollAlgOperator op_;
144 : std::vector<std::vector<RankId>> tempVTopo_;
145 : bool withMyRank_{false};
146 : u32 bitNum_{0};
147 : };
148 :
149 : } // namespace Hccl
150 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_ALL_TO_ALL_MESH_1D_2Die_H
|