runntime 0.0.1-alpha.0 → 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,206 @@
1
+ import { StorageFlag, TgpuBuffer, TgpuRoot, d } from "typegpu";
2
+ //#region src/core/kernels/common.d.ts
3
+ type U32Buffer = TgpuBuffer<d.WgslArray<d.U32>> & StorageFlag;
4
+ type F32Buffer = TgpuBuffer<d.WgslArray<d.F32>> & StorageFlag;
5
+ type F16Buffer = TgpuBuffer<d.WgslArray<d.F16>> & StorageFlag;
6
+ //#endregion
7
+ //#region src/core/kernels/activations.d.ts
8
+ declare const ACT_CODE: {
9
+ readonly none: 0;
10
+ readonly tanh: 1;
11
+ readonly gelu: 2;
12
+ readonly silu: 3;
13
+ readonly relu: 4;
14
+ };
15
+ type ActName = keyof typeof ACT_CODE;
16
+ type SlotAct = Exclude<ActName, 'none'>;
17
+ //#endregion
18
+ //#region src/core/graph/ops/matmul.d.ts
19
+ /** Options for matmul. `bias` and `addend` are fused epilogue adds, not
20
+ * available for quantW. `baseRow` views into a taller weight without copying,
21
+ * so MoE experts stay views into one fused tensor. */
22
+ interface MatmulOpts {
23
+ bias?: Value;
24
+ addend?: Value;
25
+ /** Applied to a·b + bias, before any addend, in the same dispatch. */
26
+ activation?: SlotAct;
27
+ baseRow?: number;
28
+ scales?: Value;
29
+ scaleBase?: number;
30
+ bits?: 8 | 4;
31
+ groupSize?: number;
32
+ }
33
+ //#endregion
34
+ //#region src/core/graph/value.d.ts
35
+ type EagerDtype = 'f32' | 'f16' | 'quantW';
36
+ /** Everything known about a Value without computing it. quantW is the
37
+ * exception: `dims` stay logical while `elems` is a u32 word count. */
38
+ interface ValueMeta {
39
+ /** Element count in units of `dtype`. */
40
+ readonly elems: number;
41
+ readonly dtype: EagerDtype;
42
+ /** Logical shape for non-flat ops, e.g. [rows, cols]. */
43
+ readonly dims?: readonly number[];
44
+ /** Physical storage order, when it differs from row-major. Under 'hwc4'
45
+ * `elems` includes the channel padding while `dims` stay logical, and only
46
+ * hwc4-aware ops accept the Value — everything else throws. */
47
+ readonly layout?: 'hwc4';
48
+ }
49
+ /** The storage buffer behind a materialized Value. */
50
+ type GpuBufferRef = F32Buffer | F16Buffer | U32Buffer;
51
+ /** Every op a pending node can name. */
52
+ type OpName = 'add' | 'mul' | 'sub' | 'swiglu' | 'swigluChunk' | 'rsqrt' | 'addScalar' | 'sigmoid' | 'mulScalar' | 'clampScalar' | 'tanh' | 'gelu' | 'silu' | 'asinh' | 'matmul' | 'matmulQuantW' | 'matmulGatherQuantW' | 'matmulGather' | 'argmaxDot' | 'attn' | 'rope' | 'conv1d' | 'convTranspose2d' | 'conv2dHwc4' | 'maxPool2dHwc4' | 'upsample2dHwc4' | 'avgPool2dHwc4' | 'pad2dHwc4' | 'resizeBilinearHwc4' | 'channelAffineHwc4' | 'concatChannelsHwc4' | 'sliceChannelsHwc4' | 'toHwc4' | 'toChw' | 'ssmScanProject' | 'ssmSelectiveScan' | 'ssmScanMerge' | 'softmax' | 'mean' | 'meanSquare' | 'layerNorm' | 'topk' | 'astype' | 'transpose' | 'sliceCols' | 'concatCols' | 'sliceRows' | 'concatRows' | 'reshape' | 'sliceChannels' | 'concatChannels' | 'writeRows' | 'gatherRowsFrom' | 'gatherRows';
53
+ /** The recipe for a not-yet-computed Value. Inputs may themselves be pending,
54
+ * so chained ops form the DAG eval() walks. */
55
+ interface PendingOp {
56
+ readonly op: OpName;
57
+ readonly inputs: readonly Value[];
58
+ /** Scalar operand for ops like addScalar. */
59
+ readonly scalar?: number;
60
+ /** Numeric attributes for layout and scalar ops, e.g. [start, end]. */
61
+ readonly attrs?: readonly number[];
62
+ }
63
+ /** A tensor as the eager API sees it, and one node of a lazy DAG. Calling ops
64
+ * only links nodes; reading a result evaluates everything it depends on in one
65
+ * submit. */
66
+ declare class Value {
67
+ readonly shape: ValueMeta;
68
+ /** Undefined until eval() runs the op, which is what pending means. */
69
+ private _buffer;
70
+ /** Set when this Value came from an op. Stays set after eval but is inert:
71
+ * `state` depends on `_buffer` alone. */
72
+ readonly pending: PendingOp | undefined;
73
+ private constructor();
74
+ /** Why the buffer is gone. `_buffer` keeps the stale reference on purpose —
75
+ * clearing it would flip state back to pending and rerun the recipe. */
76
+ private _released;
77
+ get state(): 'materialized' | 'pending' | 'released';
78
+ /** Why the buffer is gone; undefined while it is still there. */
79
+ get releasedReason(): string | undefined;
80
+ /** Throws if not yet materialized, or already gone. */
81
+ get buffer(): GpuBufferRef;
82
+ /** @internal */
83
+ setMaterialized(buffer: GpuBufferRef): void;
84
+ /** @internal Every later use of the Value throws `reason`. */
85
+ markReleased(reason?: string): void;
86
+ static materialized(shape: ValueMeta, buffer: GpuBufferRef): Value;
87
+ static pending(shape: ValueMeta, op: OpName, inputs: readonly Value[], scalar?: number, attrs?: readonly number[]): Value;
88
+ }
89
+ /** Method forms of the ops, implemented in methods.ts. Declared here so the
90
+ * published .d.ts carries them on Value itself rather than as an
91
+ * augmentation of a relative path that no longer exists once bundled.
92
+ * The import is type-only, so value.ts still never imports ops.ts at
93
+ * runtime. */
94
+ interface Value {
95
+ add(b: Value | number): Value;
96
+ sub(b: Value | number): Value;
97
+ mul(b: Value | number): Value;
98
+ matmul(b: Value, opts?: MatmulOpts): Value;
99
+ reshape(newDims: number[]): Value;
100
+ transpose(): Value;
101
+ clamp(lo: number, hi: number): Value;
102
+ slice(dim: number, start: number, end: number): Value;
103
+ chunk(n: number, dim: number): Value[];
104
+ split(sizes: readonly number[], dim: number): Value[];
105
+ softmax(): Value;
106
+ sigmoid(): Value;
107
+ tanh(): Value;
108
+ asinh(): Value;
109
+ mean(): Value;
110
+ rsqrt(): Value;
111
+ topk(k: number): Value;
112
+ }
113
+ //#endregion
114
+ //#region src/core/graph/evalCore.d.ts
115
+ interface DispatchExtras {
116
+ addend?: GpuBufferRef;
117
+ outBase?: number;
118
+ outElems?: number;
119
+ }
120
+ interface Executor {
121
+ acquireOutput(shape: ValueMeta): GpuBufferRef;
122
+ releaseOutput(buffer: GpuBufferRef, shape: ValueMeta): void;
123
+ dispatch(node: Value, inputs: readonly GpuBufferRef[], out: GpuBufferRef, extras?: DispatchExtras): void;
124
+ copyInto?(src: GpuBufferRef, dst: GpuBufferRef, srcShape: ValueMeta, dstShape: ValueMeta, dstBase: number): void;
125
+ submit(): void;
126
+ }
127
+ interface Releaser {
128
+ releaseValues(values: readonly Value[]): void;
129
+ dispose(): void;
130
+ }
131
+ interface Readback {
132
+ readback(buffer: GpuBufferRef, shape: ValueMeta): Promise<Float32Array>;
133
+ readbackMany?(items: readonly {
134
+ buffer: GpuBufferRef;
135
+ shape: ValueMeta;
136
+ }[]): Promise<Float32Array[]>;
137
+ }
138
+ //#endregion
139
+ //#region src/core/gpu/timing.d.ts
140
+ interface KernelTiming {
141
+ name: string;
142
+ workgroups: number | readonly [number, number];
143
+ ns: number;
144
+ }
145
+ //#endregion
146
+ //#region src/core/gpu/eval.d.ts
147
+ /** Readback fused into the next submit, so a step costs one submit and one map
148
+ * round-trip rather than two submits. */
149
+ interface FusedReadback {
150
+ /** Resolves after the next submit() or replay(); one request at a time. */
151
+ readbackOnSubmit(value: Value): Promise<Float32Array>;
152
+ /** Several values through one staging copy, resolved together. */
153
+ readbackManyOnSubmit(values: readonly Value[]): Promise<Float32Array[]>;
154
+ /** toArray with the copy fused into the eval's own submit. */
155
+ toArrayFused(value: Value): Promise<Float32Array>;
156
+ }
157
+ type RunntimeExecutor = Executor & Readback & Releaser & CaptureExecutor & FusedReadback;
158
+ /** Sets the default device and returns its executor. Call it once at startup;
159
+ * tensor(), toArray() and loadStateDict() then need no root. */
160
+ declare function initRunntime(root: TgpuRoot): RunntimeExecutor;
161
+ /** Capture and replay: records one frame's dispatches, then re-submits them
162
+ * without walking the graph again. Fixed-shape forwards only. */
163
+ interface CaptureExecutor {
164
+ /** Runs `fn` once, recording every dispatch. The executor is replay-only
165
+ * afterwards. Keep `targets` — their buffers stay valid across replays — and
166
+ * overwrite inputs in place before each replay. */
167
+ captureFrame<T>(fn: () => T): {
168
+ targets: T;
169
+ replay: () => void;
170
+ /** Replays once with a timestamp pair per dispatch. Per-dispatch passes
171
+ * remove overlap, so read the sum as relative attribution only. */
172
+ profileReplay: () => Promise<KernelTiming[] | undefined>;
173
+ };
174
+ }
175
+ //#endregion
176
+ //#region src/zoo/yolo26/config.d.ts
177
+ declare const YOLO26_SCALES: {
178
+ readonly n: {
179
+ readonly depth: 0.5;
180
+ readonly width: 0.25;
181
+ readonly maxChannels: 1024;
182
+ };
183
+ readonly s: {
184
+ readonly depth: 0.5;
185
+ readonly width: 0.5;
186
+ readonly maxChannels: 1024;
187
+ };
188
+ readonly m: {
189
+ readonly depth: 0.5;
190
+ readonly width: 1;
191
+ readonly maxChannels: 512;
192
+ };
193
+ readonly l: {
194
+ readonly depth: 1;
195
+ readonly width: 1;
196
+ readonly maxChannels: 512;
197
+ };
198
+ readonly x: {
199
+ readonly depth: 1;
200
+ readonly width: 1.5;
201
+ readonly maxChannels: 512;
202
+ };
203
+ };
204
+ type Yolo26Variant = keyof typeof YOLO26_SCALES;
205
+ //#endregion
206
+ export { initRunntime as n, Yolo26Variant as t };