forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path91-create-kernel-map-array.js
More file actions
60 lines (55 loc) · 1.94 KB
/
91-create-kernel-map-array.js
File metadata and controls
60 lines (55 loc) · 1.94 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
60
const { assert, skip, test, module: describe } = require('qunit');
const { GPU, HeadlessGLKernel, WebGLKernel, WebGL2Kernel, CPUKernel } = require('../../src');
describe('issue #91');
function getResult(mode) {
const A = [
[1, 2],
[3, 4],
[5, 6]
];
const B = [
[6, 5, 4],
[3, 2, 1]
];
const gpu = new GPU({ mode });
function multiply(b, a, y, x) {
let sum = 0;
for (let i = 0; i < 2; i++) {
sum += b[y][i] * a[i][x];
}
return sum;
}
const kernels = gpu.createKernelMap({
multiplyResult: multiply
}, function (a, b) {
return multiply(b, a, this.thread.y, this.thread.x);
})
.setOutput([2, 2]);
const result = kernels(A, B).result;
assert.deepEqual(Array.from(result[0]), [21,32]);
assert.deepEqual(Array.from(result[1]), [9,14]);
gpu.destroy();
return kernels;
}
(GPU.isWebGL2Supported || (GPU.isHeadlessGLSupported && HeadlessGLKernel.features.kernelMap) ? test : skip)("Issue #91 - type detection auto", () => {
getResult();
});
(GPU.isWebGL2Supported || (GPU.isHeadlessGLSupported && HeadlessGLKernel.features.kernelMap) ? test : skip)("Issue #91 - type detection gpu", () => {
getResult('gpu');
});
(GPU.isWebGLSupported ? test : skip)("Issue #91 - type detection webgl", () => {
const kernel = getResult('webgl');
assert.equal(kernel.kernel.constructor, WebGLKernel, 'kernel type is wrong');
});
(GPU.isWebGL2Supported ? test : skip)("Issue #91 - type detection webgl2", () => {
const kernel = getResult('webgl2');
assert.equal(kernel.kernel.constructor, WebGL2Kernel, 'kernel type is wrong');
});
(GPU.isHeadlessGLSupported ? test : skip)("Issue #91 - type detection headlessgl", () => {
const kernel = getResult('headlessgl');
assert.equal(kernel.kernel.constructor, HeadlessGLKernel, 'kernel type is wrong');
});
test("Issue #91 - type detection cpu", () => {
const kernel = getResult('cpu');
assert.equal(kernel.kernel.constructor, CPUKernel, 'kernel type is wrong');
});