diff --git a/Tutorials/ML/README-benchmark.md b/Tutorials/ML/README-benchmark.md index 65702fc5ede..0ed160d8d60 100644 --- a/Tutorials/ML/README-benchmark.md +++ b/Tutorials/ML/README-benchmark.md @@ -10,8 +10,7 @@ are filled from the options. Output types are left to ONNX Runtime. Build O2Physics normally after loading its O2 environment. This target links `O2::ML`, `O2::GPUCommon`, `ONNXRuntime::ONNXRuntime`, and the platform dynamic -loader. No HIP or CUDA headers are required for building the task. The O2 installation -must contain `ML/3rdparty/GPUORTFloat16.h` and its GPUCommon headers. +loader. No HIP or CUDA headers are required for building the task. For AMD GPU runs, ONNX Runtime must contain **MIGraphXExecutionProvider**, and its MIGraphX/ROCm shared libraries, including `libamdhip64.so`, must be discoverable @@ -78,7 +77,7 @@ masking on AMD or `CUDA_VISIBLE_DEVICES` masking on NVIDIA. Run one benchmark pr GPU. Repeat with the same batch sizes and CPU thread count, and compare several runs. Small batches can be dominated by host overhead and transfers. -`--fp16 true` selects O2's `o2::OrtDataType::Float16_t` input storage and checks +`--fp16 true` selects O2's GCC/Clang's _Float16 input storage and checks that the model input is FLOAT16. It does not convert model weights or prove that every internal operation is FP16. Export/inspect the model accordingly. FP16 models retaining FP32 input interfaces need an adapted input path; this small diff --git a/Tutorials/ML/benchmarkOnnxModel.cxx b/Tutorials/ML/benchmarkOnnxModel.cxx index 521f3604d8f..f03ee9bfee3 100644 --- a/Tutorials/ML/benchmarkOnnxModel.cxx +++ b/Tutorials/ML/benchmarkOnnxModel.cxx @@ -16,7 +16,6 @@ #include #include -#include #include #include @@ -196,15 +195,15 @@ struct BenchmarkOnnxModel { // File loading and FP16 conversion are outside the timing loop. Without a // file, retain deterministic synthetic inputs for performance-only runs. std::vector floats(fp16.value ? 0 : count); - std::vector halves(fp16.value ? count : 0); - static_assert(sizeof(o2::OrtDataType::Float16_t) == 2); + std::vector<_Float16> halves(fp16.value ? count : 0); + static_assert(sizeof(_Float16) == 2); auto store = [&](size_t i, float value) { if (!std::isfinite(value)) { throw std::runtime_error("Input features must be finite"); } if (fp16.value) { - halves[i] = o2::OrtDataType::Float16_t(value); - if (!std::isfinite(halves[i].ToFloat())) { + halves[i] = _Float16(value); + if (!std::isfinite((float)halves[i])) { throw std::runtime_error("Input feature overflows FP16"); } } else { @@ -295,11 +294,11 @@ struct BenchmarkOnnxModel { throw std::runtime_error("Prediction export requires an FP32 or FP16 first output [batch-size, classes]"); } const float* fp32 = outputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT ? output.GetTensorData() : nullptr; - const auto* fp16Data = outputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 ? output.GetTensorData() : nullptr; + const auto* fp16Data = outputType == ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT16 ? output.GetTensorData<_Float16>() : nullptr; 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] : fp16Data[i].ToFloat(); }; + auto valueAt = [&](size_t i) { return fp32 ? fp32[i] : (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");