oidn-webgpu 0.0.0-stage → 0.6.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/CHANGELOG.md +182 -0
- package/LICENSE +21 -0
- package/README.md +89 -2
- package/dist/oidn.js +6140 -0
- package/dist/oidn.umd.cjs +1513 -0
- package/lib/UNet.d.ts +161 -0
- package/lib/UNet.js +536 -0
- package/lib/UNet.js.map +1 -0
- package/lib/WGPUComputePass.d.ts +62 -0
- package/lib/WGPUComputePass.js +278 -0
- package/lib/WGPUComputePass.js.map +1 -0
- package/lib/WGPUFullQuadPass.d.ts +50 -0
- package/lib/WGPUFullQuadPass.js +261 -0
- package/lib/WGPUFullQuadPass.js.map +1 -0
- package/lib/backend.d.ts +1 -0
- package/lib/backend.js +39 -0
- package/lib/backend.js.map +1 -0
- package/lib/finalRgbShader.d.ts +13 -0
- package/lib/finalRgbShader.js +160 -0
- package/lib/finalRgbShader.js.map +1 -0
- package/lib/gpuTypes.d.ts +158 -0
- package/lib/gpuTypes.js +27 -0
- package/lib/gpuTypes.js.map +1 -0
- package/lib/graphOptimizer.d.ts +54 -0
- package/lib/graphOptimizer.js +216 -0
- package/lib/graphOptimizer.js.map +1 -0
- package/lib/hdr.d.ts +31 -0
- package/lib/hdr.js +340 -0
- package/lib/hdr.js.map +1 -0
- package/lib/hdrTransfer.d.ts +22 -0
- package/lib/hdrTransfer.js +128 -0
- package/lib/hdrTransfer.js.map +1 -0
- package/lib/main.d.ts +57 -0
- package/lib/main.js +24 -0
- package/lib/main.js.map +1 -0
- package/lib/modelSpec.d.ts +80 -0
- package/lib/modelSpec.js +270 -0
- package/lib/modelSpec.js.map +1 -0
- package/lib/native/denoise.d.ts +25 -0
- package/lib/native/denoise.js +223 -0
- package/lib/native/denoise.js.map +1 -0
- package/lib/native/program.d.ts +53 -0
- package/lib/native/program.js +310 -0
- package/lib/native/program.js.map +1 -0
- package/lib/native/recordingDevice.d.ts +125 -0
- package/lib/native/recordingDevice.js +247 -0
- package/lib/native/recordingDevice.js.map +1 -0
- package/lib/nativeUNet.d.ts +25 -0
- package/lib/nativeUNet.js +184 -0
- package/lib/nativeUNet.js.map +1 -0
- package/lib/nativeUNetCore.d.ts +202 -0
- package/lib/nativeUNetCore.js +2945 -0
- package/lib/nativeUNetCore.js.map +1 -0
- package/lib/process.d.ts +37 -0
- package/lib/process.js +328 -0
- package/lib/process.js.map +1 -0
- package/lib/resourceTracker.d.ts +26 -0
- package/lib/resourceTracker.js +65 -0
- package/lib/resourceTracker.js.map +1 -0
- package/lib/sanitize.d.ts +15 -0
- package/lib/sanitize.js +28 -0
- package/lib/sanitize.js.map +1 -0
- package/lib/tileScheduler.d.ts +61 -0
- package/lib/tileScheduler.js +199 -0
- package/lib/tileScheduler.js.map +1 -0
- package/lib/tza.d.ts +15 -0
- package/lib/tza.js +114 -0
- package/lib/tza.js.map +1 -0
- package/lib/webnnUNet.d.ts +52 -0
- package/lib/webnnUNet.js +535 -0
- package/lib/webnnUNet.js.map +1 -0
- package/package.json +43 -4
- package/src/UNet.ts +861 -0
- package/src/WGPUComputePass.ts +382 -0
- package/src/WGPUFullQuadPass.ts +348 -0
- package/src/backend.ts +42 -0
- package/src/finalRgbShader.ts +186 -0
- package/src/gpuTypes.ts +179 -0
- package/src/graphOptimizer.ts +301 -0
- package/src/hdr.ts +398 -0
- package/src/hdrTransfer.ts +169 -0
- package/src/main.ts +126 -0
- package/src/modelSpec.ts +414 -0
- package/src/native/core-profile.json +40 -0
- package/src/native/denoise.ts +268 -0
- package/src/native/program.ts +326 -0
- package/src/native/recordingDevice.ts +341 -0
- package/src/nativeUNet.ts +269 -0
- package/src/nativeUNetCore.ts +3735 -0
- package/src/process.ts +368 -0
- package/src/resourceTracker.ts +94 -0
- package/src/sanitize.ts +29 -0
- package/src/tileScheduler.ts +330 -0
- package/src/tza.ts +136 -0
- package/src/webnnUNet.ts +812 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { type OIDNGPUBindGroup, type OIDNGPUBuffer, type OIDNGPUComputePipeline, type OIDNGPUDevice, type OIDNGPUQuerySet } from './gpuTypes.js';
|
|
2
|
+
import { type ExecutableModelNode, type ModelExecutionPlan } from './graphOptimizer.js';
|
|
3
|
+
import type { UNetModelGraph, ValidatedUNetModel } from './modelSpec';
|
|
4
|
+
import { OIDNResourceTracker, type OIDNResourceSnapshot } from './resourceTracker.js';
|
|
5
|
+
export type NativeUNetPrecision = 'fp32' | 'fp16';
|
|
6
|
+
export type NativeUNetPrecisionSetting = NativeUNetPrecision | 'auto';
|
|
7
|
+
export type NativeUNetKernel = 'direct' | 'implicit-gemm' | 'spatial' | 'subgroup' | 'subgroup-matrix';
|
|
8
|
+
export type NativeUNetKernelSetting = NativeUNetKernel | 'auto';
|
|
9
|
+
export type NativeUNetGemmWorkgroup = readonly [4 | 8 | 16, 4 | 8];
|
|
10
|
+
export interface NativeUNetGemmOptions {
|
|
11
|
+
/** Internal per-layer tile selection; explicit workgroup sizes remain fixed by default. */
|
|
12
|
+
tilePolicy?: 'fixed' | 'output-aligned';
|
|
13
|
+
/** Internal decoder source-branch scheduling experiment. */
|
|
14
|
+
decoderLoad?: 'per-load' | 'source-first';
|
|
15
|
+
/** Sub-pixel GEMM decoder experiment; defaults to FP16 with K-major weights. */
|
|
16
|
+
decoderSubPixel?: boolean;
|
|
17
|
+
/** Expand register-tile rows for native shader robustness; off by default in browsers. */
|
|
18
|
+
unrollRows?: boolean;
|
|
19
|
+
/** Internal pooling dispatch experiment for the GEMM execution path. */
|
|
20
|
+
poolLayout?: 'spatial' | 'channels';
|
|
21
|
+
/** Internal shared-memory padding experiment; does not change storage ABI. */
|
|
22
|
+
sharedLayout?: 'linear' | 'padded' | 'padded-input' | 'padded-weights';
|
|
23
|
+
/** Internal loop scheduling experiment; each output keeps the same K order. */
|
|
24
|
+
accumulationOrder?: 'k-major' | 'row-major';
|
|
25
|
+
/** Internal final-convolution experiments; retains the original FP16 partial order. */
|
|
26
|
+
finalLayer?: 'direct' | 'shared-input' | 'shared-input-weights' | 'shared-auto';
|
|
27
|
+
/** Internal load-layout experiments; packed loads preserve the FP16 storage bits. */
|
|
28
|
+
loadMode?: 'native' | 'packed-weights' | 'packed-all';
|
|
29
|
+
/** Incremental addressing (default), or the original analytic path for A/B comparisons. */
|
|
30
|
+
addressMode?: 'analytic' | 'incremental' | 'base-offset';
|
|
31
|
+
/** K-major (default) coalesces neighboring output-block loads; output-major preserves the old ABI. */
|
|
32
|
+
weightLayout?: 'output-major' | 'k-major';
|
|
33
|
+
/** Register tile height (default 8). The K reduction grouping stays fixed. */
|
|
34
|
+
rowsPerThread?: 2 | 4 | 8;
|
|
35
|
+
/** Workgroup width/height (default [8, 8]); width also selects output channel blocks. */
|
|
36
|
+
workgroupSize?: NativeUNetGemmWorkgroup;
|
|
37
|
+
}
|
|
38
|
+
/** Square multiply-add shape selected from `chromium-experimental-subgroup-matrix`. */
|
|
39
|
+
export interface NativeSubgroupMatrixConfig {
|
|
40
|
+
componentType: 'f16' | 'f32';
|
|
41
|
+
resultType: 'f16' | 'f32';
|
|
42
|
+
/** M = N = K. */
|
|
43
|
+
size: 8 | 16;
|
|
44
|
+
subgroupSize: number;
|
|
45
|
+
/**
|
|
46
|
+
* WGSL spelling: Chrome's `chromium_experimental_subgroup_matrix`, or
|
|
47
|
+
* wgpu/Naga's `wgpu_cooperative_matrix` for native hosts.
|
|
48
|
+
*/
|
|
49
|
+
dialect: 'tint' | 'naga';
|
|
50
|
+
}
|
|
51
|
+
/** Experimental subgroup-matrix tile tuning; not covered by semver. */
|
|
52
|
+
export interface NativeSubgroupMatrixOptions {
|
|
53
|
+
/** Output channel fragments per workgroup (default 2). */
|
|
54
|
+
outputFragments?: 1 | 2 | 4;
|
|
55
|
+
/** Preferred accumulation type when the adapter offers several. */
|
|
56
|
+
accumulation?: 'f32' | 'f16';
|
|
57
|
+
/** Sub-pixel decomposition of the upsampling decoder layers (default true). */
|
|
58
|
+
subPixel?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Double-buffered staging with register prefetch when the workgroup memory
|
|
61
|
+
* limit allows it (default false: 6-10% slower on an Apple M4 Max).
|
|
62
|
+
*/
|
|
63
|
+
doubleBuffer?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export interface NativeUNetOptions {
|
|
66
|
+
precision?: NativeUNetPrecisionSetting;
|
|
67
|
+
/** Experimental `subgroup-matrix` kernel tuning. */
|
|
68
|
+
subgroupMatrix?: NativeSubgroupMatrixOptions;
|
|
69
|
+
/**
|
|
70
|
+
* Convolution kernel selection. `auto` uses implicit GEMM for FP16/FP32
|
|
71
|
+
* convolutions and the direct kernel for the final output layer.
|
|
72
|
+
*/
|
|
73
|
+
kernel?: NativeUNetKernelSetting;
|
|
74
|
+
/** Optional implicit-GEMM tuning; other convolution kernels ignore it. */
|
|
75
|
+
gemm?: NativeUNetGemmOptions;
|
|
76
|
+
/** Maximum number of shape-dependent activation plans retained. */
|
|
77
|
+
shapeCacheSize?: number;
|
|
78
|
+
}
|
|
79
|
+
export interface NativeUNetLayerTiming {
|
|
80
|
+
id: string;
|
|
81
|
+
durationMs: number;
|
|
82
|
+
}
|
|
83
|
+
export interface NativeUNetExecutionProfile {
|
|
84
|
+
totalMs: number;
|
|
85
|
+
layers: NativeUNetLayerTiming[];
|
|
86
|
+
}
|
|
87
|
+
export interface NativePipelineSpec {
|
|
88
|
+
key: string;
|
|
89
|
+
code: string;
|
|
90
|
+
kernel?: NativeUNetKernel;
|
|
91
|
+
}
|
|
92
|
+
interface ActivationSlot {
|
|
93
|
+
buffer: OIDNGPUBuffer;
|
|
94
|
+
capacity: number;
|
|
95
|
+
}
|
|
96
|
+
export interface CachedExecution {
|
|
97
|
+
plan: ModelExecutionPlan;
|
|
98
|
+
valueBuffers: Map<string, OIDNGPUBuffer>;
|
|
99
|
+
slots: ActivationSlot[];
|
|
100
|
+
nodeBindings: OIDNGPUBindGroup[];
|
|
101
|
+
nodePipelines: OIDNGPUComputePipeline[];
|
|
102
|
+
nodeKernels: NativeUNetKernel[];
|
|
103
|
+
/** Subgroup-matrix output fragments per node (0 for other kernels). */
|
|
104
|
+
nodeFragments: number[];
|
|
105
|
+
inputPipeline: OIDNGPUComputePipeline;
|
|
106
|
+
inputUniform: OIDNGPUBuffer;
|
|
107
|
+
ownedBuffers: OIDNGPUBuffer[];
|
|
108
|
+
cpuInputBuffers?: OIDNGPUBuffer[];
|
|
109
|
+
cpuReadbackBuffer?: OIDNGPUBuffer;
|
|
110
|
+
lastUsed: number;
|
|
111
|
+
}
|
|
112
|
+
export declare function createInputPackShader(precision: NativeUNetPrecision, sourceCount: number): string;
|
|
113
|
+
/**
|
|
114
|
+
* Picks a square configuration, preferring f32 accumulation: mixed f16
|
|
115
|
+
* inputs first, then f32 inputs (whose f16-exact values give the same
|
|
116
|
+
* products), and f16 accumulation last.
|
|
117
|
+
*/
|
|
118
|
+
export declare function selectSubgroupMatrixConfig(device: OIDNGPUDevice, accumulation?: 'f32' | 'f16'): NativeSubgroupMatrixConfig | undefined;
|
|
119
|
+
export declare function resolveNativeUNetPrecision(device: OIDNGPUDevice, requested?: NativeUNetPrecisionSetting): NativeUNetPrecision;
|
|
120
|
+
/**
|
|
121
|
+
* Native, model-driven OIDN U-Net executor without asynchronous operations, so
|
|
122
|
+
* that scriptc can compile it for native hosts. `NativeUNetExecutor` adds the
|
|
123
|
+
* browser's asynchronous preparation, CPU readback and profiling.
|
|
124
|
+
*/
|
|
125
|
+
export declare class NativeUNetCore {
|
|
126
|
+
protected _device: OIDNGPUDevice;
|
|
127
|
+
readonly usedKernels: Set<NativeUNetKernel>;
|
|
128
|
+
/** Immutable packed weights and biases, for native resource sharing. */
|
|
129
|
+
get weightBuffers(): OIDNGPUBuffer[];
|
|
130
|
+
readonly precision: NativeUNetPrecision;
|
|
131
|
+
readonly kernelSetting: NativeUNetKernelSetting;
|
|
132
|
+
readonly gemm: Readonly<Required<NativeUNetGemmOptions>>;
|
|
133
|
+
readonly maxSpatialInputBlocks: number;
|
|
134
|
+
readonly subgroupsAvailable: boolean;
|
|
135
|
+
/** Selected configuration when the `subgroup-matrix` kernel can run. */
|
|
136
|
+
readonly subgroupMatrix?: NativeSubgroupMatrixConfig;
|
|
137
|
+
readonly subgroupMatrixOutputFragments: number;
|
|
138
|
+
readonly subgroupMatrixSubPixel: boolean;
|
|
139
|
+
readonly subgroupMatrixDoubleBuffer: boolean;
|
|
140
|
+
private _subgroupMatrixFixedFragments;
|
|
141
|
+
protected _model: UNetModelGraph;
|
|
142
|
+
private _gemmByOutputBlocks;
|
|
143
|
+
private _packedConvs;
|
|
144
|
+
protected _pipelineCache: Map<string, OIDNGPUComputePipeline>;
|
|
145
|
+
private _executionCache;
|
|
146
|
+
protected _retiredExecutions: Set<CachedExecution>;
|
|
147
|
+
private _clock;
|
|
148
|
+
private _shapeCacheSize;
|
|
149
|
+
private _profileNextExecution;
|
|
150
|
+
protected _profileOperations: number;
|
|
151
|
+
protected _resources: OIDNResourceTracker;
|
|
152
|
+
protected _disposed: boolean;
|
|
153
|
+
constructor(_device: OIDNGPUDevice, model: ValidatedUNetModel, options?: NativeUNetOptions);
|
|
154
|
+
private _pipeline;
|
|
155
|
+
protected _nodePipelineSpec(node: ExecutableModelNode, isFinal: boolean, fragments?: number): NativePipelineSpec;
|
|
156
|
+
/** The decoder's sources when it runs with the sub-pixel decomposition. */
|
|
157
|
+
private _subPixelDecoder;
|
|
158
|
+
private _subgroupMatrixSpec;
|
|
159
|
+
/**
|
|
160
|
+
* Output fragments per workgroup for a subgroup-matrix layer: the default
|
|
161
|
+
* unless that leaves fewer than SUBGROUP_MATRIX_MIN_WORKGROUPS workgroups,
|
|
162
|
+
* where one fragment keeps more of the GPU busy (low-resolution layers).
|
|
163
|
+
* Never more fragments than the output channels fill (the final RGB layer).
|
|
164
|
+
*/
|
|
165
|
+
private _subgroupMatrixFragmentsFor;
|
|
166
|
+
private _gemmForOutput;
|
|
167
|
+
private _matrixPool;
|
|
168
|
+
private _coalescedPool;
|
|
169
|
+
private _selectConvKernel;
|
|
170
|
+
private _nodePipeline;
|
|
171
|
+
private _createExecution;
|
|
172
|
+
protected _execution(width: number, height: number): CachedExecution;
|
|
173
|
+
/**
|
|
174
|
+
* Releases an evicted plan. The synchronous core destroys it at once; the
|
|
175
|
+
* browser executor waits for the queue first.
|
|
176
|
+
*/
|
|
177
|
+
protected _retireExecution(execution: CachedExecution): void;
|
|
178
|
+
/** Allocates shape-dependent execution resources before interactive use. */
|
|
179
|
+
prewarm(shapes: readonly {
|
|
180
|
+
width: number;
|
|
181
|
+
height: number;
|
|
182
|
+
}[]): void;
|
|
183
|
+
/** Captures per-pass GPU timestamps for the next execute call when supported. */
|
|
184
|
+
profileNextExecution(): boolean;
|
|
185
|
+
/** Shape-owned packed input; external preprocessing must write all lanes. */
|
|
186
|
+
packedInputBuffer(width: number, height: number): OIDNGPUBuffer;
|
|
187
|
+
/** Executes after a preprocessing pass has filled packedInputBuffer. */
|
|
188
|
+
executePacked(width: number, height: number): OIDNGPUBuffer;
|
|
189
|
+
execute(inputBuffers: readonly OIDNGPUBuffer[], width: number, height: number): OIDNGPUBuffer;
|
|
190
|
+
private _execute;
|
|
191
|
+
/**
|
|
192
|
+
* Receives the timestamp queries of a profiled execution. The synchronous
|
|
193
|
+
* core cannot read them back, so it releases them.
|
|
194
|
+
*/
|
|
195
|
+
protected _readProfile(querySet: OIDNGPUQuerySet, resolveBuffer: OIDNGPUBuffer, readbackBuffer: OIDNGPUBuffer, labels: string[]): void;
|
|
196
|
+
protected _releaseBuffer(buffer: OIDNGPUBuffer | undefined): void;
|
|
197
|
+
protected _releaseQuerySet(querySet: OIDNGPUQuerySet | undefined): void;
|
|
198
|
+
protected _destroyExecution(execution: CachedExecution): void;
|
|
199
|
+
getResourceInfo(): OIDNResourceSnapshot;
|
|
200
|
+
dispose(): void;
|
|
201
|
+
}
|
|
202
|
+
export {};
|