diff --git a/impl/api_check/kernel_api_check.h b/impl/api_check/kernel_api_check.h new file mode 100644 index 0000000000000000000000000000000000000000..4b986fd7a729d0203b62700aab6d9c860cce725b --- /dev/null +++ b/impl/api_check/kernel_api_check.h @@ -0,0 +1,38 @@ +/** + * Copyright (c) 2025 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 kernel_api_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_API_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_API_CHECK_H_ + +#ifdef ASCENDC_CPU_DEBUG +#include "kernel_check/reduce/mean/mean_check.h" +#include "kernel_check/reduce/reduce_all/reduce_all_check.h" +#include "kernel_check/reduce/reduce_any/reduce_any_check.h" +#include "kernel_check/reduce/reduce_max/reduce_max_check.h" +#include "kernel_check/reduce/reduce_min/reduce_min_check.h" +#include "kernel_check/reduce/reduce_mean/reduce_mean_check.h" +#include "kernel_check/reduce/reduce_sum/reduce_sum_check.h" +#include "kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check.h" +#include "kernel_check/reduce/reduce_prod/reduce_prod_check.h" +#include "kernel_check/reduce/sum/sum_check.h" + +#define EXPAND(...) __VA_ARGS__ +#define MERGE_ARGS(first, args) (first, EXPAND args) +#define CHECK_FUNC_HIGHLEVEL_API(API, templateArgs, inputArgs)\ + HighLevelApiCheck::CheckFunc##API MERGE_ARGS(#API, inputArgs) +#else +#define CHECK_FUNC_HIGHLEVEL_API(...) +#endif + +#endif // IMPL_API_CHECK_KERNEL_API_CHECK_H_ diff --git a/impl/api_check/kernel_check/basic_check/basic_check_utils.h b/impl/api_check/kernel_check/basic_check/basic_check_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..62ae519c07c615f8e298049db20d7e3b183ac867 --- /dev/null +++ b/impl/api_check/kernel_check/basic_check/basic_check_utils.h @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2025 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 basic_check_utils.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_BASIC_CHECK_UTILS_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_BASIC_CHECK_UTILS_H_ + +#include "std/tuple.h" +#include "std/algorithm.h" +#include "std/type_traits.h" +#include "std/utility.h" +#include "kernel_tiling/kernel_tiling.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +constexpr bool HighLevelAPIParametersPrint = false; + +enum class HardWareIndex { + GM = 0, + UB, + L1, + L0A, + L0B, + L0C, + BIAS, + FIXBUF, + MAX +}; + +template +using tuple_sequence = Std::make_index_sequence>>; + +#define TO_STRING(x) (#x) + +#define VA_ARGS_TO_MAKE_TUPLE_1(p1) MakeParameters2Tuple(p1), MakeString2Tuple(TO_STRING(p1)) +#define VA_ARGS_TO_MAKE_TUPLE_2(p1, p2) MakeParameters2Tuple(p1, p2), MakeString2Tuple(TO_STRING(p1), TO_STRING(p2)) +#define VA_ARGS_TO_MAKE_TUPLE_3(p1, p2, p3) MakeParameters2Tuple(p1, p2, p3),\ + MakeString2Tuple(TO_STRING(p1), TO_STRING(p2), TO_STRING(p3)) +#define VA_ARGS_TO_MAKE_TUPLE_4(p1, p2, p3, p4) MakeParameters2Tuple(p1, p2, p3, p4),\ + MakeString2Tuple(TO_STRING(p1), TO_STRING(p2), TO_STRING(p3), TO_STRING(p4)) +#define VA_ARGS_TO_MAKE_TUPLE_5(p1, p2, p3, p4, p5) MakeParameters2Tuple(p1, p2, p3, p4, p5),\ + MakeString2Tuple(TO_STRING(p1), TO_STRING(p2), TO_STRING(p3), TO_STRING(p4), TO_STRING(p5)) + +#define GET_MACRO(_1, _2, _3, _4, _5, NAME, ...) NAME +#define VA_ARGS_TO_MAKE_TUPLE(...) GET_MACRO(__VA_ARGS__, VA_ARGS_TO_MAKE_TUPLE_5, VA_ARGS_TO_MAKE_TUPLE_4,\ + VA_ARGS_TO_MAKE_TUPLE_3, VA_ARGS_TO_MAKE_TUPLE_2, VA_ARGS_TO_MAKE_TUPLE_1) (__VA_ARGS__) + +template +__aicore__ inline auto MakeParameters2Tuple(Args... args) +{ + static_assert(sizeof...(Args) > 0, "The number of input elements must be greater than 0."); + return Std::make_tuple(args...); +} + +template +__aicore__ inline auto MakeString2Tuple(__gm__ const char* errLog, Args... args) +{ + return Std::make_tuple(errLog, args...); +} + +#define ARG_AND_STRING(x) (x), (TO_STRING(x)) + +#define ARGS_TO_STRING(...) #__VA_ARGS__ +#define VA_ARGS_TO_MAKE_TUPLE_STRING(...) MakeParameters2Tuple(__VA_ARGS__), ARGS_TO_STRING(__VA_ARGS__) + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_BASIC_CHECK_UTILS_H_ diff --git a/impl/api_check/kernel_check/basic_check/calcount_check.h b/impl/api_check/kernel_check/basic_check/calcount_check.h new file mode 100644 index 0000000000000000000000000000000000000000..7cd7429b651a1d15d536b2cee6329775d7600517 --- /dev/null +++ b/impl/api_check/kernel_check/basic_check/calcount_check.h @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2025 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 calcount_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_CALCOUNT_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_CALCOUNT_CHECK_H_ + +#include "basic_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class CalCountCheckFuncBasicClass { +public: + __aicore__ inline CalCountCheckFuncBasicClass() {}; + __aicore__ inline CalCountCheckFuncBasicClass(__gm__ const char *apiName) { + this->apiName = apiName; + }; + +public: + template + __aicore__ inline void CalCountVerifyingParameters(const uint32_t calCount, __gm__ const char* paraName, + T tensorTuple, U tensorStringTuple) + { + static_assert((Std::is_tuple_v && Std::is_tuple_v), "Input template T or U is not tuple!"); + static_assert((Std::tuple_size_v == Std::tuple_size_v), + "CalCountVerifyingParameters func, tensorTuple.Size != tensorStringTuple.Size !"); + + CalCountLoopCheck(calCount, paraName, tensorTuple, tensorStringTuple, tuple_sequence{}); + } + +private: + template + __aicore__ inline void CalCountLoopCheck(const uint32_t calCount, __gm__ const char* paraName, + T checkTensor, U tensorInfo, Std::index_sequence) + { + (CalCountCheck(checkTensor)), decltype(Std::get(tensorInfo))> + (calCount, paraName, Std::get(checkTensor), Std::get(tensorInfo)), ...); + } + + template + __aicore__ inline void CalCountCheck(const uint32_t calCount, __gm__ const char* paraName, + const T& checkTensor, const U& tensorInfo) + { + ASCENDC_ASSERT((calCount <= checkTensor.GetSize() || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] Failed to check %s, %s is %u, should be less than or equal to %s size %u.", + apiName, paraName, paraName, calCount, tensorInfo, checkTensor.GetSize()); + }); + + if constexpr (HighLevelAPIParametersPrint) { + PrintParameters(calCount, paraName, checkTensor, tensorInfo); + } + } + + template + __aicore__ inline void PrintParameters(const uint32_t calCount, __gm__ const char* paraName, + const T& checkTensor, const U& tensorInfo) + { + KERNEL_LOG(KERNEL_INFO, "[%s] The tensor size of %s is %u, %s is %u.", apiName, tensorInfo, + checkTensor.GetSize(), paraName, calCount); + } + +private: + __gm__ const char *apiName = NULL; +}; + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_CALCOUNT_CHECK_H_ diff --git a/impl/api_check/kernel_check/basic_check/datatype_check.h b/impl/api_check/kernel_check/basic_check/datatype_check.h new file mode 100644 index 0000000000000000000000000000000000000000..ea3e2164be4fb11b43864f43f525d3fa61e36248 --- /dev/null +++ b/impl/api_check/kernel_check/basic_check/datatype_check.h @@ -0,0 +1,114 @@ +/** + * Copyright (c) 2025 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 datatype_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_DATATYPE_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_DATATYPE_CHECK_H_ + +#include "basic_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +template +struct IsTypeInPack : Std::false_type {}; + +template +struct IsTypeInPack : +Std::conditional_t, Std::true_type, IsTypeInPack> {}; + +template +constexpr bool IsTypeInPackV = IsTypeInPack::value; + +template +struct IndexInTuple; + +template +struct IndexInTuple> { + static constexpr size_t value = 0; +}; + +template +struct IndexInTuple> { + static constexpr size_t value = 1 + IndexInTuple>::value; +}; + +template +__aicore__ inline __gm__ const char* GetTypeName(const Tuple1& typeData, const Tuple2& typeString) { + constexpr size_t index = IndexInTuple::value; + return Std::get(typeString); +} + +class DataTypeCheckFuncBasicClass { +public: + __aicore__ inline DataTypeCheckFuncBasicClass() {}; + __aicore__ inline DataTypeCheckFuncBasicClass(__gm__ const char *apiName) { + this->apiName = apiName; + }; + +public: + template + __aicore__ inline void DataTypeVerifyingParameters(__gm__ const char* errLog) + { + VerifyingParameters(errLog); + if constexpr (HighLevelAPIParametersPrint) { + PrintParameters(); + } + } + +private: + template + __aicore__ inline void VerifyingParameters(__gm__ const char* errLog) { + if (!IsTypeInPackV) { + ASCENDC_ASSERT((HighLevelAPIParametersPrint), + { KERNEL_LOG(KERNEL_ERROR, "[%s] The data type of the template parameter is incorrect, %s!", + apiName, errLog); }); + } + } + + template + __aicore__ inline void PrintParameters() + { + if constexpr (Std::is_tuple_v) { + PrintTupleParameters(tuple_sequence{}); + } else { + PrintSingleParameter(); + } + } + + template + __aicore__ inline void PrintTupleParameters(Std::index_sequence) + { + (PrintSingleParameter::type>(), ...); + } + + template + __aicore__ inline void PrintSingleParameter() + { + Std::tuple typeData; + + auto typeString = MakeString2Tuple("int4b_t", "int8_t", "uint8_t", "half", "int16_t", "uint16_t", + "int32_t", "uint32_t", "uint64_t", "int64_t", "float", "bfloat16_t", "double"); + + KERNEL_LOG(KERNEL_INFO, "[%s] The data type in the template parameter is %s!", apiName, + GetTypeName(typeData, typeString)); + } + +private: + __gm__ const char *apiName = NULL; +}; + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_DATATYPE_CHECK_H_ diff --git a/impl/api_check/kernel_check/basic_check/multiple_tensor_check.h b/impl/api_check/kernel_check/basic_check/multiple_tensor_check.h new file mode 100644 index 0000000000000000000000000000000000000000..b4799ad135d4164f6fc04abf1137336f556590b3 --- /dev/null +++ b/impl/api_check/kernel_check/basic_check/multiple_tensor_check.h @@ -0,0 +1,97 @@ +/** + * Copyright (c) 2025 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 multiple_tensor_check.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_MULTIPLE_TENSOR_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_MULTIPLE_TENSOR_CHECK_H_ + +#include "basic_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class MultipleTensorCheckFuncBasicClass { +public: + __aicore__ inline MultipleTensorCheckFuncBasicClass() {}; + __aicore__ inline MultipleTensorCheckFuncBasicClass(__gm__ const char *apiName) { + this->apiName = apiName; + }; + +public: + template + __aicore__ inline void TensorReuseVerifyingParameters(T tensorTuple, U tensorStringTuple) + { + static_assert((Std::is_tuple_v && Std::is_tuple_v), + "Input template T or U or W is not tuple!"); + static_assert((Std::tuple_size_v == Std::tuple_size_v), + "TPositionVerifyingParameters func, tensorTuple.Size != tensorStringTuple.Size !"); + MultipleTensorReuseLoopCheck(tensorTuple, tensorStringTuple, tuple_sequence{}); + } + +private: + template + __aicore__ inline void MultipleTensorReuseLoopCheck(T tensorTuple, U tensorStringTuple, Std::index_sequence) + { + (SingleTensorReuseLoopCheck(Std::get(tensorTuple), Std::get(tensorStringTuple), + tensorTuple, tensorStringTuple, Is, tuple_sequence{}), ...); + } + + template + __aicore__ inline void SingleTensorReuseLoopCheck(const LocalTensor &checkTensor, __gm__ const char* tensorString, + T tensorTuple, U tensorStringTuple, const uint32_t index, Std::index_sequence) + { + (TensorReuseLoopCheck(checkTensor, tensorString, + Std::get(tensorTuple), Std::get(tensorStringTuple), index, Is), ...); + + if constexpr (HighLevelAPIParametersPrint) { + PrintTensorInfo(checkTensor, tensorString); + } + } + + template + __aicore__ inline void TensorReuseLoopCheck(const LocalTensor &checkTensor, + __gm__ const char* checkTensorString, const LocalTensor &tensor, __gm__ const char* tensorString, + const uint32_t indexCheck, const uint32_t indexTensor) + { + if (indexCheck == indexTensor) { + return; + } + uint64_t checkPhyAddr = static_cast(reinterpret_cast(checkTensor.GetPhyAddr())); + uint64_t tensorPhyAddr = static_cast(reinterpret_cast(tensor.GetPhyAddr())); + if (tensorPhyAddr >= checkPhyAddr + static_cast(checkTensor.GetLength()) || + checkPhyAddr >= tensorPhyAddr + static_cast(tensor.GetLength())) { + return; + } + + ASCENDC_ASSERT(HighLevelAPIParametersPrint, {KERNEL_LOG(KERNEL_ERROR, + "[%s] The input Tensor (%s) and (%s) cannot be reused, TensorA addr is (%u, %u), TensorB addr is (%u, %u)!", + apiName, checkTensorString, tensorString, + checkPhyAddr, checkPhyAddr + static_cast(checkTensor.GetLength()), + tensorPhyAddr, tensorPhyAddr + static_cast(tensor.GetLength())); }); + } + + template + __aicore__ inline void PrintTensorInfo(const LocalTensor &checkTensor, __gm__ const char* checkTensorString) + { + uint64_t checkPhyAddr = static_cast(reinterpret_cast(checkTensor.GetPhyAddr())); + KERNEL_LOG(KERNEL_INFO, "[%s] CheckTensor (%s) physical address is (%u, %u)!", + apiName, checkTensorString, checkPhyAddr, checkPhyAddr + static_cast(checkTensor.GetLength())); + } + +private: + __gm__ const char *apiName = NULL; +}; + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_MULTIPLE_TENSOR_CHECK_H_ diff --git a/impl/api_check/kernel_check/basic_check/reuse_source_check.h b/impl/api_check/kernel_check/basic_check/reuse_source_check.h new file mode 100644 index 0000000000000000000000000000000000000000..c1329ae51234c4170db631d2e1d89447577e8a7d --- /dev/null +++ b/impl/api_check/kernel_check/basic_check/reuse_source_check.h @@ -0,0 +1,62 @@ +/** + * Copyright (c) 2025 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 reuse_source_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_REUSE_SOURCE_CHECK_H +#define IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_REUSE_SOURCE_CHECK_H + +#include "basic_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class ReuseSourceCheckFuncBasicClass { +public: + __aicore__ inline ReuseSourceCheckFuncBasicClass() {}; + __aicore__ inline ReuseSourceCheckFuncBasicClass(__gm__ const char *apiName) { + this->apiName = apiName; + }; + +public: + template + __aicore__ inline void IsReuseSourceVerifyingParameters(const bool isReuseSource, __gm__ const char* paraName) + { + ReuseSourceKernelCheckVerify(isReuseSource, paraName); + if constexpr (HighLevelAPIParametersPrint) { + PrintParameters(isReuseSource, paraName); + } + } + +private: + template + __aicore__ inline void ReuseSourceKernelCheckVerify(const bool isReuseSource, __gm__ const char* paraName) { + if (!isConfigurable && isReuseSource == true) { + KERNEL_LOG(KERNEL_WARN, "[%s] The parameter of %s is true, may not be effective.", apiName, paraName); + } + } + __aicore__ inline void PrintParameters(const bool isReuseSource, __gm__ const char* paraName) + { + if (isReuseSource) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter of %s is true!", apiName, paraName); + } else { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter of %s is false!", apiName, paraName); + } + } + +private: + __gm__ const char *apiName = NULL; +}; + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_REUSE_SOURCE_CHECK_H \ No newline at end of file diff --git a/impl/api_check/kernel_check/basic_check/single_tensor_check.h b/impl/api_check/kernel_check/basic_check/single_tensor_check.h new file mode 100644 index 0000000000000000000000000000000000000000..13803a7a60c20a6302e2e718c3b486900b9ef7b3 --- /dev/null +++ b/impl/api_check/kernel_check/basic_check/single_tensor_check.h @@ -0,0 +1,194 @@ +/** + * Copyright (c) 2025 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 single_tensor_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_SINGLE_TENSOR_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_SINGLE_TENSOR_CHECK_H_ + +#include "basic_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class SingleTensorCheckFuncBasicClass { +public: + __aicore__ inline SingleTensorCheckFuncBasicClass() {}; + __aicore__ inline SingleTensorCheckFuncBasicClass(__gm__ const char *apiName) { + this->apiName = apiName; + }; + +public: + template + __aicore__ inline void TensorVerifyingParameters(T tensorTuple, U tensorStringTuple, W posTuple, + __gm__ const char* posString) + { + TPositionVerifyingParameters(tensorTuple, tensorStringTuple, posTuple, posString); + TensorSizeVerifyingParameters(tensorTuple, tensorStringTuple); + TensorPhyAddrVerifyingParameters(tensorTuple, tensorStringTuple); + } + + template + __aicore__ inline void TPositionVerifyingParameters(T tensorTuple, U tensorStringTuple, W posTuple, + __gm__ const char* posString) + { + static_assert((Std::is_tuple_v && Std::is_tuple_v && Std::is_tuple_v), + "Input template T or U or W is not tuple!"); + static_assert((Std::tuple_size_v == Std::tuple_size_v), + "TPositionVerifyingParameters func, tensorTuple.Size != tensorStringTuple.Size !"); + + TPositionAllTensorLoopCheck(tensorTuple, tensorStringTuple, posTuple, posString, tuple_sequence{}); + } + + template + __aicore__ inline void TensorSizeVerifyingParameters(T tensorTuple, U tensorStringTuple) + { + static_assert((Std::is_tuple_v && Std::is_tuple_v), "Input template T or U is not tuple!"); + static_assert((Std::tuple_size_v == Std::tuple_size_v), + "TensorSizeVerifyingParameters func, tensorTuple.Size != tensorStringTuple.Size !"); + + TensorSizeAllTensorLoopCheck(tensorTuple, tensorStringTuple, tuple_sequence{}); + } + + template + __aicore__ inline void TensorPhyAddrVerifyingParameters(T tensorTuple, U tensorStringTuple) + { + static_assert((Std::is_tuple_v && Std::is_tuple_v), "Input template T or U is not tuple!"); + static_assert((Std::tuple_size_v == Std::tuple_size_v), + "TensorPhyAddrVerifyingParameters func, tensorTuple.Size != tensorStringTuple.Size !"); + + TensorPhyAddrAllTensorLoopCheck(tensorTuple, tensorStringTuple, tuple_sequence{}); + } + +private: + __aicore__ inline __gm__ const char* GetTPositionString(TPosition pos) + { + if (pos == TPosition::VECIN) { + return "TPosition::VECIN"; + } else if (pos == TPosition::VECOUT) { + return "TPosition::VECIN"; + } else if (pos == TPosition::VECCALC) { + return "TPosition::VECCALC"; + } else { + return "TPosition::MAX"; + } + } + + template + __aicore__ inline void TPositionAllTensorLoopCheck(T tensorTuple, U tensorStringTuple, W posTuple, + __gm__ const char* posString, Std::index_sequence) + { + (TPositionOneTensorCheck(Std::get(tensorTuple), Std::get(tensorStringTuple), posTuple, posString), ...); + } + + template + __aicore__ inline void TPositionOneTensorCheck(const LocalTensor &checkTensor, + __gm__ const char* tensorName, U posTuple, __gm__ const char* posString) + { + static_assert((Std::is_tuple_v), "Input template U is not tuple!"); + TPositionOneTensorLoopCheck(checkTensor, tensorName, posTuple, posString, tuple_sequence{}); + if constexpr (HighLevelAPIParametersPrint) { + PrintTensorTPosition(checkTensor, tensorName); + } + } + + template + __aicore__ inline void TPositionOneTensorLoopCheck(const LocalTensor &checkTensor, __gm__ const char* tensorName, + U posTuple, __gm__ const char* posString, Std::index_sequence) + { + TPosition pos = (TPosition)checkTensor.GetPosition(); + bool status = ((pos == Std::get(posTuple)) || ...); + + ASCENDC_ASSERT((status || HighLevelAPIParametersPrint), {KERNEL_LOG(KERNEL_ERROR, + "[%s] Failed to check tensor position of %s, current api support positions are %s, " + "current position is %s.", apiName, tensorName, posString, GetTPositionString(pos)); }); + } + + template + __aicore__ inline void PrintTensorTPosition(const LocalTensor &checkTensor, __gm__ const char *tensorInfo) + { + TPosition pos = (TPosition)checkTensor.GetPosition(); + KERNEL_LOG(KERNEL_INFO, "[%s] The tensor position of %s is %s.", apiName, tensorInfo, GetTPositionString(pos)); + } + + template + __aicore__ inline void TensorSizeAllTensorLoopCheck(T tensorTuple, U tensorStringTuple, Std::index_sequence) + { + (TensorSizeOneTensorCheck(Std::get(tensorTuple), Std::get(tensorStringTuple)), ...); + } + + template + __aicore__ inline void TensorSizeOneTensorCheck(const LocalTensor &checkTensor, __gm__ const char *tensorInfo) + { + uint32_t size = checkTensor.GetSize(); + uint32_t ubSize = static_cast(check::GetHardWarebufferSize(static_cast(HardWareIndex::UB))); + ubSize = ubSize / sizeof(T); + + ASCENDC_ASSERT(( (size > 0 && size < ubSize) || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, + "[%s] Failed to check tensor size of %s, current tensor size is %u, should be Greater than 0 and " + "Less than the hardware memory size.", apiName, tensorInfo, size); }); + + if constexpr (HighLevelAPIParametersPrint) { + PrintTensorSize(checkTensor, tensorInfo); + } + } + + template + __aicore__ inline void PrintTensorSize(const LocalTensor &checkTensor, __gm__ const char *tensorInfo) + { + KERNEL_LOG(KERNEL_INFO, "[%s] The size of %s is %u.", apiName, tensorInfo, checkTensor.GetSize()); + } + + template + __aicore__ inline void TensorPhyAddrAllTensorLoopCheck(T tensorTuple, U tensorStringTuple, Std::index_sequence) + { + (TensorPhyAddrOneTensorCheck(Std::get(tensorTuple), Std::get(tensorStringTuple)), ...); + } + + template + __aicore__ inline void TensorPhyAddrOneTensorCheck(const LocalTensor &checkTensor, __gm__ const char *tensorInfo) + { + uint64_t phyAddr = static_cast(reinterpret_cast(checkTensor.GetPhyAddr())); + uint64_t baseAddr = GetBaseAddr(static_cast(checkTensor.GetPosition())); + uint64_t tensorAddr = phyAddr - baseAddr; + + ASCENDC_ASSERT((tensorAddr % ONE_BLK_SIZE == 0 || HighLevelAPIParametersPrint), + { KERNEL_LOG(KERNEL_ERROR, "[%s] Failed to check %s physical address, " + "address must be 32-byte aligned, current physical address is %u.", apiName, tensorInfo, phyAddr); }); + + if constexpr (HighLevelAPIParametersPrint) { + PrintTensorPhyAddr(checkTensor, tensorInfo); + } + } + + template + __aicore__ inline void PrintTensorPhyAddr(const LocalTensor &checkTensor, __gm__ const char *tensorInfo) + { + KERNEL_LOG(KERNEL_INFO, "[%s] The physical address of %s is %u.", apiName, tensorInfo, checkTensor.GetPhyAddr()); + } + + __aicore__ inline uint64_t GetBaseAddr(int8_t logicPos) + { +#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1 + return static_cast(reinterpret_cast(GetBaseAddrCpu(logicPos))); +#else + return static_cast(0); +#endif + } + +private: + __gm__ const char *apiName = NULL; +}; + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_BASIC_CHECK_SINGLE_TENSOR_CHECK_H_ diff --git a/impl/api_check/kernel_check/reduce/mean/mean_check.h b/impl/api_check/kernel_check/reduce/mean/mean_check.h new file mode 100644 index 0000000000000000000000000000000000000000..200410f94f445d7b8f04c13e04c44eaebb0ac2ad --- /dev/null +++ b/impl/api_check/kernel_check/reduce/mean/mean_check.h @@ -0,0 +1,38 @@ + +/** + * Copyright (c) 2025 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 mean_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_MEAN_MEAN_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_MEAN_MEAN_CHECK_H_ + +#include "lib/reduce/mean_utils.h" +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "mean_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "mean_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { +template +__aicore__ inline void CheckFuncMean(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const MeanParams& meanParams, uint32_t tmpBufferSize) +{ + CheckFuncClassMean checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, meanParams, tmpBufferSize); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_MEAN_MEAN_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/mean/mean_check_c310.h b/impl/api_check/kernel_check/reduce/mean/mean_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..82ffaaf65d9fbe98aeb8dc975512c1c2dfd8ffe1 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/mean/mean_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 mean_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_MEAN_MEAN_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_MEAN_MEAN_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassMean { +public: + __aicore__ inline CheckFuncClassMean() {}; + __aicore__ inline CheckFuncClassMean(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_MEAN_MEAN_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/mean/mean_check_common.h b/impl/api_check/kernel_check/reduce/mean/mean_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..4af53a44ab7cb30e8ced4d8beab70392bd9cc20f --- /dev/null +++ b/impl/api_check/kernel_check/reduce/mean/mean_check_common.h @@ -0,0 +1,140 @@ +/** + * Copyright (c) 2025 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 mean_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_MEAN_MEAN_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_MEAN_MEAN_CHECK_COMMON_H_ + +#include "../reduce_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class MeanParamsCheck { +public: + __aicore__ inline MeanParamsCheck(__gm__ const char *apiName) { + this->apiName = apiName; + }; + + template + __aicore__ inline void CheckMeanParamsMeanParams(const MeanParams& meanParams) { + ASCENDC_ASSERT(((meanParams.outter != 0) || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, "[%s] MeanParams.outter can't be zero!", this->apiName); }); + ASCENDC_ASSERT(((meanParams.inner != 0) || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, "[%s] MeanParams.inner can't be zero!", this->apiName); }); + ASCENDC_ASSERT(((meanParams.inner * sizeof(T) % ONE_BLK_SIZE == 0) || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] MeanParams.inner must be 32B aligned, but the actual value is %u!", this->apiName, meanParams.inner); }); + bool ans = ((meanParams.n >= 1) && (meanParams.n <= meanParams.inner)); + ASCENDC_ASSERT( + (ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] MeanParams.n must be greater than or equal to 1 and less than or equal to MeanParams.inner, but actual only %u!", + this->apiName, meanParams.n); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter MeanParams.outter is %u!", apiName, meanParams.outter); + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter MeanParams.inner is %u!", apiName, meanParams.inner); + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter MeanParams.n is %u!", apiName, meanParams.n); + } + } + + template + __aicore__ inline void CheckMeanParamsSrcTensorSize(const LocalTensor& srcTensor, const MeanParams& meanParams) { + bool ans = srcTensor.GetSize() >= meanParams.outter * meanParams.inner; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, "[%s] srcTensor size should be greater than or equal to %u, but actual only %u!", + this->apiName, meanParams.outter * meanParams.inner, srcTensor.GetSize()); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter srcTensor size is %u!", apiName, srcTensor.GetSize()); + } + } + + template + __aicore__ inline void CheckMeanParamsDstTensorSize(const LocalTensor& dstTensor, const MeanParams& meanParams) { + uint32_t dstNeedSize = (meanParams.outter * sizeof(T) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE / sizeof(T); + uint32_t dstCurSize = dstTensor.GetSize(); + bool ans = dstCurSize >= dstNeedSize; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, "[%s] dstTensor size should be greater than or equal to %u, but actual only %u!", + this->apiName, dstNeedSize, dstCurSize); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter dstTensor size is %u!", apiName, dstTensor.GetSize()); + } + } + + __aicore__ inline void CheckMeanParamsTmpBufferSize(const LocalTensor& sharedTmpBuffer, uint32_t tmpBufferSize) { + bool ans = sharedTmpBuffer.GetSize() >= tmpBufferSize; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, + "[%s] sharedTmpBuffer size should be greater than or equal to %u, but actual only %u!", + this->apiName, tmpBufferSize, sharedTmpBuffer.GetSize()); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter sharedTmpBuffer size is %u!", apiName, sharedTmpBuffer.GetSize()); + } + } + + template + __aicore__ inline void CheckMeanParamsBasicBlock(const bool isBasicBlock, __gm__ const char* paraName) { + if ((!isConfigurable && isBasicBlock == true) || HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_WARN, "[%s] The parameter %s is true, may not be effective.", apiName, paraName); + } + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter %s is %u!", apiName, paraName, isBasicBlock); + } + } + + template + __aicore__ inline void CheckMeanParamsReduceDim(const int32_t reduceDim, __gm__ const char* paraName) { + if ((!isConfigurable && reduceDim != -1) || HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_WARN, "[%s] The parameter %s is %u, may not be effective.", apiName, paraName, reduceDim); + } + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter %s is %u!", apiName, paraName, reduceDim); + } + } + +private: + __gm__ const char *apiName = nullptr; +}; + +template +class CheckFuncClassMean : public CheckFuncClassReduceBase { +public: + __aicore__ inline CheckFuncClassMean() {}; + __aicore__ inline CheckFuncClassMean(__gm__ const char *apiName) : CheckFuncClassReduceBase(apiName), meanParamsCheck(apiName) { + }; + + public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const MeanParams& meanParams, uint32_t tmpBufferSize) { + DataTypeCheckFuncBasicClass::DataTypeVerifyingParameters, Std::tuple, Std::tuple, Std::tuple>( + "input template parameter (T, accType) is not (half, float) or (half, half) or (float, float)!" + ); + ReuseSourceCheckFuncBasicClass::IsReuseSourceVerifyingParameters(ARG_AND_STRING(isReuseSource)); + this->meanParamsCheck.template CheckMeanParamsMeanParams(meanParams); + this->meanParamsCheck.template CheckMeanParamsSrcTensorSize(srcTensor, meanParams); + this->meanParamsCheck.template CheckMeanParamsDstTensorSize(dstTensor, meanParams); + this->meanParamsCheck.CheckMeanParamsTmpBufferSize(sharedTmpBuffer, tmpBufferSize); + this->meanParamsCheck.CheckMeanParamsBasicBlock(ARG_AND_STRING(isBasicBlock)); + this->meanParamsCheck.CheckMeanParamsReduceDim(ARG_AND_STRING(reduceDim)); + + SingleTensorCheckFuncBasicClass::TPositionVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer), + VA_ARGS_TO_MAKE_TUPLE_STRING(TPosition::VECIN, TPosition::VECOUT, TPosition::VECCALC)); + + SingleTensorCheckFuncBasicClass::TensorSizeVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer)); + + MultipleTensorCheckFuncBasicClass::TensorReuseVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer)); + }; +private: + MeanParamsCheck meanParamsCheck; +}; +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_MEAN_MEAN_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check.h b/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check.h new file mode 100644 index 0000000000000000000000000000000000000000..1f30f05a680d3ca5de4d175458ed1a6fe8b348e6 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check.h @@ -0,0 +1,37 @@ + +/** + * Copyright (c) 2025 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 reduce_all_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ALL_REDUCE_ALL_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ALL_REDUCE_ALL_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_all_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_all_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { +template +__aicore__ inline void CheckFuncReduceAll(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceAll checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ALL_REDUCE_ALL_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..eea4aba96258a1c7a76458bd9df01614c55fd0a4 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_all_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_ALL_REDUCE_ALL_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_ALL_REDUCE_ALL_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceAll { +public: + __aicore__ inline CheckFuncClassReduceAll() {}; + __aicore__ inline CheckFuncClassReduceAll(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_ALL_REDUCE_ALL_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check_common.h b/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..e48805cd2ef054bc4ea41d279b0f35eb86b8dc37 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_all/reduce_all_check_common.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2025 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 reduce_all_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ALL_REDUCE_ALL_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ALL_REDUCE_ALL_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +template +class CheckFuncClassReduceAll : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceAll(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ALL_REDUCE_ALL_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check.h b/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check.h new file mode 100644 index 0000000000000000000000000000000000000000..e327c0c9827e455a3baee211486233d5969be8f0 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check.h @@ -0,0 +1,39 @@ + +/** + * Copyright (c) 2025 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 reduce_any_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ANY_REDUCE_ANY_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ANY_REDUCE_ANY_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_any_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_any_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { + +template +__aicore__ inline void CheckFuncReduceAny(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceAny checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ANY_REDUCE_ANY_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..9089673e1eeee54cbdd55cc34634d9e3db6b9961 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_any_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_ANY_REDUCE_ANY_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_ANY_REDUCE_ANY_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceAny { +public: + __aicore__ inline CheckFuncClassReduceAny() {}; + __aicore__ inline CheckFuncClassReduceAny(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_ANY_REDUCE_ANY_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check_common.h b/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..6eddf777c3b165c4997d77e6bc825ec92901cd59 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_any/reduce_any_check_common.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 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 reduce_any_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ANY_REDUCE_ANY_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ANY_REDUCE_ANY_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceAny : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceAny(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_ANY_REDUCE_ANY_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_check.h b/impl/api_check/kernel_check/reduce/reduce_check.h new file mode 100644 index 0000000000000000000000000000000000000000..62e07261e45ec6b0a6e9fa89ec1cded0d103d786 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_check.h @@ -0,0 +1,124 @@ +/** + * Copyright (c) 2025 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 reduce_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_REDUCE_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_REDUCE_CHECK_H_ + +#include "reduce_check_utils.h" +#include "../../../../lib/reduce/reduce_common.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class ReduceParamsCheck { +public: + __aicore__ inline ReduceParamsCheck(__gm__ const char *apiName) { + this->apiName = apiName; + }; + + __aicore__ inline void CheckSrcShape(const uint32_t srcShape[]) { + uint32_t firstAxis = srcShape[0]; + uint32_t lastAxis = srcShape[1]; + ASCENDC_ASSERT((((firstAxis > 0) && (lastAxis > 0) ) || HighLevelAPIParametersPrint), { + KERNEL_LOG( + KERNEL_ERROR, + "[%s] firstAxis and lastAxis must be greater than 0, current firstAxis is %u and lastAxis is %u!", apiName, + firstAxis, lastAxis); + }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter srcShape firstAxis is %u, srcShape firstAxis is %u!", apiName, firstAxis, lastAxis); + } + } + + template + __aicore__ inline void CheckSrcSize(const LocalTensor& srcTensor, const uint32_t srcShape[], const uint32_t padLast) { + uint32_t firstAxis = srcShape[0]; + uint32_t lastAxis = srcShape[1]; + ASCENDC_ASSERT(((srcTensor.GetSize() >= firstAxis * padLast) || HighLevelAPIParametersPrint), { + KERNEL_LOG( + KERNEL_ERROR, + "[%s] srcTensor size must be greater than or equal to %u, current size is %u!", apiName, + firstAxis * padLast, srcTensor.GetSize()); + }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter srcTensor is %u!", apiName, srcTensor.GetSize()); + } + } + + template + __aicore__ inline void CheckDstSize(const LocalTensor& dstTensor, const uint32_t srcShape[]) { + uint32_t firstAxis = srcShape[0]; + uint32_t lastAxis = srcShape[1]; + if constexpr (IsSameType::value) { + ASCENDC_ASSERT(((dstTensor.GetSize() >= firstAxis) || HighLevelAPIParametersPrint), { + KERNEL_LOG( + KERNEL_ERROR, + "[%s] dstTensor size must be greater than or equal to %u, current size is %u!", apiName, + firstAxis, dstTensor.GetSize()); + }); + } else { + ASCENDC_ASSERT(((dstTensor.GetSize() >= lastAxis) || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, + "[%s] dstTensor size must be greater than or equal to %u, current size is %u!", apiName, + lastAxis, dstTensor.GetSize()); + }); + } + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter dstTensor size is %u!", apiName, dstTensor.GetSize()); + } + } + + __aicore__ inline void CheckSrcInnerPad(bool srcInnerPad) { + ASCENDC_ASSERT((srcInnerPad || HighLevelAPIParametersPrint), { KERNEL_LOG(KERNEL_ERROR, "[%s] srcInnerPad must be set to true!", apiName); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter %s is %d!", + apiName, ARG_AND_STRING(srcInnerPad), srcInnerPad); + } + } + +private: + __gm__ const char *apiName = nullptr; +}; + +template +class CheckFuncClassReduce : public CheckFuncClassReduceBase { +public: + __aicore__ inline CheckFuncClassReduce() {}; + __aicore__ inline CheckFuncClassReduce(__gm__ const char *apiName) : CheckFuncClassReduceBase(apiName), reduceParamsCheck(apiName) { + }; + + public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + this->reduceParamsCheck.CheckSrcShape(srcShape); + this->reduceParamsCheck.template CheckSrcSize(srcTensor, srcShape, padLast); + this->reduceParamsCheck.template CheckDstSize(dstTensor, srcShape); + this->reduceParamsCheck.CheckSrcInnerPad(srcInnerPad); + SingleTensorCheckFuncBasicClass::TPositionVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer), + VA_ARGS_TO_MAKE_TUPLE_STRING(TPosition::VECIN, TPosition::VECOUT, TPosition::VECCALC)); + + SingleTensorCheckFuncBasicClass::TensorSizeVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer)); + MultipleTensorCheckFuncBasicClass::TensorReuseVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer)); + }; +private: + ReduceParamsCheck reduceParamsCheck; +}; + +} // namespace HighLevelApiCheck +} // namespace AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_REDUCE_CHECK_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_check_utils.h b/impl/api_check/kernel_check/reduce/reduce_check_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..a707fed7f313df13f326a5e9dee31419fa1cf8df --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_check_utils.h @@ -0,0 +1,40 @@ +/** + * Copyright (c) 2025 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 reduce_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_REDUCE_CHECK_UTILS_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_REDUCE_CHECK_UTILS_H_ + +#include "../basic_check/datatype_check.h" +#include "../basic_check/calcount_check.h" +#include "../basic_check/reuse_source_check.h" +#include "../basic_check/single_tensor_check.h" +#include "../basic_check/multiple_tensor_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +class CheckFuncClassReduceBase : public CalCountCheckFuncBasicClass, public DataTypeCheckFuncBasicClass, + public MultipleTensorCheckFuncBasicClass, public ReuseSourceCheckFuncBasicClass, + public SingleTensorCheckFuncBasicClass { +public: + __aicore__ inline CheckFuncClassReduceBase() {}; + __aicore__ inline CheckFuncClassReduceBase(__gm__ const char *apiName) : + CalCountCheckFuncBasicClass(apiName), DataTypeCheckFuncBasicClass(apiName), + MultipleTensorCheckFuncBasicClass(apiName), ReuseSourceCheckFuncBasicClass(apiName), SingleTensorCheckFuncBasicClass(apiName) {}; +}; +} // namespace HighLevelApiCheck +} // namespace AscendC + + +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_REDUCE_CHECK_UTILS_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check.h b/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check.h new file mode 100644 index 0000000000000000000000000000000000000000..1240b2533221292c58583213c92a0432d2adb6f0 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check.h @@ -0,0 +1,38 @@ + +/** + * Copyright (c) 2025 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 reduce_max_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MAX_REDUCE_MAX_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MAX_REDUCE_MAX_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_max_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_max_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { +template +__aicore__ inline void CheckFuncReduceMax(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceMax checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MAX_REDUCE_MAX_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..bc6dfa2ba72126bffe0dfc72a59627ab0660e9a7 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_max_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MAX_REDUCE_MAX_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MAX_REDUCE_MAX_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceMax { +public: + __aicore__ inline CheckFuncClassReduceMax() {}; + __aicore__ inline CheckFuncClassReduceMax(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MAX_REDUCE_MAX_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check_common.h b/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..7e6dd272f9dc303d2140df16b5c14122255e04b8 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_max/reduce_max_check_common.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 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 reduce_max_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MAX_REDUCE_MAX_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MAX_REDUCE_MAX_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceMax : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceMax(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MAX_REDUCE_MAX_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check.h b/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check.h new file mode 100644 index 0000000000000000000000000000000000000000..ce0f1247c9f2aa549d51973a3252e00a57b3b283 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check.h @@ -0,0 +1,38 @@ + +/** + * Copyright (c) 2025 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 reduce_mean_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MEAN_REDUCE_MEAN_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MEAN_REDUCE_MEAN_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_mean_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_mean_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { +template +__aicore__ inline void CheckFuncReduceMean(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceMean checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MEAN_REDUCE_MEAN_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..997ba59a6e389aa7b8bbd7adb5ad76e1f329c50b --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_mean_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MEAN_REDUCE_MEAN_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MEAN_REDUCE_MEAN_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceMean { +public: + __aicore__ inline CheckFuncClassReduceMean() {}; + __aicore__ inline CheckFuncClassReduceMean(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MEAN_REDUCE_MEAN_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check_common.h b/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..c8f32bcd76cf42f7c5bf42fa62566bb4594634d8 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_mean/reduce_mean_check_common.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 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 reduce_mean_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MEAN_REDUCE_MEAN_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MEAN_REDUCE_MEAN_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceMean : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceMean(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MEAN_REDUCE_MEAN_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check.h b/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check.h new file mode 100644 index 0000000000000000000000000000000000000000..7a0d56ea970fb48d958a81ad1908cb6b2a7afdb5 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check.h @@ -0,0 +1,38 @@ + +/** + * Copyright (c) 2025 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 reduce_min_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MIN_REDUCE_MIN_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MIN_REDUCE_MIN_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_min_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_min_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { + +template +__aicore__ inline void CheckFuncReduceMin(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceMin checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MIN_REDUCE_MIN_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..239dac577b1d093b7e807efd6d625c789ea81ed1 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_min_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MIN_REDUCE_MIN_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MIN_REDUCE_MIN_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceMin { +public: + __aicore__ inline CheckFuncClassReduceMin() {}; + __aicore__ inline CheckFuncClassReduceMin(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_MIN_REDUCE_MIN_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check_common.h b/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..c5ef5ebf6b84ed3d90be13f014d8ae66f034d0c3 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_min/reduce_min_check_common.h @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2025 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 reduce_min_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MIN_REDUCE_MIN_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MIN_REDUCE_MIN_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceMin : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceMin(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; + +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_MIN_REDUCE_MIN_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check.h b/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check.h new file mode 100644 index 0000000000000000000000000000000000000000..9008f9afd047751d7bafcfaafde76c136ec1c16e --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check.h @@ -0,0 +1,38 @@ + +/** + * Copyright (c) 2025 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 reduce_prod_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_PROD_REDUCE_PROD_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_PROD_REDUCE_PROD_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_prod_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_prod_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { + +template +__aicore__ inline void CheckFuncReduceProd(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceProd checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_PROD_REDUCE_PROD_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..a7dd669c45150edefb1704f3cb08e00699a687d3 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_prod_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_PROD_REDUCE_PROD_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_PROD_REDUCE_PROD_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceProd { +public: + __aicore__ inline CheckFuncClassReduceProd() {}; + __aicore__ inline CheckFuncClassReduceProd(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_PROD_REDUCE_PROD_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check_common.h b/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..0b77a9b209dcbb957aba217ee9e70ab56aa775d8 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_prod/reduce_prod_check_common.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 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 reduce_prod_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_PROD_REDUCE_PROD_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_PROD_REDUCE_PROD_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceProd : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceProd(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; +} +} +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_PROD_REDUCE_PROD_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check.h b/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check.h new file mode 100644 index 0000000000000000000000000000000000000000..c8fbbf61aa83dc03c174acd387e89777756d5c5a --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check.h @@ -0,0 +1,38 @@ + +/** + * Copyright (c) 2025 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 reduce_sum_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_SUM_REDUCE_SUM_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_SUM_REDUCE_SUM_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_sum_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_sum_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { + +template +__aicore__ inline void CheckFuncReduceSum(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) +{ + CheckFuncClassReduceSum checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_SUM_REDUCE_SUM_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..482657d1a6f5061a8d154ed9a2a4409ae44a1ca9 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_sum_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_SUM_REDUCE_SUM_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_SUM_REDUCE_SUM_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceSum { +public: + __aicore__ inline CheckFuncClassReduceSum() {}; + __aicore__ inline CheckFuncClassReduceSum(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_SUM_REDUCE_SUM_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check_common.h b/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..0a667362c2bcfae814f44da7773c74dcd89cdb74 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_sum/reduce_sum_check_common.h @@ -0,0 +1,35 @@ +/** + * Copyright (c) 2025 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 reduce_sum_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_SUM_REDUCE_SUM_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_SUM_REDUCE_SUM_CHECK_COMMON_H_ + +#include "../reduce_check.h" + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceSum : public CheckFuncClassReduce { +public: + __aicore__ inline CheckFuncClassReduceSum(__gm__ const char *apiName) : CheckFuncClassReduce(apiName) {}; + + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], const bool srcInnerPad, const uint32_t padLast) { + CheckFuncClassReduce::VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast); + }; +}; +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_SUM_REDUCE_SUM_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check.h b/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check.h new file mode 100644 index 0000000000000000000000000000000000000000..d0b0c3fb71c200a26ab4c4e8117b536a9d99cb67 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check.h @@ -0,0 +1,37 @@ + +/** + * Copyright (c) 2025 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 reduce_xor_sum_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_H_ + +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "reduce_xor_sum_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "reduce_xor_sum_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { +template +__aicore__ inline void CheckFuncReduceXorSum(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& src0Tensor, const LocalTensor& src1Tensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) +{ + CheckFuncClassReduceXorSum checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check_c310.h b/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..d92f9cee77ee6a053c7c62b0cb908135ccbb2ad5 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 reduce_xor_sum_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassReduceXorSum { +public: + __aicore__ inline CheckFuncClassReduceXorSum() {}; + __aicore__ inline CheckFuncClassReduceXorSum(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check_common.h b/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..b21fbbab4b01db59b1f04650786ce27144641975 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/reduce_xor_sum/reduce_xor_sum_check_common.h @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2025 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 reduce_xor_sum_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_COMMON_H_ + +#include "../reduce_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { +class CheckReduceXorSumParams { +public: + __aicore__ inline CheckReduceXorSumParams(__gm__ const char *apiName) { + this->apiName = apiName; + }; + template + __aicore__ inline void CheckTensorSize(const LocalTensor& src0Tensor, const LocalTensor& src1Tensor) { + ASCENDC_ASSERT(((src0Tensor.GetSize() == src1Tensor.GetSize()) || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] src0Tensor size is %u, src1Tensor size is %u, src0Tensor size must " + "equal src1Tensor size!", this->apiName, src0Tensor.GetSize(), src1Tensor.GetSize()); + }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter src0Tensor size is %u!", apiName, src0Tensor.GetSize()); + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter src1Tensor size is %u!", apiName, src1Tensor.GetSize()); + } + } +private: + __gm__ const char *apiName = nullptr; +}; + +template +class CheckFuncClassReduceXorSum : public CheckFuncClassReduceBase { +public: + __aicore__ inline CheckFuncClassReduceXorSum() {}; + __aicore__ inline CheckFuncClassReduceXorSum(__gm__ const char *apiName) : CheckFuncClassReduceBase(apiName), checkReduceXorSumParams(apiName) { + }; + + public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& src0Tensor, const LocalTensor& src1Tensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) { + this->checkReduceXorSumParams.template CheckTensorSize(src0Tensor, src1Tensor); + CalCountCheckFuncBasicClass::CalCountVerifyingParameters(ARG_AND_STRING(calCount), + VA_ARGS_TO_MAKE_TUPLE(src0Tensor, src1Tensor)); + + SingleTensorCheckFuncBasicClass::TPositionVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer), + VA_ARGS_TO_MAKE_TUPLE_STRING(TPosition::VECIN, TPosition::VECOUT, TPosition::VECCALC)); + + SingleTensorCheckFuncBasicClass::TensorSizeVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer)); + + MultipleTensorCheckFuncBasicClass::TensorReuseVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, src0Tensor, sharedTmpBuffer)); + + MultipleTensorCheckFuncBasicClass::TensorReuseVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, src1Tensor, sharedTmpBuffer)); + }; +private: + CheckReduceXorSumParams checkReduceXorSumParams; +}; +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_REDUCE_XOR_SUM_REDUCE_XOR_SUM_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/api_check/kernel_check/reduce/sum/sum_check.h b/impl/api_check/kernel_check/reduce/sum/sum_check.h new file mode 100644 index 0000000000000000000000000000000000000000..f7a513c04c107a38628c6ed5b6a693f4de2fbe04 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/sum/sum_check.h @@ -0,0 +1,39 @@ + +/** + * Copyright (c) 2025 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 sum_check.h + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_SUM_SUM_CHECK_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_SUM_SUM_CHECK_H_ + +#include "lib/reduce/sum_utils.h" +#if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 200 || __CCE_AICORE__ == 220) +#include "sum_check_common.h" +#else if defined(__DAV_C310__) || defined(__DAV_310R6__) +#include "sum_check_c310.h" +#endif + +namespace AscendC { +namespace HighLevelApiCheck { + +template +__aicore__ inline void CheckFuncSum(__gm__ const char *apiName, const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const SumParams &sumParams) +{ + CheckFuncClassSum checkFun(apiName); + checkFun.VerifyingParameters(dstTensor, srcTensor, sharedTmpBuffer, sumParams); +} +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_SUM_SUM_CHECK_H_ + diff --git a/impl/api_check/kernel_check/reduce/sum/sum_check_c310.h b/impl/api_check/kernel_check/reduce/sum/sum_check_c310.h new file mode 100644 index 0000000000000000000000000000000000000000..814905397f30e8b0d11f1241447dda149660e438 --- /dev/null +++ b/impl/api_check/kernel_check/reduce/sum/sum_check_c310.h @@ -0,0 +1,33 @@ +/** +* Copyright (c) 2025 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 sum_check_c310.h +* \brief +*/ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_MATH_SUM_SUM_CHECK_310_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_MATH_SUM_SUM_CHECK_310_H_ + +namespace AscendC { +namespace HighLevelApiCheck { +template +class CheckFuncClassSum { +public: + __aicore__ inline CheckFuncClassSum() {}; + __aicore__ inline CheckFuncClassSum(__gm__ const char *apiName) {}; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t calCount) {}; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_MATH_SUM_SUM_CHECK_310_H_ diff --git a/impl/api_check/kernel_check/reduce/sum/sum_check_common.h b/impl/api_check/kernel_check/reduce/sum/sum_check_common.h new file mode 100644 index 0000000000000000000000000000000000000000..48641033fe332dab46652ea9fc7d054593e165eb --- /dev/null +++ b/impl/api_check/kernel_check/reduce/sum/sum_check_common.h @@ -0,0 +1,156 @@ +/** + * Copyright (c) 2025 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 sum_check + * \brief + */ +#ifndef IMPL_API_CHECK_KERNEL_CHECK_REDUCE_SUM_SUM_CHECK_COMMON_H_ +#define IMPL_API_CHECK_KERNEL_CHECK_REDUCE_SUM_SUM_CHECK_COMMON_H_ + +#include "../reduce_check_utils.h" + +namespace AscendC { +namespace HighLevelApiCheck { + +class CheckSumParams { +public: + __aicore__ inline CheckSumParams(__gm__ const char *apiName) { + this->apiName = apiName; + }; + + template + __aicore__ inline void CheckSumParamsSumParams(const LocalTensor& srcTensor, const SumParams &sumParams) { + bool ans = sumParams.inner != 0 && (sumParams.inner * sizeof(T) % ONE_BLK_SIZE == 0); + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] SumParams.inner must be 32B aligned and must be greater than 0, current inner is %u!", + this->apiName, sumParams.inner); }); + ans = (sumParams.inner <= srcTensor.GetSize()); + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] SumParams.inner is %u must be less than or equal to srcTensor size, srcTensor size is %u", + this->apiName, sumParams.inner, srcTensor.GetSize()); }); + ans = ((sumParams.n >= 1) && (sumParams.n <= sumParams.inner)); + ASCENDC_ASSERT( + (ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] SumParams.n must be greater than or equal to 1 and less than or equal to SumParams.inner, but actual only %u", + this->apiName, sumParams.n); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter SumParams.outter is %u!", apiName, sumParams.outter); + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter SumParams.inner is %u!", apiName, sumParams.inner); + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter SumParams.n is %u!", apiName, sumParams.n); + } + } + + template + __aicore__ inline void CheckSumParamsDstTensorSize(const LocalTensor& dstTensor, const SumParams &sumParams) { + bool ans = dstTensor.GetSize() > 0; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] dstTensor size must be greater than 0, but actual only %u", this->apiName, dstTensor.GetSize()); }); + uint32_t dstNeedSize = (sumParams.outter * sizeof(T) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE / sizeof(T); + uint32_t dstCurSize = dstTensor.GetSize(); + ans = dstCurSize >= dstNeedSize; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] dstTensor size should be greater than or equal to %u, but actual only %u!", + this->apiName, dstNeedSize, dstCurSize); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter dstTensor size is %u!", apiName, dstTensor.GetSize()); + } + } + + template + __aicore__ inline void CheckSumParamsSrcTensorSize(const LocalTensor& srcTensor) { + bool ans = srcTensor.GetSize() > 0; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] srcTensor size must be greater than 0, but actual only %u", this->apiName, srcTensor.GetSize()); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter srcTensor size is %u!", apiName, srcTensor.GetSize()); + } + } + + template + __aicore__ inline void CheckSumParamsTmpBufferSize(const LocalTensor& sharedTmpBuffer, const SumParams &sumParams) { + uint32_t elementNumPerBlk = ONE_BLK_SIZE / sizeof(T); + uint32_t elementNumPerRep = ONE_REPEAT_BYTE_SIZE / sizeof(T); + uint32_t repeatTimes = (sumParams.n + elementNumPerRep - 1) / elementNumPerRep; + uint32_t finalWorkSize = (repeatTimes + elementNumPerBlk - 1) / elementNumPerBlk * elementNumPerBlk * sizeof(T); + ASCENDC_ASSERT((sharedTmpBuffer.GetSize() >= finalWorkSize || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] sharedTmpBuffer must be greater than %u!", this->apiName, finalWorkSize); }); + bool ans = sharedTmpBuffer.GetSize() > 0; + ASCENDC_ASSERT((ans || HighLevelAPIParametersPrint), { + KERNEL_LOG(KERNEL_ERROR, "[%s] sharedTmpBuffer size must be greater than 0, but actual only %u", this->apiName, sharedTmpBuffer.GetSize()); }); + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter sharedTmpBuffer size is %u!", apiName, sharedTmpBuffer.GetSize()); + } + } + + template + __aicore__ inline void CheckSumParamsBasicBlock(const bool isBasicBlock, __gm__ const char* paraName) { + if ((!isConfigurable && isBasicBlock == true) || HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_WARN, "[%s] The parameter %s is true, may not be effective.", apiName, paraName); + } + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter %s is %d!", apiName, paraName, isBasicBlock); + } + } + + template + __aicore__ inline void CheckSumParamsReduceDim(const int32_t reduceDim, __gm__ const char* paraName) { + if ((!isConfigurable && reduceDim != -1) || HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_WARN, "[%s] The parameter %s is %d, may not be effective.", apiName, paraName, reduceDim); + } + if constexpr (HighLevelAPIParametersPrint) { + KERNEL_LOG(KERNEL_INFO, "[%s] The parameter %s is %d!", apiName, paraName, reduceDim); + } + } + +private: + __gm__ const char *apiName = nullptr; +}; + + +template +class CheckFuncClassSum : public CheckFuncClassReduceBase { +public: + __aicore__ inline CheckFuncClassSum() {}; + __aicore__ inline CheckFuncClassSum(__gm__ const char *apiName) : CheckFuncClassReduceBase(apiName), checkSumParams(apiName) { + }; + +public: + __aicore__ inline void VerifyingParameters(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const SumParams &sumParams) { + DataTypeCheckFuncBasicClass::DataTypeVerifyingParameters( + "input template parameter (T) is not half or float"); + this->checkSumParams.template CheckSumParamsSumParams(srcTensor, sumParams); + this->checkSumParams.template CheckSumParamsDstTensorSize(dstTensor, sumParams); + this->checkSumParams.template CheckSumParamsSrcTensorSize(srcTensor); + this->checkSumParams.template CheckSumParamsTmpBufferSize(sharedTmpBuffer, sumParams); + + this->checkSumParams.CheckSumParamsBasicBlock(ARG_AND_STRING(isBasicBlock)); + this->checkSumParams.CheckSumParamsReduceDim(ARG_AND_STRING(reduceDim)); + ReuseSourceCheckFuncBasicClass::IsReuseSourceVerifyingParameters(ARG_AND_STRING(isReuseSource)); + + SingleTensorCheckFuncBasicClass::TPositionVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer), + VA_ARGS_TO_MAKE_TUPLE_STRING(TPosition::VECIN, TPosition::VECOUT, TPosition::VECCALC)); + + SingleTensorCheckFuncBasicClass::TensorSizeVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer)); + + MultipleTensorCheckFuncBasicClass::TensorReuseVerifyingParameters( + VA_ARGS_TO_MAKE_TUPLE(dstTensor, srcTensor, sharedTmpBuffer)); + }; +private: + CheckSumParams checkSumParams; +}; + +} // namespace HighLevelApiCheck +} // AscendC +#endif // IMPL_API_CHECK_KERNEL_CHECK_REDUCE_SUM_SUM_CHECK_COMMON_H_ + \ No newline at end of file diff --git a/impl/reduce/mean/mean_common_impl.h b/impl/reduce/mean/mean_common_impl.h index 4215ca7870a2e995e3f0e2d639517624aa3b7ee0..24a6848920deaf7aa880351b48ae4a651b02fa38 100644 --- a/impl/reduce/mean/mean_common_impl.h +++ b/impl/reduce/mean/mean_common_impl.h @@ -17,50 +17,18 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" -#if ASCENDC_CPU_DEBUG -#include "kernel_log.h" -#include -#endif +#include "lib/reduce/mean_utils.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { constexpr uint32_t HALF_NUM_PER = 128; constexpr uint32_t FLOAT_NUM_PER = 64; -struct MeanParams { - uint32_t outter = 1; - uint32_t inner; // inner = 32-byte alignment of n, inner = (n *sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) - uint32_t n; // actual length of the tensor -}; - -template -__aicore__ inline void CheckParamsIsValid(const LocalTensor& dstTensor, const LocalTensor& srcTensor, - const LocalTensor& sharedTmpBuffer, const MeanParams& meanParams, uint32_t tmpBufferSize) -{ -#if ASCENDC_CPU_DEBUG - bool ans = meanParams.outter != 0 && meanParams.inner != 0 && (meanParams.inner * sizeof(T) % ONE_BLK_SIZE == 0); - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "outter and inner can't be zero, inner must be 32B aligned"); }); - ans = ((meanParams.n >= 1) && (meanParams.n <= meanParams.inner)); - ASCENDC_ASSERT( - ans, { KERNEL_LOG(KERNEL_ERROR, "n must be greater than or equal to 1 and less than or equal to inner"); }); - ans = srcTensor.GetSize() >= meanParams.outter * meanParams.inner; - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "srcTensor size isn't enough!"); }); - ans = dstTensor.GetSize() * sizeof(T) >= - (meanParams.outter * sizeof(T) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "dstTensor size isn't enough!"); }); - ans = sharedTmpBuffer.GetSize() >= tmpBufferSize; - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "sharedTmpBuffer size isn't enough!"); }); -#endif -} __aicore__ inline void MeanCast(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const LocalTensor& sharedTmpBuffer, const MeanParams& meanParams) { uint32_t elementNumPerRep = FLOAT_NUM_PER; uint32_t repeateTimes = (meanParams.n + elementNumPerRep - 1) / elementNumPerRep; - uint32_t finalWorkSize = - meanParams.inner * sizeof(float) + (repeateTimes + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; -#if ASCENDC_CPU_DEBUG - CheckParamsIsValid(dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); -#endif const UnaryRepeatParams unaryParams; float scalarValue = static_cast(1) / static_cast(static_cast(meanParams.n)); LocalTensor TmpTensor = sharedTmpBuffer.ReinterpretCast(); @@ -116,7 +84,7 @@ __aicore__ inline void MeanForOneRepeatTime(const LocalTensor& dstTensor, con ResetMask(); } -template +template __aicore__ inline void MeanCommon(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const LocalTensor& sharedTmpBuffer, const MeanParams& meanParams) { @@ -125,10 +93,6 @@ __aicore__ inline void MeanCommon(const LocalTensor& dstTensor, const LocalTe elementNumPerRep = HALF_NUM_PER; } uint32_t repeateTimes = (meanParams.n + elementNumPerRep - 1) / elementNumPerRep; - uint32_t finalWorkSize = (repeateTimes + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; -#if ASCENDC_CPU_DEBUG - CheckParamsIsValid(dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); -#endif T scalarValue = static_cast(static_cast(1) / static_cast(static_cast(meanParams.n))); SetMaskCount(); if (repeateTimes == 1) { @@ -166,6 +130,32 @@ __aicore__ inline void MeanCommon(const LocalTensor& dstTensor, const LocalTe SetMaskNorm(); } +template +__aicore__ inline void MeanImpl(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const MeanParams& meanParams) { + uint32_t elementNumPerRep = FLOAT_NUM_PER; + if constexpr (sizeof(T) == sizeof(half) && sizeof(accType) == sizeof(float)) + { + uint32_t repeateTimes = (meanParams.n + elementNumPerRep - 1) / elementNumPerRep; + uint32_t finalWorkSize = meanParams.inner * sizeof(float) + (repeateTimes + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; + CHECK_FUNC_HIGHLEVEL_API(Mean, (T, accType, isReuseSource, isBasicBlock, reduceDim), (dstTensor, srcTensor, + sharedTmpBuffer, meanParams, finalWorkSize)); + MeanCast(dstTensor, srcTensor, sharedTmpBuffer, meanParams); + } else { + + if constexpr (sizeof(T) == sizeof(half)) { + elementNumPerRep = HALF_NUM_PER; + } + uint32_t repeateTimes = (meanParams.n + elementNumPerRep - 1) / elementNumPerRep; + uint32_t finalWorkSize = (repeateTimes + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; + + CHECK_FUNC_HIGHLEVEL_API(Mean, (T, accType, isReuseSource, isBasicBlock, reduceDim), (dstTensor, srcTensor, + sharedTmpBuffer, meanParams, finalWorkSize)); + MeanCommon(dstTensor, srcTensor, sharedTmpBuffer, meanParams); + } +} + #pragma end_pipe } // namespace AscendC diff --git a/impl/reduce/reduce_all/reduce_all_v220_impl.h b/impl/reduce/reduce_all/reduce_all_v220_impl.h index 223639d81a0d045b1dc23027e43adaff296f44a3..34f830d3d0ea108b6e1cb631f0176fec00823707 100644 --- a/impl/reduce/reduce_all/reduce_all_v220_impl.h +++ b/impl/reduce/reduce_all/reduce_all_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -23,21 +24,16 @@ __aicore__ inline void ReduceAllImpl(const LocalTensor& dstTensor, const Loca const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { - static_assert(SupportType(), - "failed to check the reduce pattern, it only supports AR/RA pattern"); - static_assert(SupportType(), - "failed to check the data type, current api supports data type is float/uint8_t"); uint32_t last = srcShape[1]; uint32_t first = srcShape[0]; constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); uint32_t padLast = AlignUp(last, elePerBlk); - CheckBinaryReduceParams(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, first, last, padLast); + static_assert(SupportType(), "failed to check the data type, current api supports data type is float/uint8_t!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceAll, (T, pattern), (dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast)); if constexpr (SupportType()) { if constexpr (IsSameType::value) { - ASCENDC_ASSERT((dstTensor.GetSize() >= first), { - KERNEL_LOG(KERNEL_ERROR, "dstTensor must be greater than or equal to %u, current size if %u", - first, dstTensor.GetSize()); - }); uint32_t splitK = 1 << FindClosestPowerOfTwo(last); if (last < elePerBlk) { splitK = 0; diff --git a/impl/reduce/reduce_any/reduce_any_v220_impl.h b/impl/reduce/reduce_any/reduce_any_v220_impl.h index b8d7f59dcc5501bd58eb617bf13897fac93125ed..a8c3b1954e9623a74b57a7e10fe018916cc449a4 100644 --- a/impl/reduce/reduce_any/reduce_any_v220_impl.h +++ b/impl/reduce/reduce_any/reduce_any_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -22,21 +23,16 @@ template __aicore__ inline void ReduceAnyImpl(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { - static_assert(SupportType(), - "failed to check the reduce pattern, it only supports AR/RA pattern"); - static_assert(SupportType(), - "failed to check the data type, current api supports data type is float/uint8_t"); uint32_t last = srcShape[1]; uint32_t first = srcShape[0]; constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); uint32_t padLast = AlignUp(last, elePerBlk); - CheckBinaryReduceParams(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, first, last, padLast); + static_assert(SupportType(), "failed to check the data type, current api supports data type is float/uint8_t!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceAny, (T, pattern), (dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast)); if constexpr (SupportType()) { if constexpr (IsSameType::value) { - ASCENDC_ASSERT((dstTensor.GetSize() >= first), { - KERNEL_LOG(KERNEL_ERROR, "dstTensor must be greater than or equal to %u, current size if %u", - first, dstTensor.GetSize()); - }); uint32_t splitK = 1 << FindClosestPowerOfTwo(last); if (last < elePerBlk) { splitK = 0; diff --git a/impl/reduce/reduce_common_util_v220_impl.h b/impl/reduce/reduce_common_util_v220_impl.h index f110b2c6c3009da62a04e07ee5dfa90235180ad4..1d2dfff9bfb8d3ac3105ad88939800318c502b7f 100644 --- a/impl/reduce/reduce_common_util_v220_impl.h +++ b/impl/reduce/reduce_common_util_v220_impl.h @@ -16,29 +16,6 @@ namespace AscendC { namespace Internal { -template -__aicore__ inline void CheckBinaryReduceParams(const LocalTensor& dstTensor, const LocalTensor& srcTensor, - const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad, uint32_t firstAxis, - uint32_t lastAxis, uint32_t padLast) -{ - CheckTensorPosition(dstTensor, "dstTensor", "VECIN, VECOUT, VECCALC"); - CheckTensorPosition(srcTensor, "srcTensor", "VECIN, VECOUT, VECCALC"); - CheckTensorPosition(sharedTmpBuffer, "sharedTmpBuffer", "VECIN, VECOUT, VECCALC"); - - ASCENDC_ASSERT((srcInnerPad), { KERNEL_LOG(KERNEL_ERROR, "srcInnerPad must be set to true!"); }); - ASCENDC_ASSERT((firstAxis > 0) && (lastAxis > 0), { - KERNEL_LOG( - KERNEL_ERROR, - "firstAxis and lastAxis must be greater than 0, firstAxis if %u and lastAxis if %u", - firstAxis, lastAxis); - }); - ASCENDC_ASSERT((srcTensor.GetSize() >= firstAxis * padLast), { - KERNEL_LOG( - KERNEL_ERROR, - "srcTensor must be greater than or equal to %u, current size if %u", - firstAxis * padLast, srcTensor.GetSize()); - }); -} template __aicore__ inline void DoReduceLessThanBlk(const LocalTensor& dstTensor, const LocalTensor& srcTensor, diff --git a/impl/reduce/reduce_max/reduce_max_v220_impl.h b/impl/reduce/reduce_max/reduce_max_v220_impl.h index a2926608445f9238d96fc974723ff2d18aadbbff..c232ed8fe0b3ee6e7df358ebed4dc5ffaaa73b6a 100644 --- a/impl/reduce/reduce_max/reduce_max_v220_impl.h +++ b/impl/reduce/reduce_max/reduce_max_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -23,17 +24,14 @@ __aicore__ inline void ReduceMaxImpl(const LocalTensor& dstTensor, const Loca const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { - static_assert(SupportType(), - "failed to check the reduce pattern, it only supports AR/RA pattern"); - static_assert(SupportType(), - "failed to check the data type, current api supports data type is float/half"); uint32_t last = srcShape[1]; uint32_t first = srcShape[0]; constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); uint32_t padLast = AlignUp(last, elePerBlk); - - CheckBinaryReduceParams(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, first, last, padLast); - + static_assert(SupportType(), "failed to check the data type, current api supports data type is half/float!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceMax, (T, pattern), (dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast)); LocalTensor tmpTensor = sharedTmpBuffer.ReinterpretCast(); if constexpr (IsSameType::value) { diff --git a/impl/reduce/reduce_mean/reduce_mean_v220_impl.h b/impl/reduce/reduce_mean/reduce_mean_v220_impl.h index fb9fa0df94c08b25881fe0e3cfbd7d6134ff3c82..650b04475da24f4e3e2d65223b90a025b98695b8 100644 --- a/impl/reduce/reduce_mean/reduce_mean_v220_impl.h +++ b/impl/reduce/reduce_mean/reduce_mean_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -22,10 +23,18 @@ template __aicore__ inline void ReduceMeanImpl(const LocalTensor& dstTensor, const LocalTensor& srcTensor, const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { - ReduceSumImpl(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad); - SetMaskCount(); uint32_t last = srcShape[1]; uint32_t first = srcShape[0]; + constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); + uint32_t padLast = AlignUp(last, elePerBlk); + static_assert(SupportType(), "failed to check the data type, current api supports data type is half/float!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceMean, (T, pattern), (dstTensor, srcTensor, + sharedTmpBuffer, srcShape, srcInnerPad, padLast)); + ReduceParams reduceParams = ReduceParams(first, last, padLast, 0, 0, elePerBlk); + ReduceSumCommon(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, reduceParams); + SetMaskCount(); UnaryRepeatParams defaultUnaryParam; if constexpr (IsSameType::value) { float lastAxisValReciprocal = 1.0f/static_cast(last); diff --git a/impl/reduce/reduce_min/reduce_min_v220_impl.h b/impl/reduce/reduce_min/reduce_min_v220_impl.h index 3bcaedafa522f735e1cbf4a534cade98aa5ad52c..baff6d7e408b280534b3efa20b191eca082f0605 100644 --- a/impl/reduce/reduce_min/reduce_min_v220_impl.h +++ b/impl/reduce/reduce_min/reduce_min_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -23,16 +24,14 @@ __aicore__ inline void ReduceMinImpl(const LocalTensor& dstTensor, const Loca const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { - static_assert(SupportType(), - "failed to check the reduce pattern, it only supports AR/RA pattern"); - static_assert(SupportType(), - "failed to check the data type, current api supports data type is float/half"); uint32_t last = srcShape[1]; uint32_t first = srcShape[0]; constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); uint32_t padLast = AlignUp(last, elePerBlk); - - CheckBinaryReduceParams(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, first, last, padLast); + static_assert(SupportType(), "failed to check the data type, current api supports data type is half/float!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceMin, (T, pattern), (dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast)); LocalTensor tmpTensor = sharedTmpBuffer.ReinterpretCast(); diff --git a/impl/reduce/reduce_prod/reduce_prod_v220_impl.h b/impl/reduce/reduce_prod/reduce_prod_v220_impl.h index 125f618a98f5e65feda2ee4697f0611f719bc628..a112ea2ced69556a0340a3b754717bfacb35560f 100644 --- a/impl/reduce/reduce_prod/reduce_prod_v220_impl.h +++ b/impl/reduce/reduce_prod/reduce_prod_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -121,31 +122,24 @@ __aicore__ inline void ReduceProdByLastAxis(const LocalTensor& dst, const Loc } template -__aicore__ inline void ReduceProdImpl(const LocalTensor& dst, const LocalTensor& src, - const LocalTensor& tmp, const uint32_t srcShape[], +__aicore__ inline void ReduceProdImpl(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { - static_assert(SupportType(), - "failed to check the reduce pattern, it only supports AR/RA pattern"); - static_assert(SupportType(), "failed to check the data type, current api supports data type is float"); - uint32_t last = srcShape[1]; uint32_t first = srcShape[0]; constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); uint32_t padLast = AlignUp(last, elePerBlk); - CheckBinaryReduceParams(dst, src, tmp, srcShape, srcInnerPad, first, last, padLast); - LocalTensor tmpDst = tmp.ReinterpretCast(); + static_assert(SupportType(), "failed to check the data type, current api supports data type is float!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceProd, (T, pattern), (dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast)); + LocalTensor tmpDst = sharedTmpBuffer.ReinterpretCast(); if constexpr (IsSameType::value) { - ASCENDC_ASSERT((dst.GetSize() >= first), { - KERNEL_LOG( - KERNEL_ERROR, - "dstTensor must be greater than or equal to %u, current size if %u", - first, dst.GetSize()); - }); - ReduceProdByLastAxis(dst, src,tmpDst, first, last, padLast); + ReduceProdByLastAxis(dstTensor, srcTensor,tmpDst, first, last, padLast); } else { BinaryReduceByFirstAxis>( - dst, src, tmpDst, first, last, padLast); + dstTensor, srcTensor, tmpDst, first, last, padLast); } SetMaskNorm(); ResetMask(); diff --git a/impl/reduce/reduce_sum/reduce_sum_v220_impl.h b/impl/reduce/reduce_sum/reduce_sum_v220_impl.h index 75890b67bd6874eeb1f04ae4e7d606382513d9fa..c96d2c2ce99566d3b26fffed3049960fde4bfd03 100644 --- a/impl/reduce/reduce_sum/reduce_sum_v220_impl.h +++ b/impl/reduce/reduce_sum/reduce_sum_v220_impl.h @@ -15,6 +15,7 @@ #include "kernel_tiling/kernel_tiling.h" #include "../reduce_common_util_v220_impl.h" #include "../../common/check.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { namespace Internal { @@ -229,17 +230,13 @@ __aicore__ inline void ReduceSumArUnReusedSrc(const LocalTensor& dst, const L } template -__aicore__ inline void ReduceSumImpl(const LocalTensor& dstTensor, const LocalTensor& srcTensor, - const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) +__aicore__ inline void ReduceSumCommon(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad, const ReduceParams &reduceParams) { - static_assert(SupportType(), - "failed to check the reduce pattern, it only supports AR/RA pattern"); - static_assert(SupportType(), "failed to check the data type, current api supports data type is float"); - uint32_t last = srcShape[1]; - uint32_t first = srcShape[0]; - constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); - uint32_t padLast = AlignUp(last, elePerBlk); - CheckBinaryReduceParams(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, first, last, padLast); + uint32_t first = reduceParams.first; + uint32_t last = reduceParams.last; + uint32_t padLast = reduceParams.padLast; + uint32_t elePerBlk = reduceParams.elePerBlk; LocalTensor tmpBuf = sharedTmpBuffer.ReinterpretCast(); if constexpr (IsSameType::value) { ASCENDC_ASSERT((dstTensor.GetSize() >= first), { @@ -269,6 +266,22 @@ __aicore__ inline void ReduceSumImpl(const LocalTensor& dstTensor, const Loca dstTensor, srcTensor, tmpBuf, first, last, padLast); } } + +template +__aicore__ inline void ReduceSumImpl(const LocalTensor& dstTensor, const LocalTensor& srcTensor, + const LocalTensor& sharedTmpBuffer, const uint32_t srcShape[], bool srcInnerPad) { + uint32_t last = srcShape[1]; + uint32_t first = srcShape[0]; + constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); + uint32_t padLast = AlignUp(last, elePerBlk); + static_assert(SupportType(), "failed to check the data type, current api supports data type is float!"); + static_assert(SupportType(), + "failed to check the reduce pattern, it only supports AR/RA pattern!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceSum, (T, pattern), (dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, padLast)); + ReduceParams reduceParams = ReduceParams(first, last, padLast, 0, 0, elePerBlk); + ReduceSumCommon(dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, reduceParams); +} + } // namespace Internal } // namespace AscendC #endif // IMPL_REDUCE_REDUCE_SUM_REDUCE_SUM_V220_IMPL_H \ No newline at end of file diff --git a/impl/reduce/reduce_xor_sum/reduce_xor_sum_common_impl.h b/impl/reduce/reduce_xor_sum/reduce_xor_sum_common_impl.h index 0c0cb865aab8bc703bc3b3cb4274dcc6fe8d3acf..eed546d18bd4427ce7091272d47fa42d179b5087 100644 --- a/impl/reduce/reduce_xor_sum/reduce_xor_sum_common_impl.h +++ b/impl/reduce/reduce_xor_sum/reduce_xor_sum_common_impl.h @@ -18,6 +18,7 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" #include "kernel_tiling/kernel_tiling.h" +#include "../../api_check/kernel_api_check.h" #if defined(__CCE_AICORE__) && (__CCE_AICORE__ == 220) #include "reduce_xor_sum_v220_impl.h" @@ -70,9 +71,9 @@ template __aicore__ inline void ReduceXorSumCompute(LocalTensor& dst, const LocalTensor& src0, const LocalTensor& src1, LocalTensor& tmp, const uint32_t calCount) { -#if ASCENDC_CPU_DEBUG - ReduceXorSumCheckParams(dst, src0, src1, calCount); -#endif + static_assert(std::is_same::value, "ReduceXorSum only support int16_t data type on current device!"); + CHECK_FUNC_HIGHLEVEL_API(ReduceXorSum, (T, isReuseSource), (dst, src0, src1, + tmp, calCount)); uint32_t splitSize = 0; ReduceXorSumParam param; diff --git a/impl/reduce/sum/sum_common_impl.h b/impl/reduce/sum/sum_common_impl.h index 0f9205511d25d3f4c1032ca521004caad9411bb2..4df25d239cdba86467c626287613f6c3ad52a1aa 100644 --- a/impl/reduce/sum/sum_common_impl.h +++ b/impl/reduce/sum/sum_common_impl.h @@ -17,38 +17,9 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" -#if ASCENDC_CPU_DEBUG -#include "kernel_log.h" -#include -#endif +#include "lib/reduce/sum_utils.h" +#include "../../api_check/kernel_api_check.h" namespace AscendC { -struct SumParams { - uint32_t outter = 1; - uint32_t inner; // inner = 32-byte alignment of n, inner = (n *sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) - uint32_t n; // actual length of the tensor -}; - -template -__aicore__ inline void CheckParamsIsValid(const LocalTensor &dstTensor, const LocalTensor &srcTensor, - const LocalTensor &sharedTmpBuffer, const SumParams &sumParams) -{ -#if ASCENDC_CPU_DEBUG - bool ans = dstTensor.GetSize() > 0 && srcTensor.GetSize() > 0 && sharedTmpBuffer.GetSize() > 0; - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "LocalTensor size must be greater than 0!"); }); - ans = sumParams.inner != 0 && (sumParams.inner * sizeof(T) % ONE_BLK_SIZE == 0); - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "inner must be 32B aligned"); }); - ans = (sumParams.inner <= srcTensor.GetSize()); - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "inner must be less than or equal to src tensor"); }); - ans = ((sumParams.n >= 1) && (sumParams.n <= sumParams.inner)); - ASCENDC_ASSERT( - ans, { KERNEL_LOG(KERNEL_ERROR, "n must be greater than or equal to 1 and less than or equal to inner"); }); - ans = dstTensor.GetSize() * sizeof(T) >= - (sumParams.outter * sizeof(T) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "dstTensor size isn't enough!"); }); - ans = (std::is_same::value) || (std::is_same::value); - ASCENDC_ASSERT(ans, { KERNEL_LOG(KERNEL_ERROR, "type must be half or float"); }); -#endif -} template __aicore__ inline void SumForOneRepeatTime( @@ -70,7 +41,7 @@ __aicore__ inline void SumCompute(const LocalTensor &dstTensor, const LocalTe if ASCEND_IS_AIC { return; } - CheckParamsIsValid(dstTensor, srcTensor, sharedTmpBuffer, sumParams); + CHECK_FUNC_HIGHLEVEL_API(Sum, (T, reduceDim, isReuseSource, isBasicBlock), (dstTensor, srcTensor, sharedTmpBuffer, sumParams)); #if __CCE_AICORE__ >= 200 uint32_t elementNumPerRep = ONE_REPEAT_BYTE_SIZE / sizeof(T); uint32_t elementNumPerBlk = ONE_BLK_SIZE / sizeof(T); diff --git a/lib/reduce/mean.h b/lib/reduce/mean.h index 914ce78387cbe8ca5f2471e4e65bda0087aebb14..4960bd33c9b855644c429b5b71827a9e888a355d 100644 --- a/lib/reduce/mean.h +++ b/lib/reduce/mean.h @@ -17,6 +17,7 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" +#include "lib/reduce/mean_utils.h" #include "../../impl/reduce/mean/mean_common_impl.h" #if ASCENDC_CPU_DEBUG #include "kernel_log.h" @@ -47,20 +48,7 @@ __aicore__ inline void Mean(const LocalTensor &dstTensor, const LocalTensor::value && std::is_same::value) || - (std::is_same::value && std::is_same::value) || - (std::is_same::value && std::is_same::value)), - { KERNEL_LOG(KERNEL_ERROR, "Two conditions are supported: " - "1.T is half or float , and accType is same with T; " - "2.T is half and accType is float."); }); - if constexpr (sizeof(T) == sizeof(half) && sizeof(accType) == sizeof(float)) - { - MeanCast(dstTensor, srcTensor, sharedTmpBuffer, meanParams); - } - else - { - MeanCommon(dstTensor, srcTensor, sharedTmpBuffer, meanParams); - } + MeanImpl(dstTensor, srcTensor, sharedTmpBuffer, meanParams); } /* ! diff --git a/lib/reduce/mean_utils.h b/lib/reduce/mean_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..98ce03c5faf32092a7514aa57d1efbd378b82652 --- /dev/null +++ b/lib/reduce/mean_utils.h @@ -0,0 +1,25 @@ +/** + * 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 mean_utils.h + * \brief + */ +#ifndef LIB_REDUCE_MEAN_UTILS_H +#define LIB_REDUCE_MEAN_UTILS_H +namespace AscendC { +struct MeanParams { + uint32_t outter = 1; + uint32_t inner; // inner = 32-byte alignment of n, inner = (n * sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) + uint32_t n; // actual length of the tensor +}; + +}; // namespace AscendC +#endif // LIB_REDUCE_MEAN_UTILS_H \ No newline at end of file diff --git a/lib/reduce/reduce_xor_sum.h b/lib/reduce/reduce_xor_sum.h index 56053c7489014054bdbaf7424487df2f639d8e05..aef75518e23a0489f1931c13883f36afc0264410 100644 --- a/lib/reduce/reduce_xor_sum.h +++ b/lib/reduce/reduce_xor_sum.h @@ -49,7 +49,6 @@ __aicore__ inline void ReduceXorSum(LocalTensor& dstTensor, const LocalTensor if ASCEND_IS_AIC { return; } - static_assert(std::is_same::value, "ReduceXorSum only support int16_t data type on current device!"); ReduceXorSumCompute(dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); } @@ -73,8 +72,6 @@ __aicore__ inline void ReduceXorSum(LocalTensor& dstTensor, const LocalTensor if ASCEND_IS_AIC { return; } - static_assert(std::is_same::value, "ReduceXorSum only support int16_t data type on current device!"); - LocalTensor tmp; const bool ret = PopStackBuffer(tmp); ASCENDC_ASSERT((ret), { KERNEL_LOG(KERNEL_ERROR, "PopStackBuffer Error!"); }); diff --git a/lib/reduce/sum.h b/lib/reduce/sum.h index 840ba3fff3cc3612528ede31541517d7b6a9d2b3..4017d71d779e3d5386d5043ec4a619f53f40f153 100644 --- a/lib/reduce/sum.h +++ b/lib/reduce/sum.h @@ -17,6 +17,7 @@ #include "kernel_tensor.h" #include "kernel_operator_intf.h" +#include "lib/reduce/sum_utils.h" #include "../../impl/reduce/sum/sum_common_impl.h" #if ASCENDC_CPU_DEBUG #include "kernel_log.h" @@ -65,13 +66,6 @@ __aicore__ inline void Sum(const LocalTensor &dstTensor, const LocalTensor LocalTensor sharedTmpBuffer; bool ans = PopStackBuffer(sharedTmpBuffer); ASCENDC_ASSERT((ans), { KERNEL_LOG(KERNEL_ERROR, "PopStackBuffer Error!"); }); - uint32_t elementNumPerBlk = ONE_BLK_SIZE / sizeof(T); // half=16 float=8 - uint32_t elementNumPerRep = ONE_REPEAT_BYTE_SIZE / sizeof(T); - uint32_t repeatTimes = (sumParams.n + elementNumPerRep - 1) / elementNumPerRep; - uint32_t finalWorkSize = (repeatTimes + elementNumPerBlk - 1) / elementNumPerBlk * elementNumPerBlk * sizeof(T); - ASCENDC_ASSERT( - sharedTmpBuffer.GetSize() >= finalWorkSize, { KERNEL_LOG(KERNEL_ERROR, "tmpBuffer isn't enough!"); }); - sharedTmpBuffer.SetSize(finalWorkSize); Sum(dstTensor, srcTensor, sharedTmpBuffer, sumParams); #endif } diff --git a/lib/reduce/sum_utils.h b/lib/reduce/sum_utils.h new file mode 100644 index 0000000000000000000000000000000000000000..c17324796cd6a93a017b77b13fba4e96dc3c2a9b --- /dev/null +++ b/lib/reduce/sum_utils.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2025 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 sum_utils.h + * \brief + */ +#ifndef LIB_REDUCE_SUM_UTILS_H +#define LIB_REDUCE_SUM_UTILS_H +namespace AscendC { +struct SumParams { + uint32_t outter = 1; + uint32_t inner; // inner = 32-byte alignment of n, inner = (n * sizeof(T) + 32 - 1) / 32 * 32 / sizeof(T) + uint32_t n; // actual length of the tensor +}; + +}; // namespace AscendC +#endif // LIB_REDUCE_SUM_UTILS_H \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e1f9cd3763fd4813a21ef92eb4d2b6ca7de408c2..d98c463099ed93fd7f17986e9ff87bee752c51f9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -154,6 +154,16 @@ file(GLOB ASCENDC_TEST_ascend910B1_AIV_CASE_SRC_FILES ${ASCENDC_TESTS_DIR}/normalization/welfordfinalize/test_operator_welfordfinalize.cpp ${ASCENDC_TESTS_DIR}/utils/init_global_memory/test_operator_init_global_memory.cpp ${ASCENDC_TESTS_DIR}/normalization/layernormV2/test_operator_layernormV2.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/mean/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/sum/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_xor_sum/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_all/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_any/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_max/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_min/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_sum/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_prod/*.cpp + ${ASCENDC_TESTS_DIR}/api_check/reduce/reduce_mean/*.cpp ) # ascend910B1 aic test cases @@ -228,8 +238,10 @@ foreach(product_type ${PRODUCT_TYPE_LIST}) ${ASCENDC_TESTS_DIR}/main_global.cpp $<$:${ASCENDC_TESTS_DIR}/common/tik_pv_wrapper.cpp> $<$:${ASCENDC_TESTS_DIR}/common/tik_pv_wrapper.cpp> + $<$:${ASCENDC_TESTS_DIR}/common/api_check_stub.cpp> $<$:${ASCENDC_TESTS_DIR}/common/k3_pvwrap.cpp> $<$:${ASCENDC_TESTS_DIR}/common/k3_pvwrap.cpp> + $<$:${ASCENDC_TESTS_DIR}/common/api_check_stub.cpp> $<$:${ASCENDC_TESTS_DIR}/common/k3_pvwrap.cpp> ${ASCENDC_TEST_${product_type}_CASE_SRC_FILES} ) diff --git a/tests/api_check/reduce/mean/kernel_mean_check.cpp b/tests/api_check/reduce/mean/kernel_mean_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f5425b84006218f5ede70361235ae006b9ebe04a --- /dev/null +++ b/tests/api_check/reduce/mean/kernel_mean_check.cpp @@ -0,0 +1,401 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + +class MeanAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + + +TEST_F(MeanAPICheck, MeanAPICheckTestDataType) +{ + MeanParams meanParams = {1, 32, 2}; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(uint8_t)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(uint8_t) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + HighLevelApiCheck::CheckFuncMean< + uint8_t, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); + +} + + +TEST_F(MeanAPICheck, MeanAPICheckTestIsReuseSource) +{ + MeanParams meanParams = {1, 32, 2}; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr bool isReuseSource = true; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanOutter) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + meanParams.outter = 0; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanInnnerAlign) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + meanParams.inner = 15; + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanNSize) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + meanParams.n = 0; + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanSrcSize) +{ + MeanParams meanParams = { 2, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, (1 * meanParams.inner) * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanDstSize) +{ + MeanParams meanParams = { 9, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, 8); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanTmpSize) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, 16); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanSrcPos) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanDstPos) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanTmpPos) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + + +TEST_F(MeanAPICheck, MeanAPICheckMeanReduceDimBasicBlock) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = true; + constexpr int32_t reduceDim = -2; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", dstTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + +TEST_F(MeanAPICheck, MeanAPICheckMeanOverlap) +{ + MeanParams meanParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(meanParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, meanParams.outter * meanParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (meanParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncMean< + float, float, isReuseSource, isBasicBlock, reduceDim>( + "Mean", srcTensor, srcTensor, sharedTmpBuffer, meanParams, finalWorkSize); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + diff --git a/tests/api_check/reduce/reduce_all/kernel_reduce_all_check.cpp b/tests/api_check/reduce/reduce_all/kernel_reduce_all_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d2b252ff81b289f1c8ebd5dc5d5119d9173a1f85 --- /dev/null +++ b/tests/api_check/reduce/reduce_all/kernel_reduce_all_check.cpp @@ -0,0 +1,78 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + +class ReduceAllAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllSrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllSrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllSrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllSrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllSrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllSrcPos) +{ + CheckReduceSrcPos>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckReduceAllDstPos) +{ + CheckReduceDstPos>("ReduceAll"); +} + + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceAll"); +} + +TEST_F(ReduceAllAPICheck, ReduceAllAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceAll"); +} diff --git a/tests/api_check/reduce/reduce_any/kernel_reduce_any_check.cpp b/tests/api_check/reduce/reduce_any/kernel_reduce_any_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b129ea36e006dbc0d4811e81529bf7ef84efa601 --- /dev/null +++ b/tests/api_check/reduce/reduce_any/kernel_reduce_any_check.cpp @@ -0,0 +1,87 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + +class ReduceAnyAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnySrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnySrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnySrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnySrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnySrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnySrcPos) +{ + CheckReduceSrcPos>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckReduceAnyDstPos) +{ + CheckReduceDstPos>("ReduceAny"); + +} + + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceAny"); + +} + +TEST_F(ReduceAnyAPICheck, ReduceAnyAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceAny"); + +} diff --git a/tests/api_check/reduce/reduce_case_common.h b/tests/api_check/reduce/reduce_case_common.h new file mode 100644 index 0000000000000000000000000000000000000000..ae591ba0cad6602db21ecd19add73c56a828f6b4 --- /dev/null +++ b/tests/api_check/reduce/reduce_case_common.h @@ -0,0 +1,283 @@ +#ifndef TEST_API_CHECK_REDUCE_REDUCE_CASE_COMMON_H +#define TEST_API_CHECK_REDUCE_REDUCE_CASE_COMMON_H + +#include "lib/reduce/mean_utils.h" + +using namespace AscendC; + +template +uint32_t ComputeTmpBufSize(Params &meanParams) +{ + uint32_t elemNumPerRep = 64; + if constexpr (sizeof(T) == sizeof(half)) { + elemNumPerRep = 128; + } + uint32_t repeat = (meanParams.n + elemNumPerRep - 1) / elemNumPerRep; + uint32_t finalWorkSize = meanParams.inner * sizeof(T) + (repeat + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE; + return finalWorkSize; +} + + +template +uint32_t GetPadLast(const uint32_t srcShape[]) { + uint32_t last = srcShape[1]; + uint32_t first = srcShape[0]; + constexpr uint32_t elePerBlk = ONE_BLK_SIZE / sizeof(T); + uint32_t padLast = AlignUp(last, elePerBlk); + return padLast; +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceSrcShapeLastAxis(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + uint32_t srcShape[] = { 0, 32 }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceSrcShapeArFirstAxis(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, first * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { 64, last }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceSrcShapeRaLastAxis(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { first, 64 }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceSrcShapeSrcSize(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { 64, 32 }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceSrcInnerPad(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { first, last }; + bool srcInnerPad = false; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceSrcPos(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { first, last }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceDstPos(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { first, last }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceTmpPos(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { first, last }; + bool srcInnerPad = true; + func(apiName, dstTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +template &, const AscendC::LocalTensor&, + const AscendC::LocalTensor&, const uint32_t*, bool, uint32_t)> +void inline CheckReduceOverlap(__gm__ const char* apiName) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t first = 32; + uint32_t last = 32; + pipe.InitBuffer(inQueueX, 1, first * last * sizeof(T)); + pipe.InitBuffer(outQueueY, 1, last * sizeof(T)); + pipe.InitBuffer(tmplocalBuf, last); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = true; + uint32_t srcShape[] = { first, last }; + bool srcInnerPad = true; + func(apiName, srcTensor, srcTensor, sharedTmpBuffer, srcShape, srcInnerPad, GetPadLast(srcShape)); + inQueueX.FreeTensor(srcTensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + + +#endif // TEST_API_CHECK_REDUCE_REDUCE_CASE_COMMON_H \ No newline at end of file diff --git a/tests/api_check/reduce/reduce_max/kernel_reduce_max_check.cpp b/tests/api_check/reduce/reduce_max/kernel_reduce_max_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e1fa39fb8249715d75dc4bbf93e391fdded67afa --- /dev/null +++ b/tests/api_check/reduce/reduce_max/kernel_reduce_max_check.cpp @@ -0,0 +1,89 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + + +class ReduceMaxAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxSrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxSrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxSrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxSrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxSrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxSrcPos) +{ + CheckReduceSrcPos>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckReduceMaxDstPos) +{ + CheckReduceDstPos>("ReduceMax"); + +} + + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceMax"); + +} + +TEST_F(ReduceMaxAPICheck, ReduceMaxAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceMax"); + +} diff --git a/tests/api_check/reduce/reduce_mean/kernel_reduce_mean_check.cpp b/tests/api_check/reduce/reduce_mean/kernel_reduce_mean_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6019f11de8b262d7831323eacbaeb005a398e6c0 --- /dev/null +++ b/tests/api_check/reduce/reduce_mean/kernel_reduce_mean_check.cpp @@ -0,0 +1,88 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + + +class ReduceMeanAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanSrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanSrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanSrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanSrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanSrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanSrcPos) +{ + CheckReduceSrcPos>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckReduceMeanDstPos) +{ + CheckReduceDstPos>("ReduceMean"); + +} + + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceMean"); + +} + +TEST_F(ReduceMeanAPICheck, ReduceMeanAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceMean"); + +} diff --git a/tests/api_check/reduce/reduce_min/kernel_reduce_min_check.cpp b/tests/api_check/reduce/reduce_min/kernel_reduce_min_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5d6c06787756c6b590bfd1693bcea09feb62fcc0 --- /dev/null +++ b/tests/api_check/reduce/reduce_min/kernel_reduce_min_check.cpp @@ -0,0 +1,87 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + +class ReduceMinAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinSrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinSrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinSrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinSrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinSrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinSrcPos) +{ + CheckReduceSrcPos>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckReduceMinDstPos) +{ + CheckReduceDstPos>("ReduceMin"); + +} + + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceMin"); + +} + +TEST_F(ReduceMinAPICheck, ReduceMinAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceMin"); + +} diff --git a/tests/api_check/reduce/reduce_prod/kernel_reduce_prod_check.cpp b/tests/api_check/reduce/reduce_prod/kernel_reduce_prod_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ff7fa92da4e7e3b4c3789d98d3dce7e4b649d646 --- /dev/null +++ b/tests/api_check/reduce/reduce_prod/kernel_reduce_prod_check.cpp @@ -0,0 +1,88 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + + +class ReduceProdAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdSrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdSrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdSrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdSrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdSrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdSrcPos) +{ + CheckReduceSrcPos>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckReduceProdDstPos) +{ + CheckReduceDstPos>("ReduceProd"); + +} + + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceProd"); + +} + +TEST_F(ReduceProdAPICheck, ReduceProdAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceProd"); + +} \ No newline at end of file diff --git a/tests/api_check/reduce/reduce_sum/kernel_reduce_sum_check.cpp b/tests/api_check/reduce/reduce_sum/kernel_reduce_sum_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bb8f60997badf64ddc633f15cf5233f9fd639a6e --- /dev/null +++ b/tests/api_check/reduce/reduce_sum/kernel_reduce_sum_check.cpp @@ -0,0 +1,86 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + +class ReduceSumAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumSrcShapeLastAxis) +{ + CheckReduceSrcShapeLastAxis>("ReduceSum"); + +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumSrcShapeArFirstAxis) +{ + CheckReduceSrcShapeArFirstAxis>("ReduceSum"); + +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumSrcShapeRaLastAxis) +{ + CheckReduceSrcShapeRaLastAxis>("ReduceSum"); + +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumSrcShapeSrcSize) +{ + CheckReduceSrcShapeSrcSize>("ReduceSum"); + +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumSrcInnerPad) +{ + CheckReduceSrcInnerPad>("ReduceSum"); + +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumSrcPos) +{ + CheckReduceSrcPos>("ReduceSum"); + +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckReduceSumDstPos) +{ + CheckReduceDstPos>("ReduceSum"); + +} + + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckTmpPos) +{ + CheckReduceTmpPos>("ReduceSum"); +} + +TEST_F(ReduceSumAPICheck, ReduceSumAPICheckOverlap) +{ + CheckReduceOverlap>("ReduceSum"); + +} diff --git a/tests/api_check/reduce/reduce_xor_sum/kernel_reduce_xor_sum_check.cpp b/tests/api_check/reduce/reduce_xor_sum/kernel_reduce_xor_sum_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8e759556b18c2c7170dfb3301a90dc5fa3c08dfa --- /dev/null +++ b/tests/api_check/reduce/reduce_xor_sum/kernel_reduce_xor_sum_check.cpp @@ -0,0 +1,261 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + +class ReduceXorSumAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckReduceXorSumSrc0Src1) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, 32 * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor();; + + uint32_t calCount = 16; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckReduceXorSumSrc0CalCount) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 32; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckReduceXorSumSrc1CalCount) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 32; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckReduceXorSumSrc0Pos) +{ + + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 16; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckReduceXorSumSrc1Pos) +{ + + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 16; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckReduceXorSumDstPos) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 16; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckTmpPos) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 16; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + dstTensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(ReduceXorSumAPICheck, ReduceXorSumAPICheckOverlap) +{ + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue inQueueX2; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + uint32_t computeSize = 16; + pipe.InitBuffer(inQueueX, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(inQueueX2, 1, computeSize * sizeof(int16_t)); + pipe.InitBuffer(outQueueY, 1, 32); + pipe.InitBuffer(tmplocalBuf, computeSize); + AscendC::LocalTensor src0Tensor = inQueueX.AllocTensor(); + AscendC::LocalTensor src1Tensor = inQueueX2.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + uint32_t calCount = 16; + constexpr bool isReuseSource = false; + HighLevelApiCheck::CheckFuncReduceXorSum< + int16_t, isReuseSource>("ReduceXorSum", + src0Tensor, src0Tensor, src1Tensor, sharedTmpBuffer, calCount); + inQueueX.FreeTensor(src0Tensor); + inQueueX2.FreeTensor(src1Tensor); + outQueueY.FreeTensor(dstTensor); + tmplocalBuf.FreeTensor(sharedTmpBuffer); + EXPECT_EQ(g_api_check_res, 2); +} + + diff --git a/tests/api_check/reduce/sum/kernel_sum_check.cpp b/tests/api_check/reduce/sum/kernel_sum_check.cpp new file mode 100644 index 0000000000000000000000000000000000000000..516885a33d09580368e6102a82fb02d5e594e99e --- /dev/null +++ b/tests/api_check/reduce/sum/kernel_sum_check.cpp @@ -0,0 +1,262 @@ +/** +* 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. +*/ +#include "../../../common/api_check_stub.h" +#include "kernel_operator.h" +#include "impl/api_check/kernel_api_check.h" +#include "../reduce_case_common.h" + + +class SumAPICheck : public testing::Test { +protected: + static void SetUpTestCase() {} + static void TearDownTestCase() {} + virtual void SetUp() { + g_api_check_res = 0; + } + void TearDown() {} +}; + +TEST_F(SumAPICheck, SumAPICheckTestDataType) +{ + SumParams sumParams = {1, 32, 2}; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(uint8_t)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(uint8_t) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr int32_t reduceDim = -1; + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); + +} + + +TEST_F(SumAPICheck, SumAPICheckSumInnnerAlign) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + sumParams.inner = 15; + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(SumAPICheck, SumAPICheckSumInnner) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + sumParams.inner = 64; + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(SumAPICheck, SumAPICheckSumNSize) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + sumParams.n = 0; + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + + +TEST_F(SumAPICheck, SumAPICheckSumDstSize) +{ + SumParams sumParams = { 9, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, 8); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(SumAPICheck, SumAPICheckSumSrcPos) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(SumAPICheck, SumAPICheckSumDstPos) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(SumAPICheck, SumAPICheckSumTmpPos) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 1); +} + +TEST_F(SumAPICheck, SumAPICheckSumReduceDimBasicBlock) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = true; + constexpr int32_t reduceDim = 0; + + HighLevelApiCheck::CheckFuncSum( + "Sum", dstTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 2); +} + +TEST_F(SumAPICheck, SumAPICheckSumOverlap) +{ + SumParams sumParams = { 1, 32, 2 }; + uint32_t finalWorkSize = ComputeTmpBufSize(sumParams); + AscendC::TPipe pipe; + AscendC::TQue inQueueX; + AscendC::TQue outQueueY; + AscendC::TBuf tmplocalBuf; + pipe.InitBuffer(inQueueX, 1, sumParams.outter * sumParams.inner * sizeof(float)); + pipe.InitBuffer(outQueueY, 1, (sumParams.outter * sizeof(float) + ONE_BLK_SIZE - 1) / ONE_BLK_SIZE * ONE_BLK_SIZE); + pipe.InitBuffer(tmplocalBuf, finalWorkSize); + AscendC::LocalTensor srcTensor = inQueueX.AllocTensor(); + AscendC::LocalTensor dstTensor = outQueueY.AllocTensor(); + AscendC::LocalTensor sharedTmpBuffer = tmplocalBuf.Get(); + constexpr bool isReuseSource = false; + constexpr bool isBasicBlock = false; + constexpr int32_t reduceDim = -1; + + HighLevelApiCheck::CheckFuncSum( + "Sum", srcTensor, srcTensor, sharedTmpBuffer, sumParams); + EXPECT_EQ(g_api_check_res, 2); +} diff --git a/tests/common/api_check_stub.cpp b/tests/common/api_check_stub.cpp new file mode 100644 index 0000000000000000000000000000000000000000..026a9bb813a6e00710cdf6a80af4390c6fa90206 --- /dev/null +++ b/tests/common/api_check_stub.cpp @@ -0,0 +1,15 @@ +/** + * 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. + */ + #include + #include "kernel_log.h" + #include "api_check_stub.h" + + uint32_t g_api_check_res = 0; + \ No newline at end of file diff --git a/tests/common/api_check_stub.h b/tests/common/api_check_stub.h new file mode 100644 index 0000000000000000000000000000000000000000..a967b7ae89225426db0695ea9349f86991d11d8a --- /dev/null +++ b/tests/common/api_check_stub.h @@ -0,0 +1,31 @@ +/** +* Copyright (c) 2025 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. +*/ +#ifndef _API_CHECK_STUB_H_ +#define _API_CHECK_STUB_H_ +#include +#include "kernel_log.h" + +extern uint32_t g_api_check_res; + +#undef ASCENDC_ASSERT +#define ASCENDC_ASSERT(conf, behavior) \ + do { \ + if (!(conf)) { \ + g_api_check_res++; \ + behavior; \ + } \ + } while (0) + +#undef KERNEL_LOG_KERNEL_WARN +#define KERNEL_LOG_KERNEL_WARN(format, ...) \ + do { \ + g_api_check_res++; \ + } while (0) +#endif // _API_CHECK_STUB_H_