Skip to content

Stop sharing C/C++ code with LiteRT (except schema.fbs) #3777

Description

@veblush

TFLM currently shares several headers and source files with LiteRT (tensorflow/lite/... and tensorflow/compiler/mlir/lite/...), relying on #ifdef TF_LITE_STATIC_MEMORY to strip mobile & desktop-only code and struct fields. This causes ODR/header collisions when linking both runtimes in the same binary and forces both projects to maintain TF_LITE_STATIC_MEMORY.

We are decoupling TFLM into a completely standalone codebase under tensorflow/lite/micro/ that shares only schema.fbs (tensorflow/lite/schema/schema.fbs) with LiteRT:

  • Step 1 (Mostly standalone TFLM #3671): Move tensorflow/lite/kernels/internal/** and C++ kernel helpers (RuntimeShape, reference_ops, quantization_util, kernel_util) into tensorflow/lite/micro/ under namespace tflite::micro (with namespace tflite compatibility aliases).
  • Step 2 (Decouple C API from LiteRT #3788): Move C API headers and sources (common.h, common.cc, c_api_types.h, builtin_op_data.h) into tensorflow/lite/micro/c/ while temporarily keeping TF_LITE_STATIC_MEMORY and forwarding headers in tensorflow/lite/{core/,}c/ for downstream migration.
  • Step 3 (Remove tensorflow/compiler/ and tensorflow/lite/{c,core,kernels}):
    • Move schema.fbs to tensorflow/lite/schema/schema.fbs and schema_utils.{h,cc} into tensorflow/lite/micro/.
    • Move flatbuffer_conversions.{h,cc} into tensorflow/lite/micro/tflite_bridge/ under namespace tflite::micro and replace TF_LITE_REPORT_ERROR with MicroPrintf.
    • Merge macros.h into tensorflow/lite/micro/kernels/internal/compatibility_macros.h.
    • Delete unused LiteRT files (error_reporter.{h,cc}, micro_error_reporter.{h,cc}, tensor_utils.{h,cc}, context_util.h, tensorflow/lite/array.{h,cc}), forwarding headers (tensorflow/lite/{core/,}c/, tensorflow/lite/kernels/), tensorflow/compiler/, and ci/sync_from_upstream_tf.sh.
  • Step 4 (Remove heap-allocating array.{h,cc} helpers):
    • Replace test-only IntArrayUniquePtr usage in micro_allocator_test.cc with IntArrayFromInts, delete tensorflow/lite/micro/array.{h,cc}, and remove TfLiteIntArrayCreate/Free and TfLiteFloatArrayCreate/Free from tensorflow/lite/micro/c/common.{h,cc}.
  • Step 5 (Namespace tensorflow/lite/micro/c/ & remove TF_LITE_STATIC_MEMORY):
    • Give tensorflow/lite/micro/c/*.h dedicated TENSORFLOW_LITE_MICRO_C_*_H_ header guards and move C API types/functions into namespace tflite::micro (with global-namespace aliases when LiteRT's common.h is not included).
    • Remove #ifndef TF_LITE_STATIC_MEMORY blocks, -DTF_LITE_STATIC_MEMORY build flags, and test_x86_no_tflite_static_memory.sh.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions