Skip to content

CPUArch dispatching and unified shared library #113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 97 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
9378b05
Initial implementation of CPUArch dispatcher and unified shared library
Alexsandruss Apr 23, 2025
d812859
Fix cpuid header
Alexsandruss Apr 23, 2025
08a272e
Remove dynamic _svs_* loading
Alexsandruss Apr 23, 2025
c7343aa
Remove tests for _svs_* loader
Alexsandruss Apr 23, 2025
56a84e7
TEMP: enable cmake verbosity options
Alexsandruss Apr 24, 2025
6cecfed
Correct instantiation macros workflow
Alexsandruss Apr 24, 2025
edd5c9b
Extend support to L2 and IP distances
Alexsandruss Apr 24, 2025
5ae4861
Revert "TEMP: enable cmake verbosity options"
Alexsandruss Apr 24, 2025
c8c9190
Extend x86_64 archs check
Alexsandruss Apr 25, 2025
43ee728
Remove pybind11 module name define
Alexsandruss Apr 25, 2025
f42bece
Linting and other fixes
Alexsandruss Apr 28, 2025
2ebee92
Enable microarch dispatcher for all build targets
Alexsandruss Apr 29, 2025
83588cf
Install archspec in all github workflows;
Alexsandruss Apr 29, 2025
27790b8
Add error message for unknown CMAKE_SYSTEM_PROCESSOR
Alexsandruss Apr 29, 2025
5fe8239
Fixes for aarch64 uArch targets list
Alexsandruss Apr 29, 2025
8980d7d
Fix license exception
Alexsandruss Apr 29, 2025
0c88c73
Add host microarch output
Alexsandruss Apr 29, 2025
9e2934c
Fix aarch64 support
Alexsandruss Apr 29, 2025
2a4ada7
Fix macOS-ARM support
Alexsandruss Apr 29, 2025
a27aa8b
Fix macOS-ARM support v2
Alexsandruss Apr 30, 2025
4c307f7
Remove unnecessary registers on ARM
Alexsandruss Apr 30, 2025
c2251dd
Change native options in last build target
Alexsandruss Apr 30, 2025
fd675dc
Change macOS-ARM check to based on brand string
Alexsandruss Apr 30, 2025
5ee411e
Align naming: cpuarch -> microarch
Alexsandruss Apr 30, 2025
085114a
Remove uArchs spec in setup.py
Alexsandruss Apr 30, 2025
a86397f
Add basic uArch python bindings;
Alexsandruss May 2, 2025
1f5f531
Restructure cpuid and uArch headers
Alexsandruss May 2, 2025
5570b82
Fix typo in m1 branch
Alexsandruss May 2, 2025
fb277e9
Update x86_64 targets
Alexsandruss May 2, 2025
e45db18
Revert "Update x86_64 targets"
Alexsandruss May 2, 2025
4dfd0ce
Add x86_64_v4 target
Alexsandruss May 6, 2025
30b2fcd
Change MICROARCH_OBJECT_FILES setting
Alexsandruss May 6, 2025
b9167b8
Change microarch Python API
Alexsandruss May 6, 2025
5360dd2
fix: make microarch compatiable with sde usecase
yuejiaointel May 7, 2025
0fbff56
fix: move dispatcher pipeline to public repo
yuejiaointel May 7, 2025
6360464
fix: add compielrs and os to test dispatcher
yuejiaointel May 7, 2025
2d594f5
fix: test x86 only
yuejiaointel May 7, 2025
bb397db
fix: test x86 only
yuejiaointel May 7, 2025
936635a
fix: use actual os name instead of self hosted runners
yuejiaointel May 7, 2025
37184df
fix: checkout erros
yuejiaointel May 7, 2025
a54d187
fix: checkout erros
yuejiaointel May 7, 2025
b3ac750
fix: add comiler matric for x86 targets as well
yuejiaointel May 7, 2025
1095355
add: add cpu name and avx support info print
yuejiaointel May 7, 2025
449d49c
fix: fix cpu info print for arm and macos
yuejiaointel May 8, 2025
687a5fd
fix: format
yuejiaointel May 8, 2025
aa5bf2b
Add microarch_info example
Alexsandruss May 8, 2025
bd4bcef
Merge dispatcher testing with SDE into build-linux pipeline
Alexsandruss May 8, 2025
658c770
Fix typo in pipeline
Alexsandruss May 8, 2025
d520b37
Add `describe` static function to `svs.microarch`and fix pipelines
Alexsandruss May 8, 2025
f3f076b
Remove merged dispatcher testing; macos pipeline fix; test_microarch.…
Alexsandruss May 8, 2025
d07fead
Fix for SDE
Alexsandruss May 8, 2025
e9ee015
Replace x86_64 base uarch (nehalem) with x86_64_v2
Alexsandruss May 12, 2025
ee2309c
Fix for base uarch flags
Alexsandruss May 12, 2025
11c6c09
Exp.: change base uarch to sandybridge
Alexsandruss May 12, 2025
9010819
Exp.: change base uarch to haswell
Alexsandruss May 13, 2025
5d639a5
Revert x86_64 base uarch changes
Alexsandruss May 13, 2025
ce48782
Change template args for DistanceImpl
Alexsandruss May 13, 2025
b1a51c5
Extend macros to correct linking
Alexsandruss May 14, 2025
74dc321
Linting
Alexsandruss May 14, 2025
aea0390
Fix for ARM platforms and correct naming
Alexsandruss May 14, 2025
e539cac
Fix for ARM platforms
Alexsandruss May 14, 2025
ec32357
Finalize tests for CosineSimilarity
ahuber21 May 15, 2025
6bdc0ae
Finalize standard distances
ahuber21 May 15, 2025
f039955
Add uarch tests to scalar.cpp
ahuber21 May 15, 2025
131722c
Merge remote-tracking branch 'origin/main' into dev/ahuber/unified-so…
ahuber21 May 16, 2025
04ae57c
Merge pull request #2 from intel/dev/ahuber/unified-so-with-macros
Alexsandruss May 16, 2025
36eb21c
Minor corrections for uarch-specific assertions
Alexsandruss May 16, 2025
0e31bef
Remove microarch output duplications;
Alexsandruss May 19, 2025
81b7933
Simplify uarch macros
Alexsandruss May 21, 2025
6c566ae
Reduce number of macros per uarch
Alexsandruss May 21, 2025
fef9ce7
Autogeneration of microarch macros
Alexsandruss May 22, 2025
4dad7d1
Update license ignores
Alexsandruss May 22, 2025
b0b5f60
Add registry for static dimensions for dispatching
Alexsandruss May 22, 2025
ecf01d9
Fix for cmake options
Alexsandruss May 22, 2025
85e3a44
Redirect unregistered static n_dims to dynamic in svs::distance::compute
Alexsandruss May 22, 2025
a5b8efb
Fix unused variable error
Alexsandruss May 22, 2025
b4b96f6
Code improvements
Alexsandruss May 23, 2025
bebd267
Code improvements and comments, microarch cmake fix
Alexsandruss May 26, 2025
28001dd
Merge remote-tracking branch 'origin/main' into dev/unified-so
Alexsandruss May 27, 2025
1bb7a1d
Update examples/cpp/shared/CMakeLists.txt
Alexsandruss May 27, 2025
d6397e7
External source files for `create_microarch_instantiations`
Alexsandruss May 28, 2025
7de6be9
Avoid duplicated registry of static dimensions
Alexsandruss May 29, 2025
aa05a37
Parallelize uarch-specific objects building
Alexsandruss May 29, 2025
fdf9768
Merge remote-tracking branch 'origin/main' into dev/unified-so
Alexsandruss Jun 1, 2025
1755d65
Remove SGX requirement for skylake
Alexsandruss Jun 3, 2025
3513e68
Merge remote-tracking branch 'origin/main' into dev/unified-so
Alexsandruss Jun 3, 2025
7131bfc
Simplify microarch options and split base svs target in cmake configs
Alexsandruss Jun 4, 2025
96fe9dd
Fix for cmake exports
Alexsandruss Jun 5, 2025
cd60afb
Update benchmark static dimensions
Alexsandruss Jun 5, 2025
0f60cd1
Fix cmake exports
Alexsandruss Jun 5, 2025
ff0559c
Fix cmake exports
Alexsandruss Jun 5, 2025
51928ac
Set up microarch symbols validation
Alexsandruss Jun 5, 2025
bb79863
Fix path to python script
Alexsandruss Jun 5, 2025
c43f901
Structure microarch cmake options
Alexsandruss Jun 5, 2025
afac126
Fix for cmake exports
Alexsandruss Jun 5, 2025
8ece9d7
Fix for cmake exports
Alexsandruss Jun 5, 2025
6cf042a
Extend SDE python testing with examples
Alexsandruss Jun 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/scripts/get_cpu_info.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash
# Copyright 2025 Intel Corporation
#
# 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.

# Script to get CPU information using platform-agnostic python packages

# Install python packages if not present in the environment
if ! python -m pip show archspec > /dev/null 2>&1; then
python -m pip install archspec
fi

if ! python -m pip show py-cpuinfo > /dev/null 2>&1; then
python -m pip install py-cpuinfo
fi

# Print host microarchitecture
python -c "import archspec.cpu; \
print('Host Microarchitecture[archspec]:', archspec.cpu.host().name)"

# Print full CPU information
python -c "import pprint, cpuinfo; \
print('CPU info[py-cpuinfo]:'); \
pprint.pprint(cpuinfo.get_cpu_info(), indent=4, compact=True)"
19 changes: 19 additions & 0 deletions .github/scripts/install_sde.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
# Copyright 2025 Intel Corporation
#
# 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.

wget --content-disposition "https://downloadmirror.intel.com/850782/sde-external-9.53.0-2025-03-16-lin.tar.xz"
tar -xf sde-external-*-lin.tar.xz
cd sde-external-*/
echo "$PWD" >> $GITHUB_PATH
22 changes: 22 additions & 0 deletions .github/workflows/build-linux-arm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Get CPU info
run: |
bash ${GITHUB_WORKSPACE}/.github/scripts/get_cpu_info.sh

- name: Configure build
working-directory: ${{ runner.temp }}
env:
Expand All @@ -65,8 +69,26 @@ jobs:
working-directory: ${{ runner.temp }}/build
run: make -j$(nproc)

- name: Validate MicroArch symbols
working-directory: ${{ runner.temp }}/build
run: python ${GITHUB_WORKSPACE}/tools/validate_microarch_symbols.py .

- name: Run tests
env:
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{ runner.temp }}/build/tests
run: ctest -C ${{ matrix.build_type }}

- name: Build Python Bindings
env:
CXX: ${{ matrix.cxx }}
CC: ${{ matrix.cc }}
run: |
cd bindings/python
python -m pip install .

- name: Run Python Microarch Test
run: |
cd bindings/python
python -c "import svs; svs.microarch.describe()"
python -m unittest discover -p "test_microarch.py" -s .
29 changes: 29 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ jobs:
source /opt/intel/oneapi/setvars.sh
printenv >> $GITHUB_ENV

- name: Install Intel(R) SDE
run: source ${GITHUB_WORKSPACE}/.github/scripts/install_sde.sh

- name: Get CPU info
run: bash ${GITHUB_WORKSPACE}/.github/scripts/get_cpu_info.sh

- name: Configure build
working-directory: ${{ runner.temp }}
env:
Expand All @@ -75,6 +81,10 @@ jobs:
working-directory: ${{ runner.temp }}/build
run: make -j$(nproc)

- name: Validate MicroArch symbols
working-directory: ${{ runner.temp }}/build
run: python ${GITHUB_WORKSPACE}/tools/validate_microarch_symbols.py .

- name: Run tests
env:
CTEST_OUTPUT_ON_FAILURE: 1
Expand All @@ -86,3 +96,22 @@ jobs:
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{ runner.temp }}/build/examples/cpp
run: ctest -C RelWithDebugInfo

- name: Build Python Bindings
env:
CXX: ${{ matrix.cxx }}
CC: ${{ matrix.cc }}
run: |
cd bindings/python
python -m pip install .

- name: Run Python Microarch Test with SDE
run: |
cd bindings/python
for flag in nhm hsw skx clx icl; do
echo "SDE emulation: $flag"
export SDE_FLAG=$flag
sde64 -$flag -- python -c "import svs; svs.microarch.describe()"
sde64 -$flag -- python -m unittest discover -p "test_microarch.py" -s .
sde64 -$flag -- python -m unittest discover -p "example*.py" -s ${GITHUB_WORKSPACE}/examples/python
done
29 changes: 29 additions & 0 deletions .github/workflows/build-macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Get CPU info
run: |
bash ${GITHUB_WORKSPACE}/.github/scripts/get_cpu_info.sh

- name: Install Compiler
run: |
echo "Installing ${{ matrix.package }}..."
Expand Down Expand Up @@ -83,3 +87,28 @@ jobs:
CTEST_OUTPUT_ON_FAILURE: 1
working-directory: ${{ runner.temp }}/build/tests
run: ctest -C ${{ matrix.build_type }}

- name: Build Python Bindings
env:
CXX: ${{ matrix.cxx }}
CC: ${{ matrix.cc }}
run: |
if [[ "${{ matrix.needs_prefix }}" == "true" ]]; then
# For non-default packages like llvm@15, get the install prefix
COMPILER_PREFIX=$(brew --prefix ${{ matrix.package }})
export CC="${COMPILER_PREFIX}/bin/${{ matrix.cc_name }}"
export CXX="${COMPILER_PREFIX}/bin/${{ matrix.cxx_name }}"
else
# For versioned GCC installs, the name is usually directly available
export CC="${{ matrix.cc_name }}"
export CXX="${{ matrix.cxx_name }}"
fi

cd bindings/python
python -m pip install .

- name: Run Python Microarch Test
run: |
cd bindings/python
python -c "import svs; svs.microarch.describe()"
python -m unittest discover -p "test_microarch.py" -s .
4 changes: 4 additions & 0 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ jobs:
- name: Install cibuildwheel
run: python -m pip install cibuildwheel

- name: Get CPU info
run: |
bash ${GITHUB_WORKSPACE}/.github/scripts/get_cpu_info.sh

# Install inside the temporary working directory.
- name: Build Wheel
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ __pycache__/

# Example generated files.
example_data_*/

# Auto-generated microarch macros header
include/svs/lib/microarch_macros.h
6 changes: 6 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ header:
- 'THIRD-PARTY-PROGRAMS'
- '.github/renovate.json'
- 'cmake/mkl_functions'
- 'cmake/microarch_list_aarch64'
- 'cmake/microarch_list_aarch64_darwin'
- 'cmake/microarch_list_x86_64'
- 'cmake/microarch_targets_aarch64'
- 'cmake/microarch_targets_aarch64_darwin'
- 'cmake/microarch_targets_x86_64'
- 'cmake/patches/tomlplusplus_v330.patch'
- 'docker/x86_64/manylinux2014/oneAPI.repo'
- 'docs/cpp/index/loader-compatibility.csv'
Expand Down
20 changes: 16 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@ set(SVS_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(SVS_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(SVS_VERSION_PATCH ${PROJECT_VERSION_PATCH})

# SVS targets:
# - svs_devel (${SVS_LIB}) - the internal target
# - svs_export (svs::svs) - the exported target for end users of the library
add_library(${SVS_LIB} INTERFACE)
set_target_properties(${SVS_LIB} PROPERTIES EXPORT_NAME svs)
add_library(svs::svs ALIAS ${SVS_LIB})
add_library(svs_export INTERFACE)
set_target_properties(svs_export PROPERTIES EXPORT_NAME svs)
target_link_libraries(svs_export INTERFACE ${SVS_LIB})
add_library(svs::svs ALIAS svs_export)

# Runtime include directories are established in the installation logic.
target_include_directories(
Expand All @@ -61,12 +66,20 @@ target_compile_options(
"-DSVS_VERSION_PATCH=${SVS_VERSION_PATCH}"
)

# Provide microarchitecture-specific template instantiations.
set(SVS_MICROARCH_INSTANCE_FILES
cmake/microarch_instantiations/cosine.cpp
cmake/microarch_instantiations/euclidean.cpp
cmake/microarch_instantiations/inner_product.cpp
)

#####
##### Options and extra build steps
#####

include("cmake/options.cmake")

include("cmake/microarch.cmake")
include("cmake/clang-tidy.cmake")
include("cmake/eve.cmake")
include("cmake/pthread.cmake")
Expand Down Expand Up @@ -112,7 +125,7 @@ set(LIB_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/svs")

# Install headers and target information.
install(
TARGETS svs_devel svs_compile_options svs_native_options
TARGETS svs_export svs_devel svs_compile_options
EXPORT svs-targets
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
Expand Down Expand Up @@ -163,4 +176,3 @@ install(FILES
${SVS_CMAKE_FIND_FILES}
DESTINATION "${LIB_CONFIG_INSTALL_DIR}"
)

6 changes: 4 additions & 2 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,15 @@ endif()
target_link_libraries(
svs_benchmark_library
PUBLIC
${SVS_LIB}
svs::svs
svs_compile_options
svs_native_options
svs_microarch_options_base
fmt::fmt
)

# Build the shared library.
set(EXE_FILES src/main.cpp)
add_executable(svs_benchmark ${EXE_FILES})
target_link_libraries(svs_benchmark PRIVATE svs_benchmark_library)

svs_register_static_dimensions(96 100 128 200 768)
Loading
Loading