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

Function withKernelAddFunctionMethod

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

Source from the content-addressed store, hash-verified

147});
148
149function withKernelAddFunctionMethod(mode) {
150 function customAdder(a, b) {
151 return a + b;
152 }
153 const gpu = new GPU({ mode });
154 const kernel = gpu.createKernel(function (a, b) {
155 return customAdder(a[this.thread.x], b[this.thread.x]);
156 }, {
157 output: [6]
158 })
159 .addFunction(customAdder);
160
161 const a = [1, 2, 3, 5, 6, 7];
162 const b = [4, 5, 6, 1, 2, 3];
163
164 const result = kernel(a, b);
165
166 const expected = [5, 7, 9, 6, 8, 10];
167
168 assert.deepEqual(Array.from(result), expected);
169 gpu.destroy();
170}
171
172test('with Kernel addFunction method auto', () => {
173 withKernelAddFunctionMethod(null);

Callers 1

Calls 5

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…