diff --git a/.bazelrc b/.bazelrc index e53174d04fc..829e267ab60 100644 --- a/.bazelrc +++ b/.bazelrc @@ -18,6 +18,7 @@ build --flag_alias=release_dpc=@config//:release_dpc build --flag_alias=device=@config//:device build --flag_alias=cpu=@config//:cpu build --flag_alias=enable_assert=@config//:enable_assert +build --flag_alias=stdalloc=@config//:stdalloc # Always pass this env variable to test rules, because SYCL # OpenCL backend uses it to determine available devices diff --git a/.ci/pipeline/ci.yml b/.ci/pipeline/ci.yml index 95d34a2c8b8..dacac7b63a5 100755 --- a/.ci/pipeline/ci.yml +++ b/.ci/pipeline/ci.yml @@ -438,6 +438,9 @@ jobs: echo "Checking Bazel config: release-dpc" bazel build --nobuild :release --config=release-dpc --cpu=all + echo "Checking Bazel config: stdalloc" + bazel build --nobuild :release --stdalloc=true --release_dpc=false + echo "Checking Bazel config: dev" bazel build --nobuild //cpp/oneapi/dal:tests --config=dev displayName: 'Bazel config smoke checks' diff --git a/cpp/daal/BUILD b/cpp/daal/BUILD index 78f6939dcad..b09a1270c52 100644 --- a/cpp/daal/BUILD +++ b/cpp/daal/BUILD @@ -156,6 +156,9 @@ daal_module( daal_module( name = "threading_tbb", srcs = glob(["src/threading/**/*.cpp"]), + # Match Make STDALLOC=yes: separately built threading objects keep TBB + # scalable allocation while core objects switch away from MKL allocation. + stdalloc = False, visibility_hidden = False, local_defines = [ "__TBB_NO_IMPLICIT_LINKAGE", diff --git a/dev/bazel/README.md b/dev/bazel/README.md index c415e0dc28a..fa185e14285 100644 --- a/dev/bazel/README.md +++ b/dev/bazel/README.md @@ -263,6 +263,14 @@ The most used Bazel commands are `build`, `test` and `run`. bazel test --test_disable_fp64 //cpp/oneapi/dal/algo/pca:tests ``` +- `--stdalloc` Selects standard-library aligned allocation for DAAL core + objects. Disabled by default and supported only for Linux targets. + + Example: + ```sh + bazel build //cpp/daal:core_static --stdalloc=true + ``` + ## Build recipes for oneDAL ### Build release artifacts - To build the Bazel release artifacts, run: @@ -448,6 +456,27 @@ dal_test_suite( ## What is missing in this guide - How to get make-like release structure +## Standard-library allocator + +For Linux DAAL core objects, this is equivalent to the allocator-selection +part of Make `STDALLOC=yes`: + +```sh +bazel build //:release --stdalloc=true +``` + +The option is disabled by default. When enabled, Bazel defines +`USE_STD_ALLOC` only while compiling DAAL core objects, switching the MKL +allocation wrappers to `std::aligned_alloc` and `std::free`. It intentionally +does not define the macro for the separately built `threading_tbb` objects; +this matches the current Make target-specific flag scope, so the threading +library continues to use TBB scalable allocation. + +The setting rejects every non-Linux target because this allocator path is +currently supported only on Linux. It controls allocator selection only. Make +builds with `COMPILER=icx STDALLOC=yes` additionally pass +`-static-libstdc++`; `--stdalloc=true` does not change Bazel link options. + ## Debug and Sanitizer Builds ### Debug build with assertions @@ -631,6 +660,7 @@ build --linkopt=-your-link-flag | `REQSAN=undefined` | `--config=ubsan` | UBSan | | `REQSAN=memory` | `--config=msan` | MemorySanitizer (Clang/LLVM + lld; instrumented dependencies recommended) | | `REQSAN=type` | `--config=type` | TypeSanitizer; Clang-only; GCC/ICPX unsupported | +| `STDALLOC=yes` | `--stdalloc=true` | Allocator-selection equivalent for Linux DAAL core objects; threading objects unchanged. Make ICX also adds `-static-libstdc++` | | `COMPILER=gnu` | `CC=gcc bazel build ...` | Override compiler via `CC` env | | `OPTFLAG=O2` | `--copt=-O2` | Override optimization level | | `COPT=-flag` | `--copt=-flag` (C+C++) / `--cxxopt=-flag` (C++ only) | Arbitrary compiler flag | diff --git a/dev/bazel/config/config.bzl b/dev/bazel/config/config.bzl index 24b773cd4eb..f6057778ad3 100644 --- a/dev/bazel/config/config.bzl +++ b/dev/bazel/config/config.bzl @@ -70,6 +70,16 @@ config_bool_flag = rule( build_setting = config.bool(flag = True), ) +def _unsupported_config_impl(ctx): + fail(ctx.attr.message) + +unsupported_config = rule( + implementation = _unsupported_config_impl, + attrs = { + "message": attr.string(mandatory = True), + }, +) + CpuInfo = provider( fields = [ "enabled", diff --git a/dev/bazel/config/config.tpl.BUILD b/dev/bazel/config/config.tpl.BUILD index da233e846f8..218434473a2 100644 --- a/dev/bazel/config/config.tpl.BUILD +++ b/dev/bazel/config/config.tpl.BUILD @@ -5,6 +5,7 @@ load("@onedal//dev/bazel/config:config.bzl", "config_flag", "config_bool_flag", "dump_config_info", + "unsupported_config", ) cpu_info( @@ -138,6 +139,33 @@ config_bool_flag( build_setting_default = False, ) +config_bool_flag( + name = "stdalloc", + build_setting_default = False, +) + +config_setting( + name = "stdalloc_enabled", + flag_values = { + ":stdalloc": "True", + }, + constraint_values = [ + "@platforms//os:linux", + ], +) + +config_setting( + name = "stdalloc_disabled", + flag_values = { + ":stdalloc": "False", + }, +) + +unsupported_config( + name = "stdalloc_non_linux_error", + message = "--stdalloc=true is supported only when targeting Linux", +) + config_setting( name = "assert_enabled", flag_values = { diff --git a/dev/bazel/daal.bzl b/dev/bazel/daal.bzl index bd0d8379b12..20147a41f48 100644 --- a/dev/bazel/daal.bzl +++ b/dev/bazel/daal.bzl @@ -30,13 +30,19 @@ load("@onedal//dev/bazel/config:config.bzl", def daal_module(name, features=[], lib_tag="daal", hdrs=[], srcs=[], auto=False, - local_defines=[], copts=[], visibility_hidden=True, **kwargs): + local_defines=[], copts=[], visibility_hidden=True, + stdalloc=True, **kwargs): if auto: auto_hdrs = native.glob(["**/*.h", "**/*.i"], allow_empty=True,) auto_srcs = native.glob(["**/*.cpp"], allow_empty=True,) else: auto_hdrs = [] auto_srcs = [] + deps = kwargs.pop("deps", []) + select({ + "@config//:stdalloc_enabled": [], + "@config//:stdalloc_disabled": [], + "//conditions:default": ["@config//:stdalloc_non_linux_error"], + }) cc_module( name = name, lib_tag = lib_tag, @@ -52,6 +58,7 @@ def daal_module(name, features=[], lib_tag="daal", }, hdrs = auto_hdrs + hdrs, srcs = auto_srcs + srcs, + deps = deps, copts = copts + (select({ "@platforms//os:windows": ["/utf-8"], "//conditions:default": ["-fvisibility=hidden", "-fvisibility-inlines-hidden"], @@ -62,7 +69,10 @@ def daal_module(name, features=[], lib_tag="daal", local_defines = select({ "@config//:assert_enabled": local_defines + ["__DAAL_IMPLEMENTATION", "DEBUG_ASSERT=1"], "//conditions:default": local_defines + ["__DAAL_IMPLEMENTATION"], - }) + select({ + }) + (select({ + "@config//:stdalloc_enabled": ["USE_STD_ALLOC"], + "//conditions:default": [], + }) if stdalloc else []) + select({ "@config//:backend_ref": [ "DAAL_REF", ],