MCPcopy Create free account
hub / github.com/gpujs/gpu.js / immutableKernelWithoutFloats

Function immutableKernelWithoutFloats

test/issues/267-immutable-sub-kernels.js:6–33  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

4describe('issue #267 kernel');
5
6function immutableKernelWithoutFloats(mode) {
7 const gpu = new GPU({ mode });
8 const kernel = gpu.createKernel(function (v) {
9 return v[this.thread.x] + 1;
10 }, {
11 output: [1],
12 immutable: true,
13 pipeline: true,
14 precision: 'unsigned',
15 });
16
17 // start with a value on CPU
18 const output1 = kernel([1]);
19 const result1 = output1.toArray()[0];
20
21 // reuse that output, simulating that this value will be monitored, and updated via the same kernel
22 // this is often used in neural networks
23 const output2 = kernel(output1);
24 const result2 = output2.toArray()[0];
25
26 const output3 = kernel(output2);
27 const result3 = output3.toArray()[0];
28
29 assert.equal(result1, 2);
30 assert.equal(result2, 3);
31 assert.equal(result3, 4);
32 gpu.destroy();
33}
34
35test('Issue #267 immutable kernel output without floats - auto', () => {
36 immutableKernelWithoutFloats();

Callers 1

Calls 4

createKernelMethod · 0.95
destroyMethod · 0.95
kernelFunction · 0.85
toArrayMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…