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
7c95b688
Commit
7c95b688
authored
Dec 03, 2018
by
Neil Gershenfeld
Browse files
add 3
parent
ad3a74d7
Pipeline
#2738
passed with stage
in 1 second
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
TensorFlow/tf1pi.html
View file @
7c95b688
...
...
@@ -3,7 +3,7 @@
<script
src=
tf.min.js
></script>
<script>
//
// tfpi.html
// tf
1
pi.html
// Neil Gershenfeld 11/18/18
// Nikhil Thorat 11/20/18
// TensorFlow.js pi calculation benchmark
...
...
TensorFlow/tf2pi.html
View file @
7c95b688
...
...
@@ -3,7 +3,7 @@
<script
src=
tf.min.js
></script>
<script>
//
// tfpi.html
// tf
2
pi.html
// Neil Gershenfeld 11/18/18
// Nikhil Thorat 11/20/18
// TensorFlow.js pi calculation benchmark
...
...
TensorFlow/tf3pi.html
0 → 100644
View file @
7c95b688
<html>
<body>
<script
src=
tf.min.js
></script>
<script>
//
// tf3pi.html
// Neil Gershenfeld 11/18/18
// Ann Yuan 11/30/18
// TensorFlow.js pi calculation benchmark
// pi = 3.14159265358979323846
//
const
points
=
1
e7
const
a
=
tf
.
scalar
(
0.5
)
const
b
=
tf
.
scalar
(
0.75
)
const
c
=
tf
.
scalar
(
0.25
)
const
batchSize
=
100
;
const
computeSum
=
[];
for
(
let
i
=
1
;
i
<
batchSize
;
i
++
)
{
computeSum
.
push
(
`compute(i *
${
batchSize
}
. +
${
i
}
.)`
);
}
const
divMulIndexSubProgram
=
{
variableNames
:
[
'
a
'
,
'
b
'
,
'
c
'
],
outputShape
:
[
points
/
batchSize
],
userCode
:
`
float compute(float i) {
return a / ((i - b) * (i - c));
}
void main() {
float i = float(getOutputCoords());
setOutput(
${
computeSum
.
join
(
'
+
'
)}
);
}
`
}
function
divMulIndexSub
(
x
,
y
,
z
)
{
return
tf
.
ENV
.
backend
.
compileAndRun
(
divMulIndexSubProgram
,
[
a
,
b
,
c
]);
}
function
f
()
{
return
tf
.
sum
(
divMulIndexSub
(
b
,
c
,
a
)).
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
*
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