Skip to content
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

Evaluate the need to pass meminfo and parent attributes of an array as kernel params #929

Closed
diptorupd opened this issue Feb 24, 2023 · 1 comment · Fixed by #1293
Closed
Labels
enhancement New feature or request

Comments

@diptorupd
Copy link
Contributor

diptorupd commented Feb 24, 2023

Each dpnp.ndarray object inside Numba uses the default Numba datamodel as defined in numba's _arraystruct.h:

typedef struct {
    void     *meminfo;  /* see _nrt_python.c and nrt.h in numba/core/runtime */
    PyObject *parent;
    npy_intp nitems;
    npy_intp itemsize;
    void *data;
    npy_intp shape_and_strides[];
} arystruct_t;

The meminfo is an internal structure maintained by Numba for each array that stores essential metadata about the array along with ana alias of the array's data pointer. Refer numba_dpex/core/runtime/_meminfo_helper.h:

struct MemInfo
{
    size_t refct;
    NRT_dtor_function dtor;
    void *dtor_info;
    void *data;
    size_t size; /* only used for NRT allocated memory */
    NRT_ExternalAllocator *external_allocator;
};

The parent is a pointer to any original Python object from which the Numba internal array was created. It is a nullptr if is the array was created inside a Numba jit compiled function.

Since these two attributes are defined in the Numba array datamodel, and since Numba passes array objects as flattened representation, any LLVM functions generated by Numba with array arguments will have extra args for the meminfo and parent pointers.

For kernel functions, these pointers are never accessed in side the function and are always passed as NULL pointers.

We should evaluate if these pointers should be passed as kernel arguments. The benefit of doing so will be it will make debugging the kernels using GDB simpler and code generation will also get simplified with lesser boilerplate.

@diptorupd diptorupd added the enhancement New feature or request label Dec 20, 2023
@diptorupd
Copy link
Contributor Author

The fix for the issue is to update the datamodel for DpnpNdArray for kernels.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant