compilation - 如何在 TensorFlow 中从 XLA 获取 LLVM IR 转储?

标签 compilation tensorflow

我正在尝试获取 TensorFlow 中 XLA 编译器生成的 LLVM IR。我知道整个 LLVM 上下文包含在 llvm_module 对象中。然后使用文件中 Compile() 函数中的实用函数 llvm_ir::DumpModuleToString(*llvm_module) 函数将其转换为字符串: //tensorflow/compiler/xla/service/cpu.cpu_compiler.cc

但我一直在尝试使用 tensorflow/core/logging.h 中的 VLOG(2) 来记录它。没有显示日志。但是,其他文件中剩余的 VLOG(2) 语句会记录在我的 Python 运行中。

>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
2017-03-10 22:36:43.226843: I tensorflow/compiler/xla/service/platform_util.cc:58] platform Host present with 8 visible devices
2017-03-10 22:36:43.227931: I tensorflow/compiler/xla/service/service.cc:183] XLA service 0x2821510 executing computations on platform Host. Devices:
2017-03-10 22:36:43.227951: I tensorflow/compiler/xla/service/service.cc:191]   StreamExecutor device (0): <undefined>, <undefined>
b'Hello, TensorFlow!'

最佳答案

[仅供引用,我无法发表评论,因为我刚刚加入,显然还没有声誉。]

首先,请务必阅读本文,包括带星号的蓝色框。特别注意,为整个 session 打开 XLA 目前仅对 GPU 执行 JIT,而不是对 CPU 执行 JIT。 https://www.tensorflow.org/performance/xla/jit

现在假设您已正确设置所有内容。您的示例中的程序不会使用 XLA 进行编译,原因有两个:

  1. 正如 @mrry 所指出的,XLA 不处理字符串。
  2. 即使您将字符串替换为数字,您仍然看不到任何 IR 转储,因为它只是一个常量,XLA 会将其常量折叠起来。

在评论中您提到在 mnist_softmax 上运行,大概遵循上面链接上的说明。如果您确实在 CPU 上编译和运行,那么唯一剩下的问题是使用 VLOG(2)。仅当您设置命令行标志将其打开时,VLOG 才会启用。

因此,请尝试将 VLOG(2) 替换为 LOG(INFO),您应该会在日志中看到 IR 转储。

关于compilation - 如何在 TensorFlow 中从 XLA 获取 LLVM IR 转储?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42724165/

相关文章:

c++ - 如果位于头文件中的 "heavy"函数没有标记为 'inline' ,那么它的代码被编译到哪里?

python - Keras fit_generator() - 时间序列的批处理如何工作?

python - 使用 TensorFlow.js 加载 Keras 模型时,"The first layer in a Sequential model must get an ` inputShape ` or ` batchInputShape ` argument."

python - Keras 中的自定义 Hebbian 层实现 - 输入/输出暗淡和横向节点连接

访问使用 OpenCV 的 C++ 共享库的 Java 程序

c - 为什么我的 include 指令在 gcc 中不起作用?

c++ - 链接器如何知道两个源文件中哪个是主文件,哪个包含函数定义?

java - 出现编译错误: warning: [unchecked] unchecked call to add(E) as a member of the raw type ArrayList

indexing - Tensorflow 相当于 Numpy 的 array[indices] = scalar

python-3.x - 在 ANN 模型中加载 pickle 时接收错误