[utils] add testenv for npu version selection
authorYelin Jeong <yelini.jeong@samsung.com>
Thu, 4 May 2023 02:48:14 +0000 (11:48 +0900)
committer추지호/SoC Architecture팀(SR)/삼성전자 <jiho.chu@samsung.com>
Tue, 9 May 2023 08:23:43 +0000 (17:23 +0900)
This patch adds testenv for npu version selection when testing

Signed-off-by: Yelin Jeong <yelini.jeong@samsung.com>
tests/utils/ne_test_utils.cc
tests/utils/ne_test_utils.h

index c00e7952622215eba85c12888fe026473e86bc87..1ceaea29fb1c6f0aec47bbd425e325f906205e4f 100644 (file)
@@ -867,3 +867,53 @@ UtilTRIV2::prepare_model (UtilModel *model) {
   return allocNPU_genericBuffers (dev_, output);
 #endif
 }
+
+UtilTestEnv::UtilTestEnv () {
+  int status = set_info ();
+
+  if (status < 0) {
+    std::cerr << "Failed to create UtilTestEnv instance\n";
+    return;
+  }
+}
+
+UtilTestEnv::~UtilTestEnv () {
+  if (devices_ != NULL)
+    free (devices_);
+}
+
+int
+UtilTestEnv::set_info () {
+  const char *npu_ver = getenv ("NPU_VER");
+
+  if (devices_ != NULL)
+    free (devices_);
+
+  dev_len_ = 2;
+  devices_ = (dev_type *) calloc (dev_len_, sizeof (dev_type));
+
+  if (!devices_) {
+    std::cerr << "Failed to allocate device list\n";
+    return -ENOMEM;
+  }
+
+  /* default NPU version for testing is 2.4 */
+  if (npu_ver == NULL || strcmp (npu_ver, "2.4") == 0) {
+    devices_[0] = NPUCOND_TRIV24_CONN_UNKNOWN;
+    devices_[1] = NPUCOND_TRIV24_CONN_SOCIP;
+    version_ = 0x04000402;
+    model_ = "/testdata/TRIV242/CONV_2D_000";
+    tops_ = 4;
+  } else if (strcmp (npu_ver, "2.3") == 0) {
+    devices_[0] = NPUCOND_TRIV23_CONN_UNKNOWN;
+    devices_[1] = NPUCOND_TRIV23_CONN_SOCIP;
+    version_ = 0x02080302;
+    model_ = "/testdata/TRIV238_2TOPS/CONV_2D_000";
+    tops_ = 2;
+  } else {
+    std::cerr << "Incompatible environmental variable npu version : " << npu_ver << "\n";
+    return -EINVAL;
+  }
+
+  return 0;
+}
index 9af87ef07b8f39c063647a7d383f6e77fd4a7c57..c516b5656c3d1e54ec1acc65e6e93834617a62e7 100644 (file)
@@ -180,6 +180,7 @@ class UtilTrinity {
 class UtilTRIV2 : public UtilTrinity {
  public:
   UtilTRIV2 () : UtilTrinity (NPUCOND_TRIV24_CONN_SOCIP, true, true) {}
+  UtilTRIV2 (dev_type type) : UtilTrinity (type, true, true) {}
 
  private:
   bool check_version (npubin_meta *meta);
@@ -188,6 +189,25 @@ class UtilTRIV2 : public UtilTrinity {
   bool extract_node_id (uint32_t *id);
 };
 
+class UtilTestEnv {
+ public:
+  UtilTestEnv ();
+  ~UtilTestEnv ();
+  int set_info ();
+  dev_type *get_devices () { return devices_; }
+  int get_dev_len () { return dev_len_; }
+  uint64_t get_version () { return version_; }
+  std::string get_model () { return model_; }
+  uint32_t get_tops () { return tops_; }
+
+ private:
+  dev_type *devices_;
+  int dev_len_;
+  uint64_t version_;
+  std::string model_;
+  uint32_t tops_;
+};
+
 extern "C" {
 #endif