---
title: "TypeNN execution model"
description: "How a Tensor graph runs its TypeShade kernel functions when you call data()."
url: https://nn.typeshade.dev/guide/execution/
language: en
---

Guides

# Execution model

TypeNN builds and schedules Tensor graphs. TypeShade compiles their kernel functions and runs them on the selected backend.

## Tensor calls build a deferred graph

Operations such as `matmul()`, `add()`, and `relu()` do not compute values immediately. Each one records a node that holds a TypeShade kernel function, the input Tensors, the scalars the kernel takes by value, and the gradient rule.

A small Tensor graph model.ts

```ts
const input = device.tensor(values, { shape: [batch, features] });
const logits = input.matmul(weights).add(bias);
const output = logits.relu();

// This is the materialization boundary.
const result = await output.data();
```

## How data() computes a Tensor result

When you call `data()` for a Tensor without a computed array, TypeNN collects the graph nodes needed to produce it. It creates an output array for each node and uploads the leaf arrays. TypeNN then calls TypeShade `fuse()` once, running each node's kernel in graph order. The compiler groups compatible calls into dispatches, and TypeNN reads the requested Tensor once.

TypeNN

Shape checks · graph nodes · autograd · kernel functions

TypeShade

compiler dispatch plan · backend tiers · runtime resources

## Backends and limits

Tier Selection Current note

**CPU** Auto fallback or explicit Runs the same kernel functions, one call after the other. Suited to correctness and fallback.

**WebGPU** Auto or explicit Native GPU compute when the browser exposes an adapter. Elementwise chains fuse into one dispatch.

**WebGL2** Explicit Runs the same kernel functions apart, one call after the other. A call it cannot run goes to the CPU tier.

TypeShade uses one call-layer configuration for the whole process, so each JavaScript context supports one active TypeNN Device.

## Read the plan in device.lastReport

The compiler puts consecutive kernel calls in one dispatch when TypeShade's fusion rules hold. On WebGPU, `a.add(b).mul(c).relu()` runs as one dispatch. A reduction with a different output count, a read at another index, or too many storage buffers starts a new dispatch. After a read, `device.lastReport` shows the tier, the dispatches, the submissions, and the groups of calls. On the CPU tier the report has no dispatches and one group for each call.

[Read how a read runs ↗](https://github.com/typeshade/typenn#how-a-read-runs)
