diff --git a/codegen/examples/hello_world/Makefile.inc b/codegen/examples/hello_world/Makefile.inc new file mode 100644 index 00000000000..56e2da712f6 --- /dev/null +++ b/codegen/examples/hello_world/Makefile.inc @@ -0,0 +1,10 @@ +CODEGEN_HELLO_WORLD_SRCS := \ +$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world.cc \ +$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world_model.cc + +CODEGEN_HELLO_WORLD_HDRS := \ +$(TENSORFLOW_ROOT)codegen/examples/hello_world/hello_world_model.h + +# Builds a standalone binary. +$(eval $(call microlite_test,codegen_hello_world,\ +$(CODEGEN_HELLO_WORLD_SRCS),,)) diff --git a/codegen/examples/hello_world/README.md b/codegen/examples/hello_world/README.md new file mode 100644 index 00000000000..82c9f764170 --- /dev/null +++ b/codegen/examples/hello_world/README.md @@ -0,0 +1,18 @@ +# Codegen Hello World Example + +This is a code-generated example of the hello world model. + +To generate the inference code at `codegen/example/hello_world_model.h/.cc`: + +``` +bazel run codegen:code_generator -- \ + --model $(pwd)/tensorflow/lite/micro/examples/hello_world/models/hello_world_int8.tflite \ + --output_dir $(pwd)/codegen/examples/hello_world \ + --output_name hello_world_model +``` + +To compile the generated source, you can use the Makefile: + +``` +make -f tensorflow/lite/micro/tools/make/Makefile codegen_hello_world +``` diff --git a/codegen/examples/hello_world/hello_world.cc b/codegen/examples/hello_world/hello_world.cc new file mode 100644 index 00000000000..e597c90fbd2 --- /dev/null +++ b/codegen/examples/hello_world/hello_world.cc @@ -0,0 +1,22 @@ +/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +#include "hello_world_model.h" + +int main(int argc, char** argv) { + hello_world_model::Invoke(); + + return 0; +} diff --git a/codegen/examples/hello_world/hello_world_model.cc b/codegen/examples/hello_world/hello_world_model.cc new file mode 100644 index 00000000000..50f37695748 --- /dev/null +++ b/codegen/examples/hello_world/hello_world_model.cc @@ -0,0 +1,24 @@ +/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +/* AUTOMATICALLY GENERATED DO NOT MODIFY */ + +#include "hello_world_model.h" + +namespace hello_world_model { + +void Invoke() {} + +} // namespace hello_world_model diff --git a/codegen/examples/hello_world/hello_world_model.h b/codegen/examples/hello_world/hello_world_model.h new file mode 100644 index 00000000000..241666e002e --- /dev/null +++ b/codegen/examples/hello_world/hello_world_model.h @@ -0,0 +1,24 @@ +/* Copyright 2023 The TensorFlow Authors. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +/* AUTOMATICALLY GENERATED DO NOT MODIFY */ + +#pragma once + +namespace hello_world_model { + +void Invoke(); + +} // namespace hello_world_model diff --git a/codegen/templates/inference.cc.mako b/codegen/templates/inference.cc.mako index 640feb8c178..dc4e1f7c091 100644 --- a/codegen/templates/inference.cc.mako +++ b/codegen/templates/inference.cc.mako @@ -21,4 +21,4 @@ namespace ${model_name} { void Invoke() {} -} // ${model_name} +} // namespace ${model_name} diff --git a/codegen/templates/inference.h.mako b/codegen/templates/inference.h.mako index 961cc0ad715..29f5584181f 100644 --- a/codegen/templates/inference.h.mako +++ b/codegen/templates/inference.h.mako @@ -21,4 +21,4 @@ namespace ${model_name} { void Invoke(); -} // ${model_name} +} // namespace ${model_name} diff --git a/tensorflow/lite/micro/tools/make/Makefile b/tensorflow/lite/micro/tools/make/Makefile index badd0caa100..76f17e92a52 100644 --- a/tensorflow/lite/micro/tools/make/Makefile +++ b/tensorflow/lite/micro/tools/make/Makefile @@ -287,6 +287,8 @@ MICRO_LITE_BENCHMARKS := $(wildcard $(TENSORFLOW_ROOT)tensorflow/lite/micro/tool MICROLITE_BENCHMARK_SRCS := \ $(wildcard $(TENSORFLOW_ROOT)tensorflow/lite/micro/tools/benchmarking/*benchmark.cc) +MICRO_LITE_CODEGEN_EXAMPLES := $(shell find $(TENSORFLOW_ROOT)codegen/examples/ -name Makefile.inc) + MICROLITE_TEST_SRCS := \ $(TENSORFLOW_ROOT)tensorflow/lite/micro/fake_micro_context_test.cc \ $(TENSORFLOW_ROOT)tensorflow/lite/micro/flatbuffer_utils_test.cc \ @@ -676,6 +678,9 @@ INCLUDES += -I$(GENERATED_SRCS_DIR)$(TENSORFLOW_ROOT) # Load the examples. include $(MICRO_LITE_EXAMPLE_TESTS) +# Load codegen examples. +include $(MICRO_LITE_CODEGEN_EXAMPLES) + # Load the integration tests. include $(MICRO_LITE_INTEGRATION_TESTS)