mirror of
https://github.com/gpujs/gpu.js.git
synced 2026-01-25 16:08:02 +00:00
89 lines
2.3 KiB
HTML
89 lines
2.3 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>GPU.JS! : CUDA for the browser, in JS</title>
|
|
<link href="bootstrap.min.css" rel="stylesheet">
|
|
<script src="jquery.js"></script>
|
|
<script src="bootstrap.min.js"></script>
|
|
|
|
<!-- gpu.js scripts -->
|
|
<script src="../bin/gpu.js"></script>
|
|
<script src="gpu-demo.js"></script>
|
|
|
|
<!-- JS Highlight code -->
|
|
<link rel="stylesheet" href="./highlight/styles/default.css">
|
|
<script src="./highlight//highlight.pack.js"></script>
|
|
<script>$(function() { hljs.initHighlightingOnLoad(); } );</script>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="page-header">
|
|
<h1>GPU.js! <small>CUDA for the Browser</small></h1>
|
|
</div>
|
|
|
|
<h2>Argument startup Initialiser</h2>
|
|
<pre><code class="javascript">//
|
|
// Argument Startup code
|
|
//
|
|
var _length = 2048;
|
|
var set_a = [];
|
|
var set_b = [];
|
|
for(var n = 0; n < _length; n++) {
|
|
var randA = Math.random()*100.0;
|
|
var randB = Math.random()*100.0;
|
|
set_a.push(randA);
|
|
set_b.push(randB);
|
|
}</code></pre>
|
|
|
|
<h2>GPU.JS benchmarkCode</h2>
|
|
<pre><code class="javascript">//
|
|
// GPU.JS setup code
|
|
//
|
|
// mode = "auto" / "gpu" / "cpu".
|
|
// For automatic detection, GPU only mode, or CPU only mode
|
|
//
|
|
function benchmarkCode(mode) {
|
|
var runFunction = GPU(function(a, b) {
|
|
var res = 0.0;
|
|
var i = 0.0;
|
|
for(i = 0.0; i < 500000; ++i) {
|
|
res += Math.sqrt( a[this.thread.x] * b[this.thread.x] );
|
|
}
|
|
|
|
return res;
|
|
}, {
|
|
dimensions : [2048],
|
|
mode : mode
|
|
});
|
|
|
|
// Execute the compiled GPU.JS script
|
|
c = runFunction(set_a, set_b);
|
|
}</code></pre>
|
|
|
|
<h2>GPU.JS benchmark run</h2>
|
|
<pre><code class="javascript">bench(function(){
|
|
setupBenchCode('gpu');
|
|
}, 10, [], this);</code></pre>
|
|
<div class="result">
|
|
<div class="cpu_result_gpu alert alert-warning" role="alert">GPU: Click Run!</div>
|
|
</div>
|
|
|
|
<h2>GPU.JS (CPU fallback) benchmark run</h2>
|
|
<pre><code class="javascript">bench(function(){
|
|
setupBenchCode('cpu');
|
|
}, 10, [], this);</code></pre>
|
|
<div class="result">
|
|
<div class="cpu_result_cpu alert alert-warning" role="alert">CPU: Click Run!</div>
|
|
</div>
|
|
<div class="result">
|
|
<div class="cpu_result_ovl alert alert-warning" role="alert">Percentage Gain: Click Run!</div>
|
|
</div>
|
|
|
|
<script>
|
|
</script>
|
|
<button class="run_btn btn btn-default" onclick="runBenchmark();">Run!</button>
|
|
</div>
|
|
</body>
|
|
</html>
|