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