How to add external header files during bazel / tensorflow build

I am trying to add an external header file (e.g. OpenCL header file) for some experiments for tensor flow. I tried adding this to the BUILD file in the 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 

I also created a soft link in this directory to locate these header files from the OpenCL driver (also under tensor / third_party) (e.g. ln -s / opt / opencl /), but it still complains that it did not find that the header file .

If I add an external header file directly (e.g. / opt / opencl / CL /), it complains that external files cannot be included (or some such things).

I do not have a root password to copy these header files to / usr / include /.

Can someone explain exactly how to make external header files in a tensor stream to create?

Thanks for any quick help.

+5
source share
3 answers

I ran into a similar problem when I built TensorFlow with Intel MKL and had to add MKL headers. My solution is this:

  • Create a symlink to your headers in the third_party folder, for example:

     <your tensorflow folder>/third_party/opencl/include -> /opt/OpenCL/include 

    with the command:

     ln -s /opt/OpenCL/include <your tensorflow folder>/third_party/opencl 
  • Create a simple BUILD file in the <your tensorflow folder>/third_party/opencl :

     cc_library( name = "opencl", hdrs = glob(["include/CL/*.h"]), visibility = ["//visibility:public"], ) 
  • Add deps to the target library:

     cc_library( name = "all_kernels", visibility = ["//visibility:public"], copts = tf_copts() + ["-Ithird_party/opencl/include"], deps = [ "//third_party/opencl", ... ], ) 
  • Remember to add compiler options either to the target library, as shown above, or as a flag for bazel:

      bazel build --copt="-Ithird_party/opencl/include" ... 
+2
source

You must add files depending on this rule.

IIUC, you have the following structure:

 tensorflow/ BUILD WORKSPACE tensorflow/ core/ BUILD third_party/ include -> /opt/opencl/CL # or something like that 

You want to open .h files so that Bazel can understand / depend, so open the tensorflow/BUILD file and add the following:

 cc_library( name = "opencl", hdrs = glob(["third_party/include/*.h"]), visibility = ["//visibility:public"], ) 

This creates a C ++ library of .h files in the third_party / include file, on which you can depend from anywhere in the source tree.

Now go to your tensorflow/core/BUILD file and add the dependency to cc_library:

 cc_library( name = "all_kernels", visibility = ["//visibility:public"], copts = tf_copts() + ["-Ithird_party/include"], deps = [ "//:opencl", # plus any other deps ], ) 

Configuring cops just changes flags when gcc starts. Adding //:opencl to the dependencies tells Bazel to make these files available when gcc starts.

+1
source

Bazel is trying to be very strict to make sure that its assemblies contain only files that he knows about, in order to try to make sure they are playable. Unfortunately, this can complicate the experiment. The correct way to solve the problem is to create a BUILD file and a rule for the headers you want to include. You may be able to hack something by hanging sticks with the created base, but I do not recommend it.

0
source

All Articles