MCPcopy
hub / github.com/gpujs/gpu.js / createKernel

Method createKernel

src/gpu.js:211–361  ·  view source on GitHub ↗

* @desc This creates a callable function object to call the kernel function with the argument parameter set * @param {Function|String|object} source - The calling to perform the conversion * @param {IGPUKernelSettings} [settings] - The parameter configuration object * @return {IKernelRunSho

(source, settings)

Source from the content-addressed store, hash-verified

209 * @return {IKernelRunShortcut} callable function to run
210 */
211 createKernel(source, settings) {
212 if (typeof source === 'undefined') {
213 throw new Error('Missing source parameter');
214 }
215 if (typeof source !== 'object' && !utils.isFunction(source) && typeof source !== 'string') {
216 throw new Error('source parameter not a function');
217 }
218
219 const kernels = this.kernels;
220 if (this.mode === 'dev') {
221 const devKernel = gpuMock(source, upgradeDeprecatedCreateKernelSettings(settings));
222 kernels.push(devKernel);
223 return devKernel;
224 }
225
226 source = typeof source === 'function' ? source.toString() : source;
227 const switchableKernels = {};
228 const settingsCopy = upgradeDeprecatedCreateKernelSettings(settings) || {};
229 // handle conversion of argumentTypes
230 if (settings && typeof settings.argumentTypes === 'object') {
231 settingsCopy.argumentTypes = Object.keys(settings.argumentTypes).map(argumentName => settings.argumentTypes[argumentName]);
232 }
233
234 function onRequestFallback(args) {
235 console.warn('Falling back to CPU');
236 const fallbackKernel = new CPUKernel(source, {
237 argumentTypes: kernelRun.argumentTypes,
238 constantTypes: kernelRun.constantTypes,
239 graphical: kernelRun.graphical,
240 loopMaxIterations: kernelRun.loopMaxIterations,
241 constants: kernelRun.constants,
242 dynamicOutput: kernelRun.dynamicOutput,
243 dynamicArgument: kernelRun.dynamicArguments,
244 output: kernelRun.output,
245 precision: kernelRun.precision,
246 pipeline: kernelRun.pipeline,
247 immutable: kernelRun.immutable,
248 optimizeFloatMemory: kernelRun.optimizeFloatMemory,
249 fixIntegerDivisionAccuracy: kernelRun.fixIntegerDivisionAccuracy,
250 functions: kernelRun.functions,
251 nativeFunctions: kernelRun.nativeFunctions,
252 injectedNative: kernelRun.injectedNative,
253 subKernels: kernelRun.subKernels,
254 strictIntegers: kernelRun.strictIntegers,
255 debug: kernelRun.debug,
256 });
257 fallbackKernel.build.apply(fallbackKernel, args);
258 const result = fallbackKernel.run.apply(fallbackKernel, args);
259 kernelRun.replaceKernel(fallbackKernel);
260 return result;
261 }
262
263 /**
264 *
265 * @param {IReason[]} reasons
266 * @param {IArguments} args
267 * @param {Kernel} _kernel
268 * @returns {*}

Callers 15

greenCanvasFunction · 0.95
outputArrayFunction · 0.95
outputMatrixFunction · 0.95
outputCubeFunction · 0.95
outputGraphicalArrayFunction · 0.95
outputGraphicalMatrixFunction · 0.95
outputGraphicalCubeFunction · 0.95
canvasArgumentTestFunction · 0.95
inputXFunction · 0.95
inputXYFunction · 0.95
inputYXFunction · 0.95

Calls 3

kernelRunShortcutFunction · 0.85
toStringMethod · 0.45

Tested by

no test coverage detected