diff --git a/CMakeLists.txt b/CMakeLists.txt index 8347654173ce..4f41afc2720b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.16...3.20) project(Halide - VERSION 13.0.0 + VERSION 14.0.0 DESCRIPTION "Halide compiler and libraries" HOMEPAGE_URL "https://halide-lang.org") diff --git a/apps/hannk/.gitignore b/apps/hannk/.gitignore index 46164faef484..f3f11e5104dc 100644 --- a/apps/hannk/.gitignore +++ b/apps/hannk/.gitignore @@ -1,2 +1,3 @@ build*/ bin/ +emsdk diff --git a/apps/hannk/CMakeLists.txt b/apps/hannk/CMakeLists.txt index 3e663100a6a2..4056d2dd571c 100644 --- a/apps/hannk/CMakeLists.txt +++ b/apps/hannk/CMakeLists.txt @@ -6,7 +6,14 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) enable_testing() +# ---------------------------- + +option(HANNK_AOT_HOST_ONLY "Only build AOT host tools for cross-compiling" OFF) + option(HANNK_BUILD_TFLITE "Build TFLite+Delegate for HANNK" ON) +if (HANNK_BUILD_TFLITE AND (Halide_TARGET MATCHES "wasm")) + message(FATAL_ERROR "HANNK_BUILD_TFLITE must be OFF when targeting wasm") +endif () message(STATUS "HANNK_BUILD_TFLITE is ${HANNK_BUILD_TFLITE}") # -fPIC is necessary for .so builds (at least on Linux); not necessary for the non-delegate @@ -18,28 +25,34 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED YES) set(CMAKE_CXX_EXTENSIONS NO) -# Find Halide -find_package(Halide REQUIRED) - # Set up the version of TFLite we expect # (We need to do this even if HANNK_BUILD_TFLITE is off, # so that the .tflite file parser can get the right schema) set(TFLITE_VERSION_MAJOR "2" CACHE STRING "Major version of TFLite to assume") set(TFLITE_VERSION_MINOR "6" CACHE STRING "Minor version of TFLite to assume") set(TFLITE_VERSION_PATCH "0" CACHE STRING "Patch version of TFLite to assume") +set(TFLITE_VERSION "${TFLITE_VERSION_MAJOR}.${TFLITE_VERSION_MINOR}.${TFLITE_VERSION_PATCH}") + +# ---------------------------- add_compile_definitions(TFLITE_VERSION_MAJOR=${TFLITE_VERSION_MAJOR}) add_compile_definitions(TFLITE_VERSION_MINOR=${TFLITE_VERSION_MINOR}) add_compile_definitions(TFLITE_VERSION_PATCH=${TFLITE_VERSION_PATCH}) -if (HANNK_BUILD_TFLITE) - add_compile_definitions(HANNK_BUILD_TFLITE=1) -else () - add_compile_definitions(HANNK_BUILD_TFLITE=0) -endif () +add_compile_definitions(HANNK_BUILD_TFLITE=$) -set(TFLITE_VERSION "${TFLITE_VERSION_MAJOR}.${TFLITE_VERSION_MINOR}.${TFLITE_VERSION_PATCH}") +# ---------------------------- + +# Find HalideHelpers -- this is just the Runtime headers and CMake functions, but no libraries +find_package(HalideHelpers REQUIRED) + +# ---------------------------- add_subdirectory(halide) +if (HANNK_AOT_HOST_ONLY) + # Don't add anything else to the build... everything for AOT is in the halide subdirectory + return() +endif () + add_subdirectory(interpreter) add_subdirectory(tflite) add_subdirectory(util) @@ -47,6 +60,8 @@ if (HANNK_BUILD_TFLITE) add_subdirectory(delegate) endif () +# ---------------------------- + # Benchmarking executable add_executable(benchmark benchmark.cpp) target_link_libraries(benchmark PRIVATE @@ -66,12 +81,41 @@ target_link_libraries(compare_vs_tflite PRIVATE target_include_directories(compare_vs_tflite PUBLIC $) +# TODO: Surely there's a better way to set Emscripten flags. +if (Halide_TARGET MATCHES "wasm") + foreach (t IN ITEMS benchmark compare_vs_tflite) + # Note: "SHELL:" prevents de-duplication of the -s flag. + target_link_options( + ${t} PRIVATE + "SHELL:-s ALLOW_MEMORY_GROWTH=1" + "SHELL:-s ENVIRONMENT=node" + "SHELL:-s NODERAWFS" + "SHELL:$<$:-s ASSERTIONS=1>" + ) + endforeach () +endif () + +if (Halide_TARGET MATCHES "wasm" AND NODE_JS_EXECUTABLE) + execute_process(COMMAND "${NODE_JS_EXECUTABLE}" --version + OUTPUT_VARIABLE NODE_JS_VERSION_RAW + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REPLACE "v" "" NODE_JS_VERSION ${NODE_JS_VERSION_RAW}) + + if (NODE_JS_VERSION VERSION_LESS "16.13") + message(FATAL_ERROR "Halide requires Node v16.13 or later, but found ${NODE_JS_VERSION_RAW} at ${NODE_JS_EXECUTABLE}. Please set NODE_JS_EXECUTABLE on the CMake command line.") + endif () +endif () + # Tests -file(GLOB TEST_FILES CONFIGURE_DEPENDS "test/*/*") +file(GLOB TEST_FILES CONFIGURE_DEPENDS "test/*/*.tflite") foreach (t IN LISTS TEST_FILES) file(RELATIVE_PATH test_name ${hannk_SOURCE_DIR} ${t}) - add_test(NAME ${test_name} COMMAND compare_vs_tflite ${t} --benchmark 0) + + # Emscripten sets CMAKE_CROSSCOMPILING_TOOLCHAIN to NODE_JS_EXECUTABLE, + # which ensures these tests will run in Node. + add_test(NAME ${test_name} + COMMAND compare_vs_tflite ${t} --benchmark 0) + set_tests_properties(${test_name} PROPERTIES LABELS hannk_tests) -endforeach() - +endforeach () diff --git a/apps/hannk/Makefile b/apps/hannk/Makefile index 77c4a41488f3..57794c36ec87 100644 --- a/apps/hannk/Makefile +++ b/apps/hannk/Makefile @@ -37,12 +37,12 @@ build: \ $(BIN)/$(HL_TARGET)/compare_vs_tflite test: compare_vs_tflite - $(foreach test_model, $(shell ls -1 test/*/*), $(BIN)/$(HL_TARGET)/compare_vs_tflite $(test_model) --benchmark 0;) + $(foreach test_model, $(shell ls -1 test/*/*.tflite), $(BIN)/$(HL_TARGET)/compare_vs_tflite $(test_model) --benchmark 0;) test-hexagon-sim: $(BIN)/$(HL_TARGET)/$(BENCHMARK_OUT) @mkdir -p $@ echo "Benchmarking tests..." - $(foreach test_model, $(shell ls -1 test/*/*), BIN=$(BIN) ./run_benchmark_on_hexagon_sim.sh $(test_model);) + $(foreach test_model, $(shell ls -1 test/*/*.tflite), BIN=$(BIN) ./run_benchmark_on_hexagon_sim.sh $(test_model);) test-hexagon-device: $(BIN)/$(HL_TARGET)/$(BENCHMARK_OUT) echo "Benchmarking tests..." @@ -51,7 +51,7 @@ test-hexagon-device: $(BIN)/$(HL_TARGET)/$(BENCHMARK_OUT) adb push test/. /vendor/bin/hannk-test adb push $(HEXAGON_SDK_ROOT)/libs/run_main_on_hexagon/ship/android_aarch64/run_main_on_hexagon /vendor/bin/run_main_on_hexagon adb push $(HEXAGON_SDK_ROOT)/libs/run_main_on_hexagon/ship/hexagon_toolv84_v65/librun_main_on_hexagon_skel.so /vendor/lib/rfsa/adsp/ - $(foreach test_model, $(shell ls -1 test/*/*), adb shell 'cd /vendor/bin; touch /vendor/lib/rfsa/adsp/run_main_on_hexagon.farf; ./run_main_on_hexagon 3 /vendor/bin/$(BENCHMARK_OUT) --verbose hannk-$(test_model)';) + $(foreach test_model, $(shell ls -1 test/*/*.tflite), adb shell 'cd /vendor/bin; touch /vendor/lib/rfsa/adsp/run_main_on_hexagon.farf; ./run_main_on_hexagon 3 /vendor/bin/$(BENCHMARK_OUT) --verbose hannk-$(test_model)';) clean: rm -rf $(BIN) diff --git a/apps/hannk/README.md b/apps/hannk/README.md index d2698cb238fa..3f5156a55360 100644 --- a/apps/hannk/README.md +++ b/apps/hannk/README.md @@ -65,3 +65,46 @@ Usage: compare_vs_tflite a.tflite [b.tflite ...] +### WebAssembly + +There is limited support for building and running hannk under WebAssembly. + +#### Requirements: + +- You must use CMake to build (Make isn't supported). +- You must have Emscripten v2.0.32 (or later) installed and activated. +- You must have Node.js v16.13 (or later) installed for testing. + Note that (as of this writing), EMSDK includes an older version of Node that *will not* work. + +#### Building: + +The simplest way is: + +``` +$ HL_TARGET=wasm-32-wasmrt-wasm_simd128 NODE_JS_EXECUTABLE=/path/to/good/version/of/node ./configure_cmake.sh +...output... +$ ninja +``` + +Note that `wasm_simd128` is optional, but highly recommended. + + +#### Running: + +If you've built as described above, you can just run `ctest` to run the basic self-tests. + +If you want to run `benchmark` or `compare_vs_tflite` manually, you'll need to launch it under `node` +manually; as noted above, when EMSDK is activated, `node` will likely refer to a version of Node.js +that won't work, so you will need to provide a path to a suitable version: + +``` +$ cd build +$ /path/to/good/version/of/node benchmark ../test/*/*.tflite +$ /path/to/good/version/of/node compare_vs_tflite ../test/*/*.tflite + +``` + +Note that compare_vs_tflite doesn't actually build or use tflite when compiling under WebAssembly! +The only mode it supports is directly parsing the .tflite files, which is pretty close to the same as +the `benchmark` tool. + diff --git a/apps/hannk/configure_cmake.sh b/apps/hannk/configure_cmake.sh index 99440afaff1c..5497b85d5606 100755 --- a/apps/hannk/configure_cmake.sh +++ b/apps/hannk/configure_cmake.sh @@ -2,57 +2,114 @@ set -e -HANNK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" -BUILD_DIR="${HANNK_DIR}/build" +HANNK_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" -mkdir -p "${BUILD_DIR}" -cd "${BUILD_DIR}" +if [ -z "${BUILD_DIR}" ]; then + BUILD_DIR="${HANNK_DIR}/build" +fi -if [ -z ${HALIDE_INSTALL_PATH} ]; then -HALIDE_INSTALL_PATH=${HOME}/halide-14-install/ +if [ -z "${HALIDE_INSTALL_PATH}" ]; then + HALIDE_INSTALL_PATH="${HOME}/halide-14-install/" fi -echo Using HalideInstall=${HALIDE_INSTALL_PATH} -if [ -z ${HL_TARGET} ]; then -HL_TARGET=host +if [ -z "${HL_TARGET}" ]; then + HL_TARGET=host fi -echo Using HL_TARGET=${HL_TARGET} if [ -z "${CMAKE_GENERATOR}" ]; then -CMAKE_GENERATOR=Ninja + CMAKE_GENERATOR=Ninja fi -echo Using build tool=${CMAKE_GENERATOR} if [ -z "${CMAKE_BUILD_TYPE}" ]; then -CMAKE_BUILD_TYPE=Release + CMAKE_BUILD_TYPE=Release +fi + +if [ -z "${ANDROID_PLATFORM}" ]; then + ANDROID_PLATFORM=21 fi -echo Using CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} if [ -z "${HANNK_BUILD_TFLITE}" ]; then -HANNK_BUILD_TFLITE=ON + HANNK_BUILD_TFLITE=ON else -HANNK_BUILD_TFLITE=OFF + HANNK_BUILD_TFLITE=OFF fi -echo Using HANNK_BUILD_TFLITE=${HANNK_BUILD_TFLITE} -EXTRAS= -# TODO: this doesn't work (yet); crosscompiling in CMake is painful. +## In a cross-compiling scenario, use a separate host and build dir +# TODO: figure out if there's a way to generalize "is this crosscompiling or not", and just make this a single if-else + if [[ "${HL_TARGET}" =~ ^arm-64-android.* ]]; then -echo Configuring for Android arm64-v8a build... -echo Using ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT} -EXTRAS="-DCMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake -DANDROID_ABI=arm64-v8a" + HOST_BUILD_DIR="${BUILD_DIR}/_host" + HOST_BUILD_TARGET=(--target hannk-halide_generators) + HOST_HL_TARGET=host + HOST_CMAKE_DEFS=(-DHANNK_AOT_HOST_ONLY=ON) +elif [[ "${HL_TARGET}" =~ ^wasm-32-wasmrt.* ]]; then + HOST_BUILD_DIR="${BUILD_DIR}/_host" + HOST_BUILD_TARGET=(--target hannk-halide_generators) + HOST_HL_TARGET=host + HOST_CMAKE_DEFS=(-DHANNK_AOT_HOST_ONLY=ON) else -echo Assuming host build... + HOST_BUILD_DIR="${BUILD_DIR}" + HOST_BUILD_TARGET=() + HOST_HL_TARGET="${HL_TARGET}" + HOST_CMAKE_DEFS=() fi +## Build HANNK for the host no matter what + +echo "Configuring HANNK for ${HOST_HL_TARGET}" cmake \ - ${EXTRAS} \ -G "${CMAKE_GENERATOR}" \ + -S "${HANNK_DIR}" \ + -B "${HOST_BUILD_DIR}" \ + "${HOST_CMAKE_DEFS[@]}" \ -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ - -DHalide_DIR="${HALIDE_INSTALL_PATH}" \ - -DCMAKE_PREFIX_PATH="${HALIDE_INSTALL_PATH}" \ - -DHalide_TARGET=${HL_TARGET} \ - -DHANNK_BUILD_TFLITE=${HANNK_BUILD_TFLITE} \ + -DHalide_DIR="${HALIDE_INSTALL_PATH}/lib/cmake/Halide" \ + -DHalideHelpers_DIR="${HALIDE_INSTALL_PATH}/lib/cmake/HalideHelpers" \ + -DHalide_TARGET="${HOST_HL_TARGET}" \ + -DHANNK_BUILD_TFLITE=${HANNK_BUILD_TFLITE} + +if [ -z "${HOST_BUILD_TARGET[*]}" ]; then + echo "Building HANNK for ${HOST_HL_TARGET}" +else + echo "Building HANNK host generator executables" +fi +cmake --build "${HOST_BUILD_DIR}" "${HOST_BUILD_TARGET[@]}" + +## Now if we're cross-compiling for Android or WASM, set up the build +## for that, using the platform-provided CMake toolchain files. + +if [[ "${HL_TARGET}" =~ ^arm-64-android.* ]]; then + echo "Using ANDROID_NDK_ROOT=${ANDROID_NDK_ROOT}" + echo "Using CMAKE_TOOLCHAIN_FILE=${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" + CROSS_CMAKE_DEFS=( + -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK_ROOT}/build/cmake/android.toolchain.cmake" + -DANDROID_ABI=arm64-v8a + "-DANDROID_PLATFORM=${ANDROID_PLATFORM}" + # Required because TFLite's internal Eigen tries to compile an unnecessary BLAS with the system Fortran compiler. + "-DCMAKE_Fortran_COMPILER=NO" + ) +elif [[ "${HL_TARGET}" =~ ^wasm-32-wasmrt.* ]]; then + echo "Using NODE_JS_EXECUTABLE=${NODE_JS_EXECUTABLE}" + CROSS_CMAKE_DEFS=( + -DCMAKE_TOOLCHAIN_FILE="${EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" + -DNODE_JS_EXECUTABLE="${NODE_JS_EXECUTABLE}" + ) +else + # Not cross-compiling, so we're done. + exit +fi + +echo "Configuring cross-build HANNK for ${HL_TARGET}" +cmake \ + -G "${CMAKE_GENERATOR}" \ -S "${HANNK_DIR}" \ - -B "${BUILD_DIR}" + -B "${BUILD_DIR}" \ + "${CROSS_CMAKE_DEFS[@]}" \ + -DCMAKE_BUILD_TYPE="${CMAKE_BUILD_TYPE}" \ + -DHANNK_BUILD_TFLITE=OFF \ + -DHalide_TARGET="${HL_TARGET}" \ + -DHalideHelpers_DIR="${HALIDE_INSTALL_PATH}/lib/cmake/HalideHelpers" \ + -Dhannk-halide_generators_ROOT="${HOST_BUILD_DIR}" +echo "Building cross-build HANNK for ${HL_TARGET}" +cmake --build "${BUILD_DIR}" diff --git a/apps/hannk/halide/CMakeLists.txt b/apps/hannk/halide/CMakeLists.txt index 494e346bb083..8da428833bd3 100644 --- a/apps/hannk/halide/CMakeLists.txt +++ b/apps/hannk/halide/CMakeLists.txt @@ -1,61 +1,118 @@ +add_custom_target(hannk-halide_generators) + +# This function adds the target ${TARGET} to the hannk-halide_generators +# CMake package that exists in the build-tree of a host build. It also adds +# it to the target of the same name that can be used as a convenience for +# just building the host targets. +function(_export_host_target TARGET) + add_dependencies(hannk-halide_generators ${TARGET}) + export(TARGETS ${TARGET} + NAMESPACE hannk::halide_generators:: + APPEND FILE "${hannk_BINARY_DIR}/hannk-halide_generators-config.cmake") +endfunction() + +# Emscripten tries to disable finding packages outside its sysroot, +# but we need our native generators. Setting CMAKE_FIND_ROOT_PATH_BOTH +# here overrides Emscripten's search preference. +find_package(hannk-halide_generators QUIET CMAKE_FIND_ROOT_PATH_BOTH) + +if (hannk-halide_generators_FOUND) + message(STATUS "Using hannk-halide_generators from ${hannk-halide_generators_DIR}") +else () + if (CMAKE_CROSSCOMPILING) + message(WARNING + "hannk-halide_generators were not found and it looks like you are cross-compiling. " + "This is likely to fail. Please set -Dhannk-halide_generators_ROOT=... at the CMake " + "command line to the build directory of a host-built hannk.") + endif () + find_package(Halide REQUIRED) +endif () + +if (NOT TARGET hannk::halide_generators::common_halide) + add_library(common_halide STATIC common_halide.cpp) + add_library(hannk::halide_generators::common_halide ALIAS common_halide) + + target_link_libraries(common_halide PRIVATE Halide::Halide) + target_include_directories(common_halide PUBLIC $) + + _export_host_target(common_halide) +endif () -add_library(common_halide STATIC common_halide.cpp) -target_link_libraries(common_halide PRIVATE Halide::Halide) -target_include_directories(common_halide PUBLIC $) +# ---------------------------- -set(_HANNK_HALIDE_TARGETS "") +function(_begin_halide_library_set LIBRARY_SET) + add_library(${LIBRARY_SET} INTERFACE) + target_include_directories(${LIBRARY_SET} INTERFACE "$") -# Function to reduce boilerplate -function(_add_hannk_halide_library) + add_custom_target(${LIBRARY_SET}.build_all) +endfunction() + +function(_add_halide_library_set LIBRARY_SET) set(options) set(oneValueArgs TARGET GENERATOR_NAME) set(multiValueArgs SRCS GENERATOR_ARGS GENERATOR_DEPS FEATURES) cmake_parse_arguments(args "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) - add_executable(${args_TARGET}.generator ${args_SRCS}) - target_link_libraries(${args_TARGET}.generator PRIVATE ${args_GENERATOR_DEPS} common_halide Halide::Generator) - target_include_directories(${args_TARGET}.generator PUBLIC $) + set(gen hannk::halide_generators::${args_TARGET}.generator) + + if (NOT TARGET ${gen}) + add_executable(${args_TARGET}.generator ${args_SRCS}) + add_executable(${gen} ALIAS ${args_TARGET}.generator) + + target_link_libraries(${args_TARGET}.generator PRIVATE ${args_GENERATOR_DEPS} common_halide Halide::Generator) + target_include_directories(${args_TARGET}.generator PUBLIC $) + + _export_host_target(${args_TARGET}.generator) + endif () - add_halide_library(${args_TARGET} FROM ${args_TARGET}.generator + add_halide_library(${args_TARGET} FROM ${gen} NAMESPACE hannk GENERATOR ${args_GENERATOR_NAME} - FEATURES large_buffers c_plus_plus_name_mangling ${args_FEATURES} + FEATURES c_plus_plus_name_mangling ${args_FEATURES} PARAMS ${args_GENERATOR_ARGS}) - set(_HANNK_HALIDE_TARGETS ${_HANNK_HALIDE_TARGETS} ${args_TARGET} PARENT_SCOPE) + add_dependencies("${LIBRARY_SET}.build_all" "${args_TARGET}" "${args_TARGET}.runtime") + target_link_libraries(${LIBRARY_SET} INTERFACE ${args_TARGET}) endfunction() -_add_hannk_halide_library( +function(_finish_halide_library_set LIBRARY_SET) + # Nothing to do for now. +endfunction() + +# --------------------------- + +_begin_halide_library_set(halide_op_implementations) + +_add_halide_library_set(halide_op_implementations TARGET add_uint8_uint8 SRCS elementwise_generator.cpp FEATURES no_bounds_query GENERATOR_NAME Add GENERATOR_ARGS - GENERATOR_DEPS elementwise_program) + GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET average_pool_uint8 SRCS pool_generator.cpp GENERATOR_NAME AveragePool GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET conv_u8_u8_u8 SRCS conv_generator.cpp GENERATOR_NAME Conv GENERATOR_ARGS output.type=uint8 GENERATOR_DEPS) - -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET conv_u8_u8_i16 SRCS conv_generator.cpp GENERATOR_NAME Conv GENERATOR_ARGS output.type=int16 GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET copy_uint8_uint8 SRCS copy_generator.cpp FEATURES no_bounds_query @@ -63,28 +120,28 @@ _add_hannk_halide_library( GENERATOR_ARGS input.type=uint8 output.type=uint8 GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET depthwise_conv_uint8 SRCS depthwise_conv_generator.cpp GENERATOR_NAME DepthwiseConv GENERATOR_ARGS inv_depth_multiplier=1 GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET depthwise_conv_broadcast_uint8 SRCS depthwise_conv_generator.cpp GENERATOR_NAME DepthwiseConv GENERATOR_ARGS inv_depth_multiplier=0 GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET depthwise_conv_shallow_uint8 SRCS depthwise_conv_generator.cpp GENERATOR_NAME DepthwiseConv GENERATOR_ARGS inv_depth_multiplier=1 shallow=true GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET fill_uint8 SRCS fill_generator.cpp FEATURES no_bounds_query no_asserts @@ -92,23 +149,23 @@ _add_hannk_halide_library( GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET elementwise_5xuint8_1xuint8 SRCS elementwise_generator.cpp FEATURES no_bounds_query GENERATOR_NAME Elementwise GENERATOR_ARGS inputs.size=5 inputs.type=uint8 output1_type=uint8 - GENERATOR_DEPS elementwise_program) + GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET elementwise_5xint16_1xuint8int16 SRCS elementwise_generator.cpp FEATURES no_bounds_query GENERATOR_NAME Elementwise GENERATOR_ARGS inputs.size=5 inputs.type=int16 output1_type=uint8 output2_type=int16 - GENERATOR_DEPS elementwise_program) + GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET l2_normalization_uint8 SRCS normalizations_generator.cpp FEATURES no_bounds_query @@ -116,29 +173,29 @@ _add_hannk_halide_library( GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET max_pool_uint8 SRCS pool_generator.cpp GENERATOR_NAME MaxPool GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET mean_uint8 SRCS reductions_generator.cpp GENERATOR_NAME Mean GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET mul_uint8_uint8_uint8 SRCS elementwise_generator.cpp FEATURES no_bounds_query GENERATOR_NAME Mul GENERATOR_ARGS - GENERATOR_DEPS elementwise_program) + GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET softmax_uint8 SRCS normalizations_generator.cpp FEATURES no_bounds_query @@ -146,20 +203,19 @@ _add_hannk_halide_library( GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET tile_conv_filter_uint8 SRCS conv_generator.cpp GENERATOR_NAME TileConvFilter GENERATOR_ARGS GENERATOR_DEPS) -_add_hannk_halide_library( +_add_halide_library_set(halide_op_implementations TARGET upsample_channels_uint8 SRCS depthwise_conv_generator.cpp GENERATOR_NAME UpsampleChannels GENERATOR_ARGS GENERATOR_DEPS) -add_library(op_impls INTERFACE) -target_link_libraries(op_impls INTERFACE ${_HANNK_HALIDE_TARGETS}) -target_include_directories(op_impls INTERFACE $) +_finish_halide_library_set(halide_op_implementations) + diff --git a/apps/hannk/interpreter/CMakeLists.txt b/apps/hannk/interpreter/CMakeLists.txt index e6f995320ef9..05b0def0e6c7 100644 --- a/apps/hannk/interpreter/CMakeLists.txt +++ b/apps/hannk/interpreter/CMakeLists.txt @@ -18,7 +18,7 @@ add_library(interpreter STATIC tensor.cpp transforms.cpp) target_include_directories(interpreter PUBLIC $) -target_link_libraries(interpreter PRIVATE elementwise_program op_impls interpreter_lower Halide::Runtime) +target_link_libraries(interpreter PRIVATE elementwise_program halide_op_implementations interpreter_lower Halide::Runtime) foreach (LIB IN ITEMS elementwise_program diff --git a/apps/hannk/util/CMakeLists.txt b/apps/hannk/util/CMakeLists.txt index 5cfa4c184b37..ca1bc09d5ce1 100644 --- a/apps/hannk/util/CMakeLists.txt +++ b/apps/hannk/util/CMakeLists.txt @@ -8,6 +8,7 @@ add_library(hannk_log_stderr STATIC EXCLUDE_FROM_ALL hannk_log_stderr.cpp) target_include_directories(hannk_log_stderr PUBLIC $) +target_link_libraries(hannk_log_stderr PUBLIC "$<$:log>") add_library(hannk_log_tflite STATIC EXCLUDE_FROM_ALL hannk_log_tflite.cpp) diff --git a/cmake/HalideTargetHelpers.cmake b/cmake/HalideTargetHelpers.cmake index 7725042738c7..a7235d974a9b 100644 --- a/cmake/HalideTargetHelpers.cmake +++ b/cmake/HalideTargetHelpers.cmake @@ -17,6 +17,12 @@ function(_Halide_cmake_target OUTVAR) # Get OS from CMake string(TOLOWER "${CMAKE_SYSTEM_NAME}" os) list(TRANSFORM os REPLACE "^darwin$" "osx") + list(TRANSFORM os REPLACE "^emscripten$" "wasmrt") + + # Fix up emscripten usage + if (os STREQUAL "wasmrt" AND arch STREQUAL "x86") + set(arch "wasm") + endif () set(${OUTVAR} "${arch}-${bits}-${os}" PARENT_SCOPE) endfunction() @@ -60,8 +66,10 @@ unset(_default_target) # Print the active values of all special target triples. ## -if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) +get_property(${CMAKE_FIND_PACKAGE_NAME}_MESSAGE_PRINTED GLOBAL PROPERTY ${CMAKE_FIND_PACKAGE_NAME}_MESSAGE_PRINTED) +if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY AND NOT ${CMAKE_FIND_PACKAGE_NAME}_MESSAGE_PRINTED) message(STATUS "Halide 'host' platform triple: ${Halide_HOST_TARGET}") message(STATUS "Halide 'cmake' platform triple: ${Halide_CMAKE_TARGET}") message(STATUS "Halide default AOT target: ${Halide_TARGET}") + set_property(GLOBAL PROPERTY ${CMAKE_FIND_PACKAGE_NAME}_MESSAGE_PRINTED 1) endif ()