Example #1
0
 def after_run(self, run_context, run_values):
   self._counter += 1
   if self.should_save():
     timeline = Timeline(step_stats=run_meta.step_stats)
     ctf = timeline.generate_chrome_trace_format(show_memory=True)
     with open(self.get_ctf(), "w+") as f:
       f.write(ctf)
Example #2
0
# from https://github.com/tensorflow/tensorflow/issues/7251
import os
os.environ["CUDA_VISIBLE_DEVICES"]="0"

import tensorflow as tf
from tensorflow.python.client.timeline import Timeline

with tf.device("/gpu:0"):
    x = tf.ones(100, name="x")
    idxs = tf.range(100)

    for i in range(10):
        y = tf.identity(x, name="identity-"+str(i))
        x = tf.dynamic_stitch([idxs, idxs], [x, y], name="stitch-"+str(i))

config = tf.ConfigProto(graph_options=tf.GraphOptions(optimizer_options=tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0)))
sess = tf.InteractiveSession(config=config)
metadata = tf.RunMetadata()
sess.run(x, options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE,
                                  output_partition_graphs=True),
         run_metadata=metadata)

timeline = Timeline(metadata.step_stats)
with open("dynamic_stitch_gpu_profile.json", "w") as f:
    f.write(timeline.generate_chrome_trace_format())
with open("dynamic_stitch_gpu_profile.pbtxt", "w") as f:
    f.write(str(metadata))
Example #3
0
File: io.py Project: SijanC147/Msc
def export_run_metadata(run_metadata, path):
    file_name = datetime.now().strftime("%Y%m%d-%H%M%S") + ".json"
    time_line = Timeline(run_metadata.step_stats)  # pylint: disable=E1101
    ctf = time_line.generate_chrome_trace_format()
    write_zippped_file(path=join(path, file_name), data=ctf)
Example #4
0
# from https://github.com/tensorflow/tensorflow/issues/7251
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

import tensorflow as tf
from tensorflow.python.client.timeline import Timeline

with tf.device("/gpu:0"):
    x = tf.ones(100, name="x")
    idxs = tf.range(100)

    for i in range(10):
        y = tf.identity(x, name="identity-" + str(i))
        x = tf.dynamic_stitch([idxs, idxs], [x, y], name="stitch-" + str(i))

config = tf.ConfigProto(graph_options=tf.GraphOptions(
    optimizer_options=tf.OptimizerOptions(opt_level=tf.OptimizerOptions.L0)))
sess = tf.InteractiveSession(config=config)
metadata = tf.RunMetadata()
sess.run(x,
         options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE,
                               output_partition_graphs=True),
         run_metadata=metadata)

timeline = Timeline(metadata.step_stats)
with open("dynamic_stitch_gpu_profile.json", "w") as f:
    f.write(timeline.generate_chrome_trace_format())
with open("dynamic_stitch_gpu_profile.pbtxt", "w") as f:
    f.write(str(metadata))
# gpu_opt = tf.GPUOptions(per_process_gpu_memory_fraction=0.75)
# conf = tf.ConfigProto(gpu_options=gpu_opt)
# session = tf.InteractiveSession(config=conf)

session = tf.InteractiveSession()

session.run(tf.initialize_all_variables())

run_metadata = tf.RunMetadata()

startTime = time.time()

for index in range(2):
    if index == 1:  #reset start time due to GPU overhead
        startTime = time.time()

    res = session.run(
        reduced,
        options=tf.RunOptions(trace_level=tf.RunOptions.SOFTWARE_TRACE),
        run_metadata=run_metadata)

    print(res)

    currentTime = time.time()
    print(index, "TotalTime", (currentTime - startTime))

    trace = Timeline(step_stats=run_metadata.step_stats)

trace_file = open('timeline.ctf.json', 'w')
trace_file.write(trace.generate_chrome_trace_format())