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(
23 : const AlltoAllUserRankInfo& userRankInfo, const std::vector<SendRecvInfo>& allMeshAggregationSendRecvInfo,
24 : u64& workspaceMemSize, 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 21 : 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(
50 : "[AlltoAllVStagedCalculator][CalcWorkSpaceMemSize]meshAggregationRankBegin is %u", meshAggregationRankBegin);
51 124 : for (u32 infoIndex = userRankInfo.userRank % meshAggregationRankSize; infoIndex < userRankInfo.userRankSize;
52 103 : infoIndex += meshAggregationRankSize) {
53 323 : for (u32 k = meshAggregationRankBegin; k < meshAggregationRankBegin + meshAggregationRankSize; k++) {
54 220 : workspaceMemSize += allMeshAggregationSendRecvInfo[k].sendLength[infoIndex];
55 : }
56 : }
57 :
58 21 : if (workspaceMemSize == 0) {
59 8 : HCCL_INFO("[AlltoAllVStagedCalculator][CalcWorkSpaceMemSize] workspaceMemSize is 0, use tiny mem size");
60 8 : workspaceMemSize = TINY_MEM_SIZE;
61 : }
62 21 : HCCL_INFO("[AlltoAllVStagedCalculator][CalcWorkSpaceMemSize]: workspaceMemSize[%llu]", workspaceMemSize);
63 : }
64 : // / STATIC MEMBER FUNCTIONS ENDS
65 : } // namespace hccl
|