Workflow#

Our workflow splits the development of a tensor contraction compiler into tasks, which coding agents complete on their own. An independent review system accepts or rejects the agents’ work. An orchestrator, an AI assistant that we direct, schedules the tasks and monitors them. For each supported microarchitecture, the finished compiler generates code for any contraction of two tensors within seconds.

Compiler#

The compiler consists of three parts:

  • The toolkit implements TZIR in Python. It checks and transforms programs, times them on a device and verifies their results.

  • A backend compiles TZIR programs for one microarchitecture and one programming model. For example, the backend for AMD’s RDNA 4 microarchitecture generates HIP code for GPUs such as the Radeon RX 9070 XT.

  • An optimization heuristic chooses the programs that a backend compiles. For a contraction’s initial program, the heuristic returns the trace of a fast program. A performance model predicts this program’s time.

The agents first build the toolkit, then the backends, and finally a heuristic and a performance model for each backend. We call these phases toolkit development, backend development and optimization. Figure 4 shows the phases, the parts of the compiler that they build, and one task with its reviews.

The development workflow Three phases follow each other: toolkit development, backend development with one task per backend, and optimization with one task per backend. Each phase builds one part of the compiler: the toolkit, the backends, and the heuristics with their performance models. Inside one task, the agent works with visible test cases and requests reviews; the review system answers each request and also checks the agent's work with hidden test cases. Toolkitdevelopment Backenddevelopment Optimization Compiler Toolkit Backends Heuristics andperformance models Inside one task Agentvisible test cases Review systemhidden test cases Reviewrequest Answer

Figure 4 The development workflow. Each card with rounded corners is a task. Stacked cards mark the phases with one task per backend. An arrow leads from each phase to the part of the compiler that the phase builds. The card on the right shows one task, in which the agent requests reviews and the review system answers them. The agent works with visible test cases. The review system also checks each commit with hidden test cases.#

Tasks#

Each task gives an agent a fixed working time to build one part of the compiler. The working time pauses while the agent waits for a review. Toolkit development is a single task. Backend development and optimization have one task per backend.

Test cases check the agents’ work. In toolkit development, conformance tests check the toolkit against its specification. A workload is a contraction with fixed extents, given by its initial TZIR program. In backend development and optimization, a test case runs the program for one workload.

At the start of its task, an agent receives:

  • a prompt with its goal and its rules

  • written specifications of TZIR and of the toolkit

  • visible test cases to check and tune its work

A backend agent also receives the toolkit. An optimization agent receives the toolkit and a finished backend.

The agent commits its work to a Git repository. During the task, the agent receives feedback only from the reviews that it requests. A backend or optimization task ends when the agent requests a final review or when its working time runs out. The review system then checks the reviewed commits again. The newest commit that passes becomes the task’s result.

The phases differ in what their tasks deliver:

  • In toolkit development, an agent implements the toolkit from its specification in stages. A review accepts each stage. The task ends when a review accepts the last stage.

  • In backend development, an agent builds a backend from scratch for one programming model and one microarchitecture. The agent writes a support specification, a tuned program for each visible workload and a first heuristic. The support specification lists the tile operations that the backend runs, with their shapes, layouts, memory spaces and datatypes. The agent tunes each program toward the roofline time of its workload.

  • In optimization, an agent studies the performance of a finished backend, which stays unchanged. From its measurements, the agent develops a heuristic and a performance model. The agent chooses how both work. For example, a heuristic may derive a schedule from rules on the contraction’s shape or compare candidate schedules with its performance model.

Reviews#

A review judges an agent’s latest commit with automatic checks and an AI reviewer. Each agent decides when to request a review, within a fixed budget of reviews per task. The checks first install a fresh copy of the commit and run the agent’s own tests and the visible test cases. The reviewer then reads the code and the results of these checks and reports each defect as a finding, rated as blocking, major or minor. After the reviewer has finished, the checks run the hidden test cases, so they stay hidden from the reviewer as well. Inputs get random values that change with every execution of a program. The review’s answer reports results on hidden workloads only as aggregate numbers, such as the number of failures. A review accepts a commit only when all checks pass and no finding blocks.

The compiler has to generate code for every contraction and every device of a supported microarchitecture. Reviews test this generality on hidden workloads. The reviewer also flags code that singles out particular workloads and code that hard-codes the parameters of a device.

Measurement#

The backends execute programs. The toolkit times and verifies the programs of every backend by the same method. This separation keeps the measurement independent of the code of the backend and optimization agents. Reviews check that each commit keeps the toolkit unchanged.

The toolkit runs a program 3 times to warm up the device and then times 10 further runs. Before each timed run, the backend evicts the device’s caches. A program’s time is the median of its 10 timed runs. After each run, the toolkit checks every element of the result against a reference of higher precision. The error bound of each element allows for the rounding errors of the element’s sum of products and of one final rounding to the output’s datatype.

Setup#

Our setup targets five microarchitectures of GPUs and CPUs from three vendors (Table 1). It has one backend for each microarchitecture and evaluates each backend on one device. On the GPUs, the backends support 16-bit floating-point (FP16) and bfloat16 (BF16) tensors and accumulate in 32-bit floating point (FP32). On the CPUs, they support FP32 and 64-bit floating-point (FP64) tensors and accumulate in the tensors’ type.

Table 1 The devices with their microarchitectures, programming models and peaks. Microbenchmarks on each device measured the peak throughput in each datatype and the memory bandwidth. A dash marks a datatype in which the device has no results.#

Device

Vendor

Microarchitecture

Programming model

FP16 peak (TFLOP/s)

BF16 peak (TFLOP/s)

FP32 peak (TFLOP/s)

FP64 peak (TFLOP/s)

Bandwidth (GB/s)

GB10 GPU

NVIDIA

Blackwell

CuTe DSL

121.3

121.7

–

–

250

Radeon RX 9070 XT

AMD

RDNA 4

HIP

183.1

185.9

–

–

592

M4 GPU

Apple

M4 GPU

Metal

4.01

4.01

–

–

102

Ryzen AI Max PRO 390 CPU

AMD

Zen 5

C with LIBXSMM

–

–

3.54

1.76

146

M4 CPU

Apple

M4 CPU

C with LIBXSMM

–

–

2.90

0.86

112

All agents ran in Codex 0.162.0 with OpenAI’s GPT-6 Astra. The reviewer ran in Claude Code 2.1.295 with Anthropic’s Claude Opus 5.5. We chose models of two vendors, so that the reviewer always judged the work of another model. The reasoning effort steers how much a model thinks. The toolkit agent worked at the effort max, the backend agents at xhigh, and the reviewer at max.

The limits of a task depended on its phase:

  • Toolkit development had 26 hours of working time in five stages, with a budget of four to eight reviews per stage.

  • A backend task had 36 hours and eight reviews.

  • An optimization task had 26 hours and 12 reviews in two rounds. Its first round had 18 hours and eight reviews at the effort xhigh. Its second round had 8 hours and four reviews at the effort max.

Workloads#

During development, the agents and the reviews used synthetic workloads, which a generator drew for each device. The synthetic workloads form three sets (Table 2):

  • General contractions have several axes of at least one role.

  • General matrix multiplications (GEMMs) have one axis of each role M, N and K.

  • Irregular contractions have up to four axes of each role, small extents and short roofline times.

Table 2 The ranges from which the generator draws the synthetic workloads of each set.#

Set

Batch axes

M axes

N axes

K axes

Extents

Roofline time (µs)

Visible workloads

General

0

1–3

1–3

1–2

16–32,768

100–250,000

50

GEMM

0

1

1

1

16–32,768

100–250,000

50

Irregular

0–3

1–4

1–4

1–4

≥2

1–5,000

25

For each workload, the generator draws the number of axes of each role and a roofline time evenly on a logarithmic scale. It then draws extents that give the workload this roofline time in the device’s fastest datatypes. For the general contractions and the GEMMs, the generator rounds each extent to a multiple of a power of two up to 128. The generator keeps the extents only if the three tensors take at most 1/8 of the device’s memory and at most 4 GiB. It shuffles the axes within each tensor, so the layouts vary. It also draws whether the workload overwrites its output or adds to it. The backend and optimization agents received the visible workloads of Table 2. They could draw more workloads with the generator.

Backend reviews check the tuned programs on the visible workloads for correctness and speed. They check the programs of the first heuristic on hidden workloads of all three sets for correctness alone. Optimization reviews check the heuristic’s programs on hidden general contractions and GEMMs for correctness and speed, and on new irregular contractions for correctness alone. An optimization review scores the heuristic by the geometric mean of its programs’ percentages of the roofline. It also requires a median relative error of the performance model below 25%.

Isolation#

Separate Unix accounts and a sandbox prevent the agents and their code from reading the hidden test cases. The orchestrator, the review system and each agent work in accounts of their own. The review system draws the hidden workloads from a secret key in its account. Every review step with an agent’s code runs in a sandbox, which hides the home directories and shows the rest of the system read-only.

Cost#

The tasks used 295 hours of working time and 109 reviews (Table 3). The agents’ model processed 2.8 billion cached and 39 million uncached input tokens and generated 21 million output tokens. Its reasoning accounts for 12 million of the output tokens. Over all reviews and final checks, the reviewer’s model read 1.9 billion input tokens from its cache and wrote 58 million to it. It generated 26 million output tokens, 23 million of them for its reasoning. One Codex subscription covered the agents. Two Claude subscriptions covered the reviewer and the orchestrator.

Table 3 Working time, reviews and tokens of the tasks of each phase.#

Phase

Tasks

Working time (h)

Reviews

Cached input tokens (M)

Uncached input tokens (M)

Output tokens (M)

Toolkit development

1

14.7

16

112

2.8

1.3

Backend development

5

156.3

33

1,573

19.7

10.7

Optimization

5

123.6

60

1,073

16.5

8.6

All

11

294.6

109

2,758

39.0

20.5

The development took 15.4 days from the start of toolkit development to the end of the last review. Each backend’s tasks form a chain, from toolkit development through the backend task to the optimization task. The chains of the five backends ran in parallel. In each chain, agents worked or the review system reviewed for 4.7 to 6.4 days. The chain waited for the rest of the time, mostly for the orchestrator to start its next task or final check, or for a reset of the weekly subscription limit. The chain of Blackwell, the backend of the GB10 GPU, ended last, because its second optimization round waited 5.9 days for the next reset of this limit.