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