forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path96-param-names.js
More file actions
59 lines (52 loc) · 1.45 KB
/
96-param-names.js
File metadata and controls
59 lines (52 loc) · 1.45 KB
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
const { assert, skip, test, module: describe, only } = require('qunit');
const { GPU } = require('../../src');
describe('issue #96');
function getResult(mode) {
const A = [
[1, 1, 1],
[1, 1, 1]
];
const B = [
[1, 1],
[1, 1],
[1, 1]
];
const gpu = new GPU({ mode });
function multiply(m, n, y, x) {
let sum = 0;
for (let i = 0; i < 2; i++) {
sum += m[y][i] * n[i][x];
}
return sum;
}
const kernels = gpu.createKernelMap({
multiplyResult: multiply
}, function (a, b) {
return multiply(b, a, this.thread.y, this.thread.x);
})
.setOutput([B.length, A.length]);
const result = kernels(A, B).result;
assert.deepEqual(Array.from(result[0]), [2,2,2]);
assert.deepEqual(Array.from(result[1]), [2,2,2]);
assert.deepEqual(result.length, 2);
gpu.destroy();
return result;
}
(GPU.isKernelMapSupported ? test : skip)("Issue #96 - param names auto", () => {
getResult();
});
(GPU.isKernelMapSupported ? test : skip)("Issue #96 - param names gpu", () => {
getResult('gpu');
});
(GPU.isWebGLSupported ? test : skip)("Issue #96 - param names webgl", () => {
getResult('webgl');
});
(GPU.isWebGL2Supported ? test : skip)("Issue #96 - param names webgl2", () => {
getResult('webgl2');
});
(GPU.isHeadlessGLSupported && GPU.isKernelMapSupported ? test : skip)("Issue #96 - param names headlessgl", () => {
getResult('headlessgl');
});
test("Issue #96 - param names cpu", () => {
getResult('cpu');
});