-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[OM] Pass Python values back and forth, not Attributes. #7417
Conversation
Internally, primitive OM EvaluatorValues are represented as TypedAttributes. This is great internally, but when we pass these from C++ out to Python, we have to use a very inefficient method to pull the Python value out of the attribute. This updates how primitives are handled at the Python <> C++ interface to directly construct the appropriate Python values and return them. Similarly, for top-level inputs to the Evaluator, Python values are directly accepted and converted to Attributes internally. On large designs, this was shown to decrease single threaded CPU time to process large amounts of OM data by roughly 70%. There is no difference in the output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comment, but overall looks good.
static PythonPrimitive omPrimitiveToPythonValue(MlirAttribute attr) { | ||
if (omAttrIsAIntegerAttr(attr)) { | ||
auto strRef = omIntegerAttrToString(attr); | ||
return py::int_(py::str(strRef.data, strRef.length)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason, we need to go from int to str to py::int_
?
(Not super familiar with the pybind API)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to handle ints larger than 64 bits. This is the pybind way of saying this same Python code:
circt/lib/Bindings/Python/support.py
Line 198 in 3c12682
return int(str(om.OMIntegerAttr(attr))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was some discussion previously, but this is our workaround for now: llvm/llvm-project#84190
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
For the C++ -> Python direction, this should handle all the types of primitive attributes we are using. For the Python -> C++ direction, this only supports some of the basic int, float, str, bool. Some of the more complex primitives could be supported, but nothing was actually using that, so I'm leaving it to future work. |
Internally, primitive OM EvaluatorValues are represented as TypedAttributes. This is great internally, but when we pass these from C++ out to Python, we have to use a very inefficient method to pull the Python value out of the attribute.
This updates how primitives are handled at the Python <> C++ interface to directly construct the appropriate Python values and return them. Similarly, for top-level inputs to the Evaluator, Python values are directly accepted and converted to Attributes internally.
On large designs, this was shown to decrease single threaded CPU time to process large amounts of OM data by roughly 70%. There is no difference in the output.