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_V_MESH_2DIE_H_
12 : #define HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_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 : // 为AllToAllVMesh2Die实现的CCUIns、CCUCtxArg与CCUTaskArg
25 : class CcuCtxArgAllToAllVMesh2Die : public CcuCtxArg {
26 : public:
27 0 : CcuCtxArgAllToAllVMesh2Die(const std::vector<uint32_t> &dSize, uint32_t rId, bool withMyRank,
28 : const CollAlgOperator &op, const std::vector<std::vector<RankId>> &tempVTopo,
29 0 : const std::vector<RankId> &rankGroup) :
30 0 : CcuCtxArg(), dimSize(dSize), rankId(rId), withMyRank(withMyRank), op(op), tempVTopo(tempVTopo),
31 0 : rankGroup(rankGroup) {}
32 :
33 0 : ~CcuCtxArgAllToAllVMesh2Die() override {}
34 :
35 0 : CcuCtxSignature GetCtxSignature() const override
36 : {
37 0 : CcuCtxSignature signature;
38 0 : GenerateCcuCtxSignature(signature, CcuInstType::CCU_ALLTOALLV_MESH_2DIE_DIRECT, op, tempVTopo);
39 0 : return signature;
40 0 : }
41 :
42 : std::vector<uint32_t> dimSize;
43 : uint32_t rankId;
44 : bool withMyRank;
45 : CollAlgOperator op;
46 : std::vector<std::vector<RankId>> tempVTopo;
47 : std::vector<RankId> rankGroup;
48 : };
49 :
50 : class CcuTaskArgAllToAllVMesh2Die : public CcuTaskArg {
51 : public:
52 0 : explicit CcuTaskArgAllToAllVMesh2Die(uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr,
53 0 : uint64_t token, const A2ASendRecvInfo& localSendRecvInfo) :
54 0 : inputAddr(inputAddr), outputAddr(outputAddr), scratchAddr(scratchAddr), token(token),
55 0 : localSendRecvInfo(localSendRecvInfo) {}
56 :
57 : uint64_t inputAddr;
58 : uint64_t outputAddr;
59 : uint64_t scratchAddr;
60 : uint64_t token;
61 : A2ASendRecvInfo localSendRecvInfo;
62 : };
63 :
64 : class CcuInstructionAllToAllVMesh2Die : public CcuInstruction {
65 : public:
66 0 : CcuInstructionAllToAllVMesh2Die(const CollAlgOperator &op, const std::vector<uint32_t> &dimSize,
67 0 : const std::vector<std::vector<RankId>> &tempVTopo) :
68 0 : CcuInstruction(), op_(op), dimSize_(dimSize), tempVTopo_(tempVTopo) {}
69 :
70 0 : void Init(uint32_t rankId, bool withMyRank, uint64_t inputAddr, uint64_t outputAddr, uint64_t scratchAddr,
71 : uint64_t token, const A2ASendRecvInfo& localSendRecvInfo)
72 : {
73 0 : rankId_ = rankId;
74 0 : withMyRank_ = withMyRank;
75 0 : inputAddr_ = inputAddr;
76 0 : outputAddr_ = outputAddr;
77 0 : scratchAddr_ = scratchAddr;
78 0 : token_ = token;
79 0 : localSendRecvInfo_ = localSendRecvInfo;
80 0 : return;
81 : }
82 :
83 0 : CcuInstType GetInstType() const override
84 : {
85 0 : HCCL_INFO("CcuInstructionAllToAllVMesh2Die instype is CCU_ALLTOALLV_MESH_2DIE_DIRECT.");
86 0 : return instType_;
87 : }
88 :
89 0 : std::string Describe() const override
90 : {
91 0 : return StringFormat("CcuInstructionAllToAllVMesh2Die rankId [%u], instType[%s]", rankId_,
92 0 : instType_.Describe().c_str());
93 : }
94 :
95 : void SetInstType(CcuInstType instType)
96 : {
97 : instType_ = instType;
98 : }
99 :
100 0 : std::unique_ptr<CcuCtxArg> GetCtxArg() const override
101 : {
102 0 : HCCL_INFO("[CcuInstructionAllToAllVMesh2Die][GetCtxArg] dimSize.size[%u], rankId[%u], withMyRank[%u], "
103 : "tempVTopo.size[%u]", dimSize_.size(), rankId_, withMyRank_, tempVTopo_.size());
104 0 : return std::make_unique<CcuCtxArgAllToAllVMesh2Die>(dimSize_, rankId_, withMyRank_, op_, tempVTopo_,
105 0 : rankGroup_.GetRanks());
106 : }
107 :
108 0 : std::unique_ptr<CcuTaskArg> GetTaskArg() const override
109 : {
110 : // 2个Die依赖的TaskArg要一样,因为当前ccu_ins_group只会用第一个Instruction获取TaskArg
111 0 : return std::make_unique<CcuTaskArgAllToAllVMesh2Die>(inputAddr_, outputAddr_, scratchAddr_, token_,
112 0 : localSendRecvInfo_);
113 : }
114 :
115 : private:
116 : CollAlgOperator op_;
117 : std::vector<uint32_t> dimSize_;
118 : std::vector<std::vector<RankId>> tempVTopo_;
119 :
120 : CcuInstType instType_ = CcuInstType::CCU_ALLTOALLV_MESH_2DIE_DIRECT;
121 : uint32_t rankId_{0};
122 : bool withMyRank_{false};
123 : uint64_t inputAddr_{0};
124 : uint64_t outputAddr_{0};
125 : uint64_t scratchAddr_{0};
126 : uint64_t token_{0};
127 : A2ASendRecvInfo localSendRecvInfo_;
128 : };
129 :
130 : }
131 : #endif // HCCLV2_CCU_INSTRUCTION_ALL_TO_ALL_V_MESH_2DIE_H_
|