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