diff --git a/.bazelrc b/.bazelrc index c929a2154bb..9672ae934d4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -110,3 +110,22 @@ build:dpc-private \ test:dpc-private \ --test_tag_filters="dpc,-public" + + +# Configuration: 'release' +# The //:release target automatically builds all ISA variants when +# --cpu is unset (auto), and includes DPC++ libs by default. +# Use --cpu= to restrict ISAs for CI speed, or --release_dpc=false +# to disable DPC++ libs. +# bazel build //:release # CPU + DPC++, all ISAs +# bazel build //:release --release_dpc=false # CPU only, all ISAs +# bazel build //:release --cpu=avx2 # CI: avx2 only + + +# Configuration: 'dev' +# Fast local development build — compiles only for the host machine's +# highest ISA (auto-detected). Use this to speed up iterative builds. +# NOT suitable for release/packaging. +# bazel build //cpp/oneapi/dal:tests --config=dev +build:dev \ + --cpu=auto diff --git a/.ci/pipeline/ci.yml b/.ci/pipeline/ci.yml index 02f5a2b205b..de5b728776c 100755 --- a/.ci/pipeline/ci.yml +++ b/.ci/pipeline/ci.yml @@ -289,7 +289,7 @@ jobs: displayName: 'bazel-configure' - script: | - bazel build :release + bazel build :release --release_dpc=false displayName: 'release' - script: | diff --git a/.github/workflows/docker-validation-nightly.yml b/.github/workflows/docker-validation-nightly.yml index 4009362a260..3e2cef1679b 100644 --- a/.github/workflows/docker-validation-nightly.yml +++ b/.github/workflows/docker-validation-nightly.yml @@ -75,9 +75,11 @@ jobs: mkdir -p ${{ github.workspace }}/bazel-cache docker run \ - -v ${{ github.workspace }}/bazel-cache:/root/.cache/bazel \ + -v ${{ github.workspace }}/bazel-cache:/root/.cache/bazel-disk \ onedal-dev sh -c " # Use external disk cache - echo 'build --disk_cache=/root/.cache/bazel' > ~/.bazelrc - bazel build :release + echo 'build --disk_cache=/root/.cache/bazel-disk' > ~/.bazelrc + # In CI we build for avx2 only (override default "all" ISA release build). + # For a full release with all ISA variants, omit --cpu or use --cpu=all. + bazel build :release --cpu=avx2 --release_dpc=false " diff --git a/cpp/daal/BUILD b/cpp/daal/BUILD index 624977782ab..2dbee6cb243 100644 --- a/cpp/daal/BUILD +++ b/cpp/daal/BUILD @@ -1,4 +1,5 @@ package(default_visibility = ["//visibility:public"]) +load("@rules_shell//shell:sh_test.bzl", "sh_test") load("@onedal//dev/bazel:dal.bzl", "dal_test_suite", "dal_collect_test_suites", @@ -11,7 +12,6 @@ load("@onedal//dev/bazel:daal.bzl", "daal_generate_version", "daal_patch_kernel_defines", ) -load("@rules_shell//shell:sh_test.bzl", "sh_test") daal_module( name = "microvmlipp", @@ -317,3 +317,10 @@ sh_test( }) + ["@platforms//os:linux"], ) +sh_test( + name = "isa_coverage_test", + srcs = ["@onedal//dev/bazel/tests:isa_coverage_test.sh"], + args = ["$(location :core_dynamic)"], + data = [":core_dynamic"], + target_compatible_with = ["@platforms//os:linux"], +) diff --git a/dev/bazel/README.md b/dev/bazel/README.md index b8166b7415e..ffd99347ae6 100644 --- a/dev/bazel/README.md +++ b/dev/bazel/README.md @@ -226,6 +226,22 @@ The most used Bazel commands are `build`, `test` and `run`. ``` ## Build recipes for oneDAL +### Build release artifacts +- To build the library release artifacts (similar to Make build), run: + ```sh + bazel build //:release + ``` + This automatically builds all required ISA variants (SSE2, SSE4.2, AVX2, AVX-512) and includes DPC++ libraries by default. + + - To build for a specific CPU architecture only (useful for speeding up CI), use `--cpu`: + ```sh + bazel build //:release --cpu=avx2 + ``` + - To disable building DPC++ libraries, use `--release_dpc=false`: + ```sh + bazel build //:release --release_dpc=false + ``` + ### Run oneAPI examples - To run all oneAPI C++ example use the following commands: ```sh diff --git a/dev/bazel/config/config.tpl.BUILD b/dev/bazel/config/config.tpl.BUILD index 83cd06bf9c2..9271d23986f 100644 --- a/dev/bazel/config/config.tpl.BUILD +++ b/dev/bazel/config/config.tpl.BUILD @@ -117,7 +117,7 @@ config_setting( config_bool_flag( name = "release_dpc", - build_setting_default = False, + build_setting_default = True, ) config_bool_flag( diff --git a/dev/bazel/release.bzl b/dev/bazel/release.bzl index c11a19d0b8b..0f1bfc9b9bb 100644 --- a/dev/bazel/release.bzl +++ b/dev/bazel/release.bzl @@ -18,6 +18,23 @@ load("@onedal//dev/bazel:utils.bzl", "utils", "paths") load("@onedal//dev/bazel:cc.bzl", "ModuleInfo") load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") +# Transition: force --cpu=all when building release libs, +# unless --cpu is explicitly overridden (e.g. --cpu=avx2 in CI). +# This ensures bazel build //:release compiles all ISA variants +# (sse2, sse42, avx2, avx512) by default without any extra flags. +def _release_cpu_all_impl(settings, attr): + current = settings["@config//:cpu"] + # Respect explicit --cpu flag; only force "all" for the default "auto". + if current == "auto": + return {"@config//:cpu": "all"} + return {"@config//:cpu": current} + +_release_cpu_all_transition = transition( + implementation = _release_cpu_all_impl, + inputs = ["@config//:cpu"], + outputs = ["@config//:cpu"], +) + def _match_file_name(file, entries): for entry in entries: if entry in file.path: @@ -94,10 +111,10 @@ def _copy_to_release_impl(ctx): _release = rule( implementation = _copy_to_release_impl, attrs = { - "include": attr.label_list(allow_files=True), + "include": attr.label_list(allow_files=True, cfg=_release_cpu_all_transition), "include_prefix": attr.string_list(), "include_skip_prefix": attr.string_list(), - "lib": attr.label_list(allow_files=True), + "lib": attr.label_list(allow_files=True, cfg=_release_cpu_all_transition), }, toolchains = [ "@onedal//dev/bazel/toolchains:extra" diff --git a/dev/bazel/tests/BUILD b/dev/bazel/tests/BUILD index 80b332561b7..c60ff60fdd7 100644 --- a/dev/bazel/tests/BUILD +++ b/dev/bazel/tests/BUILD @@ -1,3 +1,6 @@ package(default_visibility = ["//visibility:public"]) -exports_files(["mkl_linkage_test.sh"]) +exports_files([ + "isa_coverage_test.sh", + "mkl_linkage_test.sh", +]) diff --git a/dev/bazel/tests/isa_coverage_test.sh b/dev/bazel/tests/isa_coverage_test.sh new file mode 100644 index 00000000000..9c09fa3bfcb --- /dev/null +++ b/dev/bazel/tests/isa_coverage_test.sh @@ -0,0 +1,69 @@ +#!/usr/bin/env bash +#=============================================================================== +# Copyright contributors to the oneDAL project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +#=============================================================================== +# +# Verifies that libonedal_core.so contains CPU dispatch symbols for all +# required ISA variants: sse2, sse42, avx2, avx512 (CpuType E0/E2/E4/E6). +# +# Make builds all 4 ISA variants by default. Building via //:release +# automatically compiles all ISA variants (cfg transition on release rule). +# This test enforces that contract. + +set -euo pipefail + +LIB="${1:-}" +if [[ -z "${LIB}" ]]; then + echo "Usage: $0 " + exit 1 +fi + +if [[ ! -f "${LIB}" ]]; then + echo "ERROR: Library not found: ${LIB}" + exit 1 +fi + +PASS=0 +FAIL=0 + +check_isa() { + local cpu_type="$1" # e.g. CpuTypeE2 + local isa_name="$2" # e.g. sse42 + local count + count=$(nm -D "${LIB}" | grep -c "${cpu_type}" || true) + if [[ "${count}" -gt 0 ]]; then + echo " OK ${isa_name} (${cpu_type}): ${count} dispatch symbols" + PASS=$((PASS + 1)) + else + echo " FAIL ${isa_name} (${cpu_type}): 0 dispatch symbols found" + echo " Build via //:release (uses all ISAs via cfg transition) or pass --cpu=all" + FAIL=$((FAIL + 1)) + fi +} + +echo "=== ISA coverage check: $(basename "${LIB}") ===" +check_isa "CpuTypeE0" "sse2" +check_isa "CpuTypeE2" "sse42" +check_isa "CpuTypeE4" "avx2" +check_isa "CpuTypeE6" "avx512" + +echo "" +if [[ "${FAIL}" -gt 0 ]]; then + echo "RESULT: FAILED (${FAIL} ISA(s) missing, ${PASS} present)" + exit 1 +else + echo "RESULT: PASSED (all 4 ISA variants present)" + exit 0 +fi