use*_*229 9 cpu performance gpu tensorflow
请原谅这个问题的广泛性.也许一旦我知道更多,也许我可以更具体地问.
我有性能敏感的tensorflow代码.从对gpu编程知之甚少的人的角度来看,我想知道哪些指南或策略是优化我的代码的"好开始".(单个gpu)
或许甚至可以读出每个张量流操作花了多长时间...
我有一个模糊的理解
可能还有其他常见因素在起作用,我不知道..
Oli*_*rot 18
我想提供一个更完整的答案,关于如何使用Timeline对象来获取图中每个节点的执行时间:
sess.run()但指定参数options和run_metadatarun_metadata.step_stats数据创建时间轴对象这是示例代码:
import tensorflow as tf
from tensorflow.python.client import timeline
x = tf.random_normal([1000, 1000])
y = tf.random_normal([1000, 1000])
res = tf.matmul(x, y)
# Run the graph with full trace option
with tf.Session() as sess:
run_options = tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE)
run_metadata = tf.RunMetadata()
sess.run(res, options=run_options, run_metadata=run_metadata)
# Create the Timeline object, and write it to a json
tl = timeline.Timeline(run_metadata.step_stats)
ctf = tl.generate_chrome_trace_format()
with open('timeline.json', 'w') as f:
f.write(ctf)
Run Code Online (Sandbox Code Playgroud)
然后,您可以打开Google Chrome,转到该页面chrome://tracing并加载该timeline.json文件.你应该这样: