Use or support Intel compiler in Bazel

1,015 views
Skip to first unread message

Sunjung Lee

unread,
Sep 18, 2016, 1:35:14 AM9/18/16
to bazel-discuss
Hi, I want to use Intel compiler(icpc or icc) in Bazel because I want to use a lot of options with Intel machine.

But, CROSSTOOL didn't work and I don't know what I set the entire job.

I use CentOs 7.2 and default compiler is gcc 4.8.3

If anyone know about that, Please tell me.

Thank you for reading!

Thiago Farina

unread,
Sep 19, 2016, 3:09:04 AM9/19/16
to Sunjung Lee, bazel-discuss


On Sunday, September 18, 2016, Sunjung Lee <sunjun...@gmail.com> wrote:
Hi, I want to use Intel compiler(icpc or icc) in Bazel because I want to use a lot of options with Intel machine.

But, CROSSTOOL didn't work and I don't know what I set the entire job.

Could you post what didn't work? What changes did you make there?

Could autoconfiguration tool help you here?
 


--
Thiago Farina

Message has been deleted

Sunjung Lee

unread,
Sep 20, 2016, 4:30:42 AM9/20/16
to bazel-discuss, sunjun...@gmail.com

In the link(https://github.com/bazelbuild/bazel/issues/629), people say "Try to modify tools/cpp/CROSSTOOL"

 

So, I just modify CROSSTOOL with below process

 


First, I downloaded bazel source file(git clone https://github.com/google/bazel/)


Second, I edited the CROSSTOOL file in [BAZEL_HOME]/tools/cpp/CROSSTOOL(Because I use CentOs 7.2, I just edit local_linux)


toolchain {
  abi_version: "local"
  abi_libc_version: "local"
  builtin_sysroot: ""
  compiler: "compiler"
  host_system_name: "local"
  needsPic: true
  supports_gold_linker: false
  supports_incremental_linker: false
  supports_fission: false
  supports_interface_shared_objects: false
  supports_normalizing_ar: false
  supports_start_end_lib: false
  target_libc: "local"
  target_cpu: "local"
  target_system_name: "local"
  toolchain_identifier: "local_linux"

  tool_path { name: "ar" path: "/usr/bin/ar" }
  tool_path { name: "compat-ld" path: "/usr/bin/ld" }
  tool_path { name: "cpp" path: "/usr/bin/cpp" }
  tool_path { name: "dwp" path: "/usr/bin/dwp" }
- tool_path { name: "gcc" path: "/usr/bin/gcc" }
+ tool_path { name: "gcc" path: "/usr/bin/icpc" }
  cxx_flag: "-std=c++0x"
  linker_flag: "-lstdc++"
  linker_flag: "-B/usr/bin/"
 
  # TODO(bazel-team): In theory, the path here ought to exactly match the path
  # used by gcc. That works because bazel currently doesn't track files at
  # absolute locations and has no remote execution, yet. However, this will need
  # to be fixed, maybe with auto-detection?
- cxx_builtin_include_directory: "/usr/lib/gcc"
+ cxx_builtin_include_directory: "/opt/intel/compilers_and_libraries_2016.3.210/linux/bin/intel64"
  cxx_builtin_include_directory: "/usr/local/include"
  cxx_builtin_include_directory: "/usr/include"
  tool_path { name: "gcov" path: "/usr/bin/gcov" }

  # C(++) compiles invoke the compiler (as that is the one knowing where
  # to find libraries), but we provide LD so other rules can invoke the linker.
  tool_path { name: "ld" path: "/usr/bin/ld" }

  tool_path { name: "nm" path: "/usr/bin/nm" }
  tool_path { name: "objcopy" path: "/usr/bin/objcopy" }
  objcopy_embed_flag: "-I"
  objcopy_embed_flag: "binary"
  tool_path { name: "objdump" path: "/usr/bin/objdump" }
  tool_path { name: "strip" path: "/usr/bin/strip" }

  # Anticipated future default.
  unfiltered_cxx_flag: "-no-canonical-prefixes"
  unfiltered_cxx_flag: "-fno-canonical-system-headers"

  # Make C++ compilation deterministic. Use linkstamping instead of these
  # compiler symbols.
  unfiltered_cxx_flag: "-Wno-builtin-macro-redefined"
  unfiltered_cxx_flag: "-D__DATE__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIMESTAMP__=\"redacted\""
  unfiltered_cxx_flag: "-D__TIME__=\"redacted\""

  # Security hardening on by default.
  # Conservative choice; -D_FORTIFY_SOURCE=2 may be unsafe in some cases.
  # We need to undef it before redefining it as some distributions now have
  # it enabled by default.
  compiler_flag: "-U_FORTIFY_SOURCE"
  compiler_flag: "-D_FORTIFY_SOURCE=1"
  compiler_flag: "-fstack-protector"
  linker_flag: "-Wl,-z,relro,-z,now"

  # Enable coloring even if there's no attached terminal. Bazel removes the
  # escape sequences if --nocolor is specified. This isn't supported by gcc
  # on Ubuntu 14.04.
  # compiler_flag: "-fcolor-diagnostics"

  # All warnings are enabled. Maybe enable -Werror as well?
  compiler_flag: "-Wall"
  # Enable a few more warnings that aren't part of -Wall.
  compiler_flag: "-Wunused-but-set-parameter"
  # But disable some that are problematic.
  compiler_flag: "-Wno-free-nonheap-object" # has false positives

  # Keep stack frames for debugging, even in opt mode.
  compiler_flag: "-fno-omit-frame-pointer"

  # Anticipated future default.
  linker_flag: "-no-canonical-prefixes"
  # Have gcc return the exit code from ld.
  linker_flag: "-pass-exit-codes"
  # Stamp the binary with a unique identifier.
  linker_flag: "-Wl,--build-id=md5"
  linker_flag: "-Wl,--hash-style=gnu"
  # Gold linker only? Can we enable this by default?
  # linker_flag: "-Wl,--warn-execstack"
  # linker_flag: "-Wl,--detect-odr-violations"

  compilation_mode_flags {
    mode: DBG
    # Enable debug symbols.
    compiler_flag: "-g"
  }
  compilation_mode_flags {
    mode: OPT

    # No debug symbols.
    # Maybe we should enable https://gcc.gnu.org/wiki/DebugFission for opt or
    # even generally? However, that can't happen here, as it requires special
    # handling in Bazel.
    compiler_flag: "-g0"

    # Conservative choice for -O
    # -O3 can increase binary size and even slow down the resulting binaries.
    # Profile first and / or use FDO if you need better performance than this.
    compiler_flag: "-O2"

    # Disable assertions
    compiler_flag: "-DNDEBUG"

    # Removal of unused code and data at link time (can this increase binary size in some cases?).
    compiler_flag: "-ffunction-sections"
    compiler_flag: "-fdata-sections"
    linker_flag: "-Wl,--gc-sections"
  }
  linking_mode_flags { mode: DYNAMIC }
}


Third, build with command "./compile.sh" (That's all)



after compile process, I thought that default compiler changed from gcc to icpc.


However, when I build the simple example, bazel continually use the gcc.


[bazel_test]$ bazel build --verbose_failures --config debug -c opt //src:main

INFO: Found 1 target...

INFO: From Compiling src/main.cc:

gcc: warning: /opt/intel/vtune_amplifier_xe_2016/lib64/libittnotify.a: linker input file unused because linking not done

ERROR: /home/xxxxx/bazel_test/src/BUILD:1:1: Linking of rule '//src:main' failed: linux-sandbox failed: error executing command 

  (cd /home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-1/bazel_test/execroot/bazel_test &&\

  exec env - \

  /home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/execroot/bazel_test/_bin/linux-sandbox @/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-1/bazel_test/linux-sandbox.params -- /usr/bin/gcc -o bazel-out/local-opt/bin/src/main -Wl,-no-as-needed -B/usr/bin -B/usr/bin -pass-exit-codes '-Wl,--build-id=md5' '-Wl,--hash-style=gnu' -Wl,--gc-sections -Wl,@bazel-out/local-opt/bin/src/main-2.params).

bazel-out/local-opt/bin/src/_objs/main/src/main.o: In function `main':

/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-0/bazel_test/execroot/bazel_test/src/main.cc:36: undefined reference to `__itt_pause_ptr__3_0'

/home/xxxxx/.cache/bazel/_bazel_xxxxx/3993447ab2df42bf45f9688e3c143e8b/bazel-sandbox/e5ee3faf-2bdb-4d60-a62b-2fbb25ba6941-0/bazel_test/execroot/bazel_test/src/main.cc:42: undefined reference to `__itt_resume_ptr__3_0'

collect2: error: ld returned 1 exit status

Target //src:main failed to build

INFO: Elapsed time: 0.463s, Critical Path: 0.35s



I want to use icpc with default bazel compiler because icpc only can build some option. 

 

Please tell me about solution. thank you!




2016년 9월 19일 월요일 오후 4시 9분 4초 UTC+9, Thiago Farina 님의 말:

Thiago Farina

unread,
Sep 20, 2016, 5:44:41 AM9/20/16
to Sunjung Lee, bazel-discuss
Where is 'bazel' located in your system?

If you build with `./compile.sh compile` it will put it in `output/bazel`, and you can use 'file' to locate where it really is. Running this way, looks like you are using a different binary than the one you have just modified and built, but I could be wrong. But I think it is worth double checking.


--
Thiago Farina

Sunjung Lee

unread,
Sep 20, 2016, 6:12:56 AM9/20/16
to bazel-discuss, sunjun...@gmail.com
Bazel source file exist in the /opt/ directory and 'bazel' is located in the /opt/bazel/output directory.

I builded with '.compile.sh compile' command, but nothing changed.

Could you tell me whole process of change bazel default compiler(gcc) to icpc or link the relate page?








2016년 9월 20일 화요일 오후 6시 44분 41초 UTC+9, Thiago Farina 님의 말:

Ningyu Shi

unread,
Sep 20, 2016, 9:41:20 AM9/20/16
to bazel-discuss
There is nothing to do with bazel itself's CROSSTOOL file. You can follow this Tutorial to setup any non-default compiler.

Thanks
Ningyu

Brian Silverman

unread,
Sep 20, 2016, 3:40:10 PM9/20/16
to Ningyu Shi, bazel-discuss
I do recommend looking through that tutorial (you can ignore the parts about wrapper scripts and downloading the toolchain). If you want to use a different system compiler, you should probably start by copying Bazel's tools/cpp/BUILD and tools/cpp/CROSSTOOL into a folder in your source tree and pointing --crosstool_top there. The tutorial explains a bit more about what goes in that BUILD file.

I think the two pieces you were missing are needing to rebuild Bazel (and use the newly built bazel binary) to pick up changes to the tools/cpp folder in the Bazel source tree, and that on Linux it defaults to using tools/cpp/cc_configure.bzl to generate a CROSSTOOL instead of the tools/cpp/CROSSTOOL file in the source tree directly. Using your own --crosstool_top avoids both of those.

On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/0d2e81bd-17fb-4132-9bc4-3423a424975f%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Sunjung Lee

unread,
Sep 20, 2016, 11:42:52 PM9/20/16
to bazel-discuss, shin...@gmail.com
On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.

I don't understand the sentence 'just setting CC=icpc'.
The meaning is weather change the linux default CC to icpc or add bazel option?(like --compiler name)
If you said about add bazel option, what is the option command?

Thank you.


2016년 9월 21일 수요일 오전 4시 40분 10초 UTC+9, Brian Silverman 님의 말:
I do recommend looking through that tutorial (you can ignore the parts about wrapper scripts and downloading the toolchain). If you want to use a different system compiler, you should probably start by copying Bazel's tools/cpp/BUILD and tools/cpp/CROSSTOOL into a folder in your source tree and pointing --crosstool_top there. The tutorial explains a bit more about what goes in that BUILD file.

I think the two pieces you were missing are needing to rebuild Bazel (and use the newly built bazel binary) to pick up changes to the tools/cpp folder in the Bazel source tree, and that on Linux it defaults to using tools/cpp/cc_configure.bzl to generate a CROSSTOOL instead of the tools/cpp/CROSSTOOL file in the source tree directly. Using your own --crosstool_top avoids both of those.

On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.
On Tue, Sep 20, 2016 at 9:41 AM, Ningyu Shi <shin...@gmail.com> wrote:
There is nothing to do with bazel itself's CROSSTOOL file. You can follow this Tutorial to setup any non-default compiler.

Thanks
Ningyu

On Sunday, September 18, 2016 at 12:35:14 AM UTC-5, Sunjung Lee wrote:
Hi, I want to use Intel compiler(icpc or icc) in Bazel because I want to use a lot of options with Intel machine.

But, CROSSTOOL didn't work and I don't know what I set the entire job.

I use CentOs 7.2 and default compiler is gcc 4.8.3

If anyone know about that, Please tell me.

Thank you for reading!

--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.

Sunjung Lee

unread,
Sep 20, 2016, 11:45:44 PM9/20/16
to bazel-discuss
I think that linked tutorial seems to be updated.

Before the link is updated, I don't understand some processes such as downloading the toolchain(In prior version, first subject is 'downloading arm toolchain'), so I can't apply the whole process.

But now I am likely to understand tutorial and I try that.

Thank you so much!

2016년 9월 20일 화요일 오후 10시 41분 20초 UTC+9, Ningyu Shi 님의 말:

Brian Silverman

unread,
Sep 21, 2016, 12:56:35 AM9/21/16
to Sunjung Lee, bazel-discuss, Ningyu Shi
On Tue, Sep 20, 2016 at 11:42 PM, Sunjung Lee <sunjun...@gmail.com> wrote:
On a related note: have you tried just setting CC=icpc when you run `bazel build` instead of hand-writing a CROSSTOOL? cc_configure.bzl tries to auto-detect the settings for a compiler specified that way. However, I'm not sure it'll work with anything other than GCC or Clang.

I don't understand the sentence 'just setting CC=icpc'.
The meaning is weather change the linux default CC to icpc or add bazel option?(like --compiler name)
If you said about add bazel option, what is the option command?

Thank you.

I mean set the environment variable CC, ie building with a command like `CC=icpc bazel build //my:target`. The default --compiler should then be icpc. I think that due to #1595, you'll have to do a `bazel clean` first.

Sunjung Lee

unread,
Sep 21, 2016, 6:39:48 AM9/21/16
to bazel-discuss, sunjun...@gmail.com, shin...@gmail.com
As you say, I built my source with the command 'CC=icpc bazel build //my:target'

and It works!!!

I am very appreciative of you.

thank you

2016년 9월 21일 수요일 오후 1시 56분 35초 UTC+9, Brian Silverman 님의 말:
Reply all
Reply to author
Forward
0 new messages