Update SIMD version of life demo.

- add benchmark option
- add multi-thread support
- convert from c to cpp (inc. ppapi)
BUG=NONE
TEST=this is a demo

R=binji@chromium.org

Review URL: https://codereview.chromium.org/451883002

Cr-Commit-Position: refs/heads/master@{#288473}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288473 0039d316-1c4b-4281-b951-d872f2087c98
parent 06209e69
......@@ -2,17 +2,20 @@
'TOOLS': ['pnacl'],
'TARGETS': [
{
'NAME' : 'life_simd',
'NAME' : 'life',
'TYPE' : 'main',
'SOURCES' : [
'life.c',
'life.cc',
],
'DEPS': ['ppapi_simple', 'nacl_io'],
'LIBS': ['ppapi_simple', 'nacl_io', 'ppapi_cpp', 'ppapi', 'pthread']
'LIBS': ['ppapi_simple', 'nacl_io', 'sdk_util', 'ppapi_cpp', 'ppapi', 'pthread']
}
],
'DATA': [
'example.js'
],
'DEST': 'examples/demo',
'NAME': 'life_simd',
'TITLE': "Conway's Life (SIMD version)",
'TITLE': "Conway's Life",
'GROUP': 'Demo'
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function moduleDidLoad() {
}
// Add event listeners after the NaCl module has loaded. These listeners will
// forward messages to the NaCl module via postMessage()
function attachListeners() {
document.getElementById('benchmark').addEventListener('click',
function() {
common.naclModule.postMessage({'message' : 'run_benchmark'});
common.updateStatus('BENCHMARKING... (please wait)');
});
document.getElementById('simd').addEventListener('click',
function() {
var simd = document.getElementById('simd');
common.naclModule.postMessage({'message' : 'set_simd',
'value' : simd.checked});
});
document.getElementById('multithread').addEventListener('click',
function() {
var multithread = document.getElementById('multithread');
common.naclModule.postMessage({'message' : 'set_threading',
'value' : multithread.checked});
});
document.getElementById('large').addEventListener('click',
function() {
var large = document.getElementById('large');
var nacl = document.getElementById('nacl_module');
nacl.setAttribute('width', large.checked ? 1280 : 640);
nacl.setAttribute('height', large.checked ? 1024 : 640);
});
}
// Handle a message coming from the NaCl module.
function handleMessage(message_event) {
if (message_event.data.message == 'benchmark_result') {
// benchmark result
var result = message_event.data.value;
console.log('Benchmark result:' + result);
result = (Math.round(result * 1000) / 1000).toFixed(3);
document.getElementById('result').textContent =
'Result: ' + result + ' seconds';
common.updateStatus('SUCCESS');
}
}
......@@ -10,12 +10,24 @@ found in the LICENSE file.
<meta http-equiv="Expires" content="-1">
<title>{{title}}</title>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="example.js"></script>
</head>
<body data-width="640" data-height="640" {{attrs}}>
<h1>{{title}}</h1>
<h2>Status: <code id="statusField">NO-STATUS</code></h2>
<!-- The NaCl plugin will be embedded inside the element with id "listener".
See common.js.-->
<div>
Conway's game of life is a cellular automaton by British mathematician John
Horton Conway. Use the touch screen or mouse pointer to interact with the
simulation.
<br>
<input type="checkbox" id="simd" checked >Use SIMD<br>
<input type="checkbox" id="multithread" checked >Use multiple threads<br>
<input type="checkbox" id="large" >Use large field<br>
<input type="submit" id="benchmark" value="Run Benchmark">
<label id="result" name="result"> </label>
</div>
<div id="listener"></div>
</body>
</html>
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment