Commit graph

27 commits

Author SHA1 Message Date
Esun Kim
858f5a3edd
[CI] Removed six, updated absl_py (#3203)
* Removed ci/install_qemu.sh

* Removed six from direct deps

* Removed six from tflm-ci docker

* Use requirement(absl_py)

* New qemu-user
2025-09-25 14:37:39 -07:00
Esun Kim
ba753cef3e
[CI] Fix build (#3194)
- Upgraded the Bazel BuildTool to the latest version (8.2.1).
- Updated the `tflm-ci` Docker image and pushed the new tag (0.6.1) to the `ghcr.io/tflm-bot/tflm-ci registry`.
- Updated the WORKSPACE to load `rules_cc` and `rules_shell` explicitly
- Ran `buildifier` to ensure all BUILD files to have all the fixes.

BUG=Clean-up
2025-09-19 20:48:22 +00:00
suleshahid
bc68d362d6
Remove deprecated BUILD tags (#3091)
These tags have been deprecated and are unused now. Syncing with upstream and removing them from the BUILD files.

BUG=remove deprecated tags
2025-04-08 19:21:25 +00:00
Ryan Kuester
d660678390
build(bazel): disable codegen when building --//:with_compression (#2982)
The codegen prototype code is not compatible with the changes which
implement model compression made to the core TFLM components. For now,
disable codegen targets when building with compression enabled.

BUG=#2636
2024-12-04 18:44:33 +00:00
Ryan Kuester
11b15b3a81
build(bazel): introduce tflm_cc_* macros, refactoring away micro_copts (#2765)
Remove micro_copts() by replacing every cc_* target that used
them with a tflm_cc_* equivalent, and setting those common copts
in one place, inside the tflm_cc_* macro.

This is the first of several commits introducing tflm_cc_* macros
in place of cc_binary, cc_library, and cc_test. Motivated by the
upcoming need to support conditional compilation, the objective
is to centralize build configuration rather than requiring (and
remembering that) each cc_* target in the project add the same
common attributes such as compiler options and select()ed

Alternatives such as setting global options on the command line
or in .bazelrc, even if simplified with a --config option, fail
to preserve flags and hooks for configuration in the case TFLM is
used as an external repository by an application project. Nor is
it easy in that case for individual targets to override an
otherwise global setting.

BUG=#2636
2024-11-14 23:16:28 +00:00
Ryan Kuester
f91dd916e5
build(codegen): suppress noise in console output (#2742)
build(codegen): suppress noise in console output

Redirect output from the code_generator binary so that when it's
used within the build system, it doesn't print unexpected,
distracting noise to the console. Generally, compiler or
generator commands don't print output unless there's an error.

This reverts "build(codegen): suppress noise in console output
(#2708)", commit d2495773, which attempted to fix the same
problem by adding a --quiet flag. A subsequent upgrade to the
Tensorflow Python package caused new noise that wasn't possible
to suppress with the flag.

BUG=description
2024-11-13 22:46:20 +00:00
Ryan Kuester
d24957732b
build(codegen): suppress noise in console output (#2708)
Add a --quiet option to the code_generator binary so that when it's used
within the build system, it doesn't print unexpected, distracting noise
to the console. Generally, compiler or generator commands don't print
output unless there's an error.

BUG=description
2024-10-01 21:16:45 +00:00
Ryan Kuester
d619ad8ec5
refactor: move tflite::Span to independent header (#2638)
Hoist the universally-useful tflite::Span out of
codegen/runtime/micro_codegen_context.h and into an independent header
usable from elsewhere in the project.

BUG=#2636
2024-07-24 20:20:44 +00:00
RJ Ascani
06499e832f
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
2024-01-09 19:54:12 +00:00
suleshahid
833f7bb84c
Add dep for codegen build (#2385)
BUG=[318738218](https://b.corp.google.com/issues/318738218)
2024-01-09 01:04:19 +00:00
RJ Ascani
b766947f5a
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
2023-12-21 00:57:49 +00:00
RJ Ascani
c5c3b3e182
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
2023-12-19 21:14:31 +00: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