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_TO_ALL_MESH_2D_H
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_MESH_2D_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 : // 为AllGatherMesh1D实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAlltoAllMesh2D : public CcuCtxArg {
26 : public:
27 3 : CcuCtxArgAlltoAllMesh2D(const std::vector<uint32_t> &dSize, uint32_t rId, uint32_t aId,
28 3 : const CollAlgOperator &op, const std::vector<std::vector<RankId>> &tempVTopo) :
29 3 : CcuCtxArg(), dimSize(dSize), rankId(rId), axisId(aId), op(op), tempVTopo(tempVTopo) {}
30 :
31 3 : ~CcuCtxArgAlltoAllMesh2D() override {}
32 :
33 7 : CcuCtxSignature GetCtxSignature() const override
34 : {
35 7 : CcuCtxSignature signature;
36 7 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLTOALL_MESH_2D_DIRECT, op, tempVTopo);
37 21 : HCCL_INFO("[CcuCtxArgAlltoAllMesh2D][GetCtxSignature] signature[%s]", signature.GetData().c_str());
38 7 : return signature;
39 0 : }
40 :
41 : // 需要存储,传递给算法
42 : std::vector<uint32_t> dimSize;
43 : uint32_t rankId;
44 : uint32_t axisId;
45 :
46 : const CollAlgOperator &op;
47 : const std::vector<std::vector<RankId>> &tempVTopo;
48 : };
49 :
50 : class CcuTaskArgAlltoAllMesh2D : public CcuTaskArg {
51 : public:
52 24 : explicit CcuTaskArgAlltoAllMesh2D(uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr,
53 : uint64_t sendStride, uint64_t recvStride, uint64_t sendLength, uint64_t aSize, uint64_t bSize,
54 24 : uint64_t baseOffset, uint64_t token) :
55 24 : CcuTaskArg(), inputAddr(inputAddr), outputAddr(outputAddr), scratchAddr(scratchAddr),
56 24 : sendStride(sendStride), recvStride(recvStride), sendLength(sendLength), aSize(aSize), bSize(bSize),
57 24 : baseOffset(baseOffset), token(token) {}
58 :
59 : uint64_t inputAddr;
60 : uint64_t outputAddr;
61 : uint64_t scratchAddr;
62 : uint64_t sendStride;
63 : uint64_t recvStride;
64 : uint64_t sendLength;
65 : uint64_t aSize; // X方向第一轮传输的数据量
66 : uint64_t bSize;
67 : uint64_t baseOffset; // 多轮执行时的基础偏移,等于step*(aSize+bSize)
68 : uint64_t token;
69 : };
70 :
71 : class CcuInstructionAlltoAllMesh2D : public CcuInstruction {
72 : public:
73 4 : CcuInstructionAlltoAllMesh2D(const CollAlgOperator &op, const std::vector<uint32_t> &dimSize,
74 4 : const std::vector<std::vector<RankId>> &tempVTopo) :
75 4 : CcuInstruction(), op_(op), dimSize_(dimSize), tempVTopo_(tempVTopo) {}
76 :
77 4 : void Init(uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr, uint64_t axisId,
78 : uint64_t sendStride, uint64_t recvStride, uint64_t sendLength, uint64_t aSize, uint64_t bSize,
79 : uint64_t baseOffset, uint64_t token)
80 : {
81 4 : rankId_ = rankId;
82 4 : inputAddr_ = inputAddr;
83 4 : outputAddr_ = outputAddr;
84 4 : scratchAddr_ = scratchAddr;
85 4 : axisId_ = axisId;
86 4 : sendStride_ = sendStride;
87 4 : recvStride_ = recvStride;
88 4 : sendLength_ = sendLength;
89 4 : aSize_ = aSize;
90 4 : bSize_ = bSize;
91 4 : baseOffset_ = baseOffset;
92 4 : token_ = token;
93 12 : HCCL_INFO("[CcuInstructionAlltoAllMesh2D][Init] rankId[%u] inputAddr[%llu] outputAddr[%llu] scratchAddr[%llu],\
94 : axisId[%u], sendStride[%llu], recvStride[%llu], sendLength[%llu], aSize[%llu], bSize[%llu], baseOffset[%llu], \
95 : dimSize.size[%u], tempVTopo.size[%u]", rankId_, inputAddr_, outputAddr_, scratchAddr_, axisId_,
96 : sendStride_, recvStride_, sendLength_, aSize_, bSize_, baseOffset_, dimSize_.size(),
97 : tempVTopo_.size());
98 4 : return;
99 : }
100 :
101 0 : CcuInstType GetInstType() const override
102 : {
103 0 : HCCL_INFO("CcuInstructionAllGatherMesh1D instype is CCU_ALLTOALL_MESH_2D_DIRECT.");
104 0 : return instType_;
105 : }
106 :
107 0 : std::string Describe() const override
108 : {
109 0 : return StringFormat("[CcuInstructionAllGatherMesh1D]RankId[%u] Ins[%s]", rankId_, instType_.Describe().c_str());
110 : }
111 :
112 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
113 : {
114 0 : HCCL_INFO("[CcuInstructionAlltoAllMesh2D][GetCtxArg] dimSize.size[%u], rankId[%u], axisId[%u], tempVTopo.size[%u]",
115 : dimSize_.size(), rankId_, axisId_, tempVTopo_.size());
116 0 : return std::make_unique<CcuCtxArgAlltoAllMesh2D>(dimSize_, rankId_, axisId_, op_, tempVTopo_);
117 : }
118 :
119 : void SetInstType(CcuInstType instType)
120 : {
121 : instType_ = instType;
122 : }
123 :
124 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
125 : {
126 0 : return std::make_unique<CcuTaskArgAlltoAllMesh2D>(inputAddr_, outputAddr_, scratchAddr_, sendStride_,
127 0 : recvStride_, sendLength_, aSize_, bSize_, baseOffset_, token_);
128 : }
129 :
130 : private:
131 : CollAlgOperator op_;
132 : std::vector<uint32_t> dimSize_;
133 : std::vector<std::vector<RankId>> tempVTopo_;
134 :
135 : CcuInstType instType_ = CcuInstType::CCU_ALLTOALL_MESH_2D_DIRECT;
136 :
137 : uint32_t rankId_{0};
138 : uint64_t inputAddr_{0};
139 : uint64_t outputAddr_{0};
140 : uint64_t scratchAddr_{0};
141 : uint64_t sendStride_{0};
142 : uint64_t recvStride_{0};
143 : uint64_t axisId_{0};
144 : uint64_t sendLength_{0}; // 多轮时的单个数据块总大小
145 : uint64_t aSize_{0};
146 : uint64_t bSize_{0};
147 : uint64_t baseOffset_{0};
148 : uint64_t token_{0};
149 : };
150 :
151 : }
152 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_MESH_2D_H
|