(mode)
| 100 | describe('issue #267 sub kernel'); |
| 101 | |
| 102 | function immutableSubKernelsWithoutFloats(mode) { |
| 103 | function value1(value) { |
| 104 | return value + 1; |
| 105 | } |
| 106 | |
| 107 | function value2(value) { |
| 108 | return value + 1; |
| 109 | } |
| 110 | |
| 111 | const gpu = new GPU({ mode }); |
| 112 | const kernel = gpu.createKernelMap( |
| 113 | { |
| 114 | valueOutput1: value1, |
| 115 | valueOutput2: value2 |
| 116 | }, |
| 117 | function (a, b) { |
| 118 | value1(a[this.thread.x]); |
| 119 | return value2(b[this.thread.x]); |
| 120 | }, |
| 121 | { |
| 122 | output: [1], |
| 123 | immutable: true, |
| 124 | pipeline: true, |
| 125 | precision: 'unsigned', |
| 126 | } |
| 127 | ); |
| 128 | |
| 129 | // start with a value on CPU |
| 130 | const output1 = kernel([1], [2]); |
| 131 | const result1 = output1.valueOutput1.toArray()[0]; |
| 132 | |
| 133 | // reuse that output, simulating that this value will be monitored, and updated via the same kernel |
| 134 | // this is often used in neural networks |
| 135 | const output2 = kernel(output1.valueOutput1, output1.valueOutput2); |
| 136 | const result2 = output2.valueOutput1.toArray()[0]; |
| 137 | |
| 138 | const output3 = kernel(output2.valueOutput1, output2.valueOutput2); |
| 139 | const result3 = output3.valueOutput1.toArray()[0]; |
| 140 | |
| 141 | assert.equal(result1, 2); |
| 142 | assert.equal(result2, 3); |
| 143 | assert.equal(result3, 4); |
| 144 | gpu.destroy(); |
| 145 | } |
| 146 | (GPU.isKernelMapSupported ? test : skip)('Issue #267 immutable sub-kernel output - auto', () => { |
| 147 | immutableSubKernelsWithoutFloats(); |
| 148 | }); |
no test coverage detected
searching dependent graphs…