Allow adding compiler specific flags to the GPU crosstool.
For now, only support "clang", "msvc" and "unknown" (implying a variety of gcc compatible compilers). We hard-code the MSVC toolchain to "msvc". The darwin toolchain is kept at "unknown", as it currently isn't tested with any of our clang-specific flags. The linux toolchain will use "clang" if compiling with cuda-clang, as that's currently the only situation in which we care about using clang-specific flags. In the future, we do optimally want to use compiler detection and setting the compiler attribute accordingly. PiperOrigin-RevId: 302429367 Change-Id: I3f47582e76d86d119d3fca4a6855cfc377667922
This commit is contained in:
parent
fa3451c646
commit
99c1898d7b
third_party/gpus
2
third_party/gpus/crosstool/BUILD.tpl
vendored
2
third_party/gpus/crosstool/BUILD.tpl
vendored
@ -68,6 +68,7 @@ cc_toolchain_config(
|
||||
linker_bin_path = "%{linker_bin_path}",
|
||||
builtin_sysroot = "%{builtin_sysroot}",
|
||||
cuda_path = "%{cuda_toolkit_path}",
|
||||
compiler = "%{compiler}",
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
@ -124,6 +125,7 @@ cc_toolchain_config(
|
||||
msvc_lib_path = "%{msvc_lib_path}",
|
||||
msvc_link_path = "%{msvc_link_path}",
|
||||
msvc_ml_path = "%{msvc_ml_path}",
|
||||
compiler = "msvc",
|
||||
)
|
||||
|
||||
filegroup(
|
||||
|
@ -626,48 +626,82 @@ def _impl(ctx):
|
||||
],
|
||||
)
|
||||
|
||||
default_compile_flags_feature = feature(
|
||||
name = "default_compile_flags",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = [
|
||||
ACTION_NAMES.assemble,
|
||||
ACTION_NAMES.preprocess_assemble,
|
||||
ACTION_NAMES.linkstamp_compile,
|
||||
ACTION_NAMES.c_compile,
|
||||
ACTION_NAMES.cpp_compile,
|
||||
ACTION_NAMES.cpp_header_parsing,
|
||||
ACTION_NAMES.cpp_module_compile,
|
||||
ACTION_NAMES.cpp_module_codegen,
|
||||
ACTION_NAMES.lto_backend,
|
||||
ACTION_NAMES.clif_match,
|
||||
],
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"/DCOMPILER_MSVC",
|
||||
"/DNOMINMAX",
|
||||
"/D_WIN32_WINNT=0x0600",
|
||||
"/D_CRT_SECURE_NO_DEPRECATE",
|
||||
"/D_CRT_SECURE_NO_WARNINGS",
|
||||
"/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS",
|
||||
"/bigobj",
|
||||
"/Zm500",
|
||||
"/J",
|
||||
"/Gy",
|
||||
"/GF",
|
||||
"/EHsc",
|
||||
"/wd4351",
|
||||
"/wd4291",
|
||||
"/wd4250",
|
||||
"/wd4996",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
if ctx.attr.compiler == "clang":
|
||||
default_compile_flags_feature = feature(
|
||||
name = "default_compile_flags",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = [
|
||||
ACTION_NAMES.assemble,
|
||||
ACTION_NAMES.preprocess_assemble,
|
||||
ACTION_NAMES.linkstamp_compile,
|
||||
ACTION_NAMES.c_compile,
|
||||
ACTION_NAMES.cpp_compile,
|
||||
ACTION_NAMES.cpp_header_parsing,
|
||||
ACTION_NAMES.cpp_module_compile,
|
||||
ACTION_NAMES.cpp_module_codegen,
|
||||
ACTION_NAMES.lto_backend,
|
||||
ACTION_NAMES.clif_match,
|
||||
],
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"-fexperimental-new-pass-manager",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
elif ctx.attr.compiler == "msvc":
|
||||
default_compile_flags_feature = feature(
|
||||
name = "default_compile_flags",
|
||||
enabled = True,
|
||||
flag_sets = [
|
||||
flag_set(
|
||||
actions = [
|
||||
ACTION_NAMES.assemble,
|
||||
ACTION_NAMES.preprocess_assemble,
|
||||
ACTION_NAMES.linkstamp_compile,
|
||||
ACTION_NAMES.c_compile,
|
||||
ACTION_NAMES.cpp_compile,
|
||||
ACTION_NAMES.cpp_header_parsing,
|
||||
ACTION_NAMES.cpp_module_compile,
|
||||
ACTION_NAMES.cpp_module_codegen,
|
||||
ACTION_NAMES.lto_backend,
|
||||
ACTION_NAMES.clif_match,
|
||||
],
|
||||
flag_groups = [
|
||||
flag_group(
|
||||
flags = [
|
||||
"/DCOMPILER_MSVC",
|
||||
"/DNOMINMAX",
|
||||
"/D_WIN32_WINNT=0x0600",
|
||||
"/D_CRT_SECURE_NO_DEPRECATE",
|
||||
"/D_CRT_SECURE_NO_WARNINGS",
|
||||
"/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS",
|
||||
"/bigobj",
|
||||
"/Zm500",
|
||||
"/J",
|
||||
"/Gy",
|
||||
"/GF",
|
||||
"/EHsc",
|
||||
"/wd4351",
|
||||
"/wd4291",
|
||||
"/wd4250",
|
||||
"/wd4996",
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
else:
|
||||
default_compile_flags_feature = feature(
|
||||
name = "default_compile_flags")
|
||||
|
||||
static_link_msvcrt_debug_feature = feature(
|
||||
name = "static_link_msvcrt_debug",
|
||||
@ -1320,6 +1354,7 @@ def _impl(ctx):
|
||||
|
||||
if (ctx.attr.cpu == "local"):
|
||||
features = [
|
||||
default_compile_flags_feature,
|
||||
cpp11_feature,
|
||||
stdlib_feature,
|
||||
determinism_feature,
|
||||
@ -1510,6 +1545,7 @@ cc_toolchain_config = rule(
|
||||
"msvc_lib_path": attr.string(default = "msvc_not_used"),
|
||||
"msvc_link_path": attr.string(default = "msvc_not_used"),
|
||||
"msvc_ml_path": attr.string(default = "msvc_not_used"),
|
||||
"compiler": attr.string(values = ["clang", "msvc", "unknown"], default="unknown"),
|
||||
},
|
||||
provides = [CcToolchainConfigInfo],
|
||||
executable = True,
|
||||
|
2
third_party/gpus/cuda_configure.bzl
vendored
2
third_party/gpus/cuda_configure.bzl
vendored
@ -1024,8 +1024,10 @@ def _create_local_cuda_repository(repository_ctx):
|
||||
cuda_defines = {}
|
||||
cuda_defines["%{builtin_sysroot}"] = tf_sysroot
|
||||
cuda_defines["%{cuda_toolkit_path}"] = ""
|
||||
cuda_defines["%{compiler}"] = "unknown"
|
||||
if is_cuda_clang:
|
||||
cuda_defines["%{cuda_toolkit_path}"] = cuda_config.config["cuda_toolkit_path"]
|
||||
cuda_defines["%{compiler}"] = "clang"
|
||||
|
||||
host_compiler_prefix = get_host_environ(repository_ctx, _GCC_HOST_COMPILER_PREFIX)
|
||||
if not host_compiler_prefix:
|
||||
|
Loading…
Reference in New Issue
Block a user