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_REDUCE_SCATTER_MESH_DETOUR_1D_H_
12 : #define HCCLV2_CCU_INSTRUCTION_REDUCE_SCATTER_MESH_DETOUR_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 : // 为ReduceScatterMeshDetour1D实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgReduceScatterMeshDetour1D : public CcuCtxArg {
26 : public:
27 0 : explicit CcuCtxArgReduceScatterMeshDetour1D(
28 : const std::vector<uint64_t>& dSize, uint32_t rId, const CollAlgOperator& op,
29 : const std::vector<std::vector<RankId>>& tempVTopo, uint64_t singleTransportSize, uint64_t detourPathNum,
30 : uint64_t pathNumPerPeer)
31 0 : : dimSize_(dSize),
32 0 : rankId_(rId),
33 0 : op_(op),
34 0 : tempVTopo_(tempVTopo),
35 0 : singleTransportSize_(singleTransportSize),
36 0 : detourPathNum_(detourPathNum),
37 0 : pathNumPerPeer_(pathNumPerPeer)
38 0 : {}
39 0 : CcuCtxSignature GetCtxSignature() const override
40 : {
41 0 : CcuCtxSignature signature;
42 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_REDUCE_SCATTER_MESH_1D_DETOUR, op_, tempVTopo_);
43 0 : return signature;
44 0 : }
45 : std::vector<uint64_t> dimSize_;
46 : uint32_t rankId_;
47 : CollAlgOperator op_;
48 : std::vector<std::vector<RankId>> tempVTopo_;
49 : uint64_t singleTransportSize_;
50 : uint64_t detourPathNum_;
51 : uint64_t pathNumPerPeer_;
52 : };
53 :
54 : class CcuTaskArgReduceScatterMeshDetour1D : public CcuTaskArg {
55 : public:
56 0 : explicit CcuTaskArgReduceScatterMeshDetour1D(
57 : uint64_t inputAddr, uint64_t outputAddr, uint64_t offset, uint64_t token, uint64_t iterNum, uint64_t tailOffset,
58 : uint64_t tailSize, const std::vector<uint64_t>& lengths)
59 0 : : inputAddr_(inputAddr),
60 0 : outputAddr_(outputAddr),
61 0 : offset_(offset),
62 0 : token_(token),
63 0 : iterNum_(iterNum),
64 0 : tailOffset_(tailOffset),
65 0 : tailSize_(tailSize),
66 0 : lengths_(lengths)
67 0 : {}
68 :
69 : uint64_t inputAddr_;
70 : uint64_t outputAddr_;
71 : uint64_t offset_;
72 : uint64_t token_;
73 : uint64_t iterNum_;
74 : uint64_t tailOffset_;
75 : uint64_t tailSize_;
76 : std::vector<uint64_t> lengths_;
77 : };
78 :
79 : class CcuInstructionReduceScatterMeshDetour1D : public CcuInstruction {
80 : public:
81 0 : CcuInstructionReduceScatterMeshDetour1D() : CcuInstruction() {}
82 :
83 0 : void Init(
84 : uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, uint64_t offset, uint64_t token, CollAlgOperator& op,
85 : std::vector<std::vector<RankId>>& tempVTopo, uint64_t iterNum, uint64_t tailOffset, uint64_t tailSize,
86 : uint64_t singleTransportSize, uint64_t detourPathNum, uint64_t pathNumPerPeer, std::vector<uint64_t>& lengths)
87 : {
88 0 : u32 maxDimNum = 1;
89 0 : if (tempVTopo.size() != maxDimNum) {
90 0 : THROW<InvalidParamsException>(StringFormat(
91 : "[CcuInstructionReduceScatterMeshDetour1D] tempVTopo size is not 1, size is [%zu].", tempVTopo.size()));
92 : }
93 0 : dimSize_.push_back(tempVTopo[0].size());
94 0 : rankId_ = rankId;
95 0 : inputAddr_ = inputAddr;
96 0 : outputAddr_ = outputAddr;
97 0 : offset_ = offset;
98 0 : token_ = token;
99 0 : op_ = op;
100 0 : tempVTopo_ = tempVTopo;
101 0 : iterNum_ = iterNum;
102 0 : tailOffset_ = tailOffset;
103 0 : tailSize_ = tailSize;
104 0 : singleTransportSize_ = singleTransportSize;
105 0 : detourPathNum_ = detourPathNum;
106 0 : pathNumPerPeer_ = pathNumPerPeer;
107 0 : lengths_ = lengths;
108 0 : return;
109 : }
110 :
111 0 : CcuInstType GetInstType() const override
112 : {
113 0 : HCCL_INFO("CcuInstructionReduceScatterMeshDetour1D instype is CCU_REDUCE_SCATTER_MESH_1D_DETOUR.");
114 0 : return instType_;
115 : }
116 :
117 0 : std::string Describe() const override
118 : {
119 : return StringFormat(
120 0 : "CcuInstructionReduceScatterMeshDetour1D rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
121 : }
122 :
123 : void SetInstType(CcuInstType instType) { instType_ = instType; }
124 :
125 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
126 : {
127 0 : return std::make_unique<CcuCtxArgReduceScatterMeshDetour1D>(
128 0 : dimSize_, rankId_, op_, tempVTopo_, singleTransportSize_, detourPathNum_, pathNumPerPeer_);
129 : }
130 :
131 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
132 : {
133 0 : return std::make_unique<CcuTaskArgReduceScatterMeshDetour1D>(
134 0 : inputAddr_, outputAddr_, offset_, token_, iterNum_, tailOffset_, tailSize_, lengths_);
135 : }
136 :
137 : private:
138 : CcuInstType instType_ = CcuInstType::CCU_REDUCE_SCATTER_MESH_1D_DETOUR;
139 : std::vector<uint64_t> dimSize_;
140 : uint32_t rankId_{0};
141 : uint64_t inputAddr_{0};
142 : uint64_t outputAddr_{0};
143 : uint64_t offset_{0};
144 : uint64_t token_{0};
145 : uint64_t iterNum_{0};
146 : uint64_t tailOffset_{0};
147 : uint64_t tailSize_{0};
148 : uint64_t singleTransportSize_{0};
149 : uint64_t detourPathNum_{0}; // 到每个对端有几个绕路路径
150 : uint64_t pathNumPerPeer_{0};
151 : std::vector<uint64_t> lengths_;
152 :
153 : CollAlgOperator op_;
154 : std::vector<std::vector<RankId>> tempVTopo_;
155 : };
156 :
157 : } // namespace Hccl
158 : #endif // HCCLV2_CCU_INSTRUCTION_REDUCE_SCATTER_MESH_DETOUR_1D_H_
|