Skip to content

Instantly share code, notes, and snippets.

@xilenteyex
Created December 27, 2018 00:44
Show Gist options
  • Save xilenteyex/066c5218802c16f4b987c7d086f6f4a5 to your computer and use it in GitHub Desktop.
Save xilenteyex/066c5218802c16f4b987c7d086f6f4a5 to your computer and use it in GitHub Desktop.
A toy example to check if we can force dependencies between completely unrelated operations
import tensorflow as tf
dim = 32
X1 = tf.random_uniform([dim, dim], 0, 10)
_X1 = tf.placeholder(dtype=tf.float32, shape=[dim, dim])
X2 = tf.random_uniform([dim, dim], 0, 10)
_X2 = tf.placeholder(dtype=tf.float32, shape=[dim, dim])
mul1 = tf.matmul(_X1, _X1)
mul2 = tf.matmul(_X2, _X2)
config_proto = tf.ConfigProto(graph_options=tf.GraphOptions(build_cost_model=1))
sess = tf.Session(config=config_proto)
sess.run(tf.global_variables_initializer())
X1_, X2_ = sess.run([X1, X2])
X_ = [X1_, X2_]
_X = [_X1, _X2]
run_metadata = tf.RunMetadata()
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE, output_partition_graphs=True)
W_ = sess.run([mul1, mul2], {_i: i_ for _i, i_ in zip(_X, X_)}, options=run_options, run_metadata=run_metadata)
trace = timeline.Timeline(step_stats=run_metadata.step_stats)
trace_file = open('timeline.ctf.json', 'w')
trace_file.write(trace.generate_chrome_trace_format())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment