已合并
[simd_vf debug] fix debug api cpu debug compile error #4749
ChenZhoujie创建于 26 天前
[simd_vf debug] fix debug api cpu debug compile error #4749
已合并
共 7 个文件变更+229-2
| @@ -15,9 +15,10 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | + | ||
| 19 | + | ||
| 18 | 20 | ||
| 19 | 21 | ||
| 20 | - | ||
| 21 | 22 | ||
| 22 | 23 | ||
| 23 | namespace __asc_simd_vf { | 24 | namespace __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_vf | 168 | } // namespace __asc_simd_vf |
| 168 | 169 | ||
| 170 | + | ||
| 171 | + | ||
| 172 | + | ||
| 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 | + | ||
| 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 | + | ||
| 228 | + | ||
| 169 | 229 | ||
| 170 | 230 | ||
| 171 | 231 | ||
| @@ -16,6 +16,8 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + | ||
| 20 | + | ||
| 19 | 21 | ||
| 20 | 22 | ||
| 21 | 23 | ||
| @@ -220,4 +222,26 @@ __simd_callee__ inline void printf(__ubuf__ const char* fmt, Args&&... args) | |||
| 220 | } | 222 | } |
| 221 | } // namespace __asc_simd_vf | 223 | } // namespace __asc_simd_vf |
| 222 | 224 | ||
| 225 | + | ||
| 226 | + | ||
| 227 | + | ||
| 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 | + | ||
| 234 | + std::printf(fmt, args...); | ||
| 235 | + | ||
| 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 | |||
| 242 | +} | ||
| 243 | +} // namespace __asc_simd_vf | ||
| 244 | + | ||
| 245 | + | ||
| 246 | + | ||
| 223 | 247 | ||
| @@ -61,7 +61,7 @@ __simd_callee__ inline void printf(__ubuf__ const char* fmt, Args&&... args); | |||
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | 63 | ||
| 64 | -#if (__NPU_ARCH__ == 3510) && !defined(ASCENDC_CPU_DEBUG) | 64 | +#if __NPU_ARCH__ == 3510 |
| 65 | 65 | ||
| 66 | 66 | ||
| 67 | 67 | ||
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 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 17 | 18 | ||
| @@ -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 | + | ||
| 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 | + | ||
| 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 | + | ||
| 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 | + | ||
| 232 | +} | ||
| 233 | + | ||
| 234 | +TEST_F(TestDumpTensorSuite, AicoreDumpCpuFallbacksRemainAvailable) | ||
| 235 | +{ | ||
| 236 | + uint32_t input[1] = {0}; | ||
| 237 | + | ||
| 238 | + | ||
| 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 | + | ||
| 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 | + | ||
| 247 | +} | ||
| 248 | + | ||
| 249 | + | ||
| 202 | 250 | ||
| 203 | TEST_F(TestDumpTensorSuite, AscDumpUbufWritesUbPosition) | 251 | TEST_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 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | + | ||
| 15 | 16 | ||
| 16 | 17 | ||
| 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 | + | ||
| 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 | + | ||
| 103 | + | ||
| 87 | TEST_F(TestPrintfSuite, DumpBlockIdxAndSysVarCase) | 104 | TEST_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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 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 | + | ||
| 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 | + | ||
| 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 | + | ||
| 45 | +} | ||
| 46 | + | ||
| @@ -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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 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 | + | ||
感觉printf_impl没有存在的必要,是否可以都删除。直接printf_impl的函数移动到其中