From f83ecb1aaa9c5dc220709fa9db342652ca4d516d Mon Sep 17 00:00:00 2001 From: Abhishek Soni Date: Fri, 30 Jun 2017 20:44:05 +0530 Subject: [PATCH] kernel.js(cpu) --- src/backend/cpu/kernel.js | 57 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/backend/cpu/kernel.js b/src/backend/cpu/kernel.js index e4f1e1f8..bbf29885 100644 --- a/src/backend/cpu/kernel.js +++ b/src/backend/cpu/kernel.js @@ -5,7 +5,28 @@ const kernelString = require('./kernel-string'); /// /// Class: CPUKernel /// +/// Kernel Implementation for CPU. +/// +/// Extends: +/// KernelBase +/// +/// Parameters: +/// thread - {Object} The thread dimensions, x, y and z +/// runDimensions - {Object} The canvas dimensions +/// functionBuilder - {Object} Function Builder instance bound to this Kernel +/// run - {Function} Method to run the kernel +/// module.exports = class CPUKernel extends KernelBase { + + // + // [Constructor] + // + + /// + /// Function: CPUKernel + /// + /// Instantiates properties to the CPU Kernel. + /// constructor(fnString, settings) { super(fnString, settings); this._fnBody = utils.getFunctionBodyFromString(fnString); @@ -34,6 +55,12 @@ module.exports = class CPUKernel extends KernelBase { }.bind(this); } + /// + /// Function: validateOptions + /// + /// Validate options related to CPU Kernel, such as + /// dimensions size, and auto dimension support. + /// validateOptions() { if (!this.dimensions || this.dimensions.length === 0) { if (arguments.length !== 1) { @@ -49,8 +76,17 @@ module.exports = class CPUKernel extends KernelBase { throw 'Auto dimensions not supported for input type: ' + argType; } } - } - + } + + /// + /// Function: build + /// + /// Builds the Kernel, by generating the kernel + /// string using thread dimensions, and arguments + /// supplied to the kernel. + /// + /// If the graphical flag is enabled, canvas is used. + /// build() { const kernelArgs = []; for (let i = 0; i < arguments.length; i++) { @@ -116,6 +152,18 @@ module.exports = class CPUKernel extends KernelBase { this._colorData[index * 4 + 3] = a; } + /// + /// Function: getKernelString + /// + /// 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: + /// result {String} + /// getKernelString() { if (this._kernelString !== null) return this._kernelString; @@ -213,6 +261,11 @@ module.exports = class CPUKernel extends KernelBase { }.bind(this);`; } + /// + /// Function: toString + /// + /// Returns the *pre-compiled* Kernel as a JS Object String, that can be reused. + /// toString() { return kernelString(this); }