(mode)
| 4 | describe('features: inject native'); |
| 5 | |
| 6 | function gpuAddAB(mode) { |
| 7 | const gpu = new GPU({mode}); |
| 8 | gpu |
| 9 | .injectNative(` |
| 10 | int customAdder(int a, int b) { |
| 11 | return a + b; |
| 12 | } |
| 13 | `) |
| 14 | .addNativeFunction('customAdderLink', `int customAdderLink(int a, int b) { |
| 15 | return customAdder(a, b); |
| 16 | }`); |
| 17 | const kernel = gpu.createKernel(function (a, b) { |
| 18 | return customAdderLink(a[this.thread.x], b[this.thread.x]); |
| 19 | }, { |
| 20 | output: [6], |
| 21 | returnType: 'Integer' |
| 22 | }); |
| 23 | |
| 24 | const a = [1, 2, 3, 5, 6, 7]; |
| 25 | const b = [4, 5, 6, 1, 2, 3]; |
| 26 | |
| 27 | const result = kernel(a, b); |
| 28 | |
| 29 | const expected = [5, 7, 9, 6, 8, 10]; |
| 30 | |
| 31 | assert.deepEqual(Array.from(result), expected); |
| 32 | gpu.destroy(); |
| 33 | } |
| 34 | |
| 35 | test('addAB auto', () => { |
| 36 | gpuAddAB(null); |
no test coverage detected
searching dependent graphs…