[executorch][native] Add Scalar value type to the in-memory IR - #22220
[executorch][native] Add Scalar value type to the in-memory IR#22220SS-JIA wants to merge 3 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22220
Note: Links to docs will display an error until the docs builds have been completed. 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):
Add
Scalar(backends/native/runtime/graph/Scalar.{h,cpp}), a concrete scalarvalue — a
std::variant<int64_t, double, bool>, analogous toc10::Scalar.Tagis pinned to the variant's alternative order, sotag()is its index andthe two cannot drift apart.
Construct implicitly from
int/int64_t/double/bool; read via strictaccessors (
to_int/to_double/to_bool, which throw on a tag mismatch) orthe promoting
to<T>()template (astd::visitthatstatic_casts whicheveralternative is live, like
c10::Scalar::to<T>()). Plustag()/is_*()predicates and
tag_name()/to_string()debug helpers. No "none" state — thegraph's Value owns that.
Every pointer converts to
bool, so the implicit constructors would otherwiselet
Scalar s = some_ptr;compile and quietly produce aBool. A deletedScalar(T*)template rejects that at the call site while leaving the numericconstructors implicit.
to_string()renders a double through the sharedptn::format_double(
graph/Format.h) rather thanstd::to_string, whose fixed six-decimal formatprints
1e-300as"0.000000"and1e300as 312 digits.The constructors and the
tag()/is_*()/to<T>()readers areconstexpr,so a
Scalarcan be built and inspected in a constant-evaluated context.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: D114396762