From 1a3bb928b3820b089198afb99bbf410b1f210700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonny=20Sv=C3=A4rd?= Date: Fri, 25 Feb 2022 16:28:21 +0100 Subject: Add driver async API Add an asynchronous API to the driver. The current synchronous API is now using the new async API internally. The main new functions are ethosu_invoke_async() and ethosu_wait(). Every successfull call to ethosu_invoke_async() must be followed by a call to ethosu_wait() to get the status of the inference. The wait function can be called in a blocking or non-blocking mode by specifying the `block` argument to true/false. The regular synchronous invoke function is implemented as a invoke_async followed by a wait(block=true) call. Short sommary of changes: - Add an internal ethosu_job struct to keep track of inference data and job state. - Use async API in blocking mode for normal flow - Change default semaphore implementation to binary type - Move error prints out of interrupt context - Move ethosu_inference_begin() callback to right before HW invoke - Always call ethosu_inference_end() callback, even in case of errors - On NPU error, do not keep NPU powered after being reset Change-Id: If4c3c46e3c6732a669e17251bd848dea5765a490 --- include/ethosu_driver.h | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/ethosu_driver.h b/include/ethosu_driver.h index ff8d1eb..bf6a578 100644 --- a/include/ethosu_driver.h +++ b/include/ethosu_driver.h @@ -48,17 +48,35 @@ extern "C" { // Forward declare struct ethosu_device; +enum ethosu_job_state +{ + ETHOSU_JOB_IDLE = 0, + ETHOSU_JOB_RUNNING, + ETHOSU_JOB_DONE +}; + +struct ethosu_job +{ + volatile enum ethosu_job_state state; + const void *custom_data_ptr; + int custom_data_size; + const uint64_t *base_addr; + const size_t *base_addr_size; + int num_base_addr; + void *user_arg; +}; + struct ethosu_driver { struct ethosu_device *dev; struct ethosu_driver *next; + struct ethosu_job job; void *semaphore; uint64_t fast_memory; size_t fast_memory_size; bool status_error; bool dev_power_always_on; bool reserved; - volatile bool irq_triggered; uint8_t clock_request; uint8_t power_request; }; @@ -158,6 +176,33 @@ int ethosu_invoke_v3(struct ethosu_driver *drv, #define ethosu_invoke(drv, custom_data_ptr, custom_data_size, base_addr, base_addr_size, num_base_addr) \ ethosu_invoke_v3(drv, custom_data_ptr, custom_data_size, base_addr, base_addr_size, num_base_addr, 0) +/** + * Invoke Vela command stream using async interface. + * Must be followed by call(s) to ethosu_wait() upon successful return. + * Returns + * -1 on error + * 0 on success + */ +int ethosu_invoke_async(struct ethosu_driver *drv, + const void *custom_data_ptr, + const int custom_data_size, + const uint64_t *base_addr, + const size_t *base_addr_size, + const int num_base_addr, + void *user_arg); + +/** + * Wait for inference to complete (block=true) + * Poll status or finish up if inference is complete (block=false) + * (This function is only intended to be used in conjuction with ethosu_invoke_async) + * Returns + * 1 on inference running (only for block=false) + * 0 on inference success + * -1 on inference error + * -2 on inference not invoked + */ +int ethosu_wait(struct ethosu_driver *drv, bool block); + /** * Set Ethos-U power mode. */ -- cgit v1.2.1