Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
72 lines (65 loc) · 1.54 KB

File metadata and controls

72 lines (65 loc) · 1.54 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const { GPU } = require('../src/index.js');
const Benchmark = require('benchmark');
const suite = new Benchmark.Suite();
const gpu = new GPU({ mode: 'gpu' });
const cpu = new GPU({ mode: 'cpu' });
const size = 1024;
const a = randomMatrix(size, size);
const b = randomMatrix(size, size);
function randomMatrix(width, height) {
const matrix = new Array(height);
for (let y = 0; y < height; y++) {
const row = matrix[y] = new Float32Array(width);
for (let x = 0; x < width; x++) {
row[x] = Math.random();
}
}
return matrix;
}
const gpuKernel = gpu
.createKernel(function(a, b) {
let sum = 0;
for (let i = 0; i < this.constants.size; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
})
.setConstants({
size
})
.setPipeline(false)
.setPrecision('unsigned')
.setOutput([size, size]);
const cpuKernel = cpu
.createKernel(function(a, b) {
let sum = 0;
for (let i = 0; i < this.constants.size; i++) {
sum += a[this.thread.y][i] * b[i][this.thread.x];
}
return sum;
})
.setConstants({
size
})
.setOutput([size, size]);
// go ahead and build
gpuKernel(a, b);
cpuKernel(a, b);
// add tests
suite
.add('gpu', () => {
gpuKernel(a, b);
})
.add('cpu', () => {
cpuKernel(a, b);
})
// add listeners
.on('cycle', (event) => {
console.log(String(event.target));
})
.on('complete', function () {
gpu.destroy();
cpu.destroy();
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
.run({ async: false });
Morty Proxy This is a proxified and sanitized view of the page, visit original site.