Add mark-entry-points pass to annotate nested-module entry functions#2899
Add mark-entry-points pass to annotate nested-module entry functions#2899mehrdad2m wants to merge 6 commits into
Conversation
|
Thanks @mehrdad2m! I have a couple of questions:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2899 +/- ##
=======================================
Coverage 97.00% 97.00%
=======================================
Files 167 167
Lines 18875 18876 +1
Branches 1773 1773
=======================================
+ Hits 18309 18310 +1
Misses 420 420
Partials 146 146 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
That's a very good question. Currently we do reuse
This was not a clear choice for me as I think both are possible. The semantics of |
Co-authored-by: Mehrdad Malek <39844030+mehrdad2m@users.noreply.github.com>
Hmm, putting the question of having the same attribute for program and kernel entry points aside, why do we actually need multiple entry points for a kernel? I've never seen us make use of it, and even conceptually I would think the kernel should have one entry point. Coming back to the original question, if we make it so the kernel has exactly one entry point, then I think reusing the attribute is fine. If they do in fact have different semantics separating them out might make sense instead. |
This is true, there is a bit of maintenance burden, although this applies to all invariants of our IR that passes need to respect. They also need to make sure to propagate, add, and remove the quantum.node attribute as needed as well. I actually had a WIP branch to formalize the entry point attribute similar to qnode attribute, and the idea was to use the verifier to ensure that passes are not violating our invariants. Relying on this pass alone for example doesn't fix the problem, unless you always run it right before you need it (otherwise passes can still invalidate the attribute invariant after the pass was run). Even then you'd have to make sure the pass deletes any existing ones too, not just adding them for the current launch_kernel ops (as the pass currently does). Overall I would lean towards an "invariants" approach rather than an "analysis" approach, but I'm curious to hear what you think. |
Context:
When the compiler emits nested modules, the functions that the host actually dispatches into need to be distinguishable from purely-internal helpers. Downstream passes may use this as a signal for "this function is an externally-reachable entry point".
Description of the Change:
Introduces a
catalyst.entry_pointannotation marking the functions that are externally callable, produced from either:MarkEntryPointspass for nested modules.Benefits:
Possible Drawbacks:
Related GitHub Issues: