Ethos-U Integration for Cortex-M
Ethos-U Driver
Loading...
Searching...
No Matches
Platform-specific functions

Functions may be overwritten for specific driver and use cases. More...

Functions

void ethosu_flush_dcache (const uint64_t *base_addr, const size_t *base_addr_size, int num_base_addr)
void ethosu_invalidate_dcache (const uint64_t *base_addr, const size_t *base_addr_size, int num_base_addr)
void * ethosu_mutex_create (void)
void ethosu_mutex_destroy (void *mutex)
void * ethosu_semaphore_create (void)
void ethosu_semaphore_destroy (void *sem)
int ethosu_mutex_lock (void *mutex)
int ethosu_mutex_unlock (void *mutex)
int ethosu_semaphore_take (void *sem, uint64_t timeout)
int ethosu_semaphore_give (void *sem)
void ethosu_inference_begin (struct ethosu_driver *drv, void *user_arg)
void ethosu_inference_end (struct ethosu_driver *drv, void *user_arg)
uint64_t ethosu_address_remap (uint64_t address, int index)
unsigned int ethosu_config_select (uint64_t address, int index)

Description

Functions may be overwritten for specific driver and use cases.

The driver provides weak default implementations for these functions. See Platform-specific functions for guidance on when a platform-specific implementation is required.

Function Documentation

◆ ethosu_flush_dcache()

void ethosu_flush_dcache ( const uint64_t * base_addr,
const size_t * base_addr_size,
int num_base_addr )

Flush/clean the data cache

Addresses passed to this function must be aligned to cache line size.

Parameters
base_addrArray of 32 byte aligned base addresses
base_addr_sizeArray with size per each base addr entry
num_base_addrNumber of base addr entries

This callback hook is called before inference for the supplied base-address regions. The command-stream region is not included. The default weak implementation is a no-op.

Reimplement this function when CPU-cached memory is shared with the NPU to ensure that the data written by CPU is visible to NPU.

The invocation API requires 16-byte base-address alignment. A cache implementation may require stricter cache-line alignment, commonly 32 bytes, and must handle non-cache-line-sized regions without affecting unrelated data.

See Data caching for cache-coherency requirements and an implementation example.

◆ ethosu_invalidate_dcache()

void ethosu_invalidate_dcache ( const uint64_t * base_addr,
const size_t * base_addr_size,
int num_base_addr )

Invalidate the data cache

Addresses passed to this function must be aligned to cache line size.

Parameters
base_addrArray of 32 byte aligned base addresses
base_addr_sizeArray with size per each base addr entry
num_base_addrNumber of base addr entries

This callback hook is called when finalizing inference for the supplied base-address regions. The default weak implementation is a no-op.

Reimplement this function when CPU-cached memory is shared with the NPU to ensure that the data written by NPU is visible to CPU.

From the cache clean before inference until this invalidation completes, the CPU must not write memory owned by the NPU. Cleaning stale dirty CPU cache lines after the NPU has written the same memory can overwrite NPU results. The platform implementation must define and enforce this ownership rule, including for asynchronous invocation.

See Data caching for cache-coherency requirements and an implementation example.

◆ ethosu_mutex_create()

void * ethosu_mutex_create ( void )

Minimal mutex implementation for baremetal applications. See ethosu_driver.c.

Returns
Pointer to mutex handle

Driver provides the default weak implementation that is effectively a no-op.

Re-implement this function and use an RTOS mutex when Ethos-U NPU is used in multithreaded application or when multiple CPU cores can access the driver.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_mutex_destroy()

void ethosu_mutex_destroy ( void * mutex)

Destroy mutex.

Parameters
mutexPointer to mutex handle

Driver provides the default weak implementation that is effectively a no-op.

Re-implement this function and use an RTOS mutex when Ethos-U NPU is used in multithreaded application or when multiple CPU cores can access the driver.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_semaphore_create()

void * ethosu_semaphore_create ( void )

Minimal sempahore implementation for baremetal applications. See ethosu_driver.c.

When overriding this function with an RTOS counting semaphore, create it with an initial count of zero. The maximum count must be large enough for the reservation waiter semaphore, which can hold one token per available registered driver of the same NPU variant. A safe value is the maximum number of NPU driver instances in the system.

Returns
Pointer to semaphore handle

Driver provides the default weak implementation that allocates a minimal bare-metal semaphore.

Re-implement this function and create an RTOS semaphore with an initial count of zero in multithreaded application.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_semaphore_destroy()

void ethosu_semaphore_destroy ( void * sem)

Destroy semaphore.

Parameters
semPointer to semaphore handle

Driver provides the default weak implementation that frees the storage allocated by ethosu_semaphore_create().

Re-implement this function in multithreaded application to destroy semaphore created and returned by ethosu_semaphore_create.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_mutex_lock()

int ethosu_mutex_lock ( void * mutex)

Lock mutex.

Parameters
mutexPointer to mutex handle
Returns
0 on success, else negative error code

Driver provides the default weak implementation that is effectively a no-op.

Re-implement this function and use an RTOS mutex when Ethos-U NPU is used in multithreaded application or when multiple CPU cores can access the driver.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_mutex_unlock()

int ethosu_mutex_unlock ( void * mutex)

Unlock mutex.

Parameters
mutexPointer to mutex handle
Returns
0 on success, else negative error code

Driver provides the default weak implementation that is effectively a no-op.

Re-implement this function and use an RTOS mutex when Ethos-U NPU is used in multithreaded application or when multiple CPU cores can access the driver.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_semaphore_take()

int ethosu_semaphore_take ( void * sem,
uint64_t timeout )

Take semaphore.

Parameters
semPointer to semaphore handle
timeoutTimeout value (unit impl. defined)
Returns
0 on success else negative error code

Driver provides the default weak implementation that ignores the timeout and waits with WFE.

Re-implement this function in multithreaded application to use the semaphore created and returned by ethosu_semaphore_create.

  • ETHOSU_SEMAPHORE_WAIT_FOREVER is used to request an indefinite wait.
  • ETHOSU_SEMAPHORE_WAIT_INFERENCE is used to wait until inference completes.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_semaphore_give()

int ethosu_semaphore_give ( void * sem)

Give semaphore.

Parameters
semPointer to semaphore handle
Returns
0 on success, else negative error code

Driver provides the default weak implementation that signals an event with SEV.

Re-implement this function in multithreaded application to use the semaphore created and returned by ethosu_semaphore_create. The implementation must be callable from NPU interrupt context.

See Mutex and semaphores for RTOS integration requirements.

◆ ethosu_inference_begin()

void ethosu_inference_begin ( struct ethosu_driver * drv,
void * user_arg )

Callback invoked just before the inference is started.

Parameters
drvPointer to driver handle
user_argUser argument provided to ethosu_invoke_*()

Called immediately before starting the command stream. The default weak implementation is a no-op.

See Begin/End inference callbacks for usage and lifecycle requirements.

◆ ethosu_inference_end()

void ethosu_inference_end ( struct ethosu_driver * drv,
void * user_arg )

Callback invoked just after the inference has completed.

Parameters
drvPointer to driver handle
user_argUser argument provided to ethosu_invoke_*()

Called by ethosu_wait() when finalizing a started job, including error and timeout paths. It is not guaranteed if a running driver is released. The default weak implementation is a no-op.

See Begin/End inference callbacks for usage and lifecycle requirements.

◆ ethosu_address_remap()

uint64_t ethosu_address_remap ( uint64_t address,
int index )

Remapping command stream and base pointer addresses.

When the multi variant feature is off, the driver provides a weak function that can be overriden. When the multi variant feature is on, the function pointer in the device user ops struct (per driver) must be set instead.

Parameters
addressAddress to be remapped.
index-1 command stream, 0-n base address index
Returns
Remapped address

This callback hook is called by the driver to convert a CPU-visible address to the address used by the NPU. Index -1 identifies the command stream; indexes 0 through 7 identify base pointers.

Re-implement this function when the CPU and NPU use different addresses for the same memory.

◆ ethosu_config_select()

unsigned int ethosu_config_select ( uint64_t address,
int index )

Select configuration for region access.

When the multi variant feature is off, the driver provides a weak function that can be overriden. When the multi variant feature is on, the function pointer in the device user ops struct (per driver) must be set instead.

Default weak implementation uses NPU_QCONFIG and NPU_REGIONCFG_n defines.

Parameters
addressAddress of region.
index-1 command stream, 0-n base address index
Returns
Configuration to use

This callback hook selects the NPU memory configuration for the command stream (index -1) or a base pointer (indexes 0 through 7). Driver provides the default weak implementation based on the ethosu_config_u*.h configuration file.

Reimplement this function if the application requires an alternative configuration mechanism.