Context Management¶
Legato operations are emitted under an executor context. A context describes where the following operations run: the top executor, a single core, or all cores.
Getting The Current Context¶
Use legato.get_context() inside a compiled function to access the active
compiler context and its device.
1 | |
Most user code immediately selects an executor with a Python with statement.
1 2 3 4 5 6 7 8 | |
Executor Scopes¶
device.get_top()is used for orchestration and top-side load requests.device.get_core(index)runs the region on one core.device.get_all_cores()runs the region for every core.
The object yielded by with ... as name is the executor selected by that
context.
1 2 | |
Yielding Values Across Regions¶
Legato scopes are stricter than Python scopes. If a value produced inside a region is needed by a later region, yield it from that region.
1 2 3 4 5 6 7 | |
For conditional regions, both branches must yield compatible values when the outer scope uses those values.
Sessions And Contexts¶
Calling a @legato.compile function requires an active legato.session.
1 2 | |
The session controls compiler output and logging. Executor contexts control the IR regions emitted inside the compiled kernel.