From 6c0ebcb990e87c9621c9702e79986d1381c8b189 Mon Sep 17 00:00:00 2001 From: Wook Song Date: Thu, 30 May 2019 16:52:12 +0900 Subject: [PATCH] [Filter/MvNCSDK] Write callbacks for framework invocation This patch fills the body of the callback function for invoke_NN, which invokes the framework with the given network model. Signed-off-by: Wook Song --- .../tensor_filter/tensor_filter_movidius_ncsdk2.c | 53 +++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c b/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c index bd55195..a27ba4b 100644 --- a/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c +++ b/ext/nnstreamer/tensor_filter/tensor_filter_movidius_ncsdk2.c @@ -281,13 +281,63 @@ err_destroy_device_h: * @param[in] input : The array of input tensors * @param[out] output : The array of output tensors * @return 0 if OK. non-zero if error. - * @todo : fill this function */ static int _mvncsdk2_invoke (const GstTensorFilterProperties * prop, void **private_data, const GstTensorMemory * input, GstTensorMemory * output) { + ncStatus_t ret_code; + mvncsdk2_data *pdata = *private_data; + guint32 buf_size; + + g_return_val_if_fail (prop->input_configured, -1); + if (prop->input_meta.num_tensors != NNS_MVNCSDK2_MAX_NUM_TENOSORS_SUPPORTED) { + g_critical ("The number of input tensor should be one: " + "The MVNCSDK API supports single tensor input and output only"); + goto err_destroy; + } + + /* Warning: conversion unsigned long to unsigned int */ + buf_size = (guint32) input->size; + ret_code = ncFifoWriteElem(pdata->handle_fifo_input, input->data, + &buf_size, 0); + if (ret_code != NC_OK) { + g_printerr ("Cannot write input data to the FIFO buffer in the device"); + goto err_destroy; + } + + ret_code = ncGraphQueueInference(pdata->handle_graph, + &(pdata->handle_fifo_input), NNS_MVNCSDK2_MAX_NUM_TENOSORS_SUPPORTED, + &(pdata->handle_fifo_output), NNS_MVNCSDK2_MAX_NUM_TENOSORS_SUPPORTED); + if (ret_code != NC_OK) { + g_printerr ("Failed to run inference using the device\n"); + goto err_destroy; + } + + /* Warning: conversion unsigned long to unsigned int */ + buf_size = (guint32) output->size; + ret_code = ncFifoReadElem(pdata->handle_fifo_output, output->data, &buf_size, + NULL); + if (ret_code != NC_OK) { + g_printerr ("Cannot fetch inference results from the device\n"); + goto err_destroy; + } + return 0; + +err_destroy: + /** + * When this invoke callback is returned with -1, the whole pipeline is + * immediately terminated by g_assert() without any unref() or free() + * invocations. Until we fix this issue, the invoke callback calls the close() + * itself before returning. + */ + _mvncsdk2_close (prop, private_data); + + g_printerr ("Failed to call the invoke callback for the tensor_filter" + "framework, %s", prop->fwname); + + return -1; } /** @@ -337,7 +387,6 @@ _mvncsdk2_getOutputDim (const GstTensorFilterProperties * prop, struct ncTensorDescriptor_t *nc_output_desc = &(pdata->tensor_desc_output); GstTensorInfo *nns_output_info; - g_printerr ("data_type = %d\n", nc_output_desc->dataType); /** MVNCSDK only supports one tensor at a time */ info->num_tensors = NNS_MVNCSDK2_MAX_NUM_TENOSORS_SUPPORTED; nns_output_info = &(info->info[NNS_MVNCSDK2_MAX_NUM_TENOSORS_SUPPORTED -1]); -- 2.7.4