forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path207-same-function-reuse.js
More file actions
52 lines (42 loc) · 1.52 KB
/
207-same-function-reuse.js
File metadata and controls
52 lines (42 loc) · 1.52 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
const { assert, skip, test, module: describe, only } = require('qunit');
const { GPU } = require('../../src');
describe('issue #207');
function sameFunctionReuse(mode) {
const gpu = new GPU({ mode });
const kernel = gpu.createKernel(function(kernelArg1, kernelArg2) {
function someFun1(someFun1Arg1, someFun1Arg2) {
return customAdder(someFun1Arg1, someFun1Arg2);
}
function someFun2(someFun2Arg1, someFun2Arg2) {
return customAdder(someFun2Arg1, someFun2Arg2);
}
function customAdder(customAdderArg1, customAdderArg2) {
return customAdderArg1 + customAdderArg2;
}
return someFun1(1, 2) + someFun2(kernelArg1[this.thread.x], kernelArg2[this.thread.x]);
})
.setOutput([6]);
const a = [1, 2, 3, 5, 6, 7];
const b = [4, 5, 6, 1, 2, 3];
const result = kernel(a,b);
assert.deepEqual(Array.from(result), [8, 10, 12, 9, 11, 13]);
gpu.destroy();
}
test('Issue #207 - same function reuse auto', () => {
sameFunctionReuse(null);
});
test('Issue #207 - same function reuse gpu', () => {
sameFunctionReuse('gpu');
});
(GPU.isWebGLSupported ? test : skip)('Issue #207 - same function reuse webgl', () => {
sameFunctionReuse('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('Issue #207 - same function reuse webgl2', () => {
sameFunctionReuse('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('Issue #207 - same function reuse headlessgl', () => {
sameFunctionReuse('headlessgl');
});
test('Issue #207 - same function reuse cpu', () => {
sameFunctionReuse('cpu');
});