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 HCCLV2_CCU_INSTRUCTION_ALL_GATHER_MESH_1D_MEM2MEM_WITH_STRIDE_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_GATHER_MESH_1D_MEM2MEM_WITH_STRIDE_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 : // 为AllGatherMesh1D实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAllGatherMesh1DMem2MemWithStride : public CcuCtxArg {
26 : public:
27 0 : explicit CcuCtxArgAllGatherMesh1DMem2MemWithStride(const std::vector<uint64_t> &dimSize, uint32_t rankId,
28 : const CollAlgOperator &op,
29 : const std::vector<std::vector<RankId>> &tempVTopo)
30 0 : : dimSize_(dimSize), rankId_(rankId), op_(op), tempVTopo_(tempVTopo)
31 : {
32 0 : }
33 0 : CcuCtxSignature GetCtxSignature() const override
34 : {
35 0 : CcuCtxSignature signature;
36 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLGATHER_MESH_1D_MEM2MEM_WITH_STRIDE_DIRECT, op_,
37 0 : tempVTopo_);
38 0 : return signature;
39 0 : }
40 : std::vector<uint64_t> dimSize_;
41 : uint32_t rankId_;
42 : CollAlgOperator op_;
43 : std::vector<std::vector<RankId>> tempVTopo_;
44 : };
45 :
46 : class CcuTaskArgAllGatherMesh1DMem2MemWithStride : public CcuTaskArg {
47 : public:
48 0 : explicit CcuTaskArgAllGatherMesh1DMem2MemWithStride(uint64_t inputAddr, uint64_t outputAddr, uint64_t token,
49 : uint64_t inputSliceStride, uint64_t outputSliceStride,
50 : uint64_t repeatNum, uint64_t inputRepeatStride,
51 : uint64_t outputRepeatStride, uint64_t normalSliceSize,
52 : uint64_t lastSliceSize, uint64_t isInputOutputEqual)
53 0 : : inputAddr_(inputAddr), outputAddr_(outputAddr), token_(token), inputSliceStride_(inputSliceStride),
54 0 : outputSliceStride_(outputSliceStride), repeatNum_(repeatNum), inputRepeatStride_(inputRepeatStride),
55 0 : outputRepeatStride_(outputRepeatStride), normalSliceSize_(normalSliceSize), lastSliceSize_(lastSliceSize),
56 0 : isInputOutputEqual_(isInputOutputEqual)
57 : {
58 0 : }
59 :
60 : uint64_t inputAddr_;
61 : uint64_t outputAddr_;
62 : uint64_t token_;
63 :
64 : uint64_t inputSliceStride_;
65 : uint64_t outputSliceStride_;
66 : uint64_t repeatNum_;
67 : uint64_t inputRepeatStride_;
68 : uint64_t outputRepeatStride_;
69 :
70 : uint64_t normalSliceSize_;
71 : uint64_t lastSliceSize_;
72 : uint64_t isInputOutputEqual_;
73 : };
74 :
75 : class CcuInstructionAllGatherMesh1DMem2MemWithStride : public CcuInstruction {
76 : public:
77 0 : CcuInstructionAllGatherMesh1DMem2MemWithStride() : CcuInstruction()
78 : {
79 0 : }
80 :
81 0 : void Init(uint32_t rankId, uint32_t repeatNum, const CollAlgOperator &op,
82 : const std::vector<std::vector<RankId>> &tempVTopo, uint64_t inputAddr, uint64_t outputAddr,
83 : uint64_t token, uint64_t inputSliceStride, uint64_t outputSliceStride, uint64_t inputRepeatStride,
84 : uint64_t outputRepeatStride, uint64_t normalSliceSize, uint64_t lastSliceSize,
85 : uint64_t isInputOutputEqual)
86 : {
87 0 : u32 maxDimNum = 1;
88 0 : if (tempVTopo.size() != maxDimNum) {
89 0 : THROW<InvalidParamsException>(StringFormat(
90 : "[CcuInstructionAllGatherMesh1D] tempVTopo size is not 1, size is [%zu].", tempVTopo.size()));
91 : }
92 0 : dimSize_.push_back(tempVTopo[0].size());
93 0 : rankId_ = rankId;
94 0 : repeatNum_ = repeatNum;
95 0 : op_ = op;
96 0 : tempVTopo_ = tempVTopo;
97 0 : inputAddr_ = inputAddr;
98 0 : outputAddr_ = outputAddr;
99 0 : token_ = token;
100 0 : inputSliceStride_ = inputSliceStride;
101 0 : outputSliceStride_ = outputSliceStride;
102 0 : inputRepeatStride_ = inputRepeatStride;
103 0 : outputRepeatStride_ = outputRepeatStride;
104 0 : normalSliceSize_ = normalSliceSize;
105 0 : lastSliceSize_ = lastSliceSize;
106 0 : isInputOutputEqual_ = isInputOutputEqual;
107 0 : return;
108 : }
109 :
110 0 : CcuInstType GetInstType() const override
111 : {
112 0 : HCCL_INFO("CcuInstructionAllGatherMesh1D instype is CCU_ALLGATHER_MESH_1D_MEM2MEM_WITH_STRIDE_DIRECT.");
113 0 : return instType_;
114 : }
115 :
116 0 : std::string Describe() const override
117 : {
118 0 : return StringFormat("CcuInstructionAllGatherMesh1D rankId [%u], instType[%s]", rankId_,
119 0 : instType_.Describe().c_str());
120 : }
121 :
122 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
123 : {
124 0 : return std::make_unique<CcuCtxArgAllGatherMesh1DMem2MemWithStride>(dimSize_, rankId_, op_, tempVTopo_);
125 : }
126 :
127 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
128 : {
129 0 : return std::make_unique<CcuTaskArgAllGatherMesh1DMem2MemWithStride>(
130 0 : inputAddr_, outputAddr_, token_, inputSliceStride_, outputSliceStride_, repeatNum_, inputRepeatStride_,
131 0 : outputRepeatStride_, normalSliceSize_, lastSliceSize_, isInputOutputEqual_);
132 : }
133 :
134 : void SetInstType(CcuInstType instType)
135 : {
136 : instType_ = instType;
137 : }
138 : private:
139 : CcuInstType instType_ = CcuInstType::CCU_ALLGATHER_MESH_1D_MEM2MEM_WITH_STRIDE_DIRECT;
140 : std::vector<uint64_t> dimSize_;
141 : uint32_t rankId_{0};
142 : uint32_t repeatNum_{0};
143 : CollAlgOperator op_;
144 : std::vector<std::vector<RankId>> tempVTopo_;
145 : uint64_t inputAddr_{0};
146 : uint64_t outputAddr_{0};
147 : uint64_t token_{0};
148 : uint64_t inputSliceStride_{0};
149 : uint64_t outputSliceStride_{0};
150 : uint64_t inputRepeatStride_{0};
151 : uint64_t outputRepeatStride_{0};
152 : uint64_t normalSliceSize_{0};
153 : uint64_t lastSliceSize_{0};
154 : uint64_t isInputOutputEqual_{0};
155 : };
156 :
157 : } // namespace Hccl
158 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_GATHER_MESH_1D_MEM2MEM_WITH_STRIDE_H_
|