* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
#ifndef COLL_ALG_UTILS_H
#define COLL_ALG_UTILS_H
#include "externalinput_pub.h"
#include "hccl_common.h"
#include "common.h"
#include "device_capacity.h"
#include "coll_alg_param.h"
#include "op_context.h"
#include "env_config.h"
namespace hccl {
constexpr u64 MAX_ALLTOALL_MESH_ALGO_RANK_INTRA_MESH = 32;
constexpr u32 MAX_RING_PIPLINE_SERVER_NUM = 128;
constexpr u32 MIN_PER_LINK_DATA_SIZE = 4 * 1024 * 1024;
constexpr u32 MIN_RING_DATA_SIZE = 64 * 1024;
constexpr u64 MAX_PIPLINE_SLICE_NUM = 4;
constexpr u64 MIN_PIPLINE_SLICE_NUM = 2;
constexpr u64 TINY_MEM_SIZE = 2 * 1024 * 1024;
constexpr u64 MAX_ALLTOALLV_DIRECT_FULLMESH_RANKSIZE = 64;
constexpr u64 MAX_ALLTOALLV_DIRECT_FULLMESH_SERVER_NUM = 8;
bool IsAlgTypeLevel0Mesh(const AlgTypeLevel0 &originalAlgTypeLevel0);
bool IsSupportUnifiedMarch(const OpParam& param, const TopoType& topoType, u32 serverNum, u32 superPodNum);
bool IsAlltoAllvcSatisfyBufferSize(const OpParam& param, u32 userRankSize, u64 cclbufferSize);
bool IsSupportDirectFullmeshForAlltoallv(const OpParam& param, DevType deviceType, bool useSuperPodMode, u32 serverNum,
bool isSingleMeshAggregation, u32 userRankSize, u64 cclbufferSize);
bool FullmeshPairwiseSatisfyHighPerfAlltoallMeshCondition(DevType deviceType, u32 rankSize, bool useSuperPodMode, std::vector<HcclAlgoType> algoConfig);
bool SatisfyIntraSuperPod(DevType deviceType, u32 rankSize, bool useSuperPodMode, u32 superPodNum = 1);
bool HcclOpInplaceDefaultCase(const OpParam ¶m, u8 &isInplaceStatus);
bool IsInputOutputOverlap(const OpParam ¶m, u64 inputDataSize, u64 outputDataSize, u8 &isInplaceStatus);
bool IsInputOutPtrNotNullPtr(const OpParam ¶m, u8 &isInplaceStatus);
u32 InplaceDataUnitSize(const HcclCMDType &opType, const OpParam ¶m);
bool IsHcclOpInplace(const HcclCMDType &opType, const OpParam ¶m, u32 userRank, u32 userRankSize,
u8 &isInplaceStatus);
bool CheckUserInMemNotLargerThanCCLInMem(const HcclCMDType &opType, OpParam ¶m,
u64 commInputSize, u32 userRankSize);
bool ExecutorOnlySupportDMAReduce(const std::string& algName);
bool ExecutorCanSupportDMAReduce(const std::string& algName);
bool ExecutorNoSupportDMAReduce(const std::string& algName);
bool ExecutorSupportInPlace(const OpParam ¶m, const std::string& algName, bool retryEnable,
InplaceSupportRetryStatus &inPlaceSupportRetryStatus);
bool FitRetryConditionforInPlaceOp(const HcclCMDType &opType, OpParam ¶m, const std::string& algName,
u64 commInputSize, u32 userRankSize, bool retryEnable, InplaceSupportRetryStatus &inPlaceSupportRetryStatus);
bool IsConfigAHCAlgo(std::map<HcclCMDType, std::vector<HcclAlgoType>> algoConfigMap);
template<typename keyType>
std::string GetAlgoString(const std::map<keyType, std::string>& levelMap, keyType key);
std::string AlgTypeToStr(const AlgType algType);
bool Is310P3Common(bool isHaveCpuRank, DevType deviceType);
u64 CalculatePiplineSliceNum(HcclCMDType opType, u64 dataSize, AlgType algType, DevType deviceType,
u32 deviceNumPerAggregation, u32 moduleNum);
u32 CalGCD(std::vector<u32> &nums);
u32 CalGCD(u32 a, u32 b);
}
#endif