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

Method getKernelString

src/backend/cpu/kernel.js:212–240  ·  view source on GitHub ↗

* @desc Generates kernel string for this kernel program. * * If sub-kernels are supplied, they are also factored in. * This string can be saved by calling the `toString` method * and then can be reused later. * * @returns {String} result *

()

Source from the content-addressed store, hash-verified

210 *
211 */
212 getKernelString() {
213 if (this._kernelString !== null) return this._kernelString;
214
215 let kernelThreadString = null;
216 let {
217 translatedSources
218 } = this;
219 if (translatedSources.length > 1) {
220 translatedSources = translatedSources.filter(fn => {
221 if (/^function/.test(fn)) return fn;
222 kernelThreadString = fn;
223 return false;
224 });
225 } else {
226 kernelThreadString = translatedSources.shift();
227 }
228 return this._kernelString = ` const LOOP_MAX = ${ this._getLoopMaxString() };
229 ${ this.injectedNative || '' }
230 const _this = this;
231 ${ this._resultKernelHeader() }
232 ${ this._processConstants() }
233 return (${ this.argumentNames.map(argumentName => 'user_' + argumentName).join(', ') }) => {
234 ${ this._prependedString.join('') }
235 ${ this._earlyThrows() }
236 ${ this._processArguments() }
237 ${ this.graphical ? this._graphicalKernelBody(kernelThreadString) : this._resultKernelBody(kernelThreadString) }
238 ${ translatedSources.length > 0 ? translatedSources.join('\n') : '' }
239 };`;
240 }
241
242 /**
243 * @desc Returns the *pre-compiled* Kernel as a JS Object String, that can be reused.

Callers 1

buildMethod · 0.95

Calls 7

_getLoopMaxStringMethod · 0.95
_resultKernelHeaderMethod · 0.95
_processConstantsMethod · 0.95
_earlyThrowsMethod · 0.95
_processArgumentsMethod · 0.95
_graphicalKernelBodyMethod · 0.95
_resultKernelBodyMethod · 0.95

Tested by

no test coverage detected