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 : #include "aiv_alg_template_base.h"
12 :
13 : namespace Hccl {
14 :
15 :
16 0 : AivAlgTemplateBase::AivAlgTemplateBase(const RankId virtualRank, const u32 tempRankSize,
17 : const std::vector<std::vector<RankId>> &tempVTopo,
18 0 : const std::map<RankId, u32> &tempVirtRankMap)
19 0 : : myRank_(virtualRank), tempRankSize_(tempRankSize), tempVTopo_(tempVTopo), tempVirtRankMap_(tempVirtRankMap)
20 : {
21 0 : }
22 :
23 0 : AivAlgTemplateBase::~AivAlgTemplateBase()
24 : {
25 0 : }
26 :
27 0 : void AivAlgTemplateBase::SetCollOp(const CollAlgOperator &op)
28 : {
29 0 : op_ = op;
30 0 : return;
31 : }
32 :
33 0 : void AivAlgTemplateBase::SetDmaMode(const DmaMode dmaMode)
34 : {
35 0 : dmaMode_ = dmaMode;
36 0 : return;
37 : }
38 :
39 0 : void AivAlgTemplateBase::InitReduceInfo(const ReduceOp &redOp, const DataType &dataType)
40 : {
41 0 : reduceOp_ = redOp;
42 0 : dataType_ = dataType;
43 0 : return;
44 : }
45 :
46 0 : void AivAlgTemplateBase::SetDataType(const DataType &dataType)
47 : {
48 0 : dataType_ = dataType;
49 0 : return;
50 : }
51 :
52 0 : void AivAlgTemplateBase::SetRoot(const u32 root)
53 : {
54 0 : root_ = root;
55 0 : return;
56 : }
57 :
58 0 : HcclResult AivAlgTemplateBase::CalcRes(AlgTempResReq &tempResReq)
59 : {
60 : (void)tempResReq;
61 0 : HCCL_ERROR("[AivAlgTemplateBase] Unsupported interface of resource calculation!");
62 0 : return HcclResult::HCCL_E_INTERNAL;
63 : }
64 :
65 0 : HcclResult AivAlgTemplateBase::CalcResDetour(const RankGraph *rankGraph, AlgTempResReq &tempResReq)
66 : {
67 : (void)rankGraph;
68 : (void)tempResReq;
69 0 : HCCL_ERROR("[AivAlgTemplateBase] Current alg do not support detour mode!");
70 0 : return HcclResult::HCCL_E_INTERNAL;
71 : }
72 :
73 0 : HcclResult AivAlgTemplateBase::CalcResDetour(ConnectedLinkMgr *linkMgr, AlgTempResReq &tempResReq)
74 : {
75 : (void)linkMgr;
76 : (void)tempResReq;
77 0 : HCCL_ERROR("[AivAlgTemplateBase] Current alg do not support detour mode!");
78 0 : return HcclResult::HCCL_E_INTERNAL;
79 : }
80 :
81 0 : u32 AivAlgTemplateBase::CalcScratchMultiple(BufferType inBuffType, BufferType outBuffType)
82 : {
83 : (void)inBuffType;
84 : (void)outBuffType;
85 : // AIV模式默认返回一整块Scratch
86 0 : return 1;
87 : }
88 :
89 0 : HcclResult AivAlgTemplateBase::GenExtIns(const TempFuncs &tempFuncs, const TemplateDataParams &templateDataParams,
90 : const ResLinks &tempLinks, std::vector<InsQuePtr> &tempInsQues)
91 : {
92 : (void)tempFuncs;
93 : (void)templateDataParams;
94 : (void)tempLinks;
95 : (void)tempInsQues;
96 0 : HCCL_ERROR("[AivAlgTemplateBase] Unsupported interface of instruction generation!");
97 0 : return HcclResult::HCCL_E_INTERNAL;
98 : }
99 :
100 0 : void AivAlgTemplateBase::IncSliceId()
101 : {
102 0 : sliceId_++;
103 0 : return;
104 : }
105 :
106 0 : HcclResult AivAlgTemplateBase::CalNumBlocks(u32& numBlocks, u64 dataSize, u32 numBlocksLimit)
107 : {
108 : (void) dataSize;
109 0 : if (numBlocksLimit >= tempRankSize_) {
110 0 : numBlocks = tempRankSize_;
111 : } else {
112 0 : numBlocks = numBlocksLimit;
113 : }
114 0 : HCCL_INFO("[AivAlgTemplateBase] Actually use core num[%u]", numBlocks);
115 0 : return HCCL_SUCCESS;
116 : }
117 :
118 0 : HcclResult AivAlgTemplateBase::setPathNumMap(const std::map<u32, u32> &rank2PathNumMap) const
119 : {
120 : (void)rank2PathNumMap;
121 0 : HCCL_WARNING("[AivAlgTemplateBase] Unsupported interface of setPathNumMap!");
122 0 : return HCCL_SUCCESS;
123 : }
124 :
125 : } // namespace Hccl
|