Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement MicroContext/Graph for codegen #2218

Merged
merged 3 commits into from
Sep 12, 2023

Conversation

rascani
Copy link
Contributor

@rascani rascani commented Sep 12, 2023

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

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
The various MicroContext/Graph methods pass various indexes for
subgraphs, tensors, inputs and outputs. This commit adds bounds checking
on all of these indexes to ensure that they are within the range for
their corresponding arrays.
@rascani rascani requested a review from a team as a code owner September 12, 2023 17:36
@rascani rascani added the ci:run label Sep 12, 2023
@TFLM-bot TFLM-bot removed the ci:run label Sep 12, 2023
@rascani rascani requested a review from suleshahid September 12, 2023 19:46
@rascani rascani added the ci:run label Sep 12, 2023
@TFLM-bot TFLM-bot removed the ci:run label Sep 12, 2023
Copy link
Collaborator

@suleshahid suleshahid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mergify mergify bot merged commit 3323a41 into tensorflow:main Sep 12, 2023
68 of 69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants