已合并
将asc_vf_call移到公共文件 #4733
pangfd创建于 29 天前
将asc_vf_call移到公共文件 #4733
已合并
pangfd创建于 29 天前
已删除 :master合入到cann/asc-devkitmaster
7 个文件变更+104-38
Mimpl/basic_api/kernel_utils.h+1-22
@@ -36,6 +36,7 @@
36#include "../utils/debug/asc_aicore_printf_impl.h"36#include "../utils/debug/asc_aicore_printf_impl.h"
37#endif37#endif
38 38 
39+#include "../utils/base/helpers_impl.h"
39#include "../../include/basic_api/kernel_struct_data_copy.h"40#include "../../include/basic_api/kernel_struct_data_copy.h"
40#include "kernel_scalar_convert.h"41#include "kernel_scalar_convert.h"
41#include "kernel_utils_base.h"42#include "kernel_utils_base.h"
@@ -276,28 +277,6 @@ enum class TimeStampId : uint32_t {
276 277 
277 TIME_STAMP_MAX = 0xffff,278 TIME_STAMP_MAX = 0xffff,
278};279};
279- 
280-template <auto funcPtr, typename DebugTag = Internal::SimdVfDebugTag, typename... Args>
281-__aicore__ static inline void AscVFCallImpl(Args&&... args)
282-{
283- if constexpr (Internal::SimdVfDebugTraits<DebugTag>::enabled) {
284- AscVFDebugInitUb();
285- }
286- 
287- funcPtr(args...);
288- 
289- if constexpr (Internal::SimdVfDebugTraits<DebugTag>::enabled) {
290- const bool hasOverflow = AscVFDebugTransferUb();
291-#ifdef ASCENDC_INTERNAL_SIMD_VF_OVERFLOW_WARNING_ENABLED
292- if (hasOverflow) {
293- __asc_aicore::printf_impl(
294- "[WARNING]: SIMD VF debug buffer overflow (max limit is 2KB), output was truncated.\n");
295- }
296-#else
297- (void)hasOverflow;
298-#endif
299- }
300-}
301} // namespace AscendC280} // namespace AscendC
302#endif // ASCENDC_MODULE_UTILS_H281#endif // ASCENDC_MODULE_UTILS_H
303#ifdef ASCENDC_INTERNAL_SIMD_VF_OVERFLOW_WARNING_ENABLED282#ifdef ASCENDC_INTERNAL_SIMD_VF_OVERFLOW_WARNING_ENABLED
Mimpl/utils/CMakeLists.txt+1-1
@@ -10,7 +10,7 @@
10 10 
11# copy std to highlevel_api impl11# copy std to highlevel_api impl
12install(12install(
13- DIRECTORY std debug13+ DIRECTORY std debug base
14 DESTINATION ${INSTALL_LIBRARY_DIR}/asc/impl/utils14 DESTINATION ${INSTALL_LIBRARY_DIR}/asc/impl/utils
15 ${INSTALL_OPTIONAL} COMPONENT asc-devkit FILES_MATCHING15 ${INSTALL_OPTIONAL} COMPONENT asc-devkit FILES_MATCHING
16 PATTERN "*.h"16 PATTERN "*.h"
Aimpl/utils/base/helpers_impl.h+54-0
@@ -0,0 +1,54 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+#if !defined(__ASCENDC_INCLUDE_INTERNAL_HEADERS__)
12+#warning \
13+ "impl/utils/base/helpers_impl.h is an internal header file and must not be used directly. Functions or variables defined in this file maybe removed in the future. Please use "#include "include/utils/base/helpers.h"" and use public functions or variables defined in interface headers files."
14+#define __ASCENDC_INCLUDE_INTERNAL_HEADERS__
15+#define __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_UTILS_BASE_HELPERS_H__
16+#endif
17+ 
18+#ifndef IMPL_UTILS_BASE_HELPERS_IMPL_H
19+#define IMPL_UTILS_BASE_HELPERS_IMPL_H
20+ 
21+#include "../debug/asc_debug_utils.h"
22+ 
23+namespace asc {
24+namespace details {
25+template <auto funcPtr, typename DebugTag = AscendC::Internal::SimdVfDebugTag, typename... Args>
26+__aicore__ static inline void asc_vf_call_impl(Args&&... args)
27+{
28+ if constexpr (AscendC::Internal::SimdVfDebugTraits<DebugTag>::enabled) {
29+ AscVFDebugInitUb();
30+ }
31+ 
32+ funcPtr(args...);
33+ 
34+ if constexpr (AscendC::Internal::SimdVfDebugTraits<DebugTag>::enabled) {
35+ const bool hasOverflow = AscVFDebugTransferUb();
36+#ifdef ASCENDC_INTERNAL_SIMD_VF_OVERFLOW_WARNING_ENABLED
37+ if (hasOverflow) {
38+ __asc_aicore::printf_impl(
39+ "[WARNING]: SIMD VF debug buffer overflow (max limit is 2KB), output was truncated.\n");
40+ }
41+#else
42+ (void)hasOverflow;
43+#endif
44+ }
45+}
46+} // namespace details
47+} // namespace asc
48+ 
49+#endif // IMPL_UTILS_BASE_HELPERS_IMPL_H
50+ 
51+#if defined(__UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_UTILS_BASE_HELPERS_H__)
52+#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__
53+#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_UTILS_BASE_HELPERS_H__
54+#endif
Minclude/basic_api/kernel_common.h+1-8
@@ -35,6 +35,7 @@
35#include "../../impl/basic_api/utils/kernel_utils_macros.h"35#include "../../impl/basic_api/utils/kernel_utils_macros.h"
36#include "kernel_operator_swap_mem_intf.h"36#include "kernel_operator_swap_mem_intf.h"
37#include "kernel_operator_sys_var_intf.h"37#include "kernel_operator_sys_var_intf.h"
38+#include "../utils/base/helpers.h"
38 39 
39#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 140#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
40#include <cstdint>41#include <cstdint>
@@ -50,14 +51,6 @@ template <typename T>
50class GlobalTensor;51class GlobalTensor;
51} // namespace AscendC52} // namespace AscendC
52 53 
53-template <auto funcPtr, typename... Args>
54-__aicore__ inline void asc_vf_call(Args&&... args)
55-{
56- if ASCEND_IS_AIV {
57- AscendC::AscVFCallImpl<funcPtr, AscendC::Internal::SimdVfDebugTag>(args...);
58- }
59-}
60- 
61#if __NPU_ARCH__ == 2201 || (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102)54#if __NPU_ARCH__ == 2201 || (__NPU_ARCH__ == 3510) || (__NPU_ARCH__ == 5102)
62__BLOCK_LOCAL__ __inline__ uint32_t g_super_kernel_early_start_config;55__BLOCK_LOCAL__ __inline__ uint32_t g_super_kernel_early_start_config;
63#endif56#endif
Minclude/c_api/asc_simd.h+1-0
@@ -21,6 +21,7 @@
21#define INCLUDE_C_API_ASC_SIMD_H21#define INCLUDE_C_API_ASC_SIMD_H
22 22 
23#include "impl/c_api/instr_impl/npu_arch_2201/utils_impl/utils_impl.h"23#include "impl/c_api/instr_impl/npu_arch_2201/utils_impl/utils_impl.h"
24+#include "utils/base/helpers.h"
24 25 
25#include "c_api/atomic/atomic.h"26#include "c_api/atomic/atomic.h"
26#include "c_api/cache_ctrl/cache_ctrl.h"27#include "c_api/cache_ctrl/cache_ctrl.h"
Ainclude/utils/base/helpers.h+39-0
@@ -0,0 +1,39 @@
1+/**
2+ * Copyright (c) 2026 Huawei Technologies Co., Ltd.
3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8+ * See LICENSE in the root of the software repository for the full text of the License.
9+ */
10+ 
11+/*!
12+ * \file helpers.h
13+ * \brief Provides Ascend C helper functions and service.
14+ */
15+ 
16+#if !defined(__ASCENDC_INCLUDE_INTERNAL_HEADERS__)
17+#define __ASCENDC_INCLUDE_INTERNAL_HEADERS__
18+#define __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_UTILS_BASE_HELPERS_H__
19+#endif
20+ 
21+#ifndef INCLUDE_UTILS_BASE_HELPERS_H
22+#define INCLUDE_UTILS_BASE_HELPERS_H
23+ 
24+#include "../../../impl/utils/base/helpers_impl.h"
25+ 
26+template <auto func_ptr, typename... Args>
27+__aicore__ inline void asc_vf_call(Args&&... args)
28+{
29+ if ASCEND_IS_AIV {
30+ asc::details::asc_vf_call_impl<func_ptr>(args...);
31+ }
32+}
33+ 
34+#endif // INCLUDE_UTILS_BASE_HELPERS_H
35+ 
36+#if defined(__UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_UTILS_BASE_HELPERS_H__)
37+#undef __ASCENDC_INCLUDE_INTERNAL_HEADERS__
38+#undef __UNDEF_ASCENDC_INCLUDE_INTERNAL_HEADERS_UTILS_BASE_HELPERS_H__
39+#endif
Mtests/api/basic_api/ascendc_case_common/test_kernel_vf_debug.cpp+7-7
@@ -39,23 +39,23 @@ TEST_F(TestVFDebug, AscVFDebugTransferUb_Callable)
39 SUCCEED();39 SUCCEED();
40}40}
41 41 
42-TEST_F(TestVFDebug, AscVFCallImpl_CallsTargetFunction)42+TEST_F(TestVFDebug, asc_vf_call_impl_CallsTargetFunction)
43{43{
44- // Verify AscVFCallImpl (defined in impl/basic_api/kernel_utils.h) invokes the target44+ // Verify asc_vf_call_impl invokes the target
45 // function after AscVFDebugInitUb and before AscVFDebugTransferUb.45 // function after AscVFDebugInitUb and before AscVFDebugTransferUb.
46- AscVFCallImpl<TestTargetFunc>(42);46+ asc::details::asc_vf_call_impl<TestTargetFunc>(42);
47 EXPECT_EQ(g_testFlag, 42);47 EXPECT_EQ(g_testFlag, 42);
48}48}
49 49 
50-TEST_F(TestVFDebug, AscVFCallImpl_InitAndTransferCalled)50+TEST_F(TestVFDebug, asc_vf_call_impl_InitAndTransferCalled)
51{51{
52 // Verify both AscVFDebugInitUb and AscVFDebugTransferUb (defined in52 // Verify both AscVFDebugInitUb and AscVFDebugTransferUb (defined in
53- // impl/utils/debug/asc_debug_utils.h) are callable within AscVFCallImpl.53+ // impl/utils/debug/asc_debug_utils.h) are callable within asc_vf_call_impl.
54 g_testFlag = 0;54 g_testFlag = 0;
55- AscVFCallImpl<TestTargetFunc>(100);55+ asc::details::asc_vf_call_impl<TestTargetFunc>(100);
56 EXPECT_EQ(g_testFlag, 100);56 EXPECT_EQ(g_testFlag, 100);
57 57 
58 g_testFlag = 0;58 g_testFlag = 0;
59- AscVFCallImpl<TestTargetFunc>(-1);59+ asc::details::asc_vf_call_impl<TestTargetFunc>(-1);
60 EXPECT_EQ(g_testFlag, -1);60 EXPECT_EQ(g_testFlag, -1);
61}61}