[Segment] adds segment size info. for external memory
authorDongju Chae <dongju.chae@samsung.com>
Fri, 2 Jul 2021 02:24:13 +0000 (11:24 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Fri, 2 Jul 2021 04:38:14 +0000 (13:38 +0900)
This patch adds segment size info. for external memory
to the segment table.

Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
src/core/ne-handler.cc
src/core/ne-segment-table.cc
src/core/ne-segment-table.h

index ceb5130..21e227e 100644 (file)
@@ -1408,11 +1408,11 @@ TrinityVision2::submitRequestKernel (int req_id) {
 
   input.num_buffers = 1;
   input.bufs[0].type = BUFFER_DMABUF;
-  input.bufs[0].dmabuf = -1; /* indicator of kernel input */
+  input.bufs[0].dmabuf = KERNEL_INPUT_SEG; /* indicator of kernel input */
 
   output.num_buffers = 1;
   output.bufs[0].type = BUFFER_DMABUF;
-  output.bufs[0].dmabuf = -2; /* indicator of kernel output */
+  output.bufs[0].dmabuf = KERNEL_OUTPUT_SEG; /* indicator of kernel output */
 
   segt = prepareSegmentTable (model, &input, &output);
 
index 588506d..c073471 100644 (file)
@@ -57,12 +57,19 @@ SegmentTable::updateSegmentSlot (HWmem *hwmem, int slot) {
    * to actual physical addresses, accessed by NPU hardware, before invoking
    * an inference. Note that each entry in segment table has 32-bits slot.
    */
-  reinterpret_cast<int32_t *> (getData ())[slot] = hwmem->getDmabuf ();
-  reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] =
-      hwmem->getOffset ();
-
-  if (hwmem->getOffset () % SEGMENT_ALIGN != 0)
-    logwarn (TAG, "Segment is not aligned..?\n");
+  int dbuf_fd = hwmem->getDmabuf ();
+  if (dbuf_fd != KERNEL_INPUT_SEG && dbuf_fd != KERNEL_OUTPUT_SEG) {
+    reinterpret_cast<int32_t *> (getData ())[slot] = dbuf_fd;
+    reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] =
+        hwmem->getOffset ();
+
+    if (hwmem->getOffset () % SEGMENT_ALIGN != 0)
+      logwarn (TAG, "Segment is not aligned..?\n");
+  } else {
+    reinterpret_cast<int32_t *> (getData ())[slot] = dbuf_fd;
+    reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] =
+        hwmem->getSize ();
+  }
 }
 
 /**
index 8a8d537..befea1c 100644 (file)
@@ -20,6 +20,9 @@
 
 #include <vector>
 
+#define KERNEL_INPUT_SEG (-1)
+#define KERNEL_OUTPUT_SEG (-2)
+
 /** @brief segment table class derived from hwmem */
 class SegmentTable : public HWmem {
  public: