Published
Edited
Jun 8, 2020
Insert cell
md`# GPU.js matrix multiply webgl2 issue`
Insert cell
{
let startDate = Date.now();
const out = multiplyMatrix(matrices[0], matrices[1]);
return Date.now() - startDate;
}
Insert cell
gpu = new GPU.GPU({ mode: "webgl2" }) // GTX1070 => webgl: 80ms, webgl2: 9099ms, cpu: 728ms
Insert cell
multiplyMatrix = gpu
.createKernel(function(a, b) {
let sum = 0;
for (let i = 0; i < 512; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
})
.setOutput([512, 512])
Insert cell
matrices = {
const generateMatrices = () => {
const matrices = [[], []];
for (let y = 0; y < 512; y++) {
matrices[0].push([]);
matrices[1].push([]);
for (let x = 0; x < 512; x++) {
matrices[0][y].push(Math.random());
matrices[1][y].push(Math.random());
}
}
return matrices;
};
return generateMatrices();
}
Insert cell
GPU = require("gpu.js@2")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more