Skip to content

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

@diptorupd

Description

@diptorupd

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions