From 45cc38acc26e0ae8511bd4c74882a7410ed85301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ku=C4=8Dera?= <26327373+vkucera@users.noreply.github.com> Date: Fri, 27 Nov 2026 16:15:47 +0100 Subject: [PATCH] benchmarkOnnxModel: Fix errors --- Tutorials/ML/benchmarkOnnxModel.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Tutorials/ML/benchmarkOnnxModel.cxx b/Tutorials/ML/benchmarkOnnxModel.cxx index f03ee9bfee3..a13d3ea7864 100644 --- a/Tutorials/ML/benchmarkOnnxModel.cxx +++ b/Tutorials/ML/benchmarkOnnxModel.cxx @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -58,9 +59,9 @@ class GpuMemory throw std::runtime_error(cuda ? "GPU telemetry requires libcudart.so (CUDA 11/12/13) on LD_LIBRARY_PATH" : "GPU telemetry requires libamdhip64.so on LD_LIBRARY_PATH"); } - auto setDevice = reinterpret_cast(dlsym(library, cuda ? "cudaSetDevice" : "hipSetDevice")); + auto setDevice = reinterpret_cast(dlsym(library, cuda ? "cudaSetDevice" : "hipSetDevice")); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) memoryFunction = cuda ? "cudaMemGetInfo" : "hipMemGetInfo"; - getMemory = reinterpret_cast(dlsym(library, memoryFunction)); + getMemory = reinterpret_cast(dlsym(library, memoryFunction)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast) if (!setDevice || !getMemory || setDevice(device) != 0) { dlclose(library); library = nullptr; @@ -202,8 +203,8 @@ struct BenchmarkOnnxModel { throw std::runtime_error("Input features must be finite"); } if (fp16.value) { - halves[i] = _Float16(value); - if (!std::isfinite((float)halves[i])) { + halves[i] = static_cast<_Float16>(value); + if (!std::isfinite(static_cast(halves[i]))) { throw std::runtime_error("Input feature overflows FP16"); } } else { @@ -298,7 +299,7 @@ struct BenchmarkOnnxModel { const size_t columns = static_cast(outputShape[1]); // Validate before opening the destination, so invalid predictions do not // replace an existing file with a partial matrix. - auto valueAt = [&](size_t i) { return fp32 ? fp32[i] : (float)fp16Data[i]; }; + auto valueAt = [&](size_t i) { return fp32 ? fp32[i] : static_cast(fp16Data[i]); }; for (size_t i = 0; i < info.GetElementCount(); ++i) { if (!std::isfinite(valueAt(i))) { throw std::runtime_error("Prediction export found a nonfinite value"); @@ -311,7 +312,7 @@ struct BenchmarkOnnxModel { predictions << std::setprecision(std::numeric_limits::max_digits10); for (int row = 0; row < batchSize.value; ++row) { for (size_t column = 0; column < columns; ++column) { - if (column) { + if (column != 0u) { predictions << ' '; } predictions << valueAt(static_cast(row) * columns + column);