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