1
我正在写一个非常简单的tensorflow程序,启用了XLA
。基本上它是这样的:Tensorflow XLA变慢了吗?
import tensorflow as tf
def ChainSoftMax(x, n)
tensor = tf.nn.softmax(x)
for i in range(n-1):
tensor = tf.nn.softmax(tensor)
return tensor
config = tf.ConfigProto()
config.graph_options.optimizer_options.global_jit_level = tf.OptimizerOptions.ON_1
input = tf.placeholder(tf.float32, [1000])
feed = np.random.rand(1000).astype('float32')
with tf.Session(config=config) as sess:
res = sess.run(ChainSoftMax(input, 2000), feed_dict={input: feed})
基本想法是,看看是否XLA可融合的softmax
链一起以避免多个内核启动。使用XLA时,上述程序比装有GPU卡的机器上的XLA慢两倍。在我的gpu配置文件中,我看到XLA生成了大量名为“reduce_xxx
”和“fusion_xxx
”的内核,这似乎压倒了整个运行时间。任何人都知道这里发生了什么?