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