Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
pi
Commits
c3a41aa3
Commit
c3a41aa3
authored
6 years ago
by
Neil Gershenfeld
Browse files
Options
Downloads
Patches
Plain Diff
wip
parent
15ed36d7
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#2740
passed
6 years ago
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TensorFlow/tf4pi.html
+64
-0
64 additions, 0 deletions
TensorFlow/tf4pi.html
with
64 additions
and
0 deletions
TensorFlow/tf4pi.html
0 → 100644
+
64
−
0
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>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment