[VD/Kernel] Support multi-tensors of kernel requests
authorDongju Chae <dongju.chae@samsung.com>
Wed, 20 Oct 2021 05:24:37 +0000 (14:24 +0900)
committer채동주/On-Device Lab(SR)/Staff Engineer/삼성전자 <dongju.chae@samsung.com>
Wed, 20 Oct 2021 10:49:39 +0000 (19:49 +0900)
This patch supports multi-tensors of kernel requests.
Negative dmabuf values will be used for the indicator.

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

index f0a5ecd6ac8884e562a165e045a39d34525293f9..1c6183a656b2e73c4fb938107873303aab9f84d7 100644 (file)
@@ -1435,9 +1435,6 @@ TrinityVision2::submitRequest (int req_id) {
       status = scheduler_->submitRequest (req);
       if (status >= 0)
         sync.wait ();
-
-      /* remove the internal callback */
-      req->setCallback (nullptr);
     } break;
     case NPU_INFER_NON_BLOCKING:
       if (req->getCallback () == nullptr) {
@@ -1469,13 +1466,17 @@ TrinityVision2::submitRequestKernel (int req_id) {
   input_buffers input = {0};
   output_buffers output = {0};
 
-  input.num_buffers = 1;
-  input.bufs[0].type = BUFFER_DMABUF;
-  input.bufs[0].dmabuf = KERNEL_INPUT_SEG; /* indicator of kernel input */
+  input.num_buffers = model->getInputTensorNum ();
+  for (uint32_t i = 0; i < input.num_buffers; i++) {
+    input.bufs[i].type = BUFFER_DMABUF;
+    input.bufs[i].dmabuf = -1 * (int) (i + 1); /* indicator of kernel input */
+  }
 
-  output.num_buffers = 1;
-  output.bufs[0].type = BUFFER_DMABUF;
-  output.bufs[0].dmabuf = KERNEL_OUTPUT_SEG; /* indicator of kernel output */
+  output.num_buffers = model->getOutputTensorNum ();
+  for (uint32_t i = 0; i < output.num_buffers; i++) {
+    output.bufs[i].type = BUFFER_DMABUF;
+    output.bufs[i].dmabuf = -1 * (int) (i + 1 + MAX_TENSORS); /* indicator of kernel output */
+  }
 
   SegmentTable *segt = dynamic_cast<SegmentTable *> (req->getInferData ());
   if (segt != nullptr) {
index f526d040c22de1600d080bcf00fe41521321d98f..2acef2706b7faa4313fa61b754a59dc3b915a0ab 100644 (file)
@@ -161,9 +161,13 @@ Scheduler::handleCallback (Request *req) {
   if (!req->isStopped () && callback != nullptr)
     callback ();
 
-  /** the request instance is also deleted here */
-  if (!req->isPreserved ())
+  if (!req->isPreserved ()) {
+    /* the request instance is also deleted here */
     removeRequest (req);
+  } else if (req->getInferMode () == NPU_INFER_BLOCKING) {
+    /* remove the internal callback for next submissions */
+    req->setCallback (nullptr);
+  }
 }
 
 /**
index 2340889d3593c7ea1ccfe812e4906701f3f7c308..b3c21e2342f574df71c61491b2035026d82c455d 100644 (file)
@@ -58,13 +58,14 @@ SegmentTable::updateSegmentSlot (HWmem *hwmem, int slot) {
    * an inference. Note that each entry in segment table has 32-bits slot.
    */
   int dbuf_fd = hwmem->getDmabuf ();
-  if (dbuf_fd != KERNEL_INPUT_SEG && dbuf_fd != KERNEL_OUTPUT_SEG) {
+  if (dbuf_fd >= 0) {
     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 {
+    /* this is an external segment to be mapped in kernel */
     reinterpret_cast<int32_t *> (getData ())[slot] = dbuf_fd;
     reinterpret_cast<uint32_t *> (getData () + getSize () / 2)[slot] = hwmem->getSize ();
   }
index 3a3cd9e7f3bd37b97f82d66603abe291de5fa281..a8026c0f78ebc0a05110ce27b479ec4846941398 100644 (file)
@@ -20,9 +20,6 @@
 
 #include <vector>
 
-#define KERNEL_INPUT_SEG (-1)
-#define KERNEL_OUTPUT_SEG (-2)
-
 /** @brief segment table class derived from hwmem */
 class SegmentTable : public HWmem {
  public: