---
title: "CpuModule: interface in CPU oracle, TypeShade API reference"
description: "CpuModule, an interface in CPU oracle. The shape both CPU backends return…"
url: https://typeshade.dev/api/cpumodule/
language: en
---

# `CpuModule`

Interface in CPU oracle

The shape both CPU backends return, so a caller can compile with compileModuleJs and fall back to compileModule without touching call sites.

`import type { CpuModule } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
interface CpuModule {
  fns: Record<string, (...args: CpuValue[]) => CpuValue>;
  setBinding(name: string, value: CpuValue): void;
  dispatch(entry: string, workgroups: WorkgroupCount): DispatchReport;
}
```

## Description

`fns` is a table of the module’s declared functions by name, each taking its parameters positionally in declaration order. `setBinding` supplies a storage or uniform binding’s value before a function that reads it runs. The two backends return the same value for the same call: `compileModuleJs(m).fns.f(args)` and `compileModule(m).fns.f(args)` agree under `Object.is`, element for element.

## Instance properties

**`fns` `Record<string, (...args: CpuValue[]) => CpuValue>`**

The module’s declared functions by name. Parameters are positional, in declaration order; the return value is the function’s result as a [`CpuValue`](https://typeshade.dev/api/cpuvalue/).

## Instance methods

**`setBinding` `(name: string, value: CpuValue): void`**

Supply a storage or uniform binding’s value by its declared name, before invoking a function that reads it.

**`dispatch` `(entry: string, workgroups: WorkgroupCount): DispatchReport`**

Run a `@compute` entry over `workgroups` workgroups of its declared size (one number for a 1-D grid, or the three counts), every invocation of a workgroup in lockstep at each `workgroupBarrier()` / `storageBarrier()`, with the builtin parameters (`global_invocation_id`, `local_invocation_id`, `local_invocation_index`, `workgroup_id`, `num_workgroups`) filled in (roadmap 0.2 item 5). Workgroup memory starts zero for each workgroup and a per-invocation variable at its initializer for each invocation; the bindings are the ones `setBinding` supplied, arrays written in place. Throws when the invocations of one workgroup disagree about a barrier, naming its line and the counts. A kernel with no barrier may also be run one invocation at a time through `fns`.

## In the guide

- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)

## See also

- [`compileModuleJs`](https://typeshade.dev/api/compilemodulejs/)
- [`compileModule`](https://typeshade.dev/api/compilemodule/)
- [`CpuValue`](https://typeshade.dev/api/cpuvalue/)

## Source

[`src/core/oracle.ts`, line 98](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/oracle.ts#L98), at commit af54ddad5
