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_V_MESH_1D_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_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 : // 为AllToAllVMesh1D实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAllToAllVMesh1D : public CcuCtxArg {
26 : public:
27 0 : explicit CcuCtxArgAllToAllVMesh1D(
28 : const std::vector<uint64_t>& dSize, uint32_t rId, const CollAlgOperator& op,
29 : const std::vector<std::vector<RankId>>& tempVTopo, bool loadFromMem = false)
30 0 : : dimSize(dSize),
31 0 : rankId(rId),
32 0 : op(op),
33 0 : tempVTopo(tempVTopo),
34 0 : loadFromMem(loadFromMem)
35 0 : {}
36 0 : CcuCtxSignature GetCtxSignature() const override
37 : {
38 0 : CcuCtxSignature signature;
39 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLTOALLV_MESH_1D_DIRECT, op, tempVTopo);
40 0 : HCCL_INFO("[CcuCtxArgAllToAllVMesh1D] loadFromMem is [%d]", loadFromMem);
41 0 : return signature;
42 0 : }
43 : std::vector<uint64_t> dimSize;
44 : uint32_t rankId;
45 : CollAlgOperator op;
46 : std::vector<std::vector<RankId>> tempVTopo;
47 : bool loadFromMem;
48 : };
49 :
50 : class CcuTaskArgAllToAllVMesh1D : public CcuTaskArg {
51 : public:
52 0 : explicit CcuTaskArgAllToAllVMesh1D(
53 : uint64_t inputAddr, uint64_t outputAddr, std::vector<uint64_t> sliceSize, uint64_t token, uint64_t srcOffset,
54 : uint64_t dstOffset, const A2ASendRecvInfo& localSendRecvInfo)
55 0 : : inputAddr_(inputAddr),
56 0 : outputAddr_(outputAddr),
57 0 : sliceSize_(sliceSize),
58 0 : token_(token),
59 0 : srcOffset_(srcOffset),
60 0 : dstOffset_(dstOffset),
61 0 : localSendRecvInfo_(localSendRecvInfo)
62 0 : {}
63 :
64 : uint64_t inputAddr_;
65 : uint64_t outputAddr_;
66 : std::vector<uint64_t> sliceSize_;
67 : uint64_t token_;
68 : uint64_t srcOffset_;
69 : uint64_t dstOffset_;
70 : A2ASendRecvInfo localSendRecvInfo_;
71 : };
72 :
73 : class CcuInstructionAllToAllVMesh1D : public CcuInstruction {
74 : public:
75 0 : CcuInstructionAllToAllVMesh1D() : CcuInstruction() {}
76 :
77 0 : void Init(
78 : uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, std::vector<uint64_t> sliceSize, uint64_t token,
79 : uint64_t srcOffset, uint64_t dstOffset, CollAlgOperator& op, std::vector<std::vector<RankId>>& tempVTopo,
80 : const A2ASendRecvInfo& localSendRecvInfo, bool loadFromMem = false)
81 : {
82 0 : u32 maxDimNum = 1;
83 0 : if (tempVTopo.size() != maxDimNum) {
84 0 : THROW<InvalidParamsException>(StringFormat(
85 : "[CcuInstructionAllToAllVMesh1D] tempVTopo size is not 1, size is [%zu].", tempVTopo.size()));
86 : }
87 0 : dimSize_.push_back(tempVTopo[0].size());
88 0 : rankId_ = rankId;
89 0 : inputAddr_ = inputAddr;
90 0 : outputAddr_ = outputAddr;
91 0 : sliceSize_ = sliceSize;
92 0 : token_ = token;
93 0 : srcOffset_ = srcOffset;
94 0 : dstOffset_ = dstOffset;
95 0 : op_ = op;
96 0 : tempVTopo_ = tempVTopo;
97 0 : localSendRecvInfo_ = localSendRecvInfo;
98 0 : loadFromMem_ = loadFromMem;
99 0 : return;
100 : }
101 :
102 0 : CcuInstType GetInstType() const override
103 : {
104 0 : HCCL_INFO("CcuInstructionAllToAllVMesh1D instype is CCU_ALLTOALLV_MESH_1D_DIRECT.");
105 0 : return instType_;
106 : }
107 :
108 0 : std::string Describe() const override
109 : {
110 : return StringFormat(
111 0 : "CcuInstructionAllToAllVMesh1D rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
112 : }
113 :
114 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
115 : {
116 0 : return std::make_unique<CcuCtxArgAllToAllVMesh1D>(dimSize_, rankId_, op_, tempVTopo_, loadFromMem_);
117 : }
118 :
119 : void SetInstType(CcuInstType instType) { instType_ = instType; }
120 :
121 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
122 : {
123 0 : return std::make_unique<CcuTaskArgAllToAllVMesh1D>(
124 0 : inputAddr_, outputAddr_, sliceSize_, token_, srcOffset_, dstOffset_, localSendRecvInfo_);
125 : }
126 :
127 : private:
128 : CcuInstType instType_ = CcuInstType::CCU_ALLTOALLV_MESH_1D_DIRECT;
129 : std::vector<uint64_t> dimSize_;
130 : uint32_t rankId_{0};
131 : uint64_t inputAddr_{0};
132 : uint64_t outputAddr_{0};
133 : std::vector<uint64_t> sliceSize_;
134 : uint64_t token_{0};
135 : uint64_t srcOffset_{0};
136 : uint64_t dstOffset_{0};
137 : CollAlgOperator op_;
138 : std::vector<std::vector<RankId>> tempVTopo_;
139 : A2ASendRecvInfo localSendRecvInfo_;
140 : bool loadFromMem_{false};
141 : };
142 :
143 : } // namespace Hccl
144 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_1D_H_
|