GPUDevice from init()
number of elements to swap (must be a positive integer)
Float64Array first input/output vector
stride for x (must be a positive integer)
Float64Array second input/output vector
stride for y (must be a positive integer)
Swaps the elements of two double-precision vectors: $$x \leftrightarrow y$$ — GPU-resident overload; see the Float64Array overload above for the routine itself.
import { init, cleanup } from "wgblas";
import { dswap } from "wgblas/dswap";
import { dscal } from "wgblas/dscal";
import { GpuVector } from "wgblas/classes/GpuVector";
const device = await init();
const n = 5;
const alpha = 2.0;
const x = new Float64Array([1, 2, 3, 4, 5]);
const y = new Float64Array([10, 20, 30, 40, 50]);
const xGpu = GpuVector.from(x);
const yGpu = GpuVector.from(y);
console.log("x: ", x);
console.log("y: ", y);
await dswap(device, n, xGpu, 1, yGpu, 1);
await dscal(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();
GPUDevice from init()
number of elements to swap (must be a positive integer)
GpuVector first input/output vector (must be Float64Array-backed, mutated in place)
stride for x (must be a positive integer)
GpuVector second input/output vector (must be Float64Array-backed, mutated in place)
stride for y (must be a positive integer)
Swaps the elements of two double-precision vectors: $$x \leftrightarrow y$$ — double-double (Dekker) f64 emulation of sswap, since WGSL has no native f64 type.
Browser (standalone HTML):