numbl 0.2.0 → 0.3.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.
Files changed (37) hide show
  1. package/binding.gyp +8 -3
  2. package/dist-cli/cli.js +6676 -3695
  3. package/dist-lib/lib.js +6703 -3341
  4. package/dist-lib/numbl-core/executeCode.d.ts +3 -10
  5. package/dist-lib/numbl-core/fileIOAdapter.d.ts +2 -0
  6. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +28 -24
  7. package/dist-lib/numbl-core/jit/e1/complexKernelEmit.d.ts +46 -0
  8. package/dist-lib/numbl-core/jit/e1/hash.d.ts +10 -0
  9. package/dist-lib/numbl-core/jit/e1/kernelEmit.d.ts +1 -1
  10. package/dist-lib/numbl-core/jit/e1/multiReductionKernel.d.ts +66 -0
  11. package/dist-lib/numbl-core/jit/e2/assignKernel.d.ts +34 -0
  12. package/dist-lib/numbl-core/jit/e2/astToJitExpr.d.ts +25 -0
  13. package/dist-lib/numbl-core/jit/e2/cache.d.ts +80 -0
  14. package/dist-lib/numbl-core/jit/e2/chainKernelEmit.d.ts +55 -0
  15. package/dist-lib/numbl-core/jit/e2/classify.d.ts +119 -0
  16. package/dist-lib/numbl-core/jit/e2/compileFn.d.ts +16 -0
  17. package/dist-lib/numbl-core/jit/e2/complexChainKernelEmit.d.ts +79 -0
  18. package/dist-lib/numbl-core/jit/e2/emitShared.d.ts +71 -0
  19. package/dist-lib/numbl-core/jit/e2/install.d.ts +11 -0
  20. package/dist-lib/numbl-core/jit/e2/liveness.d.ts +29 -0
  21. package/dist-lib/numbl-core/jit/e2/loopKernel.d.ts +49 -0
  22. package/dist-lib/numbl-core/jit/e2/loopKernelEmit.d.ts +75 -0
  23. package/dist-lib/numbl-core/jit/e2/multiReductionDriver.d.ts +24 -0
  24. package/dist-lib/numbl-core/jit/e2/reductionKernelEmit.d.ts +72 -0
  25. package/dist-lib/numbl-core/jit/e2/scalarFnDriver.d.ts +29 -0
  26. package/dist-lib/numbl-core/jit/fusedScalarEmit.d.ts +8 -0
  27. package/dist-lib/numbl-core/jit/heavyOps.d.ts +15 -0
  28. package/dist-lib/numbl-core/jit/js/jitCodegen.d.ts +1 -1
  29. package/dist-lib/numbl-core/jit/js/jsFusedCodegen.d.ts +1 -1
  30. package/dist-lib/numbl-core/jit/js/jsMultiReduction.d.ts +70 -0
  31. package/dist-lib/numbl-core/version.d.ts +1 -1
  32. package/native/numbl_addon.cpp +9 -0
  33. package/package.json +2 -4
  34. package/dist-lib/numbl-core/jit/c/hybrid.d.ts +0 -42
  35. package/dist-lib/numbl-core/jit/c/install.d.ts +0 -15
  36. package/dist-lib/numbl-core/jit/c/parityError.d.ts +0 -26
  37. package/dist-lib/numbl-core/jit/c/registry.d.ts +0 -51
@@ -1,42 +0,0 @@
1
- /**
2
- * Hybrid JS/C-JIT compilation: when the outer body falls back to JS-JIT,
3
- * still try C-JIT at narrower scopes and splice the native handles in.
4
- * Two shapes:
5
- *
6
- * - `compileHybridCallees`: walks `generatedIRBodies` (one entry per
7
- * user-function specialization reached by the outer) and tries
8
- * C-JIT on each standalone. Successes get installed on
9
- * `rt.jitHelpers[$cjit_<jitName>]` and their cached JS source is
10
- * rewritten to `var <jitName> = $h.$cjit_<jitName>;` so the outer
11
- * JS transparently calls native code at the callee boundary.
12
- *
13
- * - `compileHybridLoops`: walks the outer's top-level JitStmt body,
14
- * finds `For`/`While` stmts whose body is C-feasible, extracts each
15
- * as a synthetic specialization (live-in vars → params, live-out
16
- * vars → outputs), compiles it to native, and replaces the loop
17
- * stmt in the outer's IR with a `UserCallWriteback` that invokes
18
- * the handle and writes back outputs into the outer's locals.
19
- *
20
- * Preconditions at call time:
21
- * - `interp.optimization >= 2`
22
- * - `interp.rt.jitHelpers` is populated (i.e. past executeCode init)
23
- * - the shared `generatedFns` / `generatedIRBodies` maps come from the
24
- * outer specialization's `LoweringResult`
25
- *
26
- * Calling convention matches: `$h.callUser($rt, name, fn, ...args)`
27
- * invokes `fn(...args)`, and the args are the JIT's emitted JS forms —
28
- * raw JS numbers for scalars, RuntimeTensor for tensors, etc. — same
29
- * shape the C-JIT wrapper expects since it was compiled with matching
30
- * `argTypes`.
31
- */
32
- import type { Interpreter } from "../../interpreter/interpreter.js";
33
- import type { GeneratedFn } from "../jitLower.js";
34
- import type { JitStmt } from "../jitTypes.js";
35
- import type { TypeEnv } from "../jitLowerTypes.js";
36
- export declare function compileHybridCallees(interp: Interpreter, generatedIRBodies: Map<string, GeneratedFn>, generatedFns: Map<string, string>): void;
37
- /**
38
- * Extract top-level For/While loops from the outer's IR and try to
39
- * compile each to native. On success the loop is replaced in-place by a
40
- * `UserCallWriteback` stmt.
41
- */
42
- export declare function compileHybridLoops(interp: Interpreter, outerBody: JitStmt[], outerEndEnv: TypeEnv, outerOutputNames: string[], generatedIRBodies: Map<string, GeneratedFn>, generatedFns: Map<string, string>): void;
@@ -1,15 +0,0 @@
1
- /**
2
- * Installs the C-JIT backend (koffi path). Side-effect import only.
3
- *
4
- * Must be imported exactly once from a Node-only entry point (currently
5
- * src/cli.ts). The browser bundle never reaches this file, so the
6
- * Node-only dependencies stay out of the web build.
7
- *
8
- * The JS wrapper handles:
9
- * - Extracting .data (Float64Array) and .data.length from RuntimeTensor args
10
- * - Pre-allocating output buffers (Float64Array for tensor outputs,
11
- * Float64Array(1) for scalar out-pointers)
12
- * - Buffer reuse for tensor outputs (same logic as jitHelpersTensor.ts)
13
- * - Wrapping results back into RuntimeTensor objects
14
- */
15
- export {};
@@ -1,26 +0,0 @@
1
- /**
2
- * Thrown under `--check-c-jit-parity` when the C-JIT declines to compile
3
- * a function/loop whose IR the JS-JIT would have accepted. The message
4
- * names the construct (from the feasibility checker) and the call site,
5
- * giving us an actionable punch list of features to implement in the
6
- * C-JIT so parity with JS-JIT holds.
7
- */
8
- export declare class CJitParityError extends Error {
9
- readonly reason: string;
10
- readonly kind: "infeasible" | "env";
11
- constructor(message: string, reason: string, kind: "infeasible" | "env");
12
- }
13
- /**
14
- * Build a one-line parity-error message with the offending construct,
15
- * the call site (function/loop name + file:line), and the arg-type
16
- * signature that triggered the specialization.
17
- */
18
- export declare function formatCJitParityMessage(opts: {
19
- kind: "infeasible" | "env";
20
- reason: string;
21
- reasonLine?: number;
22
- siteLabel: string;
23
- file: string;
24
- callSiteLine: number;
25
- argsDesc: string;
26
- }): string;
@@ -1,51 +0,0 @@
1
- /**
2
- * Registrable hook for the C-JIT backend.
3
- *
4
- * The C-JIT's implementation pulls in Node-only modules (`child_process`,
5
- * `fs`, `path`, ...) that would pollute the browser bundle if imported
6
- * statically from [jit/index.ts](./index.ts). This module defines a
7
- * thin interface + a module-level slot; the real backend is installed
8
- * from the CLI entry point via [install.ts](./install.ts),
9
- * which is only pulled into the Node-targeted build.
10
- *
11
- * When no backend is registered (e.g. browser, or someone running the
12
- * library API directly) `getCJitBackend()` returns null and
13
- * `tryJitCall` silently falls through to JS-JIT.
14
- */
15
- import type { Interpreter } from "../../interpreter/interpreter.js";
16
- import type { FunctionDef } from "../../interpreter/types.js";
17
- import type { JitStmt, JitType } from "../jitTypes.js";
18
- import type { GeneratedFn } from "../jitLower.js";
19
- /**
20
- * Outcome of a C-JIT compile attempt.
21
- *
22
- * - `ok: true`: compilation succeeded; `fn` is callable.
23
- * - `ok: false, kind: "infeasible"`: the lowered IR contains a construct
24
- * the C-JIT doesn't handle (JS-JIT probably would). Carries a `reason`
25
- * and optional `line` from the feasibility checker; `--check-c-jit-parity`
26
- * treats this as a hard error.
27
- * - `ok: false, kind: "env"`: the environment couldn't support C-JIT
28
- * (no C compiler, compile/link failed, header missing, etc.). Also a
29
- * hard error under `--check-c-jit-parity` because the user explicitly
30
- * asked for C-JIT.
31
- */
32
- export type CJitCompileResult = {
33
- ok: true;
34
- fn: (...args: unknown[]) => unknown;
35
- } | {
36
- ok: false;
37
- kind: "infeasible" | "env";
38
- reason: string;
39
- line?: number;
40
- };
41
- export interface CJitBackend {
42
- /**
43
- * Attempt to emit + compile + load a C specialization for the given
44
- * lowered IR. Returns a structured result: callers distinguish
45
- * `infeasible` (parity gap with JS-JIT) from `env` (missing compiler)
46
- * when `--check-c-jit-parity` is on.
47
- */
48
- tryCompile(interp: Interpreter, fn: FunctionDef, body: JitStmt[], outputNames: string[], localVars: Set<string>, outputType: JitType | null, outputTypes: JitType[], argTypes: JitType[], nargout: number, generatedIRBodies: Map<string, GeneratedFn>): CJitCompileResult;
49
- }
50
- export declare function registerCJitBackend(b: CJitBackend): void;
51
- export declare function getCJitBackend(): CJitBackend | null;