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
8 changes: 5 additions & 3 deletions cmake/HalideGeneratorHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,7 @@ function(add_halide_library TARGET)

cmake_path(SET ARG_OUTPUT_DIR "${ARG_OUTPUT_DIR}")
cmake_path(ABSOLUTE_PATH ARG_OUTPUT_DIR BASE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" NORMALIZE)
file(MAKE_DIRECTORY "${ARG_OUTPUT_DIR}")

if (ARG_NAMESPACE)
set(ARG_FUNCTION_NAME "${ARG_NAMESPACE}::${ARG_FUNCTION_NAME}")
Expand Down Expand Up @@ -793,10 +794,11 @@ function(add_halide_library TARGET)

if (ARG_AUTOSCHEDULER)
if ("${ARG_AUTOSCHEDULER}" MATCHES "::")
# Autoscheduler plugins are compiled targets that live in HalideCompiler;
# lazily load it if it hasn't already been (e.g. while cross-compiling).
# Autoscheduler plugins are compiled targets that live in their own
# HalideAutoschedulers package; lazily load it if it hasn't already
# been (e.g. while cross-compiling).
if (NOT TARGET "${ARG_AUTOSCHEDULER}")
find_package(HalideCompiler REQUIRED)
find_package(HalideAutoschedulers REQUIRED)
endif ()
if (NOT TARGET "${ARG_AUTOSCHEDULER}")
message(FATAL_ERROR "Autoscheduler ${ARG_AUTOSCHEDULER} does not exist.")
Expand Down
12 changes: 12 additions & 0 deletions doc/HalideCMakePackage.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ actually contains the compiled libraries; you generally don't need to
`HalideCompiler_ROOT`/`-DHalideCompiler_DIR=...` when pointing CMake at a
specific installed build.

Autoscheduler plugins (see [Autoschedulers](#autoschedulers)) are resolved
separately, via a `HalideAutoschedulers` package, and are always available to
`add_halide_library(... AUTOSCHEDULER ...)` regardless of cross-compiling --
unlike `HalideCompiler`, this package's targets are never linked against (only
dlopen()'d, by their build path, at Generator run time), so there's no reason to
gate them behind the `JIT`/`Python` components.

Note that `static`/`shared`, unlike `JIT`/`Python`, never force this load by
themselves -- requesting one merely records your preference for whichever
package eventually loads the compiled compiler (whether that's this same
Expand Down Expand Up @@ -348,6 +355,11 @@ The following targets only guaranteed when `WITH_AUTOSCHEDULERS` is true:
| `Halide::Li2018` | the Li et.al. 2018 gradient autoscheduler (limited GPU support) |
| `Halide::Mullapudi2016` | the Mullapudi et.al. 2016 autoscheduler (no GPU support) |

These come from a separate `HalideAutoschedulers` package (distinct from
`HalideCompiler`), loaded automatically the first time
`add_halide_library(... AUTOSCHEDULER ...)` needs one -- including while
cross-compiling.

## Functions

The Halide package provides several useful functions for dealing with AOT
Expand Down
61 changes: 58 additions & 3 deletions packaging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ set(Halide_INSTALL_COMPILERDIR "${CMAKE_INSTALL_LIBDIR}/cmake/HalideCompiler"
CACHE STRING "Path to Halide's platform-specific compiled-library CMake files"
)

set(Halide_INSTALL_AUTOSCHEDULERSDIR "${CMAKE_INSTALL_LIBDIR}/cmake/HalideAutoschedulers"
CACHE STRING "Path to Halide's autoscheduler plugin CMake files"
)

set(Halide_INSTALL_PLUGINDIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Path to Halide plugins folder")

set(Halide_INSTALL_TOOLSDIR "${CMAKE_INSTALL_DATADIR}/tools"
Expand Down Expand Up @@ -55,11 +59,13 @@ if (WITH_AUTOSCHEDULERS)
set(autoschedulers Halide_Adams2019 Halide_Li2018 Halide_Mullapudi2016 Halide_Anderson2021)

# Autoscheduler plugins are compiled, platform-specific shared libraries,
# so they belong to HalideCompiler even though they're loaded via dlopen
# rather than linked directly.
# but they are dlopen()'d by the generator process at Generator run time
# and never linked, so they get their own export set/package
# (HalideAutoschedulers) instead of joining HalideCompiler's. See the
# ARCH_INDEPENDENT comment below for why that distinction matters.
install(
TARGETS ${autoschedulers}
EXPORT HalideCompiler_Targets
EXPORT HalideAutoschedulers_Targets
LIBRARY
DESTINATION ${Halide_INSTALL_PLUGINDIR}
COMPONENT Halide_Runtime
Expand Down Expand Up @@ -215,6 +221,16 @@ install(
COMPONENT Halide_Development
)

if (WITH_AUTOSCHEDULERS)
install(
EXPORT HalideAutoschedulers_Targets
DESTINATION ${Halide_INSTALL_AUTOSCHEDULERSDIR}
NAMESPACE Halide::
FILE HalideAutoschedulers-targets.cmake
COMPONENT Halide_Development
)
endif ()

write_basic_package_version_file(
HalideConfigVersion.cmake
COMPATIBILITY SameMajorVersion
Expand All @@ -223,6 +239,27 @@ write_basic_package_version_file(

write_basic_package_version_file(HalideCompilerConfigVersion.cmake COMPATIBILITY SameMajorVersion)

if (WITH_AUTOSCHEDULERS)
# Autoscheduler plugins are real compiled, platform-specific binaries, so
# this ARCH_INDEPENDENT is a deliberate abuse of the flag, not an oversight
# (contrast HalideCompilerConfigVersion.cmake just above, which is
# correctly *not* ARCH_INDEPENDENT for the same kind of compiled target).
# It's safe here specifically because nothing ever links against
# Halide::<Scheduler> -- add_halide_library(... AUTOSCHEDULER ...) only
# ever reads its $<TARGET_FILE:...> to pass to the generator executable's
# `-p` (plugin) command-line flag, which then dlopen()s it at Generator
# run time. That means this package's version check never needs to agree
# with the *consuming* project's word size, which is the one that
# matters when a baremetal/embedded toolchain file is in play -- e.g.
# CMAKE_SIZEOF_VOID_P reflects the cross-compiler's target ABI, not the
# host machine's, when CMAKE_CROSSCOMPILING is set.
write_basic_package_version_file(
HalideAutoschedulersConfigVersion.cmake
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
endif ()

if (WITH_PYTHON_BINDINGS)
set(extra_paths Halide_Python_INSTALL_CMAKEDIR)
else ()
Expand All @@ -243,6 +280,14 @@ configure_package_config_file(
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO
)

if (WITH_AUTOSCHEDULERS)
configure_package_config_file(
common/HalideAutoschedulersConfig.cmake HalideAutoschedulersConfig.cmake
INSTALL_DESTINATION "${Halide_INSTALL_AUTOSCHEDULERSDIR}"
NO_SET_AND_CHECK_MACRO NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
endif ()

install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/HalideConfig.cmake
Expand All @@ -264,6 +309,16 @@ install(
COMPONENT Halide_Development
)

if (WITH_AUTOSCHEDULERS)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/HalideAutoschedulersConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/HalideAutoschedulersConfigVersion.cmake
DESTINATION ${Halide_INSTALL_AUTOSCHEDULERSDIR}
COMPONENT Halide_Development
)
endif ()

##
# Compute find_dependency calls for HalideCompiler
##
Expand Down
11 changes: 11 additions & 0 deletions packaging/common/HalideAutoschedulersConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.28)
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/HalideAutoschedulers-targets.cmake")

# Autoscheduler plugins are dlopen()'d by the generator executable at
# Generator run time -- never linked -- so this package exposes only their
# IMPORTED MODULE targets (for their $<TARGET_FILE:...>), never a compile or
# link interface. See the ARCH_INDEPENDENT comment in packaging/CMakeLists.txt
# for why that's safe to resolve even while cross-compiling for a different
# word size than the host.
14 changes: 14 additions & 0 deletions packaging/pip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ endfunction()

configure_trampoline(Halide "${Halide_INSTALL_CMAKEDIR}")
configure_trampoline(HalideCompiler "${Halide_INSTALL_COMPILERDIR}")
if (WITH_AUTOSCHEDULERS)
configure_trampoline(HalideAutoschedulers "${Halide_INSTALL_AUTOSCHEDULERSDIR}")
endif ()

install(
FILES
Expand Down Expand Up @@ -38,6 +41,17 @@ install(
COMPONENT Halide_Python
)

# Same thing for HalideAutoschedulers
if (WITH_AUTOSCHEDULERS)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/HalideAutoschedulersConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/../HalideAutoschedulersConfigVersion.cmake"
DESTINATION "${SKBUILD_DATA_DIR}/share/cmake/HalideAutoschedulers"
COMPONENT Halide_Python
)
endif ()

##
# Set up RPATH for the Python bindings plugin.

Expand Down
Loading