wgblas
    Preparing search index...

    Function init

    • Initializes the WebGPU device.

      Parameters

      • Optionaloptions: { benchmark?: boolean; powerPreference?: GPUPowerPreference }
        • Optionalbenchmark?: boolean

          enable GPU timestamp queries; BLAS functions return { result, gpuTimeMs } (default: false)

        • OptionalpowerPreference?: GPUPowerPreference

          GPU 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().

      Returns Promise<GPUDevice>

      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`);