forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtactic.js
More file actions
112 lines (90 loc) · 2.34 KB
/
tactic.js
File metadata and controls
112 lines (90 loc) · 2.34 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const { assert, skip, test, module: describe } = require('qunit');
const { GPU } = require('../../src');
describe('internal: tactic');
function speedTest(mode) {
const gpu = new GPU({ mode });
const add = gpu.createKernel(function(a, b) {
return a + b;
})
.setOutput([1])
.setTactic('speed');
let addResult = add(0.1, 0.2)[0];
assert.equal(addResult.toFixed(7), (0.1 + 0.2).toFixed(7));
gpu.destroy();
}
test('speed auto', () => {
speedTest();
});
test('speed gpu', () => {
speedTest('gpu');
});
(GPU.isWebGLSupported ? test : skip)('speed webgl', () => {
speedTest('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('speed webgl2', () => {
speedTest('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('speed headlessgl', () => {
speedTest('headlessgl');
});
test('speed cpu', () => {
speedTest('cpu');
});
function balancedTest(mode) {
const gpu = new GPU({ mode });
const add = gpu.createKernel(function(a, b) {
return a + b;
})
.setOutput([1])
.setTactic('balanced');
let addResult = add(0.1, 0.2)[0];
assert.equal(addResult.toFixed(7), (0.1 + 0.2).toFixed(7));
gpu.destroy();
}
test('balanced auto', () => {
balancedTest();
});
test('balanced gpu', () => {
balancedTest('gpu');
});
(GPU.isWebGLSupported ? test : skip)('balanced webgl', () => {
balancedTest('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('balanced webgl2', () => {
balancedTest('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('balanced headlessgl', () => {
balancedTest('headlessgl');
});
test('balanced cpu', () => {
balancedTest('cpu');
});
function precisionTest(mode) {
const gpu = new GPU({ mode });
const add = gpu.createKernel(function(a, b) {
return a + b;
})
.setOutput([1])
.setTactic('precision');
let addResult = add(0.1, 0.2)[0];
assert.equal(addResult.toFixed(7), (0.1 + 0.2).toFixed(7));
gpu.destroy();
}
test('precision auto', () => {
precisionTest();
});
test('precision gpu', () => {
precisionTest('gpu');
});
(GPU.isWebGLSupported ? test : skip)('precision webgl', () => {
precisionTest('webgl');
});
(GPU.isWebGL2Supported ? test : skip)('precision webgl2', () => {
precisionTest('webgl2');
});
(GPU.isHeadlessGLSupported ? test : skip)('precision headlessgl', () => {
precisionTest('headlessgl');
});
test('precision cpu', () => {
precisionTest('cpu');
});