(mode)
| 196 | describe('features: add custom function with `this.constants.width` in loop'); |
| 197 | |
| 198 | function sumAB(mode) { |
| 199 | const gpu = new GPU({mode}); |
| 200 | |
| 201 | function customAdder(a, b) { |
| 202 | let sum = 0; |
| 203 | for (let i = 0; i < this.constants.width; i++) { |
| 204 | sum += a[this.thread.x] + b[this.thread.x]; |
| 205 | } |
| 206 | return sum; |
| 207 | } |
| 208 | |
| 209 | gpu.addFunction(customAdder); |
| 210 | |
| 211 | const kernel = gpu.createKernel(function (a, b) { |
| 212 | return customAdder(a, b); |
| 213 | }, { |
| 214 | output: [6], |
| 215 | constants: {width: 6}, |
| 216 | precision: 'unsigned', |
| 217 | }); |
| 218 | |
| 219 | assert.ok(kernel !== null, 'function generated test'); |
| 220 | |
| 221 | const a = [1, 2, 3, 5, 6, 7]; |
| 222 | const b = [1, 1, 1, 1, 1, 1]; |
| 223 | |
| 224 | const result = kernel(a, b); |
| 225 | const expected = [12, 18, 24, 36, 42, 48]; |
| 226 | |
| 227 | assert.deepEqual(Array.from(result), expected); |
| 228 | gpu.destroy(); |
| 229 | } |
| 230 | |
| 231 | test('sumAB auto', () => { |
| 232 | sumAB(null); |
no test coverage detected
searching dependent graphs…