Skip to content

Instantly share code, notes, and snippets.

@yaroslavvb
Created January 14, 2017 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save yaroslavvb/53052184e50cdfec35f0a127dd6df843 to your computer and use it in GitHub Desktop.
Save yaroslavvb/53052184e50cdfec35f0a127dd6df843 to your computer and use it in GitHub Desktop.
Simple XLA benchmark
# XLA compilation controlled by "compile_ops" option
# compile_ops=False: 4.39 sec
# compile_ops=True: 0.90 sec
import os
os.environ['CUDA_VISIBLE_DEVICES']=''
import tensorflow as tf
from tensorflow.contrib.compiler import jit
tf.reset_default_graph()
jit_scope = jit.experimental_jit_scope
with jit_scope(compile_ops=True):
N = 500*1000*1000
x = tf.Variable(tf.random_uniform(shape=(N,)))
y = 0.1*x*x*x*x*x-0.5*x*x*x*x+.25*x*x*x+.75*x*x-1.5*x-2
y0 = y[0]
import time
sess = tf.Session()
sess.run(tf.global_variables_initializer())
sess.run(y.op)
start_time = time.time()
print(sess.run(y0))
end_time = time.time()
print("%.2f sec"%(end_time-start_time))
@yehenrytian
Copy link

ok, I figured it out, just by change the source from compile_ops=True to compile_ops=False ^_^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment