Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
pub
pi
Commits
c3a41aa3
Commit
c3a41aa3
authored
Dec 04, 2018
by
Neil Gershenfeld
Browse files
wip
parent
15ed36d7
Pipeline
#2740
passed with stage
in 1 second
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
TensorFlow/tf4pi.html
0 → 100644
View file @
c3a41aa3
<html>
<body>
<script
src=
tf.min.js
></script>
<script>
//
// tf4pi.html
// Neil Gershenfeld 11/18/18
// Ann Yuan 12/4/18
// TensorFlow.js pi calculation benchmark
// pi = 3.14159265358979323846
//
const
points
=
1
e10
;
const
a
=
tf
.
scalar
(
0.5
)
const
b
=
tf
.
scalar
(
0.75
)
const
c
=
tf
.
scalar
(
0.25
)
const
indicesPerTexel
=
1000
;
const
outputSize
=
points
/
indicesPerTexel
;
const
divMulIndexSubProgram
=
{
variableNames
:
[
'
X
'
,
'
Y
'
,
'
Z
'
],
outputShape
:
[
outputSize
],
userCode
:
`
float compute(float i) {
return 0.5 / ((i - 0.75) * (i - 0.25));
}
void main() {
float i = float(getOutputCoords());
float sum = 0.;
for(int index=0; index<
${
indicesPerTexel
}
; index++) {
sum += compute(float(i *
${
indicesPerTexel
}
. + float(index)));
}
setOutput(sum);
}
`
}
function
divMulIndexSub
(
x
,
y
,
z
)
{
return
tf
.
ENV
.
backend
.
compileAndRun
(
divMulIndexSubProgram
,
[
x
,
y
,
z
]);
}
function
f
()
{
const
product
=
divMulIndexSub
(
b
,
c
,
a
);
return
tf
.
sum
(
product
).
dataSync
();
}
// Warmup
f
();
const
tstart
=
performance
.
now
()
/
1000
const
sum
=
f
();
const
tend
=
performance
.
now
()
/
1000
const
mflops
=
outputSize
*
5.0
*
indicesPerTexel
*
1
e
-
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>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment