GPUDevice from init()
number of elements (must be a positive integer)
Float32Array input vector
stride for x (must be a positive integer)
absolute sum scalar — always a CPU readback, even for GpuVector inputs
Computes the sum of absolute values of a vector: result = sum(|x[i]|)
import { init, cleanup } from "wgblas";
import { sasum } from "wgblas/sasum";
import { sscal } from "wgblas/sscal";
import { GpuVector } from "wgblas/classes/GpuVector";
import { randomFloat32Array } from "wgblas/random";
const device = await init();
const n = 10;
const scale = 2.0;
const x = randomFloat32Array(n, -10, 10);
const xGpu = GpuVector.from(x);
console.log("x: ", x);
await sscal(device, n, scale, xGpu, 1);
const { asum } = await sasum(device, n, xGpu, 1);
console.log("asum (of 2x): ", asum);
xGpu.destroy();
if (typeof process !== "undefined") cleanup();
GPUDevice from init()
number of elements (must be a positive integer)
GpuVector input vector
stride for x (must be a positive integer)
absolute sum scalar — always a CPU readback, even for GpuVector inputs
Computes the sum of absolute values of a vector: result = sum(|x[i]|)