/**
 * Copyright (c) 2025-2026 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 ascend_quant_apt.cpp
 * \brief ascend_quant kernel enter
 */

#include "kernel_operator.h"
#include "arch35/ascend_quant_regbase.h"
#include "arch35/ascend_quant_struct.h"
#include "arch35/ascend_quant_tilingdata.h"

using namespace AscendC;
using namespace AscendQuantOp;
template <uint64_t RoundMode, uint64_t ExtraBit, uint64_t OffsetZero>
__global__ __aicore__ void ascend_quant(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling)
{
#if (__NPU_ARCH__ == 3510)
    int64_t oriOverflowMode = AscendC::GetCtrlSpr<FLOAT_OVERFLOW_MODE_CTRL, FLOAT_OVERFLOW_MODE_CTRL>();
#endif
    REGISTER_TILING_DEFAULT(AscendQuantTilingData);
    GET_TILING_DATA(tilingData, tiling);
    KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY);
    AscendQuantPerTensorRegbase<DTYPE_X, DTYPE_Y, RoundMode, OffsetZero> op;
    TPipe pipe;
    op.Init(x, y, &tilingData, &pipe);
    op.Process();
#if (__NPU_ARCH__ == 3510)
    AscendC::SetCtrlSpr<FLOAT_OVERFLOW_MODE_CTRL, FLOAT_OVERFLOW_MODE_CTRL>(oriOverflowMode);
#endif
}