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

Function addCustomPrivate

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

Source from the content-addressed store, hash-verified

309
310describe('features: add custom private');
311function addCustomPrivate(mode) {
312 const gpu = new GPU({ mode });
313
314 const kernel = gpu.createKernel(function(a, b) {
315 function customAdder(a, b) {
316 let sum = 0;
317 for (let i = 0; i < this.output.x; i++) {
318 sum += a[this.thread.x] + b[this.thread.x];
319 }
320 return sum;
321 }
322 return customAdder(a, b);
323 }, {
324 output : [6],
325 });
326
327 assert.ok(kernel !== null, 'function generated test');
328
329 const a = [1, 2, 3, 5, 6, 7];
330 const b = [1, 1, 1, 1, 1, 1];
331
332 const result = kernel(a,b);
333 const expected = [12, 18, 24, 36, 42, 48];
334
335 assert.deepEqual(Array.from(result), expected);
336 gpu.destroy();
337}
338
339test('auto', () => {
340 addCustomPrivate(null);

Callers 1

Calls 4

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…