Skip to content
This repository has been archived by the owner on Aug 16, 2018. It is now read-only.

Commit

Permalink
Merge pull request gpujs#122 from abhisheksoni27/develop
Browse files Browse the repository at this point in the history
Closes gpujs#119 : Rename createKernels to createKernelMap
  • Loading branch information
robertleeplummerjr authored Jul 8, 2017
2 parents 8cc7a38 + 529f1c0 commit 820a0a9
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Or alternatively you can experiment around with the [kernel playground here](htt
* [Accepting Input](#accepting-input)
* [Graphical Output](#graphical-output)
* [Combining Kernels](#combining-kernels)
* [Create Kernels](#create-kernels)
* [Create Kernel Map](#create-kernel-map)
* [Adding Custom Functions](#adding-custom-functions)
* [Full API reference](#full-api-reference)
* [Automatically-built Documentation](#automatically-built-documentation)
Expand Down Expand Up @@ -168,13 +168,13 @@ superKernel(a, b, c);
```
This gives you the flexibility of using multiple transformations but without the performance penalty, resulting in a much much MUCH faster operation.

### Create kernels
### Create Kernel Map

Sometimes you want to do multiple math operations in one kernel, and save the output of each of those operations. An example is **Machine Learning** where the previous output is required for back propagation. To aid this there is the `createKernels` method.
Sometimes you want to do multiple math operations in one kernel, and save the output of each of those operations. An example is **Machine Learning** where the previous output is required for back propagation. To aid this there is the `createKernelMap` method.

#### object outputs
```js
const megaKernel = gpu.createKernels({
const megaKernel = gpu.createKernelMap({
addResult: function add(a, b) {
return a[this.thread.x] + b[this.thread.x];
},
Expand All @@ -190,7 +190,7 @@ megaKernel(a, b, c);
```
#### array outputs
```js
const megaKernel = gpu.createKernels([
const megaKernel = gpu.createKernelMap([
function add(a, b) {
return a[this.thread.x] + b[this.thread.x];
},
Expand Down
4 changes: 2 additions & 2 deletions src/backend/kernel-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ module.exports = class BaseKernel {
* @name addSubKernel
*
* @desc Add a sub kernel to the root kernel instance.
* This is what `createKernels` uses.
* This is what `createKernelMap` uses.
*
* @param {String} fnString - function (as a String) of the subKernel to add
*
Expand All @@ -305,7 +305,7 @@ module.exports = class BaseKernel {
* @name addSubKernelProperty
*
* @desc Add a sub kernel to the root kernel instance, indexed by a property name
* This is what `createKernels` uses.
* This is what `createKernelMap` uses.
*
* @param {String} property - property key for the subKernel
* @param {String} fnString - function (as a String) of the subKernel to add
Expand Down
6 changes: 3 additions & 3 deletions src/core/gpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GPU extends GPUCore {
* 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*
*
* @name createKernels
* @name createKernelMap
* @function
* @memberOf GPU#
*
Expand All @@ -117,7 +117,7 @@ class GPU extends GPUCore {
* @returns {Function} callable kernel function
*
* @example
* const megaKernel = gpu.createKernels({
* const megaKernel = gpu.createKernelMap({
* addResult: function add(a, b) {
* return a[this.thread.x] + b[this.thread.x];
* },
Expand All @@ -134,7 +134,7 @@ class GPU extends GPUCore {
* > [add, multiply]
*
*/
createKernels() {
createKernelMap() {
let fn;
let settings;
if (typeof arguments[arguments.length - 2] === 'function') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html>
<head>
<meta charset="utf-8">
<title>GPU.JS : Create Kernels</title>
<title>GPU.JS : Create Kernel Map</title>
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">

<!-- gpu.js scripts -->
Expand All @@ -12,6 +12,6 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../../src/features/create-kernels.js"></script>
<script src="../../src/features/create-kernel-map.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../../src/issues/114-create-kernels-run-second-time.js"></script>
<script src="../../src/issues/114-create-kernel-map-run-second-time.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="../../../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="../../src/issues/91-create-kernels-array.js"></script>
<script src="../../src/issues/91-create-kernel-map-array.js"></script>
</body>
</html>
6 changes: 3 additions & 3 deletions test/html/test-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<!-- features -->
<script src="../src/features/add-custom-function.js"></script>
<script src="../src/features/combine-kernels.js"></script>
<script src="../src/features/create-kernels.js"></script>
<script src="../src/features/create-kernel-map.js"></script>
<script src="../src/features/for-loop.js"></script>
<script src="../src/features/function-return.js"></script>
<script src="../src/features/get-canvas.js"></script>
Expand All @@ -36,9 +36,9 @@

<!-- bug issues -->
<script src="../src/issues/31-nested-var-declare-test.js"></script>
<script src="../src/issues/91-create-kernels-array.js"></script>
<script src="../src/issues/91-create-kernel-map-array.js"></script>
<script src="../src/issues/96-param-names.js"></script>
<script src="../src/issues/114-create-kernels-run-second-time.js"></script>
<script src="../src/issues/114-create-kernel-map-run-second-time.js"></script>
<script src="../src/issues/116-multiple-kernels-run-again.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function createPropertyKernels(mode, dimensions, canvas) {
var gpu = new GPU({mode: mode, canvas: canvas});
return gpu.createKernels({
return gpu.createKernelMap({
addResult: GPU.alias('adder', function add(v1, v2) {
return v1 + v2;
}),
Expand All @@ -15,7 +15,7 @@ function createPropertyKernels(mode, dimensions, canvas) {

function createArrayKernels(mode, dimensions, canvas) {
var gpu = new GPU({mode: mode, canvas: canvas});
return gpu.createKernels([
return gpu.createKernelMap([
function add(v1, v2) {
return v1 + v2;
},
Expand All @@ -35,7 +35,7 @@ function createKernel(mode, dimensions, canvas) {
}).setDimensions(dimensions);
}

QUnit.test( "createKernels object 1 dimension 1 length (auto)", function() {
QUnit.test( "createKernelMap object 1 dimension 1 length (auto)", function() {
var canvas = document.createElement('canvas');
var superKernel = createPropertyKernels(null, [1], canvas);
var kernel = createKernel(null, [1], canvas);
Expand All @@ -48,7 +48,7 @@ QUnit.test( "createKernels object 1 dimension 1 length (auto)", function() {
QUnit.assert.deepEqual(divideResult, [8]);
});

QUnit.test( "createKernels object 1 dimension 1 length (gpu)", function() {
QUnit.test( "createKernelMap object 1 dimension 1 length (gpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createPropertyKernels('gpu', [1], canvas);
var kernel = createKernel('gpu', [1], canvas);
Expand All @@ -61,7 +61,7 @@ QUnit.test( "createKernels object 1 dimension 1 length (gpu)", function() {
QUnit.assert.deepEqual(divideResult, [8]);
});

QUnit.test( "createKernels (cpu)", function() {
QUnit.test( "createKernelMap (cpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createPropertyKernels('cpu', [1], canvas);
var output = superKernel([2], [2], [0.5]);
Expand All @@ -73,7 +73,7 @@ QUnit.test( "createKernels (cpu)", function() {
QUnit.assert.deepEqual(divideResult, [8]);
});

QUnit.test( "createKernels array 1 dimension 1 length (auto)", function() {
QUnit.test( "createKernelMap array 1 dimension 1 length (auto)", function() {
var canvas = document.createElement('canvas');
var superKernel = createArrayKernels('gpu', [1], canvas);
var kernel = createKernel('gpu', [1], canvas);
Expand All @@ -86,7 +86,7 @@ QUnit.test( "createKernels array 1 dimension 1 length (auto)", function() {
QUnit.assert.deepEqual(divideResult, [8]);
});

QUnit.test( "createKernels array 1 dimension 1 length (gpu)", function() {
QUnit.test( "createKernelMap array 1 dimension 1 length (gpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createArrayKernels('gpu', [1], canvas);
var kernel = createKernel('gpu', [1], canvas);
Expand All @@ -99,7 +99,7 @@ QUnit.test( "createKernels array 1 dimension 1 length (gpu)", function() {
QUnit.assert.deepEqual(divideResult, [8]);
});

QUnit.test( "createKernels array 1 dimension 1 length (cpu)", function() {
QUnit.test( "createKernelMap array 1 dimension 1 length (cpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createArrayKernels('cpu', [1], canvas);
var output = superKernel([2], [2], [0.5]);
Expand All @@ -111,7 +111,7 @@ QUnit.test( "createKernels array 1 dimension 1 length (cpu)", function() {
QUnit.assert.deepEqual(divideResult, [8]);
});

QUnit.test( "createKernels object 1 dimension 5 length (auto)", function() {
QUnit.test( "createKernelMap object 1 dimension 5 length (auto)", function() {
var canvas = document.createElement('canvas');
var superKernel = createPropertyKernels(null, [5], canvas, true);
var kernel = createKernel(null, [5], canvas, true);
Expand All @@ -124,7 +124,7 @@ QUnit.test( "createKernels object 1 dimension 5 length (auto)", function() {
QUnit.assert.deepEqual(divideResult, [2, 2, 2, 2, 2]);
});

QUnit.test( "createKernels object 1 dimension 5 length (gpu)", function() {
QUnit.test( "createKernelMap object 1 dimension 5 length (gpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createPropertyKernels('gpu', [5], canvas);
var kernel = createKernel('gpu', [5], canvas);
Expand All @@ -137,7 +137,7 @@ QUnit.test( "createKernels object 1 dimension 5 length (gpu)", function() {
QUnit.assert.deepEqual(divideResult, [2, 2, 2, 2, 2]);
});

QUnit.test( "createKernels array (auto)", function() {
QUnit.test( "createKernelMap array (auto)", function() {
var canvas = document.createElement('canvas');
var superKernel = createArrayKernels(null, [5], canvas, true);
var kernel = createKernel(null, [5], canvas, true);
Expand All @@ -150,7 +150,7 @@ QUnit.test( "createKernels array (auto)", function() {
QUnit.assert.deepEqual(divideResult, [2, 2, 2, 2, 2]);
});

QUnit.test( "createKernels array (gpu)", function() {
QUnit.test( "createKernelMap array (gpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createArrayKernels('gpu', [5], canvas);
var kernel = createKernel('gpu', [5], canvas);
Expand All @@ -163,7 +163,7 @@ QUnit.test( "createKernels array (gpu)", function() {
QUnit.assert.deepEqual(divideResult, [2, 2, 2, 2, 2]);
});

QUnit.test( "createKernels array (cpu)", function() {
QUnit.test( "createKernelMap array (cpu)", function() {
var canvas = document.createElement('canvas');
var superKernel = createArrayKernels('cpu', [5], canvas);
var output = superKernel([1,2,3,4,5], [1,2,3,4,5], [1,2,3,4,5]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
QUnit.test( "Issue #114 - run createKernels the second time", function() {
QUnit.test( "Issue #114 - run createKernelMap the second time", function() {

const gpu = new GPU();
const A = [1, 2, 3, 4, 5];
const B = [1, 2, 3, 4, 5];
function add(a,b){
return a + b;
}
const kernels = gpu.createKernels([add],function(a, b){
const kernels = gpu.createKernelMap([add],function(a, b){
return a[this.thread.x] + b[this.thread.x];
}).setDimensions([5]);

Expand Down
2 changes: 1 addition & 1 deletion test/src/issues/116-multiple-kernels-run-again.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ QUnit.test( "Issue #116 - multiple kernels run again", function() {
const layerForward = [];

for (let i = 0; i < 2; i++) {
const kernels = gpu.createKernels([add],function(a, b){
const kernels = gpu.createKernelMap([add],function(a, b){
return add(a,b, gpu_threadX);
}).setDimensions([sizes[i + 1]]); // First: 5. Second: 1.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ QUnit.test( "Issue #91 - type detection (GPU only)", function() {
return sum;
}

var kernels = gpu.createKernels({
var kernels = gpu.createKernelMap({
multiplyResult: multiply
}, function (a, b) {
return multiply(b, a, this.thread.y, this.thread.x);
Expand Down
2 changes: 1 addition & 1 deletion test/src/issues/96-param-names.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ QUnit.test( "Issue #96 - param names (GPU only)", function() {
return sum;
}

var kernels = gpu.createKernels({
var kernels = gpu.createKernelMap({
multiplyResult: multiply
}, function (a, b) {
return multiply(b, a, this.thread.y, this.thread.x);
Expand Down

0 comments on commit 820a0a9

Please sign in to comment.