[executorch][native] Add TensorMeta + ScalarType in-memory IR types - #22219
[executorch][native] Add TensorMeta + ScalarType in-memory IR types#22219SS-JIA wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22219
Note: Links to docs will display an error until the docs builds have been completed. ❌ 1 New Failure, 3 Unrelated FailuresAs of commit 038de22 with merge base cf9bcd8 ( NEW FAILURE - The following job has failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
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),
to_string(), 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.
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