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

Function withGPUAddFunctionMethod

test/features/add-custom-function.js:53–74  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

51
52
53function withGPUAddFunctionMethod(mode) {
54 function customAdder(a, b) {
55 return a + b;
56 }
57 const gpu = new GPU({ mode })
58 .addFunction(customAdder);
59 const kernel = gpu.createKernel(function (a, b) {
60 return customAdder(a[this.thread.x], b[this.thread.x]);
61 }, {
62 output: [6]
63 });
64
65 const a = [1, 2, 3, 5, 6, 7];
66 const b = [4, 5, 6, 1, 2, 3];
67
68 const result = kernel(a, b);
69
70 const expected = [5, 7, 9, 6, 8, 10];
71
72 assert.deepEqual(Array.from(result), expected);
73 gpu.destroy();
74}
75
76test('with GPU addFunction method auto', () => {
77 withGPUAddFunctionMethod(null);

Callers 1

Calls 5

kernelFunction · 0.85
createKernelMethod · 0.80
customAdderFunction · 0.70
addFunctionMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…