wgblas
    Preparing search index...

    Function dgemv

    • Performs the matrix-vector operation $$y \leftarrow \alpha \mathrm{op}(A) x + \beta y$$ in double precision (double-double emulation — WGSL has no native f64 type).

      • trans='no-transpose': op(A) = A, x is length n, y is length m
      • trans='transpose': op(A) = A^T, x is length m, y is length n

      A is an m×n matrix stored in row-major order. lda is the leading dimension (number of doubles between the start of consecutive rows — must be >= n).

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

      const device = await init();

      // y = alpha*A*x + beta*y, with A a 2x3 row-major matrix.
      const m = 2,
      n = 3,
      lda = n;
      const A = new Float64Array([1, 2, 3, 4, 5, 6]);
      const x = new Float64Array([1, 1, 1]);
      const y = new Float64Array([0, 0]);

      console.log("A =");
      console.table([A.slice(0, 3), A.slice(3, 6)]);
      console.log("x =", x);

      const { y: result } = await dgemv(
      device,
      "no-transpose",
      m,
      n,
      1,
      A,
      lda,
      x,
      1,
      0,
      y,
      1,
      );
      console.log("y = A*x =", result); // row sums: [1+2+3, 4+5+6] = [6, 15]

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

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>dgemv — 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, dgemv, cleanup } = window.wgblas;

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

      // y = A*x with A a 2x3 row-major matrix.
      const m = 2, n = 3, lda = n;
      const A = new Float64Array([1, 2, 3,
      4, 5, 6]);
      const x = new Float64Array([1, 1, 1]);
      const y = new Float64Array([0, 0]);

      const { y: result } = await dgemv(device, "no-transpose", m, n, 1, A, lda, x, 1, 0, y, 1);

      document.getElementById("out").textContent = [
      "A =",
      " [" + [...A.subarray(0, 3)].join(", ") + "]",
      " [" + [...A.subarray(3, 6)].join(", ") + "]",
      "x = [" + [...x].join(", ") + "]",
      "y = A*x = [" + [...result].join(", ") + "] // row sums: 1+2+3, 4+5+6",
      ].join("\n");

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • trans: "no-transpose" | "transpose"

        'no-transpose' for A, 'transpose' for A^T

      • m: number

        number of rows in A

      • n: number

        number of columns in A

      • alpha: number

        scalar multiplier for op(A)*x

      • A: Float64Array

        Float64Array, row-major or column-major (see layout), at least (m-1)*lda+n elements for row-major or (n-1)*lda+m elements for column-major

      • lda: number

        leading dimension of A (>= n for row-major, >= m for column-major)

      • x: Float64Array

        Float64Array input vector

      • incx: number

        stride for x (must be a positive integer)

      • beta: number

        scalar multiplier for y

      • y: Float64Array

        Float64Array input/output vector

      • incy: number

        stride for y (must be a positive integer)

      • Optionallayout: "column-major" | "row-major"

        storage layout of A (default: 'row-major'); column-major swaps the effective m/n and flips trans internally (op(A) stays what you asked for either way — x/y keep their original lengths)

      Returns Promise<{ gpuTimeMs?: number; y: Float64Array }>

    • Performs the matrix-vector operation $$y \leftarrow \alpha \mathrm{op}(A) x + \beta y$$ in double precision (double-double emulation).

      x and y are kept resident on the GPU. A must be a GpuMatrix (Float64Array- backed); its own layout (set at GpuMatrix.from time) determines the operation — there is no separate layout argument here.

      import { init, cleanup } from "wgblas";
      import { dgemv } from "wgblas/dgemv";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";

      const device = await init();

      // A diagonal A makes the chained result easy to check by eye.
      const n = 3;
      const A = new Float64Array([1, 0, 0, 0, 2, 0, 0, 0, 3]);
      const x = new Float64Array([1, 1, 1]);

      const AGpu = GpuMatrix.from(A, n, n, n, "row-major");
      const xGpu = GpuVector.from(x);
      const yGpu = GpuVector.from(new Float64Array(n));

      console.log("A = diag(1, 2, 3) =");
      console.table([A.slice(0, 3), A.slice(3, 6)]);
      console.log("x =", x);

      // Results stay on the GPU between the two calls — no readback in between.
      await dgemv(
      device,
      "no-transpose",
      n,
      n,
      1,
      AGpu,
      AGpu.lda,
      xGpu,
      1,
      0,
      yGpu,
      1,
      ); // y = A*x
      await dgemv(
      device,
      "no-transpose",
      n,
      n,
      1,
      AGpu,
      AGpu.lda,
      yGpu,
      1,
      0,
      xGpu,
      1,
      ); // x = A*y

      // Single readback at the end.
      console.log("A*A*x =", await xGpu.read()); // [1*1, 2*2, 3*3] = [1, 4, 9]

      AGpu.destroy();
      xGpu.destroy();
      yGpu.destroy();
      if (typeof process !== "undefined") cleanup();

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • trans: "no-transpose" | "transpose"

        'no-transpose' for A, 'transpose' for A^T

      • m: number

        number of rows in A

      • n: number

        number of columns in A

      • alpha: number

        scalar multiplier for op(A)*x

      • A: GpuMatrix

        GpuMatrix (Float64Array-backed)

      • lda: number

        leading dimension of A (must equal A.lda)

      • x: GpuVector

        GpuVector input vector (Float64Array-backed, not mutated)

      • incx: number

        stride for x (must be a positive integer)

      • beta: number

        scalar multiplier for y

      • y: GpuVector

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

      • incy: number

        stride for y (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number }>