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

Function sumABThisOutputX

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

Source from the content-addressed store, hash-verified

254
255describe('features: add custom function with `this.output.x` in loop');
256function sumABThisOutputX(mode) {
257 const gpu = new GPU({ mode, functions: [customAdder] });
258
259 function customAdder(a, b) {
260 let sum = 0;
261 for (let i = 0; i < this.output.x; i++) {
262 sum += a[this.thread.x] + b[this.thread.x];
263 }
264 return sum;
265 }
266
267 const kernel = gpu.createKernel(function(a, b) {
268 return customAdder(a, b);
269 }, {
270 output : [6],
271 });
272
273 assert.ok(kernel !== null, 'function generated test');
274
275 const a = [1, 2, 3, 5, 6, 7];
276 const b = [1, 1, 1, 1, 1, 1];
277
278 const result = kernel(a,b);
279 const expected = [12, 18, 24, 36, 42, 48];
280
281 assert.deepEqual(Array.from(result), expected);
282 gpu.destroy();
283}
284
285test('sumABThisOutputX auto', () => {
286 sumABThisOutputX(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…