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
134 changes: 132 additions & 2 deletions apps/hannk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ set(CMAKE_CXX_EXTENSIONS NO)
# (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 "19" CACHE STRING "Minor version of TFLite to assume")
set(TFLITE_VERSION_MINOR "21" 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}")

Expand All @@ -44,6 +44,14 @@ add_compile_definitions(HANNK_BUILD_TFLITE=$<BOOL:${HANNK_BUILD_TFLITE}>)

# Find HalideHelpers -- this is just the Runtime headers and CMake functions, but no libraries
find_package(HalideHelpers REQUIRED)
if (HANNK_BUILD_TFLITE)
find_package(tensorflow-lite CONFIG REQUIRED)
endif ()

# Canonical include root for hannk headers (e.g. "util/error_util.h").
add_library(hannk_headers INTERFACE)
target_include_directories(hannk_headers INTERFACE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)

# ----------------------------

Expand Down Expand Up @@ -107,7 +115,129 @@ if (Halide_TARGET MATCHES "wasm" AND NODE_JS_EXECUTABLE)
endif ()

# Tests
file(GLOB TEST_FILES CONFIGURE_DEPENDS "test/*/*.tflite")

set(TEST_FILES
inception_v2_224_quant/000.DEPTHWISE_CONV_2D.tflite
inception_v4_299_quant/000.CONV_2D.tflite
inception_v4_299_quant/001.CONV_2D.tflite
inception_v4_299_quant/002.CONV_2D.tflite
inception_v4_299_quant/003.MAX_POOL_2D.tflite
inception_v4_299_quant/004.CONV_2D.tflite
inception_v4_299_quant/006.CONV_2D.tflite
inception_v4_299_quant/008.CONV_2D.tflite
inception_v4_299_quant/009.CONV_2D.tflite
inception_v4_299_quant/013.MAX_POOL_2D.tflite
inception_v4_299_quant/015.CONCATENATION.tflite
inception_v4_299_quant/016.AVERAGE_POOL_2D.tflite
inception_v4_299_quant/024.CONCATENATION.tflite
inception_v4_299_quant/044.CONV_2D.tflite
inception_v4_299_quant/045.CONV_2D.tflite
inception_v4_299_quant/049.CONV_2D.tflite
inception_v4_299_quant/052.MAX_POOL_2D.tflite
inception_v4_299_quant/054.CONV_2D.tflite
inception_v4_299_quant/057.CONCATENATION.tflite
inception_v4_299_quant/069.CONCATENATION.tflite
inception_v4_299_quant/081.CONCATENATION.tflite
inception_v4_299_quant/093.CONCATENATION.tflite
inception_v4_299_quant/105.CONCATENATION.tflite
inception_v4_299_quant/117.CONCATENATION.tflite
inception_v4_299_quant/118.AVERAGE_POOL_2D.tflite
inception_v4_299_quant/129.CONCATENATION.tflite
inception_v4_299_quant/140.CONV_2D.tflite
inception_v4_299_quant/141.CONCATENATION.tflite
inception_v4_299_quant/142.MAX_POOL_2D.tflite
inception_v4_299_quant/149.CONCATENATION.tflite
inception_v4_299_quant/178.AVERAGE_POOL_2D.tflite
inception_v4_299_quant/189.CONCATENATION.tflite
inception_v4_299_quant/191.CONCATENATION.tflite
inception_v4_299_quant/192.AVERAGE_POOL_2D.tflite
inception_v4_299_quant/194.SOFTMAX.tflite
misc/L2_NORMALIZATION.tflite
misc/LOGISTIC.tflite
misc/MUL.tflite
misc/SPACE_TO_DEPTH.2.tflite
misc/SPACE_TO_DEPTH.4.tflite
misc/SPLIT.1_1_1.tflite
misc/SPLIT_V.36_5_7.tflite
misc/TRANSPOSE.2_0_1.tflite
misc/bad_broadcast_add.tflite
misc/bad_broadcast_mul.tflite
misc/bad_broadcast_sub.tflite
misc/bad_fully_connected.tflite
mobilenet_v1_0.25_128_quant/000.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/001.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/002.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/003.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/004.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/005.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/006.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/007.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/008.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/009.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/010.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/011.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/012.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/013.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/014.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/019.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/022.CONV_2D.tflite
mobilenet_v1_0.25_128_quant/025.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_0.25_128_quant/027.AVERAGE_POOL_2D.tflite
mobilenet_v1_0.25_128_quant/029.RESHAPE.tflite
mobilenet_v1_0.25_128_quant/030.SOFTMAX.tflite
mobilenet_v1_1.0_224_quant/000.CONV_2D.tflite
mobilenet_v1_1.0_224_quant/001.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/002.CONV_2D.tflite
mobilenet_v1_1.0_224_quant/003.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/004.CONV_2D.tflite
mobilenet_v1_1.0_224_quant/005.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/006.CONV_2D.tflite
mobilenet_v1_1.0_224_quant/007.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/008.CONV_2D.tflite
mobilenet_v1_1.0_224_quant/009.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/013.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/025.DEPTHWISE_CONV_2D.tflite
mobilenet_v1_1.0_224_quant/027.AVERAGE_POOL_2D.tflite
mobilenet_v1_1.0_224_quant/029.RESHAPE.tflite
mobilenet_v1_1.0_224_quant/030.SOFTMAX.tflite
mobilenet_v2_1.0_224_quant/000.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/001.DEPTHWISE_CONV_2D.tflite
mobilenet_v2_1.0_224_quant/002.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/003.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/004.DEPTHWISE_CONV_2D.tflite
mobilenet_v2_1.0_224_quant/005.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/008.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/009.ADD.tflite
mobilenet_v2_1.0_224_quant/012.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/015.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/016.ADD.tflite
mobilenet_v2_1.0_224_quant/020.ADD.tflite
mobilenet_v2_1.0_224_quant/021.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/022.DEPTHWISE_CONV_2D.tflite
mobilenet_v2_1.0_224_quant/023.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/027.ADD.tflite
mobilenet_v2_1.0_224_quant/031.ADD.tflite
mobilenet_v2_1.0_224_quant/032.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/033.DEPTHWISE_CONV_2D.tflite
mobilenet_v2_1.0_224_quant/034.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/035.ADD.tflite
mobilenet_v2_1.0_224_quant/038.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/040.DEPTHWISE_CONV_2D.tflite
mobilenet_v2_1.0_224_quant/042.ADD.tflite
mobilenet_v2_1.0_224_quant/045.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/046.ADD.tflite
mobilenet_v2_1.0_224_quant/047.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/049.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/053.ADD.tflite
mobilenet_v2_1.0_224_quant/054.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/056.CONV_2D.tflite
mobilenet_v2_1.0_224_quant/057.ADD.tflite
mobilenet_v2_1.0_224_quant/059.DEPTHWISE_CONV_2D.tflite
mobilenet_v2_1.0_224_quant/062.AVERAGE_POOL_2D.tflite
mobilenet_v2_1.0_224_quant/064.RESHAPE.tflite
)
list(TRANSFORM TEST_FILES PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/test/")

foreach (t IN LISTS TEST_FILES)
file(RELATIVE_PATH test_name ${hannk_SOURCE_DIR} ${t})

Expand Down
18 changes: 7 additions & 11 deletions apps/hannk/delegate/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
add_library(hannk_delegate STATIC
hannk_delegate.cpp)
target_link_libraries(hannk_delegate PRIVATE
hannk_headers
hannk_log_tflite
interpreter_lower
tensorflowlite_headers
tensorflow-lite::tensorflow-lite
Halide::Runtime)
target_include_directories(hannk_delegate PRIVATE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)

# --------------- registrar (static-library) delegate

add_library(hannk_delegate_registrar STATIC
hannk_delegate_provider.cpp)
target_link_libraries(hannk_delegate_registrar PRIVATE
hannk_headers
error_util
interpreter
hannk_delegate
hannk_log_tflite
tensorflowlite_headers
tensorflow-lite::tensorflow-lite
Halide::Runtime)
target_include_directories(hannk_delegate_registrar PRIVATE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)


# --------------- external (shared-library) delegate
Expand All @@ -33,20 +31,18 @@ target_include_directories(hannk_delegate_registrar PRIVATE
add_library(hannk_delegate_external MODULE
hannk_delegate_adaptor.cpp)
target_link_libraries(hannk_delegate_external PRIVATE
hannk_headers
error_util
interpreter
hannk_delegate
hannk_log_tflite
tensorflowlite_headers
tensorflow-lite::tensorflow-lite
Halide::Runtime)
target_include_directories(hannk_delegate_external PRIVATE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
if (APPLE)
target_link_options(hannk_delegate_external PRIVATE "-Wl,-exported_symbols_list,${hannk_SOURCE_DIR}/delegate/exported_symbols.osx")
else ()
target_link_options(hannk_delegate_external PRIVATE "-Wl,--version-script,${hannk_SOURCE_DIR}/delegate/exported_symbols.ldscript")
endif()
endif ()

# Give it the name that we already use elsewhere ("lib" and ".so" will be added)
set_target_properties(hannk_delegate_external PROPERTIES OUTPUT_NAME "HannkDelegate")

90 changes: 10 additions & 80 deletions apps/hannk/tflite/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,82 +1,12 @@
include(FetchContent)

set(TFLITE_TAG "v${TFLITE_VERSION}")

message(STATUS "Fetching TFLite ${TFLITE_TAG}...")

# static linking makes life with TFLite much easier
set(TFLITE_C_BUILD_SHARED_LIBS OFF)

# We don't care about comparing against these delegates (yet),
# and disabling it reduces compile time meaningfully
set(TFLITE_ENABLE_RUY OFF)
set(TFLITE_ENABLE_XNNPACK OFF)

# Also have to disable some stuff dragged in by TFLite
set(FLATBUFFERS_BUILD_TESTS OFF)
set(FLATBUFFERS_INSTALL OFF)
set(FLATBUFFERS_BUILD_FLATC OFF)

# Enable this to see details about downloading -- useful for debugging
# set(FETCHCONTENT_QUIET NO)

# tflite includes neon2sse transitively, but it's pinned to an old version
# that declares a minimum CMake version of 3.0. We override it here to a
# new enough version that CMake 4+ won't refuse to build it.
FetchContent_Declare(
neon2sse
GIT_REPOSITORY https://github.com/intel/ARM_NEON_2_x86_SSE
GIT_TAG 4732aac1e6c02984a12635d85c4644c2ffe585ca
add_library(tflite_parser STATIC tflite_parser.cpp)
target_sources(
tflite_parser
PUBLIC
FILE_SET HEADERS
FILES tflite_parser.h
)

FetchContent_Declare(
tflite
GIT_REPOSITORY https://github.com/tensorflow/tensorflow
GIT_TAG ${TFLITE_TAG}
GIT_SHALLOW TRUE
SOURCE_SUBDIR tensorflow/lite/c
target_link_libraries(
tflite_parser
PUBLIC hannk_headers tensorflow-lite::tensorflow-lite interpreter
PRIVATE Halide::Runtime
)

block(SCOPE_FOR POLICIES VARIABLES)
# Suppress warnings about rotting CMake code we don't control
set(CMAKE_POLICY_DEFAULT_CMP0135 OLD) # DOWNLOAD_EXTRACT_TIMESTAMP
set(CMAKE_POLICY_DEFAULT_CMP0169 OLD) # FetchContent_Populate
set(CMAKE_POLICY_DEFAULT_CMP0177 OLD) # install() path normalization

# Configuration for tflite + upstream deps
set(ABSL_PROPAGATE_CXX_STD ON)

# Suppress warnings in tflite code
add_compile_options(
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-anon-enum-enum-conversion>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-deprecated-this-capture>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow-uncaptured-local>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-shadow>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-tautological-type-limit-compare>
$<$<CXX_COMPILER_ID:Clang,AppleClang>:-Wno-unused-template>
)

FetchContent_MakeAvailable(tflite)

set_property(TARGET tensorflowlite_c PROPERTY EXCLUDE_FROM_ALL TRUE)
endblock()

FetchContent_GetProperties(tflite)

# Make an interface library that is just to get the tflite headers,
# without any implied linkage
add_library(tensorflowlite_headers INTERFACE)
target_include_directories(tensorflowlite_headers INTERFACE
$<BUILD_INTERFACE:${tflite_SOURCE_DIR}>)

# ----------------
add_library(tflite_parser STATIC tflite_parser.cpp)
target_include_directories(tflite_parser
PUBLIC $<BUILD_INTERFACE:${hannk_SOURCE_DIR}>
PRIVATE $<BUILD_INTERFACE:${hannk_BINARY_DIR}>
$<BUILD_INTERFACE:${tflite_SOURCE_DIR}>)
# Ensure that the includes from TFLite's captive flatbuffer library get precedence;
# in case the system may have a too-old version installed.
target_include_directories(tflite_parser BEFORE
PRIVATE $<BUILD_INTERFACE:${FlatBuffers_SOURCE_DIR}/include>)
target_link_libraries(tflite_parser PRIVATE Halide::Runtime)
52 changes: 25 additions & 27 deletions apps/hannk/util/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
add_library(error_util STATIC
error_util.cpp)
target_include_directories(error_util PUBLIC
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_link_libraries(error_util PRIVATE Halide::Runtime)
target_sources(error_util PUBLIC FILE_SET HEADERS FILES error_util.h)
target_link_libraries(error_util PUBLIC hannk_headers
PRIVATE Halide::Runtime)


add_library(hannk_log_stderr STATIC EXCLUDE_FROM_ALL
hannk_log_stderr.cpp)
target_include_directories(hannk_log_stderr PUBLIC
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_link_libraries(hannk_log_stderr PUBLIC "$<$<PLATFORM_ID:Android>:log>")
target_link_libraries(hannk_log_stderr PUBLIC
hannk_headers
"$<$<PLATFORM_ID:Android>:log>")


add_library(hannk_log_tflite STATIC EXCLUDE_FROM_ALL
hannk_log_tflite.cpp)
target_link_libraries(hannk_log_tflite PRIVATE tensorflowlite_headers)
target_include_directories(hannk_log_tflite PUBLIC
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_link_libraries(hannk_log_tflite
PRIVATE tensorflow-lite::tensorflow-lite
PUBLIC hannk_headers)

# Sigh, header-only libraries shouldn't be special
add_library(buffer_util INTERFACE)
target_include_directories(buffer_util INTERFACE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_sources(buffer_util INTERFACE FILE_SET HEADERS FILES buffer_util.h)
target_link_libraries(buffer_util INTERFACE hannk_headers)

add_library(file_util INTERFACE)
target_include_directories(file_util INTERFACE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_sources(file_util INTERFACE FILE_SET HEADERS FILES file_util.h)
target_link_libraries(file_util INTERFACE hannk_headers)

add_library(small_vector INTERFACE)
target_include_directories(small_vector INTERFACE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_sources(small_vector INTERFACE FILE_SET HEADERS FILES small_vector.h)
target_link_libraries(small_vector INTERFACE hannk_headers)

add_library(hannk_log_hdr INTERFACE)
target_include_directories(hannk_log_hdr INTERFACE
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_sources(hannk_log_hdr INTERFACE FILE_SET HEADERS FILES hannk_log_hdr.h)
target_link_libraries(hannk_log_hdr INTERFACE hannk_headers)

add_library(model_runner STATIC
model_runner.cpp)
target_include_directories(model_runner PUBLIC
$<BUILD_INTERFACE:${hannk_SOURCE_DIR}>)
target_compile_definitions(model_runner PRIVATE
-DTFLITE_VERSION_MAJOR=${TFLITE_VERSION_MAJOR}
-DTFLITE_VERSION_MINOR=${TFLITE_VERSION_MINOR}
-DTFLITE_VERSION_PATCH=${TFLITE_VERSION_PATCH})
TFLITE_VERSION_MAJOR=${TFLITE_VERSION_MAJOR}
TFLITE_VERSION_MINOR=${TFLITE_VERSION_MINOR}
TFLITE_VERSION_PATCH=${TFLITE_VERSION_PATCH})
target_link_libraries(model_runner PRIVATE
hannk_headers
interpreter
error_util
file_util
tflite_parser
Halide::Tools # for halide_benchmark.h
Halide::Runtime
tensorflowlite_headers)

Halide::Runtime)
if (HANNK_BUILD_TFLITE)
target_link_libraries(model_runner PRIVATE
tensorflowlite_c
tensorflow-lite::tensorflow-lite
hannk_delegate)
endif ()
7 changes: 7 additions & 0 deletions apps/onnx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ if (NOT Python_FOUND)
return()
endif ()

# Normalize to forward slashes before passing to find_package. vcpkg overrides
# find_package with a macro that stores ${ARGN} in a double-quoted string; if
# the path contains a backslash followed by a letter (e.g. \build_bot -> \b),
# CMake treats it as an escape sequence and errors (CMP0010). file(TO_CMAKE_PATH)
# converts native separators to forward slashes, sidestepping the issue on all
# CMake versions.
file(TO_CMAKE_PATH "${Python_SITEARCH}" Python_SITEARCH)
find_package(pybind11 HINTS "${Python_SITEARCH}")
if (NOT pybind11_FOUND)
message(WARNING "Could NOT find pybind11")
Expand Down
Loading
Loading