已合并
[simd_vf debug] fix debug api cpu debug compile error #4749
[simd_vf debug] fix debug api cpu debug compile error #4749
已合并
ChenZhoujie创建于 26 天前
7 个文件变更+229-2
Mimpl/utils/debug/asc_simd_dump_impl.h+61-1
@@ -15,9 +15,10 @@
15#ifndef IMPL_UTILS_DEBUG_ASC_SIMD_DUMP_IMPL_H15#ifndef IMPL_UTILS_DEBUG_ASC_SIMD_DUMP_IMPL_H
16#define IMPL_UTILS_DEBUG_ASC_SIMD_DUMP_IMPL_H16#define IMPL_UTILS_DEBUG_ASC_SIMD_DUMP_IMPL_H
17 17 
18+#include "impl/utils/sys_macros.h"
19+ 
18#ifndef ASCENDC_CPU_DEBUG20#ifndef ASCENDC_CPU_DEBUG
19 21 
20-#include "impl/utils/sys_macros.h"
21#include "impl/utils/debug/asc_debug_utils.h"22#include "impl/utils/debug/asc_debug_utils.h"
22 23 
23namespace __asc_simd_vf {24namespace __asc_simd_vf {
@@ -166,6 +167,65 @@ __simd_callee__ inline void asc_dump(__ubuf__ T* input, uint32_t desc, uint32_t
166}167}
167} // namespace __asc_simd_vf168} // namespace __asc_simd_vf
168 169 
170+#else
171+ 
172+#include <cassert>
173+ 
174+namespace __asc_simd_vf {
175+template <typename T, typename U>
176+__simd_callee__ inline void asc_dump_reg(U& input, uint32_t desc, uint32_t dump_size)
177+{
178+ (void)input;
179+ (void)desc;
180+ (void)dump_size;
181+ assert(false && "asc_dump_reg is not supported in cpu mode.");
182+}
183+ 
184+template <typename T>
185+__simd_callee__ inline void asc_dump_ubuf(__ubuf__ T* input, uint32_t desc, uint32_t dump_size)
186+{
187+ (void)input;
188+ (void)desc;
189+ (void)dump_size;
190+ assert(false && "asc_dump_ubuf is not supported in cpu mode.");
191+}
192+ 
193+template <typename T, typename U>
194+__simd_callee__ inline void asc_dump(U& input, uint32_t desc, uint32_t dump_size)
195+{
196+ (void)input;
197+ (void)desc;
198+ (void)dump_size;
199+ assert(false && "asc_dump is not supported in cpu mode.");
200+}
201+ 
202+template <typename T>
203+__simd_callee__ inline void asc_dump(__ubuf__ T* input, uint32_t desc, uint32_t dump_size)
204+{
205+ (void)input;
206+ (void)desc;
207+ (void)dump_size;
208+ assert(false && "asc_dump is not supported in cpu mode.");
209+}
210+} // namespace __asc_simd_vf
211+ 
212+#if __NPU_ARCH__ == 3510
213+namespace __asc_aicore {
214+// CPU debug exposes unqualified debug APIs through this namespace; bridge the SIMD-only register overloads.
215+template <typename T, typename U>
216+__simd_callee__ inline void asc_dump_reg(U& input, uint32_t desc, uint32_t dump_size)
217+{
218+ __asc_simd_vf::asc_dump_reg<T>(input, desc, dump_size);
219+}
220+ 
221+template <typename T, typename U>
222+__simd_callee__ inline void asc_dump(U& input, uint32_t desc, uint32_t dump_size)
223+{
224+ __asc_simd_vf::asc_dump<T>(input, desc, dump_size);
225+}
226+} // namespace __asc_aicore
227+#endif
228+ 
169#endif // ASCENDC_CPU_DEBUG229#endif // ASCENDC_CPU_DEBUG
170 230 
171#endif // IMPL_UTILS_DEBUG_ASC_SIMD_DUMP_IMPL_H231#endif // IMPL_UTILS_DEBUG_ASC_SIMD_DUMP_IMPL_H
Mimpl/utils/debug/asc_simd_printf_impl.h+24-0
@@ -16,6 +16,8 @@
16#define IMPL_UTILS_DEBUG_ASC_SIMD_PRINTF_IMPL_H16#define IMPL_UTILS_DEBUG_ASC_SIMD_PRINTF_IMPL_H
17 17 
18#include "impl/utils/sys_macros.h"18#include "impl/utils/sys_macros.h"
19+ 
20+#ifndef ASCENDC_CPU_DEBUG
19#include "impl/utils/debug/asc_debug_utils.h"21#include "impl/utils/debug/asc_debug_utils.h"
20#include "impl/utils/debug/npu_arch_3510/asc_type_conversion_utils.h"22#include "impl/utils/debug/npu_arch_3510/asc_type_conversion_utils.h"
21 23 
@@ -220,4 +222,26 @@ __simd_callee__ inline void printf(__ubuf__ const char* fmt, Args&&... args)
220}222}
221} // namespace __asc_simd_vf223} // namespace __asc_simd_vf
222 224 
225+#else
226+ 
227+#include <cstdio>
228+ 
229+namespace __asc_simd_vf {
230+template <class... Args>
231+__simd_callee__ inline void printf_impl(__ubuf__ const char* fmt, Args&&... args)
232+{
233+#if !(defined(ASCENDC_DUMP) && ASCENDC_DUMP == 0)
234+ std::printf(fmt, args...);
235+#endif
236+}
237+ 
238+template <class... Args>
239+__simd_callee__ inline void printf(__ubuf__ const char* fmt, Args&&... args)
240+{
241+ printf_impl(fmt, args...);
C
Cchentianyu1921 天前

感觉printf_impl没有存在的必要,是否可以都删除。直接printf_impl的函数移动到其中

likedislike
242+}
243+} // namespace __asc_simd_vf
244+ 
245+#endif // ASCENDC_CPU_DEBUG
246+ 
223#endif // IMPL_UTILS_DEBUG_ASC_SIMD_PRINTF_IMPL_H247#endif // IMPL_UTILS_DEBUG_ASC_SIMD_PRINTF_IMPL_H
Minclude/utils/debug/asc_printf.h+1-1
@@ -61,7 +61,7 @@ __simd_callee__ inline void printf(__ubuf__ const char* fmt, Args&&... args);
61#ifndef __NPU_COMPILER_INTERNAL_PURE_SIMT__61#ifndef __NPU_COMPILER_INTERNAL_PURE_SIMT__
62#include "impl/utils/debug/asc_aicore_printf_impl.h"62#include "impl/utils/debug/asc_aicore_printf_impl.h"
63 63 
64-#if (__NPU_ARCH__ == 3510) && !defined(ASCENDC_CPU_DEBUG)64+#if __NPU_ARCH__ == 3510
65#include "impl/utils/debug/asc_simd_printf_impl.h"65#include "impl/utils/debug/asc_simd_printf_impl.h"
66#endif66#endif
67#endif67#endif
Mtests/api/basic_api/ascendc_case_ascend950pr_9599/ascendc_case_ascend950pr_9599_aiv_basic/test_dump_tensor.cpp+48-0
@@ -12,6 +12,7 @@
12#include <mockcpp/mockcpp.hpp>12#include <mockcpp/mockcpp.hpp>
13#include <vector>13#include <vector>
14#include "kernel_operator.h"14#include "kernel_operator.h"
15+#include "utils/debug/asc_dump.h"
15 16 
16#if defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3510) && !defined(ASCENDC_CPU_DEBUG)17#if defined(__NPU_ARCH__) && (__NPU_ARCH__ == 3510) && !defined(ASCENDC_CPU_DEBUG)
17#include "impl/utils/debug/npu_arch_3510/asc_aicore_dump_utils.h"18#include "impl/utils/debug/npu_arch_3510/asc_aicore_dump_utils.h"
@@ -199,6 +200,53 @@ TEST_F(TestDumpTensorSuite, InitDumpNullStartAddrReturns)
199 EXPECT_EQ(AscendC::g_dumpWorkspaceReserved, nullptr);200 EXPECT_EQ(AscendC::g_dumpWorkspaceReserved, nullptr);
200}201}
201 202 
203+#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
204+TEST_F(TestDumpTensorSuite, SimdVfDumpCpuFallbacks)
205+{
206+ constexpr uint32_t desc = 630;
207+ constexpr uint32_t dumpSize = 1;
208+ uint32_t ubInput[1] = {0};
209+ vector_u32 regInput = {};
210+ 
211+#ifndef NDEBUG
212+ EXPECT_DEATH(asc_dump_ubuf<uint32_t>(ubInput, desc, dumpSize), "asc_dump_ubuf is not supported in cpu mode");
213+ EXPECT_DEATH(
214+ __asc_simd_vf::asc_dump_ubuf<uint32_t>(ubInput, desc, dumpSize), "asc_dump_ubuf is not supported in cpu mode");
215+ EXPECT_DEATH(asc_dump_reg<uint32_t>(regInput, desc, dumpSize), "asc_dump_reg is not supported in cpu mode");
216+ EXPECT_DEATH(
217+ __asc_simd_vf::asc_dump_reg<uint32_t>(regInput, desc, dumpSize), "asc_dump_reg is not supported in cpu mode");
218+ EXPECT_DEATH(asc_dump<uint32_t>(ubInput, desc, dumpSize), "asc_dump is not supported in cpu mode");
219+ EXPECT_DEATH(__asc_simd_vf::asc_dump<uint32_t>(ubInput, desc, dumpSize), "asc_dump is not supported in cpu mode");
220+ EXPECT_DEATH(asc_dump<uint32_t>(regInput, desc, dumpSize), "asc_dump is not supported in cpu mode");
221+ EXPECT_DEATH(__asc_simd_vf::asc_dump<uint32_t>(regInput, desc, dumpSize), "asc_dump is not supported in cpu mode");
222+#else
223+ asc_dump_ubuf<uint32_t>(ubInput, desc, dumpSize);
224+ __asc_simd_vf::asc_dump_ubuf<uint32_t>(ubInput, desc, dumpSize);
225+ asc_dump_reg<uint32_t>(regInput, desc, dumpSize);
226+ __asc_simd_vf::asc_dump_reg<uint32_t>(regInput, desc, dumpSize);
227+ asc_dump<uint32_t>(ubInput, desc, dumpSize);
228+ __asc_simd_vf::asc_dump<uint32_t>(ubInput, desc, dumpSize);
229+ asc_dump<uint32_t>(regInput, desc, dumpSize);
230+ __asc_simd_vf::asc_dump<uint32_t>(regInput, desc, dumpSize);
231+#endif
232+}
233+ 
234+TEST_F(TestDumpTensorSuite, AicoreDumpCpuFallbacksRemainAvailable)
235+{
236+ uint32_t input[1] = {0};
237+ 
238+#ifndef NDEBUG
239+ EXPECT_DEATH(__asc_aicore::asc_dump_ubuf<uint32_t>(input, 0, 1), "asc_dump_ubuf is not supported in cpu mode");
240+ EXPECT_DEATH(__asc_aicore::asc_dump<uint32_t>(input, 0, 1), "asc_dump is not supported in cpu mode");
241+ EXPECT_DEATH(asc_dump_gm<uint32_t>(input, 0, 1), "asc_dump_gm is not supported in cpu mode");
242+#else
243+ __asc_aicore::asc_dump_ubuf<uint32_t>(input, 0, 1);
244+ __asc_aicore::asc_dump<uint32_t>(input, 0, 1);
245+ asc_dump_gm<uint32_t>(input, 0, 1);
246+#endif
247+}
248+#endif
249+ 
202#if defined(ASCENDC_TEST_HAS_SIMD_VF_DUMP_POSITION)250#if defined(ASCENDC_TEST_HAS_SIMD_VF_DUMP_POSITION)
203TEST_F(TestDumpTensorSuite, AscDumpUbufWritesUbPosition)251TEST_F(TestDumpTensorSuite, AscDumpUbufWritesUbPosition)
204{252{
Mtests/api/basic_api/ascendc_case_ascend950pr_9599/ascendc_case_ascend950pr_9599_aiv_basic/test_operator_printf.cpp+17-0
@@ -12,6 +12,7 @@
12#include <mockcpp/mockcpp.hpp>12#include <mockcpp/mockcpp.hpp>
13#include <vector>13#include <vector>
14#include "kernel_operator.h"14#include "kernel_operator.h"
15+#include "utils/debug/asc_printf.h"
15 16 
16#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 117#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
17__aicore__ inline uint32_t asc_debug_get_core_idx()18__aicore__ inline uint32_t asc_debug_get_core_idx()
@@ -84,6 +85,22 @@ TEST_F(TestPrintfSuite, PrintfCase)
84 g_taskRation = taskRationTmp;85 g_taskRation = taskRationTmp;
85}86}
86 87 
88+#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1
89+TEST_F(TestPrintfSuite, SimdVfPrintfMatchesAicoreCpuFallback)
90+{
91+ testing::internal::CaptureStdout();
92+ __asc_aicore::printf("SIMD_VF_PRINTF %s %d %u %.2f 0x%x", "value", -3, 6U, 1.25, 0x2AU);
93+ const std::string aicoreOutput = testing::internal::GetCapturedStdout();
94+ 
95+ testing::internal::CaptureStdout();
96+ __asc_simd_vf::printf("SIMD_VF_PRINTF %s %d %u %.2f 0x%x", "value", -3, 6U, 1.25, 0x2AU);
97+ const std::string simdVfOutput = testing::internal::GetCapturedStdout();
98+ 
99+ EXPECT_EQ(simdVfOutput, aicoreOutput);
100+ EXPECT_EQ(simdVfOutput, "SIMD_VF_PRINTF value -3 6 1.25 0x2a");
101+}
102+#endif
103+ 
87TEST_F(TestPrintfSuite, DumpBlockIdxAndSysVarCase)104TEST_F(TestPrintfSuite, DumpBlockIdxAndSysVarCase)
88{105{
89 int32_t coreTypeTmp = g_coreType;106 int32_t coreTypeTmp = g_coreType;
Atests/api/basic_api/ascendc_case_ascend950pr_9599/ascendc_case_ascend950pr_9599_aiv_basic/test_simd_vf_debug_dump_disabled.cpp+46-0
@@ -0,0 +1,46 @@
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+#include <array>
12+#include <gtest/gtest.h>
13+#include "utils/debug/asc_dump.h"
14+#include "utils/debug/asc_printf.h"
15+ 
16+#if defined(ASCENDC_CPU_DEBUG) && ASCENDC_CPU_DEBUG == 1 && __NPU_ARCH__ == 3510
17+TEST(SimdVfDebugDumpDisabledTest, PrintfIsSilentAndDumpFallbacksRemainAvailable)
18+{
19+ testing::internal::CaptureStdout();
20+ __asc_simd_vf::printf("disabled %llu", 1ULL);
21+ EXPECT_TRUE(testing::internal::GetCapturedStdout().empty());
22+ 
23+ int16_t ubInput[1] = {0};
24+ std::array<int16_t, 128> regInput = {};
25+ 
26+#ifndef NDEBUG
27+ EXPECT_DEATH(asc_dump_ubuf<int16_t>(ubInput, 0, 1), "asc_dump_ubuf is not supported in cpu mode");
28+ EXPECT_DEATH(asc_dump_reg<int16_t>(regInput, 0, 1), "asc_dump_reg is not supported in cpu mode");
29+ EXPECT_DEATH(asc_dump<int16_t>(ubInput, 0, 1), "asc_dump is not supported in cpu mode");
30+ EXPECT_DEATH(asc_dump<int16_t>(regInput, 0, 1), "asc_dump is not supported in cpu mode");
31+ EXPECT_DEATH(__asc_simd_vf::asc_dump_ubuf<int16_t>(ubInput, 0, 1), "asc_dump_ubuf is not supported in cpu mode");
32+ EXPECT_DEATH(__asc_simd_vf::asc_dump_reg<int16_t>(regInput, 0, 1), "asc_dump_reg is not supported in cpu mode");
33+ EXPECT_DEATH(__asc_simd_vf::asc_dump<int16_t>(ubInput, 0, 1), "asc_dump is not supported in cpu mode");
34+ EXPECT_DEATH(__asc_simd_vf::asc_dump<int16_t>(regInput, 0, 1), "asc_dump is not supported in cpu mode");
35+#else
36+ asc_dump_ubuf<int16_t>(ubInput, 0, 1);
37+ asc_dump_reg<int16_t>(regInput, 0, 1);
38+ asc_dump<int16_t>(ubInput, 0, 1);
39+ asc_dump<int16_t>(regInput, 0, 1);
40+ __asc_simd_vf::asc_dump_ubuf<int16_t>(ubInput, 0, 1);
41+ __asc_simd_vf::asc_dump_reg<int16_t>(regInput, 0, 1);
42+ __asc_simd_vf::asc_dump<int16_t>(ubInput, 0, 1);
43+ __asc_simd_vf::asc_dump<int16_t>(regInput, 0, 1);
44+#endif
45+}
46+#endif
Atests/api/basic_api/ascendc_header_checker/simd_vf_debug.cpp+32-0
@@ -0,0 +1,32 @@
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+#ifndef VERIFY_SINGLE_HEADER
12+#include "kernel_operator.h"
13+#endif
14+ 
15+#if __NPU_ARCH__ == 3510
16+#include "utils/debug/asc_dump.h"
17+#include "utils/debug/asc_printf.h"
18+ 
19+__simd_vf__ inline void TestSimdVfDebugApis(__ubuf__ uint32_t* ubInput)
20+{
21+ vector_u32 regInput;
22+ __asc_simd_vf::printf("SIMD VF debug %u", 1U);
23+ asc_dump_ubuf<uint32_t>(ubInput, 0, 1);
24+ asc_dump_reg<uint32_t>(regInput, 0, 1);
25+ asc_dump<uint32_t>(ubInput, 0, 1);
26+ asc_dump<uint32_t>(regInput, 0, 1);
27+ __asc_simd_vf::asc_dump_ubuf<uint32_t>(ubInput, 0, 1);
28+ __asc_simd_vf::asc_dump_reg<uint32_t>(regInput, 0, 1);
29+ __asc_simd_vf::asc_dump<uint32_t>(ubInput, 0, 1);
30+ __asc_simd_vf::asc_dump<uint32_t>(regInput, 0, 1);
31+}
32+#endif