Back to Top

gpu.js master

GPU Accelerated JavaScript

function()

gpu.js http://gpu.rocks/

GPU Accelerated JavaScript

Returns

Void

function()

gpu.js http://gpu.rocks/

GPU Accelerated JavaScript

Returns

Void

alias(name, source)

Parameters

Name Type Description
name
source

Returns

Function

new CPUFunctionNode()

Returns

Void

CPUFunctionNode.astFunction(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astReturnStatement(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astLiteral(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astBinaryExpression(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astIdentifierExpression(idtNode, retArr)

Parameters

Name Type Description
idtNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astForStatement(forNode, retArr)

Parameters

Name Type Description
forNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the parsed webgl string

CPUFunctionNode.astWhileStatement(whileNode, retArr)

Parameters

Name Type Description
whileNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the parsed javascript string

CPUFunctionNode.astDoWhileStatement(doWhileNode, retArr)

Parameters

Name Type Description
doWhileNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the parsed webgl string

CPUFunctionNode.astAssignmentExpression(assNode, retArr)

Parameters

Name Type Description
assNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astBlockStatement(bNode, retArr)

Parameters

Name Type Description
bNode Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astVariableDeclaration(varDecNode, retArr)

Parameters

Name Type Description
varDecNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astIfStatement(ifNode, retArr)

Parameters

Name Type Description
ifNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astThisExpression(tNode, retArr)

Parameters

Name Type Description
tNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astMemberExpression(mNode, retArr)

Parameters

Name Type Description
mNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astCallExpression(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

CPUFunctionNode.astArrayExpression(arrNode, retArr)

Parameters

Name Type Description
arrNode Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

new CPUKernel()

Returns

Void

validateSettings(args)

Parameters

Name Type Description
args IArguments

Returns

Void

build()

Returns

Void

getKernelString()

Returns

String

result

toString()

Returns

Void

_getLoopMaxString()

Returns

String

result

getPixels(flip)

Parameters

Name Type Description
flip

Returns

Uint8ClampedArray

new FunctionBuilder()

Returns

Void

FunctionBuilder.fromKernel(kernel, FunctionNode[, extraNodeOptions])

Parameters

Name Type Description
kernel Kernel
FunctionNode FunctionNode
extraNodeOptions object Optional

Returns

FunctionBuilder

FunctionBuilder.constructor([settings])

Parameters

Name Type Description
settings IFunctionBuilderSettings Optional

Returns

Void

FunctionBuilder.addFunctionNode(functionNode)

Parameters

Name Type Description
functionNode FunctionNode
  • functionNode to add

Returns

Void

FunctionBuilder.traceFunctionCalls(functionName[, retList])

Parameters

Name Type Description
functionName String
  • Function name to trace from, default to 'kernel'
retList Array.<String>
  • Returning list of function names that is traced. Including itself.
Optional

Returns

Array.<String>

Returning list of function names that is traced. Including itself.

dependantNativeFunctionName()

https://github.com/gpujs/gpu.js/issues/207 if dependent function is already in the list, because a function depends on it, and because it has already been traced, we know that we must move the dependent function to the end of the the retList.

Returns

Void

dependantFunctionName()

https://github.com/gpujs/gpu.js/issues/207 if dependent function is already in the list, because a function depends on it, and because it has already been traced, we know that we must move the dependent function to the end of the the retList.

Returns

Void

getPrototypeString(functionName)

Parameters

Name Type Description
functionName String
  • Function name to trace from. If null, it returns the WHOLE builder stack

Returns

String

The full string, of all the various functions. Trace optimized if functionName given

getPrototypes([functionName])

Parameters

Name Type Description
functionName String
  • Function name to trace from. If null, it returns the WHOLE builder stack
Optional

Returns

Array

The full string, of all the various functions. Trace optimized if functionName given

getStringFromFunctionNames(functionList)

Parameters

Name Type Description
functionList Array.<String>
  • List of function to build string

Returns

String

The string, of all the various functions. Trace optimized if functionName given

getPrototypesFromFunctionNames(functionList)

Parameters

Name Type Description
functionList Array.<String>
  • List of function names to build the string.

Returns

Array

Prototypes of all functions converted

getString(functionName)

Parameters

Name Type Description
functionName String
  • Function name to trace from. If null, it returns the WHOLE builder stack

Returns

String

settings - The string, of all the various functions. Trace optimized if functionName given

_getFunction(functionName) private method

Parameters

Name Type Description
functionName String

Returns

FunctionNode

lookupFunctionArgumentBitRatio(functionName, argumentName)

Parameters

Name Type Description
functionName string
argumentName string

Returns

number

assignArgumentBitRatio(functionName, argumentName, calleeFunctionName, argumentIndex)

Parameters

Name Type Description
functionName string
argumentName string
calleeFunctionName string
argumentIndex number

Returns

number

new FunctionNode()

Returns

Void

FunctionNode.constructor(source[, settings])

Parameters

Name Type Description
source string object
settings IFunctionSettings Optional

Returns

Void

FunctionNode.isIdentifierConstant(name)

Parameters

Name Type Description
name String

Returns

boolean

FunctionNode.astMemberExpressionUnroll(ast)

Parameters

Name Type Description
ast Object
  • the AST object to parse

Returns

String

the function namespace call, unrolled

FunctionNode.getJsAST([inParser])

Parameters

Name Type Description
inParser Object
  • Parser to use, assumes in scope 'parser' if null or undefined
Optional

Returns

Object

The function AST Object, note that result is cached under this.ast;

FunctionNode.getVariableType(ast)

Parameters

Name Type Description
ast Object
  • Identifier

Returns

String

Type of the parameter

FunctionNode.getLookupType(type)

Generally used to lookup the value type returned from a member expressions

Parameters

Name Type Description
type String

Returns

String

FunctionNode.getType(ast)

Recursively looks up type for ast expression until it's found

Parameters

Name Type Description
ast

Returns

String

FunctionNode.getDependencies(ast, dependencies, isNotSafe)

Parameters

Name Type Description
ast
dependencies
isNotSafe

Returns

Array

FunctionNode.astGeneric(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the parsed string array

FunctionNode.astErrorOutput(error, ast)

Parameters

Name Type Description
error string
  • the error message output
ast Object
  • the AST object where the error is

Returns

Void

FunctionNode.astFunction(ast, retArr)

Parameters

Name Type Description
ast Object
retArr Array.<String>

Returns

Array.<String>

FunctionNode.astFunctionDeclaration(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astExpressionStatement(esNode, retArr)

Parameters

Name Type Description
esNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astEmptyStatement(eNode, retArr)

Parameters

Name Type Description
eNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astBreakStatement(brNode, retArr)

Parameters

Name Type Description
brNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astContinueStatement(crNode, retArr)

Parameters

Name Type Description
crNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astVariableDeclarator(iVarDecNode, retArr)

Parameters

Name Type Description
iVarDecNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astUnaryExpression(uNode, retArr)

Parameters

Name Type Description
uNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astUpdateExpression(uNode, retArr)

Parameters

Name Type Description
uNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.astLogicalExpression(logNode, retArr)

Parameters

Name Type Description
logNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

FunctionNode.getMemberExpressionDetails(ast)

Parameters

Name Type Description
ast

Returns

IFunctionNodeMemberExpressionDetails

this.declarations()

Returns

Void

getDeclaration(name)

Parameters

Name Type Description
name string

Returns

IDeclaration

scan(ast)

Recursively scans AST for declarations and functions, and add them to their respective context

Parameters

Name Type Description
ast

Returns

Void

glKernelString(Kernel, args, originKernel[, setupContextString, destroyContextString])

Parameters

Name Type Description
Kernel GLKernel
args Array.<KernelVariable>
originKernel Kernel
setupContextString string Optional
destroyContextString string Optional

Returns

string

findKernelValue(argument, kernelValues, values, context, uploadedValues)

Parameters

Name Type Description
argument KernelVariable
kernelValues Array.<KernelValue>
values Array.<KernelVariable>
context
uploadedValues Array.<KernelVariable>

Returns

string

new GLKernel()

Returns

Void

setupFeatureChecks()

Returns

Void

setFixIntegerDivisionAccuracy(fix)

Parameters

Name Type Description
fix Boolean
  • should fix

Returns

Void

setPrecision(flag)

Parameters

Name Type Description
flag String
  • 'single' or 'unsigned'

Returns

Void

setFloatTextures(flag)

Parameters

Name Type Description
flag Boolean
  • true to enable floatTextures

Returns

Void

nativeFunctionArguments(source)

A highly readable very forgiving micro-parser for a glsl function that gets argument types

Parameters

Name Type Description
source String

Returns

[object Object]

this.TextureConstructor()

Returns

Void

pickRenderStrategy(args)

Picks a render strategy for the now finally parsed kernel

Parameters

Name Type Description
args

Returns

KernelOutput

getKernelString()

Returns

String

getMainResultKernelNumberTexture()

Returns

String[]

getMainResultSubKernelNumberTexture()

Returns

String[]

getMainResultKernelArray2Texture()

Returns

String[]

getMainResultSubKernelArray2Texture()

Returns

String[]

getMainResultKernelArray3Texture()

Returns

String[]

getMainResultSubKernelArray3Texture()

Returns

String[]

getMainResultKernelArray4Texture()

Returns

String[]

getMainResultSubKernelArray4Texture()

Returns

String[]

getMainResultGraphical()

Returns

String[]

getMainResultMemoryOptimizedFloats()

Returns

String[]

getMainResultPackedPixels()

Returns

String[]

getFloatTacticDeclaration()

Returns

string

getIntTacticDeclaration()

Returns

string

getSampler2DTacticDeclaration()

Returns

string

getPixels([flip])

Parameters

Name Type Description
flip Boolean Optional

Returns

Uint8ClampedArray

updateTextureArgumentRefs(kernelValue, arg)

Parameters

Name Type Description
kernelValue WebGLKernelValue
arg GLTexture

Returns

Void

new GLTexture()

Properties

Name Type Description
framebuffer

Returns

Void

GLTexture.textureType()

Returns

Number

GLTexture.beforeMutate()

Returns

Boolean

GLTexture.cloneTexture() private method

Returns

Void

GLTexture.newTexture() private method

Returns

Void

toString()

Returns

Void

new KernelValue()

Returns

Void

KernelValue.constructor(value, settings)

Parameters

Name Type Description
value KernelVariable
settings IKernelValueSettings

Returns

Void

isContextMatch()

Returns

Boolean

getFeatures()

Returns

Void

constructor(source, settings)

Parameters

Name Type Description
source string IKernelJSON
settings

Returns

Void

this.argumentNames()

Name of the arguments found from parsing source argument

Returns

Void

this.source()

The function source

Returns

Void

this.output()

The size of the kernel's output

Returns

Void

this.debug()

Debug mode

Returns

Void

this.graphical()

Graphical mode

Returns

Void

this.loopMaxIterations()

Maximum loops when using argument values to prevent infinity

Returns

Void

this.constants()

Constants used in kernel via this.constants

Returns

Void

this.constantTypes()

Returns

Void

this.constantBitRatios()

Returns

Void

this.dynamicArguments()

Returns

Void

this.dynamicOutput()

Returns

Void

this.canvas()

Returns

Void

this.context()

Returns

Void

this.checkContext()

Returns

Void

this.gpu()

Returns

Void

this.functions()

Returns

Void

this.nativeFunctions()

Returns

Void

this.injectedNative()

Returns

Void

this.subKernels()

Returns

Void

this.validate()

Returns

Void

this.immutable()

Enforces kernel to write to a new array or texture on run

Returns

Void

this.pipeline()

Enforces kernel to write to a texture on run

Returns

Void

this.precision()

Make GPU use single precision or unsigned. Acceptable values: 'single' or 'unsigned'

Returns

Void

this.tactic()

Returns

Void

mergeSettings(settings)

Parameters

Name Type Description
settings IDirectKernelSettings IJSONSettings

Returns

Void

build()

Returns

Void

run()

Returns

Float32Array Array.<Float32Array> Array.<Array.<Float32Array>>

Result The final output of the program, as float, and as Textures for reuse.

initCanvas()

Returns

Object

initContext()

Returns

Object

initPlugins(settings)

Parameters

Name Type Description
settings IDirectKernelSettings

Returns

{string[]};

addFunction(source[, settings])

Parameters

Name Type Description
source KernelFunction string IGPUFunction
settings IFunctionSettings Optional

Returns

Kernel

addNativeFunction(name, source[, settings])

Parameters

Name Type Description
name string
source string
settings IGPUFunctionSettings Optional

Returns

Void

setupArguments(args)

Parameters

Name Type Description
args IArguments
  • The actual parameters sent to the Kernel

Returns

Void

setupConstants()

Setup constants

Returns

Void

setOptimizeFloatMemory(flag)

Parameters

Name Type Description
flag

Returns

this

toKernelOutput(output)

Parameters

Name Type Description
output Array Object

Returns

Array.<number>

setOutput(output)

Parameters

Name Type Description
output Array Object
  • The output array to set the kernel output size to

Returns

this

setDebug(flag)

Parameters

Name Type Description
flag Boolean
  • true to enable debug

Returns

this

setGraphical(flag)

Parameters

Name Type Description
flag Boolean
  • true to enable graphical output

Returns

this

setLoopMaxIterations(max)

Parameters

Name Type Description
max number
  • iterations count

Returns

this

setConstants()

Returns

this

setConstantTypes(constantTypes)

Parameters

Name Type Description
constantTypes IKernelValueTypes

Returns

this

setFunctions(functions)

Parameters

Name Type Description
functions Array.<IFunction> Array.<KernelFunction>

Returns

this

setNativeFunctions(nativeFunctions)

Parameters

Name Type Description
nativeFunctions Array.<IGPUNativeFunction>

Returns

this

setInjectedNative(injectedNative)

Parameters

Name Type Description
injectedNative String

Returns

this

setPipeline(flag)

Set writing to texture on/off

Parameters

Name Type Description
flag

Returns

this

setPrecision(flag)

Set precision to 'unsigned' or 'single'

Parameters

Name Type Description
flag String

'unsigned' or 'single'

Returns

this

setDimensions(flag)

Parameters

Name Type Description
flag

Returns

Kernel

setOutputToTexture(flag)

Parameters

Name Type Description
flag

Returns

this

setImmutable(flag)

Set to immutable

Parameters

Name Type Description
flag

Returns

this

setCanvas(canvas)

Parameters

Name Type Description
canvas Object

Returns

this

setStrictIntegers(flag)

Parameters

Name Type Description
flag Boolean

Returns

this

setDynamicOutput(flag)

Parameters

Name Type Description
flag

Returns

this

setHardcodeConstants(flag)

Parameters

Name Type Description
flag

Returns

this

setDynamicArguments(flag)

Parameters

Name Type Description
flag

Returns

this

setUseLegacyEncoder(flag)

Parameters

Name Type Description
flag Boolean

Returns

this

setWarnVarUsage(flag)

Parameters

Name Type Description
flag Boolean

Returns

this

getCanvas()

Returns

Object

getWebGl()

Returns

Object

setContext(context)

Parameters

Name Type Description
context WebGLRenderingContext
  • webGl instance to bind

Returns

Void

setArgumentTypes(argumentTypes)

Parameters

Name Type Description
argumentTypes IKernelValueTypes Array.<GPUVariableType>

Returns

this

setTactic(tactic)

Parameters

Name Type Description
tactic Tactic

Returns

this

validateSettings()

Returns

Void

addSubKernel(subKernel)

Parameters

Name Type Description
subKernel ISubKernel
  • function (as a String) of the subKernel to add

Returns

Void

destroy([removeCanvasReferences])

Parameters

Name Type Description
removeCanvasReferences Boolean

remove any associated canvas references

Optional

Returns

Void

getBitRatio(value)

bit storage ratio of source to target 'buffer', i.e. if 8bit array -> 32bit tex = 4

Parameters

Name Type Description
value

Returns

number

getPixels([flip])

Parameters

Name Type Description
flip Boolean Optional

Returns

Uint8ClampedArray

prependString(value)

Parameters

Name Type Description
value String

Returns

Void

hasPrependString(value)

Parameters

Name Type Description
value String

Returns

Boolean

toJSON()

Returns

IKernelJSON

buildSignature(args)

Parameters

Name Type Description
args IArguments

Returns

Void

getArgumentTypes(kernel, args)

Parameters

Name Type Description
kernel Kernel
args IArguments

Returns

GPUVariableType[]

getSignature(kernel, argumentTypes)

Parameters

Name Type Description
kernel Kernel
argumentTypes Array.<GPUVariableType>

Returns

Void

functionToIGPUFunction(source[, settings])

Parameters

Name Type Description
source String Function
settings IFunctionSettings Optional

Returns

IGPUFunction

onActivate(previousKernel)

Parameters

Name Type Description
previousKernel Kernel

Returns

Void

new WebGLFunctionNode()

Returns

Void

WebGLFunctionNode.astFunction(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astReturnStatement(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astLiteral(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astBinaryExpression(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.castLiteralToInteger(ast, retArr)

Parameters

Name Type Description
ast Object
retArr Array

Returns

Array.<String>

WebGLFunctionNode.castLiteralToFloat(ast, retArr)

Parameters

Name Type Description
ast Object
retArr Array

Returns

Array.<String>

WebGLFunctionNode.castValueToInteger(ast, retArr)

Parameters

Name Type Description
ast Object
retArr Array

Returns

Array.<String>

WebGLFunctionNode.castValueToFloat(ast, retArr)

Parameters

Name Type Description
ast Object
retArr Array

Returns

Array.<String>

WebGLFunctionNode.astIdentifierExpression(idtNode, retArr)

Parameters

Name Type Description
idtNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astForStatement(forNode, retArr)

Parameters

Name Type Description
forNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the parsed webgl string

WebGLFunctionNode.astWhileStatement(whileNode, retArr)

Parameters

Name Type Description
whileNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the parsed webgl string

WebGLFunctionNode.astDoWhileStatement(doWhileNode, retArr)

Parameters

Name Type Description
doWhileNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the parsed webgl string

WebGLFunctionNode.astAssignmentExpression(assNode, retArr)

Parameters

Name Type Description
assNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astBlockStatement(bNode, retArr)

Parameters

Name Type Description
bNode Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astVariableDeclaration(varDecNode, retArr)

Parameters

Name Type Description
varDecNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astIfStatement(ifNode, retArr)

Parameters

Name Type Description
ifNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astThisExpression(tNode, retArr)

Parameters

Name Type Description
tNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astMemberExpression(mNode, retArr)

Parameters

Name Type Description
mNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astCallExpression(ast, retArr)

Parameters

Name Type Description
ast Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

WebGLFunctionNode.astArrayExpression(arrNode, retArr)

Parameters

Name Type Description
arrNode Object
  • the AST object to parse
retArr Array
  • return array string

Returns

Array

the append retArr

new WebGLKernelArray()

Returns

Void

WebGLKernelArray.checkSize(width, height)

Parameters

Name Type Description
width number
height number

Returns

Void

WebGLKernelArray.getBitRatio(value)

bit storage ratio of source to target 'buffer', i.e. if 8bit array -> 32bit tex = 4

Parameters

Name Type Description
value

Returns

number

constructor(value, settings)

Parameters

Name Type Description
value KernelVariable
settings IWebGLKernelValueSettings

Returns

Void

getStringValueHandler()

Used for when we want a string output of our kernel, so we can still input values to the kernel

Returns

Void

updateValue(inputTexture)

Parameters

Name Type Description
inputTexture GLTextureMemoryOptimized

Returns

Void

updateValue(inputTexture)

Parameters

Name Type Description
inputTexture GLTexture

Returns

Void

testCanvas()

Returns

Void

testContext()

Returns

Void

new WebGLKernel()

Properties

Name Type Description
textureCache Array.<WebGLTexture>
  • webGl Texture cache
programUniformLocationCache Object.<string, WebGLUniformLocation>
  • Location of program variables in memory
framebuffer WebGLFramebuffer
  • Webgl frameBuffer
buffer WebGLBuffer
  • WebGL buffer
program WebGLProgram
  • The webGl Program
functionBuilder FunctionBuilder
  • Function Builder instance bound to this Kernel
pipeline Boolean
  • Set output type to FAST mode (GPU to GPU via Textures), instead of float
endianness string
  • Endian information like Little-endian, Big-endian.
argumentTypes Array.<string>
  • Types of parameters sent to the Kernel
compiledFragmentShader string
  • Compiled fragment shader string
compiledVertexShader string
  • Compiled Vertical shader string

Returns

Void

WebGLKernel.lookupKernelValueType(type, dynamic, precision, value)

Parameters

Name Type Description
type
dynamic
precision
value

Returns

KernelValue

WebGLKernel.constructor(source, settings)

Parameters

Name Type Description
source String IKernelJSON
settings IDirectKernelSettings

Returns

Void

this.maxTexSize()

Returns

Void

this.threadDim()

The thread dimensions, x, y and z

Returns

Void

initContext()

Returns

WebGLRenderingContext

initPlugins(settings)

Parameters

Name Type Description
settings IDirectKernelSettings

Returns

Array.<string>

validateSettings(args)

Parameters

Name Type Description
args IArguments

Returns

Void

_replaceOutputTexture()

Returns

Void

_setupOutputTexture()

Returns

Void

_replaceSubOutputTextures()

Returns

Void

_setupSubOutputTextures()

Returns

Void

getUniformLocation()

Returns

Void

_getFragShaderArtifactMap(args)

Parameters

Name Type Description
args Array
  • The actual parameters sent to the Kernel

Returns

Object

An object containing the Shader Artifacts(CONSTANTS, HEADER, KERNEL, etc.)

_getVertShaderArtifactMap(args)

Parameters

Name Type Description
args Array
  • The actual parameters sent to the Kernel

Returns

Object

An object containing the Shader Artifacts(CONSTANTS, HEADER, KERNEL, etc.)

_getHeaderString()

Returns

String

result

_getLoopMaxString()

Returns

String

result

_getConstantsString()

Returns

String

result

_getTextureCoordinate()

Returns

String

result

_getDecode32EndiannessString()

Returns

String

result

_getEncode32EndiannessString()

Returns

String

result

_getDivideWithIntegerCheckString()

Returns

String

result

_getMainArgumentsString(args)

Parameters

Name Type Description
args Array
  • The actual parameters sent to the Kernel

Returns

String

result

getKernelString()

Returns

String

result

getMainResultKernelPackedPixels()

Returns

String

getMainResultSubKernelPackedPixels()

Returns

String

replaceArtifacts(src, map)

Parameters

Name Type Description
src String
  • Shader string
map Object
  • Variables/Constants associated with shader

Returns

Void

getFragmentShader(args)

Parameters

Name Type Description
args Array
  • The actual parameters sent to the Kernel

Returns

string

Fragment Shader string

getVertexShader(args)

Parameters

Name Type Description
args Array IArguments
  • The actual parameters sent to the Kernel

Returns

string

Vertical Shader string

toString()

Returns

Void

toJSON()

Returns

IKernelJSON

new WebGL2FunctionNode()

Returns

the converted webGL function string

WebGL2FunctionNode.astIdentifierExpression(idtNode, retArr)

Parameters

Name Type Description
idtNode Object
  • An ast Node
retArr Array
  • return array string

Returns

Array

the append retArr

testCanvas()

Returns

Void

testContext()

Returns

Void

features()

Returns

Void

new WebGL2Kernel()

Returns

Void

WebGL2Kernel.getFeatures()

Returns

IKernelFeatures

initContext()

Returns

WebGLRenderingContext WebGL2RenderingContext

validateSettings(args)

Parameters

Name Type Description
args IArguments

Returns

Void

_getHeaderString()

Returns

String

result

_getTextureCoordinate()

Returns

String

result

_getMainArgumentsString(args)

Parameters

Name Type Description
args Array
  • The actual parameters sent to the Kernel

Returns

String

result

getKernelString()

Returns

String

result

getMainResultKernelPackedPixels()

Returns

String

getMainResultSubKernelPackedPixels()

Returns

String

toJSON()

Returns

IKernelJSON

kernelOrder()

Returns

Void

kernelTypes()

Returns

Void

new GPU()

The GPU.js library class which manages the GPU context for the creating kernels

Returns

GPU

constructor([settings])

Creates an instance of GPU.

Parameters

Name Type Description
settings IGPUSettings
  • Settings to set mode, and other properties
Optional

Returns

Void

chooseKernel()

Choose kernel type and save on .Kernel property of GPU

Returns

Void

Kernel()

Returns

Void

createKernel(source[, settings])

Parameters

Name Type Description
source Function String object
  • The calling to perform the conversion
settings IGPUKernelSettings
  • The parameter configuration object
Optional

Returns

IKernelRunShortcut

callable function to run

onRequestSwitchKernel(reasons, args, _kernel)

Parameters

Name Type Description
reasons Array.<IReason>
args IArguments
_kernel Kernel

Returns

createKernelMap(subKernels, rootKernel)

Create a super kernel which executes sub kernels and saves their output to be used with the next sub kernel. This can be useful if we want to save the output on one kernel, and then use it as an input to another kernel. Machine Learning

Parameters

Name Type Description
subKernels Object Array
  • Sub kernels for this kernel
rootKernel Function
  • Root kernel

Examples

const megaKernel = gpu.createKernelMap({
  addResult: function add(a, b) {
    return a[this.thread.x] + b[this.thread.x];
  },
  multiplyResult: function multiply(a, b) {
    return a[this.thread.x] * b[this.thread.x];
  },
 }, function(a, b, c) {
      return multiply(add(a, b), c);
});

megaKernel(a, b, c);

Note: You can also define subKernels as an array of functions.
> [add, multiply]

Returns

Function

callable kernel function

combineKernels(subKernels, rootKernel)

Combine different kernels into one super Kernel, useful to perform multiple operations inside one kernel without the penalty of data transfer between cpu and gpu.

The number of kernel functions sent to this method can be variable. You can send in one, two, etc.

Parameters

Name Type Description
subKernels Function
  • Kernel function(s) to combine.
rootKernel Function
  • Root kernel to combine kernels into

Examples

  combineKernels(add, multiply, function(a,b,c){
    return add(multiply(a,b), c)
 })

Returns

Function

Callable kernel function

addFunction(source[, settings])

Parameters

Name Type Description
source Function String
  • Javascript function to convert
settings IFunctionSettings Optional

Returns

GPU

returns itself

addNativeFunction(name, source[, settings])

Parameters

Name Type Description
name String
  • native function name, used for reverse lookup
source String
  • the native function implementation, as it would be defined in it's entirety
settings object Optional

Returns

GPU

returns itself

injectNative(source)

Inject a string just before translated kernel functions

Parameters

Name Type Description
source String

Returns

GPU

destroy()

Returns

Promise

kernelRunShortcut(kernel)

Makes kernels easier for mortals (including me)

Parameters

Name Type Description
kernel

Returns

function()

shortcut.exec()

Run kernel in async mode

Returns

Promise.<KernelOutput>

module.exports()

Returns

Void

onBeforeRun(kernel)

Parameters

Name Type Description
kernel Kernel

Returns

Void

plugin()

Returns

Void

new Texture(settings)

Parameters

Name Type Description
settings IGPUTextureSettings

Returns

Void

this.kernel()

Returns

Void

toArray()

Returns

TextureArrayOutput

clone()

Returns

Texture

delete()

Returns

Void

utils()

Returns

Void

systemEndianness()

Returns

String

'LE' or 'BE' depending on system architecture Credit: https://gist.github.com/TooTallNate/4750953

isFunction(funcObj)

Parameters

Name Type Description
funcObj Function
  • Object to validate if its a function

Returns

Boolean

TRUE if the object is a JS function

isFunctionString(fn)

Parameters

Name Type Description
fn String
  • String of JS function to validate

Returns

Boolean

TRUE if the string passes basic validation

getFunctionNameFromString(funcStr)

Parameters

Name Type Description
funcStr String
  • String of JS function to validate

Returns

String

Function name string (if found)

getArgumentNamesFromString(fn)

Parameters

Name Type Description
fn String
  • String of JS function to validate

Returns

Array.<String>

Array representing all the parameter names

clone(obj)

Parameters

Name Type Description
obj Object
  • Object to clone

Returns

Object Array

Cloned object

isArray(array)

Parameters

Name Type Description
array Object
  • The argument object to check if is array

Returns

Boolean

true if is array or Array-like object

getVariableType(value[, strictIntegers])

Parameters

Name Type Description
value
  • The argument object to evaluate type
strictIntegers boolean Optional

Returns

String

Argument type Array/Number/Float/Texture/Unknown

closestSquareDimensions(length)

Parameters

Name Type Description
length Number

Returns

TextureDimensions

getMemoryOptimizedFloatTextureSize(dimensions, bitRatio)

A texture takes up four

Parameters

Name Type Description
dimensions OutputDimensions
bitRatio Number

Returns

TextureDimensions

getMemoryOptimizedPackedTextureSize(dimensions, bitRatio)

Parameters

Name Type Description
dimensions
bitRatio

Returns

TextureDimensions

getDimensions(x[, pad])

Parameters

Name Type Description
x Array String Texture Input
  • The array
pad Boolean
  • To include padding in the dimension calculation
Optional

Returns

OutputDimensions

flatten2dArrayTo(array, target)

Puts a nested 2d array into a one-dimensional target array

Parameters

Name Type Description
array Array
target Float32Array Float64Array

Returns

Void

flatten3dArrayTo(array, target)

Puts a nested 3d array into a one-dimensional target array

Parameters

Name Type Description
array Array
target Float32Array Float64Array

Returns

Void

flatten4dArrayTo(array, target)

Puts a nested 4d array into a one-dimensional target array

Parameters

Name Type Description
array Array
target Float32Array Float64Array

Returns

Void

flattenTo(array, target)

Puts a nested 1d, 2d, or 3d array into a one-dimensional target array

Parameters

Name Type Description
array Float32Array Uint16Array Uint8Array
target Float32Array

Returns

Void

splitArray(array, part)

Parameters

Name Type Description
array Array.<Number>
  • The array to split into chunks
part Number
  • elements in one chunk

Returns

Array.<Number>

An array of smaller chunks

linesToString(lines)

Parameters

Name Type Description
lines Array
  • An Array of strings

Returns

String

Single combined String, separated by \n

flattenFunctionToString(source, settings)

Parameters

Name Type Description
source String
settings Object

Returns

String

splitHTMLImageToRGB(gpu, image)

Parameters

Name Type Description
gpu GPU
image

Returns

Array

splitRGBAToCanvases(gpu, rgba, width, height)

A visual debug utility

Parameters

Name Type Description
gpu GPU
rgba
width
height

Returns

Array.<Object>