* Copyright (C) 2020 Dongju Chae <dongju.chae@samsung.com>
*/
/**
- * @file ne-dsp-input-service.c
+ * @file ne-hw-input-service.c
* @date 27 Feb 2020
- * @brief Handles input data from DSP to NPU for processing
+ * @brief Handles input data from third-party HW to NPU for processing
* @author Dongju Chae <dongju.chae@samsung.com>
* @bug No known bugs except for NYI items
*/
#define DEVICE_ID 2 /** @todo fix this */
#define TLB_NAME "srtlb"
-/** Get the dsp inservice element */
-#define DSP_PRIV(INPUT_SERVICE) ((dsp_priv_t *) INPUT_SERVICE->pdata)
+/** Get the hw inservice element */
+#define HW_PRIV(INPUT_SERVICE) ((hw_priv_t *) INPUT_SERVICE->pdata)
typedef struct {
/** private data structure per opened device */
int device_npu_id; /**< npu device number */
- int device_dsp_id; /**< dsp device number */
+ int device_hw_id; /**< hw device number */
int fd; /**< configured file descriptor */
int tlb_fd; /**< file descriptor of TLB driver */
/** could be changed during execution */
bool started; /**< check it was started */
-} dsp_priv_t;
+} hw_priv_t;
/**
* @brief private data structure for worker data
*/
typedef struct {
- dsp_priv_t *dpriv; /**< dsp private data */
+ hw_priv_t *hpriv; /**< hw private data */
config_priv_t config; /**< the configured setup */
npu_priority priority; /**< the inference priority */
uint64_t timestamp; /**< the timestamp when it was requested */
/**
* @brief register constructor and destructor functions
*/
-int init_dsp_inputservice(void) __attribute__ ((
+int init_hw_inputservice(void) __attribute__ ((
constructor(INPUTSERVICE_PRIORITY)));
-void fini_dsp_inputservice(void) __attribute__ ((
+void fini_hw_inputservice(void) __attribute__ ((
destructor(INPUTSERVICE_PRIORITY)));
/**
}
/**
- * @brief configure the dsp input service
+ * @brief configure the hw input service
*/
-static int configureDSP (inputservice *me, const model *m, n40_data *data)
+static int configureHW (inputservice *me, const model *m, n40_data *data)
{
int status = 0;
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
uint64_t model_base_offset;
npu_model_config model_config;
npubin_meta *meta;
- dpriv = DSP_PRIV (me);
- assert (dpriv);
+ hpriv = HW_PRIV (me);
+ assert (hpriv);
/** make sure that thread isnt created, else halt should be called */
- if (dpriv->started) {
+ if (hpriv->started) {
logerr(TAG, "Cannot configure device in non idle state of service\n");
return -EBUSY;
}
meta = m->meta;
- dpriv->config.model = m;
- dpriv->config.data = data;
+ hpriv->config.model = m;
+ hpriv->config.data = data;
/** set the mode for the device */
- if (meta->type == SMODEL_OPS_NPU_DSP) {
- dpriv->config.opmode = NPUINPUT_DSP;
- dpriv->config.fd = dpriv->config.npu_fd;
+ if (meta->type == SMODEL_OPS_RECURRING) {
+ hpriv->config.opmode = NPUINPUT_HW;
+ hpriv->config.fd = hpriv->config.npu_fd;
} else {
logerr(TAG, "Unknown metadata provided, type: %d\n", meta->type);
return -EINVAL;
}
- npu_set_mode (dpriv->config.fd, dpriv->config.opmode);
+ npu_set_mode (hpriv->config.fd, hpriv->config.opmode);
/** ensure npu is in ready state */
- status = npu_check_compute_ready(dpriv->config.fd);
+ status = npu_check_compute_ready(hpriv->config.fd);
if (status < 0) {
- logerr(TAG, "Cannot configure dsp in busy state of the device\n");
+ logerr(TAG, "Cannot configure HW in busy state of the device\n");
return status;
}
return status;
}
- /** dsp input service passes dmabuf id as dmabuf_id */
- model_config.dmabuf_id = get_dmabuf_id (dpriv->config.tlb_fd, m->memblock);
+ /** hw input service passes dmabuf id as dmabuf_id */
+ model_config.dmabuf_id = get_dmabuf_id (hpriv->config.tlb_fd, m->memblock);
if (model_config.dmabuf_id < 0) {
logerr(TAG, "Invalid dmabuf id for the provided model, errno: %d\n",
model_config.dmabuf_id);
return -EINVAL;
}
- /** setup model; @todo fix this when model for NPU-DSP is finalized*/
+ /** setup model; @todo fix this when model for the interface with HW is finalized*/
model_config.program_size = meta->program_size;
model_config.program_offset_addr = model_base_offset + NPUBIN_META_SIZE;
model_config.weight_offset_addr = model_base_offset + NPUBIN_META_SIZE +
model_config.program_size;
- status = npu_set_model(dpriv->config.fd, &model_config);
+ status = npu_set_model(hpriv->config.fd, &model_config);
if (status < 0) {
logerr(TAG, "Unable to set the model on the NPU\n");
return status;
}
- dpriv->config.model_id = model_config.model_id;
- assert (dpriv->config.model_id >= 0);
+ hpriv->config.model_id = model_config.model_id;
+ assert (hpriv->config.model_id >= 0);
}
return 0;
/**
* @brief halt the service
*/
-static int haltDSP (inputservice *me, n40_haltmode mode)
+static int haltHW (inputservice *me, n40_haltmode mode)
{
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
- dpriv = DSP_PRIV (me);
+ hpriv = HW_PRIV (me);
- if (!dpriv->started) {
+ if (!hpriv->started) {
logerr(TAG, "Halting device which has already been halted/not started\n");
return -EPERM;
}
assert (mode != HALT_NONE);
- /** just stop the DSP service */
- dpriv->started = false;
+ /** just stop the HW service */
+ hpriv->started = false;
return 0;
}
* @brief get the status for the service
* @todo need refactoring
*/
-static n40_status getStatusDSP (inputservice *me, model_opmode opmode)
+static n40_status getStatusHW (inputservice *me, model_opmode opmode)
{
n40_status nstatus;
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
- if (opmode != SMODEL_OPS_NPU_DSP)
+ if (opmode != SMODEL_OPS_RECURRING)
return N40_ERROR;
- dpriv = DSP_PRIV (me);
- assert (dpriv);
+ hpriv = HW_PRIV (me);
+ assert (hpriv);
- if (dpriv->started) {
+ if (hpriv->started) {
nstatus = N40_BUSY;
} else {
nstatus = N40_IDLE;
static int perform_inference (void *data)
{
work_priv_t *wpriv;
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
npu_input_config input_config;
uint64_t cur_timestamp;
assert (data);
wpriv = (work_priv_t *) data;
- dpriv = wpriv->dpriv;
+ hpriv = wpriv->hpriv;
- if (dpriv == NULL) {
- logerr (TAG, "Fail to find DSP inputservice\n");
+ if (hpriv == NULL) {
+ logerr (TAG, "Fail to find HW inputservice\n");
status = -EINVAL;
goto exit;
}
- /** check DSP inputservice first */
- pthread_mutex_lock(dpriv->mutex);
- if (!dpriv->started) {
- pthread_mutex_unlock(dpriv->mutex);
+ /** check HW inputservice first */
+ pthread_mutex_lock(hpriv->mutex);
+ if (!hpriv->started) {
+ pthread_mutex_unlock(hpriv->mutex);
status = 0;
goto exit;
}
- pthread_mutex_unlock(dpriv->mutex);
+ pthread_mutex_unlock(hpriv->mutex);
/** @todo set ioctl argument correctly */
input_config.enable = 1;
"but still work without any errors\n");
}
- /** DSP does not require callback handling */
+ /** HW does not require callback handling */
exit:
free (wpriv);
/**
* @brief start the input service
*/
-static int startDSP (inputservice *me)
+static int startHW (inputservice *me)
{
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
- dpriv = DSP_PRIV (me);
- assert (dpriv);
+ hpriv = HW_PRIV (me);
+ assert (hpriv);
- if (dpriv->started) {
+ if (hpriv->started) {
logerr(TAG, "Cannot start already-started service\n");
return -EBUSY;
}
- dpriv->started = true;
+ hpriv->started = true;
return 0;
}
/**
* @brief move to the next input data
*/
-static int nextDSP (inputservice *me, buffer *buffer,
+static int nextHW (inputservice *me, buffer *buffer,
npu_priority priority, uint64_t timestamp)
{
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
work_priv_t *wpriv;
int status;
- dpriv = DSP_PRIV (me);
- assert (dpriv);
+ hpriv = HW_PRIV (me);
+ assert (hpriv);
- if (!dpriv->started) {
- logerr(TAG, "Cannot feed dsp input to unstarted input service\n");
+ if (!hpriv->started) {
+ logerr(TAG, "Cannot feed HW input to unstarted input service\n");
return -EINVAL;
}
if (!wpriv)
return -ENOMEM;
- memcpy (&wpriv->config, &dpriv->config, sizeof(config_priv_t));
- wpriv->dpriv = dpriv;
+ memcpy (&wpriv->config, &hpriv->config, sizeof(config_priv_t));
+ wpriv->hpriv = hpriv;
wpriv->priority = priority;
wpriv->timestamp = timestamp;
/**
* @brief open the input service device
* @param[in] device_id device number of npu for the input service
- * @param[in] dpriv dsp service private obj
+ * @param[in] hpriv hw service private obj
* @return 0 on success, errno on failure
* @note at least one NPU device should be opened
*/
-static int open_dsp_inputservice (int device_id, dsp_priv_t *dpriv)
+static int open_hw_inputservice (int device_id, hw_priv_t *hpriv)
{
- dpriv->config.npu_fd = npu_open(device_id, NPUCOND_CONN_SOCIP);
- if (dpriv->config.npu_fd < 0) {
- logerr(TAG, "Failed to open the NPU device, errno = %d\n", dpriv->config.npu_fd);
+ hpriv->config.npu_fd = npu_open(device_id, NPUCOND_CONN_SOCIP);
+ if (hpriv->config.npu_fd < 0) {
+ logerr(TAG, "Failed to open the NPU device, errno = %d\n", hpriv->config.npu_fd);
} else {
- dpriv->config.device_npu_id = device_id;
+ hpriv->config.device_npu_id = device_id;
}
- return (dpriv->config.npu_fd >= 0);
+ return (hpriv->config.npu_fd >= 0);
}
/**
* @brief deregister the dsp input service
- * @param[in] dpriv dsp service private obj
+ * @param[in] hpriv dsp service private obj
*/
-static void close_dsp_inputservice (dsp_priv_t *dpriv)
+static void close_hw_inputservice (hw_priv_t *hpriv)
{
int status;
- if (dpriv->config.npu_fd >= 0) {
- status = npu_close (dpriv->config.npu_fd);
+ if (hpriv->config.npu_fd >= 0) {
+ status = npu_close (hpriv->config.npu_fd);
if (status < 0)
logwarn(TAG, "Fail to close npu device, (fd:%d, err: %d)\n",
- dpriv->config.npu_fd, status);
+ hpriv->config.npu_fd, status);
}
}
/**
- * @brief dsp inputservice object
+ * @brief hw inputservice object
*/
-static inputservice dsp_inputservice = {
- .configure = configureDSP,
- .halt = haltDSP,
- .getStatus = getStatusDSP,
- .start = startDSP,
- .next = nextDSP,
+static inputservice hw_inputservice = {
+ .configure = configureHW,
+ .halt = haltHW,
+ .getStatus = getStatusHW,
+ .start = startHW,
+ .next = nextHW,
};
/**
- * @brief Start the dsp input service
+ * @brief Start the hw input service
*/
-int init_dsp_inputservice (void)
+int init_hw_inputservice (void)
{
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
int status;
- dpriv = (dsp_priv_t *) malloc(sizeof(dsp_priv_t));
- if (dpriv == NULL) {
+ hpriv = (hw_priv_t *) malloc(sizeof(hw_priv_t));
+ if (hpriv == NULL) {
return -ENOMEM;
}
- memset (dpriv, 0, sizeof (dsp_priv_t));
- dpriv->mutex = &dsp_inputservice.mutex;
- dpriv->cond = &dsp_inputservice.cond;
+ memset (hpriv, 0, sizeof (hw_priv_t));
+ hpriv->mutex = &hw_inputservice.mutex;
+ hpriv->cond = &hw_inputservice.cond;
if ((status = tlb_open (TLB_NAME)) < 0) {
logerr (TAG, "Fail to open a TLB driver\n");
- free (dpriv);
+ free (hpriv);
return status;
}
- dpriv->config.tlb_fd = status;
+ hpriv->config.tlb_fd = status;
- if ((status = open_dsp_inputservice (DEVICE_ID, dpriv)) < 0) {
- tlb_close (dpriv->config.tlb_fd);
- free (dpriv);
+ if ((status = open_hw_inputservice (DEVICE_ID, hpriv)) < 0) {
+ tlb_close (hpriv->config.tlb_fd);
+ free (hpriv);
return status;
}
- pthread_mutex_init(dpriv->mutex, NULL);
- pthread_cond_init(dpriv->cond, NULL);
+ pthread_mutex_init(hpriv->mutex, NULL);
+ pthread_cond_init(hpriv->cond, NULL);
- dsp_inputservice.pdata = (void *) dpriv;
- dsp_inputservice.initialized = 1;
- status = n40_register_input_service (SMODEL_OPS_NPU_DSP, &dsp_inputservice);
+ hw_inputservice.pdata = (void *) hpriv;
+ hw_inputservice.initialized = 1;
+ status = n40_register_input_service (SMODEL_OPS_RECURRING, &hw_inputservice);
if (status < 0) {
- pthread_mutex_destroy(dpriv->mutex);
- pthread_cond_destroy(dpriv->cond);
- close_dsp_inputservice (dpriv);
- tlb_close (dpriv->config.tlb_fd);
- free (dpriv);
- dsp_inputservice.initialized = 0;
+ pthread_mutex_destroy(hpriv->mutex);
+ pthread_cond_destroy(hpriv->cond);
+ close_hw_inputservice (hpriv);
+ tlb_close (hpriv->config.tlb_fd);
+ free (hpriv);
+ hw_inputservice.initialized = 0;
return status;
}
}
/**
- * @brief Terminate dsp input service
+ * @brief Terminate hw input service
*/
-void fini_dsp_inputservice (void)
+void fini_hw_inputservice (void)
{
- dsp_priv_t *dpriv;
+ hw_priv_t *hpriv;
- if (dsp_inputservice.initialized == 1) {
- dpriv = dsp_inputservice.pdata;
+ if (hw_inputservice.initialized == 1) {
+ hpriv = hw_inputservice.pdata;
/** free all resources */
- n40_unregister_input_service (SMODEL_OPS_NPU_DSP);
+ n40_unregister_input_service (SMODEL_OPS_RECURRING);
- pthread_mutex_destroy(dpriv->mutex);
- pthread_cond_destroy(dpriv->cond);
+ pthread_mutex_destroy(hpriv->mutex);
+ pthread_cond_destroy(hpriv->cond);
- close_dsp_inputservice (dpriv);
- tlb_close (dpriv->config.tlb_fd);
+ close_hw_inputservice (hpriv);
+ tlb_close (hpriv->config.tlb_fd);
/** fini done */
- dsp_inputservice.initialized = 0;
- free (dpriv);
+ hw_inputservice.initialized = 0;
+ free (hpriv);
}
}