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