web-tensors
v0.0.5
Published
A tensor library for WebGPU
Downloads
11
Maintainers
Readme
A library for accelerated tensors using WebGPU
Install:
npm i web-tensors
WIP! Currently only supports vectorizing element-wise operations.
Usage:
import {WebTensorsContext} from "web-tensors";
//
const adapter = await navigator.gpu.requestAdapter();
if (!adapter) {
console.log("Failed to get GPU adapter.");
}
const device = await adapter.requestDevice();
// Initialize
const wt = new WebTensorsContext(device);
const {
add, mult, cos, sqrt // dump ops directly into the scope
} = wt.getOps();
// create from data
const a = wt.gpuTensorFromData(
[[1,2,3,4],
[7,8,9,10]]
);
// create empty tensor with dimensions
const b = wt.gpuTensorFromDims([2,4]);
// perform operations
const c = add(a, b);
const d = mult(c, c);
const result = sqrt( mult( add(a, c), cos(d) ) );
console.log(await result.cpu());