Commit Graph

19 Commits

Author SHA1 Message Date
RJ Ascani b074c64fc0 codegen: Remove make helpers for codegen (#2378)
This partially reverts commit 1e9b4c5d84. The make helpers for running the inference code generator were somewhat of a hack due to the desire to integrate a target-specific preprocessor binary as part of the process. Since that is no longer necessary, we can now switch over to just using Bazel for running the code generator.

BUG=b/294230402
2026-04-20 14:47:58 +08:00
suleshahid b3c32f1172 Add dep for codegen build (#2385)
BUG=[318738218](https://b.corp.google.com/issues/318738218)
2026-04-20 14:47:58 +08:00
RJ Ascani 1335dbc27c codegen: Add Bazel macro for inference library (#2366)
The TFLM code_generator takes a TFLite model and generates C/C++ source code that can then be compiled into a binary. This change adds a Bazel macro for invoking the code generator and creating a cc_library with the resulting sources. It also updates the checked-in hello_world example with an appropriate BUILD file and updates the script to use Bazel instead of make.

BUG=b/294230402
2026-04-20 14:47:57 +08:00
RJ Ascani 85d9b04659 codegen: Remove preprocessor (#2355)
The original idea for the codegen preprocessor was to perform init & prepare stages using a simulator and capture the output. This idea is being abandoned in favor of generating the necessary structures from python.

BUG=cleanup
2026-04-20 14:47:56 +08:00
Ryan Kuester 6bb1e3a635
build: update flatbuffers dependency to v23.5.26 (#2274)
Update the third_party flatbuffers library to v23.5.26, the
current version in upstream TF. Synchronize the override BUILD
and build_defs.bzl files with those from upstream TF at
e4485c98eae.

Also update the Makefile build, which downloads flatbuffers
separately. Rebase the patch applied to the download.

Regenerate the generated-and-checked-in schemas (see
ci/sync_from_upstream_tf.sh and codegen/preprocessor/
update_schema.sh), because they are stamped with the version of
the flatbuffers library, and fail a static_assert if they are
built with a different version of flatbuffers than they were
generated with.

BUG=unsuccessful attempt to fix warning in #2183
2023-10-18 21:01:22 +00:00
RJ Ascani 1e9b4c5d84
Create Make helpers for running codegen (#2222)
The codegen process is a multi-step process that requires compiling,
executing code under simulation, and executing python scripts. To
simplify this workflow, this commit adds Make helper functions for
generating inference source code from a model and creating a binary with
it.

It also updates the hello world example to use these helpers and adds an
update script for keeping the checked in generated source in sync.

BUG=cleanup
2023-09-21 18:17:50 +00:00
TFLM-bot ad8d238f9f
Automated sync from github.com/tensorflow/tensorflow (#2221)
BUG=automated sync from upstream
NO_CHECK_TFLITE_FILES=automated sync from upstream
2023-09-14 23:18:01 +00:00
RJ Ascani 77e2cdbdd6
Create codegen_preprocessor (#2219) 2023-09-14 13:08:49 -07:00
RJ Ascani 3323a41d69
Implement MicroContext/Graph for codegen (#2218)
The TFLM kernels use the MicroContext and MicroGraph interfaces to fetch
eval tensors and access other parts of the graph. Since codegen does not
have the MicroInterpreter and related objects to serve those, this PR
introduces a new MicroCodegenContext class that serves as both the
MicroContext and MicroGraph.

The MicroCodegenContext is configured with a span of Subgraphs, each of
which includes the inputs, outputs, nodes, tensors and an invocation
function. The code generator will create the data and functions needed
for each Subgraph and initialize the MicroCodegenContext with it. By
having the re-usable MicroCodegenContext, the code generator won't have
to generate nearly as much code.

BUG=b/295174086
2023-09-12 22:28:30 +00:00
RJ Ascani 4813acf547
Define preprocessor schema (#2211)
The purpose of the preprocessor is to load a model with the TFLM interpreter, allocate tensors, and then capture the resulting data structures. To capture this data, we need to provide structure and serialization to it for ingesting into the code generator. This commit defines a preprocessor data schema with generated C++ and python bindings for it. Unfortunately, we need to check-in the generated code, as the Makefiles are currently not capable of running the flatc compiler. An update script is included to help keep these files in sync.

BUG=b/295076067
2023-09-07 22:27:53 +00:00
RJ Ascani b45012b52c
Fix RISC-V codegen example (#2199)
The RISC-V toolchain we're using failed to properly discern the TfLiteEvalTensor type for use with an assignment operator. It produced compiler errors for "no match for 'operator=' with operand types TfLiteEvalTensor and a brace-closed initializer list. This PR resolves this issue by explicitly using the TfLiteEvalTensor constructor for the initializer list. We also apply this approach to the TfLiteNode initialization as well, just for consistency.

BUG=#2195
2023-08-29 18:22:08 +00:00
RJ Ascani 4d07bd0f44
Generate static TfLiteEvalTensors (#2193)
This PR generates all of the TfLiteEvalTensors for the graph. It also generates all of the static buffers used for tensors that were present in the flatbuffer.

BUG=b/295077140
2023-08-29 03:44:17 +00:00
Advait Jain 1e7c710ca9
remove unused symbol from BUILD file. (#2190)
Warning shown by internal tools in http://cl/560228301.

BUG=cleanup
2023-08-28 04:07:34 +00:00
RJ Ascani f8ab03d6b7
Generate BuiltinData for FullyConnected (#2184)
Each operator has its own set of BuiltinOptions, which will translate into an op-specific TfLite Params structure. This change turns Operator into a base class with common functionality, and adds a FullyConnected subclass that knows how to generate the TfLiteFullyConnectedParams struct.

BUG=b/295175961
2023-08-24 18:32:39 +00:00
RJ Ascani 34691a66f2
codegen: Add TFLiteContext and TfLiteNodes (#2179)
This PR adds the generation of empty TfLiteContext and TfLiteNode structures, and generates appropriate invocation methods for each subgraph. It also generates the input, output, and intermediate arrays for each TfLiteNode.

BUG=b/295175961
2023-08-23 23:46:03 +00:00
RJ Ascani a0f8970856
Generate op table and subgraph invoke functions (#2176)
As the next step in the codegen experiment, we want to generate the invoke calls for each layer. This is slightly challenging with the existing sources, as kernels only expose a registration function, not their individual Eval functions. In an effort to keep the code churn to a minimum, this PR introduces an inference only registration structure and function. It includes just two function pointers: invoke and reset. For this CL, we've only introduced it for FullyConnected.

In the code generator, this PR creates a new op_table array in the generated source, with an enum for lookup. It also generates an invoke function for each subgraph, that calls each operator's invoke function.

BUG=295174388
2023-08-18 20:38:16 +00:00
RJ Ascani e3d1a5a3b1
Add py load statement for codegen (#2166)
The new codegen python build rules were added without properly loading the rules.

BUG=b/295216390
2023-08-14 19:18:02 +00:00
RJ Ascani feb26698cf
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
2023-08-11 00:16:50 +00:00
RJ Ascani 901d8306e5
Add code generator experiment (#2162)
This PR creates the initial code generator scaffolding for performing inference without an interpreter. Currently, this does nothing other create a header and source file from Mako templates. Mako was chosen as a template engine due to existing dependency.

BUG=b/295076487
2023-08-10 18:48:59 +00:00