* Copyright (c) 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 sparse_bincount.cpp
* \brief Kernel entry for sparse_bincount operator.
* Scene mode dispatched via TilingKey (isPrecise x isDeterministic x is1D x binaryOutput x hasWeights = 32
* variants). dtype dispatched via DTYPE_VALUES / DTYPE_SIZE macros.
*
* TilingKey encoding: schMode = isPrecise * 16 + isDeterministic * 8 + is1D * 4 + binaryOutput * 2 + hasWeights
* 0-7: non-precise, non-deterministic modes (atomic-add scatter)
* 8-15: non-precise, deterministic modes (fixed-order gather accumulation, bitwise reproducible)
* 16-23: precise, non-deterministic modes
* 24-31: precise, deterministic modes (fixed-order + precise accumulation)
*/
#include "arch35/sparse_bincount_simt.h"
template <uint32_t schMode>
__global__ __aicore__ void sparse_bincount(GM_ADDR indices, GM_ADDR values, GM_ADDR dense_shape, GM_ADDR size,
GM_ADDR weights, GM_ADDR output, GM_ADDR workspace, GM_ADDR tiling)
{
REGISTER_TILING_DEFAULT(SparseBincountTilingData);
GET_TILING_DATA_WITH_STRUCT(SparseBincountTilingData, tilingData, tiling);
constexpr bool IS_PRECISE = ((schMode & 0x10) != 0);
constexpr bool IS_DETERMINISTIC = ((schMode & 0x8) != 0);
constexpr bool IS_1D = ((schMode & 0x4) != 0);
constexpr bool BINARY_OUTPUT = ((schMode & 0x2) != 0);
constexpr bool HAS_WEIGHTS = ((schMode & 0x1) != 0);
NsSparseBincount::Process<DTYPE_VALUES, DTYPE_SIZE, IS_PRECISE, IS_1D, BINARY_OUTPUT, HAS_WEIGHTS,
IS_DETERMINISTIC>(indices, values, dense_shape, size, weights, output, &tilingData);
}