forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic_for_loop.js
More file actions
38 lines (30 loc) · 854 Bytes
/
basic_for_loop.js
File metadata and controls
38 lines (30 loc) · 854 Bytes
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
function basic_for_loop_test( assert, mode ) {
var gpu = new GPU();
var f = gpu.createKernel(function(a, b) {
var x = 0.0;
for(var i = 0.0; i<10.0; i++) {
x = x + 1.0;
}
return (a[this.thread.x] + b[this.thread.x] + x);
}, {
dimensions : [6],
mode : mode
});
assert.ok( f !== null, "function generated test");
var a = [1, 2, 3, 5, 6, 7];
var b = [4, 5, 6, 1, 2, 3];
var res = f(a,b);
var exp = [15, 17, 19, 16, 18, 20];
for(var i = 0; i < exp.length; ++i) {
QUnit.close(exp[i], res[i], 0.1, "Result arr idx: "+i);
}
}
QUnit.test( "basic_for_loop (auto)", function( assert ) {
basic_for_loop_test(assert, null);
});
QUnit.test( "basic_for_loop (GPU)", function( assert ) {
basic_for_loop_test(assert, "gpu");
});
QUnit.test( "basic_for_loop (CPU)", function( assert ) {
basic_for_loop_test(assert, "cpu");
});