mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +00:00
Merge branch 'master' of bitbucket.org:fuzzie/gpu.js
This commit is contained in:
commit
648bd70e8a
@ -1,26 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Test Case A</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="../src/gpu.js"></script>
|
||||
<script>
|
||||
var threadDim = [3];
|
||||
var blockDim = [1];
|
||||
|
||||
var f = GPU(function(a, b) {
|
||||
var ret = a[this.thread.x] + b[this.thread.x];
|
||||
return ret;
|
||||
}, threadDim, blockDim);
|
||||
|
||||
var a = [1, 2, 3];
|
||||
var b = [4, 5, 6];
|
||||
|
||||
var c = f(a, b);
|
||||
// c = [5, 7, 9];
|
||||
console.log(c);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@ -3,3 +3,7 @@
|
||||
+ demo : demo HTML files
|
||||
+ lib : External library JS files
|
||||
+ src : The source javascript
|
||||
+ test
|
||||
+ lib : the QUnit library
|
||||
+ html : the QUnit html page
|
||||
+ src : The unit test source code
|
||||
|
||||
29
src/gpu.js
29
src/gpu.js
@ -2,9 +2,16 @@
|
||||
///
|
||||
/// The parameter object contains the following sub parameters
|
||||
///
|
||||
/// + thread (default: [1024])
|
||||
/// + block (default: [1])
|
||||
/// + mode (default: null)
|
||||
/// +---------+---------------+---------------------------------------------------------------------------+
|
||||
/// | Name | Default value | Description |
|
||||
/// +---------+---------------+---------------------------------------------------------------------------+
|
||||
/// | thread | [1024] | Thread dimension array |
|
||||
/// | block | [1] | Block dimension array |
|
||||
/// | mode | null | The CPU / GPU configuration mode, "auto" / null. Has the following modes. |
|
||||
/// | | | + null / "auto" : Attempts to build GPU mode, else fallbacks |
|
||||
/// | | | + "gpu" : Attempts to build GPU mode, else fallbacks |
|
||||
/// | | | + "cpu" : Forces JS fallback mode only |
|
||||
/// +---------+---------------+---------------------------------------------------------------------------+
|
||||
///
|
||||
/// @param inputFunction The calling to perform the conversion
|
||||
/// @param paramObj The parameter configuration object
|
||||
@ -30,13 +37,23 @@ var GPU = function(kernal, paramObj) {
|
||||
//
|
||||
var thread = paramObj.thread || [1024];
|
||||
var block = paramObj.block || [1];
|
||||
var mode = paramObj.mode && paramObj.mode.toLowerCase();
|
||||
|
||||
//
|
||||
// Attempts to do the webclgl conversion, returns if success
|
||||
//
|
||||
var ret = GPU_jsToWebclgl(kernal, thread, block, paramObj);
|
||||
if(ret != null) {
|
||||
return ret;
|
||||
var ret = null;
|
||||
|
||||
if( mode == null || mode == "gpu" ) {
|
||||
// Attempts to do the conversion to webclgl
|
||||
if( (ret = GPU_jsToWebclgl(kernal, thread, block, paramObj)) != null) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// GPU only mode failed, return null
|
||||
if( mode == "gpu" ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
1851
src/grammar.jison
Normal file
1851
src/grammar.jison
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,12 +1,25 @@
|
||||
QUnit.test( "basic_sum_AB (auto)", function( assert ) {
|
||||
function basic_sum_AB_test( assert, mode ) {
|
||||
var f = GPU(function(a, b) {
|
||||
var ret = a[this.thread.x] + b[this.thread.x];
|
||||
return ret;
|
||||
}, {
|
||||
thread : [3],
|
||||
block : [1]
|
||||
block : [1],
|
||||
mode : mode
|
||||
});
|
||||
|
||||
assert.ok( f !== null, "function generated test");
|
||||
assert.deepEqual(f( [1, 2, 3], [4, 5, 6] ), [5, 7, 9], "basic sum function test");
|
||||
}
|
||||
|
||||
QUnit.test( "basic_sum_AB (auto)", function( assert ) {
|
||||
basic_sum_AB_test(assert, null);
|
||||
});
|
||||
|
||||
QUnit.test( "basic_sum_AB (GPU)", function( assert ) {
|
||||
basic_sum_AB_test(assert, "gpu");
|
||||
});
|
||||
|
||||
QUnit.test( "basic_sum_AB (CPU)", function( assert ) {
|
||||
basic_sum_AB_test(assert, "cpu");
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user