@nodetool-ai/kernels 0.0.0-bootstrap.0 → 0.8.14
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 +44 -0
- package/dist/.nodetool-build-stamp +1 -0
- package/dist/backend.d.ts +34 -0
- package/dist/backend.d.ts.map +1 -0
- package/dist/backend.js +9 -0
- package/dist/backend.js.map +1 -0
- package/dist/generated/kernels-wasm.d.ts +3 -0
- package/dist/generated/kernels-wasm.d.ts.map +1 -0
- package/dist/generated/kernels-wasm.js +887 -0
- package/dist/generated/kernels-wasm.js.map +1 -0
- package/dist/index.d.ts +254 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +605 -0
- package/dist/index.js.map +1 -0
- package/dist/wasm.d.ts +10 -0
- package/dist/wasm.d.ts.map +1 -0
- package/dist/wasm.js +101 -0
- package/dist/wasm.js.map +1 -0
- package/package.json +48 -3
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# @nodetool-ai/kernels
|
|
2
|
+
|
|
3
|
+
The typed TypeScript API of the [native kernel library](../../native/kernels/README.md):
|
|
4
|
+
the sample and pixel loops of the audio and image nodes, written in C++.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { loadKernels } from "@nodetool-ai/kernels";
|
|
8
|
+
|
|
9
|
+
const kernels = await loadKernels();
|
|
10
|
+
const out = kernels.imageEqualize(rgba, width, height);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`loadKernels()` selects the host once for each process:
|
|
14
|
+
|
|
15
|
+
- Inside the graph runner, the native `kernels` capability runs the library
|
|
16
|
+
as native code.
|
|
17
|
+
- Everywhere else (the Node server, the browser, workers), the package
|
|
18
|
+
instantiates the WebAssembly build of the same sources. The module is
|
|
19
|
+
embedded in `src/generated/kernels-wasm.ts`, so no asset loads at run time.
|
|
20
|
+
|
|
21
|
+
Both hosts give the same output. `loadWasmKernels()` always picks the
|
|
22
|
+
WebAssembly build, which the tests use.
|
|
23
|
+
|
|
24
|
+
## Conventions
|
|
25
|
+
|
|
26
|
+
- Image methods take straight-alpha RGBA8 and return a new buffer. They
|
|
27
|
+
process RGB and copy alpha.
|
|
28
|
+
- Audio methods take interleaved float32 samples and return a new buffer.
|
|
29
|
+
- A streaming method takes a `state` array that the caller owns and passes
|
|
30
|
+
again with the next chunk. `createBiquadState`, `createOscillatorState`,
|
|
31
|
+
`createSamplerState` and `STATE_LEN` give its size.
|
|
32
|
+
- A method checks that each buffer holds the elements the kernel reads, and
|
|
33
|
+
throws a `RangeError` before the call when it does not.
|
|
34
|
+
|
|
35
|
+
## Tests
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm run test --workspace=packages/kernels
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
`tests/parity.test.ts` compares each kernel with a copy of the TypeScript
|
|
42
|
+
loop it replaced (`tests/reference.ts`). Image kernels must be byte-equal and
|
|
43
|
+
audio kernels sample-equal. `tests/biquad.test.ts` checks the filter
|
|
44
|
+
responses and that the filter state carries across chunks.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2026-11-26T12:48:27.641Z
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one call shape that every kernel host implements: the WebAssembly
|
|
3
|
+
* module in Node and the browser, and the graph runner's native `kernels`
|
|
4
|
+
* capability. The typed API in `index.ts` builds these calls.
|
|
5
|
+
*/
|
|
6
|
+
/** A typed array a kernel reads. */
|
|
7
|
+
export interface KernelInput {
|
|
8
|
+
readonly in: Uint8Array | Float32Array | Float64Array;
|
|
9
|
+
}
|
|
10
|
+
/** A typed array a kernel writes. Its prior contents are not read. */
|
|
11
|
+
export interface KernelOutput {
|
|
12
|
+
readonly out: Uint8Array | Float32Array | Float64Array;
|
|
13
|
+
}
|
|
14
|
+
/** A typed array a kernel reads and writes, such as carried filter state. */
|
|
15
|
+
export interface KernelInOut {
|
|
16
|
+
readonly inout: Uint8Array | Float32Array | Float64Array;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* One argument of a kernel call, in the order of the C declaration in
|
|
20
|
+
* `native/kernels/include/nodetool/kernels.h`. A number passes a scalar and
|
|
21
|
+
* `null` passes a null pointer.
|
|
22
|
+
*/
|
|
23
|
+
export type KernelArg = KernelInput | KernelOutput | KernelInOut | number | null;
|
|
24
|
+
/** A host that runs a kernel of `kernels.h` by name. */
|
|
25
|
+
export interface KernelBackend {
|
|
26
|
+
/** Which host this is, for logs and benches. */
|
|
27
|
+
readonly kind: "wasm" | "native";
|
|
28
|
+
/** Runs the C function `name` and returns its integer result (0 for void). */
|
|
29
|
+
call(name: string, args: readonly KernelArg[]): number;
|
|
30
|
+
}
|
|
31
|
+
/** NT_OK and NT_ERR_ARGS of kernels.h. */
|
|
32
|
+
export declare const NT_OK = 0;
|
|
33
|
+
export declare const NT_ERR_ARGS = -1;
|
|
34
|
+
//# sourceMappingURL=backend.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.d.ts","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;CACvD;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;CACxD;AAED,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG,YAAY,CAAC;CAC1D;AAED;;;;GAIG;AACH,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,WAAW,GAAG,MAAM,GAAG,IAAI,CAAC;AAEjF,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC5B,gDAAgD;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;IACjC,8EAA8E;IAC9E,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,SAAS,EAAE,GAAG,MAAM,CAAC;CACxD;AAED,0CAA0C;AAC1C,eAAO,MAAM,KAAK,IAAI,CAAC;AACvB,eAAO,MAAM,WAAW,KAAK,CAAC"}
|
package/dist/backend.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one call shape that every kernel host implements: the WebAssembly
|
|
3
|
+
* module in Node and the browser, and the graph runner's native `kernels`
|
|
4
|
+
* capability. The typed API in `index.ts` builds these calls.
|
|
5
|
+
*/
|
|
6
|
+
/** NT_OK and NT_ERR_ARGS of kernels.h. */
|
|
7
|
+
export const NT_OK = 0;
|
|
8
|
+
export const NT_ERR_ARGS = -1;
|
|
9
|
+
//# sourceMappingURL=backend.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"backend.js","sourceRoot":"","sources":["../src/backend.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAgCH,0CAA0C;AAC1C,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;AACvB,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kernels-wasm.d.ts","sourceRoot":"","sources":["../../src/generated/kernels-wasm.ts"],"names":[],"mappings":"AAIA,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,QAk3BQ,CAAC"}
|