* 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.
*/
* \file exp_tiling_impl.cpp
* \brief
*/
#include <cstdint>
#include "include/adv_api/math/exp_tiling.h"
#include "graph/tensor.h"
namespace AscendC {
namespace {
constexpr uint32_t EXP_HALF_CALC_PROC = 8;
constexpr uint32_t EXP_FLOAT_CALC_PROC = 3;
constexpr uint32_t EXP_ONE_REPEAT_BYTE_SIZE = 256;
constexpr uint32_t EXP_TWO_TIMES = 2;
constexpr uint32_t EXP_THREE_TIMES = 3;
constexpr uint32_t EXP_FOUR_TIMES = 4;
inline uint32_t GetExpMaxTmpSize(const uint32_t inputSize, const uint32_t typeSize, const bool isReuseSource)
{
const uint32_t tmpBufferSize = std::max<uint64_t>(inputSize * sizeof(float), EXP_ONE_REPEAT_BYTE_SIZE);
uint32_t numberOfTmpBuf = EXP_FOUR_TIMES;
if (typeSize == sizeof(float)) {
numberOfTmpBuf = isReuseSource ? EXP_TWO_TIMES : EXP_THREE_TIMES;
}
return numberOfTmpBuf * tmpBufferSize;
}
inline uint32_t GetExpMinTmpSize(const uint32_t typeSize, const bool isReuseSource)
{
uint32_t numberOfTmpBuf = EXP_FOUR_TIMES;
if (typeSize == sizeof(float)) {
numberOfTmpBuf = isReuseSource ? EXP_TWO_TIMES : EXP_THREE_TIMES;
}
return numberOfTmpBuf * EXP_ONE_REPEAT_BYTE_SIZE;
}
}
void GetExpTmpBufferFactorSize(const uint32_t typeSize, uint32_t& maxLiveNodeCount, uint32_t& extraBuffer)
{
extraBuffer = 0;
maxLiveNodeCount = (typeSize == sizeof(float)) ? EXP_FLOAT_CALC_PROC : EXP_HALF_CALC_PROC;
}
bool GetExpMaxMinTmpSize(
const ge::Shape& srcShape, const uint32_t typeSize, const bool isReuseSource, uint32_t& maxValue,
uint32_t& minValue)
{
const uint32_t inputSize = srcShape.GetShapeSize();
minValue = GetExpMinTmpSize(typeSize, isReuseSource);
maxValue = GetExpMaxTmpSize(inputSize, typeSize, isReuseSource);
return true;
}
}