diff --git a/extension/flat_tensor/serialize/TARGETS b/extension/flat_tensor/serialize/TARGETS new file mode 100644 index 0000000000..c3acdca054 --- /dev/null +++ b/extension/flat_tensor/serialize/TARGETS @@ -0,0 +1,16 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") +load(":targets.bzl", "define_common_targets") + +oncall("executorch") + +define_common_targets() + +runtime.python_library( + name = "schema", + srcs = [ + "flat_tensor_schema.py", + ], + visibility = [ + "//executorch/...", + ], +) diff --git a/extension/flat_tensor/flat_tensor.fbs b/extension/flat_tensor/serialize/flat_tensor.fbs similarity index 99% rename from extension/flat_tensor/flat_tensor.fbs rename to extension/flat_tensor/serialize/flat_tensor.fbs index 33ab16fab8..71938fb15c 100644 --- a/extension/flat_tensor/flat_tensor.fbs +++ b/extension/flat_tensor/serialize/flat_tensor.fbs @@ -13,7 +13,7 @@ table TensorMetadata { scalar_type: executorch_flatbuffer.ScalarType; // Size of each dimension. - dim_sizes: [int32]; + sizes: [int32]; // Specifies in what order the dimensions are laid out in memory (from outer // to inner). diff --git a/extension/flat_tensor/flat_tensor_schema.py b/extension/flat_tensor/serialize/flat_tensor_schema.py similarity index 96% rename from extension/flat_tensor/flat_tensor_schema.py rename to extension/flat_tensor/serialize/flat_tensor_schema.py index 95a3150597..091ce1178b 100644 --- a/extension/flat_tensor/flat_tensor_schema.py +++ b/extension/flat_tensor/serialize/flat_tensor_schema.py @@ -17,7 +17,7 @@ class TensorMetadata: fully_qualified_name: str scalar_type: ScalarType - dim_sizes: List[int] + sizes: List[int] dim_order: List[bytes] segment_index: int diff --git a/extension/flat_tensor/scalar_type.fbs b/extension/flat_tensor/serialize/scalar_type.fbs similarity index 100% rename from extension/flat_tensor/scalar_type.fbs rename to extension/flat_tensor/serialize/scalar_type.fbs diff --git a/extension/flat_tensor/serialize/targets.bzl b/extension/flat_tensor/serialize/targets.bzl new file mode 100644 index 0000000000..be0460147a --- /dev/null +++ b/extension/flat_tensor/serialize/targets.bzl @@ -0,0 +1,36 @@ +load("@fbsource//xplat/executorch/build:runtime_wrapper.bzl", "runtime") + +def define_common_targets(): + runtime.genrule( + name = "gen_schema", + srcs = [ + "flat_tensor.fbs", + "scalar_type.fbs", + ], + outs = { + "schema_generated.h": ["flat_tensor_generated.h"], + "scalar_type_generated.h": ["scalar_type_generated.h"] + }, + cmd = " ".join([ + "$(exe {})".format(runtime.external_dep_location("flatc")), + "--cpp", + "--cpp-std c++11", + "--scoped-enums", + "-o ${OUT}", + "${SRCS}", + ]), + default_outs = ["."], + ) + + runtime.cxx_library( + name = "generated_headers", + srcs = [], + visibility = [ + "//executorch/...", + ], + exported_headers = { + "schema_generated.h": ":gen_schema[schema_generated.h]", + "scalar_type_generated.h": ":gen_schema[scalar_type_generated.h]", + }, + exported_external_deps = ["flatbuffers-api"], + )