forked from fingerecho/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloop-max.js
More file actions
51 lines (48 loc) · 1.45 KB
/
loop-max.js
File metadata and controls
51 lines (48 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
QUnit.test('WebGL Loop Max', function(assert) {
var gpu = new GPU({mode: 'webgl'});
var add = gpu.createKernel(function(a, b) {
var sum = 0;
for (var i = 0; i < a; i++) {
sum += b[this.thread.x][i];
}
}).setOutput([1]);
add.build(1, [1]);
assert.equal(
add.functionBuilder.getPrototypeString('kernel'),
'void kernel() {\n' +
'float user_sum=0.0;\n' +
'for (float user_i=0.0;user_i<LOOP_MAX;user_i++){\n' +
'if (user_i<user_a) {\n' +
'user_sum+=get(user_b, ivec2(user_bSize[0],user_bSize[1]), ivec3(user_bDim[0],user_bDim[1],user_bDim[2]), user_bBitRatio, threadId.x,int(user_i));\n' +
'} else {\n' +
'break;\n' +
'}\n' +
'}\n' +
'\n' +
'}');
gpu.destroy();
});
QUnit.test('WebGL2 Loop Max', function(assert) {
var gpu = new GPU({mode: 'webgl2'});
var add = gpu.createKernel(function(a, b) {
var sum = 0;
for (var i = 0; i < a; i++) {
sum += b[this.thread.x][i];
}
}).setOutput([1]);
add.build(1, [1]);
assert.equal(
add.functionBuilder.getPrototypeString('kernel'),
'void kernel() {\n' +
'float user_sum=0.0;\n' +
'for (float user_i=0.0;user_i<LOOP_MAX;user_i++){\n' +
'if (user_i<user_a) {\n' +
'user_sum+=get(user_b, ivec2(user_bSize[0],user_bSize[1]), ivec3(user_bDim[0],user_bDim[1],user_bDim[2]), user_bBitRatio, threadId.x,int(user_i));\n' +
'} else {\n' +
'break;\n' +
'}\n' +
'}\n' +
'\n' +
'}');
gpu.destroy();
});