-
Notifications
You must be signed in to change notification settings - Fork 833
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add hello world codegen example (#2163)
This PR adds a codegen inference example for the hello world model to demonstrate how to invoke the code generator and build the generated source. For now, we're just checking the generated source into the repo to skip over building out the make rules and also ensuring the generated source complies with formatting rules. This also fixes a minor formatting issue in the source templates, as clang-format now properly complained about it. BUG=b/295390000
- Loading branch information
Showing
8 changed files
with
105 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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),,)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ namespace ${model_name} { | |
|
||
void Invoke() {} | ||
|
||
} // ${model_name} | ||
} // namespace ${model_name} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,4 @@ namespace ${model_name} { | |
|
||
void Invoke(); | ||
|
||
} // ${model_name} | ||
} // namespace ${model_name} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters