From b4d7abb9bed1001efc59bf81f3f2e4fc5893404c Mon Sep 17 00:00:00 2001 From: Dongju Chae Date: Fri, 19 Jul 2019 11:17:13 +0900 Subject: [PATCH] [N4C] Make only N4C call .getNextBuffer() in N7 This commit adds getNextBuffer wrappers in N2 and N3, and append prefixes. Signed-off-by: Dongju Chae --- core/npu-engine/src/ne-handler.c | 15 +++++++++++---- core/npu-engine/src/ne-inf.c | 8 +++++++- core/npu-engine/src/ne-inf.h | 11 +++++++++-- core/npu-engine/src/ne-mem.h | 8 +++++--- core/npu-engine/src/ne-scheduler.c | 25 +++++++++++++++---------- core/npu-engine/src/ne-scheduler.h | 15 +++++++++++---- 6 files changed, 58 insertions(+), 24 deletions(-) diff --git a/core/npu-engine/src/ne-handler.c b/core/npu-engine/src/ne-handler.c index cab4006..ce7286e 100644 --- a/core/npu-engine/src/ne-handler.c +++ b/core/npu-engine/src/ne-handler.c @@ -358,7 +358,7 @@ handler_set_op_mode (npu_input_opmode op, bool force, model* m, output_ready cb, HANDLER_UNLOCK (); - return setOpMode (op, force, m, n2_cb, cb_data); + return n3_setOpMode (op, force, m, n2_cb, cb_data); } /** @@ -372,7 +372,7 @@ handler_set_op_mode (npu_input_opmode op, bool force, model* m, output_ready cb, static buffer* handler_get_current_input_buffer (int *err) { - return GET_MEM()->get_next_buffer(BUFFER_ROLE_INPUT, err); + return n3_getNextBuffer(BUFFER_ROLE_INPUT, err); } /** @@ -385,7 +385,7 @@ handler_get_current_input_buffer (int *err) static buffer* handler_get_current_output_buffer (int *err) { - return GET_MEM()->get_next_buffer(BUFFER_ROLE_OUTPUT, err); + return n3_getNextBuffer(BUFFER_ROLE_OUTPUT, err); } /** @@ -398,12 +398,19 @@ handler_get_current_output_buffer (int *err) static int handler_validate_buffer (buffer *buffer) { + int err; + if (!buffer) { logerr (TAG, "Empty buffer (NULL) provided\n"); return -EINVAL; } - return GET_MEM()->return_buffer (buffer); + if ((err = GET_MEM()->return_buffer (buffer)) < 0) { + logerr (TAG, "Fail to validate buffer\n"); + return err; + } + + return n3_dataReady (); } /** diff --git a/core/npu-engine/src/ne-inf.c b/core/npu-engine/src/ne-inf.c index 31f85fd..2aa8eab 100644 --- a/core/npu-engine/src/ne-inf.c +++ b/core/npu-engine/src/ne-inf.c @@ -109,10 +109,16 @@ int n4_configure(n4_opmode op, submodel *m, output_ready cb, void *cb_data) { } /** @brief Allows to enter host input data. For more detail, refer to the header */ -int n4_dataReady(buffer *buffer) { +int n4_dataReady(void) { return 0; } +/** @brief Get the next I/O buffer dedicated to the requsted role */ +buffer *n4_getNextBuffer (buffer_role role, int *err) +{ + return GET_MEM()->get_next_buffer (role, err); +} + /** This part is for N40 default implementation */ /** * @brief Register the input service implementation for N4C. For more detail, refer to N40 header. diff --git a/core/npu-engine/src/ne-inf.h b/core/npu-engine/src/ne-inf.h index dee11d0..09deaa6 100644 --- a/core/npu-engine/src/ne-inf.h +++ b/core/npu-engine/src/ne-inf.h @@ -67,9 +67,16 @@ extern int n4_configure(n4_opmode op, submodel *m, output_ready cb, void *cb_dat /** * @brief Allows to enter host input data. - * @param[in] buffer The buffer with input data. Use offset/size values of input. * @return 0 if success, otherwise negative error numbers. */ -extern int n4_dataReady(buffer *buffer); +extern int n4_dataReady(void); + +/** + * @brief get the next I/O buffer dedicated to the requsted role. + * @param[in] role the role of buffer + * @param[out] err set with error-number if there is an error + * @return the next buffer if no error, otherwise NULL + */ +extern buffer *n4_getNextBuffer (buffer_role role, int *err); #endif /* __NPU_ENGINE_N4_INFERENCE_H__ */ diff --git a/core/npu-engine/src/ne-mem.h b/core/npu-engine/src/ne-mem.h index cea50ff..94b36bf 100644 --- a/core/npu-engine/src/ne-mem.h +++ b/core/npu-engine/src/ne-mem.h @@ -192,18 +192,20 @@ typedef struct { /** * @brief switch the role of each I/O buffer (in triple buffering) - * @note This should be called only in N4x. + * @note This SHOULD be called in N4x only. */ void (*switch_buffers) (void); /** * @brief get the next I/O buffer dedicated to the requsted role. * @param[in] role the role of buffer + * @param[out] err set with error-number if there is an error * @return the next buffer if no error, otherwise NULL * - * @note it needs to wait to get a valid buffer if another component is still using it. + * @note This SHOULD be called in N4x only. + * It needs to wait to get a valid buffer if another component is still using it. */ - buffer * (*get_next_buffer) (buffer_role role); + buffer * (*get_next_buffer) (buffer_role role, int *err); /** * @brief return the buffer for next requesters diff --git a/core/npu-engine/src/ne-scheduler.c b/core/npu-engine/src/ne-scheduler.c index 0f61f2c..c32109b 100644 --- a/core/npu-engine/src/ne-scheduler.c +++ b/core/npu-engine/src/ne-scheduler.c @@ -98,8 +98,8 @@ n3_cb (buffer *buf, uint64_t offset, uint64_t size, void *data) * @param[in] cb_data The private data to be given to the callback. * @return @c 0 if success. otherwise, -ERRNO. */ -int setOpMode(npu_input_opmode op, int force, model *model, - output_ready cb, void *cb_data) +int n3_setOpMode(npu_input_opmode op, int force, model *model, + output_ready cb, void *cb_data) { n4_opmode n4_op; int err; @@ -147,23 +147,28 @@ int setOpMode(npu_input_opmode op, int force, model *model, } /** - * @brief Mark the buffer ready for inference. - * @param[in] The input buffer that is ready. + * @brief Notify the input buffer is ready for inference. * @return @c 0 if success. otherwise, -ERRNO. */ -int dataReady(buffer *buf) +int n3_dataReady(void) { if (spriv.cur_opmode == N4_OPS_END) { logerr (TAG, "No input service yet\n"); return -EINVAL; } - if (!buf) { - logerr (TAG, "Empty buffer\n"); - return -EINVAL; - } + return n4_dataReady (); +} - return n4_dataReady (buf); +/** + * @brief get the next I/O buffer dedicated to the requsted role. + * @param[in] role the role of buffer + * @param[out] err set with error-number if there is an error + * @return the next buffer if no error, otherwise NULL + */ +buffer *n3_getNextBuffer(buffer_role role, int *err) +{ + return n4_getNextBuffer (role, err); } /** diff --git a/core/npu-engine/src/ne-scheduler.h b/core/npu-engine/src/ne-scheduler.h index 9e45d88..302f31d 100644 --- a/core/npu-engine/src/ne-scheduler.h +++ b/core/npu-engine/src/ne-scheduler.h @@ -34,13 +34,20 @@ * @param[in] cb_data The private data to be given to the callback. * @return @c 0 if success. otherwise, -ERRNO. */ -int setOpMode(npu_input_opmode op, int force, model *model, output_ready cb, void *cb_data); +int n3_setOpMode(npu_input_opmode op, int force, model *model, output_ready cb, void *cb_data); /** - * @brief Mark the buffer ready for inference. - * @param[in] The input buffer that is ready. + * @brief Notify the input buffer is ready for inference. * @return @c 0 if success. otherwise, -ERRNO. */ -int dataReady(buffer *buf); +int n3_dataReady(void); + +/** + * @brief get the next I/O buffer dedicated to the requsted role. + * @param[in] role the role of buffer + * @param[out] err set with error-number if there is an error + * @return the next buffer if no error, otherwise NULL + */ +buffer *n3_getNextBuffer(buffer_role role, int *err); #endif /* NRC_SCHEDULER_H__ */ -- 2.7.4