(mode)
| 118 | describe('features: argument casting'); |
| 119 | |
| 120 | function argumentCasting(mode) { |
| 121 | const gpu = new GPU({ |
| 122 | mode, |
| 123 | functions: [divide], |
| 124 | nativeFunctions: [{ |
| 125 | // deliberately add, rather than divide, to ensure native functions are treated as more important than regular ones |
| 126 | name: 'divide', |
| 127 | source: `float divide(int a, int b) { |
| 128 | return float(a + b); |
| 129 | }` |
| 130 | }] |
| 131 | }); |
| 132 | |
| 133 | function divide(a,b) { |
| 134 | return a / b; |
| 135 | } |
| 136 | |
| 137 | const kernel = gpu.createKernel(function(a, b) { |
| 138 | return divide(a[this.thread.x], b[this.thread.x]); |
| 139 | }, { |
| 140 | output : [6] |
| 141 | }); |
| 142 | |
| 143 | const a = [1, 4, 3, 5, 6, 3]; |
| 144 | const b = [4, 2, 6, 1, 2, 3]; |
| 145 | |
| 146 | const res = kernel(a,b); |
| 147 | const exp = [5, 6, 9, 6, 8, 6]; |
| 148 | |
| 149 | assert.deepEqual(Array.from(res), exp); |
| 150 | gpu.destroy(); |
| 151 | } |
| 152 | |
| 153 | test('argumentCasting (GPU only) auto', () => { |
| 154 | argumentCasting(null); |
no test coverage detected
searching dependent graphs…