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_GATHER_MESH_1D_2DIE_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_GATHER_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 : // 为AllGatherMesh1D实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAllGatherMesh1D2Die : public CcuCtxArg {
26 : public:
27 0 : explicit CcuCtxArgAllGatherMesh1D2Die(const std::vector<uint64_t> &dSize, uint32_t rId, bool withMyRank, const CollAlgOperator &op,
28 0 : const std::vector<std::vector<RankId>> &tempVTopo) :
29 0 : dimSize_(dSize), rankId_(rId), withMyRank_(withMyRank), op_(op), tempVTopo_(tempVTopo) {}
30 0 : CcuCtxSignature GetCtxSignature() const override
31 : {
32 0 : CcuCtxSignature signature;
33 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLGATHER_MESH_1D_2DIE, op_, tempVTopo_);
34 0 : return signature;
35 0 : }
36 : std::vector<uint64_t> dimSize_;
37 : uint32_t rankId_;
38 : bool withMyRank_;
39 : CollAlgOperator op_;
40 : std::vector<std::vector<RankId>> tempVTopo_;
41 : };
42 :
43 : class CcuTaskArgAllGatherMesh1D2Die : public CcuTaskArg {
44 : public:
45 0 : explicit CcuTaskArgAllGatherMesh1D2Die(uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize, uint64_t outputSliceStride,
46 0 : uint64_t token) :
47 0 : inputAddr_(inputAddr), outputAddr_(outputAddr), sliceSize_(sliceSize), outputSliceStride_(outputSliceStride), token_(token) {}
48 :
49 : uint64_t inputAddr_;
50 : uint64_t outputAddr_;
51 : uint64_t sliceSize_;
52 : uint64_t outputSliceStride_;
53 : uint64_t token_;
54 : };
55 :
56 : class CcuInstructionAllGatherMesh1D2Die : public CcuInstruction {
57 : public:
58 0 : CcuInstructionAllGatherMesh1D2Die() : CcuInstruction()
59 : {
60 0 : }
61 :
62 0 : void Init(uint32_t rankId, uint64_t inputAddr, uint64_t outputAddr, uint64_t sliceSize, uint64_t outputSliceStride,
63 : uint64_t token, uint64_t withMyRank, CollAlgOperator &op, std::vector<std::vector<RankId>> &tempVTopo)
64 : {
65 0 : u32 maxDimNum = 1;
66 0 : if (tempVTopo.size() != maxDimNum) {
67 0 : THROW<InvalidParamsException>(StringFormat(
68 : "[CcuInstructionAllGatherMesh1D2Die] tempVTopo size is not 1, size is [%zu].", tempVTopo.size()));
69 : }
70 0 : dimSize_.push_back(tempVTopo[0].size());
71 0 : rankId_ = rankId;
72 0 : inputAddr_ = inputAddr;
73 0 : outputAddr_ = outputAddr;
74 0 : token_ = token;
75 0 : outputSliceStride_ = outputSliceStride;
76 0 : withMyRank_ = withMyRank;
77 0 : op_ = op;
78 0 : tempVTopo_ = tempVTopo;
79 0 : sliceSize_ = sliceSize;
80 0 : return;
81 : }
82 :
83 : void SetInstType(CcuInstType instType)
84 : {
85 : instType_ = instType;
86 : }
87 :
88 0 : std::string Describe() const override
89 : {
90 0 : return StringFormat("CcuInstructionAllGatherMesh1D2Die rankId [%u], instType[%s]", rankId_, instType_.Describe().c_str());
91 : }
92 :
93 0 : CcuInstType GetInstType() const override
94 : {
95 0 : HCCL_INFO("CcuInstructionAllGatherMesh1D2Die instype is CCU_ALLGATHER_MESH_1D_2DIE.");
96 0 : return instType_;
97 : }
98 :
99 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
100 : {
101 0 : return std::make_unique<CcuCtxArgAllGatherMesh1D2Die>(dimSize_, rankId_, withMyRank_, op_, tempVTopo_);
102 : }
103 :
104 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
105 : {
106 0 : return std::make_unique<CcuTaskArgAllGatherMesh1D2Die>(inputAddr_, outputAddr_, sliceSize_, outputSliceStride_, token_);
107 : }
108 :
109 : private:
110 : CcuInstType instType_ = CcuInstType::CCU_ALLGATHER_MESH_1D_2DIE;
111 : std::vector<uint64_t> dimSize_;
112 : uint32_t rankId_{0};
113 : bool withMyRank_{false};
114 : uint64_t inputAddr_{0};
115 : uint64_t outputAddr_{0};
116 : uint64_t sliceSize_{0};
117 : uint64_t outputSliceStride_{0};
118 : uint64_t token_{0};
119 : CollAlgOperator op_;
120 : std::vector<std::vector<RankId>> tempVTopo_;
121 : };
122 :
123 : }
124 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_GATHER_MESH_1D_2DIE_H_
|