-
Notifications
You must be signed in to change notification settings - Fork 33
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
Adds Range and NdRange as supported types in numba_dpex.dpjit. #1148
Conversation
66d6bd3
to
b0a2d1e
Compare
69330d8
to
f3b7d26
Compare
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.
Overall looks good. I was trying to understand what's going on here, so most of the comments is more to get better understanding, that request to changes something. Also NDRange concept still unclear for me.
with cgutils.early_exit_if_null(c.builder, stack, dim2_obj): | ||
c.builder.store(fail_obj, ret_ptr) | ||
|
||
class_obj = c.pyapi.unserialize(c.pyapi.serialize_object(Range)) |
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.
Sorry, lack of knowledge, could you explain why do we do this?
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.
First a mea culpa, I have no idea! Purely "monkey see, monkey do" from the Numba extension guide.
But, I dug up what it does. Here is the paper trail:
https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromStringAndSize
My superficial reading of what is happening here is that for every registered type Numba is maintaining a cache of how to serialize and unserialize an object of that type using the Python pickle
module. It is a functionality I believe was designed mainly for on-disk caching of compiled functions and that involves being able to box and unbox argument types. So, we are using that API to call the CPython PyBytes_FromStringAndSize
to get the PyObject
structure that represents a Range
object in this case. Once we have that we are next doing a PyObject_CallFunctionObjArgs
to call the constructor for that object.
We might need a better CPython expert like @oleksandr-pavlyk for further explanation.
""" | ||
Convert a native range structure to a Range object. | ||
""" | ||
ret_ptr = cgutils.alloca_once(c.builder, c.pyapi.pyobj) |
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.
Am I right that this one creates reference on the created object, that's why we don't have to increase reference manually?
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.
ret_ptr
is the PyObject*
into which the res
(Range
) object to be stored is stored. Since it is a new object that gets returned from Numba to CPython, a incref is not needed.
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.
So, how does it getting cleaned then?
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.
When a PyObject is created the ref count should be 1
. Once Numba returns the object to CPython, then CPython will track the lifetime of the object, and decref once the object is out of scope and dead. The garbage collector will free it up at that point.
- The numba_dpex.core.kernel_interface.indexers.Range and NdRange classes can now be used inside a numba_dpex.dpjit decorated function, as arguments to a dpjit decorated function, and returned from a dpjit decorated function. - Defines a datamodel, type class, overloads for the constructors, box, and unbox functions for both classes.
38ee434
to
af0208d
Compare
- A static variable Range.UNDEFINED_DIMENSION is now used instead of the magic -1 value to indicate that the dimension extent is undefined. - An ndim_obj need not be created when boxing a Range.
af0208d
to
7e44902
Compare
https://enccs.github.io/sycl-workshop/expressing-parallelism-nd-range/ |
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.
Still not 100% sure if I competent enough to put approval if it is good or not, but from my perspective it LGTM)
…support Adds Range and NdRange as supported types in numba_dpex.dpjit. cd5332f
NdRange classes can now be used inside a numba_dpex.dpjit
decorated function, as arguments to a dpjit decorated function,
and returned from a dpjit decorated function.
box, and unbox functions for both classes.
The PR should be merged post 0.21.3 tag