From 554fb8af11a17653ea0e65c1003643ae6acc7c59 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Fri, 6 Dec 2024 11:41:46 +0100 Subject: [PATCH] teflon/tests: Take into account signedness when checking the output tensors Otherwise, it won't be able to apply the tolerance in all cases. Part-of: --- src/gallium/targets/teflon/test_teflon.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/gallium/targets/teflon/test_teflon.cpp b/src/gallium/targets/teflon/test_teflon.cpp index 8b650f704bf..178a94cf568 100644 --- a/src/gallium/targets/teflon/test_teflon.cpp +++ b/src/gallium/targets/teflon/test_teflon.cpp @@ -81,7 +81,24 @@ test_model(void *buf, size_t buf_size, std::string cache_dir, unsigned tolerance } break; } - default: { + case kTfLiteInt8: { + int8_t *cpu = ((int8_t**)cpu_output)[i]; + int8_t *npu = ((int8_t**)npu_output)[i]; + if (abs(cpu[j] - npu[j]) > tolerance) { + std::cout << "CPU: "; + for (int k = 0; k < std::min(int(output_sizes[i]), 24); k++) + std::cout << std::setfill('0') << std::setw(2) << std::hex << int(cpu[k]) << " "; + std::cout << "\n"; + std::cout << "NPU: "; + for (int k = 0; k < std::min(int(output_sizes[i]), 24); k++) + std::cout << std::setfill('0') << std::setw(2) << std::hex << int(npu[k]) << " "; + std::cout << "\n"; + + FAIL() << "Output at " << j << " from the NPU (" << std::setfill('0') << std::setw(2) << std::hex << int(npu[j]) << ") doesn't match that from the CPU (" << std::setfill('0') << std::setw(2) << std::hex << int(cpu[j]) << ")."; + } + break; + } + case kTfLiteUInt8: { uint8_t *cpu = ((uint8_t**)cpu_output)[i]; uint8_t *npu = ((uint8_t**)npu_output)[i]; if (abs(cpu[j] - npu[j]) > tolerance) { @@ -98,6 +115,8 @@ test_model(void *buf, size_t buf_size, std::string cache_dir, unsigned tolerance } break; } + default: + assert(!"Unsupported data type for output tensor"); } } }