wgblas
    Preparing search index...

    Function dcopy

    • Performs the operation $$y \leftarrow x$$ — double-double (Dekker) f64 emulation of scopy, since WGSL has no native f64 type.

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

      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]);

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

      Browser (standalone HTML):

      <!doctype html>
      <html lang="en">
      <head>
      <meta charset="UTF-8" />
      <title>dcopy — 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, dcopy, 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]);

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

      const { y: resultY } = await dcopy(device, n, x, 1, y, 1);

      document.getElementById("out").textContent =
      "x before: " + xBefore +
      "\ny before: " + yBefore +
      "\ny after: " + Array.from(resultY).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 vector

      • incx: number

        stride for x (must be a positive integer)

      • y: Float64Array

        Float64Array output vector

      • incy: number

        stride for y (must be a positive integer)

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

    • Performs the operation $$y \leftarrow x$$ — GPU-resident overload; see the Float64Array overload above for the routine itself.

      import { init, cleanup } from "wgblas";
      import { dcopy } from "wgblas/dcopy";
      import { dscal } from "wgblas/dscal";
      import { GpuVector } from "wgblas/classes/GpuVector";

      const device = await init();

      const n = 5;
      const scale = 2.0;
      const x = new Float64Array([1, 2, 3, 4, 5]);
      const y = new Float64Array(n);

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

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

      // copy x into y, then scale y — all on GPU with single readback
      await dcopy(device, n, xGpu, 1, yGpu, 1);
      await dscal(device, n, scale, yGpu, 1);

      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)

      • x: GpuVector

        GpuVector input vector (must be Float64Array-backed)

      • incx: number

        stride for x (must be a positive integer)

      • y: GpuVector

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

      • incy: number

        stride for y (must be a positive integer)

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