From 71de9ad4bd495df8532c6a9592228edf4b417bc5 Mon Sep 17 00:00:00 2001 From: lucylq Date: Tue, 5 Nov 2024 14:49:28 -0800 Subject: [PATCH 1/3] [executorch][serialization] Rename scalar_type.fbs --> common.fbs Allow us to add other shared flatbuffer types into `common.fbs`. - Rename scalar_type.fbs --> common.fbs - Rename scalar_type.py --> common_schema.py (differentiate from exir/common.py) Differential Revision: [D65442256](https://our.internmc.facebook.com/intern/diff/D65442256/) [ghstack-poisoned] --- .ci/scripts/build-qnn-sdk.sh | 2 +- .ci/scripts/test_llama.sh | 2 +- backends/qualcomm/scripts/build.sh | 2 +- devtools/CMakeLists.txt | 6 ++--- devtools/bundled_program/schema/TARGETS | 2 +- .../schema/bundled_program_schema.fbs | 2 +- .../schema/bundled_program_schema.py | 2 +- .../schema/{scalar_type.fbs => common.fbs} | 0 devtools/bundled_program/schema/targets.bzl | 22 ++++++++--------- .../schema/test/test_schema.py | 8 +++---- devtools/bundled_program/serialize/TARGETS | 2 +- .../bundled_program/serialize/__init__.py | 6 ++--- devtools/etdump/TARGETS | 4 ++-- .../etdump/{scalar_type.fbs => common.fbs} | 0 devtools/etdump/etdump_schema_flatcc.fbs | 2 +- devtools/etdump/schema_flatcc.py | 2 +- devtools/etdump/serialize.py | 6 ++--- devtools/etdump/targets.bzl | 24 +++++++++---------- ...d-run-qualcomm-ai-engine-direct-backend.md | 2 +- .../docs/delegates/qualcomm_README.md | 2 +- exir/TARGETS | 6 ++--- exir/_serialize/TARGETS | 2 +- exir/_serialize/_flatbuffer.py | 2 +- exir/_serialize/test/test_flatbuffer.py | 10 ++++---- exir/{scalar_type.py => common_schema.py} | 0 exir/schema.py | 2 +- extension/pybindings/test/TARGETS | 2 +- schema/CMakeLists.txt | 2 +- schema/README.md | 4 ++-- schema/{scalar_type.fbs => common.fbs} | 0 schema/program.fbs | 2 +- schema/targets.bzl | 16 ++++++------- setup.py | 8 ++++--- 33 files changed, 79 insertions(+), 75 deletions(-) rename devtools/bundled_program/schema/{scalar_type.fbs => common.fbs} (100%) rename devtools/etdump/{scalar_type.fbs => common.fbs} (100%) rename exir/{scalar_type.py => common_schema.py} (100%) rename schema/{scalar_type.fbs => common.fbs} (100%) diff --git a/.ci/scripts/build-qnn-sdk.sh b/.ci/scripts/build-qnn-sdk.sh index deeaed34ac3..21a4696f239 100644 --- a/.ci/scripts/build-qnn-sdk.sh +++ b/.ci/scripts/build-qnn-sdk.sh @@ -42,7 +42,7 @@ set_up_aot() { # Workaround for fbs files in exir/_serialize cp schema/program.fbs exir/_serialize/program.fbs - cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs + cp schema/common.fbs exir/_serialize/common.fbs } build_qnn_backend diff --git a/.ci/scripts/test_llama.sh b/.ci/scripts/test_llama.sh index ed2a9c2558b..35446c4c02a 100644 --- a/.ci/scripts/test_llama.sh +++ b/.ci/scripts/test_llama.sh @@ -79,7 +79,7 @@ if [[ "${MODE}" =~ .*qnn.* ]]; then export LD_LIBRARY_PATH="${QNN_SDK_ROOT}/lib/x86_64-linux-clang" export PYTHONPATH=".." cp schema/program.fbs exir/_serialize/program.fbs - cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs + cp schema/common.fbs exir/_serialize/common.fbs cp -f build-x86/backends/qualcomm/PyQnnManagerAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python cp -f build-x86/backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so backends/qualcomm/python diff --git a/backends/qualcomm/scripts/build.sh b/backends/qualcomm/scripts/build.sh index ed77a873516..08154238463 100755 --- a/backends/qualcomm/scripts/build.sh +++ b/backends/qualcomm/scripts/build.sh @@ -136,7 +136,7 @@ if [ "$BUILD_X86_64" = true ]; then rm -f $PRJ_ROOT/backends/qualcomm/python/* cp -fv $BUILD_ROOT/backends/qualcomm/Py* "$PRJ_ROOT/backends/qualcomm/python" cp -fv "$PRJ_ROOT/schema/program.fbs" "$PRJ_ROOT/exir/_serialize/program.fbs" - cp -fv "$PRJ_ROOT/schema/scalar_type.fbs" "$PRJ_ROOT/exir/_serialize/scalar_type.fbs" + cp -fv "$PRJ_ROOT/schema/common.fbs" "$PRJ_ROOT/exir/_serialize/common.fbs" EXAMPLE_ROOT=examples/qualcomm CMAKE_PREFIX_PATH="${BUILD_ROOT}/lib/cmake/ExecuTorch;${BUILD_ROOT}/third-party/gflags;" diff --git a/devtools/CMakeLists.txt b/devtools/CMakeLists.txt index 776d421a8d3..f2bfb7ac12d 100644 --- a/devtools/CMakeLists.txt +++ b/devtools/CMakeLists.txt @@ -37,10 +37,10 @@ if(NOT FLATC_EXECUTABLE) endif() # Paths to headers generated from the .fbs files. set(_etdump_schemas -# etdump_schema_flatcc.fbs scalar_type.fbs) +# etdump_schema_flatcc.fbs common.fbs) -set(_etdump_schema_names "etdump_schema_flatcc.fbs" "scalar_type.fbs") -set(_bundled_input_schema_names "bundled_program_schema.fbs" "scalar_type.fbs") +set(_etdump_schema_names "etdump_schema_flatcc.fbs" "common.fbs") +set(_bundled_input_schema_names "bundled_program_schema.fbs" "common.fbs") foreach(schema_file ${_etdump_schema_names}) list(APPEND _etdump_schema__srcs diff --git a/devtools/bundled_program/schema/TARGETS b/devtools/bundled_program/schema/TARGETS index 51c004cbec0..bd335cdcfb4 100644 --- a/devtools/bundled_program/schema/TARGETS +++ b/devtools/bundled_program/schema/TARGETS @@ -19,6 +19,6 @@ runtime.python_library( "//executorch/devtools/etrecord/...", ], deps = [ - "//executorch/exir:scalar_type", + "//executorch/exir:common_schema", ], ) diff --git a/devtools/bundled_program/schema/bundled_program_schema.fbs b/devtools/bundled_program/schema/bundled_program_schema.fbs index b37164a410d..b2e3f393553 100644 --- a/devtools/bundled_program/schema/bundled_program_schema.fbs +++ b/devtools/bundled_program/schema/bundled_program_schema.fbs @@ -4,7 +4,7 @@ // See README.md before modifying this file. // -include "scalar_type.fbs"; +include "common.fbs"; namespace bundled_program_flatbuffer; diff --git a/devtools/bundled_program/schema/bundled_program_schema.py b/devtools/bundled_program/schema/bundled_program_schema.py index 08b86c61d31..4445a661890 100644 --- a/devtools/bundled_program/schema/bundled_program_schema.py +++ b/devtools/bundled_program/schema/bundled_program_schema.py @@ -9,7 +9,7 @@ from dataclasses import dataclass from typing import List, Union -from executorch.exir.scalar_type import ScalarType +from executorch.exir.common_schema import ScalarType @dataclass diff --git a/devtools/bundled_program/schema/scalar_type.fbs b/devtools/bundled_program/schema/common.fbs similarity index 100% rename from devtools/bundled_program/schema/scalar_type.fbs rename to devtools/bundled_program/schema/common.fbs diff --git a/devtools/bundled_program/schema/targets.bzl b/devtools/bundled_program/schema/targets.bzl index 532a01e039e..783689e9504 100644 --- a/devtools/bundled_program/schema/targets.bzl +++ b/devtools/bundled_program/schema/targets.bzl @@ -1,17 +1,17 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -BUNLDED_STEM = "bundled_program_schema" -SCALAR_TYPE_STEM = "scalar_type" +BUNDLED_STEM = "bundled_program_schema" +COMMON_STEM = "common" -INPUT_BUNDLED = BUNLDED_STEM + ".fbs" -INPUT_SCALAR_TYPE = SCALAR_TYPE_STEM + ".fbs" +INPUT_BUNDLED = BUNDLED_STEM + ".fbs" +INPUT_COMMON = COMMON_STEM + ".fbs" -OUTPUT_BUNDLED_HEADER = BUNLDED_STEM + "_generated.h" -OUTPUT_SCALAR_TYPE_HEADER = SCALAR_TYPE_STEM + "_generated.h" +OUTPUT_BUNDLED_HEADER = BUNDLED_STEM + "_generated.h" +OUTPUT_COMMON_HEADER = COMMON_STEM + "_generated.h" BUNDLED_GEN_RULE_NAME = "generate_bundled_program" -BUNDLED_LIBRARY_NAME = BUNLDED_STEM + "_fbs" +BUNDLED_LIBRARY_NAME = BUNDLED_STEM + "_fbs" def _generate_schema_header(rule_name, srcs, headers, default_header): """Generate header file given flatbuffer schema @@ -54,7 +54,7 @@ def define_common_targets(): ) runtime.export_file( - name = INPUT_SCALAR_TYPE, + name = INPUT_COMMON, visibility = [ "//executorch/devtools/bundled_program/serialize/...", ], @@ -62,8 +62,8 @@ def define_common_targets(): _generate_schema_header( BUNDLED_GEN_RULE_NAME, - [INPUT_BUNDLED, INPUT_SCALAR_TYPE], - [OUTPUT_BUNDLED_HEADER, OUTPUT_SCALAR_TYPE_HEADER], + [INPUT_BUNDLED, INPUT_COMMON], + [OUTPUT_BUNDLED_HEADER, OUTPUT_COMMON_HEADER], OUTPUT_BUNDLED_HEADER, ) @@ -77,7 +77,7 @@ def define_common_targets(): ], exported_headers = { OUTPUT_BUNDLED_HEADER: ":{}[{}]".format(BUNDLED_GEN_RULE_NAME, OUTPUT_BUNDLED_HEADER), - OUTPUT_SCALAR_TYPE_HEADER: ":{}[{}]".format(BUNDLED_GEN_RULE_NAME, OUTPUT_SCALAR_TYPE_HEADER), + OUTPUT_COMMON_HEADER: ":{}[{}]".format(BUNDLED_GEN_RULE_NAME, OUTPUT_COMMON_HEADER), }, exported_external_deps = ["flatbuffers-api"], ) diff --git a/devtools/bundled_program/schema/test/test_schema.py b/devtools/bundled_program/schema/test/test_schema.py index c2a19adef79..6a2d2441037 100644 --- a/devtools/bundled_program/schema/test/test_schema.py +++ b/devtools/bundled_program/schema/test/test_schema.py @@ -15,13 +15,13 @@ class TestSchema(unittest.TestCase): def test_schema_sync(self) -> None: # make the test work in both internal and oss. prefix = ( - "executorch/" if os.path.exists("executorch/schema/scalar_type.fbs") else "" + "executorch/" if os.path.exists("executorch/schema/common.fbs") else "" ) self.assertTrue( filecmp.cmp( - prefix + "devtools/bundled_program/schema/scalar_type.fbs", - prefix + "schema/scalar_type.fbs", + prefix + "devtools/bundled_program/schema/common.fbs", + prefix + "schema/common.fbs", ), - 'Please run "hg cp fbcode//executorch/schema/scalar_type.fbs fbcode//executorch/devtools/bundled_program/schema/scalar_type.fbs" to sync schema changes.', + 'Please run "hg cp fbcode//executorch/schema/common.fbs fbcode//executorch/devtools/bundled_program/schema/common.fbs" to sync schema changes.', ) diff --git a/devtools/bundled_program/serialize/TARGETS b/devtools/bundled_program/serialize/TARGETS index 11c58399778..acf562826a9 100644 --- a/devtools/bundled_program/serialize/TARGETS +++ b/devtools/bundled_program/serialize/TARGETS @@ -11,7 +11,7 @@ runtime.python_library( ], resources = { "//executorch/devtools/bundled_program/schema:bundled_program_schema.fbs": "bundled_program_schema.fbs", - "//executorch/devtools/bundled_program/schema:scalar_type.fbs": "scalar_type.fbs", + "//executorch/devtools/bundled_program/schema:common.fbs": "common.fbs", }, # Currently serialization API should only be used in some dedicated targets, # to avoid ODR violation when linking with another Flatbuffers library. diff --git a/devtools/bundled_program/serialize/__init__.py b/devtools/bundled_program/serialize/__init__.py index 075436e9c11..2ebef6f11de 100644 --- a/devtools/bundled_program/serialize/__init__.py +++ b/devtools/bundled_program/serialize/__init__.py @@ -23,7 +23,7 @@ # The prefix of schema files used for bundled program BUNDLED_PROGRAM_SCHEMA_NAME = "bundled_program_schema" -SCALAR_TYPE_SCHEMA_NAME = "scalar_type" +COMMON_SCHEMA_NAME = "common" def write_schema(d: str, schema_name: str) -> None: @@ -51,7 +51,7 @@ def convert_to_flatbuffer(program_json: str) -> bytes: with tempfile.TemporaryDirectory() as d: # load given and common schema write_schema(d, BUNDLED_PROGRAM_SCHEMA_NAME) - write_schema(d, SCALAR_TYPE_SCHEMA_NAME) + write_schema(d, COMMON_SCHEMA_NAME) schema_path = os.path.join(d, "{}.fbs".format(BUNDLED_PROGRAM_SCHEMA_NAME)) json_path = os.path.join(d, "{}.json".format(BUNDLED_PROGRAM_SCHEMA_NAME)) @@ -66,7 +66,7 @@ def convert_to_flatbuffer(program_json: str) -> bytes: def convert_from_flatbuffer(program_flatbuffer: bytes) -> bytes: with tempfile.TemporaryDirectory() as d: write_schema(d, BUNDLED_PROGRAM_SCHEMA_NAME) - write_schema(d, SCALAR_TYPE_SCHEMA_NAME) + write_schema(d, COMMON_SCHEMA_NAME) schema_path = os.path.join(d, "{}.fbs".format(BUNDLED_PROGRAM_SCHEMA_NAME)) bin_path = os.path.join(d, "schema.bin") diff --git a/devtools/etdump/TARGETS b/devtools/etdump/TARGETS index 7dcc4c1e84b..4e7af8cb74a 100644 --- a/devtools/etdump/TARGETS +++ b/devtools/etdump/TARGETS @@ -14,7 +14,7 @@ runtime.python_library( "//executorch/devtools/...", ], deps = [ - "//executorch/exir:scalar_type", + "//executorch/exir:common_schema", ], ) @@ -25,7 +25,7 @@ runtime.python_library( ], resources = { "//executorch/devtools/etdump:etdump_schema_flatcc.fbs": "etdump_schema_flatcc.fbs", - "//executorch/schema:scalar_type.fbs": "scalar_type.fbs", + "//executorch/schema:common.fbs": "common.fbs", }, visibility = [ "//executorch/devtools/...", diff --git a/devtools/etdump/scalar_type.fbs b/devtools/etdump/common.fbs similarity index 100% rename from devtools/etdump/scalar_type.fbs rename to devtools/etdump/common.fbs diff --git a/devtools/etdump/etdump_schema_flatcc.fbs b/devtools/etdump/etdump_schema_flatcc.fbs index 1244ebd4aeb..79c56453613 100644 --- a/devtools/etdump/etdump_schema_flatcc.fbs +++ b/devtools/etdump/etdump_schema_flatcc.fbs @@ -1,4 +1,4 @@ -include "scalar_type.fbs"; +include "common.fbs"; namespace etdump; diff --git a/devtools/etdump/schema_flatcc.py b/devtools/etdump/schema_flatcc.py index 404fa1c9758..a39e63aa141 100644 --- a/devtools/etdump/schema_flatcc.py +++ b/devtools/etdump/schema_flatcc.py @@ -15,7 +15,7 @@ from enum import Enum from typing import List, Optional -from executorch.exir.scalar_type import ScalarType +from executorch.exir.common_schema import ScalarType @dataclass diff --git a/devtools/etdump/serialize.py b/devtools/etdump/serialize.py index 4ed63bc385b..d9695c665f2 100644 --- a/devtools/etdump/serialize.py +++ b/devtools/etdump/serialize.py @@ -19,7 +19,7 @@ # The prefix of schema files used for etdump ETDUMP_FLATCC_SCHEMA_NAME = "etdump_schema_flatcc" -SCALAR_TYPE_SCHEMA_NAME = "scalar_type" +COMMON_SCHEMA_NAME = "common" def _write_schema(d: str, schema_name: str) -> None: @@ -49,7 +49,7 @@ def _convert_to_flatcc(etdump_json: str) -> bytes: with tempfile.TemporaryDirectory() as d: # load given and common schema _write_schema(d, ETDUMP_FLATCC_SCHEMA_NAME) - _write_schema(d, SCALAR_TYPE_SCHEMA_NAME) + _write_schema(d, COMMON_SCHEMA_NAME) schema_path = os.path.join(d, "{}.fbs".format(ETDUMP_FLATCC_SCHEMA_NAME)) json_path = os.path.join(d, "{}.json".format(ETDUMP_FLATCC_SCHEMA_NAME)) @@ -65,7 +65,7 @@ def _convert_to_flatcc(etdump_json: str) -> bytes: def _convert_from_flatcc(etdump_flatbuffer: bytes, size_prefixed: bool = True) -> bytes: with tempfile.TemporaryDirectory() as d: _write_schema(d, ETDUMP_FLATCC_SCHEMA_NAME) - _write_schema(d, SCALAR_TYPE_SCHEMA_NAME) + _write_schema(d, COMMON_SCHEMA_NAME) schema_path = os.path.join(d, "{}.fbs".format(ETDUMP_FLATCC_SCHEMA_NAME)) bin_path = os.path.join(d, "schema.bin") diff --git a/devtools/etdump/targets.bzl b/devtools/etdump/targets.bzl index ddbb35eab74..0e8c7fd833d 100644 --- a/devtools/etdump/targets.bzl +++ b/devtools/etdump/targets.bzl @@ -1,7 +1,7 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -SCALAR_TYPE_STEM = "scalar_type" -SCALAR_TYPE = SCALAR_TYPE_STEM + ".fbs" +COMMON_STEM = "common" +COMMON = COMMON_STEM + ".fbs" # flatcc ETDUMP_STEM_FLATCC = "etdump_schema_flatcc" @@ -12,9 +12,9 @@ ETDUMP_SCHEMA_FLATCC_BUILDER = ETDUMP_STEM_FLATCC + "_builder.h" ETDUMP_SCHEMA_FLATCC_READER = ETDUMP_STEM_FLATCC + "_reader.h" ETDUMP_SCHEMA_FLATCC_VERIFIER = ETDUMP_STEM_FLATCC + "_verifier.h" -SCALAR_TYPE_BUILDER = SCALAR_TYPE_STEM + "_builder.h" -SCALAR_TYPE_READER = SCALAR_TYPE_STEM + "_reader.h" -SCALAR_TYPE_VERIFIER = SCALAR_TYPE_STEM + "_verifier.h" +COMMON_BUILDER = COMMON_STEM + "_builder.h" +COMMON_READER = COMMON_STEM + "_reader.h" +COMMON_VERIFIER = COMMON_STEM + "_verifier.h" FLATBUFFERS_COMMON_STEM = "flatbuffers_common" FLATBUFFERS_COMMON_BUILDER = FLATBUFFERS_COMMON_STEM + "_builder.h" @@ -52,14 +52,14 @@ def define_common_targets(): generate_schema_header_flatcc( ETDUMP_GEN_RULE_NAME_FLATCC, - [ETDUMP_SCHEMA_FLATCC, SCALAR_TYPE], + [ETDUMP_SCHEMA_FLATCC, COMMON], [ ETDUMP_SCHEMA_FLATCC_BUILDER, ETDUMP_SCHEMA_FLATCC_READER, ETDUMP_SCHEMA_FLATCC_VERIFIER, - SCALAR_TYPE_BUILDER, - SCALAR_TYPE_READER, - SCALAR_TYPE_VERIFIER, + COMMON_BUILDER, + COMMON_READER, + COMMON_VERIFIER, FLATBUFFERS_COMMON_BUILDER, FLATBUFFERS_COMMON_READER, ], @@ -78,9 +78,9 @@ def define_common_targets(): ETDUMP_SCHEMA_FLATCC_BUILDER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, ETDUMP_SCHEMA_FLATCC_BUILDER), ETDUMP_SCHEMA_FLATCC_READER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, ETDUMP_SCHEMA_FLATCC_READER), ETDUMP_SCHEMA_FLATCC_VERIFIER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, ETDUMP_SCHEMA_FLATCC_VERIFIER), - SCALAR_TYPE_BUILDER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, SCALAR_TYPE_BUILDER), - SCALAR_TYPE_READER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, SCALAR_TYPE_READER), - SCALAR_TYPE_VERIFIER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, SCALAR_TYPE_VERIFIER), + COMMON_BUILDER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, COMMON_BUILDER), + COMMON_READER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, COMMON_READER), + COMMON_VERIFIER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, COMMON_VERIFIER), FLATBUFFERS_COMMON_BUILDER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, FLATBUFFERS_COMMON_BUILDER), FLATBUFFERS_COMMON_READER: ":{}[{}]".format(ETDUMP_GEN_RULE_NAME_FLATCC, FLATBUFFERS_COMMON_READER), }, diff --git a/docs/source/build-run-qualcomm-ai-engine-direct-backend.md b/docs/source/build-run-qualcomm-ai-engine-direct-backend.md index 5e43a63c760..69ce21e4267 100644 --- a/docs/source/build-run-qualcomm-ai-engine-direct-backend.md +++ b/docs/source/build-run-qualcomm-ai-engine-direct-backend.md @@ -150,7 +150,7 @@ cp -f backends/qualcomm/PyQnnWrapperAdaptor.cpython-310-x86_64-linux-gnu.so $EXE # Workaround for fbs files in exir/_serialize cp $EXECUTORCH_ROOT/schema/program.fbs $EXECUTORCH_ROOT/exir/_serialize/program.fbs -cp $EXECUTORCH_ROOT/schema/scalar_type.fbs $EXECUTORCH_ROOT/exir/_serialize/scalar_type.fbs +cp $EXECUTORCH_ROOT/schema/common.fbs $EXECUTORCH_ROOT/exir/_serialize/common.fbs ``` ### Runtime: diff --git a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md index 8308da6d840..8d6b62dc404 100644 --- a/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md +++ b/examples/demo-apps/android/LlamaDemo/docs/delegates/qualcomm_README.md @@ -46,7 +46,7 @@ export EXECUTORCH_ROOT=$HOME/repos/executorch export LD_LIBRARY_PATH=$QNN_SDK_ROOT/lib/x86_64-linux-clang/:$LD_LIBRARY_PATH export PYTHONPATH=$EXECUTORCH_ROOT/.. cp schema/program.fbs exir/_serialize/program.fbs -cp schema/scalar_type.fbs exir/_serialize/scalar_type.fbs +cp schema/common.fbs exir/_serialize/common.fbs ``` ### Build QNN backend with ExecuTorch diff --git a/exir/TARGETS b/exir/TARGETS index 8539311e27d..9d7d14c48f9 100644 --- a/exir/TARGETS +++ b/exir/TARGETS @@ -41,9 +41,9 @@ python_library( ) python_library( - name = "scalar_type", + name = "common_schema", srcs = [ - "scalar_type.py", + "common_schema.py", ], ) @@ -53,7 +53,7 @@ python_library( "schema.py", ], deps = [ - ":scalar_type", + ":common_schema", "//executorch/exir/backend:compile_spec_schema", ], ) diff --git a/exir/_serialize/TARGETS b/exir/_serialize/TARGETS index 49419a4159c..00df33fc8c2 100644 --- a/exir/_serialize/TARGETS +++ b/exir/_serialize/TARGETS @@ -36,7 +36,7 @@ runtime.python_library( ], resources = { "//executorch/schema:program.fbs": "program.fbs", - "//executorch/schema:scalar_type.fbs": "scalar_type.fbs", + "//executorch/schema:common.fbs": "common.fbs", "fbsource//third-party/flatbuffers:flatc-host": "flatbuffers-flatc", }, # Currently serialization API should only be used in some dedicated targets, diff --git a/exir/_serialize/_flatbuffer.py b/exir/_serialize/_flatbuffer.py index 4599249f00c..854b72dd848 100644 --- a/exir/_serialize/_flatbuffer.py +++ b/exir/_serialize/_flatbuffer.py @@ -143,7 +143,7 @@ def _prepare_schema( """ program_schema = "program.fbs" # Included by the root program schema; must also be present. - deps = ["scalar_type.fbs"] + deps = ["common.fbs"] schemas = _ResourceFiles([program_schema] + deps) diff --git a/exir/_serialize/test/test_flatbuffer.py b/exir/_serialize/test/test_flatbuffer.py index 9b843938c7b..7a7c46bc3a6 100644 --- a/exir/_serialize/test/test_flatbuffer.py +++ b/exir/_serialize/test/test_flatbuffer.py @@ -5,6 +5,8 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# pyre-unsafe + import os import re import shutil @@ -85,7 +87,7 @@ def test_load_patch_and_write(self) -> None: b"}", ] ), - "scalar_type.fbs": b"\n".join( + "common.fbs": b"\n".join( [ b"table ScalarType {", # Spaces around the colon. @@ -156,7 +158,7 @@ def test_update_tensor_alignment(self) -> None: ), ) self.assertEqual( - read_file(out_dir, "scalar_type.fbs"), + read_file(out_dir, "common.fbs"), b"\n".join( [ b"table ScalarType {", @@ -192,7 +194,7 @@ def test_update_delegate_alignment(self) -> None: ), ) self.assertEqual( - read_file(out_dir, "scalar_type.fbs"), + read_file(out_dir, "common.fbs"), b"\n".join( [ b"table ScalarType {", @@ -232,7 +234,7 @@ def test_update_tensor_and_delegate_alignment(self) -> None: ), ) self.assertEqual( - read_file(out_dir, "scalar_type.fbs"), + read_file(out_dir, "common.fbs"), b"\n".join( [ b"table ScalarType {", diff --git a/exir/scalar_type.py b/exir/common_schema.py similarity index 100% rename from exir/scalar_type.py rename to exir/common_schema.py diff --git a/exir/schema.py b/exir/schema.py index 9ef294abb6c..c52240445fe 100644 --- a/exir/schema.py +++ b/exir/schema.py @@ -12,7 +12,7 @@ from executorch.exir.backend.compile_spec_schema import CompileSpec -from executorch.exir.scalar_type import ScalarType +from executorch.exir.common_schema import ScalarType @dataclass diff --git a/extension/pybindings/test/TARGETS b/extension/pybindings/test/TARGETS index 73063deb651..ed793d1c530 100644 --- a/extension/pybindings/test/TARGETS +++ b/extension/pybindings/test/TARGETS @@ -19,7 +19,7 @@ runtime.python_library( "//caffe2:torch_fx", "//executorch/exir:lib", "//executorch/exir:pass_manager", - "//executorch/exir:scalar_type", + "//executorch/exir:common_schema", "//executorch/exir/_serialize:lib", "//executorch/exir/emit:lib", "//executorch/exir/passes:lib", diff --git a/schema/CMakeLists.txt b/schema/CMakeLists.txt index 5a4013f43e0..1d30bcc7671 100644 --- a/schema/CMakeLists.txt +++ b/schema/CMakeLists.txt @@ -60,7 +60,7 @@ function(generate_program_schema _schema_srcs _schema_name) endfunction() # Generate common schema -set(common_schema_srcs scalar_type.fbs) +set(common_schema_srcs common.fbs) generate_program_schema("${common_schema_srcs}" "common_schema") # For the other schemas diff --git a/schema/README.md b/schema/README.md index 5bc74eb2c87..c01665a1096 100644 --- a/schema/README.md +++ b/schema/README.md @@ -2,8 +2,8 @@ The `schema.fbs` file in this directory describes the [Flatbuffers](https://google.github.io/flatbuffers/) schema used to serialize ExecuTorch programs. -The `scalar_type.fbs` file contains schema for scalar types, used in both -`schema.fbs` and `bundled_program_schema.fbs`. +The `common.fbs` file contains schema for scalar types and other shared types, +used in both `schema.fbs` and `bundled_program_schema.fbs`. ## Rules to ensure forward/backward compatibility diff --git a/schema/scalar_type.fbs b/schema/common.fbs similarity index 100% rename from schema/scalar_type.fbs rename to schema/common.fbs diff --git a/schema/program.fbs b/schema/program.fbs index e3c7597fcdc..7e552de23e8 100644 --- a/schema/program.fbs +++ b/schema/program.fbs @@ -4,7 +4,7 @@ // See README.md before modifying this file. // -include "scalar_type.fbs"; +include "common.fbs"; namespace executorch_flatbuffer; diff --git a/schema/targets.bzl b/schema/targets.bzl index 40c6d8d5c8d..983a4063724 100644 --- a/schema/targets.bzl +++ b/schema/targets.bzl @@ -1,14 +1,14 @@ load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") -# Construct the input and output file names. All input and output files rely on scalar_type file. +# Construct the input and output file names. All input and output files rely on common file. PROGRAM_STEM = "program" -SCALAR_TYPE_STEM = "scalar_type" +COMMON_STEM = "common" INPUT_PROGRAM = PROGRAM_STEM + ".fbs" -INPUT_SCALAR_TYPE = SCALAR_TYPE_STEM + ".fbs" +INPUT_COMMON = COMMON_STEM + ".fbs" OUTPUT_PROGRAM_HEADER = PROGRAM_STEM + "_generated.h" -OUTPUT_SCALAR_TYPE_HEADER = SCALAR_TYPE_STEM + "_generated.h" +OUTPUT_COMMON_HEADER = COMMON_STEM + "_generated.h" PROGRAM_GEN_RULE_NAME = "generate_program" @@ -54,7 +54,7 @@ def define_common_targets(): ], ) runtime.export_file( - name = INPUT_SCALAR_TYPE, + name = INPUT_COMMON, visibility = [ "//executorch/exir/_serialize/...", "//executorch/devtools/etdump/...", @@ -63,8 +63,8 @@ def define_common_targets(): _generate_schema_header( PROGRAM_GEN_RULE_NAME, - [INPUT_PROGRAM, INPUT_SCALAR_TYPE], - [OUTPUT_PROGRAM_HEADER, OUTPUT_SCALAR_TYPE_HEADER], + [INPUT_PROGRAM, INPUT_COMMON], + [OUTPUT_PROGRAM_HEADER, OUTPUT_COMMON_HEADER], OUTPUT_PROGRAM_HEADER, ) @@ -81,7 +81,7 @@ def define_common_targets(): ], exported_headers = { OUTPUT_PROGRAM_HEADER: ":{}[{}]".format(PROGRAM_GEN_RULE_NAME, OUTPUT_PROGRAM_HEADER), - OUTPUT_SCALAR_TYPE_HEADER: ":{}[{}]".format(PROGRAM_GEN_RULE_NAME, OUTPUT_SCALAR_TYPE_HEADER), + OUTPUT_COMMON_HEADER: ":{}[{}]".format(PROGRAM_GEN_RULE_NAME, OUTPUT_COMMON_HEADER), }, exported_external_deps = ["flatbuffers-api"], ) diff --git a/setup.py b/setup.py index ff1afa89bd6..fce0938b296 100644 --- a/setup.py +++ b/setup.py @@ -46,6 +46,8 @@ # other computer software, distribute, and sublicense such enhancements or # derivative works thereof, in binary and source code form. +# pyre-unsafe + import contextlib import os import platform @@ -413,15 +415,15 @@ def run(self): # TODO(dbort): See if we can add a custom pyproject.toml section for # these, instead of hard-coding them here. See # https://setuptools.pypa.io/en/latest/userguide/extension.html - ("schema/scalar_type.fbs", "exir/_serialize/scalar_type.fbs"), + ("schema/common.fbs", "exir/_serialize/common.fbs"), ("schema/program.fbs", "exir/_serialize/program.fbs"), ( "devtools/bundled_program/schema/bundled_program_schema.fbs", "devtools/bundled_program/serialize/bundled_program_schema.fbs", ), ( - "devtools/bundled_program/schema/scalar_type.fbs", - "devtools/bundled_program/serialize/scalar_type.fbs", + "devtools/bundled_program/schema/common.fbs", + "devtools/bundled_program/serialize/common.fbs", ), # Install executorch-wheel-config.cmake to pip package. ( From 8ba5b36c578f64251e0086de2c68c8517164f4a9 Mon Sep 17 00:00:00 2001 From: lucylq Date: Tue, 5 Nov 2024 15:08:36 -0800 Subject: [PATCH 2/3] Update on "[executorch][serialization] Rename scalar_type.fbs --> common.fbs" Allow us to add other shared flatbuffer types into `common.fbs`. - Rename scalar_type.fbs --> common.fbs - Rename scalar_type.py --> common_schema.py (differentiate from exir/common.py) Differential Revision: [D65442256](https://our.internmc.facebook.com/intern/diff/D65442256/) [ghstack-poisoned] --- devtools/bundled_program/schema/test/test_schema.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/devtools/bundled_program/schema/test/test_schema.py b/devtools/bundled_program/schema/test/test_schema.py index 6a2d2441037..cc169efaf66 100644 --- a/devtools/bundled_program/schema/test/test_schema.py +++ b/devtools/bundled_program/schema/test/test_schema.py @@ -14,9 +14,7 @@ class TestSchema(unittest.TestCase): def test_schema_sync(self) -> None: # make the test work in both internal and oss. - prefix = ( - "executorch/" if os.path.exists("executorch/schema/common.fbs") else "" - ) + prefix = ("executorch/" if os.path.exists("executorch/schema/common.fbs") else "") self.assertTrue( filecmp.cmp( From c4a9a3b46c4fe41ae41aba9261d38c37b905f9cc Mon Sep 17 00:00:00 2001 From: lucylq Date: Tue, 5 Nov 2024 15:36:32 -0800 Subject: [PATCH 3/3] Update on "[executorch][serialization] Rename scalar_type.fbs --> common.fbs" Allow us to add other shared flatbuffer types into `common.fbs`. - Rename scalar_type.fbs --> common.fbs - Rename scalar_type.py --> common_schema.py (differentiate from exir/common.py) Differential Revision: [D65442256](https://our.internmc.facebook.com/intern/diff/D65442256/) [ghstack-poisoned] --- devtools/bundled_program/schema/test/test_schema.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devtools/bundled_program/schema/test/test_schema.py b/devtools/bundled_program/schema/test/test_schema.py index cc169efaf66..af79561a92f 100644 --- a/devtools/bundled_program/schema/test/test_schema.py +++ b/devtools/bundled_program/schema/test/test_schema.py @@ -14,7 +14,7 @@ class TestSchema(unittest.TestCase): def test_schema_sync(self) -> None: # make the test work in both internal and oss. - prefix = ("executorch/" if os.path.exists("executorch/schema/common.fbs") else "") + prefix = "executorch/" if os.path.exists("executorch/schema/common.fbs") else "" self.assertTrue( filecmp.cmp(