Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
88 lines (79 loc) · 2.3 KB

File metadata and controls

88 lines (79 loc) · 2.3 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!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>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.