-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.js
39 lines (37 loc) · 851 Bytes
/
index.js
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
29
30
31
32
33
34
35
36
37
38
39
export {
default as init,
initSync,
Model,
Tensor,
} from "./dist/rten.js";
/**
* Return true if the current JS environment supports the SIMD extension for
* WebAssembly.
*/
function simdSupported() {
// Tiny WebAssembly file generated from the following source using `wat2wasm`:
//
// (module
// (func (result v128)
// i32.const 0
// i8x16.splat
// i8x16.popcnt
// )
// )
const simdTest = Uint8Array.from([
0, 97, 115, 109, 1, 0, 0, 0, 1, 5, 1, 96, 0, 1, 123, 3, 2, 1, 0, 10, 10, 1,
8, 0, 65, 0, 253, 15, 253, 98, 11,
]);
return WebAssembly.validate(simdTest);
}
/**
* Return the filename of the preferred RTen binary for the current
* environment.
*/
export function binaryName() {
if (simdSupported()) {
return "rten_bg.wasm";
} else {
return "rten-nosimd_bg.wasm";
}
}