GPUDevice from init()
number of elements (must be a positive integer)
Float32Array input vector
stride for x (must be a positive integer)
Euclidean norm scalar — always a CPU readback, even for GpuVector inputs
Computes the Euclidean norm of a vector: result = sqrt(sum(x[i] * x[i]))
import { init, cleanup } from "wgblas";
import { snrm2 } from "wgblas/snrm2";
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 { nrm2 } = await snrm2(device, n, xGpu, 1);
console.log("nrm2 (of 2x): ", nrm2);
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)
Euclidean norm scalar — always a CPU readback, even for GpuVector inputs
Computes the Euclidean norm of a vector: result = sqrt(sum(x[i] * x[i]))