/** * Copyright (c) 2024 Huawei Technologies Co., Ltd. * This file is a part of the CANN Open Software. * Licensed under CANN Open Software License Agreement Version 1.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 sigmoid.h * \brief Sigmoid is an activation function, * Mathematical formulas: Sigmoid(x) = 1 / (1 + exp(-x)) */ #ifndef LIB_SIGMOID_SIGMOID_H #define LIB_SIGMOID_SIGMOID_H #if __CCE_AICORE__ == 100 || __CCE_AICORE__ == 200 || __CCE_AICORE__ == 220 #include "kernel_tensor.h" #include "../../impl/activation/sigmoid/sigmoid_common_impl.h" namespace AscendC { #pragma begin_pipe(V) /*! * \ingroup Sigmoid * \brief compute Sigmoid elementwisely * \tparam T: input dataType, support half/float * \tparam isReuseSource: whether allows API to modify source data, usually for performance reason, * not enabled currently. * \param [out] dstTensor: output LocalTensor * \param [in] srcTensor: input LocalTensor * \param [in] sharedTmpBuffer:extra temporary shared space used for intermediate values among calculation process, * whose required space size should refer to corresponding tiling API, which is defined at * sigmoid_tiling.h. Generally, the more space you allocate, the better performance you will achieve, * and the performance reaches peak when buffer size is maximum(calculated by tiling function). Moreover, it * is not guaranteed that the shared space will be cleared after usage, the data could be anything. * \param [in] calCount: amount of input data to be calculated */ template __aicore__ inline void Sigmoid(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const LocalTensor& sharedTmpBuffer, const uint32_t calCount) { SigmoidImpl(dstTensor, srcTensor, sharedTmpBuffer, calCount); } /*! * \ingroup Sigmoid * \brief compute Sigmoid elementwisely * \tparam T: input dataType, support half/float * \tparam isReuseSource: whether allows API to modify source data, usually for performance reason, * not enabled currently. * \param [out] dstTensor: output LocalTensor * \param [in] srcTensor: input LocalTensor * \param [in] calCount: amount of input data to be calculated */ template __aicore__ inline void Sigmoid(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const uint32_t calCount) { SigmoidImpl(dstTensor, srcTensor, calCount); } /*! * \ingroup Sigmoid * \brief compute Sigmoid elementwisely * \tparam T: input dataType, support half/float * \tparam isReuseSource: whether allows API to modify source data, usually for performance reason, * not enabled currently. * \param [out] dstTensor: output LocalTensor * \param [in] srcTensor: input LocalTensor * \param [in] sharedTmpBuffer:extra temporary shared space used for intermediate values among calculation process, * whose required space size should refer to corresponding tiling API, which is defined at * sigmoid_tiling.h. Generally, the more space you allocate, the better performance you will achieve, * and the performance reaches peak when buffer size is maximum(calculated by tiling function). Moreover, it * is not guaranteed that the shared space will be cleared after usage, the data could be anything. * \param [in] calCount: amount of input data to be calculated */ template __aicore__ inline void Sigmoid(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const LocalTensor& sharedTmpBuffer) { Sigmoid(dstTensor, srcTensor, sharedTmpBuffer, srcTensor.GetSize()); } /*! * \ingroup Sigmoid * \brief compute Sigmoid elementwisely * \tparam T: input dataType, support half/float * \tparam isReuseSource: whether allows API to modify source data, usually for performance reason, * not enabled currently. * \param [out] dstTensor: output LocalTensor * \param [in] srcTensor: input LocalTensor */ template __aicore__ inline void Sigmoid(const LocalTensor& dstTensor, const LocalTensor& srcTensor) { Sigmoid(dstTensor, srcTensor, srcTensor.GetSize()); } #pragma end_pipe } // namespace AscendC #endif #endif // LIB_SIGMOID_SIGMOID_H