diff options
author | Benoit Steiner <bsteiner@google.com> | 2016-11-09 14:57:34 -0800 |
---|---|---|
committer | TensorFlower Gardener <gardener@tensorflow.org> | 2016-11-09 15:06:00 -0800 |
commit | 715585c50625d8d6177ad5eeeec244bc76070b09 (patch) | |
tree | eb6f9fd222affc57413ab76b648992ada6760a78 /third_party/sycl/crosstool | |
parent | e105989bef735af5dcca15f09ccae9224ff3bcc6 (diff) |
Added a new rule to handle the OpenCL backend: we comment it out in
google3, and enable it in github. This is because we haven't imported the backed in google3 just yet.
Change: 138689620
Diffstat (limited to 'third_party/sycl/crosstool')
-rw-r--r-- | third_party/sycl/crosstool/BUILD | 0 | ||||
-rwxr-xr-x | third_party/sycl/crosstool/BUILD.tpl | 29 | ||||
-rwxr-xr-x | third_party/sycl/crosstool/CROSSTOOL.tpl | 82 | ||||
-rwxr-xr-x | third_party/sycl/crosstool/computecpp.tpl | 61 |
4 files changed, 172 insertions, 0 deletions
diff --git a/third_party/sycl/crosstool/BUILD b/third_party/sycl/crosstool/BUILD new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/third_party/sycl/crosstool/BUILD diff --git a/third_party/sycl/crosstool/BUILD.tpl b/third_party/sycl/crosstool/BUILD.tpl new file mode 100755 index 0000000000..f539a376c8 --- /dev/null +++ b/third_party/sycl/crosstool/BUILD.tpl @@ -0,0 +1,29 @@ +licenses(["notice"]) # Apache 2.0 + +package(default_visibility = ["//visibility:public"]) + +cc_toolchain_suite( + name = "toolchain", + toolchains = { + "local|compiler": ":cc-compiler-local", + }, +) + +cc_toolchain( + name = "cc-compiler-local", + all_files = ":empty", + compiler_files = ":empty", + cpu = "local", + dwp_files = ":empty", + dynamic_runtime_libs = [":empty"], + linker_files = ":empty", + objcopy_files = ":empty", + static_runtime_libs = [":empty"], + strip_files = ":empty", + supports_param_files = 0, +) + +filegroup( + name = "empty", + srcs = [], +) diff --git a/third_party/sycl/crosstool/CROSSTOOL.tpl b/third_party/sycl/crosstool/CROSSTOOL.tpl new file mode 100755 index 0000000000..2108a5b9f0 --- /dev/null +++ b/third_party/sycl/crosstool/CROSSTOOL.tpl @@ -0,0 +1,82 @@ +major_version: "local" +minor_version: "" +default_target_cpu: "same_as_host" + +default_toolchain { + cpu: "k8" + toolchain_identifier: "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 + supports_thin_archives: 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: "computecpp" } + # Use "-std=c++11" for nvcc. For consistency, force both the host compiler + # and the device compiler to use "-std=c++11". + cxx_flag: "-std=c++11" + 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: "/usr/lib" + cxx_builtin_include_directory: "/usr/lib64" + cxx_builtin_include_directory: "/usr/local/include" + cxx_builtin_include_directory: "/usr/include" + + cxx_builtin_include_directory: "%{computecpp_toolkit_path}" + + 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" } + + # 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\"" + + # All warnings are enabled. Maybe enable -Werror as well? + compiler_flag: "-Wall" + + # Anticipated future default. + linker_flag: "-Wl,-no-as-needed" + # Stamp the binary with a unique identifier. + linker_flag: "-Wl,--build-id=md5" + linker_flag: "-Wl,--hash-style=gnu" + + linking_mode_flags { mode: DYNAMIC } +} diff --git a/third_party/sycl/crosstool/computecpp.tpl b/third_party/sycl/crosstool/computecpp.tpl new file mode 100755 index 0000000000..4860e9f0a0 --- /dev/null +++ b/third_party/sycl/crosstool/computecpp.tpl @@ -0,0 +1,61 @@ +#!/usr/bin/env python + +from argparse import ArgumentParser +import os +import subprocess +import re +import sys +import pipes + +CPU_CXX_COMPILER = ('%{host_cxx_compiler}') +CPU_C_COMPILER = ('%{host_c_compiler}') + +CURRENT_DIR = os.path.dirname(sys.argv[0]) +COMPUTECPP_ROOT = CURRENT_DIR +"/../sycl/" +COMPUTECPP_DRIVER= COMPUTECPP_ROOT+"bin/compute++" +COMPUTECPP_INCLUDE = COMPUTECPP_ROOT+"include" + +def main(): + computecpp_compiler_flags = [""] + computecpp_compiler_flags = [flag for flag in sys.argv[1:]] + computecpp_compiler_flags = computecpp_compiler_flags + ["-D_GLIBCXX_USE_CXX11_ABI=0"] + + output_file_index = computecpp_compiler_flags.index("-o") +1 + output_file_name = computecpp_compiler_flags[output_file_index] + + if(output_file_index == 1): + # we are linking + return subprocess.call([CPU_CXX_COMPILER] +computecpp_compiler_flags ) + + # find what we compile + compiling_cpp = 0 + if("-c" in computecpp_compiler_flags): + compiled_file_index = computecpp_compiler_flags.index("-c") +1 + compited_file_name = computecpp_compiler_flags[compiled_file_index] + if(compited_file_name.endswith(('.cc', '.c++', '.cpp', '.CPP', '.C', '.cxx'))): + compiling_cpp = 1; + + if(compiling_cpp == 1): + filename, file_extension = os.path.splitext(output_file_name) + bc_out = filename + ".sycl" + + computecpp_compiler_flags = ['-DTENSORFLOW_USE_SYCL', '-Wno-unused-variable','-I', COMPUTECPP_INCLUDE,'-isystem', + COMPUTECPP_INCLUDE, "-std=c++11", "-sycl", "-emit-llvm", "-no-serial-memop"] + computecpp_compiler_flags + + # dont want that in case of compiling with computecpp first + host_compiler_flags = [""] + host_compiler_flags = [flag for flag in sys.argv[1:] + if not flag.startswith(('-MF','-MD',)) + if not ".d" in flag] + + x = subprocess.call([COMPUTECPP_DRIVER] +computecpp_compiler_flags ) + if(x == 0): + host_compiler_flags = ['-DTENSORFLOW_USE_SYCL', '-Wno-unused-variable', '-I', COMPUTECPP_INCLUDE, "--include",bc_out] + host_compiler_flags + return subprocess.call([CPU_CXX_COMPILER] +host_compiler_flags ) + return x + else: + # compile for C + return subprocess.call([CPU_C_COMPILER] +computecpp_compiler_flags) + +if __name__ == '__main__': + sys.exit(main()) |