2017-03-20 18 views
0

TensorFlowでGPUの使用率を上げようとしていますが、サブグラフの実行が並列化されていないことがわかりました。これは、我々が興味を持っているものですTensorFlowでサブグラフの実行を並列化する方法は?

#specify two networks with random inputs as data 
with tf.device('/gpu:0'): 
    # first network 
    with tf.variable_scope('net1'): 
     tf_data1 = tf.random_normal(shape=[batch_size, input_dim]) 
     w1 = tf.get_variable('w1', shape=[input_dim, num_hidden], dtype=tf.float32) 
     b1 = tf.get_variable('b1', shape=[num_hidden], dtype=tf.float32) 
     l1 = tf.add(tf.matmul(tf_data1, w1), b1) 
     w2 = tf.get_variable('w2', shape=[num_hidden, output_dim], dtype=tf.float32) 
     result1 = tf.matmul(l1, w2) 

    # second network 
    with tf.variable_scope('net2'): 
     tf_data2 = tf.random_normal(shape=[batch_size, input_dim]) 
     w1 = tf.get_variable('w1', shape=[input_dim, num_hidden], dtype=tf.float32) 
     b1 = tf.get_variable('b1', shape=[num_hidden], dtype=tf.float32) 
     l1 = tf.add(tf.matmul(tf_data1, w1), b1) 
     w2 = tf.get_variable('w2', shape=[num_hidden, output_dim], dtype=tf.float32) 
     result2 = tf.matmul(l1, w2) 

:我々は2つのネットワークを作成

import tensorflow as tf 
import numpy as np 
from tensorflow.python.client import timeline 

#initialize graph 
tf.reset_default_graph() 
sess = tf.Session() 

# some parameters 
input_dim = 10000 
output_dim = 100 
num_hidden = 10000 
batch_size = 256 

まず:ここ は(tensorflowバージョンr.012)の例を働いている今

#the result that we are interested 
    out = tf.add(result1, result2) 

たちセッションを初期化して実行します。

sess.run(tf.global_variables_initializer()) #initialize variables 

# run out operation with trace 
run_metadata = tf.RunMetadata() 
sess.run(out, 
     options=tf.RunOptions(trace_level=tf.RunOptions.FULL_TRACE), 
     run_metadata=run_metadata) 

# write trace to file 
trace = timeline.Timeline(step_stats=run_metadata.step_stats) 
trace_file = open('trace.ctf.json', 'w') 
trace_file.write(trace.generate_chrome_trace_format()) 

は、我々は以下を参照してくださいすることができます

  • 最初MATMULがNET1のためであり、第二MATMULはNET2のためです。

質問:

1 - 親操作「」アウト「」を呼び出すときにこれらの操作が並行して処理されていない、なぜ結果1は、結果2に依存しないため?

2-私はグラフを定義するときに何か間違っていますか? documentationから、私はTensorflowが自動的に並行処理を行うことを理解します。

3このレベルで並行性を実現する方法はありますか?

おかげで

答えて

0

再(1)デフォルトでTensorFlowは、シングルGPUのストリームを使用しています。 CPU上でコードを実行すると、並列性が見えます。より良いGPU使用率を得るには、代わりにバッチサイズ/カーネルサイズを増やすことをお勧めします。

Re(2)グラフが正しく定義されているようです。自動並列化は、主にCPUに適用されます。

Re(3)TensorFlow GPUでマルチコンピュートストリームコードを実行する方法はありません。

関連する問題