[Apptest] Add apptest to test API call interleaving
authorDongju Chae <dongju.chae@samsung.com>
Mon, 5 Jul 2021 05:49:44 +0000 (14:49 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Mon, 5 Jul 2021 08:20:29 +0000 (17:20 +0900)
This adds apptest to test API call interleaving for multiple models.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
tests/apptests/meson.build
tests/apptests/tvn_triv2_interleave.cc [new file with mode: 0644]

index c39a2a6..7869a70 100644 (file)
@@ -127,6 +127,16 @@ executable ('apptest_tvn_triv2_aging',
   install_dir : join_paths(ne_bindir, 'apptests')
 )
 
+executable ('apptest_tvn_triv2_interleave',
+  'tvn_triv2_interleave.cc',
+  include_directories : ne_apptest_inc,
+  dependencies : ne_test_utils_dep,
+  link_with : ne_library_shared,
+  install : true,
+  install_rpath : ne_libdir,
+  install_dir : join_paths(ne_bindir, 'apptests')
+)
+
 # npumgr is available on tizen env.
 if target_platform == 'tizen'
   subdir('npumgr')
diff --git a/tests/apptests/tvn_triv2_interleave.cc b/tests/apptests/tvn_triv2_interleave.cc
new file mode 100644 (file)
index 0000000..e1e2a24
--- /dev/null
@@ -0,0 +1,137 @@
+/**
+ * Proprietary
+ * Copyright (C) 2021 Samsung Electronics
+ * Copyright (C) 2021 Dongju Chae <dongju.chae@samsung.com>
+ */
+/**
+ * @file tvn_triv2_interleave.cc
+ * @date 05 Jul 2021
+ * @brief Apptest to interleave inferences with multiple models
+ * @author Dongju Chae <dongju.chae@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#include <ne_test_utils.h>
+#include <iostream>
+#include <vector>
+#include <sstream>
+
+#define NPU_TIMEOUT_MS 5000
+
+using namespace std;
+
+extern char *__progname;
+
+static void
+print_help (void) {
+  cerr << "Usage: " << __progname;
+  cerr << " [# iters] [comma-seperated modelpath]\n";
+}
+
+/** @brief apptest main  */
+int
+main (int argc, char **argv) {
+  unique_ptr<UtilTRIV2[]> testers;
+  unique_ptr<uint32_t[]> model_ids;
+  unique_ptr<int[]> req_ids;
+  int num_models, num_iters;
+
+  if (argc < 3) {
+    print_help ();
+    return 0;
+  }
+
+  /* number of iterations*/
+  num_iters = atoi (argv[1]);
+
+  /* number of model paths (comma-seperated) */
+  vector<string> model_paths;
+  stringstream ss (argv[2]);
+  string str;
+  while (getline (ss, str, ',')) model_paths.push_back (str);
+
+  if (num_iters <= 0 || model_paths.empty ()) {
+    cerr << "Invalid arguments detected\n";
+    print_help ();
+    return -EINVAL;
+  }
+
+  /* initialize testers for each model */
+  num_models = model_paths.size ();
+  testers.reset (new UtilTRIV2[num_models]);
+  model_ids.reset (new uint32_t[num_models]);
+  req_ids.reset (new int[num_models]);
+
+  int status = -EINVAL;
+  bool is_error = false;
+
+  /* perform interleaving for libnpuhost API calls */
+  for (int i = 0; i < num_iters; i++) {
+    cerr << "[" << i << "] starting...\n";
+
+    for (int j = 0; j < num_models; j++) {
+      status = testers[j].init (2);
+      if (status != 0) {
+        cerr << "Unable to initialize\n";
+        is_error = true;
+        goto out;
+      }
+    }
+
+    for (int j = 0; j < num_models; j++) {
+      status = testers[j].loadModel (model_paths[j].c_str (), &model_ids[j],
+                                     NPU_PRIORITY_MID, NPU_TIMEOUT_MS);
+      if (status != 0) {
+        cerr << "Unable to load model\n";
+        is_error = true;
+        goto out_clear;
+      }
+    }
+
+    for (int j = 0; j < num_models; j++) {
+      req_ids[j] = testers[j].createRequest (model_ids[j]);
+      if (req_ids[j] < 0) {
+        cerr << "Unable to create request\n";
+        is_error = true;
+        goto out_unload;
+      }
+    }
+
+    for (int j = 0; j < num_models; j++) {
+      status = testers[j].submitRequest (req_ids[j]);
+      if (status != 0) {
+        cerr << "Unable to submit request\n";
+        is_error = true;
+        break;
+      }
+    }
+
+    for (int j = 0; j < num_models; j++) {
+      status = testers[j].removeRequest (req_ids[j]);
+      if (status != 0) {
+        cerr << "Unable to remove request\n";
+        is_error = true;
+        break;
+      }
+    }
+
+  out_unload:
+    for (int j = 0; j < num_models; j++) {
+      status = testers[j].unloadModel (model_ids[j]);
+      if (status != 0) {
+        cerr << "Unable to unload model\n";
+        is_error = true;
+        break;
+      }
+    }
+
+  out_clear:
+    for (int j = 0; j < num_models; j++) testers[j].clear ();
+
+  out:
+    if (is_error)
+      break;
+  }
+
+  return status;
+}