diff --git a/TensorFlow/tf1pi.html b/TensorFlow/tf1pi.html new file mode 100644 index 0000000000000000000000000000000000000000..e8e0513a2c741e24dc6652d7775d8266b24a48bd --- /dev/null +++ b/TensorFlow/tf1pi.html @@ -0,0 +1,34 @@ +<html> +<body> +<script src=tf.min.js></script> +<script> +// +// tfpi.html +// Neil Gershenfeld 11/18/18 +// Nikhil Thorat 11/20/18 +// TensorFlow.js pi calculation benchmark +// pi = 3.14159265358979323846 +// +const points = 1e7 +const a = tf.scalar(0.5) +const b = tf.scalar(0.75) +const c = tf.scalar(0.25) + +function f() { + const index = tf.range(1,points) + return tf.sum(tf.div(a,tf.mul(index.sub(b),index.sub(c)))).dataSync(); +} +// Warmup +f(); + +const tstart = performance.now()/1000 +const sum = f(); +const tend = performance.now()/1000 +const mflops = points*5.0*1e-6/(tend-tstart); +document.write('pi: '+sum.toString()) +document.write('<br>') +document.write('time: '+(tend-tstart)+'s') +document.write('<br>') +document.write('estimated MFlops: '+mflops) +</script> + diff --git a/TensorFlow/tf2pi.html b/TensorFlow/tf2pi.html new file mode 100644 index 0000000000000000000000000000000000000000..f1c5097686501792e3fa36b57725aa9307cd357b --- /dev/null +++ b/TensorFlow/tf2pi.html @@ -0,0 +1,53 @@ +<html> +<body> +<script src=tf.min.js></script> +<script> +// +// tfpi.html +// Neil Gershenfeld 11/18/18 +// Nikhil Thorat 11/20/18 +// TensorFlow.js pi calculation benchmark +// pi = 3.14159265358979323846 +// +const points = 1e7 +const a = tf.scalar(0.5) +const b = tf.scalar(0.75) +const c = tf.scalar(0.25) + +const indexSubProgram = { + variableNames: ['X'], + outputShape: [points], + userCode: ` + void main() { + float x = getX(); + int i = getOutputCoords(); + float value = float(i) - x; + setOutput(value); + } + ` +} +function indexSub(x) { + return tf.ENV.backend.compileAndRun(indexSubProgram, [x]); +} + +function f(index) { + // const index = tf.range(1,points) + return tf.sum(tf.div(a,tf.mul(indexSub(b),indexSub(c)))).dataSync(); +} + +// Warmup +f() + +const tstart = performance.now()/1000 +//const sum = tf.range(1,points) +const sum = f() +//const sum = f(); +const tend = performance.now()/1000 +const mflops = points*5.0*1e-6/(tend-tstart); +document.write('pi: '+sum.toString()) +document.write('<br>') +document.write('time: '+(tend-tstart)+'s') +document.write('<br>') +document.write('estimated MFlops: '+mflops) +</script> +