[test] add unittest for profiler
authorYelin Jeong <yelini.jeong@samsung.com>
Wed, 30 Nov 2022 12:22:31 +0000 (21:22 +0900)
committer추지호/NPU Lab(SR)/삼성전자 <jiho.chu@samsung.com>
Mon, 5 Dec 2022 07:31:01 +0000 (16:31 +0900)
This patch add uniitest for profiler's mergeProfile

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
debian/npu-engine-example.install
meson.build
packaging/npu-engine.spec
tests/meson.build
tests/testdata/meson.build [new file with mode: 0644]
tests/testdata/triv2.3.rec [new file with mode: 0644]
tests/testdata/triv2.4_dlp_284_485.rec [new file with mode: 0644]
tests/testdata/triv2.4_nodlp_284.rec [new file with mode: 0644]
tests/unittests/meson.build
tests/unittests/ne_core_profiler_test.cc [new file with mode: 0644]

index 53674de733c00138aa16cd8c926b35321def44b4..03c4f69244d40d196fa493c030487eb194cec5e7 100644 (file)
@@ -1,2 +1,3 @@
 /opt/trinity/bin/unittests/*
 /opt/trinity/bin/apptests/*
+/opt/trinity/bin/testdata/*
index d2f95dc470d5397503aa8d8dd9dc6ea9a9dccbd4..abd9dd97e43c57c678c60221b0bd800c70f4c849 100644 (file)
@@ -71,6 +71,7 @@ ne_datadir = join_paths(ne_prefix, join_paths(get_option('datadir'), 'npu-engine
 
 add_project_arguments('-DNE_PREFIX="' + ne_prefix + '"', language: ['c', 'cpp'])
 add_project_arguments('-DNE_INIDIR="' + ne_inidir + '"', language: ['c', 'cpp'])
+add_project_arguments('-DNE_BINDIR="' + ne_bindir + '"', language: ['c', 'cpp'])
 add_project_arguments('-DNE_DATADIR="' + ne_datadir + '"', language: ['c', 'cpp'])
 
 ne_common_inc = include_directories('include/common')
index 0d0e5615477f00bb1aac6311085f15ff564d8e99..57405af2b53919cf6b8f2f78f1aedc97b45ca6f5 100644 (file)
@@ -141,6 +141,7 @@ Example application package for NPU Engine, including UnitTests and AppTest with
 %defattr(-,root,root,-)
 %{neexampledir}/unittests/*
 %{neexampledir}/apptests/*
+%{neexampledir}/testdata/*
 
 %package utils
 Requires:      npu-engine = %{version}-%{release}
index 9fab197d0cdef727596f76392715ca9f500a211a..9b9d9d450d8c6e8dd27c5cd02f29ec3f52e58ab9 100644 (file)
@@ -2,3 +2,4 @@ subdir('utils')
 subdir('unittests')
 subdir('apptests')
 subdir('plugins')
+subdir('testdata')
diff --git a/tests/testdata/meson.build b/tests/testdata/meson.build
new file mode 100644 (file)
index 0000000..b883863
--- /dev/null
@@ -0,0 +1,3 @@
+install_data(sources : 'triv2.3.rec', install_dir : join_paths(ne_bindir, 'testdata'))
+install_data(sources : 'triv2.4_dlp_284_485.rec', install_dir : join_paths(ne_bindir, 'testdata'))
+install_data(sources : 'triv2.4_nodlp_284.rec', install_dir : join_paths(ne_bindir, 'testdata'))
diff --git a/tests/testdata/triv2.3.rec b/tests/testdata/triv2.3.rec
new file mode 100644 (file)
index 0000000..29e974c
Binary files /dev/null and b/tests/testdata/triv2.3.rec differ
diff --git a/tests/testdata/triv2.4_dlp_284_485.rec b/tests/testdata/triv2.4_dlp_284_485.rec
new file mode 100644 (file)
index 0000000..224ed9c
Binary files /dev/null and b/tests/testdata/triv2.4_dlp_284_485.rec differ
diff --git a/tests/testdata/triv2.4_nodlp_284.rec b/tests/testdata/triv2.4_nodlp_284.rec
new file mode 100644 (file)
index 0000000..624eee9
Binary files /dev/null and b/tests/testdata/triv2.4_nodlp_284.rec differ
index 62302bc2ed7c1c1df456bad24792c2b23abd2e2a..704d6a3d5d07e4b2f1e4b5e5a314c74b404d79f3 100644 (file)
@@ -132,4 +132,14 @@ if ne_test_utils_gtest_dep.found()
     install_dir : join_paths(ne_bindir, 'unittests')
   )
   test('unittest_ne_libnpuhost', unittest_ne_libnpuhost, env: testenv, suite: ['fast-test'])
+
+  unittest_ne_core_profiler = executable('unittest_ne_core_profiler',
+    ['ne_core_profiler_test.cc'],
+    include_directories: [ne_host_inc, ne_common_inc],
+    dependencies: [ne_test_utils_gtest_dep, ne_host_dep, ne_core_dep],
+    install : true,
+    install_rpath : ne_libdir,
+    install_dir : join_paths(ne_bindir, 'unittests')
+  )
+  test('unittest_ne_core_profiler', unittest_ne_core_profiler, env: testenv, suite: ['fast-test'])
 endif
diff --git a/tests/unittests/ne_core_profiler_test.cc b/tests/unittests/ne_core_profiler_test.cc
new file mode 100644 (file)
index 0000000..165d11b
--- /dev/null
@@ -0,0 +1,97 @@
+/* SPDX-License-Identifier: Apache-2.0 */
+/**
+ * Copyright (C) 2022 Samsung Electronics
+ * Copyright (C) 2022 Yelin Jeong <yelini.jeong@samsung.com>
+ */
+/**
+ * @file ne_core_profiler_test.cc
+ * @date 23 Nov 2022
+ * @brief Test npu profiler
+ * @author Yelin Jeong <yelini.jeong@samsung.com>
+ * @bug No known bugs except for NYI items
+ */
+
+#include <ne_test_utils_gtest.h>
+#include <ne-profiler.h>
+#include <ne-handler.h>
+
+#define REC_PATH NE_BINDIR "/testdata/triv2.4_nodlp_284.rec"
+#define DLP_REC_PATH NE_BINDIR "/testdata/triv2.4_dlp_284_485.rec"
+
+/**
+ * @brief check mergeProfile
+ */
+TEST (ne_core_profiler_test, merge_profile) {
+  const npu_profile_opt opt_visa = {.level = PROFILE_LEVEL_VISA};
+
+  int ret, num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
+  ASSERT_GT (num_devices, 0);
+
+  auto api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+  ModelProfiler *profiler = new ModelProfiler (api.get ());
+  ASSERT_NE (api.get (), nullptr);
+
+  npu_profile profile = {0};
+
+  if (!std::ifstream (REC_PATH)) {
+    printf ("no rec file %s found\n", REC_PATH);
+    return;
+  }
+
+  ret = profiler->getProfile (1, opt_visa, &profile, REC_PATH);
+  ASSERT_EQ (ret, 0);
+
+  npu_profile profile_dlp = {0};
+
+  if (!std::ifstream (DLP_REC_PATH)) {
+    printf ("no rec file %s found\n", DLP_REC_PATH);
+    return;
+  }
+
+  ret = profiler->getProfile (1, opt_visa, &profile_dlp, DLP_REC_PATH);
+  ASSERT_EQ (ret, 0);
+
+  ASSERT_EQ (profile.num_layers, profile_dlp.num_layers);
+  for (int i = 0; i < profile.num_layers; i++) {
+    EXPECT_EQ (profile.layers[i].visa_opcode, profile_dlp.layers[i].visa_opcode);
+  }
+}
+
+/**
+ * @brief check mergeProfile
+ */
+TEST (ne_core_profiler_test, profile_level_visa_dlp) {
+  const npu_profile_opt opt_dlp = {.level = PROFILE_LEVEL_VISA_DLP};
+  const npu_profile_opt opt_visa = {.level = PROFILE_LEVEL_VISA};
+
+  int ret, num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_SOCIP);
+  ASSERT_GT (num_devices, 0);
+
+  auto api = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+  ModelProfiler *profiler = new ModelProfiler (api.get ());
+  ASSERT_NE (api.get (), nullptr);
+
+  npu_profile profile_dlp = {0};
+  npu_profile profile_visa = {0};
+
+  if (!std::ifstream (DLP_REC_PATH)) {
+    printf ("no rec file %s found\n", DLP_REC_PATH);
+    return;
+  }
+
+  ret = profiler->getProfile (1, opt_dlp, &profile_dlp, DLP_REC_PATH);
+  ASSERT_EQ (ret, 0);
+  ASSERT_EQ (profile_dlp.num_layers, 485);
+
+  ret = profiler->getProfile (1, opt_visa, &profile_visa, DLP_REC_PATH);
+  ASSERT_EQ (ret, 0);
+  ASSERT_EQ (profile_visa.num_layers, 284);
+}
+
+/**
+ * @brief main function for unit test
+ */
+int
+main (int argc, char **argv) {
+  return start_gtest (argc, argv);
+}