This patch adds new API to check the device status before running.
It's one of VD requirments in July release.
Signed-off-by: Dongju Chae <dongju.chae@samsung.com>
} npu_notimode;
/**
+ * @brief Description of npu device status
+ */
+typedef enum {
+ NPU_ERROR = 0, /**< The NPU is not available for now (check the log file for details) */
+ NPU_READY = 1, /**< The NPU is available but the request can be delayed due to others */
+ NPU_IDLE = 2, /**< The NPU is available and there's no active request currently */
+} npu_status;
+
+/**
* @brief Operable modes of NPU when the inputs are from NPU's own hardware.
* @note this mode will decide which input service performs the inference of a model.
*/
int getNPU_memoryStatus(npudev_h dev, size_t *alloc_total, size_t *free_total);
/**
+ * @brief Get the current device status to be used
+ * @param[in] dev The NPU device handle
+ * @param[out] status the device status
+ * @param[out] num_requests the number of running requests (or pending)
+ * @return 0 if no error, otherwise a negative errno.
+ */
+int getNPU_deviceStatus(npudev_h dev, npu_status *status, uint32_t *num_requests);
+
+/**
* [IMPORTANT] Descriptions for buffer allocation APIs.
*
* NPU Engine provides some APIs to allocate model and input buffers for users.
/** @todo func prototype TBD */
int getRegisteredNPUmodels(npudev_h dev, uint32_t **modelids, uint32_t *nummodels);
-/** @todo func prototype TBD */
int waitNPUrun(npudev_h dev);
/** @todo func prototype TBD */
-int getNPUrunStatus(npudev_h dev, uint64_t *status);
-
-/** @todo func prototype TBD */
-int getNPUstatus(npudev_h dev, uint64_t *status);
+int getNPU_runStatus(npudev_h dev, uint64_t *status);
#if defined(__cplusplus)
}
}
/**
+ * @brief Get the current device status to be used
+ * @param[in] dev The NPU device handle
+ * @param[out] status the device status
+ * @param[out] num_requests the number of running requests (or pending)
+ * @return 0 if no error, otherwise a negative errno.
+ */
+int getNPU_deviceStatus(npudev_h dev, npu_status *status, uint32_t *num_requests)
+{
+ INIT_HOST_HANDLER (host_handler, dev);
+
+ return host_handler->getDeviceStatus (status, num_requests);
+}
+
+/**
* @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
return api->getMemoryStatus (alloc_total, free_total);
}
+/**
+ * @brief Get the current device status to be used
+ * @param[out] status the device status
+ * @param[out] num_requests the number of running requests (or pending)
+ * @return 0 if no error, otherwise a negative errno.
+ */
+int
+HostHandler::getDeviceStatus (npu_status *status, uint32_t *num_requests)
+{
+ /** API is always set in initialize () */
+ const DriverAPI * api = device_->getDriverAPI ();
+ assert (api != nullptr);
+
+ device_state_t state = api->isReady ();
+ if (state == device_state_t::STATE_READY) {
+ *num_requests = api->numRequests ();
+ if (*num_requests > 0)
+ *status = NPU_READY;
+ else
+ *status = NPU_IDLE;
+ } else {
+ *num_requests = 0;
+ *status = NPU_ERROR;
+ }
+
+ return 0;
+}
+
/** implement methods of Device class */
/** @brief constructor of device */
/** @brief get statistics */
int getMemoryStatus (size_t *alloc_total, size_t *free_total);
+ int getDeviceStatus (npu_status *status, uint32_t *num_requests);
static int getNumDevices (dev_type type);
static int getDevice (npudev_h *dev, dev_type type, uint32_t id);
/** @brief check whether the device is ready (true) or busy (false) */
virtual device_state_t isReady () const { return device_state_t::STATE_UNKNOWN; }
+ /** @brief return a number of requests submitted */
+ virtual uint32_t numRequests () const { return 0; }
+
/** @brief allocate memory with the given size. return dmabuf fd */
virtual int alloc (size_t size) const { return -EPERM; }
/** @brief deallocate memory with the corresponding dmabuf fd */