Skip to content

Instantly share code, notes, and snippets.

@yaroslavvb
Created October 28, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaroslavvb/a930aab500e7e42f77af443fd40cf96a to your computer and use it in GitHub Desktop.
Save yaroslavvb/a930aab500e7e42f77af443fd40cf96a to your computer and use it in GitHub Desktop.
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