Skip to content

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

Open
SS-JIA wants to merge 2 commits into
gh/SS-JIA/599/basefrom
gh/SS-JIA/599/head
Open

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

Conversation

@SS-JIA

@SS-JIA SS-JIA commented Aug 27, 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), to_string(), 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.

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 27, 2026

Copy link
Copy Markdown

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

As of commit 038de22 with merge base cf9bcd8 (image):

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.

@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.

[ghstack-poisoned]

@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.

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