Skip to content

[chore](build) Build BE against the prebuilt OpenBLAS and datasketches-cpp - #68619

Draft
morningman wants to merge 1 commit into
apache:masterfrom
morningman:be-use-prebuilt-openblas-datasketches
Draft

morningman wants to merge 1 commit into
apache:masterfrom
morningman:be-use-prebuilt-openblas-datasketches

Conversation

@morningman

@morningman morningman commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: N/A

Related PR: #68617 (adds the two libraries to the third-party build; must be merged first), #66511 (moved datasketches-cpp into the BE CMake tree)

Do not merge before #68617 is merged and the prebuilt third-party archives from apache/doris-thirdparty contain libopenblas.a and include/DataSketches. Until then BE fails to build: ninja stops right away with libopenblas.a missing.

Problem Summary:

Context. faiss (the ANN index) links OpenBLAS, and the datasketches_hll_union_agg functions include the datasketches-cpp headers. Both are git submodules under contrib/, fetched by build.sh --be and run-be-ut.sh before every build and built inside the BE build directory: be/src/storage/index/ann/cmake-protect add_subdirectory()s OpenBLAS, and be/CMakeLists.txt add_subdirectory()s datasketches-cpp (header-only). #68617 adds both to thirdparty/, whose prebuilt archives CI and developers already download.

1. The problem, and what it cost

  • On a fresh checkout git submodule update clones the whole apache/doris-thirdparty repository (about 650 MB on GitHub) for contrib/openblas, or downloads a 24.7 MB tarball when the clone fails.
  • Every cold BE build compiles OpenBLAS: 6,725 build steps on macOS arm64, where the rest of the BE is 740 unity steps, and 12,577 on Linux x86_64, where DYNAMIC_ARCH builds kernels for every CPU generation.
  • In ASAN builds OpenBLAS's configure step runs an ASAN-instrumented getarch probe, which is where macOS ASAN builds hung before [fix](build) Move the macOS toolchain to LLVM 22 so ASAN works on macOS 26.4+ #68595.

2. What this PR does, and why it helps

  • be/cmake/thirdparty.cmake imports lib64/libopenblas.a as the openblas target, with NOTADD because only faiss needs it. contrib/faiss already links a target of that name when one exists (it prints Using OpenBLAS target for linking), so faiss itself is unchanged, and cmake-protect no longer configures OpenBLAS.
  • The datasketches-cpp headers come from include/DataSketches and are included as <DataSketches/hll.hpp>, the way BE included them before [Fix](build) Manage datasketches-cpp in the BE CMake build tree #66511. The add_subdirectory() build, its DataSketches::HLL link and the BUILD_TESTS setting it needed go away.
  • build.sh and run-be-ut.sh stop updating the two submodules, and .gitmodules drops them.
  • build.sh drops --enable-dynamic-arch / --disable-dynamic-arch: they only set DYNAMIC_ARCH for the in-tree OpenBLAS, and the third-party build decides that now. (The ENABLE_DYNAMIC_ARCH environment variable they documented was overwritten before it was read.)
  • conf/ubsan_ignorelist.txt drops contrib/openblas: the prebuilt library is not instrumented, like every other third-party library.
  • Comments and docs that named the two submodules are updated (be-ut-mac.yml, compile-bench, fe/.idea/vcs.xml).

What it buys:

3. How the pieces fit

build.sh --be / run-be-ut.sh
  |- update_submodule: contrib/apache-orc, contrib/clucene, contrib/faiss   (openblas, datasketches-cpp removed)
  '- cmake be/
       |- include(cmake/thirdparty.cmake)
       |     '- add_thirdparty(openblas LIB64 NOTADD) -> IMPORTED target `openblas` = installed/lib64/libopenblas.a
       |- include_directories(SYSTEM installed/include)  -> <DataSketches/hll.hpp>
       '- add_subdirectory(src/storage/index/ann)
             |- cmake-protect: add_subdirectory(contrib/faiss)
             |     '- faiss/CMakeLists.txt: elseif(TARGET openblas) -> target_link_libraries(faiss PRIVATE openblas)
             '- ann_index PUBLIC faiss, OpenMP::OpenMP_CXX
  link: doris_be <- ann_index <- faiss <- libopenblas.a (static, OpenMP) + the OpenMP runtime

Not touched: faiss, apache-orc and clucene stay submodules; the BE source only changes the include path of hll.hpp in two files.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
      • macOS arm64: with the two libraries from build-thirdparty.sh, build.sh --be (Release, clang 20) builds and links doris_be. faiss is configured with the imported target (Using OpenBLAS target for linking), and doris_be resolves sgemm_, ssyrk_ and dsyev_ from the prebuilt libopenblas.a. The libfaiss.a of that build, linked against the prebuilt library, passes the smoke test described in [chore](thirdparty) Add OpenBLAS and datasketches-cpp to the third-party build #68617 (sgemm, ssyrk + dsyev, sgesvd, IVF-PQ under OpenMP).
      • build-support/check-build-hygiene.sh passes; clang-format 16 reports no changes to the two C++ files.
      • CI cannot build this PR until the prebuilt archives carry the two libraries.
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes. build.sh no longer accepts --enable-dynamic-arch or --disable-dynamic-arch. A BE build needs a third-party tree that contains OpenBLAS and datasketches-cpp: refresh the prebuilt package, or run thirdparty/build-thirdparty.sh openblas datasketches.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@morningman

Copy link
Copy Markdown
Contributor Author

Folded into #68617, which now carries the third-party and the BE changes as a single commit.

@morningman morningman closed this Sep 29, 2026
…s-cpp

### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#68617 (adds the two libraries to the third-party build)

Problem Summary:

contrib/openblas and contrib/datasketches-cpp are git submodules that
`build.sh --be` and `run-be-ut.sh` update on every run. On a fresh checkout that
clones the whole apache/doris-thirdparty repository for contrib/openblas (about
650 MB on GitHub), or downloads a 24.7 MB tarball when the clone fails. Every
cold BE build then compiles OpenBLAS in its build directory: 6,725 build steps
on macOS arm64, where the rest of the BE is 740 unity steps, and 12,577 on Linux
x86_64, where DYNAMIC_ARCH builds kernels for every CPU generation. apache#68617 adds
both libraries to the third-party build; this PR builds the BE against them and
removes the submodules.

- be/cmake/thirdparty.cmake imports lib64/libopenblas.a as the `openblas`
  target, with NOTADD because only faiss needs it. contrib/faiss already links
  a target of that name when one exists, so faiss itself is unchanged, and the
  cmake-protect directory no longer configures OpenBLAS.
- The datasketches-cpp headers come from include/DataSketches and are included
  as <DataSketches/hll.hpp>, the way BE included them before apache#66511. The
  add_subdirectory() build and its DataSketches::HLL link go away.
- build.sh and run-be-ut.sh stop updating the two submodules, and .gitmodules
  drops them. build.sh drops --enable-dynamic-arch / --disable-dynamic-arch,
  which only set DYNAMIC_ARCH for the in-tree OpenBLAS; the third-party build
  decides that now. (The ENABLE_DYNAMIC_ARCH environment variable they
  documented was overwritten before it was read.)
- conf/ubsan_ignorelist.txt drops contrib/openblas: the prebuilt library is not
  instrumented, like every other third-party library.
- Comments and docs that named the two submodules are updated.

A side effect on macOS: the in-tree OpenBLAS configure step ran an
ASAN-instrumented getarch probe, which is where ASAN builds hung on macOS 26.4+
with llvm@20. BE builds no longer run it.

A BE build needs a third-party tree that has the two libraries, so this lands
only after the prebuilt packages have been refreshed; a local tree can add them
with `thirdparty/build-thirdparty.sh openblas datasketches`. Without them the BE
build stops before compiling anything, with ninja reporting libopenblas.a as
missing.

### Release note

None

### Check List (For Author)

- Test: Manual test
    - macOS arm64: with the two libraries from build-thirdparty.sh,
      `build.sh --be` (Release, clang 20) builds and links doris_be. faiss is
      configured with the imported target ("Using OpenBLAS target for
      linking"), and doris_be resolves sgemm_, ssyrk_ and dsyev_ from the
      prebuilt libopenblas.a. The libfaiss.a of this build, linked against the
      prebuilt library, passes the smoke test described in apache#68617.
    - build-support/check-build-hygiene.sh passes; clang-format 16 reports no
      changes to the two C++ files.
- Behavior changed: Yes. build.sh no longer accepts --enable-dynamic-arch or
  --disable-dynamic-arch, and a BE build needs a third-party tree that contains
  OpenBLAS and datasketches-cpp.
- Does this need documentation: No

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@morningman

Copy link
Copy Markdown
Contributor Author

Reopened: the change is split again. #68617 now carries only the third-party part; this PR carries the BE side and waits for #68617 and the refreshed prebuilt archives.

@morningman morningman reopened this Sep 29, 2026
morningman added a commit to morningman/doris that referenced this pull request Sep 29, 2026
…rty build

### What problem does this PR solve?

Issue Number: N/A

Related PR: apache#68619 (switches BE to these packages)

Problem Summary:

OpenBLAS (which faiss uses for the ANN index) and datasketches-cpp are git
submodules under contrib/. Every `build.sh --be` and `run-be-ut.sh` runs
`git submodule update` on them; on a fresh checkout that clones the whole
apache/doris-thirdparty repository for contrib/openblas (about 650 MB on
GitHub), or downloads a 24.7 MB tarball when the clone fails. Every cold BE
build then compiles OpenBLAS in its build directory: 6,725 build steps on macOS
arm64, where the rest of the BE is 740 unity steps, and 12,577 on Linux x86_64,
where DYNAMIC_ARCH builds kernels for every CPU generation. Doris does not
modify either library, so both belong in the third-party build like the other
dependencies. This PR adds them there. apache#68619 switches BE over and removes the
submodules; it can only land after the prebuilt third-party packages carry the
two libraries.

OpenBLAS 0.3.30 comes from the upstream release. The doris-thirdparty openblas
branch is that release plus two build-only edits (it forces
`-O3 -Wno-everything` so that the in-tree Debug and ASAN builds compile, and it
comments out a CMake message); every other file is identical, and a Release
third-party build compiles with -O3 anyway. It is configured the way
be/src/storage/index/ann/cmake-protect configured the in-tree build: static,
LAPACK built from its C translation plus ReLAPACK, no CBLAS, no Fortran, OpenMP
threading, no AVX-512. Three settings that the in-tree build took from the
machine running it are pinned, since a prebuilt archive is built on a CI runner
and then runs everywhere:

- NUM_THREADS=128. It defaults to the build host's core count and caps the
  threads one call can use at run time, so a 4-vCPU runner would cap it at 4.
- DYNAMIC_ARCH on Linux, now on aarch64 too, so the kernels are chosen on the
  CPU that runs BE. On aarch64 the in-tree build compiled for the build host
  only. The arm64 prebuilt is built on GitHub's Cobalt 100 (Neoverse N2)
  runners, and when OpenBLAS detects that core it compiles the whole library
  with -march=armv8.5-a+sve+sve2, which faults on Graviton2, Ampere Altra or
  Kunpeng 920.
- TARGET, the CPU the code outside the kernels is compiled for, which also
  follows the build host unless set (OpenBLAS's README recommends setting it
  with DYNAMIC_ARCH): HASWELL, or NEHALEM plus NO_AVX/NO_AVX2 when USE_AVX2=0
  as cmake-protect did, and ARMV8 on aarch64, the same baselines BE uses.

With gcc the build names the OpenMP flag and library itself. gcc in the LDB
toolchain v0.25, which the Linux job of build-thirdparty.yml builds with, is
configured for offloading (--enable-offload-targets=nvptx-none) but ships no
crtoffloadbegin.o or crtoffloadend.o, so every link with -fopenmp fails and so
does FindOpenMP's probe. Compiling with -fopenmp works, and a static library is
never linked.

macOS keeps host detection, as before. Homebrew's LLVM ships no OpenMP
runtime, so the build points FindOpenMP at Homebrew's libomp, the runtime BE
already links on macOS, and stops with an explicit message when it is not
installed. The macOS jobs of build-thirdparty.yml install it. The
apache/doris-thirdparty automation installs its own macOS packages and needs
the same addition before this lands, or its macOS legs fail at this package.

datasketches-cpp is pinned to 46025e9, the commit contrib/ pins, because no
release carries its HLL union fix yet. It is header-only and installs into
include/DataSketches, where BE included it from before apache#66511.

### Release note

None

### Check List (For Author)

- Test: Manual test
    - macOS arm64, clang 20: `build-thirdparty.sh openblas datasketches` with
      no libomp flags in the environment, as on CI. With a stubbed `brew` that
      has no libomp, the build stops with the explicit message.
    - Linux x86_64 in apache/doris:build-env-ldb-toolchain-latest:
      `DORIS_TOOLCHAIN=clang build-thirdparty.sh openblas datasketches`, the
      configuration of the doris-thirdparty automation; faiss built against
      the result passes the smoke test below. At run time DYNAMIC_ARCH picks
      the Nehalem kernels on the Rosetta-emulated CPU, and the library reports
      MAX_THREADS=128.
    - aarch64 DYNAMIC_ARCH with TARGET=ARMV8 and clang 20 (on the macOS host,
      as there is no aarch64 Linux image with the toolchain here): all 14 cores
      compile, the SVE and SME ones included, and on a CPU without SVE the
      library selects neoversen1 and passes the smoke test.
    - Smoke test: faiss linked against the prebuilt libopenblas.a runs
      IndexFlatL2 search (sgemm), PCA training (ssyrk + dsyev; the eigenvalues
      add up to the trace), OPQ training (sgesvd; the rotation is orthonormal
      to 1e-6) and IVF-PQ training and search under OpenMP, all correct.
    - Linux x86_64 in the same image with DORIS_TOOLCHAIN=gcc, the
      configuration of the Linux job of build-thirdparty.yml: without the
      explicit OpenMP settings configure fails with "Could NOT find OpenMP_C";
      with them both packages build. The gcc-built library calls the GOMP_*
      entry points; faiss built with clang against it passes the smoke test
      with the LDB libomp supplying them, so a third-party tree built with gcc
      still links into a clang-built BE.
    - The OpenBLAS 0.3.30 release differs from the doris-thirdparty openblas
      branch only in the edits described above (`diff -r`).
    - thirdparty/test: the download fallback, md5, juicefs mirror, azure retry
      and adbc JNI configuration tests pass.
- Behavior changed: No. Nothing uses the new packages yet.
- Does this need documentation: No

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@morningman
morningman force-pushed the be-use-prebuilt-openblas-datasketches branch from 392c6fa to 76ab92d Compare September 29, 2026 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants