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
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ enable_testing()
# Set up project-wide properties
##

# Import useful standard modules
include(CMakeDependentOption)
include(CheckCXXSymbolExists)

# Make our custom helpers available throughout the project via include().
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)
include(HalideGeneratorHelpers)
include(CMakeDependentOption)

# Build Halide as a shared lib by default, but still honor command-line settings.
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
Expand Down Expand Up @@ -67,6 +70,14 @@ if (Halide_CCACHE_BUILD)
message(STATUS "Enabling ccache usage for building.")
endif ()

# Detect whether or not ASAN is enabled
check_cxx_symbol_exists(HALIDE_INTERNAL_USING_ASAN "${Halide_SOURCE_DIR}/src/Util.h" Halide_ASAN_ENABLED)
if (Halide_ASAN_ENABLED)
set(Halide_ANY_SANITIZERS_ENABLED 1)
else ()
set(Halide_ANY_SANITIZERS_ENABLED 0)
endif ()

# Enable the SPIR-V target if requested (must declare before processing dependencies)
option(TARGET_SPIRV "Include SPIR-V target" OFF)

Expand Down
40 changes: 40 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
"binaryDir": "build/${presetName}",
"installDir": "install/${presetName}"
},
{
"name": "ci",
"hidden": true,
"inherits": "default",
"toolchainFile": "${sourceDir}/cmake/toolchain.${presetName}.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "windows-only",
"hidden": true,
Expand Down Expand Up @@ -145,6 +154,37 @@
"BUILD_SHARED_LIBS": "NO",
"Halide_BUNDLE_LLVM": "YES"
}
},
{
"name": "linux-x64-asan",
"inherits": "ci",
"displayName": "ASAN (Linux x64)",
"description": "Build everything with ASAN enabled",
"cacheVariables": {
"LLVM_ROOT": "$penv{LLVM_ROOT}"
}
}
],
"buildPresets": [
{
"name": "linux-x64-asan",
"configurePreset": "linux-x64-asan",
"displayName": "ASAN (Linux x64)",
"description": "Build everything with ASAN enabled"
}
],
"testPresets": [
{
"name": "linux-x64-asan",
"configurePreset": "linux-x64-asan",
"displayName": "ASAN (Linux x64)",
"description": "Test everything with ASAN enabled",
"environment": {
"ASAN_OPTIONS": "detect_leaks=0:detect_container_overflow=0"
},
"output": {
"outputOnFailure": true
}
}
]
}
86 changes: 46 additions & 40 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,56 @@
cmake_minimum_required(VERSION 3.22)
project(Halide_apps)

enable_testing()

if (WIN32)
option(ENABLE_APPS_HANNK "Build apps/hannk" OFF)
else ()
option(ENABLE_APPS_HANNK "Build apps/hannk" ON)
endif ()

enable_testing()
function(add_app app_name)
string(TOUPPER "ENABLE_APPS_${app_name}" opt)
option(${opt} "Build apps/${app_name}" ON)
if (${opt})
add_subdirectory(${app_name})
endif ()
endfunction()

# add_subdirectory(HelloAndroid) # TODO(#5374): missing CMake build
# add_subdirectory(HelloAndroidCamera2) # TODO(#5374): missing CMake build
# add_subdirectory(HelloPyTorch) # TODO(#5374): missing CMake build
# add_subdirectory(HelloWasm) # TODO(#5374): missing CMake build
# add_subdirectory(HelloiOS) # TODO(#5374): missing CMake build
# add_subdirectory(auto_viz) # TODO(#5374): missing CMake build
add_subdirectory(bgu)
add_subdirectory(bilateral_grid)
add_subdirectory(blur)
add_subdirectory(c_backend)
add_subdirectory(camera_pipe)
add_subdirectory(conv_layer)
add_subdirectory(cuda_mat_mul)
add_subdirectory(depthwise_separable_conv)
add_subdirectory(fft)
if (ENABLE_APPS_HANNK)
add_subdirectory(hannk)
endif ()
add_subdirectory(harris)
# add_subdirectory(hexagon_benchmarks) # TODO(#5374): missing CMake build
# add_subdirectory(hexagon_dma) # TODO(#5374): missing CMake build
add_subdirectory(hist)
add_subdirectory(iir_blur)
add_subdirectory(interpolate)
add_subdirectory(lens_blur)
add_subdirectory(linear_algebra)
# add_subdirectory(linear_blur) # TODO(#5374): missing CMake build
add_subdirectory(local_laplacian)
add_subdirectory(max_filter)
add_subdirectory(nl_means)
# add_subdirectory(nn_ops) # TODO(#5374): missing CMake build
# add_subdirectory(onnx) # TODO(#5374): missing CMake build
# add_subdirectory(openglcompute) # TODO(#5374): missing CMake build
add_subdirectory(resize)
# add_subdirectory(resnet_50) # TODO(#5374): missing CMake build
# add_subdirectory(simd_op_check) # TODO(#5374): missing CMake build
add_subdirectory(stencil_chain)
add_subdirectory(unsharp)
add_subdirectory(wavelet)
# add_app(HelloAndroid) # TODO(#5374): missing CMake build
# add_app(HelloAndroidCamera2) # TODO(#5374): missing CMake build
# add_app(HelloPyTorch) # TODO(#5374): missing CMake build
# add_app(HelloWasm) # TODO(#5374): missing CMake build
# add_app(HelloiOS) # TODO(#5374): missing CMake build
# add_app(auto_viz) # TODO(#5374): missing CMake build
add_app(bgu)
add_app(bilateral_grid)
add_app(blur)
add_app(c_backend)
add_app(camera_pipe)
add_app(conv_layer)
add_app(cuda_mat_mul)
add_app(depthwise_separable_conv)
add_app(fft)
add_app(hannk)
add_app(harris)
# add_app(hexagon_benchmarks) # TODO(#5374): missing CMake build
# add_app(hexagon_dma) # TODO(#5374): missing CMake build
add_app(hist)
add_app(iir_blur)
add_app(interpolate)
add_app(lens_blur)
add_app(linear_algebra)
# add_app(linear_blur) # TODO(#5374): missing CMake build
add_app(local_laplacian)
add_app(max_filter)
add_app(nl_means)
# add_app(nn_ops) # TODO(#5374): missing CMake build
# add_app(onnx) # TODO(#5374): missing CMake build
# add_app(openglcompute) # TODO(#5374): missing CMake build
add_app(resize)
# add_app(resnet_50) # TODO(#5374): missing CMake build
# add_app(simd_op_check) # TODO(#5374): missing CMake build
add_app(stencil_chain)
add_app(unsharp)
add_app(wavelet)
60 changes: 60 additions & 0 deletions apps/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 22,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"hidden": true,
"binaryDir": "build/${presetName}",
"installDir": "install/${presetName}"
},
{
"name": "ci",
"hidden": true,
"inherits": "default",
"toolchainFile": "${sourceDir}/../cmake/toolchain.${presetName}.cmake",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
}
},
{
"name": "linux-x64-asan",
"inherits": "ci",
"displayName": "ASAN (Linux x64)",
"description": "Build everything with ASAN enabled",
"cacheVariables": {
"LLVM_ROOT": "$penv{LLVM_ROOT}",
"ENABLE_APPS_BGU": "OFF"
}
}
],
"buildPresets": [
{
"name": "linux-x64-asan",
"configurePreset": "linux-x64-asan",
"displayName": "ASAN (Linux x64)",
"description": "Build everything with ASAN enabled",
"environment": {
"ASAN_OPTIONS": "detect_leaks=0:detect_container_overflow=0"
}
}
],
"testPresets": [
{
"name": "linux-x64-asan",
"configurePreset": "linux-x64-asan",
"displayName": "ASAN (Linux x64)",
"description": "Test everything with ASAN enabled",
"environment": {
"ASAN_OPTIONS": "detect_leaks=0:detect_container_overflow=0"
},
"output": {
"outputOnFailure": true
}
}
]
}
2 changes: 1 addition & 1 deletion apps/fft/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ set_tests_properties(fft_aot_test PROPERTIES

foreach (i IN ITEMS 8 12 16 24 32 48)
add_test(NAME bench${i}x${i} COMMAND bench_fft ${i} ${i} "${CMAKE_CURRENT_BINARY_DIR}")
set_tests_properties(bench${i}x${i}
set_tests_properties(bench${i}x${i}
PROPERTIES
LABELS fft
ENVIRONMENT "PATH=$<SHELL_PATH:$<TARGET_FILE_DIR:Halide::Halide>>")
Expand Down
7 changes: 4 additions & 3 deletions cmake/HalideGeneratorHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ function(_Halide_try_load_generators)
# Communicate found information to the caller
set(${ARG_PACKAGE_NAME}_FOUND "${${ARG_PACKAGE_NAME}_FOUND}" PARENT_SCOPE)

if (NOT ${ARG_PACKAGE_NAME}_FOUND AND CMAKE_CROSSCOMPILING)
if (NOT ${ARG_PACKAGE_NAME}_FOUND AND CMAKE_CROSSCOMPILING AND NOT CMAKE_CROSSCOMPILING_EMULATOR)
message(WARNING
"${ARG_PACKAGE_NAME} were not found and it looks like you are cross-compiling. "
"This is likely to fail. Please set -D${ARG_PACKAGE_NAME}_ROOT=... at the CMake "
"'${ARG_PACKAGE_NAME}' was not found and it looks like you "
"are cross-compiling without an emulator. This is likely to "
"fail. Please set -D${ARG_PACKAGE_NAME}_ROOT=... at the CMake "
"command line to the build directory of a host-built ${PROJECT_NAME}.")
endif ()
endif ()
Expand Down
32 changes: 32 additions & 0 deletions cmake/toolchain.linux-x64-asan.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Toolchain for compiling with ASAN enabled on a Linux-x86-64 host.
# This is done as a "crosscompile" because we must use our LLVM version
# of clang for *all* compilation (rather than using it just for bitcode
# and letting the host compiler, eg gcc, handle everything else); ASAN
# essentially requires everything to be compiled with matching versions
# of the same compiler.
#
# Note: requires LLVM to be built with -DLLVM_ENABLE_RUNTIMES="compiler-rt;libcxx;libcxxabi;libunwind"
#
# Note: only tested with LLVM/Clang 16 as of this comment. Earlier versions
# may likely work but are not tested.

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR i686)

set(CMAKE_C_COMPILER ${LLVM_ROOT}/bin/clang)
set(CMAKE_CXX_COMPILER ${LLVM_ROOT}/bin/clang++)
set(CMAKE_LINKER ${LLVM_ROOT}/bin/ld.lld)

set(CMAKE_C_FLAGS_INIT "-fsanitize=address")
set(CMAKE_CXX_FLAGS_INIT "-fsanitize=address")

set(CMAKE_EXE_LINKER_FLAGS_INIT "-fuse-ld=${CMAKE_LINKER}")
set(CMAKE_MODULE_LINKER_FLAGS_INIT "-fuse-ld=${CMAKE_LINKER}")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-fuse-ld=${CMAKE_LINKER}")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/env)
25 changes: 24 additions & 1 deletion python_bindings/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,39 @@ if (NOT Halide_ENABLE_RTTI OR NOT Halide_ENABLE_EXCEPTIONS)
endif ()

##
# A helper for creating tests with correct PYTHONPATH
# A helper for creating tests with correct PYTHONPATH and sanitizer preloading
##

if (Halide_ASAN_ENABLED)
if (NOT DEFINED Halide_Python_ASAN_LIBRARY)
# TODO: this assumes clang-on-Linux, we could be smarter here and check
# CMAKE_CXX_COMPILER_ID to behave differently on GNU, AppleClang, or
# MSVC.
execute_process(
COMMAND ${CMAKE_CXX_COMPILER} "-print-file-name=libclang_rt.asan.so"
OUTPUT_VARIABLE Halide_Python_ASAN_LIBRARY
OUTPUT_STRIP_TRAILING_WHITESPACE
)
endif ()

set(Halide_Python_ASAN_LIBRARY "${Halide_Python_ASAN_LIBRARY}"
CACHE FILEPATH "Library to preload when running Python tests.")
endif ()

function(add_python_test)
cmake_parse_arguments(ARG "" "FILE;LABEL" "PYTHONPATH;ENVIRONMENT" ${ARGN})

list(PREPEND ARG_PYTHONPATH "$<TARGET_FILE_DIR:Halide::Python>/..")
list(TRANSFORM ARG_PYTHONPATH PREPEND "PYTHONPATH=path_list_prepend:")

list(PREPEND ARG_ENVIRONMENT "HL_TARGET=${Halide_TARGET}")
if (Halide_Python_ASAN_LIBRARY)
if (APPLE)
list(PREPEND ARG_ENVIRONMENT "DYLD_INSERT_LIBRARIES=${Halide_Python_ASAN_LIBRARY}")
else ()
list(PREPEND ARG_ENVIRONMENT "LD_PRELOAD=${Halide_Python_ASAN_LIBRARY}")
endif ()
endif ()

cmake_path(GET ARG_FILE STEM test_name)
set(test_name "${ARG_LABEL}_${test_name}")
Expand Down
11 changes: 5 additions & 6 deletions src/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,19 +567,18 @@ Target get_target_from_environment() {
Target get_jit_target_from_environment() {
Target host = get_host_target();
host.set_feature(Target::JIT);
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
// Note, we must include Util.h for these to be defined properly (or not)
#ifdef HALIDE_INTERNAL_USING_ASAN
host.set_feature(Target::ASAN);
#endif
#if __has_feature(memory_sanitizer)
#ifdef HALIDE_INTERNAL_USING_MSAN
host.set_feature(Target::MSAN);
#endif
#if __has_feature(thread_sanitizer)
#ifdef HALIDE_INTERNAL_USING_TSAN
host.set_feature(Target::TSAN);
#endif
#if __has_feature(coverage_sanitizer)
#ifdef HALIDE_INTERNAL_USING_COVSAN
host.set_feature(Target::SanitizerCoverage);
#endif
#endif
string target = Internal::get_env_variable("HL_JIT_TARGET");
if (target.empty()) {
Expand Down
Loading