Skip to content

Programming Model

Legato describes a kernel using execution contexts, typed values, and explicit data movement. These are programming abstractions: the compiler maps a valid program to the selected backend.

LPU compute model

The figure shows the LPU from a programmer's perspective. It is an abstract compute model, rather than an exact diagram of the physical implementation. It describes the execution and memory resources that the compiler can use; the selected backend supplies their configuration and requirements.

LPU Compute Model

Components and roles

Component Programming-model role
DRAM + Controller Provide data from shared DRAM to the cores, independently of core computation. The PC represents its program position, and metadata describes the work being coordinated.
Shared and virtual regions Represent memory shared by the cores. The virtual region represents shared memory accessed through address translation.
PIM (optional) Represent optional processing-in-memory support. Availability depends on the selected compute model.
Core #0 through #N Execute core-local programs. A core has a program counter (PC), registers, execution units, and local memory resources.
Execution units Perform matrix, vector, reshape, and load/store operations. Bertha documentation uses MPU and VPU for the matrix and vector units. The compiler assigns supported operations to suitable units.
Cache and private DRAM Represent core-local memory resources. Cache corresponds to on-chip SRAM in this model; private DRAM represents storage reserved for a core's work.

The model groups shared DRAM, virtual shared memory, and core-local memory into separate memory spaces. Core memory combines SRAM and private DRAM from the programmer's perspective; the compiler plans placement subject to the selected model's constraints.

Layout maps describe how tensor indices address storage. A memory can impose alignment, shape, and size requirements; padding and swizzling can adapt storage to those requirements or distribute accesses across banks. Logical shape describes the data used by an operation, while physical shape describes its allocated capacity. See Layouts and Memory Kinds.

Execution contexts

Context How to select it Role in a kernel
Top device.get_top() Coordinate input requests and work shared by the participating cores.
One core device.get_core(i) Describe the operations performed by the selected core.
Several cores device.get_cores(...) or device.get_all_cores() Describe the work for each participating core.

Create a backend with the matching device configuration, then obtain its execution contexts through legato.get_context().get_device(). Keep core indices within the configured core count.

Values belong to the context where they are defined. Use yield when a value must leave a context; see Context Management.

Memory and data movement

Tensor types describe the element type, logical shape, physical capacity, and storage kind expected by a kernel. Shared and core-local storage have different allocation scopes and alignment requirements.

Operation Programming contract
legato.tensor.request_load Request that an input become available in a target context.
legato.tensor.receive / receive_type Obtain the requested value in that context.
legato.tensor.memcpy Copy a result into an existing tensor or view.

Pair requests with receives in the documented order. Allocate backing storage that satisfies the declared physical capacity and storage kind; changing an annotation does not allocate or initialize that storage. See Memory Operations and PyTorch Integration.

Device configuration

The configured group and core counts, memory capacities, word sizes, channel count and address spacing, MAC size, and reuse limit constrain valid programs. Use the configuration for the selected device and runtime. A value supported by one backend or revision is not automatically supported by another.

The compiler checks argument binding, shapes, storage requirements, and target support. Successful frontend compilation does not by itself establish binary compilation or device execution support. See Compile Diagnostics.