(mode)
| 167 | |
| 168 | describe('issue #267 sub kernels mixed'); |
| 169 | function immutableKernelsMixedWithoutFloats(mode) { |
| 170 | function value1(value) { |
| 171 | return value + 10; |
| 172 | } |
| 173 | |
| 174 | function value2(value) { |
| 175 | return value + 50; |
| 176 | } |
| 177 | |
| 178 | const gpu = new GPU({ mode }); |
| 179 | const kernel = gpu.createKernelMap( |
| 180 | { |
| 181 | valueOutput1: value1, |
| 182 | valueOutput2: value2, |
| 183 | }, |
| 184 | function (a, b) { |
| 185 | value1(a[this.thread.x]); |
| 186 | return value2(b[this.thread.x]) + 100; |
| 187 | }, |
| 188 | { |
| 189 | output: [1], |
| 190 | immutable: true, |
| 191 | pipeline: true, |
| 192 | precision: 'unsigned', |
| 193 | } |
| 194 | ); |
| 195 | |
| 196 | // start with a value on CPU |
| 197 | const output1 = kernel([10], [20]); |
| 198 | |
| 199 | // reuse that output, simulating that this value will be monitored, and updated via the same kernel |
| 200 | // this is often used in neural networks |
| 201 | const output2 = kernel(output1.result, output1.valueOutput2); |
| 202 | const output3 = kernel(output2.result, output2.valueOutput2); |
| 203 | |
| 204 | function toArray(value) { |
| 205 | return value.toArray ? value.toArray() : value; |
| 206 | } |
| 207 | |
| 208 | assert.equal(toArray(output1.valueOutput1)[0], 20); // 10 + 10 |
| 209 | assert.equal(toArray(output1.valueOutput2)[0], 70); // 20 + 50 |
| 210 | assert.equal(toArray(output1.result)[0], 170); // (20 + 50) + 100 |
| 211 | |
| 212 | assert.equal(toArray(output2.valueOutput1)[0], 180); // 170 + 10 |
| 213 | assert.equal(toArray(output2.valueOutput2)[0], 120); // 70 + 50 |
| 214 | assert.equal(toArray(output2.result)[0], 220); // (70 + 50) + 100 |
| 215 | |
| 216 | assert.equal(toArray(output3.valueOutput1)[0], 230); // 220 + 10 |
| 217 | assert.equal(toArray(output3.valueOutput2)[0], 170); // 120 + 50 |
| 218 | assert.equal(toArray(output3.result)[0], 270); // (120 + 50) + 100 |
| 219 | |
| 220 | gpu.destroy(); |
| 221 | } |
| 222 | |
| 223 | (GPU.isKernelMapSupported ? test : skip)('Issue #267 immutable kernel & sub-kernel output without floats - auto', () => { |
| 224 | immutableKernelsMixedWithoutFloats(); |
no test coverage detected
searching dependent graphs…