TECHNOLOGY

TVM Relax call_tir: output declarations drive destination allocation

In this article
THE QUICK TAKE

call_tir allocates declared tensor destinations for a destination-passing function; it is not interchangeable with a native call that receives every argument explicitly.

A primitive writes an output that the graph never allocated correctly

A Relax integration calls a primitive function with an output buffer parameter. The caller describes an incompatible result shape, assuming the primitive will somehow return a self-describing tensor instead. Allocation and primitive execution now disagree about the destination. Trace the calling convention before debugging arithmetic. A destination-passing function writes caller-provided storage; the graph-level operator must know what storage to create and how that result appears to later graph operations.

The current call interface declares tensor results

The Relax API reference describes call_tir as allocating output tensors for a destination-passing primitive. Its declared output type participates in that contract. Consult the installed version’s signature instead of copying an older tutorial’s parameter names. The same reference distinguishes a native packed-call path that supplies native parameters explicitly and does not implicitly allocate destination tensors. These interfaces express different responsibilities even when they eventually invoke related low-level code.

Cross-level abstraction keeps allocation visible

The Relax abstraction guide explains connecting Relax and primitive tensor functions. Follow the declared dimensions and dtypes through the call boundary, including symbolic relationships needed to allocate a result. The tensor descriptor guide supplies background on interpreting the resulting storage, but the allocation declaration must first match what the primitive actually writes. A correct input shape alone cannot establish that an incorrectly declared destination is safe.

Runtime execution has a separate lowering stage

The Relax VM architecture describes execution through compiled primitives and external functions. Preserve the distinction between graph-level allocation semantics and final runtime dispatch. Inspect the lowered call when integrating an external primitive, rather than assuming its original native return convention remains unchanged through every wrapper. Validate numerical outputs and declared result shapes together. A function that computes the expected values into the wrong-sized or incorrectly interpreted destination is not a compatible integration.

Test the declared result rather than an accidental example

Use inputs that vary supported symbolic extents and distinguish multiple output shapes where the function has several results. Compare the primitive’s expected destinations with the graph’s actual returned tensors. Bind call definition, primitive implementation and compiled module through artifact verification. This establishes the allocation contract behind a working cross-level call and prevents a future model change from silently relying on a wrapper that confused destination-passing execution with an ordinary native function return.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles