[EMUL] Use device type for dspm size
authorJiho Chu <jiho.chu@samsung.com>
Mon, 27 Feb 2023 06:56:01 +0000 (15:56 +0900)
committer추지호/NPU Lab(SR)/삼성전자 <jiho.chu@samsung.com>
Tue, 7 Mar 2023 00:45:20 +0000 (09:45 +0900)
This patch implemnts dspm size for each device.

Each device has own dspm memory, and it needs to be device type for
presenting the size.

Signed-off-by: Jiho Chu <jiho.chu@samsung.com>
src/core/ne-handler.cc
src/core/ne-handler.h
src/core/npu/NPUdrvAPI_emul.cc
src/host/ne-host.cc
tests/unittests/ne_core_handler_test.cc
tests/unittests/ne_core_npu_test.cc

index 672eb07e416f98f7e8658fc70d04c9488b1ac723..7c0af1aa1ab3863c65c6eaa7d299cddf32cf7821 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "ne-handler.h"
 #include "ne-data.h"
+#include "typedef.h"
 
 #include <npubinfmt.h>
 #include <NPUdrvAPI.h>
@@ -756,7 +757,7 @@ Device::createInstance (dev_type type, int id) {
 
   switch (type & DEVICETYPE_MASK) {
     case DEVICETYPE_TRIV2:
-      device = new TrinityVision2 (id);
+      device = new TrinityVision2 ((type & DEVICEVERSION_MASK), id);
       break;
     case DEVICETYPE_DEPR:
       logwarn (TAG, "You're trying to open deprecated devices..\n");
index 17d509f8d1fad89fec3d4d25726150a65750e68f..46c87c09b13e4c41d16cd3be12a975d66ffb1c03 100644 (file)
@@ -180,7 +180,8 @@ class Device {
 /** @brief Trinity Vision2 (TRIV2) class */
 class TrinityVision2 : public Device {
  public:
-  TrinityVision2 (int id) : Device (NPUCOND_TRIV23_CONN_SOCIP, id) {}
+  TrinityVision2 (int dev_ver, int id)
+      : Device (dev_type (DEVICETYPE_TRIV2 | DEVICEGROUP_SOCIP | dev_ver), id) {}
   ~TrinityVision2 () {}
 
   static size_t manipulateData (const Model *model, uint32_t idx, bool is_input, void *dst,
index d25bfcc02389b0ad857b350e3fc6f6930691e347..79848694d36df1eecbb753e5139f8cfb3d8db1f1 100644 (file)
 #include <iostream>
 
 #define TAG _N94
-#define MAX_EMUL_DEVICES (4)
+#define MAX_EMUL_DEVICES (3)
 #define TRIV23_DEFAULT_DSPM_SIZE (128 * 1024) /* 128 KiB */
-#define TRIV24_DEFAULT_DSPM_SIZE (256 * 1024) /* 128 KiB */
-#define RESERVED_DSPM_SIZE (64 * 1024) /* 64 KiB */
+#define TRIV24_DEFAULT_DSPM_SIZE (256 * 1024) /* 256 KiB */
+#define RESERVED_DSPM_SIZE (64 * 1024)        /* 64 KiB */
 #define ENVNAME_DSPM_SIZE ("MRPSIM_SPM_SIZE")
 
 namespace {
@@ -441,7 +441,17 @@ TrinityEmulAPI::getDspmSize (uint32_t *dspm) const {
     return -EINVAL;
   }
 
-  *dspm = TRIV23_DEFAULT_DSPM_SIZE;
+  switch (dev_type_) {
+    case dev_type::NPUCOND_TRIV2_CONN_SOCIP:
+      *dspm = TRIV23_DEFAULT_DSPM_SIZE;
+      break;
+    case dev_type::NPUCOND_TRIV24_CONN_SOCIP:
+      *dspm = TRIV24_DEFAULT_DSPM_SIZE;
+      break;
+    default:
+      logerr (TAG, "Invalid device type");
+      return -EINVAL;
+  }
 
   char *dspm_str = getenv (ENVNAME_DSPM_SIZE);
   if (dspm_str != NULL) {
index 3a8d34becca16a552ef2c424f0265d23bbb82e92..d7604b829920b17604b9d7f27c322f479f4f3673 100644 (file)
@@ -44,6 +44,7 @@ getVersion (uint32_t *major, uint32_t *minor, uint32_t *extra) {
 
 /**
  * @brief Returns the number of available NPU devices.
+ * @param[in] type the NPU device type
  * @return @c The number of NPU devices.
  * @retval 0 if no NPU devices available. if positive (number of NPUs) if NPU devices available. otherwise, a negative error value.
  * @note the caller should call putNPUdevice() to release the device handle
@@ -56,6 +57,7 @@ getnumNPUdeviceByType (dev_type type) {
 /**
  * @brief Returns the handle of the chosen NPU devices.
  * @param[out] dev The NPU device handle
+ * @param[in] type the NPU device type
  * @param[in] id The NPU id to get the handle. 0 <= id < getnumNPUdeviceByType().
  * @return @c 0 if no error. otherwise a negative error value
  * @note the caller should call putNPUdevice() to release the device handle
index 675d6e91bca1249db6397724316f914d3ca6e584..fd232263209672862cf5798cd1ea001328fa9f40 100644 (file)
@@ -81,7 +81,7 @@ TEST (ne_core_handler_test, device_instance_uninitilized_n) {
   EXPECT_GT (num_devices, 0);
 
   /** directly creating a device instance but not initialized */
-  std::unique_ptr<Device> triv2 (new TrinityVision2 (0));
+  std::unique_ptr<Device> triv2 (new TrinityVision2 (3, 0));
   EXPECT_EQ (triv2->initialized (), false);
 
   void *addr = nullptr;
index 39f2646f894ff318d2670ac479779961deef3b4c..c9a0e3121aa5d1845f569987997bc3ae320e529a 100644 (file)
@@ -20,6 +20,7 @@
 #include <future>
 #include <mutex>
 #include <thread>
+#include "typedef.h"
 
 #include <ne_test_utils_gtest.h>
 
@@ -69,6 +70,25 @@ TEST (ne_core_npu_test, get_num_devices_deprecated_n) {
   EXPECT_LE (num_devices, 0);
 }
 
+/**
+ * @brief check device dspm size
+ */
+TEST (ne_core_npu_test, check_dev_dspm_size) {
+  int num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV2_CONN_UNKNOWN);
+  ASSERT_GT (num_devices, 0);
+  num_devices = DriverAPI::getNumDevices (NPUCOND_TRIV24_CONN_UNKNOWN);
+  ASSERT_GT (num_devices, 0);
+
+  auto api_23 = DriverAPI::createDriverAPI (NPUCOND_TRIV2_CONN_SOCIP, 0);
+  uint32_t dspm_size;
+  EXPECT_EQ (api_23->getDspmSize (&dspm_size), 0);
+  EXPECT_EQ (dspm_size, 64 * 1024);
+
+  auto api_24 = DriverAPI::createDriverAPI (NPUCOND_TRIV24_CONN_SOCIP, 0);
+  EXPECT_EQ (api_24->getDspmSize (&dspm_size), 0);
+  EXPECT_EQ (dspm_size, 192 * 1024);
+}
+
 /**
  * @brief check device statuses
  */