diff --git a/.gitignore b/.gitignore index afd358cba55..de0e473c189 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ tao/third_party/blade_service_common tao/build.txt tao/*.tgz third_party/bazel/blade_service_common/*.BUILD +third_party/bazel/blade_service_common/*.BUILD.tpl third_party/bazel/blade_service_common/blade_service_common_workspace.bzl.tpl **/*.so **/*.so.[0-9] diff --git a/VERSION b/VERSION index 655614af0e3..8de1e0302e0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.21.05 \ No newline at end of file +0.23.01 diff --git a/scripts/python/common_setup.py b/scripts/python/common_setup.py index ea68d1caf57..47977c38848 100644 --- a/scripts/python/common_setup.py +++ b/scripts/python/common_setup.py @@ -619,9 +619,6 @@ def symlink_disc_files(args): ) ) - logger.info("linking PatineClient") - link_dirs(os.path.join(dir_tf_community, 'tao', 'third_party', 'PatineClient'), - os.path.join(dir_platform_alibaba, 'third_party', 'PatineClient')) logger.info("linking blade_gemm") link_dirs(os.path.join(get_source_root_dir(), 'tf_community', 'tao', 'blade_gemm'), os.path.join(dir_platform_alibaba, 'blade_gemm')) diff --git a/tao/BUILD b/tao/BUILD index 54d38071c09..5ffdcc15f4e 100644 --- a/tao/BUILD +++ b/tao/BUILD @@ -10,6 +10,7 @@ load("@local_config_blade_disc_helper//:build_defs.bzl", "disc_build_ip", "disc_build_time", "if_platform_alibaba", + "if_internal_serving", ) load("@org_tensorflow//tensorflow:tensorflow.bzl", "tf_cc_shared_object") load("@local_config_rocm//rocm:build_defs.bzl", "if_dcu", "if_rocm") @@ -102,12 +103,22 @@ cc_library( ), deps = [ ":version_header", - "@local_config_tf//:tf_header_lib", - "@local_config_tf//:libtensorflow_framework", "@org_tao_compiler//tensorflow/compiler/mlir/xla/ral:ral_bridge", ] + if_platform_alibaba([ "@blade_service_common//blade_service_common:blade_service_common_deps", - ]), + ]) + if_internal_serving( + [ + "@org_tensorflow//tensorflow/core:lib", + "@org_tensorflow//tensorflow/core:framework", + "@org_tensorflow//tensorflow/core:core_cpu", + "@org_tensorflow//tensorflow/core:stream_executor_no_cuda", + "@org_tensorflow//tensorflow/stream_executor:stream_executor_impl", + ], + [ + "@local_config_tf//:tf_header_lib", + "@local_config_tf//:libtensorflow_framework", + ] + ), copts = if_cuda([ "-DGOOGLE_CUDA=1" ]) + if_dcu([ @@ -115,7 +126,10 @@ cc_library( ]) + if_rocm([ "-DTENSORFLOW_USE_ROCM=1", "-x rocm", - ])+ tf_copts(), + ]) + if_internal_serving([ + "-DTF_1_12", + "-DIS_PAI_TF", + ]) + tf_copts(), linkopts = [ "-lm", ], diff --git a/tao_compiler/decoupling/BUILD b/tao_compiler/decoupling/BUILD index f1c6c7cef5b..3b7dcbb64ec 100644 --- a/tao_compiler/decoupling/BUILD +++ b/tao_compiler/decoupling/BUILD @@ -1,7 +1,7 @@ licenses(["notice"]) # Apache 2.0 load("//tensorflow:tensorflow.bzl", "tf_cc_binary", "tf_cc_test") -load("//tensorflow/compiler/mlir/disc:disc.bzl", "if_platform_alibaba") +load("//tensorflow/compiler/mlir/util:util.bzl", "if_platform_alibaba") package_group( name = "internal", @@ -25,7 +25,7 @@ package( load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") load("@local_config_rocm//rocm:build_defs.bzl", "if_rocm_is_configured") -load("//tensorflow/compiler/mlir/disc:disc.bzl", "if_cuda_or_rocm") +load("//tensorflow/compiler/mlir/util:util.bzl", "if_cuda_or_rocm") load( "@com_google_protobuf//:protobuf.bzl", "cc_proto_library", diff --git a/tao_compiler/file_map b/tao_compiler/file_map index dc355640572..812ad5d7761 100644 --- a/tao_compiler/file_map +++ b/tao_compiler/file_map @@ -1,5 +1,6 @@ # relative path under tao_compiler, relative path under tf_community decoupling,tensorflow/compiler/decoupling mlir/disc,tensorflow/compiler/mlir/disc +mlir/util,tensorflow/compiler/mlir/util mlir/xla/ral,tensorflow/compiler/mlir/xla/ral .bazelrc.user,tensorflow/../.bazelrc.user diff --git a/tao_compiler/mlir/disc/BUILD b/tao_compiler/mlir/disc/BUILD index 28c26ea3ed9..b052be0296a 100644 --- a/tao_compiler/mlir/disc/BUILD +++ b/tao_compiler/mlir/disc/BUILD @@ -18,52 +18,12 @@ load("@org_tensorflow//tensorflow/core/platform:build_config_root.bzl", "if_stat load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library", "gentbl_filegroup", "td_library") load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured") load("@local_config_rocm//rocm:build_defs.bzl", "if_rocm_is_configured") -load("//tensorflow/compiler/mlir/disc:disc.bzl", +load("//tensorflow/compiler/mlir/util:util.bzl", "disc_cc_library", "if_cuda_or_rocm", "if_skip_compute_intensive_fusion", ) -load("//tensorflow/compiler/mlir/disc:disc.bzl", "if_torch_disc") - -config_setting( - name = "is_platform_alibaba", - define_values = {"is_platform_alibaba": "true"}, -) - -config_setting( - name = "is_patine", - define_values = {"is_patine": "true"}, -) - -config_setting( - name = "is_blade_gemm", - define_values = {"is_blade_gemm": "true"}, -) - -config_setting( - name = "is_mkldnn", - define_values = {"is_mkldnn": "true"}, -) - -config_setting( - name = "disc_aarch64", - define_values = {"disc_aarch64": "true"}, -) - -config_setting( - name = "disc_x86", - define_values = {"disc_x86": "true"}, -) - -config_setting( - name = "is_torch_disc", - define_values = {"is_torch_disc": "true"}, -) - -config_setting( - name = "skip_compute_intensive_fusion", - define_values = {"skip_compute_intensive_fusion": "true"}, -) +load("//tensorflow/compiler/mlir/util:util.bzl", "if_torch_disc") package( default_visibility = [":friends"], diff --git a/tao_compiler/mlir/disc/tests/BUILD b/tao_compiler/mlir/disc/tests/BUILD index cb0f1b0f5f5..059ee23a65f 100644 --- a/tao_compiler/mlir/disc/tests/BUILD +++ b/tao_compiler/mlir/disc/tests/BUILD @@ -3,7 +3,7 @@ load("@local_config_cuda//cuda:build_defs.bzl", "if_cuda_is_configured",) load("@local_config_rocm//rocm:build_defs.bzl", "if_rocm_is_configured",) load("//tensorflow/core/platform:build_config.bzl", "tf_proto_library",) load("//tensorflow/core/platform:build_config_root.bzl", "if_static") -load("//tensorflow/compiler/mlir/disc:disc.bzl", "disc_cc_library") +load("//tensorflow/compiler/mlir/util:util.bzl", "disc_cc_library") # buildifier: disable=same-origin-load load("//tensorflow:tensorflow.bzl", "get_compatible_with_cloud") diff --git a/tao_compiler/mlir/disc/tools/disc-replay/BUILD b/tao_compiler/mlir/disc/tools/disc-replay/BUILD index fa58b79e51b..4dde01ec499 100644 --- a/tao_compiler/mlir/disc/tools/disc-replay/BUILD +++ b/tao_compiler/mlir/disc/tools/disc-replay/BUILD @@ -4,7 +4,7 @@ load( "tf_cc_test", ) -load("//tensorflow/compiler/mlir/disc:disc.bzl", +load("//tensorflow/compiler/mlir/util:util.bzl", "disc_cc_library", "if_cuda_or_rocm", ) diff --git a/tao_compiler/mlir/util/BUILD b/tao_compiler/mlir/util/BUILD new file mode 100644 index 00000000000..ccda72df5ad --- /dev/null +++ b/tao_compiler/mlir/util/BUILD @@ -0,0 +1,44 @@ +config_setting( + name = "is_platform_alibaba", + define_values = {"is_platform_alibaba": "true"}, +) + +config_setting( + name = "is_patine", + define_values = {"is_patine": "true"}, +) + +config_setting( + name = "is_blade_gemm", + define_values = {"is_blade_gemm": "true"}, +) + +config_setting( + name = "is_mkldnn", + define_values = {"is_mkldnn": "true"}, +) + +config_setting( + name = "disc_aarch64", + define_values = {"disc_aarch64": "true"}, +) + +config_setting( + name = "disc_x86", + define_values = {"disc_x86": "true"}, +) + +config_setting( + name = "is_torch_disc", + define_values = {"is_torch_disc": "true"}, +) + +config_setting( + name = "skip_compute_intensive_fusion", + define_values = {"skip_compute_intensive_fusion": "true"}, +) + +config_setting( + name = "is_internal_serving", + define_values = {"is_internal_serving": "true"}, +) diff --git a/tao_compiler/mlir/disc/disc.bzl b/tao_compiler/mlir/util/util.bzl similarity index 68% rename from tao_compiler/mlir/disc/disc.bzl rename to tao_compiler/mlir/util/util.bzl index 02b1826f716..050dbbf09f3 100644 --- a/tao_compiler/mlir/disc/disc.bzl +++ b/tao_compiler/mlir/util/util.bzl @@ -22,55 +22,61 @@ def disc_cc_library(copts = tf_copts(), **kwargs): def if_platform_alibaba(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:is_platform_alibaba": if_true, + "//tensorflow/compiler/mlir/util:is_platform_alibaba": if_true, "//conditions:default": if_false }) def if_cuda_or_rocm(if_true, if_false=[]): return select({ - "@local_config_cuda//:is_cuda_enabled": if_true, + "@local_config_cuda//cuda:using_nvcc": if_true, "@local_config_rocm//rocm:using_hipcc": if_true, "//conditions:default": if_false }) def if_patine(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:is_patine": if_true, + "//tensorflow/compiler/mlir/util:is_patine": if_true, "//conditions:default": if_false }) def if_blade_gemm(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:is_blade_gemm": if_true, + "//tensorflow/compiler/mlir/util:is_blade_gemm": if_true, "//conditions:default": if_false }) def if_mkldnn(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:is_mkldnn": if_true, + "//tensorflow/compiler/mlir/util:is_mkldnn": if_true, "//conditions:default": if_false }) def if_disc_aarch64(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:disc_aarch64": if_true, + "//tensorflow/compiler/mlir/util:disc_aarch64": if_true, "//conditions:default": if_false }) def if_disc_x86(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:disc_x86": if_true, + "//tensorflow/compiler/mlir/util:disc_x86": if_true, "//conditions:default": if_false }) def if_torch_disc(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:is_torch_disc": if_true, + "//tensorflow/compiler/mlir/util:is_torch_disc": if_true, "//conditions:default": if_false }) def if_skip_compute_intensive_fusion(if_true, if_false=[]): return select({ - "//tensorflow/compiler/mlir/disc:skip_compute_intensive_fusion": if_true, + "//tensorflow/compiler/mlir/util:skip_compute_intensive_fusion": if_true, + "//conditions:default": if_false + }) + +def if_internal_serving(if_true, if_false=[]): + return select({ + "@local_config_blade_disc_helper//:is_internal_serving": if_true, "//conditions:default": if_false }) diff --git a/tao_compiler/mlir/xla/ral/BUILD b/tao_compiler/mlir/xla/ral/BUILD index 60dcef53e47..538a293cee7 100644 --- a/tao_compiler/mlir/xla/ral/BUILD +++ b/tao_compiler/mlir/xla/ral/BUILD @@ -21,7 +21,7 @@ load( "@com_google_protobuf//:protobuf.bzl", "cc_proto_library", ) -load("//tensorflow/compiler/mlir/disc:disc.bzl", +load("//tensorflow/compiler/mlir/util:util.bzl", "disc_cc_library", "if_cuda_or_rocm", "if_platform_alibaba", @@ -31,6 +31,7 @@ load("//tensorflow/compiler/mlir/disc:disc.bzl", "if_disc_aarch64", "if_disc_x86", "if_torch_disc", + "if_internal_serving", ) package( @@ -206,6 +207,7 @@ cc_library( ["//tao/blade_gemm:blade_gemm"], ) ) + cc_library( name = "disc_blade_gemm_deps", deps = if_platform_alibaba([ @@ -323,7 +325,6 @@ cc_library( "context/common_context_impl_acl.h", ]), copts = [ - # "-DTF_1_12", "-fopenmp", ] + if_dcu(["-DTENSORFLOW_USE_DCU=1"]) + if_cuda_or_rocm(["-DTAO_RAL_USE_STREAM_EXECUTOR"]), @@ -434,7 +435,6 @@ cc_library( ], hdrs = [ ], - #copts = ["-DTF_1_12"], deps = [ ":ral_context", ":ral_gpu_driver", @@ -666,6 +666,26 @@ tf_gpu_kernel_library( ) ########################################################################################### + +cc_library( + name = "tf_deps", + deps = if_internal_serving( + [ + "@com_google_absl//absl/types:variant", + "@org_tensorflow//tensorflow/core:lib", + "@org_tensorflow//tensorflow/core:framework", + "@org_tensorflow//tensorflow/core:core_cpu", + "@org_tensorflow//tensorflow/core:stream_executor_no_cuda", + "@org_tensorflow//tensorflow/stream_executor:stream_executor_impl", + ], + [ + "@local_config_tf//:libtensorflow_framework", + "@local_config_tf//:tf_header_lib", + ], + ), + alwayslink = 1, +) + # The targets following are for tf bridge side build. Get rid of all the deps from tf source code, only use some of the `.bzl` utils from tensorflow. cc_library( @@ -692,8 +712,7 @@ cc_library( hdrs = [ "context/common_context_impl.h", "context/stream_executor_based_impl.h", - ] + if_cuda_or_rocm([ - ])+ if_mkldnn([ + ] + if_mkldnn([ "context/common_context_impl_mkldnn.h", "context/common_context_impl_quantization.h", ]) + if_disc_aarch64([ @@ -709,6 +728,9 @@ cc_library( ]) + if_rocm_is_configured([ "-DTENSORFLOW_USE_ROCM=1", "-x rocm", + ]) + if_internal_serving([ + "-DTF_1_12", + "-DIS_PAI_TF", ]), linkopts = [ "-fopenmp", @@ -729,15 +751,15 @@ cc_library( ":ral_logging", ":ral_metadata", ":context_util", - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ] + if_cuda_is_configured([ "@local_config_cuda//cuda:cuda_driver", "@local_config_cuda//cuda:cuda_headers", ]) + if_rocm_is_configured([ "@local_config_rocm//rocm:rocm_headers", ]) + if_blade_gemm([ - ":disc_blade_gemm_deps", + "@blade_gemm//:blade_gemm", + "@mkl_static//:mkl_static_lib", ]) + if_mkldnn([ ":disc_mkl_bazel", ":ral_md5", @@ -762,6 +784,9 @@ cc_library( ] + if_rocm_is_configured([ "-DTENSORFLOW_USE_ROCM=1", "-x rocm", + ]) + if_internal_serving([ + "-DTF_1_12", + "-DIS_PAI_TF", ]), deps = [ ":context_util", @@ -771,8 +796,7 @@ cc_library( ":ral_gpu_driver", ":ral_library", "@local_config_cuda//cuda:cuda_headers", - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ], alwayslink = 1, ) @@ -794,8 +818,7 @@ cuda_library( "-x rocm", ]) + cuda_default_copts(), deps = [ - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ] + if_cuda_is_configured([ "@cub_archive//:cub", "@local_config_cuda//cuda:cuda_headers", @@ -824,8 +847,7 @@ cc_library( ":context_util", ":common_context_bridge", ":dynamic_sort_kernel_bridge", - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ] + if_cuda_is_configured([ "@local_config_cuda//cuda:cuda_driver", ]), @@ -865,8 +887,7 @@ cc_library( ":ral_logging", ":context_util", ":random_gpu_lib_bridge", - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ] + if_cuda_is_configured([ "@local_config_cuda//cuda:cuda_driver", "@local_config_cuda//cuda:cuda_headers", @@ -899,15 +920,14 @@ cuda_library( ]) + cuda_default_copts(), deps = [ ":ral_context", - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ] + if_cuda_is_configured([ "@cub_archive//:cub", "@local_config_cuda//cuda:cuda_headers", ]) + if_rocm_is_configured([ "@local_config_rocm//rocm:rocm_headers", ]) + if_blade_gemm([ - ":disc_blade_gemm_deps", + "@blade_gemm//:blade_gemm", ]), ) @@ -933,8 +953,7 @@ cc_library( ":ral_logging", ":context_util", ":transpose_gpu_lib_bridge", - "@local_config_tf//:libtensorflow_framework", - "@local_config_tf//:tf_header_lib", + ":tf_deps", ] + if_cuda_is_configured([ "@local_config_cuda//cuda:cuda_driver", "@local_config_cuda//cuda:cuda_headers", diff --git a/tao_compiler/mlir/xla/ral/context/stream_executor_based_impl.cc b/tao_compiler/mlir/xla/ral/context/stream_executor_based_impl.cc index f3b6b3ef65b..17dd59538cd 100644 --- a/tao_compiler/mlir/xla/ral/context/stream_executor_based_impl.cc +++ b/tao_compiler/mlir/xla/ral/context/stream_executor_based_impl.cc @@ -1441,6 +1441,8 @@ Status RunCudnnConvolution( params.bias_descriptor, DeviceMemory(operand_buffers[2]), se::dnn::ActivationMode::kNone, output_descriptor, &output_buf, scratch_allocator, algorithm, profile_result); +#elif TF_MAJOR_VERSION == 1 && TF_MINOR_VERSION == 12 + return errors::Internal("Not supported on tensorflow==1.12"); #else stream->ThenFusedConvolveWithAlgorithm( input_descriptor, input_buf, params.scale, filter_descriptor, diff --git a/third_party/bazel/blade_disc_helper/BUILD.tpl b/third_party/bazel/blade_disc_helper/BUILD.tpl index f1798526207..a0ad860340b 100644 --- a/third_party/bazel/blade_disc_helper/BUILD.tpl +++ b/third_party/bazel/blade_disc_helper/BUILD.tpl @@ -29,3 +29,8 @@ config_setting( name = "is_cxx11_abi", define_values = {"is_cxx11_abi": "true"}, ) + +config_setting( + name = "is_internal_serving", + define_values = {"is_internal_serving": "true"}, +) diff --git a/third_party/bazel/blade_disc_helper/build_defs.bzl.tpl b/third_party/bazel/blade_disc_helper/build_defs.bzl.tpl index dca80edbf94..d61fe65617b 100644 --- a/third_party/bazel/blade_disc_helper/build_defs.bzl.tpl +++ b/third_party/bazel/blade_disc_helper/build_defs.bzl.tpl @@ -93,3 +93,8 @@ def if_platform_alibaba(if_true, if_false=[]): def foreign_make_args(): return [ "-j%{DISC_FOREIGN_MAKE_JOBS}" ] +def if_internal_serving(if_true, if_false=[]): + return select({ + "@local_config_blade_disc_helper//:is_internal_serving": if_true, + "//conditions:default": if_false + }) diff --git a/third_party/bazel/blade_service_common/blade_service_common_configure.bzl b/third_party/bazel/blade_service_common/blade_service_common_configure.bzl index 73ac4b419ad..6a0fa2bb258 100644 --- a/third_party/bazel/blade_service_common/blade_service_common_configure.bzl +++ b/third_party/bazel/blade_service_common/blade_service_common_configure.bzl @@ -1,9 +1,35 @@ load("//bazel:common.bzl", "get_env_bool_value") _IS_PLATFORM_ALIBABA = "IS_PLATFORM_ALIBABA" +_IS_INTERNAL_SERVING = "IS_INTERNAL_SERVING" + +def _tpl(repository_ctx, tpl, substitutions): + repository_ctx.template( + tpl, + Label("//bazel/blade_service_common:%s.tpl" % tpl), + substitutions, + ) def _blade_service_common_impl(repository_ctx): if get_env_bool_value(repository_ctx, _IS_PLATFORM_ALIBABA): + if get_env_bool_value(repository_ctx, _IS_INTERNAL_SERVING): + substitutions = { + "%{RULES_FOREIGN_CC_MAKE}": "@rules_foreign_cc//tools/build_defs:configure.bzl", + "%{ARGS}": "" + } + _tpl(repository_ctx, "libuuid.BUILD", substitutions) + substitutions["%{TARGETS}"] = "" + substitutions["%{STATIC_LIB_ARG}"] = "static_libraries" + _tpl(repository_ctx, "openssl.BUILD", substitutions) + else: + substitutions = { + "%{RULES_FOREIGN_CC_MAKE}": "@rules_foreign_cc//foreign_cc:defs.bzl", + "%{ARGS}": "args = foreign_make_args()," + } + _tpl(repository_ctx, "libuuid.BUILD", substitutions) + substitutions["%{TARGETS}"] = "targets = [\"\", \"install_sw\"]," + substitutions["%{STATIC_LIB_ARG}"] = "out_static_libs" + _tpl(repository_ctx, "openssl.BUILD", substitutions) repository_ctx.template("blade_service_common_workspace.bzl", Label("//bazel/blade_service_common:blade_service_common_workspace.bzl.tpl"), { }) else: @@ -17,5 +43,6 @@ blade_service_common_configure = repository_rule( implementation = _blade_service_common_impl, environ = [ _IS_PLATFORM_ALIBABA, + _IS_INTERNAL_SERVING, ], ) diff --git a/third_party/bazel/tf/tf_configure.bzl b/third_party/bazel/tf/tf_configure.bzl index f8b5dd22d19..78301e301fe 100644 --- a/third_party/bazel/tf/tf_configure.bzl +++ b/third_party/bazel/tf/tf_configure.bzl @@ -20,12 +20,14 @@ def _tf_configure_impl(repository_ctx): with_tf = repository_ctx.os.environ[_BLADE_WITH_TF].lower() if with_tf not in ["1", "true", "on"]: # nothing to do with BUILD since it is empty + repository_ctx.symlink(Label("//bazel/tf:BUILD.tpl"), "BUILD") _tpl(repository_ctx, "build_defs.bzl", { - "%{IS_PAI_TF}": "True", + "%{IS_PAI_TF}": "False", "%{TF_COPTS}": "[]", "%{TF_LIB_DIR}": "", "%{IS_TF2}": "False", - "%{TF_VERSION}": "{}.{}".format(tf_major, tf_minor) + "%{TF_VERSION}": "Unknown", + "%{TF_MAJOR_VERSION}": "", }) return