mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-18 16:04:10 +00:00
Fallback mode handling
This commit is contained in:
parent
266e9dae1b
commit
df50c42df5
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user