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

Function divideOverride

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

Source from the content-addressed store, hash-verified

63describe('features: instantiate native and override');
64
65function divideOverride(mode) {
66 const gpu = new GPU({
67 mode,
68 functions: [divide],
69 nativeFunctions: [{
70 name: 'divide',
71 // deliberately add, rather than divide, to ensure native functions are treated as more important than regular ones
72 source: `float divide(float a, float b) {
73 return a + b;
74 }`
75 }]
76 });
77
78 function divide(a,b) {
79 return a / b;
80 }
81
82 const kernel = gpu.createKernel(function(a, b) {
83 return divide(a[this.thread.x], b[this.thread.x]);
84 }, {
85 output : [6]
86 });
87
88 const a = [1, 4, 3, 5, 6, 3];
89 const b = [4, 2, 6, 1, 2, 3];
90
91 const res = kernel(a,b);
92 const exp = [5, 6, 9, 6, 8, 6];
93
94 assert.deepEqual(Array.from(res), exp);
95 gpu.destroy();
96}
97
98test('divideOverride (GPU only) auto', () => {
99 divideOverride(null);

Callers 1

Calls 4

createKernelMethod · 0.95
destroyMethod · 0.95
kernelFunction · 0.85
divideFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…