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_REDUCE_MESH_2D_ONE_SHOT_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_REDUCE_MESH_2D_ONE_SHOT_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 : // 为AllReduceMesh2DOneShot实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAllReduceMesh2DOneShot : public CcuCtxArg {
26 : public:
27 0 : explicit CcuCtxArgAllReduceMesh2DOneShot(
28 : const std::vector<uint64_t>& dSize, uint32_t rId, uint32_t axisId, const CollAlgOperator& op,
29 : const std::vector<std::vector<RankId>>& tempVTopo)
30 0 : : dimSize_(dSize),
31 0 : rankId_(rId),
32 0 : axisId_(axisId),
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_ALL_REDUCE_MESH_2D_ONE_SHOT_DIRECT, op_, tempVTopo_);
40 0 : return signature;
41 0 : }
42 :
43 : std::vector<uint64_t> dimSize_;
44 : uint32_t rankId_;
45 : uint32_t axisId_;
46 : CollAlgOperator op_;
47 : std::vector<std::vector<RankId>> tempVTopo_;
48 : };
49 :
50 : class CcuTaskArgAllReduceMesh2DOneShot : public CcuTaskArg {
51 : public:
52 0 : explicit CcuTaskArgAllReduceMesh2DOneShot(
53 : uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr, uint64_t xSliceSize, uint64_t ySliceSize,
54 : uint64_t xSliceOffset, uint64_t ySliceOffset, uint64_t token)
55 0 : : inputAddr_(inputAddr),
56 0 : outputAddr_(outputAddr),
57 0 : scratchAddr_(scratchAddr),
58 0 : xSliceSize_(xSliceSize),
59 0 : ySliceSize_(ySliceSize),
60 0 : xSliceOffset_(xSliceOffset),
61 0 : ySliceOffset_(ySliceOffset),
62 0 : token_(token)
63 0 : {}
64 : uint64_t inputAddr_;
65 : uint64_t outputAddr_;
66 : uint64_t scratchAddr_;
67 : uint64_t xSliceSize_;
68 : uint64_t ySliceSize_;
69 : uint64_t xSliceOffset_;
70 : uint64_t ySliceOffset_;
71 : uint64_t token_;
72 : };
73 :
74 : class CcuInstructionAllReduceMesh2DOneShot : public CcuInstruction {
75 : public:
76 0 : CcuInstructionAllReduceMesh2DOneShot() : CcuInstruction() {}
77 :
78 0 : void Init(
79 : std::vector<uint64_t>& dimSize, uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr,
80 : uint32_t axisId, uint64_t xSliceSize, uint64_t ySliceSize, uint64_t xSliceOffset, uint64_t ySliceOffset,
81 : uint64_t token, CollAlgOperator& op, std::vector<std::vector<RankId>>& tempVTopo)
82 : {
83 0 : dimSize_ = dimSize;
84 0 : rankId_ = rankId;
85 0 : inputAddr_ = inputAddr;
86 0 : outputAddr_ = outputAddr;
87 0 : scratchAddr_ = scratchAddr;
88 :
89 0 : axisId_ = axisId;
90 :
91 0 : xSliceSize_ = xSliceSize;
92 0 : ySliceSize_ = ySliceSize;
93 :
94 0 : xSliceOffset_ = xSliceOffset;
95 0 : ySliceOffset_ = ySliceOffset;
96 :
97 0 : token_ = token;
98 0 : op_ = op;
99 0 : tempVTopo_ = tempVTopo;
100 0 : return;
101 : }
102 :
103 0 : CcuInstType GetInstType() const override
104 : {
105 0 : HCCL_INFO("CcuInstructionAllReduceMesh2DOneShot instype is CCU_ALL_REDUCE_MESH_2D_ONE_SHOT_DIRECT.");
106 0 : return instType_;
107 : }
108 :
109 0 : std::string Describe() const override
110 : {
111 : return StringFormat(
112 0 : "CcuInstructionAllReduceMesh2DOneShot rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
113 : }
114 :
115 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
116 : {
117 0 : return std::make_unique<CcuCtxArgAllReduceMesh2DOneShot>(dimSize_, rankId_, axisId_, op_, tempVTopo_);
118 : }
119 :
120 : void SetInstType(CcuInstType instType) { instType_ = instType; }
121 :
122 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
123 : {
124 0 : return std::make_unique<CcuTaskArgAllReduceMesh2DOneShot>(
125 0 : inputAddr_, outputAddr_, scratchAddr_, xSliceSize_, ySliceSize_, xSliceOffset_, ySliceOffset_, token_);
126 : }
127 :
128 : private:
129 : CcuInstType instType_ = CcuInstType::CCU_ALL_REDUCE_MESH_2D_ONE_SHOT_DIRECT;
130 : std::vector<uint64_t> dimSize_;
131 : uint32_t rankId_{0};
132 :
133 : uint64_t inputAddr_{0};
134 : uint64_t outputAddr_{0};
135 : uint64_t scratchAddr_{0};
136 :
137 : uint32_t axisId_{0};
138 :
139 : uint64_t xSliceSize_{0};
140 : uint64_t ySliceSize_{0};
141 : uint64_t xSliceOffset_{0};
142 : uint64_t ySliceOffset_{0};
143 :
144 : uint64_t token_{0};
145 : CollAlgOperator op_;
146 : std::vector<std::vector<RankId>> tempVTopo_;
147 : };
148 :
149 : } // namespace Hccl
150 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_REDUCE_MESH_2D_ONE_SHOT_H_
|