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