wgblas
    Preparing search index...

    Function sgemv

    • Performs the matrix-vector operation y = alpha * op(A) * x + beta * y

      • 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 floats between the start of consecutive rows — must be >= n).

      import { init, cleanup } from "wgblas";
      import { sgemv } from "wgblas/sgemv";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      // 4×4 row-major matrix A, vector x of length 4, output y of length 4
      const m = 4, n = 4, lda = n;
      const alpha = 1.0, beta = 0.0;
      const A = randomFloat32Array(m * lda, -10, 10);
      const x = randomFloat32Array(n, -10, 10);
      const y = randomFloat32Array(m, -10, 10);

      console.log("A:", A);
      console.log("x:", x);
      const { y: result } = await sgemv(device, "no-transpose", m, n, alpha, A, lda, x, 1, beta, y, 1);
      console.log("y:", result);
      if (typeof process !== "undefined") cleanup();

      Browser (standalone HTML):

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

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

      const m = 4, n = 4, lda = n;
      const alpha = 1.0, beta = 0.0;
      const A = randomFloat32Array(m * lda, -10, 10);
      const x = randomFloat32Array(n, -10, 10);
      const y = randomFloat32Array(m, -10, 10);

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

      document.getElementById("out").textContent =
      "A: " + Array.from(A).map(v => v.toFixed(4)).join(", ") +
      "\nx: " + Array.from(x).map(v => v.toFixed(4)).join(", ") +
      "\ny: " + Array.from(result).map(v => v.toFixed(4)).join(", ");

      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: Float32Array<ArrayBufferLike> | GpuMatrix

        Float32Array or GpuMatrix, row-major, at least (m-1)*lda+n elements

      • lda: number

        leading dimension of A (>= n)

      • x: Float32Array

        Float32Array input vector

      • incx: number

        stride for x (must be a positive integer)

      • beta: number

        scalar multiplier for y

      • y: Float32Array

        Float32Array input/output vector

      • incy: number

        stride for y (must be a positive integer)

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

    • Performs the matrix-vector operation y = alpha * op(A) * x + beta * y

      A is kept GPU-resident; x and y are CPU Float32Arrays.

      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, row-major, GPU-resident

      • lda: number

        leading dimension of A (must equal A.lda)

      • x: Float32Array

        Float32Array input vector

      • incx: number

        stride for x (must be a positive integer)

      • beta: number

        scalar multiplier for y

      • y: Float32Array

        Float32Array input/output vector

      • incy: number

        stride for y (must be a positive integer)

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

    • Performs the matrix-vector operation y = alpha * op(A) * x + beta * y

      x and y are kept resident on the GPU. A must be a GpuMatrix.

      import { init, cleanup } from "wgblas";
      import { sgemv } from "wgblas/sgemv";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { GpuMatrix } from "wgblas/classes/GpuMatrix";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      // 4×4 row-major matrix A, GPU-resident x and y
      const m = 4, n = 4;
      const alpha = 1.0, beta = 0.0;
      const A = randomFloat32Array(m * n, -10, 10);
      const x = randomFloat32Array(n, -10, 10);
      const y = randomFloat32Array(m, -10, 10);

      const AGpu = GpuMatrix.from(A, m, n);
      const xGpu = GpuVector.from(x);
      const yGpu = GpuVector.from(y);

      console.log("A:", A);
      console.log("x:", x);

      // result stays GPU-resident
      await sgemv(device, "no-transpose", m, n, alpha, AGpu, AGpu.lda, xGpu, 1, beta, yGpu, 1);

      // single readback
      const result = await yGpu.read();
      console.log("y:", result);

      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, row-major

      • lda: number

        leading dimension of A (>= n)

      • x: GpuVector

        GpuVector input vector (not mutated)

      • incx: number

        stride for x (must be a positive integer)

      • beta: number

        scalar multiplier for y

      • y: GpuVector

        GpuVector input/output vector (mutated in place)

      • incy: number

        stride for y (must be a positive integer)

      Returns Promise<{ gpuTimeMs?: number }>