forked from gpujs/gpu.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path390-thread-assignment.js
More file actions
163 lines (150 loc) · 5.12 KB
/
390-thread-assignment.js
File metadata and controls
163 lines (150 loc) · 5.12 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const { assert, skip, test, module: describe, only } = require('qunit');
const { WebGLFunctionNode, WebGL2FunctionNode, CPUFunctionNode } = require('../../src');
describe('issue #390');
test('Issue #390 - thread assignment webgl', function(assert) {
const node = new WebGLFunctionNode(function assignThreadToVar() {
const x = this.thread.x;
const y = this.thread.y;
const sum = x + y;
return sum;
}.toString(), { output: [1], returnType: 'Number' });
assert.equal(node.toString(), 'float assignThreadToVar() {'
+ '\nfloat user_x=float(threadId.x);'
+ '\nfloat user_y=float(threadId.y);'
+ '\nfloat user_sum=(user_x+user_y);'
+ '\nreturn user_sum;'
+ '\n}');
const { x, y, sum } = node.contexts[1];
assert.equal(x.name, 'x');
assert.equal(x.valueType, 'Number');
assert.equal(y.name, 'y');
assert.equal(y.valueType, 'Number');
assert.equal(sum.name, 'sum');
assert.equal(sum.valueType, 'Number');
});
test('Issue #390 - thread assignment webgl2', function(assert) {
const node = new WebGL2FunctionNode(function assignThreadToVar() {
const x = this.thread.x;
const y = this.thread.y;
const sum = x + y;
return sum;
}.toString(), { output: [1], returnType: 'Number' });
assert.equal(node.toString(), 'float assignThreadToVar() {'
+ '\nfloat user_x=float(threadId.x);'
+ '\nfloat user_y=float(threadId.y);'
+ '\nfloat user_sum=(user_x+user_y);'
+ '\nreturn user_sum;'
+ '\n}');
const { x, y, sum } = node.contexts[1];
assert.equal(x.name, 'x');
assert.equal(x.valueType, 'Number');
assert.equal(y.name, 'y');
assert.equal(y.valueType, 'Number');
assert.equal(sum.name, 'sum');
assert.equal(sum.valueType, 'Number');
});
test('Issue #390 - thread assignment cpu', function(assert) {
const node = new CPUFunctionNode(function assignThreadToVar() {
const x = this.thread.x;
const y = this.thread.y;
const sum = x + y;
return sum;
}.toString(), { output: [1] });
assert.equal(node.toString(), 'function assignThreadToVar() {'
+ '\nconst user_x=_this.thread.x;'
+ '\nconst user_y=_this.thread.y;'
+ '\nconst user_sum=(user_x+user_y);'
+ '\nreturn user_sum;'
+ '\n}');
const { x, y, z, sum } = node.contexts[1];
assert.equal(x.name, 'x');
assert.equal(x.valueType, 'Integer');
assert.equal(y.name, 'y');
assert.equal(y.valueType, 'Integer');
assert.equal(sum.name, 'sum');
assert.equal(sum.valueType, 'Number');
});
test('Issue #390 (related) - output assignment webgl', function(assert) {
const node = new WebGLFunctionNode(function assignThreadToVar() {
const x = this.output.x;
const y = this.output.y;
const z = this.output.z;
const sum = x + y + z;
return sum;
}.toString(), {
output: [1,2,3]
});
assert.equal(node.toString(), 'float assignThreadToVar() {'
+ '\nfloat user_x=1.0;'
+ '\nfloat user_y=2.0;'
+ '\nfloat user_z=3.0;'
+ '\nfloat user_sum=((user_x+user_y)+user_z);'
+ '\nreturn user_sum;'
+ '\n}');
const { x, y, z, sum } = node.contexts[1];
assert.equal(x.name, 'x');
assert.equal(x.valueType, 'Number');
assert.equal(y.name, 'y');
assert.equal(y.valueType, 'Number');
assert.equal(z.name, 'z');
assert.equal(z.valueType, 'Number');
assert.equal(sum.name, 'sum');
assert.equal(sum.valueType, 'Number');
});
test('Issue #390 (related) - output assignment webgl2', function(assert) {
const node = new WebGL2FunctionNode(function assignThreadToVar() {
const x = this.output.x;
const y = this.output.y;
const z = this.output.z;
const sum = x + y + z;
return sum;
}.toString(), {
output: [1,2,3]
});
assert.equal(node.toString(), 'float assignThreadToVar() {'
+ '\nfloat user_x=1.0;'
+ '\nfloat user_y=2.0;'
+ '\nfloat user_z=3.0;'
+ '\nfloat user_sum=((user_x+user_y)+user_z);'
+ '\nreturn user_sum;'
+ '\n}');
const context = node.contexts[1];
const { x, y, z, sum } = context;
assert.equal(x.name, 'x');
assert.equal(x.valueType, 'Number');
assert.equal(y.name, 'y');
assert.equal(y.valueType, 'Number');
assert.equal(z.name, 'z');
assert.equal(z.valueType, 'Number');
assert.equal(sum.name, 'sum');
assert.equal(sum.valueType, 'Number');
});
test('Issue #390 (related) - output assignment cpu', function(assert) {
const node = new CPUFunctionNode(`function assignThreadToVar() {
const x = this.output.x;
const y = this.output.y;
const z = this.output.z;
const sum = x + y + z;
return sum;
}`, {
output: [1,2,3]
});
assert.equal(node.toString(), 'function assignThreadToVar() {'
+ '\nconst user_x=outputX;'
+ '\nconst user_y=outputY;'
+ '\nconst user_z=outputZ;'
+ '\nconst user_sum=((user_x+user_y)+user_z);'
+ '\nreturn user_sum;'
+ '\n}');
const context = node.contexts[1];
const { x, y, z, sum } = context;
assert.equal(context['@contextType'], 'const/let');
assert.equal(x.name, 'x');
assert.equal(x.valueType, 'Number');
assert.equal(y.name, 'y');
assert.equal(y.valueType, 'Number');
assert.equal(z.name, 'z');
assert.equal(z.valueType, 'Number');
assert.equal(sum.name, 'sum');
assert.equal(sum.valueType, 'Number');
});