wgblas
    Preparing search index...

    Function saxpy

    • Performs the operation y = alpha * x + y

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

      const device = await init();

      const n = 10;
      const alpha = 2;
      const x = randomFloat32Array(n, -10, 10);
      const y = randomFloat32Array(n, -10, 10);

      console.log("x before:", x);
      console.log("y before:", y);
      const { y: resultY } = await saxpy(device, n, alpha, x, 1, y, 1);
      console.log("y after: ", resultY);
      if (typeof process !== "undefined") cleanup();

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements (must be a positive integer)

      • alpha: number

        scalar multiplier

      • x: Float32Array

        Float32Array input vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float32Array

        Float32Array input/output vector

      • incy: number

        stride for y (must be a positive integer)

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

    • Performs the operation y = alpha * x + y

      import { init, cleanup } from "wgblas";
      import { saxpy } from "wgblas/saxpy";
      import { sscal } from "wgblas/sscal";
      import { GpuVector } from "wgblas/classes/GpuVector";
      import { randomFloat32Array } from "wgblas/random";

      const device = await init();

      const n = 10;
      const alpha = 2;
      const scale = 0.5;
      const x = randomFloat32Array(n, -10, 10);
      const y = randomFloat32Array(n, -10, 10);

      const xGpu = GpuVector.from(x);
      const yGpu = GpuVector.from(y);

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

      // results stay in the GPU.
      await saxpy(device, n, alpha, xGpu, 1, yGpu, 1);
      await sscal(device, n, scale, yGpu, 1);

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

      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)

      • alpha: number

        scalar multiplier

      • x: GpuVector

        GpuVector input vector

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector input/output vector (mutated in place)

      • incy: number

        stride for y (must be a positive integer)

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