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);
* 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 ();
+ }
}
/**
#include <vector>
+#define KERNEL_INPUT_SEG (-1)
+#define KERNEL_OUTPUT_SEG (-2)
+
/** @brief segment table class derived from hwmem */
class SegmentTable : public HWmem {
public: