[executorch][native] Add Scalar value type to the in-memory IR - #22276
[executorch][native] Add Scalar value type to the in-memory IR#22276SS-JIA wants to merge 1 commit into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22276
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit cd0319a with merge base a5f15b5 ( BROKEN TRUNK - The following job failed but were 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):
Add
Scalar(backends/native/runtime/graph/Scalar.{h,cpp}), a concrete scalarvalue — a
std::variant<int64_t, double, bool>, analogous toc10::Scalar:one alternative per domain (integral, floating point, boolean), each stored at
its widest type, so a narrower value is stored exactly and
to<T>()narrows itback on read.
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>()). Plusis_*()predicates. No"none" state — the graph'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(const Scalar&)joins the IR printer inutils/Print.{h,cpp}. Itrenders a double through the shared
ptn::format_double(
graph/StringFormat.h) rather thanstd::to_string, whose fixed six-decimalformat prints
1e-300as"0.000000"and1e300as 312 digits.The constructors and the
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