如何在bazel/tensorflow构建期间添加外部头文件 [英] How to add external header files during bazel/tensorflow build
问题描述
我正在尝试添加外部头文件(如OpenCL头文件)以进行一些针对tensorflow的实验.我试图将其添加到tensorflow/core/BUILD文件下的BUILD文件中:
I am trying to add external header file (like OpenCL header file) for some experimentation for tensorflow. I tried to add this into BUILD file under tensorflow/core/BUILD file:
# This includes implementations of all kernels built into TensorFlow.
cc_library(
name = "all_kernels",
visibility = ["//visibility:public"],
copts = tf_copts() + ["-Ithird_party/include"], <==== this is the line I added
我还在此目录中也创建了一个软链接,这些链接也来自OpenCL驱动程序(在tensorflow/third_party下)这些头文件的位置(例如ln -s/opt/opencl/),但它仍然抱怨找不到它头文件.
I have also created a softlink in this directory to the location of these header files from OpenCL driver (under tensorflow/third_party) too (like ln -s /opt/opencl/ ) but it still complains that it has not found that header file.
如果我直接添加外部头文件(如/opt/opencl/CL/),它会抱怨无法包含外部文件(或类似的东西).
If I add external header file directly (like /opt/opencl/CL/) it complains that external files cannot be included (or some such thing).
我也没有root密码将这些头文件复制到/usr/include/.
I do not have root password to copy these header files into /usr/include/ too.
有人可以解释如何将外部头文件准确地放入tensorflow进行构建吗?
Can someone explain how exactly to do external header files into tensorflow for building?
感谢您的快速帮助.
推荐答案
当我使用Intel MKL构建TensorFlow并不得不添加MKL标头时,我遇到了类似的问题.我的解决方案如下:
I've faced with the similar problem when I built TensorFlow with Intel MKL and had to add MKL headers. My solution is the following:
-
在您的标头中创建指向第三方文件夹的符号链接,例如:
Create symlink to your headers into third_party folder, like:
<your tensorflow folder>/third_party/opencl/include -> /opt/OpenCL/include
使用命令:
ln -s /opt/OpenCL/include <your tensorflow folder>/third_party/opencl
在<your tensorflow folder>/third_party/opencl
文件夹中创建简单的BUILD文件:
Create simple BUILD file into <your tensorflow folder>/third_party/opencl
folder:
cc_library(
name = "opencl",
hdrs = glob(["include/CL/*.h"]),
visibility = ["//visibility:public"],
)
将deps添加到目标库中:
Add deps into target library:
cc_library(
name = "all_kernels",
visibility = ["//visibility:public"],
copts = tf_copts() + ["-Ithird_party/opencl/include"],
deps = [
"//third_party/opencl",
...
],
)
别忘了将编译器选项添加到目标库中,如上图所示,或者只是将其标记为bazel:
Don't forget to add compiler options either into target library as shown above or just as a flag to bazel:
bazel build --copt="-Ithird_party/opencl/include" ...
这篇关于如何在bazel/tensorflow构建期间添加外部头文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!