control.async


template <typename T>
inline void async_then(() -> T task, (T) -> void then) §

Execute task asynchronously and call then with the result once the task completes.

Example
async_then(
    []() -> uint32
    {
        // ...
    },
    [](uint32 result)
    {
        // ...
    });
inline void async_then_void(() -> void task, () -> void then) §

Like async_then but for tasks that don’t produce a result.

inline void async_exec(() -> void task) §

Execute a task asynchronously.

Hardware

A call to async_exec is implemented as a dataflow fork. For the common case of passing a lambda to async_exec, the lambda entry FIFO holds the value of each variable captured by the lambda. If the lambda pipeline does not introduce backpressure, the compiler can optimize away the entry FIFO.

void F(uint32 a)
{
    uint32 b = a + 1;

    async_exec
        (   [b]()
            {
            }
        );
}
template <typename T, auto ReturnDepth, auto WaitForDepth>
class async_await §

A class faciliating the async/await pattern. async spawns a new asynchronous thread in which the provided lambda will be executed. Upon completion, the lambda’s return value will be stored into an internal FIFO. In parallel, a call to await will block the calling thread until a result from async is available. The standard thread ordering guarantee ensures that no threads can overtake another and results will be returned by await in the same order as they entered async.

Parameters

  • typename T
    

    Type returned by lambda argument to async.

  • auto ReturnDepth
    

    Depth of return value FIFO (maximum number of fork<i> results that can be buffered ahead of a corresponding async call). A recommended value would be 32 allowing it to be implemented in LUTRAM.

  • auto WaitForDepth
    

    Depth of the wait-for FIFO (maximum number of threads that can queue inside await). A conservative value would be 32 allowing it to be implemented in LUTRAM, however, for lambdas that typically take more than 32 cycles to return, this should be increased.

Methods

  • inline void async(() -> T task) §
    

    Spawn a new thread that calls the provided lambda. Out-of-order behaviour can occur if multiple calls (causing multiple inlines) to the same method on the same instance exists and is thus not recommended.

  • inline bool check() §
    

    Check to see if the async function has returned. It is exposed as a public function to provide the option for a consumer to wait on multiple async_await instances simultaneously (e.g. fork_join).

  • inline void decrement(bool value) §
    

    Decrement the return counter if argument is true.

  • T await() §
    

    Wait for task started by async to complete and return its result.

  • inline T dequeue() §
    

    Pop the value returned by the lambda function to async. This function is called by await. It is exposed as a public function so that use can wait for check_and_decrement() and then dequeue.

template <typename T, auto N, auto ReturnDepth, auto WaitForDepth>
class fork_join §

A wrapper around an array of async_await objects. This allows zero, one, or more threads (forks) to be spawned and their lambdas to execute in parallel. A call to join will block until all the provided forks (if any) have returned a result.

Parameters

  • typename T
    

    Type returned by lambda argument to all fork calls.

  • auto N
    

    Maximum number of parallel forks supported.

  • auto ReturnDepth
    

    Depth of return value FIFO (maximum number of fork<i> results that can be buffered ahead of a corresponding join call). A recommended value would be 32 allowing it to be implemented in LUTRAM.

  • auto WaitForDepth
    

    Depth of the wait-for FIFO (maximum number of threads that can queue inside join). A conservative value would be 32 allowing it to be implemented in LUTRAM, however, for lambdas that typically take more than 32 cycles to return, this should be increased.

Methods

  • template <auto i>
    inline void fork(() -> T task) §
    

    Create a single fork which runs the lambda function asynchronously. Out-of-order behaviour can occur if multiple calls (causing multiple inlines) to the same method, with the same template argument, on the same instance exist and is thus not recommended.

  • T[N] join(bool[N] which) §
    

    Block until all forks flagged in the argument have returned, and return their values.