[libnpuhost] Add the API to get DSPM size of DSP HW.
authorDongju Chae <dongju.chae@samsung.com>
Thu, 11 Mar 2021 03:41:35 +0000 (12:41 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Fri, 12 Mar 2021 08:40:19 +0000 (17:40 +0900)
This patch adds the API to get DSPM size of DSP HW.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
include/common/npubinfmt.h
include/host/libnpuhost.h
src/core/ne-handler.cc
src/core/ne-handler.h
src/core/npu/NPUdrvAPI.h
src/core/npu/NPUdrvAPI_triv2.cc
src/host/ne-host.cc

index b05d88a..43439e8 100644 (file)
@@ -224,7 +224,7 @@ typedef struct {
           float output_seg_quant_s[MAX_TENSORS];            /**< output quantization parameter (scale) */
 
           /** DSP-specific variables */
-          uint32_t dspm_size;                               /**< The size of DSP memory */
+          uint32_t dspm_size;                               /**< The data scratch-pad memory (dspm) size of the DSP */
 
           /** vISA instructions */
           uint32_t visa_num_plus_one;                       /**< Number of vISA insts + 1 (i.e., unknown if zero) */
index f44d174..8c08fe3 100644 (file)
@@ -102,6 +102,15 @@ int getNPU_driverAPILevel (npudev_h dev, uint32_t *level);
 int getNPU_tops (npudev_h dev, uint32_t *tops);
 
 /**
+ * @brief Get the DSP DSPM size of the opened NPU device
+ * @param[in] dev the NPU device handle
+ * @param[out] dspm dspm size
+ * @return 0 if no error, otherwise a negative errno
+ * @note this does not support for emulated devices
+ */
+int getNPU_dspmSize (npudev_h dev, uint32_t *dspm);
+
+/**
  * @brief Get metadata for NPU model
  * @param[in] model The path of model binary file
  * @param[in] need_extra whether you want to extract the extra data in metadata
index cdb301a..17b2c14 100644 (file)
@@ -210,6 +210,21 @@ HostHandler::getTops (uint32_t *tops)
 }
 
 /**
+ * @brief Get the DSP DSPM size of the opened NPU device
+ * @param[in] dev the NPU device handle
+ * @param[out] dspm dspm size
+ * @return 0 if no error, otherwise a negative errno
+ * @note this does not support for emulated devices
+ */
+int
+HostHandler::getDspmSize (uint32_t *dspm)
+{
+  const DriverAPI * api = device_->getDriverAPI ();
+  assert (api != nullptr);
+
+  return api->getDspmSize (dspm);
+}
+/**
  * @brief Set the data layout for input/output tensors
  * @param[in] modelid The ID of model whose layouts are set
  * @param[in] in the layout/type info for input tensors
index 91774d3..47b41ab 100644 (file)
@@ -37,6 +37,7 @@ class HostHandler {
     int getProfile (int run_id, npu_profile *profile);
     int getAPILevel (uint32_t *level);
     int getTops (uint32_t *tops);
+    int getDspmSize (uint32_t *dspm);
 
     int setDataInfo (uint32_t modelid, tensors_data_info *in, tensors_data_info *out);
     int setConstraint (uint32_t modelid, npuConstraint constraint);
index 315e7ca..fbe813a 100644 (file)
@@ -68,6 +68,7 @@ class DriverAPI {
     virtual int open () { return -ENODEV; }
     virtual int getAPILevel (uint32_t *level) const { return -EPERM; }
     virtual int getTops (uint32_t *tops) const { return -EPERM; }
+    virtual int getDspmSize (uint32_t *dspm) const { return -EPERM; }
 
     virtual int checkSanity () { return 0; }
 
@@ -135,6 +136,7 @@ class TrinityVision2API : public DriverAPI {
     int checkSanity ();
     int getAPILevel (uint32_t *level) const;
     int getTops (uint32_t *tops) const;
+    int getDspmSize (uint32_t *dspm) const;
 
     device_state_t isReady () const;
     uint32_t numRequests () const;
index e1334a6..175e0b3 100644 (file)
@@ -514,6 +514,21 @@ TrinityVision2API::getTops (uint32_t *tops) const
 }
 
 int
+TrinityVision2API::getDspmSize (uint32_t *dspm) const
+{
+  int ret;
+
+  if (!this->initialized())
+    return -EPERM;
+
+  ret = ioctl (this->getDeviceFD (), TRINITY_IOCTL_GET_DSPM, dspm);
+  if (ret != 0)
+    return -errno;
+
+  return ret;
+}
+
+int
 TrinityVision2API::getStatApps (npu_stat_apps *stat) const
 {
   struct trinity_ioctl_stat_apps stat_apps;
index f1b2d5d..32174e2 100644 (file)
@@ -159,6 +159,23 @@ int getNPU_tops (npudev_h dev, uint32_t *tops)
 }
 
 /**
+ * @brief Get the DSP DSPM size of the opened NPU device
+ * @param[in] dev the NPU device handle
+ * @param[out] dspm dspm size
+ * @return 0 if no error, otherwise a negative errno
+ * @note this does not support for emulated devices
+ */
+int getNPU_dspmSize (npudev_h dev, uint32_t *dspm)
+{
+  INIT_HOST_HANDLER (host_handler, dev);
+
+  if (dspm == nullptr)
+    return -EINVAL;
+
+  return host_handler->getDspmSize (dspm);
+}
+
+/**
  * @brief Get the profile information from NPU
  * @param[in] dev The NPU device handle
  * @param[in] task_id The identifier for each inference