/**  * 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 l0c_to_gm_iterator.h * \brief */ #ifndef L0C_TO_GM_ITERATOR_H #define L0C_TO_GM_ITERATOR_H #ifdef __CCE_KT_TEST__ #define __bf16 bfloat16_t #endif #include "iterator.h" constexpr uint32_t BLOCK_NUM = 16; constexpr uint32_t BLOCK_SIZE_INT8 = 32; template <> struct l0c_to_gm { /** * @brief Copy data from L0C buffer to global memory, partial specialized for * * @param gmTensor the destination tensor on global memory, which is stored in ND format. * @param l0cTensor the source tensor on L0C buffer, which is stored in FRACTAL_NZ format. * @param mTileActual the m-direction size of the matrix in L0C buffer. * @param nTileActual the n-direction size of the matrix in L0C buffer. * @param srcStride the source stride between the adjacent fractal matrices along n-direction in unit of C0_SIZE. * @param dstStride the leading dimension of the destination matrix in unit of element. */ __aicore__ l0c_to_gm(AscendC::GlobalTensor gmTensor, AscendC::LocalTensor l0cTensor, uint32_t mTileActual, uint32_t nTileActual, uint32_t srcStride, uint32_t dstStride) { #ifdef __DAV_C220_CUBE__ auto intriParams = AscendC::FixpipeParamsV220(nTileActual, // nSize mTileActual, // mSize srcStride, // srcStride dstStride, // dstStride false); // enRelu intriParams.quantPre = QuantMode_t::F322F16; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #else AscendC::FixpipeParams intriParams( (nTileActual + BLOCK_NUM - 1) / AscendC::BLOCK_CUBE, static_cast(mTileActual * BLOCK_NUM * sizeof(float) / BLOCK_SIZE_INT8), 0, dstStride); intriParams.nz2ndParams = {true, 1, 0, 0, static_cast(nTileActual)}; intriParams.quantParams = {QuantMode_t::F322F16}; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #endif }; }; template <> struct l0c_to_gm { __aicore__ l0c_to_gm(AscendC::GlobalTensor gmTensor, AscendC::LocalTensor l0cTensor, uint32_t mTileActual, uint32_t nTileActual, uint32_t srcStride, uint32_t dstStride) { #ifdef __DAV_C220_CUBE__ auto intriParams = AscendC::FixpipeParamsV220(nTileActual, // nSize mTileActual, // mSize srcStride, // srcStride dstStride, // dstStride false); // enRelu intriParams.quantPre = QuantMode_t::VDEQF16; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #else AscendC::FixpipeParams intriParams( (nTileActual + BLOCK_NUM - 1) / AscendC::BLOCK_CUBE, static_cast(mTileActual * BLOCK_NUM * sizeof(float) / BLOCK_SIZE_INT8), 0, dstStride); intriParams.nz2ndParams = {true, 1, 0, 0, static_cast(nTileActual)}; intriParams.quantParams = {QuantMode_t::VDEQF16}; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #endif }; }; template <> struct l0c_to_gm { __aicore__ l0c_to_gm(AscendC::GlobalTensor<__bf16> gmTensor, AscendC::LocalTensor l0cTensor, uint32_t mTileActual, uint32_t nTileActual, uint32_t srcStride, uint32_t dstStride) { #ifdef __DAV_C220_CUBE__ auto intriParams = AscendC::FixpipeParamsV220(nTileActual, // nSize mTileActual, // mSize srcStride, // srcStride dstStride, // dstStride false); // enRelu intriParams.quantPre = QuantMode_t::F322BF16; AscendC::Fixpipe<__bf16, float, AscendC::CFG_ROW_MAJOR>(gmTensor, l0cTensor, intriParams); #else AscendC::FixpipeParams intriParams( (nTileActual + BLOCK_NUM - 1) / AscendC::BLOCK_CUBE, static_cast(mTileActual * BLOCK_NUM * sizeof(float) / BLOCK_SIZE_INT8), 0, dstStride); intriParams.nz2ndParams = {true, 1, 0, 0, static_cast(nTileActual)}; intriParams.quantParams = {QuantMode_t::F322BF16}; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #endif }; }; // Partial specialization ND, float template <> struct l0c_to_gm { __aicore__ l0c_to_gm(AscendC::GlobalTensor gmTensor, AscendC::LocalTensor l0cTensor, uint32_t mTileActual, uint32_t nTileActual, uint32_t srcStride, uint32_t dstStride) { #ifdef __DAV_C220_CUBE__ auto intriParams = AscendC::FixpipeParamsV220(nTileActual, // nSize mTileActual, // mSize srcStride, // srcStride dstStride, // dstStride false); // enRelu intriParams.quantPre = QuantMode_t::NoQuant; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #else AscendC::FixpipeParams intriParams( (nTileActual + BLOCK_NUM - 1) / AscendC::BLOCK_CUBE, static_cast(mTileActual * BLOCK_NUM * sizeof(float) / BLOCK_SIZE_INT8), 0, dstStride); intriParams.nz2ndParams = {true, 1, 0, 0, static_cast(nTileActual)}; intriParams.quantParams = {QuantMode_t::NoQuant}; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #endif }; }; template <> struct l0c_to_gm { __aicore__ l0c_to_gm(AscendC::GlobalTensor gmTensor, AscendC::LocalTensor l0cTensor, uint32_t mTileActual, uint32_t nTileActual, uint32_t srcStride, uint32_t dstStride) { #ifdef __DAV_C220_CUBE__ auto intriParams = AscendC::FixpipeParamsV220(nTileActual, // nSize mTileActual, // mSize srcStride, // srcStride dstStride, // dstStride false); // enRelu intriParams.quantPre = QuantMode_t::F322F16; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #else AscendC::FixpipeParams intriParams( (nTileActual + BLOCK_NUM - 1) / AscendC::BLOCK_CUBE, static_cast(mTileActual * BLOCK_NUM * sizeof(float) / BLOCK_SIZE_INT8), 0, dstStride - (nTileActual * sizeof(half) / sizeof(float))); intriParams.quantParams = {QuantMode_t::F322F16}; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #endif }; }; template <> struct l0c_to_gm { __aicore__ l0c_to_gm(AscendC::GlobalTensor gmTensor, AscendC::LocalTensor l0cTensor, uint32_t mTileActual, uint32_t nTileActual, uint32_t srcStride, uint32_t dstStride){ #ifdef __DAV_C220_CUBE__ auto intriParams = AscendC::FixpipeParamsV220(nTileActual, // nSize mTileActual, // mSize srcStride, // srcStride dstStride, // dstStride false); // enRelu intriParams.quantPre = QuantMode_t::NoQuant; AscendC::Fixpipe(gmTensor, l0cTensor, intriParams); #endif }; }; #endif // L0C_TO_GM_ITERATOR_H