[executorch][native] Add TensorMeta + ScalarType in-memory IR types - #22275
[executorch][native] Add TensorMeta + ScalarType in-memory IR types#22275SS-JIA wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22275
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 978a757 with merge base 16d3b9f ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
digantdesai
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Stack from ghstack (oldest at bottom):
First concrete in-memory IR value types for the native runtime, under
backends/native/runtime/graph/:ScalarType(ScalarType.h) — a standalone, header-only scalar element-typeenum driven by an X-macro table (
PTN_FORALL_SCALAR_TYPES(cpp_type, name, id)). The macro generates the enum (ids pinned to ExecuTorch'sScalarType/ the
native_graph.fbsschema so a deserializer maps the serialized bytedirectly), the
k<Name>constants, the forwardScalarType -> C++ typetrait (
ScalarTypeToCppType<N>/cpp_type_t<N>), and theelement_size()/
scalar_type_name()helpers. Half / BFloat16 map touint16_tas a rawstorage stand-in.
TensorMeta(TensorMeta.{h,cpp}) — logical tensor metadata: element type,per-dim size ranges (
Dim{min, max}), and an advisorydim_order_hint(non-prescriptive — engines choose their own physical layout). Helpers:
ndim(),is_static(),is_contiguous(),numel()(upper-bound extent;throws on an unbounded dim), and equality.
Dim's range constructor rejects a range no shape can have -- a negative lowerbound, or a bounded upper bound below it -- so a malformed serialized shape
fails where it enters the IR instead of surfacing later as a wrong
numel().numel()itself checks each product againstINT64_MAXbefore multiplying,since signed overflow is UB and an overflowed count would silently plan a
smaller buffer than the shape asks for.
to_string(const TensorMeta&)(utils/Print.{h,cpp}, targetgraph:print) —the first entry in the IR's debug printer. A free function in its own target
rather than a member, so only a consumer that dumps the IR links the
formatting code; later diffs extend it as each IR type lands.
Pure std — no ExecuTorch and no flatbuffers dependency. Mirrored into both the
fbcode/andxplat/trees to match the native backend layout.Authored with Claude Code.
Differential Revision: D114396765