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