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