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 "alltoallv_staged_calculator.h"
12 : #include "log.h"
13 :
14 : namespace hccl {
15 : using namespace std;
16 :
17 0 : AlltoAllVStagedCalculator::AlltoAllVStagedCalculator() {}
18 :
19 0 : AlltoAllVStagedCalculator::~AlltoAllVStagedCalculator() {}
20 :
21 : // / STATIC MEMBER FUNCTIONS BEGINS
22 21 : void AlltoAllVStagedCalculator::CalcWorkSpaceMemSize(const AlltoAllUserRankInfo &userRankInfo,
23 : const std::vector<SendRecvInfo> &allMeshAggregationSendRecvInfo, u64 &workspaceMemSize,
24 : u32 meshAggregationRankSize)
25 : {
26 241 : for (const auto &oneMeshAggregationSendRecvInfo : allMeshAggregationSendRecvInfo) {
27 2604 : for (const auto &sendLength : oneMeshAggregationSendRecvInfo.sendLength) {
28 2384 : HCCL_DEBUG("[CalcWorkSpaceMemSize] sendLength[%llu]", sendLength);
29 : }
30 2604 : for (const auto &sendOffset : oneMeshAggregationSendRecvInfo.sendOffset) {
31 2384 : HCCL_DEBUG("[CalcWorkSpaceMemSize] sendOffset[%llu]", sendOffset);
32 : }
33 2604 : for (const auto &recvLength : oneMeshAggregationSendRecvInfo.recvLength) {
34 2384 : HCCL_DEBUG("[CalcWorkSpaceMemSize] recvLength[%llu]", recvLength);
35 : }
36 2604 : for (const auto &recvOffset : oneMeshAggregationSendRecvInfo.recvOffset) {
37 2384 : HCCL_DEBUG("[CalcWorkSpaceMemSize] recvOffset[%llu]", recvOffset);
38 : }
39 : }
40 42 : if (allMeshAggregationSendRecvInfo.size() % meshAggregationRankSize != 0 ||
41 21 : allMeshAggregationSendRecvInfo.size() == 0) {
42 0 : workspaceMemSize = 0;
43 0 : HCCL_ERROR("Invalid Send Recv Info Size[%u]", allMeshAggregationSendRecvInfo.size());
44 0 : return;
45 : }
46 21 : workspaceMemSize = 0;
47 21 : u32 meshAggregationIndex = userRankInfo.userRank / meshAggregationRankSize;
48 21 : u32 meshAggregationRankBegin = meshAggregationIndex * meshAggregationRankSize;
49 21 : HCCL_DEBUG("[AlltoAllVStagedCalculator][CalcWorkSpaceMemSize]meshAggregationRankBegin is %u", meshAggregationRankBegin);
50 124 : for (u32 infoIndex = userRankInfo.userRank % meshAggregationRankSize; infoIndex < userRankInfo.userRankSize;
51 103 : infoIndex += meshAggregationRankSize) {
52 323 : for (u32 k = meshAggregationRankBegin; k < meshAggregationRankBegin + meshAggregationRankSize; k++) {
53 220 : workspaceMemSize += allMeshAggregationSendRecvInfo[k].sendLength[infoIndex];
54 : }
55 : }
56 :
57 21 : if (workspaceMemSize == 0) {
58 8 : HCCL_INFO("[AlltoAllVStagedCalculator][CalcWorkSpaceMemSize] workspaceMemSize is 0, use tiny mem size");
59 8 : workspaceMemSize = TINY_MEM_SIZE;
60 : }
61 21 : HCCL_INFO("[AlltoAllVStagedCalculator][CalcWorkSpaceMemSize]: workspaceMemSize[%llu]", workspaceMemSize);
62 : }
63 : // / STATIC MEMBER FUNCTIONS ENDS
64 : } // namespace hccl
|