Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions Tutorials/ML/benchmarkOnnxModel.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <fstream>
#include <iomanip>
#include <ios>
#include <istream>
#include <limits>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -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<int (*)(int)>(dlsym(library, cuda ? "cudaSetDevice" : "hipSetDevice"));
auto setDevice = reinterpret_cast<int (*)(int)>(dlsym(library, cuda ? "cudaSetDevice" : "hipSetDevice")); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
memoryFunction = cuda ? "cudaMemGetInfo" : "hipMemGetInfo";
getMemory = reinterpret_cast<int (*)(size_t*, size_t*)>(dlsym(library, memoryFunction));
getMemory = reinterpret_cast<int (*)(size_t*, size_t*)>(dlsym(library, memoryFunction)); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast)
if (!setDevice || !getMemory || setDevice(device) != 0) {
dlclose(library);
library = nullptr;
Expand Down Expand Up @@ -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<float>(halves[i]))) {
throw std::runtime_error("Input feature overflows FP16");
}
} else {
Expand Down Expand Up @@ -298,7 +299,7 @@ struct BenchmarkOnnxModel {
const size_t columns = static_cast<size_t>(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<float>(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");
Expand All @@ -311,7 +312,7 @@ struct BenchmarkOnnxModel {
predictions << std::setprecision(std::numeric_limits<float>::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<size_t>(row) * columns + column);
Expand Down
Loading