From c7c92cd8101ad75b3f32d30840e79c58860a7fe8 Mon Sep 17 00:00:00 2001 From: HÃ¥vard Pettersen Date: Thu, 10 Jun 2021 14:03:09 +0000 Subject: added very simple onnx model analyzer just estimating memory needed to load the model for now --- eval/CMakeLists.txt | 1 + eval/src/apps/analyze_onnx_model/.gitignore | 1 + eval/src/apps/analyze_onnx_model/CMakeLists.txt | 8 +++ .../apps/analyze_onnx_model/analyze_onnx_model.cpp | 59 ++++++++++++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 eval/src/apps/analyze_onnx_model/.gitignore create mode 100644 eval/src/apps/analyze_onnx_model/CMakeLists.txt create mode 100644 eval/src/apps/analyze_onnx_model/analyze_onnx_model.cpp (limited to 'eval') diff --git a/eval/CMakeLists.txt b/eval/CMakeLists.txt index 302b6768cea..16c9c72d8a5 100644 --- a/eval/CMakeLists.txt +++ b/eval/CMakeLists.txt @@ -5,6 +5,7 @@ vespa_define_module( staging_vespalib APPS + src/apps/analyze_onnx_model src/apps/eval_expr src/apps/make_tensor_binary_format_test_spec src/apps/tensor_conformance diff --git a/eval/src/apps/analyze_onnx_model/.gitignore b/eval/src/apps/analyze_onnx_model/.gitignore new file mode 100644 index 00000000000..12ce20b03ba --- /dev/null +++ b/eval/src/apps/analyze_onnx_model/.gitignore @@ -0,0 +1 @@ +/vespa-analyze-onnx-model diff --git a/eval/src/apps/analyze_onnx_model/CMakeLists.txt b/eval/src/apps/analyze_onnx_model/CMakeLists.txt new file mode 100644 index 00000000000..47cbb6504f4 --- /dev/null +++ b/eval/src/apps/analyze_onnx_model/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +vespa_add_executable(vespa-analyze-onnx-model + SOURCES + analyze_onnx_model.cpp + INSTALL bin + DEPENDS + vespaeval +) diff --git a/eval/src/apps/analyze_onnx_model/analyze_onnx_model.cpp b/eval/src/apps/analyze_onnx_model/analyze_onnx_model.cpp new file mode 100644 index 00000000000..f1cc3b28751 --- /dev/null +++ b/eval/src/apps/analyze_onnx_model/analyze_onnx_model.cpp @@ -0,0 +1,59 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include +#include + +using vespalib::FilePointer; +using namespace vespalib::eval; + +bool read_line(FilePointer &file, vespalib::string &line) { + char line_buffer[1024]; + char *res = fgets(line_buffer, sizeof(line_buffer), file.fp()); + if (res == nullptr) { + line.clear(); + return false; + } + line = line_buffer; + while (!line.empty() && isspace(line[line.size() - 1])) { + line.pop_back(); + } + return true; +} + +void extract(const vespalib::string &str, const vespalib::string &prefix, vespalib::string &dst) { + if (starts_with(str, prefix)) { + size_t pos = prefix.size(); + while ((str.size() > pos) && isspace(str[pos])) { + ++pos; + } + dst = str.substr(pos); + } +} + +void report_memory_usage(const vespalib::string &desc) { + vespalib::string vm_size = "unknown"; + vespalib::string vm_rss = "unknown"; + vespalib::string line; + FilePointer file(fopen("/proc/self/status", "r")); + while (read_line(file, line)) { + extract(line, "VmSize:", vm_size); + extract(line, "VmRSS:", vm_rss); + } + fprintf(stderr, "vm_size: %s, vm_rss: %s (%s)\n", vm_size.c_str(), vm_rss.c_str(), desc.c_str()); +} + +int usage(const char *self) { + fprintf(stderr, "usage: %s \n", self); + fprintf(stderr, " load onnx model and report memory usage\n"); + return 1; +} + +int main(int argc, char **argv) { + if (argc != 2) { + return usage(argv[0]); + } + report_memory_usage("before loading model"); + Onnx onnx(argv[1], Onnx::Optimize::ENABLE); + report_memory_usage("after loading model"); + return 0; +} -- cgit v1.2.3