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