diff --git a/.bazelrc b/.bazelrc index 590a87f5732..01b416c1dac 100644 --- a/.bazelrc +++ b/.bazelrc @@ -30,6 +30,10 @@ build:monolithic --define framework_shared_object=false # opts in to modular op registration support by default. build --define framework_shared_object=true +# Flags for open source build, always set to be true. +build --define open_source_build=true +test --define open_source_build=true + # Please note that MKL on MacOS or windows is still not supported. # If you would like to use a local MKL instead of downloading, please set the # environment variable "TF_MKL_ROOT" every time before build. diff --git a/tensorflow/BUILD b/tensorflow/BUILD index f5556d5a804..b014782806a 100644 --- a/tensorflow/BUILD +++ b/tensorflow/BUILD @@ -356,6 +356,15 @@ config_setting( }, ) +# Flag to indicate open source build, .bazelrc always has it set to be true +config_setting( + name = "oss", + define_values = { + "open_source_build": "true", + }, + visibility = ["//visibility:public"], +) + config_setting( name = "using_cuda_clang_with_dynamic_build", define_values = { @@ -364,6 +373,14 @@ config_setting( }, ) +config_setting( + name = "build_oss_using_cuda_clang", + define_values = { + "using_cuda_clang": "true", + "open_source_build": "true", + }, +) + # Setting to use when loading kernels dynamically config_setting( name = "dynamic_loaded_kernels", @@ -389,6 +406,14 @@ config_setting( }, ) +config_setting( + name = "build_oss_using_cuda_nvcc", + define_values = { + "using_cuda_nvcc": "true", + "open_source_build": "true", + }, +) + config_setting( name = "using_rocm_hipcc", define_values = { diff --git a/tensorflow/compiler/xla/service/gpu/BUILD b/tensorflow/compiler/xla/service/gpu/BUILD index acd48be479b..866df46d9db 100644 --- a/tensorflow/compiler/xla/service/gpu/BUILD +++ b/tensorflow/compiler/xla/service/gpu/BUILD @@ -4,7 +4,6 @@ load("//tensorflow/compiler/xla:xla.bzl", "xla_proto_library") load( "//tensorflow/core/platform:default/build_config_root.bzl", - "if_static", "tf_cuda_tests_tags", ) load("//tensorflow:tensorflow.bzl", "tf_cc_test", "tf_copts", "tf_cuda_library") @@ -692,10 +691,8 @@ cc_library( "//tensorflow/core:lib", "//tensorflow/core:stream_executor_no_cuda", "//tensorflow/stream_executor:blas", - ] + if_static( - ["@local_config_cuda//cuda:cusolver"], - ["//tensorflow/stream_executor/cuda:cusolver_stub"], - ), + "//tensorflow/stream_executor/cuda:cusolver_lib", + ], ) cc_library( diff --git a/tensorflow/core/kernels/BUILD b/tensorflow/core/kernels/BUILD index 4c55ced5824..58e5664d28b 100644 --- a/tensorflow/core/kernels/BUILD +++ b/tensorflow/core/kernels/BUILD @@ -29,7 +29,6 @@ load( ) load( "//tensorflow/core/platform:default/build_config_root.bzl", - "if_static", "tf_cuda_tests_tags", ) load( @@ -3297,16 +3296,9 @@ tf_kernel_library( "//tensorflow/core:framework", "//tensorflow/core:lib", "//tensorflow/core/platform/default/build_config:cublas_plugin", - ] + if_static( - [ - "@local_config_cuda//cuda:cusolver", - "@local_config_cuda//cuda:cublas", - ], - [ - "//tensorflow/stream_executor/cuda:cusolver_stub", - "//tensorflow/stream_executor/cuda:cublas_stub", - ], - ), + "//tensorflow/stream_executor/cuda:cublas_lib", + "//tensorflow/stream_executor/cuda:cusolver_lib", + ], ) tf_kernel_library( @@ -3316,10 +3308,8 @@ tf_kernel_library( deps = [ "//tensorflow/core:framework", "//tensorflow/core:lib", - ] + if_static( - ["@local_config_cuda//cuda:cusparse"], - ["//tensorflow/stream_executor/cuda:cusparse_stub"], - ), + "//tensorflow/stream_executor/cuda:cusparse_lib", + ], ) LINALG_DEPS = [ diff --git a/tensorflow/stream_executor/cuda/BUILD b/tensorflow/stream_executor/cuda/BUILD index 48e9665ef05..27b1364c6cb 100644 --- a/tensorflow/stream_executor/cuda/BUILD +++ b/tensorflow/stream_executor/cuda/BUILD @@ -16,7 +16,6 @@ load( ) load( "//tensorflow/core/platform:default/build_config_root.bzl", - "if_static", "tf_cuda_tests_tags", ) @@ -139,8 +138,8 @@ cc_library( "//tensorflow/stream_executor/platform:dso_loader", ] + tf_additional_cuda_driver_deps()) + select({ # include dynamic loading implementation only when if_cuda_is_configured and build dynamically - "//tensorflow:using_cuda_nvcc_with_dynamic_build": ["cudart_stub"], - "//tensorflow:using_cuda_clang_with_dynamic_build": ["cudart_stub"], + "//tensorflow:build_oss_using_cuda_nvcc": ["cudart_stub"], + "//tensorflow:build_oss_using_cuda_clang": ["cudart_stub"], "//conditions:default": ["//tensorflow/core:cuda"], }) + [ "@com_google_absl//absl/base:core_headers", @@ -154,20 +153,20 @@ cc_library( name = "cudart_stub", srcs = select({ # include dynamic loading implementation only when if_cuda_is_configured and build dynamically - "//tensorflow:using_cuda_nvcc_with_dynamic_build": ["cudart_stub.cc"], - "//tensorflow:using_cuda_clang_with_dynamic_build": ["cudart_stub.cc"], + "//tensorflow:build_oss_using_cuda_nvcc": ["cudart_stub.cc"], + "//tensorflow:build_oss_using_cuda_clang": ["cudart_stub.cc"], "//conditions:default": [], }), textual_hdrs = glob(["cuda_runtime_*.inc"]), visibility = ["//visibility:public"], deps = select({ - "//tensorflow:using_cuda_nvcc_with_dynamic_build": [ + "//tensorflow:build_oss_using_cuda_nvcc": [ ":cuda_stub", "@local_config_cuda//cuda:cuda_headers", "//tensorflow/stream_executor/lib", "//tensorflow/stream_executor/platform:dso_loader", ], - "//tensorflow:using_cuda_clang_with_dynamic_build": [ + "//tensorflow:build_oss_using_cuda_clang": [ ":cuda_stub", "@local_config_cuda//cuda:cuda_headers", "//tensorflow/stream_executor/lib", @@ -232,11 +231,11 @@ cc_library( alias( name = "cublas_lib", - actual = if_static( - "@local_config_cuda//cuda:cublas", - ":cublas_stub", - ), - visibility = ["//visibility:private"], + actual = select({ + "//tensorflow:oss": ":cublas_stub", + "//conditions:default": "@local_config_cuda//cuda:cublas", + }), + visibility = ["//visibility:public"], ) cc_library( @@ -288,11 +287,11 @@ cc_library( alias( name = "cufft_lib", - actual = if_static( - "@local_config_cuda//cuda:cufft", - ":cufft_stub", - ), - visibility = ["//visibility:private"], + actual = select({ + "//tensorflow:oss": ":cufft_stub", + "//conditions:default": "@local_config_cuda//cuda:cufft", + }), + visibility = ["//visibility:public"], ) cc_library( @@ -333,11 +332,11 @@ cc_library( alias( name = "cudnn_lib", - actual = if_static( - "@local_config_cuda//cuda:cudnn", - ":cudnn_stub", - ), - visibility = ["//visibility:private"], + actual = select({ + "//tensorflow:oss": ":cudnn_stub", + "//conditions:default": "@local_config_cuda//cuda:cudnn", + }), + visibility = ["//visibility:public"], ) cc_library( @@ -386,11 +385,11 @@ cc_library( alias( name = "curand_lib", - actual = if_static( - "@local_config_cuda//cuda:curand", - ":curand_stub", - ), - visibility = ["//visibility:private"], + actual = select({ + "//tensorflow:oss": ":curand_stub", + "//conditions:default": "@local_config_cuda//cuda:curand", + }), + visibility = ["//visibility:public"], ) cc_library( @@ -443,6 +442,15 @@ cc_library( ]), ) +alias( + name = "cusolver_lib", + actual = select({ + "//tensorflow:oss": ":cusolver_stub", + "//conditions:default": "@local_config_cuda//cuda:cusolver", + }), + visibility = ["//visibility:public"], +) + cc_library( name = "cusparse_stub", srcs = if_cuda_is_configured(["cusparse_stub.cc"]), @@ -454,6 +462,15 @@ cc_library( ]), ) +alias( + name = "cusparse_lib", + actual = select({ + "//tensorflow:oss": ":cusparse_stub", + "//conditions:default": "@local_config_cuda//cuda:cusparse", + }), + visibility = ["//visibility:public"], +) + cc_library( name = "cuda_kernel", srcs = if_cuda_is_configured(["cuda_kernel.cc"]),