Skip to content

Commit

Permalink
Disable bluepill, hexagon and riscv
Browse files Browse the repository at this point in the history
Also eliminates needs for codegen examples to specify the runtime
objects
  • Loading branch information
rascani committed Sep 14, 2023
1 parent 29c9fba commit cbb40c1
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
13 changes: 4 additions & 9 deletions codegen/examples/hello_world/Makefile.inc
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
# TODO(rjascani): The codegen runtime files (ie, in runtime subdir) should be a
# separate library.
CODEGEN_HELLO_WORLD_SRCS := \
$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world.cc \
$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world_model.cc \
$(TENSORFLOW_ROOT)codegen/runtime/micro_codegen_context.cc
CODEGEN_HELLO_WORLD_MODEL := \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/examples/hello_world/models/hello_world_int8.tflite

CODEGEN_HELLO_WORLD_HDRS := \
$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world_model.h \
$(TENSORFLOW_ROOT)codegen/runtime/micro_codegen_context.h
CODEGEN_HELLO_WORLD_SRCS := \
$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world.cc

# Builds a standalone binary.
$(eval $(call codegen_model_binary,codegen_hello_world,hello_world_model,\
Expand Down
2 changes: 1 addition & 1 deletion codegen/examples/hello_world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ make -f tensorflow/lite/micro/tools/make/Makefile codegen_hello_world
## Running the example

TODO(rjascani): The command works, but it'll just crash as we don't have all of
the data structures fullypopulated yet.
the data structures fully populated yet.

```
make -f tensorflow/lite/micro/tools/make/Makefile run_codegen_hello_world
Expand Down
5 changes: 5 additions & 0 deletions codegen/runtime/Makefile.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CODEGEN_RUNTIME_CC_SRCS := \
$(TENSORFLOW_ROOT)codegen/runtime/micro_codegen_context.cc

CODEGEN_RUNTIME_CC_HDRS := \
$(TENSORFLOW_ROOT)codegen/runtime/micro_codegen_context.h
12 changes: 12 additions & 0 deletions tensorflow/lite/micro/tools/make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ endif
TENSORFLOW_ROOT :=
RELATIVE_MAKEFILE_DIR := tensorflow/lite/micro/tools/make
MAKEFILE_DIR := $(TENSORFLOW_ROOT)$(RELATIVE_MAKEFILE_DIR)
BAZEL_ROOT := $(TENSORFLOW_ROOT)
ifeq ($(BAZEL_ROOT),)
BAZEL_ROOT = .
endif

# Pull in some convenience functions.
include $(MAKEFILE_DIR)/helper_functions.inc
Expand Down Expand Up @@ -298,6 +302,8 @@ CODEGEN_PREPROCESSOR_PATH := $(BINDIR)codegen_preprocessor

MICRO_LITE_CODEGEN_PREPROCESSOR := $(TENSORFLOW_ROOT)codegen/preprocessor/Makefile.inc

MICRO_LITE_CODEGEN_RUNTIME := $(TENSORFLOW_ROOT)codegen/runtime/Makefile.inc

MICRO_LITE_CODEGEN_EXAMPLES := $(shell find $(TENSORFLOW_ROOT)codegen/examples/ -name Makefile.inc)

MICROLITE_TEST_SRCS := \
Expand Down Expand Up @@ -711,6 +717,9 @@ include $(MAKEFILE_DIR)/additional_tests.inc
# Load codegen preprocessor rules
include $(MICRO_LITE_CODEGEN_PREPROCESSOR)

# Load codegen runtime rules
include $(MICRO_LITE_CODEGEN_RUNTIME)

# Create rules for downloading third-party dependencies.
THIRD_PARTY_TARGETS :=
$(foreach DOWNLOAD,$(THIRD_PARTY_DOWNLOADS),$(eval $(call create_download_rule,$(DOWNLOAD))))
Expand All @@ -728,6 +737,9 @@ $(patsubst %.S,%.o,$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(THIRD_PARTY_KERNEL_C
MICROLITE_KERNEL_OBJS := $(addprefix $(KERNEL_OBJDIR), \
$(patsubst %.S,%.o,$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(MICROLITE_CC_KERNEL_SRCS)))))

MICROLITE_CODEGEN_RUNTIME_OBJS := $(addprefix $(CORE_OBJDIR), \
$(patsubst %.S,%.o,$(patsubst %.cc,%.o,$(patsubst %.c,%.o,$(MICROLITE_CC_CODEGEN_RUNTIME_SRCS)))))

$(CORE_OBJDIR)%.o: %.cc $(THIRD_PARTY_TARGETS)
@mkdir -p $(dir $@)
$(CXX) $(CXXFLAGS) $(CORE_OPTIMIZATION_LEVEL) $(INCLUDES) -c $< -o $@
Expand Down
42 changes: 39 additions & 3 deletions tensorflow/lite/micro/tools/make/helper_functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,17 @@ recursive_find = $(wildcard $(1)$(2)) $(foreach dir,$(wildcard $(1)*),$(call rec
# 3 - Model
# Calling eval on the output will create the targets that you need.
define codegen_model
# Filter out targets that currently don't support codegen:
# Bluepill: Is compiled with nostdlib, but preprocessor uses standard library.
# RISC-V: TODO(b/300484340): qemu-riscv32 currently does not support semi-
# hosting, which prevents the preprocessor from opening a file on the
# host filesystem.
# Hexagon: TODO(b/300322637): The hexagon 3.5.1 SDK doesn't provide a working
# C++11 stdlib, so preprocessor fails to link.
ifneq ($(TARGET), $(filter $(TARGET), bluepill riscv32_generic hexagon))

$(1)_MODEL := $(3)
$(1)_PREPROCESSOR_OUTPUT := $(GENERATED_SRCS_DIR)/$(2).ppd
$(1)_PREPROCESSOR_OUTPUT := $(GENERATED_SRCS_DIR)$(2).ppd

$(1)_GENERATED_SRCS := $(GENERATED_SRCS_DIR)$(2).cc
$(1)_GENERATED_HDRS := $(GENERATED_SRCS_DIR)$(2).h
Expand All @@ -139,18 +147,22 @@ $$($(1)_PREPROCESSOR_OUTPUT): $(CODEGEN_PREPROCESSOR_PATH) $$($(1)_MODEL)
$(abspath $$($(1)_MODEL)) $(abspath $$($(1)_PREPROCESSOR_OUTPUT))

$$($(1)_GENERATED_SRCS) $$($(1)_GENERATED_HDRS): $$($(1)_MODEL) $$($(1)_PREPROCESSOR_OUTPUT)
cd $(TENSORFLOW_ROOT) && bazel run //codegen:code_generator -- \
cd $(BAZEL_ROOT) && bazel run //codegen:code_generator -- \
--model $(abspath $$($(1)_MODEL)) \
--preprocessed_data $(abspath $$($(1)_PREPROCESSOR_OUTPUT)) \
--output_dir $(abspath $(GENERATED_SRCS_DIR)) --output_name $(2)

$(1): $$($(1)_GENERATED_SRCS) $$($(1)_GENERATED_HDRS)

endif
endef # codegen_model

# Generates and compiles code capable of performing inference without an
# interpreter.
#
# Users can use `make run_<target>` to execute the binary in the appropriate
# simulator.
#
# Arguments are:
# 1 - Name of target
# 2 - Generated source basename
Expand All @@ -159,6 +171,14 @@ endef # codegen_model
# 5 - C/C++ header files
# Calling eval on the output will create the targets that you need.
define codegen_model_binary
# Filter out targets that currently don't support codegen:
# Bluepill: Is compiled with nostdlib, but preprocessor uses standard library.
# RISC-V: TODO(b/300484340): qemu-riscv32 currently does not support semi-
# hosting, which prevents the preprocessor from opening a file on the
# host filesystem.
# Hexagon: TODO(b/300322637): The hexagon 3.5.1 SDK doesn't provide a working
# C++11 stdlib, so preprocessor fails to link.
ifneq ($(TARGET), $(filter $(TARGET), bluepill riscv32_generic hexagon))

$(1)_CODEGEN_SRCS := $(4)
$(1)_CODEGEN_HDRS := $(5)
Expand All @@ -168,6 +188,22 @@ $(call codegen_model,$(1)_codegen,$(2),$(3))
$(1)_CODEGEN_SRCS += $$($(1)_codegen_GENERATED_SRCS)
$(1)_CODEGEN_HDRS += $$($(1)_codegen_GENERATED_HDRS)

$(call microlite_test,$(1),$$($(1)_CODEGEN_SRCS),$$($(1)_CODEGEN_HDRS),,)
$(1)_CODEGEN_OBJS := $(MICROLITE_CODEGEN_RUNTIME_OBJS)
$(1)_CODEGEN_OBJS += $$(addprefix $$(CORE_OBJDIR), \
$$(patsubst %.S,%.o,$$(patsubst %.cc,%.o,$$(patsubst %.c,%.o,$$($(1)_CODEGEN_SRCS)))))

$(1)_BINARY := $$(BINDIR)$(1)
$$($(1)_BINARY): $$($(1)_CODEGEN_OBJS) $$(MICROLITE_LIB_PATH)
@mkdir -p $$(dir $$@)
$$(CXX) $$(CXXFLAGS) $$(INCLUDES) \
-o $$($(1)_BINARY) $$($(1)_CODEGEN_OBJS) \
$$(MICROLITE_LIB_PATH) $$(LDFLAGS) $$(MICROLITE_LIBS)

$(1): $$($(1)_BINARY)
$(1)_bin: $$($(1)_BINARY).bin

run_$(1): $$($(1)_BINARY)
$$(RUN_COMMAND) $$($(1)_BINARY)

endif
endef # codegen_model_binary

0 comments on commit cbb40c1

Please sign in to comment.