wgblas
    Preparing search index...

    Function sswap

    • Swaps the elements of two single-precision vectors: x <-> y

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

      const device = await init();

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

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements to swap (must be a positive integer)

      • x: Float32Array

        Float32Array first input/output vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float32Array

        Float32Array second input/output vector

      • incy: number

        stride for y (must be a positive integer)

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

    • Swaps the elements of two single-precision vectors: x <-> y

      import { init, cleanup } from "wgblas";
      import { sswap } from "wgblas/sswap";
      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.0;
      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);

      await sswap(device, n, xGpu, 1, yGpu, 1);
      await sscal(device, n, alpha, xGpu, 1);

      // single readback
      const resultX = await xGpu.read();
      const resultY = await yGpu.read();
      console.log("x (2 * orig y): ", resultX);
      console.log("y (orig x): ", resultY);

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

      Parameters

      • device: GPUDevice

        GPUDevice from init()

      • n: number

        number of elements to swap (must be a positive integer)

      • x: GpuVector

        GpuVector first input/output vector (mutated in place)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

        GpuVector second input/output vector (mutated in place)

      • incy: number

        stride for y (must be a positive integer)

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