summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHåvard Pettersen <havardpe@oath.com>2021-06-10 14:03:09 +0000
committerHåvard Pettersen <havardpe@oath.com>2021-06-10 14:03:09 +0000
commitc7c92cd8101ad75b3f32d30840e79c58860a7fe8 (patch)
tree9588e954ee34a9cffd0f2bb6b9f991c3787f6303
parenteb93f635cde554ab681c1029d68412b8dbcd5487 (diff)
added very simple onnx model analyzer
just estimating memory needed to load the model for now
-rw-r--r--eval/CMakeLists.txt1
-rw-r--r--eval/src/apps/analyze_onnx_model/.gitignore1
-rw-r--r--eval/src/apps/analyze_onnx_model/CMakeLists.txt8
-rw-r--r--eval/src/apps/analyze_onnx_model/analyze_onnx_model.cpp59
4 files changed, 69 insertions, 0 deletions
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 <vespa/eval/onnx/onnx_wrapper.h>
+#include <vespa/vespalib/util/guard.h>
+
+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 <onnx-model>\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;
+}