Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ target_compile_options(
"-DSVS_VERSION_PATCH=${SVS_VERSION_PATCH}"
)

# Must precede the cmake/*.cmake includes: their install rules get empty, absolute paths otherwise.
include(GNUInstallDirs)

#####
##### Options and extra build steps
#####
Expand Down Expand Up @@ -119,8 +122,6 @@ endif()
##### Install Logic
#####

include(GNUInstallDirs)

# Location of auxiliary generated cmake files to help consumers of this package.
set(LIB_CONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/svs")

Expand All @@ -134,6 +135,7 @@ install(
DIRECTORY "${PROJECT_SOURCE_DIR}/include/svs"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
FILES_MATCHING PATTERN "*.h"
PATTERN "dispatch_surface.h" EXCLUDE
)
install(
EXPORT svs-targets
Expand Down
60 changes: 60 additions & 0 deletions cmake/dispatch-levels.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2026 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.

##
## This is a cmake helper to split a spec provided as `a|b|c`
## into three fields `[a, b, c]`
##

include_guard(GLOBAL)

# Scoped this file via PUSH/POP so it does not affect the includer
cmake_policy(PUSH)
cmake_policy(SET CMP0007 NEW)

# Splits `spec` on '|' into `n` fields
function(svs_split_fields spec n)
string(REPLACE "|" ";" fields "${spec}")
list(LENGTH fields n_fields)
if(NOT n_fields EQUAL n)
message(FATAL_ERROR "Malformed spec '${spec}': expected ${n} '|'-separated fields, got ${n_fields}.")
endif()
math(EXPR last_index "${n} - 1")
foreach(i RANGE 0 ${last_index})
list(GET fields ${i} value)
list(GET ARGN ${i} out_var)
set(${out_var} "${value}" PARENT_SCOPE)
endforeach()
endfunction()

# e.g. svs_parse_isa_level("AVX2|haswell|avx2" level arch infix) sets
# level=AVX2, arch=haswell, infix=avx2
function(svs_parse_isa_level spec out_level out_arch out_infix)
svs_split_fields("${spec}" 3 level arch infix)
set(${out_level} "${level}" PARENT_SCOPE)
set(${out_arch} "${arch}" PARENT_SCOPE)
set(${out_infix} "${infix}" PARENT_SCOPE)
endfunction()

# e.g. svs_parse_tu_spec("avx2.cpp|AVX2|haswell|avx2" src level arch infix) sets
# src=avx2.cpp, level=AVX2, arch=haswell, infix=avx2
function(svs_parse_tu_spec spec out_src out_level out_arch out_infix)
svs_split_fields("${spec}" 4 src level arch infix)
set(${out_src} "${src}" PARENT_SCOPE)
set(${out_level} "${level}" PARENT_SCOPE)
set(${out_arch} "${arch}" PARENT_SCOPE)
set(${out_infix} "${infix}" PARENT_SCOPE)
endfunction()

cmake_policy(POP)
83 changes: 83 additions & 0 deletions cmake/dispatch-surface.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2026 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.

#####
##### The dispatch surface for the x86 distance kernels.
#####
##### This file is the single place the extent list and the ISA levels are
##### written down. Everything derived from them is generated:
#####
##### - svs/core/distance/dispatch_surface.h, which drives every `extern
##### template` and explicit instantiation, and `supported_dim_list`
##### - the object library each ISA level's translation unit is compiled into,
##### and the instruction budget it is compiled at
#####
##### Edit this file. The header is written into the build directory on every
##### configure and installed from there. A copy is committed for header-only use;
##### configure fails if it is stale, and -DSVS_UPDATE_DEFAULT_DISPATCH_HEADER=ON refreshes it.
#####
##### A build may point somewhere else with -DSVS_DISPATCH_SURFACE_FILE=<file>,
##### in which case only that build tree describes the overridden surface.
#####
##### Bookkeeping
#####
##### To add or remove a fixed extent:
##### Edit `SVS_SUPPORTED_DIMS`. The generated header, every `extern
##### template`, and `supported_dim_list` follow automatically.
#####
##### To add an ISA level:
##### 1. Add a row to `SVS_ISA_LEVELS`.
##### 2. Add a `SVS_TYPE_PAIRS_<enumerator>` list in
##### include/svs/multi-arch/x86/preprocessor.h, listing the element-type
##### pairs that level has kernels for.
##### 3. Add the level's translation unit at
##### include/svs/multi-arch/x86/<infix>.cpp.
##### The object library and its compile flags follow from the row here. A
##### level without a type-pair list is a compile error, not an empty
##### instantiation set.
#####
##### To add or remove an element-type pair for a level:
##### Edit that level's `SVS_TYPE_PAIRS_<enumerator>` list in
##### include/svs/multi-arch/x86/preprocessor.h. Not configured here: a type
##### pair exists because an implementation exists for it.
#####
##### To change a level's instruction budget:
##### Edit the middle field of its row in `SVS_ISA_LEVELS`, observing the
##### constraint recorded there.
#####


##
## List of supported dimensions; kernels will be available for these dimensions
## If used with dimensions not in this list, compute will be dispatched to
## svs::Dynamic, which is automatically added to the list of supported dims.
##

set(SVS_SUPPORTED_DIMS 64 96 100 128 160 200 512 768)

##
## ISA mapping
##
## All compute kernels will be compiled for the architectures below
## NONE is not added; it only serves as a fallback and it will compile with
## the flags set by the consumer.
## Format is "ENUM|arch|infix", where
## - ENUM is the AVX_AVAILABILITY value from distance_core.h
## - arch is the -march flag passed to the compiler
## - infix is a **unique** string used for object and library names

set(SVS_ISA_LEVELS
"AVX2|haswell|avx2"
"AVX512|cascadelake|avx512"
)
Loading
Loading