Files
wehub-resource-sync 8a852e4b4e
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s
chore: import upstream snapshot with attribution
2026-07-13 12:14:16 +08:00

342 lines
10 KiB
Python

load("@llvm-project//mlir:tblgen.bzl", "gentbl_cc_library")
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@xla//third_party/rules_python/python:py_test.bzl", "py_test")
load("@xla//xla/tsl:tsl.default.bzl", "tsl_pybind_extension")
load("@xla//xla/tsl/platform:build_config_root.bzl", "if_static")
load("//tensorflow:pytype.default.bzl", "pytype_strict_library")
load("//tensorflow:tensorflow.bzl", "tf_cc_test")
load("//tensorflow:tensorflow.default.bzl", "get_compatible_with_portable")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:license"],
default_visibility = [
":friends",
"//tensorflow/tools/pip_package:__subpackages__",
],
licenses = ["notice"],
)
package_group(
name = "friends",
packages = [
"//tensorflow/compiler/mlir/lite/...",
"//tensorflow/compiler/mlir/quantization/...",
"//tensorflow/compiler/mlir/quantization/tensorflow/...",
"//tensorflow/compiler/tests/...",
],
)
tsl_pybind_extension(
name = "stablehlo_extension",
srcs = [
"stablehlo.cc",
"@stablehlo//:stablehlo/integrations/python/StablehloApi.cpp",
],
hdrs = [
"@stablehlo//:stablehlo/integrations/python/StablehloApi.h",
],
copts = [
"-fexceptions",
"-frtti",
],
features = ["-use_header_modules"],
deps = [
"@llvm-project//llvm:Support",
"@llvm-project//mlir:CAPIIR",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:MLIRBindingsPythonHeadersAndDeps",
"@nanobind",
"@stablehlo//:stablehlo_capi",
"@xla//third_party/python_runtime:headers",
],
)
pytype_strict_library(
name = "stablehlo",
srcs = ["stablehlo.py"],
visibility = ["//visibility:public"],
deps = [
":stablehlo_extension",
],
)
py_test(
name = "stablehlo_test",
srcs = ["stablehlo_test.py"],
strict_deps = True,
deps = [
":stablehlo",
#internal proto upb dep
],
)
gentbl_cc_library(
name = "legalize_tf_patterns_inc_gen",
compatible_with = get_compatible_with_portable(),
tbl_outs = [
(
["-gen-rewriters"],
"transforms/generated_legalize_tf.inc",
),
],
tblgen = "@llvm-project//mlir:mlir-tblgen",
td_file = "transforms/legalize_tf_patterns.td",
deps = [
"//tensorflow/compiler/mlir/tensorflow:tensorflow_ops_td_files",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:FuncTdFiles",
"@llvm-project//mlir:TensorOpsTdFiles",
"@xla//xla/mlir_hlo:hlo_ops_td_files",
],
)
cc_library(
name = "fold_broadcast_pass",
srcs = [
"transforms/fold_broadcast_pass.cc",
],
hdrs = [
"transforms/fold_broadcast_pass.h",
],
compatible_with = get_compatible_with_portable(),
copts = [
"-Ithird_party",
],
visibility = ["//visibility:public"],
deps = [
"@llvm-project//llvm:Support",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@xla//xla/mlir_hlo",
],
alwayslink = 1,
)
cc_library(
name = "legalize_utils",
srcs = ["transforms/utils.cc"],
hdrs = ["transforms/utils.h"],
compatible_with = get_compatible_with_portable(),
deps = [
"@llvm-project//llvm:Support",
"@llvm-project//mlir:IR",
"@xla//xla/mlir_hlo",
],
)
tf_cc_test(
name = "legalize_utils_test",
srcs = ["transforms/utils_test.cc"],
compatible_with = get_compatible_with_portable(),
deps = [
":legalize_utils",
"@com_google_googletest//:gtest_main",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Support",
"@xla//xla/mlir_hlo",
],
)
cc_library(
name = "legalize_tf",
srcs = [
"transforms/generated_legalize_tf.inc",
"transforms/legalize_tf.cc",
],
hdrs = [
"transforms/legalize_tf_passes.h",
],
compatible_with = get_compatible_with_portable(),
visibility = ["//visibility:public"],
deps = [
":legalize_tf_patterns_inc_gen",
":legalize_utils",
"//tensorflow/compiler/mlir/tensorflow",
"//tensorflow/compiler/mlir/tensorflow:dynamic_shape_utils",
"//tensorflow/compiler/mlir/tensorflow:xla_sharding_util",
"//tensorflow/core:framework",
"//tensorflow/core/kernels:conv_grad_shape_utils",
"@com_google_absl//absl/status",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:Dialect",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:MemRefDialect",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:ShapeDialect",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TensorDialect",
"@llvm-project//mlir:TransformUtils",
"@stablehlo//:chlo_ops",
"@stablehlo//:stablehlo_ops",
"@tsl//tsl/platform:bfloat16",
"@tsl//tsl/platform:tensor_float_32_hdr_lib",
"@xla//xla:xla_data_proto_cc",
"@xla//xla/hlo/builder:padding",
"@xla//xla/hlo/builder:sharding_builder",
"@xla//xla/hlo/builder/lib:conv_grad_size_util",
"@xla//xla/hlo/translate/hlo_to_mhlo:attribute_importer",
"@xla//xla/mlir_hlo",
"@xla//xla/mlir_hlo:convert_op_folder",
"@xla//xla/tsl/platform:status",
] + if_static(["@tsl//tsl/platform:tensor_float_32_utils"]),
)
cc_library(
name = "tf_stablehlo",
srcs = [
"transforms/tf_stablehlo_pass.cc",
],
hdrs = [
"transforms/tf_stablehlo_pass.h",
],
compatible_with = get_compatible_with_portable(),
copts = [
"-Ithird_party",
],
visibility = ["//visibility:public"],
deps = [
":legalize_tf",
"//tensorflow/compiler/mlir/tensorflow",
"//tensorflow/compiler/mlir/tensorflow/transforms:lower_tf_lib",
"//tensorflow/compiler/mlir/tf2xla/transforms:xla_legalize_tf_with_tf2xla",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:ArithDialect",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:ShapeDialect",
"@llvm-project//mlir:TensorDialect",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@stablehlo//:chlo_ops",
"@stablehlo//:register",
"@xla//xla/mlir_hlo",
"@xla//xla/mlir_hlo:hlo_dialect_registration",
"@xla//xla/mlir_hlo:mhlo_passes",
"@xla//xla/mlir_hlo:type_conversion",
],
alwayslink = 1,
)
# LINT.IfChange(legalize_tf_xla_call_module_to_stablehlo_pass)
cc_library(
name = "legalize_tf_xla_call_module_to_stablehlo_pass",
srcs = [
"transforms/legalize_tf_xla_call_module_to_stablehlo_pass.cc",
],
hdrs = [
"transforms/legalize_tf_xla_call_module_to_stablehlo_pass.h",
],
compatible_with = get_compatible_with_portable(),
copts = [
"-Ithird_party",
],
deps = [
"//tensorflow/compiler/mlir/tensorflow",
"@com_google_absl//absl/strings",
"@com_google_absl//absl/strings:string_view",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:QuantOps",
"@llvm-project//mlir:ShapeDialect",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@stablehlo//:stablehlo_ops",
"@stablehlo//:stablehlo_serialization",
"@stablehlo//:vhlo_ops",
],
alwayslink = 1,
)
# LINT.ThenChange(//tensorflow/compiler/mlir/lite/stablehlo:legalize_tf_xla_call_module_to_stablehlo_pass)
cc_library(
name = "fuse_convolution_pass",
srcs = [
"transforms/mhlo_passes/fuse_convolution_pass.cc",
],
hdrs = [
"transforms/mhlo_passes/fuse_convolution_pass.h",
],
compatible_with = get_compatible_with_portable(),
copts = [
"-Ithird_party",
],
visibility = ["//visibility:public"],
deps = [
"//tensorflow/compiler/mlir/quantization/common:attrs_and_constraints",
"//tensorflow/compiler/mlir/utils:validators",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:Dialect",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:ShapeDialect",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TransformUtils",
"@llvm-project//mlir:Transforms",
"@xla//xla/mlir_hlo",
],
alwayslink = 1,
)
cc_library(
name = "unfuse_batch_norm_pass",
srcs = [
"transforms/mhlo_passes/unfuse_batch_norm_pass.cc",
],
hdrs = [
"transforms/mhlo_passes/unfuse_batch_norm_pass.h",
],
compatible_with = get_compatible_with_portable(),
copts = [
"-Ithird_party",
],
visibility = ["//visibility:public"],
deps = [
"//tensorflow/compiler/mlir/tensorflow:tensorflow_ops",
"//tensorflow/compiler/mlir/tensorflow:tensorflow_types",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:ShapeDialect",
"@llvm-project//mlir:Support",
"@llvm-project//mlir:TransformUtils",
"@xla//xla/mlir_hlo",
],
alwayslink = 1,
)
cc_library(
name = "rename_entrypoint_to_main",
srcs = [
"transforms/rename_entrypoint_to_main.cc",
],
hdrs = [
"transforms/rename_entrypoint_to_main.h",
],
compatible_with = get_compatible_with_portable(),
copts = [
"-Ithird_party",
],
visibility = ["//visibility:public"],
deps = [
"//tensorflow/compiler/mlir/tensorflow",
"@llvm-project//llvm:Support",
"@llvm-project//mlir:FuncDialect",
"@llvm-project//mlir:IR",
"@llvm-project//mlir:Pass",
"@llvm-project//mlir:Support",
],
alwayslink = 1,
)