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

Function argumentCasting

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

Source from the content-addressed store, hash-verified

118describe('features: argument casting');
119
120function argumentCasting(mode) {
121 const gpu = new GPU({
122 mode,
123 functions: [divide],
124 nativeFunctions: [{
125 // deliberately add, rather than divide, to ensure native functions are treated as more important than regular ones
126 name: 'divide',
127 source: `float divide(int a, int b) {
128 return float(a + b);
129 }`
130 }]
131 });
132
133 function divide(a,b) {
134 return a / b;
135 }
136
137 const kernel = gpu.createKernel(function(a, b) {
138 return divide(a[this.thread.x], b[this.thread.x]);
139 }, {
140 output : [6]
141 });
142
143 const a = [1, 4, 3, 5, 6, 3];
144 const b = [4, 2, 6, 1, 2, 3];
145
146 const res = kernel(a,b);
147 const exp = [5, 6, 9, 6, 8, 6];
148
149 assert.deepEqual(Array.from(res), exp);
150 gpu.destroy();
151}
152
153test('argumentCasting (GPU only) auto', () => {
154 argumentCasting(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…