MCPcopy Index your code
hub / github.com/gpujs/gpu.js / cpuAddAB

Function cpuAddAB

test/features/inject-native.js:55–78  ·  view source on GitHub ↗
(mode)

Source from the content-addressed store, hash-verified

53});
54
55function cpuAddAB(mode) {
56 function customAdder(a, b) {
57 return a + b;
58 }
59 const gpu = new GPU({mode});
60 gpu
61 .injectNative(customAdder.toString());
62 const kernel = gpu.createKernel(function (a, b) {
63 return customAdder(a[this.thread.x], b[this.thread.x]);
64 }, {
65 output: [6],
66 returnType: 'Integer'
67 });
68
69 const a = [1, 2, 3, 5, 6, 7];
70 const b = [4, 5, 6, 1, 2, 3];
71
72 const result = kernel(a, b);
73
74 const expected = [5, 7, 9, 6, 8, 10];
75
76 assert.deepEqual(Array.from(result), expected);
77 gpu.destroy();
78}
79
80test('addAB cpu', () => {
81 cpuAddAB('cpu');

Callers 1

inject-native.jsFile · 0.85

Calls 6

injectNativeMethod · 0.95
createKernelMethod · 0.95
destroyMethod · 0.95
kernelFunction · 0.85
customAdderFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…