Skip to content

[executorch][native] Add TensorMeta + ScalarType in-memory IR types - #22275

Open
SS-JIA wants to merge 3 commits into
gh/SS-JIA/612/basefrom
gh/SS-JIA/612/head
Open

[executorch][native] Add TensorMeta + ScalarType in-memory IR types#22275
SS-JIA wants to merge 3 commits into
gh/SS-JIA/612/basefrom
gh/SS-JIA/612/head

Conversation

@SS-JIA

@SS-JIA SS-JIA commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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-type
    enum driven by an X-macro table (PTN_FORALL_SCALAR_TYPES(cpp_type, name, id)). The macro generates the enum (ids pinned to ExecuTorch's ScalarType
    / the native_graph.fbs schema so a deserializer maps the serialized byte
    directly), the k<Name> constants, the forward ScalarType -> C++ type
    trait (ScalarTypeToCppType<N> / cpp_type_t<N>), and the element_size()
    / scalar_type_name() helpers. Half / BFloat16 map to uint16_t as a raw
    storage stand-in.
  • TensorMeta (TensorMeta.{h,cpp}) — logical tensor metadata: element type,
    per-dim size ranges (Dim{min, max}), and an advisory dim_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 lower
bound, 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 against INT64_MAX before 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}, target graph: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/ and xplat/ trees to match the native backend layout.

Authored with Claude Code.

Differential Revision: D114396765

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Aug 28, 2026

Copy link
Copy Markdown

🔗 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 Failures

As of commit 978a757 with merge base 16d3b9f (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@digantdesai digantdesai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

[ghstack-poisoned]
[ghstack-poisoned]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants