Line data Source code
1 : /**
2 : * Copyright (c) 2026 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_1D_2DIE_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_MESH_1D_2DIE_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 : class CcuCtxArgAllToAllMesh1D2Die : public CcuCtxArg {
25 : public:
26 0 : explicit CcuCtxArgAllToAllMesh1D2Die(const std::vector<uint64_t> &dimSize, uint32_t rankId, const CollAlgOperator &op,
27 0 : const std::vector<std::vector<RankId>> &tempVTopo, bool withMyRank, const std::vector<RankId> &rankGroup, u32 bitNum) :
28 0 : dimSize_(dimSize), rankId_(rankId), op_(op), tempVTopo_(tempVTopo), withMyRank_(withMyRank), rankGroup(rankGroup), bitNum_(bitNum) {}
29 0 : CcuCtxSignature GetCtxSignature() const override
30 : {
31 0 : CcuCtxSignature signature;
32 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLTOALL_MESH_1D_2DIE, op_, tempVTopo_);
33 0 : return signature;
34 0 : }
35 : std::vector<uint64_t> dimSize_;
36 : uint32_t rankId_;
37 : CollAlgOperator op_;
38 : std::vector<std::vector<RankId>> tempVTopo_;
39 : bool withMyRank_;
40 : std::vector<RankId> rankGroup;
41 : u32 bitNum_;
42 : };
43 :
44 : class CcuTaskArgAllToAllMesh1D2Die : public CcuTaskArg {
45 : public:
46 0 : explicit CcuTaskArgAllToAllMesh1D2Die(uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize,
47 0 : uint64_t token, uint64_t inputSliceStride, uint64_t outputSliceStride, uint64_t outBuffBaseOff) :
48 0 : inputAddr_(inputAddr), outputAddr_(outputAddr), sliceSize_(sliceSize),
49 0 : token_(token), inputSliceStride_(inputSliceStride), outputSliceStride_(outputSliceStride),
50 0 : outBuffBaseOff_(outBuffBaseOff){}
51 :
52 : uint64_t inputAddr_;
53 : uint64_t outputAddr_;
54 : uint64_t sliceSize_;
55 : uint64_t token_;
56 : uint64_t inputSliceStride_;
57 : uint64_t outputSliceStride_;
58 : uint64_t outBuffBaseOff_;
59 : };
60 :
61 : class CcuInstructionAllToAllMesh1D2Die : public CcuInstruction {
62 : public:
63 0 : CcuInstructionAllToAllMesh1D2Die() : CcuInstruction()
64 : {
65 0 : }
66 :
67 0 : void Init(uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize,
68 : uint64_t token, uint64_t inputSliceStride, uint64_t outputSliceStride,
69 : uint64_t outBuffBaseOff, CollAlgOperator &op,
70 : std::vector<std::vector<RankId>> &tempVTopo, bool withMyRank, u32 bitNum)
71 : {
72 0 : u32 maxDimNum = 1;
73 0 : if (tempVTopo.size() != maxDimNum) {
74 0 : THROW<InvalidParamsException>(StringFormat(
75 : "[CcuInstructionAllToAllMesh1D2Die] 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 : inputSliceStride_ = inputSliceStride;
84 0 : outputSliceStride_ = outputSliceStride;
85 0 : outBuffBaseOff_ = outBuffBaseOff;
86 0 : op_ = op;
87 0 : tempVTopo_ = tempVTopo;
88 0 : withMyRank_ = withMyRank;
89 0 : bitNum_ = bitNum;
90 0 : return;
91 : }
92 :
93 0 : CcuInstType GetInstType() const override
94 : {
95 0 : HCCL_INFO("CcuInstructionAllToAllMesh1D2Die instype is CCU_ALLTOALL_MESH_1D_2DIE.");
96 0 : return instType_;
97 : }
98 :
99 0 : std::string Describe() const override
100 : {
101 0 : return StringFormat("CcuInstructionAllToAllMesh1D2Die rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
102 : }
103 :
104 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
105 : {
106 0 : return std::make_unique<CcuCtxArgAllToAllMesh1D2Die>(dimSize_, rankId_, op_, tempVTopo_, withMyRank_,rankGroup_.GetRanks(), bitNum_);
107 : }
108 :
109 : void SetInstType(CcuInstType instType)
110 : {
111 : instType_ = instType;
112 : }
113 :
114 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
115 : {
116 0 : return std::make_unique<CcuTaskArgAllToAllMesh1D2Die>(inputAddr_, outputAddr_, sliceSize_, token_, inputSliceStride_, outputSliceStride_, outBuffBaseOff_);
117 : }
118 :
119 : private:
120 : CcuInstType instType_ = CcuInstType::CCU_ALLTOALL_MESH_1D_2DIE;
121 : std::vector<uint64_t> dimSize_;
122 : uint32_t rankId_{0};
123 : uint64_t inputAddr_{0};
124 : uint64_t outputAddr_{0};
125 : uint64_t sliceSize_{0};
126 : uint64_t token_{0};
127 : uint64_t inputSliceStride_{0};
128 : uint64_t outputSliceStride_{0};
129 : uint64_t outBuffBaseOff_{0};
130 : CollAlgOperator op_;
131 : std::vector<std::vector<RankId>> tempVTopo_;
132 : bool withMyRank_{false};
133 : u32 bitNum_{0};
134 : };
135 :
136 : }
137 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_ALL_TO_ALL_MESH_1D_2Die_H
|