Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
170 lines (158 loc) · 4.42 KB

File metadata and controls

170 lines (158 loc) · 4.42 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
163
164
165
166
167
168
169
170
const { assert, skip, test, module: describe, only } = require('qunit');
const { GPU, input } = require('../../src');
describe('features: dev mode');
test('are added to GPU instance .kernels property', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value;
}, { output: [1] });
assert.equal(gpu.kernels.length, 1);
assert.deepEqual(kernel(1), new Float32Array([1]));
gpu.destroy();
});
test('works with integer', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value;
}, { output: [1] });
assert.deepEqual(kernel(1), new Float32Array([1]));
gpu.destroy();
});
test('works with float', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value;
}, { output: [1] });
assert.deepEqual(kernel(1.5), new Float32Array([1.5]));
gpu.destroy();
});
test('works with array', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.x];
}, { output: [4] });
assert.deepEqual(kernel([1,2,3,4]), new Float32Array([1,2,3,4]));
gpu.destroy();
});
test('works with matrix', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.y][this.thread.x];
}, { output: [4, 2] });
assert.deepEqual(kernel(
[
[1,2,3,4],
[5,6,7,8]
]
), [
new Float32Array([1,2,3,4]),
new Float32Array([5,6,7,8]),
]);
gpu.destroy();
});
test('works with cube', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.z][this.thread.y][this.thread.x];
}, { output: [4, 2, 2] });
assert.deepEqual(kernel(
[
[
[1,2,3,4],
[5,6,7,8]
],
[
[9,10,11,12],
[13,14,15,16]
]
]
), [
[
new Float32Array([1,2,3,4]),
new Float32Array([5,6,7,8]),
],[
new Float32Array([9,10,11,12]),
new Float32Array([13,14,15,16]),
]
]);
gpu.destroy();
});
test('works with input array', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.x];
}, { output: [4] });
assert.deepEqual(kernel(input([1,2,3,4], [4])), new Float32Array([1,2,3,4]));
gpu.destroy();
});
test('works with input matrix', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.y][this.thread.x];
}, { output: [4, 2] });
assert.deepEqual(kernel(input([1,2,3,4,5,6,7,8], [4, 2])), [
new Float32Array([1,2,3,4]),
new Float32Array([5,6,7,8]),
]);
gpu.destroy();
});
test('works with input cube', () => {
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.z][this.thread.y][this.thread.x];
}, { output: [4, 2, 2] });
assert.deepEqual(kernel(
input([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16], [4,2,2])
), [
[
new Float32Array([1,2,3,4]),
new Float32Array([5,6,7,8]),
],[
new Float32Array([9,10,11,12]),
new Float32Array([13,14,15,16]),
]
]);
gpu.destroy();
});
test('works with texture', () => {
const texture = ((new GPU()).createKernel(function (cube) {
return cube[this.thread.z][this.thread.y][this.thread.x];
}, { output: [4,2,2], pipeline: true }))([
[
new Float32Array([1,2,3,4]),
new Float32Array([5,6,7,8]),
],[
new Float32Array([9,10,11,12]),
new Float32Array([13,14,15,16]),
]
]);
assert.ok(texture.constructor.name.match('Texture'));
const gpu = new GPU({ mode: 'dev' });
const kernel = gpu.createKernel(function(value) {
return value[this.thread.z][this.thread.y][this.thread.x];
}, { output: [4, 2, 2] });
assert.deepEqual(kernel(
texture
), [
[
new Float32Array([1,2,3,4]),
new Float32Array([5,6,7,8]),
],[
new Float32Array([9,10,11,12]),
new Float32Array([13,14,15,16]),
]
]);
gpu.destroy();
});
test('works with adding functions', () => {
const gpu = new GPU({ mode: 'dev' });
function addOne(value) {
return value + 1;
}
gpu.addFunction(addOne);
const kernel = gpu.createKernel(function(value) {
return addOne(value);
}, { output: [1] });
assert.deepEqual(kernel(1), new Float32Array([2]));
gpu.destroy();
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.