wgblas
    Preparing search index...

    Function drotm

    • Applies a modified Givens plane rotation H to double-precision vectors x and y: $$\begin{pmatrix} x \\ y \end{pmatrix} \leftarrow \begin{pmatrix} h_{11} & h_{12} \\ h_{21} & h_{22} \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}$$ — double-double (Dekker) f64 emulation of srotm, since WGSL has no native f64 type.

      import { init, cleanup } from "wgblas";
      import { drotm } from "wgblas/drotm";

      const device = await init();

      const n = 5;
      const x = new Float64Array([1, 2, 3, 4, 5]);
      const y = new Float64Array([10, 20, 30, 40, 50]);

      // flag = -1: full 2x2 matrix H
      // H = [ h11 h12 ] = [ 2 1 ]
      // [ h21 h22 ] [ 1 -1 ]
      const param = new Float64Array([-1, 2, 1, 1, -1]);

      console.log("x (before):", x);
      console.log("y (before):", y);

      const { x: xOut, y: yOut } = await drotm(device, n, x, 1, y, 1, param);

      console.log("x (after): ", xOut);
      console.log("y (after): ", yOut);

      if (typeof process !== "undefined") cleanup();

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>drotm — wgblas browser example</title>
      <script src="https://unpkg.com/wgblas/dist/wgblas.browser.js"></script>
      </head>
      <body>
      <pre id="out">Running…</pre>
      <script>
      const { init, drotm, cleanup } = window.wgblas;

      (async () => {
      const device = await init();

      const n = 5;
      const x = new Float64Array([1, 2, 3, 4, 5]);
      const y = new Float64Array([10, 20, 30, 40, 50]);

      // flag = -1: full 2x2 matrix H
      // H = [ h11 h12 ] = [ 2 1 ]
      // [ h21 h22 ] [ 1 -1 ]
      const param = new Float64Array([-1, 2, 1, 1, -1]);

      const xBefore = Array.from(x).map(v => v.toFixed(4)).join(", ");
      const yBefore = Array.from(y).map(v => v.toFixed(4)).join(", ");

      const { x: xOut, y: yOut } = await drotm(device, n, x, 1, y, 1, param);

      document.getElementById("out").textContent =
      "x (before): " + xBefore +
      "\ny (before): " + yBefore +
      "\nx (after): " + Array.from(xOut).map(v => v.toFixed(4)).join(", ") +
      "\ny (after): " + Array.from(yOut).map(v => v.toFixed(4)).join(", ");

      cleanup();
      })();
      </script>
      </body>
      </html>

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • x: Float64Array

        Float64Array input/output vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float64Array

        Float64Array input/output vector

      • incy: number

        stride for y (must be a positive integer)

      • param: Float64Array

        5-element Float64Array: [flag, h11, h21, h12, h22] flag = -2: identity (no-op), -1: full H, 0: unit diagonal, 1: unit off-diagonal

      Returns Promise<
          | { x: Float64Array; y: Float64Array }
          | { gpuTimeMs: number; x: Float64Array; y: Float64Array },
      >

    • Applies a modified Givens plane rotation H to double-precision vectors x and y: $$\begin{pmatrix} x \\ y \end{pmatrix} \leftarrow \begin{pmatrix} h_{11} & h_{12} \\ h_{21} & h_{22} \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix}$$ — GPU-resident overload; see the Float64Array overload above for the routine itself.

      import { init, cleanup } from "wgblas";
      import { drotm } from "wgblas/drotm";
      import { daxpy } from "wgblas/daxpy";
      import { GpuVector } from "wgblas/classes/GpuVector";

      const device = await init();

      const n = 5;
      const xCpu = new Float64Array([1, 2, 3, 4, 5]);
      const yCpu = new Float64Array([10, 20, 30, 40, 50]);

      const xGpu = GpuVector.from(xCpu);
      const yGpu = GpuVector.from(yCpu);

      console.log("x (cpu): ", xCpu);
      console.log("y (cpu): ", yCpu);

      // flag = 0: unit diagonal — H = [ 1 h12 ] = [ 1 1 ]
      // [ h21 1 ] [ 2 1 ]
      const param = new Float64Array([0, 1, 2, 1, 1]);

      // shift y by adding 2*x on GPU, then apply modified rotation
      await daxpy(device, n, 2.0, xGpu, 1, yGpu, 1);
      await drotm(device, n, xGpu, 1, yGpu, 1, param);

      console.log("x (after): ", await xGpu.read());
      console.log("y (after): ", await yGpu.read());

      xGpu.destroy();
      yGpu.destroy();

      if (typeof process !== "undefined") cleanup();

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • x: GpuVector

        GpuVector input/output vector (must be Float64Array-backed, mutated in place)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector input/output vector (must be Float64Array-backed, mutated in place)

      • incy: number

        stride for y (must be a positive integer)

      • param: Float64Array

        5-element Float64Array: [flag, h11, h21, h12, h22] flag = -2: identity (no-op), -1: full H, 0: unit diagonal, 1: unit off-diagonal

      Returns Promise<{} | { gpuTimeMs: number }>