Created
October 28, 2016 02:39
-
-
Save yaroslavvb/a930aab500e7e42f77af443fd40cf96a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from numpy.testing.utils import nulp_diff | |
import time | |
n = 1024 | |
v1 = tf.Variable(tf.ones_initializer((n, n))) | |
v2 = tf.Variable(tf.ones_initializer((n, n))) | |
op = v1.assign(tf.matmul(v1, v2)/n).op | |
norm = tf.reduce_sum(v1) | |
sess = tf.Session() | |
sess.run(tf.initialize_all_variables()) | |
sess.run(op) # pre-warming | |
start_time = time.time() | |
sess.run(tf.initialize_all_variables()) | |
num_iters = 10 | |
start = time.time() | |
for i in range(num_iters): | |
sess.run(op) | |
elapsed = time.time()-start | |
error = nulp_diff(n**2, sess.run(norm)) | |
total_ops = num_iters*(n**3+n**2*(n-1)) | |
print("%.2f G ops/sec, error %.2f"%(total_ops/elapsed/10**9,error)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment