@gmitch215/folio 1.0.1 → 1.2.0
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.
- package/README.md +98 -460
- package/dist/boot.d.ts +1 -0
- package/dist/boot.js +1 -0
- package/dist/browser/index.d.ts +73 -0
- package/dist/browser/index.js +277 -0
- package/dist/browser.d.ts +1 -68
- package/dist/browser.js +1 -274
- package/dist/continuation.d.ts +1 -0
- package/dist/continuation.js +1 -0
- package/dist/{compiler.d.ts → execution/compiler.d.ts} +1 -1
- package/dist/{compiler.js → execution/compiler.js} +5 -12
- package/dist/{coordinator.d.ts → execution/coordinator.d.ts} +1 -1
- package/dist/{coordinator.js → execution/coordinator.js} +55 -8
- package/dist/{extract.d.ts → execution/extract.d.ts} +22 -13
- package/dist/{extract.js → execution/extract.js} +137 -10
- package/dist/execution/fold.d.ts +44 -0
- package/dist/execution/fold.js +105 -0
- package/dist/{guards.d.ts → execution/guards.d.ts} +2 -1
- package/dist/execution/runs.d.ts +44 -0
- package/dist/execution/runs.js +182 -0
- package/dist/{transaction.d.ts → execution/transaction.d.ts} +10 -0
- package/dist/execution/types.d.ts +221 -0
- package/dist/folds/affine-state.d.ts +142 -0
- package/dist/folds/affine-state.js +737 -0
- package/dist/folds/affine.d.ts +148 -0
- package/dist/folds/affine.js +562 -0
- package/dist/folds/boundaries.d.ts +48 -0
- package/dist/folds/boundaries.js +119 -0
- package/dist/folds/certified.d.ts +55 -0
- package/dist/folds/certified.js +178 -0
- package/dist/folds/certify.d.ts +87 -0
- package/dist/folds/certify.js +2611 -0
- package/dist/footprints/memo.d.ts +74 -0
- package/dist/footprints/memo.js +256 -0
- package/dist/footprints/ranges.d.ts +78 -0
- package/dist/footprints/ranges.js +263 -0
- package/dist/footprints/read-scan.d.ts +18 -0
- package/dist/footprints/read-scan.js +94 -0
- package/dist/footprints/read-windows.d.ts +77 -0
- package/dist/footprints/read-windows.js +245 -0
- package/dist/index.d.ts +16 -4
- package/dist/index.js +14 -2
- package/dist/iteration/admission.d.ts +149 -0
- package/dist/iteration/admission.js +201 -0
- package/dist/iteration/index.d.ts +239 -0
- package/dist/iteration/index.js +1210 -0
- package/dist/iteration/inline.d.ts +182 -0
- package/dist/{inline.js → iteration/inline.js} +277 -21
- package/dist/{iteration-owner.d.ts → iteration/owner.d.ts} +16 -3
- package/dist/{iteration-owner.js → iteration/owner.js} +6 -5
- package/dist/iteration/worker.js +216 -0
- package/dist/{managed.d.ts → managed/index.d.ts} +75 -3
- package/dist/managed/index.js +817 -0
- package/dist/managed/outbox.d.ts +128 -0
- package/dist/managed/outbox.js +156 -0
- package/dist/managed/pool.d.ts +221 -0
- package/dist/managed/pool.js +310 -0
- package/dist/managed/tasks.d.ts +154 -0
- package/dist/managed/tasks.js +183 -0
- package/dist/{bake.d.ts → memory/bake.d.ts} +12 -6
- package/dist/{bake.js → memory/bake.js} +9 -7
- package/dist/memory/continuation.d.ts +141 -0
- package/dist/memory/continuation.js +495 -0
- package/dist/memory/elastic-peer.d.ts +20 -0
- package/dist/memory/elastic-peer.js +39 -0
- package/dist/memory/elastic-sql.d.ts +11 -0
- package/dist/memory/elastic-sql.js +35 -0
- package/dist/memory/elastic.d.ts +130 -0
- package/dist/memory/elastic.js +475 -0
- package/dist/memory/growth-governor.d.ts +16 -0
- package/dist/memory/growth-governor.js +42 -0
- package/dist/memory/imports.d.ts +10 -0
- package/dist/memory/imports.js +89 -0
- package/dist/{iteration-layout.d.ts → memory/iteration-layout.d.ts} +61 -1
- package/dist/{iteration-layout.js → memory/iteration-layout.js} +54 -3
- package/dist/memory/lease.d.ts +45 -0
- package/dist/memory/lease.js +274 -0
- package/dist/{pages.d.ts → memory/pages.d.ts} +3 -3
- package/dist/memory.d.ts +5 -10
- package/dist/memory.js +5 -89
- package/dist/{context.d.ts → node/context.d.ts} +17 -3
- package/dist/{context.js → node/context.js} +60 -14
- package/dist/{host.d.ts → node/host.d.ts} +1 -1
- package/dist/{host.js → node/host.js} +2 -2
- package/dist/{node.d.ts → node/index.d.ts} +46 -49
- package/dist/{node.js → node/index.js} +101 -26
- package/dist/{tasks.d.ts → node/tasks.d.ts} +16 -17
- package/dist/{tasks.js → node/tasks.js} +12 -11
- package/dist/node/worker.d.ts +1 -0
- package/dist/{worker.js → node/worker.js} +2 -2
- package/dist/ownership/index.d.ts +161 -0
- package/dist/ownership/index.js +6565 -0
- package/dist/ownership/redirect.d.ts +30 -0
- package/dist/ownership/redirect.js +179 -0
- package/dist/ownership/slices.d.ts +44 -0
- package/dist/ownership/slices.js +72 -0
- package/dist/{frames.d.ts → remote/frames.d.ts} +6 -2
- package/dist/remote/frames.js +306 -0
- package/dist/{remote.d.ts → remote/index.d.ts} +7 -2
- package/dist/{remote.js → remote/index.js} +7 -2
- package/dist/routing/index.d.ts +203 -0
- package/dist/routing/index.js +671 -0
- package/dist/routing/worker.d.ts +1 -0
- package/dist/routing/worker.js +4 -0
- package/dist/slices/index.d.ts +126 -0
- package/dist/slices/index.js +441 -0
- package/dist/slices/worker.d.ts +1 -0
- package/dist/slices/worker.js +38 -0
- package/dist/workers.d.ts +5 -0
- package/dist/workers.js +5 -0
- package/package.json +32 -46
- package/dist/frames.js +0 -159
- package/dist/inline.d.ts +0 -68
- package/dist/iteration-admission.d.ts +0 -76
- package/dist/iteration-admission.js +0 -72
- package/dist/iteration-worker.js +0 -150
- package/dist/iteration.d.ts +0 -163
- package/dist/iteration.js +0 -435
- package/dist/managed.js +0 -421
- /package/dist/{browser-worker.d.ts → browser/worker.d.ts} +0 -0
- /package/dist/{browser-worker.js → browser/worker.js} +0 -0
- /package/dist/{guards.js → execution/guards.js} +0 -0
- /package/dist/{import-order.d.ts → execution/import-order.d.ts} +0 -0
- /package/dist/{import-order.js → execution/import-order.js} +0 -0
- /package/dist/{transaction.js → execution/transaction.js} +0 -0
- /package/dist/{iteration-worker.d.ts → execution/types.js} +0 -0
- /package/dist/{worker.d.ts → iteration/worker.d.ts} +0 -0
- /package/dist/{pages.js → memory/pages.js} +0 -0
- /package/dist/{values.d.ts → remote/values.d.ts} +0 -0
- /package/dist/{values.js → remote/values.js} +0 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/** Why the rest of a loop ran serially after the pooled path was tried or refused. */
|
|
2
|
+
export type IterationStop = 'no-admission' | 'log-exhausted' | 'frame-carried dependence' | 'dependency' | 'stalled';
|
|
3
|
+
/** What the admission decision saw and chose for one owner call's loop. */
|
|
4
|
+
export interface IterationAdmission {
|
|
5
|
+
/** Time of iteration 0 on the owner thread, on a plain instance and the real frame. */
|
|
6
|
+
plainIterationMs: number;
|
|
7
|
+
/** Serial time of the iterations after iteration 0, from `plainIterationMs`. */
|
|
8
|
+
remainingSerialMs: number;
|
|
9
|
+
/** The least remaining serial time worth dispatching: `fixedMs * margin`. */
|
|
10
|
+
floorMs: number;
|
|
11
|
+
/** The decision before the first dispatch. A later stop is `IterationReport.stopped`. */
|
|
12
|
+
admitted: boolean;
|
|
13
|
+
/** Wall of the last batch, dispatch to the end of its replays. */
|
|
14
|
+
batchWallMs?: number;
|
|
15
|
+
/** The serial time of the iterations of that batch, from the online estimate. */
|
|
16
|
+
batchSerialMs?: number;
|
|
17
|
+
/** The latest estimate of serial time per iteration, from iteration 0, replays or workers. */
|
|
18
|
+
estimateMs?: number;
|
|
19
|
+
/** Set when a refused loop was admitted after timed serial iterations; the iteration index. */
|
|
20
|
+
readmittedAt?: number;
|
|
21
|
+
/** Admitted as a probe: under the floor, over `probeFraction` of it, one timed batch decides. */
|
|
22
|
+
probe?: boolean;
|
|
23
|
+
/** The probe batch did not beat the serial time of its iterations, and the dispatch ended. */
|
|
24
|
+
probeLost?: boolean;
|
|
25
|
+
/** One entry per batch, only under `admissionSeam.trace`. */
|
|
26
|
+
trace?: AdmissionStep[];
|
|
27
|
+
}
|
|
28
|
+
/** What the estimate and the batch rule saw after one batch. @internal */
|
|
29
|
+
export interface AdmissionStep {
|
|
30
|
+
first: number;
|
|
31
|
+
count: number;
|
|
32
|
+
windows: boolean;
|
|
33
|
+
trackedMeanMs: number;
|
|
34
|
+
kappa?: number;
|
|
35
|
+
estimateMs: number;
|
|
36
|
+
wallMs: number;
|
|
37
|
+
serialMs: number;
|
|
38
|
+
}
|
|
39
|
+
/** Why the iteration route is not used, in `ExecutionReport.reason`. */
|
|
40
|
+
export type IterationReason = 'no-arena' | 'memory-size-observed' | 'import-order' | 'workers-unavailable' | 'trip-zero' | 'no-admission' | 'log-exhausted' | 'frame-carried dependence' | 'stalled';
|
|
41
|
+
/**
|
|
42
|
+
* The read windows of one loop. The strided window moves with the iteration index: iteration `k`
|
|
43
|
+
* reads from the granule boundary at or below `low + (k - index) * stride`. The fixed window is the
|
|
44
|
+
* same range in every iteration. Neither has to be right for a run to be correct: a load outside
|
|
45
|
+
* the window is tracked as usual, and a window only costs a false conflict when another iteration
|
|
46
|
+
* writes inside it.
|
|
47
|
+
*/
|
|
48
|
+
export interface IterationReadWindows {
|
|
49
|
+
strided?: {
|
|
50
|
+
index: number;
|
|
51
|
+
low: number;
|
|
52
|
+
stride: number;
|
|
53
|
+
bytes: number;
|
|
54
|
+
};
|
|
55
|
+
fixed?: IterationReadWindow;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Loads of at most 8 bytes of one run on the module with read windows, by where they landed:
|
|
59
|
+
* inside a window, tracked outside every window, or exempt (the slot's own callee stack).
|
|
60
|
+
*/
|
|
61
|
+
export interface ReadWindowCounts {
|
|
62
|
+
hits: number;
|
|
63
|
+
misses: number;
|
|
64
|
+
exempt: number;
|
|
65
|
+
}
|
|
66
|
+
/** A byte range an iteration reads without per-access marks. */
|
|
67
|
+
export interface IterationReadWindow {
|
|
68
|
+
low: number;
|
|
69
|
+
bytes: number;
|
|
70
|
+
}
|
|
71
|
+
/** What a run did. `regions`, `replayed`, `fallbacks` and `workers` parallel `ExecutionReport`. */
|
|
72
|
+
export interface IterationReport {
|
|
73
|
+
/** Workers that took part. */
|
|
74
|
+
workers: number;
|
|
75
|
+
/** Iterations run on workers, the regions of this mode. */
|
|
76
|
+
regions: number;
|
|
77
|
+
/** Dispatched iterations that were rolled back and rerun serially at the owner. */
|
|
78
|
+
replayed: number;
|
|
79
|
+
/** Iterations whose writes were undone before the rerun. */
|
|
80
|
+
rolledBack: number;
|
|
81
|
+
/** Batches whose first failure was a trap or an exhausted undo log, not a dependency. */
|
|
82
|
+
fallbacks: number;
|
|
83
|
+
/** Iterations that trapped on a worker. */
|
|
84
|
+
traps: number;
|
|
85
|
+
/** Iterations that exhausted their undo log. */
|
|
86
|
+
exhausted: number;
|
|
87
|
+
/** Iterations that trapped on an access to another iteration's stack slot. */
|
|
88
|
+
violations: number;
|
|
89
|
+
/** Batches in which the stall guard fired. */
|
|
90
|
+
stalls: number;
|
|
91
|
+
/** Iterations the stall word stopped, rolled back and rerun serially. */
|
|
92
|
+
stalledIterations: number;
|
|
93
|
+
batches: number;
|
|
94
|
+
failedBatches: number;
|
|
95
|
+
undoEntries: number;
|
|
96
|
+
/** The most undo entries one completed iteration logged. */
|
|
97
|
+
maxLogEntries: number;
|
|
98
|
+
/** Times a batch that exhausted its log was retried with the grown log. */
|
|
99
|
+
logGrowths: number;
|
|
100
|
+
/** Iterations rolled back and dispatched again by such a retry. They are not in `regions`. */
|
|
101
|
+
retried: number;
|
|
102
|
+
/** Ordered iteration pairs by hazard. */
|
|
103
|
+
conflicts: {
|
|
104
|
+
raw: number;
|
|
105
|
+
war: number;
|
|
106
|
+
waw: number;
|
|
107
|
+
frame: number;
|
|
108
|
+
};
|
|
109
|
+
/** From posting a batch to the last worker reply. */
|
|
110
|
+
dispatchMs: number;
|
|
111
|
+
validationMs: number;
|
|
112
|
+
rollbackMs: number;
|
|
113
|
+
replayMs: number;
|
|
114
|
+
/** Wasm time inside workers, summed. */
|
|
115
|
+
workerRunMs: number;
|
|
116
|
+
/** Bitmap scan and clear time inside workers, summed. */
|
|
117
|
+
workerScanMs: number;
|
|
118
|
+
/** Time the workers spent marking read windows before their iterations, summed. */
|
|
119
|
+
workerMarkMs: number;
|
|
120
|
+
/** Read bitmap words the workers scanned, summed. */
|
|
121
|
+
workerScanWords: number;
|
|
122
|
+
/** Read bitmap words they found non-zero. */
|
|
123
|
+
workerScanSet: number;
|
|
124
|
+
/**
|
|
125
|
+
* Iterations the owner ran as the serial program without dispatching them: iteration 0, the
|
|
126
|
+
* rest of a loop after a stop, or all of them when admission refused the loop.
|
|
127
|
+
*/
|
|
128
|
+
serial: number;
|
|
129
|
+
/** What ended the dispatch early, or why admission refused the loop. */
|
|
130
|
+
stopped?: IterationStop;
|
|
131
|
+
/** What the admission callback saw and chose; set when the job had one. */
|
|
132
|
+
admission?: IterationAdmission;
|
|
133
|
+
/** Frame conflicts that fell in a window's bytes; they are also in `conflicts.frame`. */
|
|
134
|
+
windowConflicts: number;
|
|
135
|
+
/** The window the batches ran on, if any, and where it came from. */
|
|
136
|
+
window?: {
|
|
137
|
+
low: number;
|
|
138
|
+
end: number;
|
|
139
|
+
source: 'given' | 'discovered';
|
|
140
|
+
/** Batches dispatched on it. */
|
|
141
|
+
batches: number;
|
|
142
|
+
};
|
|
143
|
+
/** Why a window that was offered or found was not used. */
|
|
144
|
+
windowRefused?: string;
|
|
145
|
+
/** The read windows learned from the first clean batch, with the batches that ran on them. */
|
|
146
|
+
readWindows?: IterationReadWindows & {
|
|
147
|
+
batches: number;
|
|
148
|
+
learnedFrom: number;
|
|
149
|
+
};
|
|
150
|
+
/** Why read windows were not learned, or were dropped after a batch on them conflicted. */
|
|
151
|
+
readWindowRefused?: string;
|
|
152
|
+
/** What the counted batch on the read windows saw, and whether they were armed for the loop. */
|
|
153
|
+
readWindowGate?: {
|
|
154
|
+
iterations: number;
|
|
155
|
+
counts: ReadWindowCounts;
|
|
156
|
+
saved: number;
|
|
157
|
+
spent: number;
|
|
158
|
+
/** which check the armed module runs first for a load of at most 8 bytes */
|
|
159
|
+
order: 'window' | 'exempt';
|
|
160
|
+
armed: boolean;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
/** Timing and size evidence for one joined task. Timestamps are epoch milliseconds. */
|
|
164
|
+
export interface TaskRecord {
|
|
165
|
+
id: string;
|
|
166
|
+
worker: number;
|
|
167
|
+
name: string;
|
|
168
|
+
submitMs: number;
|
|
169
|
+
startMs: number;
|
|
170
|
+
endMs: number;
|
|
171
|
+
waitMs: number;
|
|
172
|
+
cpuMs?: number;
|
|
173
|
+
inputBytes: number;
|
|
174
|
+
outputBytes: number;
|
|
175
|
+
}
|
|
176
|
+
/** What a run did: results, how it was routed and what the speculation cost. */
|
|
177
|
+
export interface ExecutionReport {
|
|
178
|
+
/** Return values of the call, or of each call in a batch. */
|
|
179
|
+
values: unknown[];
|
|
180
|
+
/** Workers that executed regions; zero for a serial run. */
|
|
181
|
+
workers: number;
|
|
182
|
+
/** Regions discovered and dispatched. */
|
|
183
|
+
regions: number;
|
|
184
|
+
/** Regions that conflicted and replayed against committed state. */
|
|
185
|
+
replayed: number;
|
|
186
|
+
/** Regions or batches that fell back to native execution at the owner. */
|
|
187
|
+
fallbacks: number;
|
|
188
|
+
/** `native-shared` ran proved kernels on the shared allocation without tracking. */
|
|
189
|
+
mode: 'serial' | 'speculative' | 'native-shared';
|
|
190
|
+
/** Set when the control-flow extractor or the iteration route produced the regions. */
|
|
191
|
+
extraction?: 'control-flow' | 'iteration';
|
|
192
|
+
/** `shared` regions read the physical allocation; `snapshot` ran on a copied arena. */
|
|
193
|
+
memoryMode?: 'shared' | 'snapshot';
|
|
194
|
+
/** Bytes copied into the worker group for snapshot execution. */
|
|
195
|
+
snapshotBytes?: number;
|
|
196
|
+
/** Why a run stayed serial or left the fast path. */
|
|
197
|
+
reason?: 'requested' | 'small-workload' | 'no-parallel-plan' | 'single-region' | 'unsupported-module' | 'dependency' | 'guard-failed' | 'snapshot-unavailable' | 'previous-conflicts' | 'opaque-input' | IterationReason;
|
|
198
|
+
/** The iteration executor's counts, summed over the owner calls of the run. */
|
|
199
|
+
iteration?: IterationReport;
|
|
200
|
+
/** Present when `FolioOptions.profile` is set. */
|
|
201
|
+
profile?: ExecutionProfile;
|
|
202
|
+
}
|
|
203
|
+
/** Opt-in timings. Process CPU is measured once at the coordinator, not summed from these. */
|
|
204
|
+
export interface ExecutionProfile {
|
|
205
|
+
/** Elapsed time of the whole run. */
|
|
206
|
+
wallMs: number;
|
|
207
|
+
/** Elapsed time of each region or batch observation on its worker. */
|
|
208
|
+
workerWallMs: number[];
|
|
209
|
+
/** Thread CPU time of each observation. */
|
|
210
|
+
workerCpuMs: number[];
|
|
211
|
+
/** Ordered dependency validation. */
|
|
212
|
+
validationMs: number;
|
|
213
|
+
/** Committing validated writes to canonical memory. */
|
|
214
|
+
commitMs: number;
|
|
215
|
+
/** Re-executing conflicted regions. */
|
|
216
|
+
replayMs: number;
|
|
217
|
+
/** Bytes tracked as read by speculative regions. */
|
|
218
|
+
readBytes: number;
|
|
219
|
+
/** Bytes tracked as written by speculative regions. */
|
|
220
|
+
writeBytes: number;
|
|
221
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { type FoldChunk } from '../execution/fold.ts';
|
|
2
|
+
import { type TaskLink, type TaskPool } from '../node/tasks.ts';
|
|
3
|
+
import { type AffineCheck, type AffineRing } from './affine.ts';
|
|
4
|
+
/** Where the probe puts the context and the data in the kernel's linear memory. */
|
|
5
|
+
export declare const CONTEXT_ADDRESS: number;
|
|
6
|
+
export declare const DATA_ADDRESS: number;
|
|
7
|
+
/** Where the context pointer, the data pointer and the length sit in the entry's parameters. */
|
|
8
|
+
export interface ContextLayout {
|
|
9
|
+
entry: string;
|
|
10
|
+
ctx: number;
|
|
11
|
+
ptr: number;
|
|
12
|
+
len: number;
|
|
13
|
+
/** Bytes of the context the probe examines and every task copies. At most 256. */
|
|
14
|
+
window: number;
|
|
15
|
+
}
|
|
16
|
+
/** Inputs a worker needs to run a context kernel: module, layout, image and state bytes. */
|
|
17
|
+
export interface ContextSubject {
|
|
18
|
+
module: WebAssembly.Module | Uint8Array;
|
|
19
|
+
layout: ContextLayout;
|
|
20
|
+
context: Uint8Array;
|
|
21
|
+
state: number[];
|
|
22
|
+
}
|
|
23
|
+
/** One independent part of the state vector, with the ring it is affine over. */
|
|
24
|
+
export interface StateFactor {
|
|
25
|
+
ring: AffineRing;
|
|
26
|
+
/** Context offsets of the bytes of this factor, ascending. */
|
|
27
|
+
offsets: number[];
|
|
28
|
+
/** Positions of those bytes in the state vector of the model. */
|
|
29
|
+
slots: number[];
|
|
30
|
+
wordBytes: number;
|
|
31
|
+
endian: 'le' | 'be';
|
|
32
|
+
words: number;
|
|
33
|
+
/** Bits per word. For `gf2` it is the width of the whole factor. */
|
|
34
|
+
bits: number;
|
|
35
|
+
/** `gf2`: columns of the one-unit bit matrix. `z2w`: words x words matrix over Z/2^bits. */
|
|
36
|
+
operator: bigint[] | bigint[][];
|
|
37
|
+
}
|
|
38
|
+
export interface StateCheck extends AffineCheck {
|
|
39
|
+
/** Index of the factor, or -1 for a check on the whole context. */
|
|
40
|
+
factor: number;
|
|
41
|
+
shape: string;
|
|
42
|
+
}
|
|
43
|
+
/** The recovered model of a state vector that lives in the context. */
|
|
44
|
+
export interface StateModel {
|
|
45
|
+
kind: 'state';
|
|
46
|
+
layout: ContextLayout;
|
|
47
|
+
/** The context image the probe ran from. Bytes that are not state stay at these values. */
|
|
48
|
+
context: Uint8Array;
|
|
49
|
+
/** Context offsets of the state: bytes that a call both reads and writes. */
|
|
50
|
+
state: number[];
|
|
51
|
+
/** Bytes a call reads and never writes, and that change the result. Held at `context`. */
|
|
52
|
+
params: number[];
|
|
53
|
+
/** Bytes a call writes and never reads. They are not state and are not carried. */
|
|
54
|
+
scratch: number[];
|
|
55
|
+
factors: StateFactor[];
|
|
56
|
+
align: number;
|
|
57
|
+
checks: StateCheck[];
|
|
58
|
+
calls: number;
|
|
59
|
+
}
|
|
60
|
+
export interface StateRefusal {
|
|
61
|
+
kind: 'refusal';
|
|
62
|
+
reason: string;
|
|
63
|
+
checks: StateCheck[];
|
|
64
|
+
calls: number;
|
|
65
|
+
}
|
|
66
|
+
export interface StateProbeOptions {
|
|
67
|
+
/** Seed of the PRNG. The default is fixed. */
|
|
68
|
+
seed?: number;
|
|
69
|
+
/** Trials per check. The default is 32. */
|
|
70
|
+
trials?: number;
|
|
71
|
+
/** Every probed data length is a multiple of this. */
|
|
72
|
+
align?: number;
|
|
73
|
+
/** The context image as the caller's init function left it. The default is zeros. */
|
|
74
|
+
context?: Uint8Array;
|
|
75
|
+
/** Bytes of the context to examine, at most 256. The default is 256. */
|
|
76
|
+
window?: number;
|
|
77
|
+
}
|
|
78
|
+
export interface StateFoldOptions {
|
|
79
|
+
/** The state vector before the first byte. The default is the state bytes of `model.context`. */
|
|
80
|
+
initial?: Uint8Array;
|
|
81
|
+
chunks?: FoldChunk[];
|
|
82
|
+
}
|
|
83
|
+
export interface StateFoldResult {
|
|
84
|
+
state: Uint8Array;
|
|
85
|
+
chunks: number;
|
|
86
|
+
tasks: number;
|
|
87
|
+
validated: number;
|
|
88
|
+
mismatchAt: number;
|
|
89
|
+
fallbackBytes: number;
|
|
90
|
+
}
|
|
91
|
+
/** One private instance of a context kernel: put and get bytes, call it, count the calls. */
|
|
92
|
+
export declare class ContextKernel {
|
|
93
|
+
#private;
|
|
94
|
+
readonly arity: number;
|
|
95
|
+
readonly entry: string;
|
|
96
|
+
calls: number;
|
|
97
|
+
constructor(module: WebAssembly.Module | Uint8Array, entry: string);
|
|
98
|
+
/** Puts the memory back to what it was after instantiation. */
|
|
99
|
+
restore(): void;
|
|
100
|
+
put(at: number, bytes: Uint8Array): void;
|
|
101
|
+
get(at: number, length: number): Uint8Array;
|
|
102
|
+
raw(args: (number | bigint)[]): number | bigint;
|
|
103
|
+
/** Copies of every byte of memory outside the given ranges, for the hidden state check. */
|
|
104
|
+
outside(ranges: [number, number][]): Uint8Array;
|
|
105
|
+
/** One call. Returns the context window afterwards, or undefined when the kernel traps. */
|
|
106
|
+
run(layout: ContextLayout, image: Uint8Array, data: Uint8Array): Uint8Array | undefined;
|
|
107
|
+
}
|
|
108
|
+
/** The context image after one init call. `inputs` is placed at the data address first. */
|
|
109
|
+
export declare function initialContext(module: WebAssembly.Module | Uint8Array, entry: string, args: (ctx: number, data: number) => (number | bigint)[], inputs?: Uint8Array, window?: number): Uint8Array;
|
|
110
|
+
/** A subject whose state is the whole window, for chains with no model. */
|
|
111
|
+
export declare function contextSubject(module: WebAssembly.Module | Uint8Array, entry: string, context: Uint8Array, layout?: Partial<ContextLayout>): ContextSubject;
|
|
112
|
+
/** The subject a model describes, for `serveContext`. */
|
|
113
|
+
export declare function modelSubject(module: WebAssembly.Module | Uint8Array, model: StateModel): ContextSubject;
|
|
114
|
+
export declare const pick: (image: Uint8Array, offsets: number[]) => Uint8Array;
|
|
115
|
+
export declare function toHex(bytes: Uint8Array): string;
|
|
116
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
117
|
+
export declare const bytesEqual: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
118
|
+
/** Next state after `length` bytes from `start`: A(length) start + offset, factor by factor. */
|
|
119
|
+
export declare function predictState(model: Pick<StateModel, 'factors' | 'align' | 'state'>, start: Uint8Array, length: number, offset: Uint8Array): Uint8Array;
|
|
120
|
+
/**
|
|
121
|
+
* Probes `entry`, a (context, data, length) function that updates a context in place, and returns
|
|
122
|
+
* the affine model of its state bytes or the reason there is none. State is the bytes a call both
|
|
123
|
+
* reads and writes; bytes only read are parameters. Each independent factor is checked over GF(2)
|
|
124
|
+
* and over Z/2^bits, and a factor affine in no ring refuses the whole context.
|
|
125
|
+
*
|
|
126
|
+
* Evidence is sampled: state outside the window is not seen, so `foldState` in exact mode is what
|
|
127
|
+
* makes a result trustworthy.
|
|
128
|
+
*/
|
|
129
|
+
export declare function probeState(module: WebAssembly.Module | Uint8Array, entry: string, options?: StateProbeOptions): StateModel | StateRefusal;
|
|
130
|
+
/**
|
|
131
|
+
* Worker side: answers `ctx:<hex state>` with the end state, and `ctxrec:<hex state>:<step>` with
|
|
132
|
+
* the state every `step` bytes. Each task rebuilds the image from `subject.context`.
|
|
133
|
+
*/
|
|
134
|
+
export declare function serveContext(link: TaskLink, subject: ContextSubject): void;
|
|
135
|
+
/** The serial reference: one call over all the bytes on a private instance. */
|
|
136
|
+
export declare function stateSerial(subject: ContextSubject): (input: Uint8Array, state?: Uint8Array) => Uint8Array;
|
|
137
|
+
/**
|
|
138
|
+
* Exact fold of a context state: pass 1 runs each chunk from zero, pass 2 from predicted starts,
|
|
139
|
+
* and each end is checked against the next start. The first mismatch runs the rest serially.
|
|
140
|
+
* Returns the state bytes only; scratch bytes a call writes and never reads are not returned.
|
|
141
|
+
*/
|
|
142
|
+
export declare function foldState(pool: TaskPool, input: Uint8Array, model: StateModel, options?: StateFoldOptions): StateFoldResult;
|