Company

Resources

Company

Resources

Technology

Optimizing the MLIR-Based Torq NPU Compiler

Optimizing the MLIR-Based Torq NPU Compiler

How ENERZAi reduced the DMA overhead caused by SLICE parallelism in the IREE/MLIR-based compiler for the Torq NPU on Synaptics Astra

Jaeho Kim

October 20, 2026

Hi, this is ENERZAi. We recently contributed to the backend implementation and model optimization of the Torq compiler, an open-source IREE/MLIR-based compiler for the Torq NPU in the Astra SL2610 product line from global semiconductor company Synaptics. In this post, we’ll share the challenges we ran into along the way and the insights we gained.

In particular, we’ll take a close look at the hidden data-movement (DMA) cost that arises when an operation is split across the NPU’s two compute blocks (SLICEs) to run in parallel, and at where in the compiler’s layers we reduced it, and how.

Once again, a big thank-you to Synaptics for making this opportunity possible!

An NPU Ecosystem That Is Still Taking Shape

Interest in domain-specific architectures has grown rapidly over the past few years. CPUs and GPUs have already evolved to divide work between general-purpose computation and massively parallel workloads. Deep learning has created a similar need for specialization: much of a model can be expressed as a flow of tensor operations, making architectures tailored to those workloads increasingly important. The rapid growth of model-based services is accelerating this trend.

As a result, many companies are developing and shipping processing units specialized for neural-network workloads: NPUs, or Neural Processing Units. They are particularly important in edge computing, where models need to run directly on-device under tight power and memory budgets while still delivering useful intelligence.

Unlike CPUs and GPUs, however, NPUs do not yet benefit from mature compiler stacks, runtimes, and the thick ecosystem built on top of them. Architectures vary widely across vendors, commercial deployment is still relatively young compared with GPUs, and there is no broadly established agreement on where the hardware/software boundary should sit. APIs and infrastructure therefore differ significantly from one platform to another. In some cases, an NPU may already be in production while the software stack needed to use it effectively is still catching up.

The Optimization That Looked Obvious

One of the first ideas an NPU with multiple compute units suggests is simple: split the work and run the pieces in parallel. The Torq NPU on the Astra SL2619 has two SLICEs, or compute blocks, so at first glance splitting an operation in half and running one half on each SLICE looks like an obvious optimization.

A few hardware terms are enough to see why the result is not always so simple:

  • A SLICE program operates on data that has already been placed in LRAM, a small on-chip memory.

  • XRAM is a region reserved in the board’s main DRAM for NPU execution.

  • Data moves between XRAM and LRAM through DMA. Inputs need to reach LRAM before a SLICE can use them, and results are copied back to XRAM when needed.

Splitting an operation can create more opportunities for parallel execution, but it can also create more data movement. The split is decided while the compiler is still working with tensor-level intermediate representation (IR), before concrete DMA tasks and SLICE programs exist. Once the pieces are lowered, each one may acquire its own loads, stores, and program-code transfers. If two pieces need the same constant or input, that data may be moved more than once.

There is another subtlety: having two SLICE tasks does not mean the two SLICEs actually overlap. The current scheduler assigns work according to the ordering of start and wait operations in the IR. Both programs need to start before the corresponding waits if we want them to execute concurrently.

# Two SLICEs actually overlap

slice_start(0)
slice_start(1)
slice_wait(0)
slice_wait(1)

# Two tasks, but still sequential
slice_start(0)
slice_wait(0)
slice_start(1)
slice_wait(1)

When an MLIR parallel loop such as scf.forall is unrolled into two independent pieces, the first schedule can be produced. Simply creating two operations side by side, however, may still result in the second form: if each operation is immediately followed by its own wait, the second SLICE does not begin until the first has finished.

Data movement adds another complication. DMA can overlap with SLICE execution, so extra traffic is not automatically serialized into latency. But it is still more work for the schedule to absorb, and any part that does not overlap extends the critical path.

This became a recurring pattern in our work on Torq: an optimization that looked beneficial in tensor IR could expose a new cost only after it reached a lower level of the compiler. Parallelism was not the hard part by itself. The hard part was making the cost of that parallelism visible soon enough to do something about it.

That observation leads to a compiler-design question: where should each optimization live when the decision is made at one level, but its cost appears at another?

Why Torq Uses Multiple Compiler Layers

Compilers represent a model through a sequence of intermediate representations (IRs) between the original model and the final hardware code. Different optimizations need different information from those representations.

Some transformations are useful across many targets. Others depend on the target’s dataflow, supported operation patterns, or memory hierarchy. The two kinds cannot simply be separated and forgotten about, because their decisions still interact. Operation fusion is a good example: combining operations can avoid materializing intermediate results, but a fused expression may not fit the small set of specialized operations an NPU provides, and the cost of making it fit can outweigh the savings from fusion. Tiling has the same tension. It can be expressed at the tensor level, while the useful tile shape is ultimately constrained by hardware memory and allocation strategy.

Torq handles this by separating concerns across several compiler layers. In MLIR, these layers are organized as dialects, each representing operations and concepts at a particular level of abstraction. Torq keeps tensor semantics and high-level transformations in standard dialects for as long as possible. Torq-specific dialects appear only when concrete information about NPU programs and memory becomes necessary.

Torq Compiler is implemented as an IREE plugin and makes extensive use of MLIR. The main layers are:

  • The linalg layer: MLIR’s builtin dialect for expressing tensor operations primarily in terms of their mathematical semantics. Tensor-level transformations such as tiling and fusion operate on this IR. Some passes may consult target information, but hardware-specific program descriptors and internal data paths are not exposed yet.

  • The torq_hl layer: A dialect that gives operations Torq-specific semantics and represents XRAM/LRAM transfers as well as SLICE-program execution. At this level, it becomes explicit which data needs to move into or out of NPU memory and when NPU programs are launched.

  • The torq_hw layer: A dialect that maps to the descriptors consumed by the hardware. Information such as the D/W/B/Q data paths and ALU/ACT configuration appears directly in the IR that defines an actual SLICE task.

Looking at the same matrix multiplication at each level makes the progression concrete:

// linalg: only the mathematical tensor operation is expressed here.
//         tensor.empty and linalg.fill(0.0) initialize the tensor that
//         becomes the outs operand (output tensor) of the matmul.
%zero = arith.constant 0.000000e+00 : bf16
%e = tensor.empty() : tensor<64x128xbf16>
%f = linalg.fill ins(%zero : bf16) outs(%e : tensor<64x128xbf16>) -> tensor<64x128xbf16>
%m = linalg.matmul ins(%a, %b : tensor<64x64xbf16>, tensor<64x128xbf16>)
                   outs(%f : tensor<64x128xbf16>) -> tensor<64x128xbf16>

// torq_hl: an execution unit understood by the NPU. linalg.fill is gone;
//          an uninitialized tensor.empty remains as the init operand,
//          and bias / quantization parameters are attached as operands.
//          (%sb = dense<[0, 1]> : tensor<2xi32>, i.e. bias 0 · scale 1)
%init = tensor.empty() : tensor<64x128xbf16>
%q = "torq_hl.matmul"(%init, %sb, %a, %b) {output_zp = 0, shift = 0, ...}

// torq_hw: the hardware descriptor itself.
torq_hw.slice_task {
  op : "matmul-fast"
  D %arg3 : memref<64x128xbf16, lram>    W %arg2 : memref<64x64xbf16, lram>
  B %arg1 : memref<2xi32, lram>          Q %arg0 : memref<64x128xbf16, lram>
  CFG {alu_op0_mode = [MUL, ...], alu_op1_mode = [ACC, ...], act_mode = ACT,
       weight_format = BF, alu_format = BF, act_format = BF, ...}
}

The arithmetic is the same at every level, but the representation becomes increasingly concrete. linalg carries the tensor-level semantics. torq_hl adds the information needed to execute the operation as an NPU program. By the time we reach torq_hw, D (Input Data), W (Weight), B (Bias/Scale), Q (Output), and the ALU/ACT configuration expose something close to the hardware behavior itself.

The lower-level cost becomes even clearer once the surrounding program and data movement are visible:

// torq_hl: the machinery surrounding a single kernel operation.
%a_x = torq_hl.map_binding {binding_index = 0} : memref<64x64xbf16>   // XRAM address
%a_l = memref.alloc() : memref<64x64xbf16, lram>                      // LRAM allocation
torq_hl.load %a_x to %a_l {element_size_bytes = 8192}                 // DMA in (XRAM -> LRAM)
...

%prog = torq_hl.program "slice_program_torq_hl.matmul_0" {
  ^bb0(%q: ..., %b: ..., %w: ..., %d: ...):
    "torq_hl.matmul"(%q, %b, %w, %d) {output_zp = 0, shift = 0, ...}
}
%inv, %code = torq_hl.create_invocation "slice_program_torq_hl.matmul_0"
                program(%prog) on 0 : ..., memref<5120xi8>
torq_hl.load %code to %code_l {element_size_bytes = 5120}             // program-code DMA
torq_hl.start_program %inv args(%q_l, %b_l, %a_l, %d_l)
torq_hl.wait_program %inv
torq_hl.store %q_l to %q_x {element_size_bytes = 16384}               // DMA out (LRAM -> XRAM)

What was a single tensor operation in linalg has expanded into finding XRAM addresses, allocating LRAM, loading inputs, launching and waiting for a program, and finally storing the result back out. The arithmetic has not changed, but the cost of preparing that computation for execution on the device is now visible.

This is why the layering mattered to our work. A split made at the linalg level can turn into additional addresses, DMA, and program launches in torq_hl. At the same time, some fixes are easiest before those details exist, while others require exactly the information that appears later. Instead of putting every optimization into one layer, we can address each cost where the necessary information becomes available.

The same structure also gives the compiler room to evolve. NPU operations, memory capacity, and data paths may change across hardware generations. Keeping high-level semantics separate from lower-level hardware details limits how much of the pipeline needs to change with the target.

Paying Back the Cost of Slicing

Once we could see where the extra movement appeared, most of our work followed one theme: keep the parallelism, but remove as much of the movement it introduces as possible. The fixes landed at different abstraction levels because each one needed a different view of the program.

Keep Elementwise Chains Together in linalg

At the linalg layer, we found cases where consecutive element-wise operations were sliced one operation at a time. Composite activations and post-processing often canonicalize into chains of linalg.generic operations. If each operation ends up in a separate loop, intermediate values can cross loop boundaries and later be materialized in XRAM.

We unified the torq-fuse-group attached to operations in such a chain. The compiler pulls linalg operations in the same group into a single scf.forall, while operations in different groups are placed in separate loops. By assigning the chain to one group before slicing begins, the compiler can construct one loop for the whole chain from the start rather than trying to merge loops afterward. The example below compresses a longer chain down to three operations for readability.

// [Before change, before slicing]
// The chain still consists of multiple operations, and no loop has been
// created yet. Each operation only carries a marker describing which group
// it belongs to. Those markers are fragmented across the chain.
%a = linalg.generic { ... }          {torq-fuse-group = [3]}
%b = linalg.generic { ... %a ... }   {torq-fuse-group = [4]}
%c = linalg.generic { ... %b ... }   // no marker

// [After change, before slicing]
// Walk the chain and unify the group marker. The operations and their order
// do not change; only the marker does.
%a = linalg.generic { ... }          {torq-fuse-group = [30]}
%b = linalg.generic { ... %a ... }   {torq-fuse-group = [30]}
%c = linalg.generic { ... %b ... }   {torq-fuse-group = [30]}

// [Before change, after slicing]
// Fragmented markers produce one loop per operation.
%a = scf.forall (%i) = (0) to (N) step (N/2) { linalg.generic { ... } }         // %a survives across a loop boundary
%b = scf.forall (%i) = (0) to (N) step (N/2) { linalg.generic { ... %a ... } }  // the next loop consumes %a
%c = scf.forall (%i) = (0) to (N) step (N/2) { linalg.generic { ... %b ... } }  // the boundary repeats at every stage

// [After change, after slicing]
// One loop contains the whole chain, so the intermediates stay inside it.
%c = scf.forall (%i) = (0) to (N) step (N/2) {
  %t0 = linalg.generic { ... }
  %t1 = linalg.generic { ... %t0 ... }
        linalg.generic { ... %t1 ... }
}

On the lowering paths where this problem occurred, intermediates crossing different scf.forall loops were materialized in XRAM, creating extra round trips. Keeping the chain inside one loop lets those intermediates stay in LRAM longer and reduces the associated DMA in/out. The point is less “fusion for its own sake” than preserving on-chip residency across the chain.


Compile-time timeline of erf (1x1024x64, bf16) with slicing enabled. In each panel the upper group is before the elementwise chain was placed in one fuse group and the lower group is after; the bottom panel enlarges the blue frame, the first 330 µs of each run. ① Stores to XRAM between the ops of the chain: each op writes both SLICE halves out. ② Loads that bring those values straight back into LRAM for the next op. ③ With the whole chain in one fuse group, the intermediates stay in LRAM and the SLICE programs run back to back. Stores drop from 36 (2.6 MB) to 7 (448 KB), and the estimated time from 1834.9 µs to 888.0 µs.

Reorder SLICE Extraction Before Memory Conversion

A different problem appeared after the compiler had reached torq_hl. Some values were still represented as tensors, but their memory placement was now encoded in their types. In the original IR, the compiler could convert a full value to XRAM first and only then extract the smaller SLICE that was actually needed.

We rewrote that into an equivalent form: extract the SLICE while the value is still in LRAM, then convert only the smaller SLICE. This keeps the large tensor on-chip and exposes a redundant round trip on the smaller SLICE that an existing compiler optimization can fold away.

// Before our change
%x  = torq_hl.convert in(%big) {encoding = xram}   // write the full result to XRAM
%sl = tensor.extract_slice %x [...]                // extract the required part from XRAM
%l  = torq_hl.convert in(%sl) {encoding = lram}    // bring it back into LRAM

// After our change
%sl = tensor.extract_slice %big [...]              // extract directly while still in LRAM
%x  = torq_hl.convert in(%sl) {encoding = xram}    // the large tensor never leaves for XRAM
%l  = torq_hl.convert in(%x) {encoding = lram}     // this round trip on the SLICE is now redundant

// After subsequent cleanup
%sl = tensor.extract_slice %big [...]              // extract directly in LRAM\


max_pool (5x5, 1x15x20x384, i8) before (upper group) and after (lower group) SLICE extraction was moved ahead of the LRAM-to-XRAM conversion. ① The full 112.5 KB result is converted to XRAM. ② Each SLICE then extracts its 56.2 KB half and loads it back into LRAM. ③ After the change both SLICEs take their halves while the value is still in LRAM, so the round trip disappears. The estimated time drops from 369.3 µs to 312.9 µs.

Neither this change nor the linalg grouping above introduced a new operation. In both cases, the useful transformation already existed somewhere in the compiler; the important part was arranging the IR so that it could do the right thing for Torq’s memory model.

Expose Access Semantics Instead of Reimplementing Analysis

At the torq_hl layer, LRAM addresses, loads/stores, and program boundaries are explicit, so some redundant movement can be attacked directly. If the same read-only data is loaded separately for two SLICEs, we want to transfer it once and share it. If an intermediate is written to temporary XRAM but will never be read again, we want to remove that store.

The interesting part was that many of the analyses and transformations needed for these cases already existed. The problem was that torq_hl is a custom dialect, so the compiler did not automatically know how its operations access memory or whether they are safe to move. Rather than reimplementing the analyses, we exposed those properties through compiler interfaces.

The read/write direction of SLICE-program arguments is described through AsyncAccessOpInterface, a simplified version of the interface used in IREE. For operation-level memory effects and motion legality, we use MemoryEffectsOpInterface and ConditionallySpeculatable. Once those properties are available, existing MLIR analyses and utilities can reason about torq_hl as well.

One immediate benefit is eliminating dead stores. Without read/write information, the compiler has to assume that every SLICE-program argument might be both read and written. Once it knows that a later program overwrites a value rather than reading it, an earlier spill can disappear.

// Before our change
%t_x = torq_hl.map_binding {binding_index = 2}   // temporary location in XRAM
%t_l = memref.alloc() : memref<..., lram>        // location in LRAM

torq_hl.start_program %inv_a args(%t_l, %d_l)    // A writes its result to %t_l
torq_hl.wait_program %inv_a
torq_hl.store %t_l to %t_x                       // spill %t_l because LRAM is tight

torq_hl.start_program %inv_b args(%t_l, %e_l)    // B also writes a result to %t_l
torq_hl.wait_program %inv_b                      // but we cannot tell whether B reads or writes %t_l
torq_hl.store %t_l to %q_x                       // so the earlier store cannot be removed

// After our change: the interface tells us B only overwrites %t_l,
// so the previously spilled copy will never be read again.
%t_l = memref.alloc() : memref<..., lram>

torq_hl.start_program %inv_a args(%t_l, %d_l)
torq_hl.wait_program %inv_a
                                                 // one store and the %t_x binding disappear
torq_hl.start_program %inv_b args(%t_l, %e_l)
torq_hl.wait_program %inv_b
torq_hl.store %t_l to %q_x                       // the final result store remains

The same information helps when a buffer is temporarily spilled to XRAM because LRAM is full and loaded again later. If the intervening program only reads the buffer, the previously written XRAM copy is still valid. The compiler can release the LRAM allocation and reuse that copy instead of allocating another XRAM location and storing the same data again.

A conv1d layer (kernel 127, stride 64, 80,000 audio samples to 288 channels) before (upper group) and after (lower group) AsyncAccessOpInterface. The bottom panel lines up the same loop iteration from both runs (blue frames: 1950–2720 µs before, 1842–2612 µs after), each shifted to start at 0. ① A dead store: a 200 KB value is spilled to XRAM although the next program only overwrites it. ② The matching 200 KB load, which disappears with it. ③ An unchanged 309 KB buffer is stored to XRAM again; after the change the copy already in XRAM is reused. DMA out drops from 22 transfers (4.5 MB) to 13 (2.4 MB), and the estimated time from 5091.1 µs to 4218.8 µs.

A related question is whether an operation can move at all. If an operation produces the same value on every loop iteration, it is better to execute it once outside the loop and reuse the result. Previously, MLIR could not tell whether moving a torq_hl operation was legal.

// Before our change: recompute the same value on every iteration
// (or for every SLICE program). We cannot prove it is safe to move out.
scf.forall (%i) ... {
  %s = torq_hl.segmentation ... (%w, %sb, %in)   // all three inputs are independent of %i
  ... computations using %s ...
}

// After our change: the operation is classified as safe to move,
// allowing MLIR's moveLoopInvariantCode utility to process it.
%s = torq_hl.segmentation ... (%w, %sb, %in)
scf.forall (%i) ... {
  ... computations using %s ...
}

We marked only the operations that were actually safe to move; operations whose meaning depends on their position, such as those that gather values by index, were excluded. This allowed us to reuse MLIR’s getBackwardSlice and moveLoopInvariantCode instead of writing separate legality logic.

Taken together, these changes removed part of the duplicate movement introduced by slicing. They also changed how we thought about the problem: splitting work well is not enough. If parallelization creates overhead, the compiler needs a way to pay that overhead back before the parallelism turns into real performance.

What We Learned

Looking back, the individual rewrites and interfaces matter less than the pattern behind them.

First, optimization starts with understanding how data moves through the chip. On Torq, each operation has specific input paths, accumulation paths, and post-processing paths available to it, and those constraints determine what can fit inside a single program. Task count and DMA bytes are useful diagnostics, but they are not performance verdicts by themselves. Even when fusion reduces the number of tasks, we still need to ask which kernel path the fused operation selects and what happens to the actual critical path.

Second, tiling, fusion, and slicing are tightly coupled under a constrained LRAM budget. All three affect what stays on-chip, how much of it stays there, and how often it needs to move again. Making those decisions independently can easily make the optimizations work against each other.

The answer is not to collapse everything into one hardware-specific IR. The layered pipeline does not remove the coupling between optimizations; it gives that coupling a place to become visible. High-level transformations can keep working with tensor semantics, while lower layers expose the hardware costs those decisions eventually create. For us, that separation became less about architectural neatness and more about having the right information available at the right time.

What’s Next

The same lesson shapes where we want to take the compiler next. Our goal is to support a broader range of models and future hardware without turning every new target into another set of hard-coded special cases.

1. From EasyKernel to Nadya.
Today, Torq kernels are written in EasyKernel, an internal C++ DSL. Instead of writing low-level hardware descriptors and instruction streams directly, a kernel can be expressed in something closer to ordinary loops and then serialized into descriptors. This is much easier to work with, but the implementation of each tensor operation still lives inside the compiler. That makes new operations and future hardware generations harder to support and also limits opportunities for runtime profiling and tuning of kernel implementations.

One direction we are exploring is moving kernel authoring to Nadya, a kernel programming language we are developing. Nadya is designed to make it possible to write high-performance programs without requiring every author to understand all of the underlying hardware optimization details. The implementation of how the NPU executes an operation could live in external kernel code, while the compiler decides how multiple operations should be scheduled together.

2. Making optimization decisions searchable.
The compilation pipeline contains many decisions driven by heuristics: tile sizes, SLICE partitioning, whether to fuse, and so on. Rather than hard-coding those choices into individual passes, we want to parameterize them so they can be explored systematically by a tuning loop. That loop may live in an external tool or be integrated more tightly with the compiler over time; the important part is to separate the search policy from the transformation logic. This lets the same compiler pipeline evaluate different configurations and adapt to new hardware without rewriting heuristics for every target.

There are still many open problems in making a compiler for a new class of target both powerful and flexible. But that is exactly what makes the project interesting. At ENERZAi, we are still working through those problems one by one.

An Open Project

One of the best parts of this project is that both the hardware specifications and the compiler are public. The compiler is available at synaptics-torq/torq-compiler Github repo, model examples are available in torq-examples, and the official documentation is at synaptics-torq.github.io. Anyone can inspect the kinds of problems we are working on, and contributors who are interested can get involved directly.

If you’d like to learn more about the Torq project or ENERZAi’s other optimization technologies, such as Nadya, feel free to reach out anytime!

ENERZAi - Contact

Optimium

Optimium

Solutions

Resources

ENERZAi

Copyright ⓒ ENERZAi Inc. All Rights Reserved

Business number: 246-86-01405

Email: contact@enerzai.com

Call: +82 (2) 883 1231

Address: 06140 27, Teheran-ro 27-gil, Gangnam-gu, Seoul, Republic of Korea

Optimium

Optimium

Solutions

Resources

ENERZAi

Copyright ⓒ ENERZAi Inc. All Rights Reserved

Business number: 246-86-01405

Email: contact@enerzai.com

Call: +82 (2) 883 1231

Address: 06140 27, Teheran-ro 27-gil, Gangnam-gu, Seoul, Republic of Korea

Optimium

Optimium

Solutions

Resources

ENERZAi

Copyright ⓒ ENERZAi Inc. All Rights Reserved

Business number: 246-86-01405

Email: contact@enerzai.com

Call: +82 (2) 883 1231

Address: 06140 27, Teheran-ro 27-gil, Gangnam-gu, Seoul, Republic of Korea