Optionaloptions: { benchmark?: boolean; powerPreference?: GPUPowerPreference }Optionalbenchmark?: booleanenable GPU timestamp queries; BLAS functions return { result, gpuTimeMs } (default: false)
OptionalpowerPreference?: GPUPowerPreferenceGPU power preference (default: "high-performance").
This is a hint to the browser: on dual-GPU systems, "high-performance" typically favors the discrete GPU
and "low-power" favors the integrated one.
See MDN: GPU.requestAdapter().
import { init, gpuName } from "wgblas";
await init();
const { description, device } = gpuName();
console.log("description:", description, "device:", device);
import { init, gpuName } from "wgblas";
await init({ powerPreference: "low-power" });
const { description, device } = gpuName();
console.log("description:", description, "device:", device);
import { init, sscal } from "wgblas";
const device = await init({ benchmark: true });
const n = 5;
const alpha = 2.0;
const x = new Float32Array([1, 2, 3, 4, 5]);
const { result, gpuTimeMs } = await sscal(device, n, alpha, x, 1);
console.log(`Result: [${Array.from(result).join(", ")}]`);
console.log(`GPU time: ${gpuTimeMs.toFixed(3)} ms`);
Initializes the WebGPU device.