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
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}",
|
linker_bin_path = "%{linker_bin_path}",
|
||||||
builtin_sysroot = "%{builtin_sysroot}",
|
builtin_sysroot = "%{builtin_sysroot}",
|
||||||
cuda_path = "%{cuda_toolkit_path}",
|
cuda_path = "%{cuda_toolkit_path}",
|
||||||
|
compiler = "%{compiler}",
|
||||||
)
|
)
|
||||||
|
|
||||||
cc_toolchain(
|
cc_toolchain(
|
||||||
@ -124,6 +125,7 @@ cc_toolchain_config(
|
|||||||
msvc_lib_path = "%{msvc_lib_path}",
|
msvc_lib_path = "%{msvc_lib_path}",
|
||||||
msvc_link_path = "%{msvc_link_path}",
|
msvc_link_path = "%{msvc_link_path}",
|
||||||
msvc_ml_path = "%{msvc_ml_path}",
|
msvc_ml_path = "%{msvc_ml_path}",
|
||||||
|
compiler = "msvc",
|
||||||
)
|
)
|
||||||
|
|
||||||
filegroup(
|
filegroup(
|
||||||
|
@ -626,48 +626,82 @@ def _impl(ctx):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
default_compile_flags_feature = feature(
|
if ctx.attr.compiler == "clang":
|
||||||
name = "default_compile_flags",
|
default_compile_flags_feature = feature(
|
||||||
enabled = True,
|
name = "default_compile_flags",
|
||||||
flag_sets = [
|
enabled = True,
|
||||||
flag_set(
|
flag_sets = [
|
||||||
actions = [
|
flag_set(
|
||||||
ACTION_NAMES.assemble,
|
actions = [
|
||||||
ACTION_NAMES.preprocess_assemble,
|
ACTION_NAMES.assemble,
|
||||||
ACTION_NAMES.linkstamp_compile,
|
ACTION_NAMES.preprocess_assemble,
|
||||||
ACTION_NAMES.c_compile,
|
ACTION_NAMES.linkstamp_compile,
|
||||||
ACTION_NAMES.cpp_compile,
|
ACTION_NAMES.c_compile,
|
||||||
ACTION_NAMES.cpp_header_parsing,
|
ACTION_NAMES.cpp_compile,
|
||||||
ACTION_NAMES.cpp_module_compile,
|
ACTION_NAMES.cpp_header_parsing,
|
||||||
ACTION_NAMES.cpp_module_codegen,
|
ACTION_NAMES.cpp_module_compile,
|
||||||
ACTION_NAMES.lto_backend,
|
ACTION_NAMES.cpp_module_codegen,
|
||||||
ACTION_NAMES.clif_match,
|
ACTION_NAMES.lto_backend,
|
||||||
],
|
ACTION_NAMES.clif_match,
|
||||||
flag_groups = [
|
],
|
||||||
flag_group(
|
flag_groups = [
|
||||||
flags = [
|
flag_group(
|
||||||
"/DCOMPILER_MSVC",
|
flags = [
|
||||||
"/DNOMINMAX",
|
"-fexperimental-new-pass-manager",
|
||||||
"/D_WIN32_WINNT=0x0600",
|
],
|
||||||
"/D_CRT_SECURE_NO_DEPRECATE",
|
),
|
||||||
"/D_CRT_SECURE_NO_WARNINGS",
|
],
|
||||||
"/D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS",
|
),
|
||||||
"/bigobj",
|
],
|
||||||
"/Zm500",
|
)
|
||||||
"/J",
|
|
||||||
"/Gy",
|
elif ctx.attr.compiler == "msvc":
|
||||||
"/GF",
|
default_compile_flags_feature = feature(
|
||||||
"/EHsc",
|
name = "default_compile_flags",
|
||||||
"/wd4351",
|
enabled = True,
|
||||||
"/wd4291",
|
flag_sets = [
|
||||||
"/wd4250",
|
flag_set(
|
||||||
"/wd4996",
|
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(
|
static_link_msvcrt_debug_feature = feature(
|
||||||
name = "static_link_msvcrt_debug",
|
name = "static_link_msvcrt_debug",
|
||||||
@ -1320,6 +1354,7 @@ def _impl(ctx):
|
|||||||
|
|
||||||
if (ctx.attr.cpu == "local"):
|
if (ctx.attr.cpu == "local"):
|
||||||
features = [
|
features = [
|
||||||
|
default_compile_flags_feature,
|
||||||
cpp11_feature,
|
cpp11_feature,
|
||||||
stdlib_feature,
|
stdlib_feature,
|
||||||
determinism_feature,
|
determinism_feature,
|
||||||
@ -1510,6 +1545,7 @@ cc_toolchain_config = rule(
|
|||||||
"msvc_lib_path": attr.string(default = "msvc_not_used"),
|
"msvc_lib_path": attr.string(default = "msvc_not_used"),
|
||||||
"msvc_link_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"),
|
"msvc_ml_path": attr.string(default = "msvc_not_used"),
|
||||||
|
"compiler": attr.string(values = ["clang", "msvc", "unknown"], default="unknown"),
|
||||||
},
|
},
|
||||||
provides = [CcToolchainConfigInfo],
|
provides = [CcToolchainConfigInfo],
|
||||||
executable = True,
|
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 = {}
|
||||||
cuda_defines["%{builtin_sysroot}"] = tf_sysroot
|
cuda_defines["%{builtin_sysroot}"] = tf_sysroot
|
||||||
cuda_defines["%{cuda_toolkit_path}"] = ""
|
cuda_defines["%{cuda_toolkit_path}"] = ""
|
||||||
|
cuda_defines["%{compiler}"] = "unknown"
|
||||||
if is_cuda_clang:
|
if is_cuda_clang:
|
||||||
cuda_defines["%{cuda_toolkit_path}"] = cuda_config.config["cuda_toolkit_path"]
|
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)
|
host_compiler_prefix = get_host_environ(repository_ctx, _GCC_HOST_COMPILER_PREFIX)
|
||||||
if not host_compiler_prefix:
|
if not host_compiler_prefix:
|
||||||
|
Loading…
Reference in New Issue
Block a user