-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreateVectorBackend.ts
More file actions
28 lines (27 loc) · 948 Bytes
/
CreateVectorBackend.ts
File metadata and controls
28 lines (27 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { detectBackend } from "./BackendKind";
import type { VectorBackend } from "./VectorBackend";
import { WasmVectorBackend } from "./WasmVectorBackend";
import { WebGlVectorBackend } from "./WebGLVectorBackend";
import { WebGpuVectorBackend } from "./WebGPUVectorBackend";
import { WebNnVectorBackend } from "./WebNNVectorBackend";
export async function createVectorBackend(
wasmBytes: ArrayBuffer
): Promise<VectorBackend> {
const kind = detectBackend();
if (kind === "webgpu") {
return WebGpuVectorBackend.create().catch(() =>
WasmVectorBackend.create(wasmBytes)
);
}
if (kind === "webgl") {
return Promise.resolve()
.then(() => WebGlVectorBackend.create())
.catch(() => WasmVectorBackend.create(wasmBytes));
}
if (kind === "webnn") {
return WebNnVectorBackend.create(wasmBytes).catch(() =>
WasmVectorBackend.create(wasmBytes)
);
}
return WasmVectorBackend.create(wasmBytes);
}