diff --git a/apps/hannk/CMakeLists.txt b/apps/hannk/CMakeLists.txt index 740766c0476a..ee2565773f62 100644 --- a/apps/hannk/CMakeLists.txt +++ b/apps/hannk/CMakeLists.txt @@ -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}") @@ -44,6 +44,14 @@ add_compile_definitions(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 + $) # ---------------------------- @@ -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}) diff --git a/apps/hannk/delegate/CMakeLists.txt b/apps/hannk/delegate/CMakeLists.txt index e53f022bf426..b7d56f7c2e26 100644 --- a/apps/hannk/delegate/CMakeLists.txt +++ b/apps/hannk/delegate/CMakeLists.txt @@ -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 - $) # --------------- 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 - $) # --------------- external (shared-library) delegate @@ -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 - $) 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") - diff --git a/apps/hannk/tflite/CMakeLists.txt b/apps/hannk/tflite/CMakeLists.txt index 0f3e238e72fc..9938c3f656ab 100644 --- a/apps/hannk/tflite/CMakeLists.txt +++ b/apps/hannk/tflite/CMakeLists.txt @@ -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( - $<$:-Wno-anon-enum-enum-conversion> - $<$:-Wno-deprecated-this-capture> - $<$:-Wno-shadow-uncaptured-local> - $<$:-Wno-shadow> - $<$:-Wno-tautological-type-limit-compare> - $<$:-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 - $) - -# ---------------- -add_library(tflite_parser STATIC tflite_parser.cpp) -target_include_directories(tflite_parser - PUBLIC $ - PRIVATE $ - $) -# 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 $) -target_link_libraries(tflite_parser PRIVATE Halide::Runtime) diff --git a/apps/hannk/util/CMakeLists.txt b/apps/hannk/util/CMakeLists.txt index ca1bc09d5ce1..cf90afbe4302 100644 --- a/apps/hannk/util/CMakeLists.txt +++ b/apps/hannk/util/CMakeLists.txt @@ -1,57 +1,55 @@ add_library(error_util STATIC error_util.cpp) -target_include_directories(error_util PUBLIC - $) -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 - $) -target_link_libraries(hannk_log_stderr PUBLIC "$<$:log>") +target_link_libraries(hannk_log_stderr PUBLIC + hannk_headers + "$<$: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 - $) +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 - $) +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 - $) +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 - $) +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 - $) +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 - $) 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 () diff --git a/apps/onnx/CMakeLists.txt b/apps/onnx/CMakeLists.txt index 54200c8d3e2d..4be0fce23ec9 100644 --- a/apps/onnx/CMakeLists.txt +++ b/apps/onnx/CMakeLists.txt @@ -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") diff --git a/apps/onnx/model.cpp b/apps/onnx/model.cpp index 1e9c7770d301..b1e439cfd94b 100644 --- a/apps/onnx/model.cpp +++ b/apps/onnx/model.cpp @@ -6,9 +6,10 @@ #include "common_types.h" #include "denormal_disabler.h" #include "onnx_converter.h" +#include #include +#include #include -#include #include namespace py = pybind11; @@ -72,14 +73,53 @@ std::string auto_schedule(const HalideModel &pipeline) { template struct Distribution { - typedef typename std::conditional< + using Type = typename std::conditional< std::is_floating_point::value, std::uniform_real_distribution, - std::uniform_int_distribution>::type Type; + std::uniform_int_distribution>::type; + + T operator()(std::mt19937 &generator) { + return distrib(generator); + } + +private: + Type distrib; }; + template<> struct Distribution { - typedef typename std::uniform_int_distribution Type; + using Type = std::bernoulli_distribution; + + bool operator()(std::mt19937 &generator) { + return distrib(generator); + } + +private: + Type distrib = Type(0.5); +}; + +template<> +struct Distribution { + using Type = std::uniform_int_distribution; + + std::int8_t operator()(std::mt19937 &generator) { + return static_cast(distrib(generator)); + } + +private: + Type distrib = Type(0, std::numeric_limits::max()); +}; + +template<> +struct Distribution { + using Type = std::uniform_int_distribution; + + std::uint8_t operator()(std::mt19937 &generator) { + return static_cast(distrib(generator)); + } + +private: + Type distrib = Type(0, std::numeric_limits::max()); }; template @@ -92,7 +132,7 @@ void prepare_random_image_param( std::vector dims(shape.size()); std::iota(dims.rbegin(), dims.rend(), 0); values.transpose(dims); - typename Distribution::Type distrib; + Distribution distrib; std::mt19937 generator; values.for_each_value([&](T &val) { val = distrib(generator); }); image_param.set(values); @@ -436,7 +476,7 @@ double benchmark( CacheEvictor cache_evictor; // Generate random value for every input - for (ssize_t i = 0; i < pipeline.model->inputs.size(); ++i) { + for (size_t i = 0; i < pipeline.model->inputs.size(); ++i) { const std::string &input_name = pipeline.input_names[i]; prepare_random_input(pipeline, input_name); } @@ -469,29 +509,28 @@ double benchmark( pipeline.rep->realize(real, tgt); // Now benchmark by computing the value of the outputs num_iter times - struct timespec start; - struct timespec end; - clock_gettime(CLOCK_REALTIME, &start); + using clock = std::chrono::high_resolution_clock; + auto start = clock::now(); for (int i = 0; i < num_iters; ++i) { // Increment the coefficients store in the cache evictor: this ensures that // all the data left in caches from the previous iteration is flushed out. cache_evictor.flush_caches(); pipeline.rep->realize(real, tgt); } - clock_gettime(CLOCK_REALTIME, &end); + auto end = clock::now(); double total_runtime = - (end.tv_sec - start.tv_sec) * 1e9 + end.tv_nsec - start.tv_nsec; + std::chrono::duration(end - start).count(); // Figure out how long it took to generate new inputs at every iteration // and adjust the runtime accordingly. - clock_gettime(CLOCK_REALTIME, &start); + start = clock::now(); for (int i = 0; i < num_iters; ++i) { cache_evictor.flush_caches(); } - clock_gettime(CLOCK_REALTIME, &end); + end = clock::now(); double input_gen_time = - (end.tv_sec - start.tv_sec) * 1e9 + end.tv_nsec - start.tv_nsec; + std::chrono::duration(end - start).count(); total_runtime -= input_gen_time; diff --git a/apps/onnx/onnx_converter.cc b/apps/onnx/onnx_converter.cc index 9902beaeae0f..917bd5029753 100644 --- a/apps/onnx/onnx_converter.cc +++ b/apps/onnx/onnx_converter.cc @@ -1,9 +1,11 @@ #include "onnx_converter.h" #include -#include -#include +#include #include +#define _USE_MATH_DEFINES +#include + static Halide::Expr div_up(Halide::Expr num, int denom) { return Halide::Internal::simplify((num + denom - 1) / denom); } diff --git a/apps/vcpkg-configuration.json b/apps/vcpkg-configuration.json new file mode 100644 index 000000000000..34f2b6940592 --- /dev/null +++ b/apps/vcpkg-configuration.json @@ -0,0 +1,5 @@ +{ + "overlay-ports": [ + "vcpkg/ports" + ] +} diff --git a/apps/vcpkg.json b/apps/vcpkg.json index 424c59220fbe..9420a5f7ec93 100644 --- a/apps/vcpkg.json +++ b/apps/vcpkg.json @@ -4,10 +4,6 @@ "license": "MIT", "supports": "!uwp", "builtin-baseline": "66c0373dc7fca549e5803087b9487edfe3aca0a1", - "default-features": [ - "jit", - "serialization" - ], "dependencies": [ { "name": "cuda", @@ -20,6 +16,7 @@ { "name": "opencl", "platform": "(windows & x64 & !uwp & !xbox) | (linux & x64) | (linux & arm64)" - } + }, + "tensorflow-lite" ] } diff --git a/apps/vcpkg/ports/farmhash/portfile.cmake b/apps/vcpkg/ports/farmhash/portfile.cmake new file mode 100644 index 000000000000..83da051a6377 --- /dev/null +++ b/apps/vcpkg/ports/farmhash/portfile.cmake @@ -0,0 +1,11 @@ +set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO google/farmhash + REF 0d859a811870d10f53a594927d0d0b97573ad06d # latest (2019-05-13) as of 2026-02-24 + SHA512 7bc14931e488464c1cedbc17551fb90a8cec494d0e0860db9df8efff09000fd8d91e01060dd5c5149b1104ac4ac8bf7eb57e5b156b05ef42636938edad1518f1 +) + +file(INSTALL "${SOURCE_PATH}/" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/src") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/COPYING") diff --git a/apps/vcpkg/ports/farmhash/vcpkg.json b/apps/vcpkg/ports/farmhash/vcpkg.json new file mode 100644 index 000000000000..8c47e132d8b0 --- /dev/null +++ b/apps/vcpkg/ports/farmhash/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "farmhash", + "version": "1.1", + "description": "FarmHash hash functions (source provider for TFLite in-tree build)", + "homepage": "https://github.com/google/farmhash", + "license": "MIT" +} diff --git a/apps/vcpkg/ports/fft2d/portfile.cmake b/apps/vcpkg/ports/fft2d/portfile.cmake new file mode 100644 index 000000000000..336b777d662d --- /dev/null +++ b/apps/vcpkg/ports/fft2d/portfile.cmake @@ -0,0 +1,11 @@ +set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO petewarden/OouraFFT + REF c6fd2dd6d21397baa6653139d31d84540d5449a2 # v1.0 + SHA512 e6ee68df13f803707384856c5b02460826ba03710cde9c17e64469026993806305d89fff139e91d99fe655550ba7cc66d3d69e14a682bfd34951382f7a95ec92 +) + +file(INSTALL "${SOURCE_PATH}/" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/src") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/readme2d.txt") diff --git a/apps/vcpkg/ports/fft2d/vcpkg.json b/apps/vcpkg/ports/fft2d/vcpkg.json new file mode 100644 index 000000000000..41310731d6b3 --- /dev/null +++ b/apps/vcpkg/ports/fft2d/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "fft2d", + "version-string": "1.0", + "description": "Ooura FFT C sources (source provider for TFLite in-tree build)", + "homepage": "https://github.com/petewarden/OouraFFT", + "license": "LicenseRef-OouraFFT" +} \ No newline at end of file diff --git a/apps/vcpkg/ports/ml-dtypes/portfile.cmake b/apps/vcpkg/ports/ml-dtypes/portfile.cmake new file mode 100644 index 000000000000..bfd6f0f27f3c --- /dev/null +++ b/apps/vcpkg/ports/ml-dtypes/portfile.cmake @@ -0,0 +1,13 @@ +set(VCPKG_POLICY_EMPTY_INCLUDE_FOLDER enabled) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO jax-ml/ml_dtypes + REF 9fd1a480f1cdb23b3d28dfea5eadf3d84b6dfc62 # v0.5.4 + SHA512 b04a5968e1c6fa143d018e927888597feb97b52d2df214538f517e74a5cc87a412ccc4dff4e1a65d40f048e08d13c74778c1c584f1ad12f4ae92fffb5dd6321d +) + +file(INSTALL "${SOURCE_PATH}/" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/src") +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/share/${PORT}/src/third_party") + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") diff --git a/apps/vcpkg/ports/ml-dtypes/vcpkg.json b/apps/vcpkg/ports/ml-dtypes/vcpkg.json new file mode 100644 index 000000000000..e6ce32e35676 --- /dev/null +++ b/apps/vcpkg/ports/ml-dtypes/vcpkg.json @@ -0,0 +1,7 @@ +{ + "name": "ml-dtypes", + "version-string": "0.5.4", + "description": "Machine learning data types support headers (source provider for TFLite in-tree build)", + "homepage": "https://github.com/jax-ml/ml_dtypes", + "license": "Apache-2.0" +} diff --git a/apps/vcpkg/ports/ruy/portfile.cmake b/apps/vcpkg/ports/ruy/portfile.cmake new file mode 100644 index 000000000000..34794d2d79c6 --- /dev/null +++ b/apps/vcpkg/ports/ruy/portfile.cmake @@ -0,0 +1,27 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO google/ruy + REF 2af88863614a8298689cc52b1a47b3fcad7be835 # latest (2026-02-16) as of 2026-02-24 + SHA512 e2cb19d7cc98c29b86a02971cb98941954eee05505ff1600e3eebbd0ec85afad01c22eed7d49d9948fde9f83413704f86b58f4a10c5dedcb0bbfaf854fa25242 +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DRUY_MINIMAL_BUILD=ON + -DRUY_ENABLE_INSTALL=ON + -DRUY_FIND_CPUINFO=ON + -DRUY_PROFILER=OFF +) + +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(PACKAGE_NAME ruy CONFIG_PATH lib/cmake/ruy) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) diff --git a/apps/vcpkg/ports/ruy/vcpkg.json b/apps/vcpkg/ports/ruy/vcpkg.json new file mode 100644 index 000000000000..b8167f8e6c01 --- /dev/null +++ b/apps/vcpkg/ports/ruy/vcpkg.json @@ -0,0 +1,19 @@ +{ + "name": "ruy", + "version-string": "2026.02.16", + "description": "Matrix multiplication library used by TensorFlow Lite", + "homepage": "https://github.com/google/ruy", + "license": "Apache-2.0", + "dependencies": [ + "abseil", + "cpuinfo", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/apps/vcpkg/ports/tensorflow-lite/fix-msvc-friend-access.patch b/apps/vcpkg/ports/tensorflow-lite/fix-msvc-friend-access.patch new file mode 100644 index 000000000000..fde14b4d2e92 --- /dev/null +++ b/apps/vcpkg/ports/tensorflow-lite/fix-msvc-friend-access.patch @@ -0,0 +1,20 @@ +diff --git a/tensorflow/lite/core/model_building.h b/tensorflow/lite/core/model_building.h +--- a/tensorflow/lite/core/model_building.h ++++ b/tensorflow/lite/core/model_building.h +@@ -88,6 +88,7 @@ + + Buffer(const Buffer&) = default; + Buffer& operator=(const Buffer&) = default; ++ InterpreterInfo* GetBuilder() const noexcept { return builder_; } + + private: + Buffer(InterpreterInfo* builder, BufferIdx buffer_idx) +@@ -136,7 +137,7 @@ + Tensor(const Tensor&) = default; + Tensor& operator=(const Tensor&) = default; + +- explicit Tensor(Buffer buffer) : builder_(buffer.builder_) {} ++ explicit Tensor(Buffer buffer) : builder_(buffer.GetBuilder()) {} + + private: + Tensor() = default; diff --git a/apps/vcpkg/ports/tensorflow-lite/fix-neon2sse-config.patch b/apps/vcpkg/ports/tensorflow-lite/fix-neon2sse-config.patch new file mode 100644 index 000000000000..886022ae8c2e --- /dev/null +++ b/apps/vcpkg/ports/tensorflow-lite/fix-neon2sse-config.patch @@ -0,0 +1,15 @@ +diff --git a/tensorflow/lite/tools/cmake/tensorflow-liteConfig.cmake.in b/tensorflow/lite/tools/cmake/tensorflow-liteConfig.cmake.in +index e49f635..d4b92a7 100644 +--- a/tensorflow/lite/tools/cmake/tensorflow-liteConfig.cmake.in ++++ b/tensorflow/lite/tools/cmake/tensorflow-liteConfig.cmake.in +@@ -18,7 +18,9 @@ include(CMakeFindDependencyMacro) + find_dependency(absl) + find_dependency(Eigen3) + find_dependency(FlatBuffers) +-find_dependency(NEON_2_SSE) ++if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86|X86|amd64|AMD64|x86_64|X64") ++ find_dependency(NEON_2_SSE) ++endif() + find_dependency(cpuinfo) + find_dependency(ruy) + find_dependency(gemmlowp) diff --git a/apps/vcpkg/ports/tensorflow-lite/portfile.cmake b/apps/vcpkg/ports/tensorflow-lite/portfile.cmake new file mode 100644 index 000000000000..0743528594d8 --- /dev/null +++ b/apps/vcpkg/ports/tensorflow-lite/portfile.cmake @@ -0,0 +1,106 @@ +vcpkg_check_linkage(ONLY_STATIC_LIBRARY) + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO tensorflow/tensorflow + REF a344c313f75bbe28d00abe63f5d49cd6f233b6d0 # 2.21.0-rc0 + SHA512 48463c1dde438f18bf8d17104537258d6edf308be9f48af4fb40abee011a6f8c1c8aa50220fd1928bdfb8f251b8a9c764a1db50c9b7b9b0fe34d9e11d5273e4e + PATCHES + fix-neon2sse-config.patch + fix-msvc-friend-access.patch +) + +# Protobuf is used by subdirectories (profiling/proto, tools/benchmark). +# Injecting find_package at TFLite's top-level scope ensures that +# protobuf::libprotobuf is visible to all subdirectories regardless +# how upstream structures its find_package/add_subdirectory ordering. +file(WRITE "${CURRENT_BUILDTREES_DIR}/inject_protobuf.cmake" + "find_package(Protobuf REQUIRED)\n") + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}/tensorflow/lite" + OPTIONS + -DTENSORFLOW_SOURCE_DIR="${SOURCE_PATH}" + -DBUILD_SHARED_LIBS=OFF + -DTFLITE_ENABLE_INSTALL=ON + -DTFLITE_ENABLE_LABEL_IMAGE=OFF + -DTFLITE_ENABLE_BENCHMARK_MODEL=OFF + -DTFLITE_ENABLE_RUY=OFF + -DTFLITE_ENABLE_XNNPACK=OFF + -DTFLITE_ENABLE_EXTERNAL_DELEGATE=OFF + -DTFLITE_ENABLE_GPU=OFF + -DTFLITE_ENABLE_METAL=OFF + -DCMAKE_FIND_PACKAGE_PREFER_CONFIG=ON + "-DCMAKE_PROJECT_tensorflow-lite_INCLUDE=${CURRENT_BUILDTREES_DIR}/inject_protobuf.cmake" + # farmhash, fft2d, and ml-dtypes are source-provider ports; redirect + # TFLite's FetchContent to the vcpkg-installed source trees so they + # compile in-tree and are exported into tensorflow-liteTargets. + "-DFETCHCONTENT_SOURCE_DIR_FARMHASH=${CURRENT_INSTALLED_DIR}/share/farmhash/src" + "-DFETCHCONTENT_SOURCE_DIR_FFT2D=${CURRENT_INSTALLED_DIR}/share/fft2d/src" + "-DFETCHCONTENT_SOURCE_DIR_ML_DTYPES=${CURRENT_INSTALLED_DIR}/share/ml-dtypes/src" +) + +vcpkg_cmake_install() + +# Upstream install omits headers used by Hannk delegate/logging. +file( + INSTALL "${SOURCE_PATH}/tensorflow/lite/tools" + DESTINATION "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite" + FILES_MATCHING + PATTERN "*.h" +) +file( + INSTALL "${SOURCE_PATH}/tensorflow/compiler/mlir/lite" + DESTINATION "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir" + FILES_MATCHING + PATTERN "*.h" +) + +vcpkg_cmake_config_fixup(PACKAGE_NAME tensorflow-lite CONFIG_PATH lib/cmake/tensorflow-lite) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") + +file( + REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" + # The tools and mlir/lite header installs above replicate the full source + # directory tree, including subdirectories with no headers (testdata, tests, + # Android/iOS app scaffolding, cmake module scripts, etc.). + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/experimental/tac/g3doc" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/experimental/tac/tests" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/integrations" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/metrics/testdata" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/quantization/lite/testdata" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/quantization/tensorflow/tests" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/quantization/tests" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/quantization/tools" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/sparsity/testdata" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/stablehlo/odml_converter/tests" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/stablehlo/odml_converter/transforms" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/stablehlo/tests" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/stablehlo/transforms/mhlo_passes" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/stablehlo/transforms/torch" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/testdata" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/compiler/mlir/lite/tests" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/benchmark/android" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/benchmark/experimental" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/benchmark/ios" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/benchmark/proto" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/cmake" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/delegates/compatibility/protos" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/delegates/experimental" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/proto" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/stages/testdata" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/tasks/coco_object_detection" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/tasks/imagenet_image_classification" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/tasks/inference_diff" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/tasks/ios" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/evaluation/testdata" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/make" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/optimize/debugging" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/optimize/g3doc" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/optimize/python" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/optimize/sparsity" + "${CURRENT_PACKAGES_DIR}/include/tensorflow/lite/tools/pip_package" +) diff --git a/apps/vcpkg/ports/tensorflow-lite/vcpkg.json b/apps/vcpkg/ports/tensorflow-lite/vcpkg.json new file mode 100644 index 000000000000..ad16c0bab12d --- /dev/null +++ b/apps/vcpkg/ports/tensorflow-lite/vcpkg.json @@ -0,0 +1,36 @@ +{ + "name": "tensorflow-lite", + "version-string": "2.21.0-rc0-a344c313", + "description": "TensorFlow Lite runtime and C API", + "homepage": "https://github.com/tensorflow/tensorflow", + "license": "Apache-2.0", + "dependencies": [ + "abseil", + "cpuinfo", + "eigen3", + "fp16", + "farmhash", + "fft2d", + "flatbuffers", + "gemmlowp", + "ml-dtypes", + { + "name": "neon2sse", + "platform": "x86 | x64" + }, + "protobuf", + { + "name": "protobuf", + "host": true + }, + "ruy", + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +}