From 60269a0f7bf8e26bab971d64713a7a2eab1d13d4 Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Thu, 18 Jul 2024 14:39:19 -0700 Subject: [PATCH] Some updates to C++ benchmark (#708) - Fix whitespace in usage text - Fix memory usage output on MacOS - Add readme --- benchmark/c/options.cpp | 2 +- benchmark/c/posix/resource_utils.cpp | 8 +++++++- benchmark/c/readme.md | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 benchmark/c/readme.md diff --git a/benchmark/c/options.cpp b/benchmark/c/options.cpp index 7047a4466..7f333e969 100644 --- a/benchmark/c/options.cpp +++ b/benchmark/c/options.cpp @@ -23,7 +23,7 @@ namespace { s << "Usage: " << program_name << " -i \n" << " Options:\n" << " -i,--input_folder \n" - << " Path to the ONNX model directory to benchmark, compatible with onnxruntime-genai.\n " + << " Path to the ONNX model directory to benchmark, compatible with onnxruntime-genai.\n" << " -b,--batch_size \n" << " Number of sequences to generate in parallel. Default: " << defaults.batch_size << "\n" << " -l,--prompt_length \n" diff --git a/benchmark/c/posix/resource_utils.cpp b/benchmark/c/posix/resource_utils.cpp index 0e761b3de..af63ca25c 100644 --- a/benchmark/c/posix/resource_utils.cpp +++ b/benchmark/c/posix/resource_utils.cpp @@ -17,7 +17,13 @@ size_t GetPeakWorkingSetSizeInBytes() { throw std::runtime_error("getrusage failed with error code " + std::to_string(errno)); } - return static_cast(rusage.ru_maxrss * 1024L); +#if defined(__APPLE__) + constexpr size_t kBytesPerMaxRssUnit = 1; +#else + constexpr size_t kBytesPerMaxRssUnit = 1024; +#endif + + return static_cast(rusage.ru_maxrss) * kBytesPerMaxRssUnit; } } // namespace benchmark::utils diff --git a/benchmark/c/readme.md b/benchmark/c/readme.md new file mode 100644 index 000000000..3a493f591 --- /dev/null +++ b/benchmark/c/readme.md @@ -0,0 +1,15 @@ +# model_benchmark + +`model_benchmark` is an end-to-end benchmark program for ONNX Runtime GenAI models. +It is written in C++ and built as part of the ONNX Runtime GenAI build (e.g., via [build.py](../../build.py)). + +It is an alternative to the [Python benchmark script](../python/benchmark_e2e.py) that can be run in environments where Python is not available. + +Example usage: +``` +model_benchmark -i +``` + +Run with `--help` to see information about additional options. + +Note: On some platforms, such as Android, you may need to set the environment variable `LD_LIBRARY_PATH` to the directory containing the onnxruntime shared library for `model_benchmark` to be able to run.