From cb82c790d50dd87f301df67b710161906dafb0c2 Mon Sep 17 00:00:00 2001 From: Isaac Torres Date: Wed, 8 Nov 2023 11:26:06 -0800 Subject: [PATCH] third_party: make mkl a constraint [DIP-196] (#103) We need to model mkl version of the build as a proper platform with a toolchain - See: https://bazel.build/extending/platforms for more details. Not having this in place is what caused our multi-arch builds to be built against vanilla x86 without mkl --- cc/repositories.bzl | 1 + cc/toolchains/llvm/x86_64-linux/BUILD.bazel | 16 ++++++++++++++++ platforms/BUILD.bazel | 9 +++++++++ third_party/BUILD.bazel | 8 ++++++++ third_party/eigen.BUILD | 2 ++ 5 files changed, 36 insertions(+) diff --git a/cc/repositories.bzl b/cc/repositories.bzl index ac39c79..4608083 100644 --- a/cc/repositories.bzl +++ b/cc/repositories.bzl @@ -102,6 +102,7 @@ def register_swift_cc_toolchains(): native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-darwin:cc-toolchain-x86_64-darwin") native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/aarch64-linux:cc-toolchain-aarch64-linux") native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-x86_64-linux") + native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-linux:cc-toolchain-intel-mkl") native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-aarch64-linux:cc-toolchain-aarch64-bullseye-graviton2") native.register_toolchains("@rules_swiftnav//cc/toolchains/llvm/x86_64-aarch64-linux:cc-toolchain-aarch64-bullseye-graviton3") diff --git a/cc/toolchains/llvm/x86_64-linux/BUILD.bazel b/cc/toolchains/llvm/x86_64-linux/BUILD.bazel index 408e9cd..552aa5f 100644 --- a/cc/toolchains/llvm/x86_64-linux/BUILD.bazel +++ b/cc/toolchains/llvm/x86_64-linux/BUILD.bazel @@ -177,3 +177,19 @@ toolchain( toolchain = ":cc-clang-x86_64-linux", toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", ) + +toolchain( + name = "cc-toolchain-intel-mkl", + exec_compatible_with = [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + ], + target_compatible_with = [ + "@platforms//cpu:x86_64", + "@platforms//os:linux", + "//third_party:intel_mkl", + ], + target_settings = None, + toolchain = ":cc-clang-x86_64-linux", + toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", +) diff --git a/platforms/BUILD.bazel b/platforms/BUILD.bazel index 615eb98..85df801 100644 --- a/platforms/BUILD.bazel +++ b/platforms/BUILD.bazel @@ -100,6 +100,15 @@ platform( visibility = ["//visibility:public"], ) +platform( + name = "intel_mkl", + constraint_values = [ + "@platforms//os:linux", + "//third_party:intel_mkl", + "@platforms//cpu:x86_64", + ], +) + platform( name = "x86_64_linux_musl", constraint_values = [ diff --git a/third_party/BUILD.bazel b/third_party/BUILD.bazel index 8385a89..97b02b4 100644 --- a/third_party/BUILD.bazel +++ b/third_party/BUILD.bazel @@ -10,6 +10,14 @@ load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") +constraint_setting(name = "intel") + +constraint_value( + name = "intel_mkl", + constraint_setting = ":intel", + visibility = ["//visibility:public"], +) + bool_flag( name = "enable_mkl", build_setting_default = False, diff --git a/third_party/eigen.BUILD b/third_party/eigen.BUILD index 7f99b88..c68f0b1 100644 --- a/third_party/eigen.BUILD +++ b/third_party/eigen.BUILD @@ -18,11 +18,13 @@ cc_library( defines = [ "EIGEN_NO_DEBUG", ] + select({ + "@rules_swiftnav//third_party:intel_mkl": ["EIGEN_USE_MKL_ALL"], "@rules_swiftnav//third_party:_enable_mkl": ["EIGEN_USE_MKL_ALL"], "//conditions:default": [], }), includes = ["."], deps = select({ + "@rules_swiftnav//third_party:intel_mkl": ["@mkl"], "@rules_swiftnav//third_party:_enable_mkl": ["@mkl"], "//conditions:default": [], }),