问题
From my understanding tensorflow makes a computational graph and then when I run the session it evaluates this graph and does what it can in parallel. How do I as a user make sure/check that tensorflow is doing stuff in parallel? Suppose I have the following code:
x = tf.placeholder()
y = x**2 + 123
z = 5*x/(x+2)
res = y+z
When I evaluate res, is y and z calculated in parallel? Also, from my testing it appears that building the graph inside a for loop breaks something because when I've tried to run the following code (but with more complex calculations) it does not appear to run in parallel:
x = tf.placeholder()
y_list = []
for i in range(100):
y_list.append(i*x + i)
res = np.sum(y_list)
I am running tensorflow with a GPU card and the time it takes to run the session depends linearly on the range of the for loop, which tells me that it does not evaluate the elements in y_list in parallel. How do I tell tensorflow to evaluate them in parallel?
来源:https://stackoverflow.com/questions/62169648/how-do-i-make-tensorflow-evaluate-tensors-in-parallel