(mode)
| 63 | describe('features: instantiate native and override'); |
| 64 | |
| 65 | function divideOverride(mode) { |
| 66 | const gpu = new GPU({ |
| 67 | mode, |
| 68 | functions: [divide], |
| 69 | nativeFunctions: [{ |
| 70 | name: 'divide', |
| 71 | // deliberately add, rather than divide, to ensure native functions are treated as more important than regular ones |
| 72 | source: `float divide(float a, float b) { |
| 73 | return a + b; |
| 74 | }` |
| 75 | }] |
| 76 | }); |
| 77 | |
| 78 | function divide(a,b) { |
| 79 | return a / b; |
| 80 | } |
| 81 | |
| 82 | const kernel = gpu.createKernel(function(a, b) { |
| 83 | return divide(a[this.thread.x], b[this.thread.x]); |
| 84 | }, { |
| 85 | output : [6] |
| 86 | }); |
| 87 | |
| 88 | const a = [1, 4, 3, 5, 6, 3]; |
| 89 | const b = [4, 2, 6, 1, 2, 3]; |
| 90 | |
| 91 | const res = kernel(a,b); |
| 92 | const exp = [5, 6, 9, 6, 8, 6]; |
| 93 | |
| 94 | assert.deepEqual(Array.from(res), exp); |
| 95 | gpu.destroy(); |
| 96 | } |
| 97 | |
| 98 | test('divideOverride (GPU only) auto', () => { |
| 99 | divideOverride(null); |
no test coverage detected
searching dependent graphs…