@onda-lang/processor-abi 0.8.4 → 0.8.6
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 +11 -2
- package/api.md +16 -3
- package/package.json +1 -1
- package/src/index.d.ts +18 -2
- package/src/index.js +18 -1
- package/src/payload.js +9 -0
package/README.md
CHANGED
|
@@ -65,9 +65,18 @@ Wire payloads are packed little-endian in canonical structure-of-arrays leaf ord
|
|
|
65
65
|
`sizes(lengths)` when only dynamic slice lengths are known, or `requiredWorkspace(payload)` to
|
|
66
66
|
preflight encoded bytes. Allocate payload, workspace, and the 16-byte `EventInput` descriptor before
|
|
67
67
|
realtime dispatch, and keep their memory regions disjoint from one another and processor storage.
|
|
68
|
+
`plan.tensorMetadata` exposes the same flattened contract as immutable records containing the leaf
|
|
69
|
+
`path`, primitive `encoding`, fixed `shape`, owning `parameterIndex`, `isSlice`, and
|
|
70
|
+
`fixedElementCount`. It is suitable for generating typed host storage or diagnostics without
|
|
71
|
+
walking the recursive schema again.
|
|
68
72
|
`PayloadPlan.encode()` itself allocates and therefore belongs on a host/control thread, as does
|
|
69
73
|
decoding published delegate records. An event result of `PROCESSOR_EXECUTION_INPUT_REJECTED` (`2`)
|
|
70
|
-
means preflight failed
|
|
74
|
+
means preflight failed after output was reset but before handler or processor-state mutation.
|
|
75
|
+
|
|
76
|
+
WebAssembly intentionally exposes only the packed checked event entry. JavaScript values cross a
|
|
77
|
+
thread boundary and must enter Wasm linear memory, so the native synchronous borrowed-view contract
|
|
78
|
+
cannot provide end-to-end zero-copy dispatch on the Web. Web hosts should prepare capacity ahead of
|
|
79
|
+
time and reuse the payload and workspace regions.
|
|
71
80
|
|
|
72
81
|
## Delegate batches
|
|
73
82
|
|
|
@@ -99,7 +108,7 @@ writeDelegateBatch(memory, batchAddress, storageAddress, capacityBytes);
|
|
|
99
108
|
writeExecutionOutput(memory, outputAddress, batchAddress, 0);
|
|
100
109
|
// Before onda_process (or initialization):
|
|
101
110
|
resetExecutionOutput(memory, outputAddress);
|
|
102
|
-
// Pass outputAddress as the final entry argument. onda_event_N resets it
|
|
111
|
+
// Pass outputAddress as the final entry argument. onda_event_N resets it before preflight.
|
|
103
112
|
const batch = readDelegateBatch(memory, batchAddress);
|
|
104
113
|
const storage = new Uint8Array(memory.buffer, storageAddress, batch.usedBytes);
|
|
105
114
|
const occurrences = decodeDelegateRecords(
|
package/api.md
CHANGED
|
@@ -135,12 +135,14 @@ endpoints, apply linear, logarithmic, or curved scale, and clamp and snap to the
|
|
|
135
135
|
|
|
136
136
|
Complete wasm32 processor exports receive an optional execution-output descriptor containing
|
|
137
137
|
independently nullable delegate and print batches. Allocate all descriptors and storage before
|
|
138
|
-
real-time execution.
|
|
138
|
+
real-time execution. Their linear-memory regions must be mutually disjoint and must not overlap any
|
|
139
|
+
other region accessed by the processor call, matching the processor ABI's execution-output
|
|
140
|
+
contract.
|
|
139
141
|
|
|
140
142
|
`writeDelegateBatch` and `writePrintBatch` initialize reusable batch descriptors.
|
|
141
143
|
`writeExecutionOutput` connects their addresses. Call `resetExecutionOutput` immediately before
|
|
142
|
-
every generated init or process entry. Generated event entries reset
|
|
143
|
-
|
|
144
|
+
every generated init or process entry. Generated event entries reset before input preflight, so
|
|
145
|
+
rejected input returns empty batches. After a successful generated call,
|
|
144
146
|
`readDelegateBatch` or `readPrintBatch` validates the result counters.
|
|
145
147
|
`decodeDelegateRecords` converts delegate payloads using `metadata.delegates`.
|
|
146
148
|
`decodePrintRecords` preserves primitive types and source sites; `formatPrintRecords` and
|
|
@@ -303,6 +305,7 @@ OndaPayloadSchema
|
|
|
303
305
|
OndaPayloadDefault
|
|
304
306
|
OndaPayloadValue
|
|
305
307
|
OndaPayloadSizes
|
|
308
|
+
OndaPayloadTensorMetadata
|
|
306
309
|
PayloadPlan
|
|
307
310
|
canonicalF32Number
|
|
308
311
|
EVENT_INPUT_SIZE_BYTES
|
|
@@ -432,11 +435,21 @@ are rejected. Missing event arguments use declared constant defaults.
|
|
|
432
435
|
Supply `i64` as `bigint`, an exact safe integer, or a decimal string. `decode(bytes)` returns named
|
|
433
436
|
nested values with `bigint` for `i64`. Plans own immutable schema snapshots.
|
|
434
437
|
|
|
438
|
+
`tensorMetadata` exposes the schema's flattened SoA contract without reparsing JSON. Each immutable
|
|
439
|
+
record contains `path`, `encoding`, fixed `shape`, `parameterIndex`, `isSlice`, and
|
|
440
|
+
`fixedElementCount`. Tuple path components use `__0`, `__1`, and so on. A slice's runtime tensor
|
|
441
|
+
length is its logical length times `fixedElementCount`; the dynamic outer axis is therefore not
|
|
442
|
+
repeated in `shape`.
|
|
443
|
+
|
|
435
444
|
`requiredWorkspace(bytes)` preflights packed little-endian input. `sizes(lengths)` reports wire
|
|
436
445
|
and aligned workspace sizes without allocating payload storage. Low-level wasm hosts provision
|
|
437
446
|
both regions and a 16-byte descriptor, then call `writeEventInput` before invoking the event.
|
|
438
447
|
Rejected input returns `PROCESSOR_EXECUTION_INPUT_REJECTED` (2) and leaves processor state usable.
|
|
439
448
|
`OndaAudioProcessor.trigger` performs logical encoding before transferring bytes to the worklet.
|
|
449
|
+
Web hosts intentionally have no unchecked tensor-view event entry: JavaScript values must cross the
|
|
450
|
+
main-thread/worklet and Wasm linear-memory boundaries, so native borrowed addresses cannot be
|
|
451
|
+
preserved end to end. Web event dispatch remains the packed, checked `onda_event_N` path and uses
|
|
452
|
+
its preallocated workspace.
|
|
440
453
|
Decoded `f32` leaves use `canonicalF32Number(value)`: the returned JavaScript number has the
|
|
441
454
|
shortest decimal representation that round-trips to the same `f32`, so JSON and controls do not
|
|
442
455
|
expose an irrelevant widened binary tail.
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export const PROCESSOR_ARTIFACT_FORMAT: "onda-processor";
|
|
2
2
|
// Synchronized from format-versions.json; do not edit these copies directly.
|
|
3
3
|
export const PROCESSOR_ARTIFACT_FORMAT_VERSION: 6;
|
|
4
|
-
export const PROCESSOR_ABI_VERSION:
|
|
4
|
+
export const PROCESSOR_ABI_VERSION: 7;
|
|
5
5
|
export const PROCESSOR_EXECUTION_OK: 0;
|
|
6
6
|
export const PROCESSOR_EXECUTION_RUNTIME_SAFETY_FAILURE: 1;
|
|
7
7
|
export const PROCESSOR_INIT_PRESERVE_PINNED: 0;
|
|
@@ -167,6 +167,18 @@ export interface OndaPayloadField {
|
|
|
167
167
|
}
|
|
168
168
|
export interface OndaPayloadSchema { params: OndaPayloadField[] }
|
|
169
169
|
|
|
170
|
+
export interface OndaPayloadTensorMetadata {
|
|
171
|
+
/** Dot-separated top-level parameter and struct-field path. Array axes are described by shape. */
|
|
172
|
+
readonly path: string;
|
|
173
|
+
readonly encoding: OndaScalarType;
|
|
174
|
+
/** Fixed array axes, outermost first. */
|
|
175
|
+
readonly shape: readonly number[];
|
|
176
|
+
readonly parameterIndex: number;
|
|
177
|
+
readonly isSlice: boolean;
|
|
178
|
+
/** Product of all fixed array axes. */
|
|
179
|
+
readonly fixedElementCount: number;
|
|
180
|
+
}
|
|
181
|
+
|
|
170
182
|
export type OndaPayloadValue = number | bigint | boolean | string | OndaPayloadValue[] | { [name: string]: OndaPayloadValue };
|
|
171
183
|
export interface OndaPayloadSizes { wire: number; workspace: number }
|
|
172
184
|
export class PayloadPlan {
|
|
@@ -176,6 +188,8 @@ export class PayloadPlan {
|
|
|
176
188
|
readonly minimumWorkspace: number;
|
|
177
189
|
readonly dynamicParameters: number;
|
|
178
190
|
readonly abiParameterCount: number;
|
|
191
|
+
/** Flattened SoA tensors in event/delegate ABI order. */
|
|
192
|
+
readonly tensorMetadata: readonly OndaPayloadTensorMetadata[];
|
|
179
193
|
/** Whether scalar representations match this flattened ABI parameter's schema default. */
|
|
180
194
|
matchesAbiDefault(parameter: number, defaultReprs: readonly string[] | null): boolean;
|
|
181
195
|
sizes(lengths: readonly number[]): OndaPayloadSizes;
|
|
@@ -257,7 +271,7 @@ export interface OndaProcessorMetadata {
|
|
|
257
271
|
format: "onda-processor";
|
|
258
272
|
format_version: 6;
|
|
259
273
|
artifact_kind: OndaArtifactKind;
|
|
260
|
-
abi_version:
|
|
274
|
+
abi_version: 7;
|
|
261
275
|
backend: string;
|
|
262
276
|
mir_schema_version: number;
|
|
263
277
|
target: OndaTargetInfo;
|
|
@@ -273,6 +287,8 @@ export interface OndaProcessorMetadata {
|
|
|
273
287
|
init: string;
|
|
274
288
|
process: string;
|
|
275
289
|
events: string[];
|
|
290
|
+
/** Trusted native SoA entries parallel to events; absent for WebAssembly artifacts. */
|
|
291
|
+
event_views?: string[];
|
|
276
292
|
};
|
|
277
293
|
runtime: {
|
|
278
294
|
state_size_bytes: number;
|
package/src/index.js
CHANGED
|
@@ -7,7 +7,7 @@ const PARAM_CONTROL = globalThis.__ONDA_PARAM_CONTROL_V2__;
|
|
|
7
7
|
export const PROCESSOR_ARTIFACT_FORMAT = "onda-processor";
|
|
8
8
|
// Synchronized from format-versions.json; do not edit these copies directly.
|
|
9
9
|
export const PROCESSOR_ARTIFACT_FORMAT_VERSION = 6;
|
|
10
|
-
export const PROCESSOR_ABI_VERSION =
|
|
10
|
+
export const PROCESSOR_ABI_VERSION = 7;
|
|
11
11
|
export const PROCESSOR_EXECUTION_OK = 0;
|
|
12
12
|
export const PROCESSOR_EXECUTION_RUNTIME_SAFETY_FAILURE = 1;
|
|
13
13
|
export const PROCESSOR_INIT_PRESERVE_PINNED = 0;
|
|
@@ -143,6 +143,17 @@ export function validateProcessorMetadata(metadata, expectedKind = null) {
|
|
|
143
143
|
for (const name of metadata.exports.events) {
|
|
144
144
|
requireString(name, "exports.events[]");
|
|
145
145
|
}
|
|
146
|
+
if (metadata.exports.event_views !== undefined) {
|
|
147
|
+
if (!Array.isArray(metadata.exports.event_views)) {
|
|
148
|
+
throw new OndaArtifactError("exports.event_views must be an array when present");
|
|
149
|
+
}
|
|
150
|
+
if (metadata.exports.event_views.length !== metadata.exports.events.length) {
|
|
151
|
+
throw new OndaArtifactError("exports.event_views must be parallel to exports.events");
|
|
152
|
+
}
|
|
153
|
+
for (const name of metadata.exports.event_views) {
|
|
154
|
+
requireString(name, "exports.event_views[]");
|
|
155
|
+
}
|
|
156
|
+
}
|
|
146
157
|
if (!Array.isArray(metadata.integration?.required_symbols)) {
|
|
147
158
|
throw new OndaArtifactError("integration.required_symbols must be an array");
|
|
148
159
|
}
|
|
@@ -154,6 +165,7 @@ export function validateProcessorMetadata(metadata, expectedKind = null) {
|
|
|
154
165
|
metadata.exports.init,
|
|
155
166
|
metadata.exports.process,
|
|
156
167
|
...metadata.exports.events,
|
|
168
|
+
...(metadata.exports.event_views ?? []),
|
|
157
169
|
]) {
|
|
158
170
|
if (!requiredSymbols.has(name)) {
|
|
159
171
|
throw new OndaArtifactError(
|
|
@@ -175,6 +187,11 @@ export function validateProcessorMetadata(metadata, expectedKind = null) {
|
|
|
175
187
|
`integration profile '${String(profileKind)}' is incompatible with artifact kind '${metadata.artifact_kind}'`,
|
|
176
188
|
);
|
|
177
189
|
}
|
|
190
|
+
if (metadata.exports.event_views !== undefined && profileKind !== "native_relocatable_object") {
|
|
191
|
+
throw new OndaArtifactError(
|
|
192
|
+
"exports.event_views is only valid for native relocatable objects",
|
|
193
|
+
);
|
|
194
|
+
}
|
|
178
195
|
if (profileKind === "core_webassembly_module") {
|
|
179
196
|
requireLiteral(metadata.target.byte_order, "target.byte_order", "little_endian");
|
|
180
197
|
requireString(metadata.exports?.memory, "exports.memory");
|
package/src/payload.js
CHANGED
|
@@ -136,6 +136,15 @@ export class PayloadPlan {
|
|
|
136
136
|
}
|
|
137
137
|
this.abiParameterCount = abiParameter;
|
|
138
138
|
this.dynamicParameters = this.parameters.filter((param) => param.dynamic).length;
|
|
139
|
+
this.tensorMetadata = Object.freeze(this.parameters.flatMap((group, parameterIndex) =>
|
|
140
|
+
this.tensors.slice(group.start, group.end).map((tensor) => Object.freeze({
|
|
141
|
+
path: tensor.path,
|
|
142
|
+
encoding: tensor.encoding,
|
|
143
|
+
shape: Object.freeze([...tensor.shape]),
|
|
144
|
+
parameterIndex,
|
|
145
|
+
isSlice: group.dynamic,
|
|
146
|
+
fixedElementCount: tensor.elements,
|
|
147
|
+
}))));
|
|
139
148
|
const minimum = this.sizes(Array(this.dynamicParameters).fill(0));
|
|
140
149
|
this.fixedWireSize = this.dynamicParameters === 0 ? minimum.wire : null;
|
|
141
150
|
this.minimumWorkspace = minimum.workspace;
|