Skip to content

Commit

Permalink
HANNK_BUILD_TFLITE_DELEGATE -> HANNK_BUILD_TFLITE
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-johnson committed Oct 28, 2021
1 parent e443e17 commit 6e92475
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 33 deletions.
18 changes: 9 additions & 9 deletions apps/hannk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

enable_testing()

option(HANNK_BUILD_TFLITE_DELEGATE "Build TFLite Delegate for HANNK" ON)
if (HANNK_BUILD_TFLITE_DELEGATE AND (Halide_TARGET MATCHES "wasm"))
message(FATAL_ERROR "HANNK_BUILD_TFLITE_DELEGATE must be OFF when targeting wasm")
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_DELEGATE is ${HANNK_BUILD_TFLITE_DELEGATE}")
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
# builds but easier to enable it for everything.
Expand All @@ -25,7 +25,7 @@ set(CMAKE_CXX_EXTENSIONS NO)
find_package(HalideHelpers REQUIRED)

# Set up the version of TFLite we expect
# (We need to do this even if HANNK_BUILD_TFLITE_DELEGATE is off,
# (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")
Expand All @@ -34,10 +34,10 @@ set(TFLITE_VERSION_PATCH "0" CACHE STRING "Patch version of TFLite to assume")
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_DELEGATE)
add_compile_definitions(HANNK_BUILD_TFLITE_DELEGATE=1)
if (HANNK_BUILD_TFLITE)
add_compile_definitions(HANNK_BUILD_TFLITE=1)
else ()
add_compile_definitions(HANNK_BUILD_TFLITE_DELEGATE=0)
add_compile_definitions(HANNK_BUILD_TFLITE=0)
endif ()

set(TFLITE_VERSION "${TFLITE_VERSION_MAJOR}.${TFLITE_VERSION_MINOR}.${TFLITE_VERSION_PATCH}")
Expand All @@ -46,7 +46,7 @@ add_subdirectory(halide)
add_subdirectory(interpreter)
add_subdirectory(tflite)
add_subdirectory(util)
if (HANNK_BUILD_TFLITE_DELEGATE)
if (HANNK_BUILD_TFLITE)
add_subdirectory(delegate)
endif ()

Expand Down
2 changes: 1 addition & 1 deletion apps/hannk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include ../support/Makefile.inc
CXXFLAGS += -Wno-unused-private-field -fno-exceptions -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -Wunused-variable -Wsuggest-override -Woverloaded-virtual -I$(MAKEFILE_DIR)

# No option to build without TFLite/Delegate in Make (use CMake for that)
CXXFLAGS += -DHANNK_BUILD_TFLITE_DELEGATE=1
CXXFLAGS += -DHANNK_BUILD_TFLITE=1

BENCHMARK_OUT = benchmark
ifeq (hexagon-32-qurt,$(findstring hexagon-32-qurt,$(HL_TARGET)))
Expand Down
12 changes: 6 additions & 6 deletions apps/hannk/configure_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ if [ -z "${CMAKE_BUILD_TYPE}" ]; then
CMAKE_BUILD_TYPE=Release
fi

if [ -z "${HANNK_BUILD_TFLITE_DELEGATE}" ]; then
HANNK_BUILD_TFLITE_DELEGATE=ON
if [ -z "${HANNK_BUILD_TFLITE}" ]; then
HANNK_BUILD_TFLITE=ON
else
HANNK_BUILD_TFLITE_DELEGATE=OFF
HANNK_BUILD_TFLITE=OFF
fi

PREFIX=
Expand All @@ -45,7 +45,7 @@ if [[ "${HL_TARGET}" =~ ^arm-64-android.* ]]; then
elif [[ "${HL_TARGET}" =~ ^wasm-32-wasmrt.* ]]; then

PREFIX=emcmake
HANNK_BUILD_TFLITE_DELEGATE=OFF
HANNK_BUILD_TFLITE=OFF

else

Expand All @@ -63,7 +63,7 @@ echo Using BUILD_DIR=${BUILD_DIR}
echo Using build tool=${CMAKE_GENERATOR}
echo Using CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
echo Using HL_TARGET=${HL_TARGET}
echo Using HANNK_BUILD_TFLITE_DELEGATE=${HANNK_BUILD_TFLITE_DELEGATE}
echo Using HANNK_BUILD_TFLITE=${HANNK_BUILD_TFLITE}

mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}"
Expand All @@ -75,6 +75,6 @@ ${PREFIX} cmake \
-DHalide_DIR="${HALIDE_INSTALL_PATH}/lib/cmake/Halide" \
-DHalideHelpers_DIR="${HALIDE_INSTALL_PATH}/lib/cmake/HalideHelpers" \
-DHalide_TARGET=${HL_TARGET} \
-DHANNK_BUILD_TFLITE_DELEGATE=${HANNK_BUILD_TFLITE_DELEGATE} \
-DHANNK_BUILD_TFLITE=${HANNK_BUILD_TFLITE} \
-S "${HANNK_DIR}" \
-B "${BUILD_DIR}"
4 changes: 2 additions & 2 deletions apps/hannk/delegate/hannk_delegate.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef HANNK_DELEGATE_H
#define HANNK_DELEGATE_H

#if !HANNK_BUILD_TFLITE_DELEGATE
#error "This file should not be included when HANNK_BUILD_TFLITE_DELEGATE=0"
#if !HANNK_BUILD_TFLITE
#error "This file should not be included when HANNK_BUILD_TFLITE=0"
#endif

#include "tensorflow/lite/c/c_api.h"
Expand Down
2 changes: 1 addition & 1 deletion apps/hannk/tflite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ endif ()

# tensorflowlite_c is implicitly declared by this FetchContent.
# Mark it as EXCLUDE_FROM_ALL so that it won't be built unless we actually
# depend on it (which we might not depending on HANNK_BUILD_TFLITE_DELEGATE)
# depend on it (which we might not depending on HANNK_BUILD_TFLITE)
set_property(TARGET tensorflowlite_c PROPERTY EXCLUDE_FROM_ALL TRUE)

# Disable some noisy warnings in abseil
Expand Down
2 changes: 1 addition & 1 deletion apps/hannk/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ target_link_libraries(model_runner PRIVATE
Halide::Runtime
tensorflowlite_headers)

if (HANNK_BUILD_TFLITE_DELEGATE)
if (HANNK_BUILD_TFLITE)
target_link_libraries(model_runner PRIVATE
tensorflowlite_c
hannk_delegate)
Expand Down
20 changes: 10 additions & 10 deletions apps/hannk/util/model_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#include "util/model_runner.h"

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
#include "delegate/hannk_delegate.h"
#endif
#include "halide_benchmark.h"
Expand All @@ -19,7 +19,7 @@
#include "util/error_util.h"
#include "util/file_util.h"

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
// IMPORTANT: use only the TFLite C API here.
#include "tensorflow/lite/c/c_api.h"
#include "tensorflow/lite/c/common.h"
Expand All @@ -33,7 +33,7 @@ std::chrono::duration<double> bench(std::function<void()> f) {
return std::chrono::duration<double>(result.wall_time);
}

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
halide_type_t tf_lite_type_to_halide_type(TfLiteType t) {
switch (t) {
case kTfLiteBool:
Expand Down Expand Up @@ -240,7 +240,7 @@ int SeedTracker::seed_for_name(const std::string &name) {
return seed_here;
}

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
/*static*/ void TfLiteModelRunner::ErrorReporter(void *user_data, const char *format, va_list args) {
TfLiteModelRunner *self = (TfLiteModelRunner *)user_data;
if (self->verbose_output_) {
Expand Down Expand Up @@ -351,7 +351,7 @@ TfLiteModelRunner::~TfLiteModelRunner() {

ModelRunner::ModelRunner() {
for (int i = 0; i < kNumRuns; i++) {
#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
do_run[i] = true;
#else
do_run[i] = (i == kHannk);
Expand Down Expand Up @@ -381,7 +381,7 @@ void ModelRunner::status() {
std::cout << "Using random seed: " << seed_tracker_.next_seed() << "\n";
std::cout << "Using threads: " << threads << "\n";

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
std::string tf_ver = TfLiteVersion();
std::cout << "Using TFLite version: " << tf_ver << "\n";
std::string expected = std::to_string(TFLITE_VERSION_MAJOR) + "." + std::to_string(TFLITE_VERSION_MINOR) + ".";
Expand Down Expand Up @@ -453,7 +453,7 @@ ModelRunner::RunResult ModelRunner::run_in_hannk(const std::vector<char> &buffer
return result;
}

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
ModelRunner::RunResult ModelRunner::run_in_tflite(const std::vector<char> &buffer, TfLiteDelegate *delegate) {
RunResult result;

Expand Down Expand Up @@ -539,7 +539,7 @@ int ModelRunner::parse_flags(int argc, char **argv, std::vector<std::string> &fi
case 'h':
this->do_run[ModelRunner::kHannk] = true;
break;
#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
case 't':
this->do_run[ModelRunner::kTfLite] = true;
break;
Expand Down Expand Up @@ -650,7 +650,7 @@ void ModelRunner::run(const std::string &filename) {

const std::vector<char> buffer = read_entire_file(filename);

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
const auto exec_tflite = [this, &buffer]() {
return run_in_tflite(buffer);
};
Expand Down Expand Up @@ -679,7 +679,7 @@ void ModelRunner::run(const std::string &filename) {
#endif

for (WhichRun i : active_runs) {
#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
results[i] = execs.at(i)();
#else
if (i != kHannk) {
Expand Down
6 changes: 3 additions & 3 deletions apps/hannk/util/model_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "util/buffer_util.h"

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
struct TfLiteDelegate;
struct TfLiteInterpreter;
struct TfLiteInterpreterOptions;
Expand Down Expand Up @@ -62,7 +62,7 @@ struct SeedTracker {
SeedTracker &operator=(SeedTracker &&) = delete;
};

#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
class TfLiteModelRunner {
TfLiteModel *tf_model_ = nullptr;
TfLiteInterpreterOptions *tf_options_ = nullptr;
Expand Down Expand Up @@ -134,7 +134,7 @@ struct ModelRunner {
std::chrono::duration<double> time{0};
};
RunResult run_in_hannk(const std::vector<char> &buffer);
#if HANNK_BUILD_TFLITE_DELEGATE
#if HANNK_BUILD_TFLITE
RunResult run_in_tflite(const std::vector<char> &buffer, TfLiteDelegate *delegate = nullptr);
#endif
bool compare_results(const std::string &name_a, const std::string &name_b, const RunResult &a, const RunResult &b);
Expand Down

0 comments on commit 6e92475

Please sign in to comment.