Skip to content

Commit

Permalink
Merge pull request #1153 from IntelPython/fix/improve_unbox_box_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZzEeKkAa authored Oct 17, 2023
2 parents 6e6e6e3 + b3b7522 commit 26518c3
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 189 deletions.
22 changes: 3 additions & 19 deletions numba_dpex/core/runtime/_dpexrt_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -1214,14 +1214,8 @@ DPEXRT_sycl_usm_ndarray_to_python_acqref(usmarystruct_t *arystruct,
static int DPEXRT_sycl_queue_from_python(PyObject *obj,
queuestruct_t *queue_struct)
{

struct PySyclQueueObject *queue_obj = NULL;
DPCTLSyclQueueRef queue_ref = NULL;
PyGILState_STATE gstate;

// Increment the ref count on obj to prevent CPython from garbage
// collecting the dpctl.SyclQueue object
Py_IncRef(obj);

// We are unconditionally casting obj to a struct PySyclQueueObject*. If
// the obj is not a struct PySyclQueueObject* then the SyclQueue_GetQueueRef
Expand Down Expand Up @@ -1261,11 +1255,6 @@ static int DPEXRT_sycl_queue_from_python(PyObject *obj,
"DPEXRT-ERROR: Failed to unbox dpctl SyclQueue into a Numba "
"queuestruct at %s, line %d\n",
__FILE__, __LINE__));
gstate = PyGILState_Ensure();
// decref the python object
Py_DECREF(obj);
// release the GIL
PyGILState_Release(gstate);

return -1;
}
Expand All @@ -1284,7 +1273,6 @@ static int DPEXRT_sycl_queue_from_python(PyObject *obj,
static PyObject *DPEXRT_sycl_queue_to_python(queuestruct_t *queuestruct)
{
PyObject *orig_queue = NULL;
PyGILState_STATE gstate;

orig_queue = queuestruct->parent;
// FIXME: Better error checking is needed to enforce the boxing of the queue
Expand All @@ -1298,11 +1286,9 @@ static PyObject *DPEXRT_sycl_queue_to_python(queuestruct_t *queuestruct)
return NULL;
}

gstate = PyGILState_Ensure();
// decref the parent python object as we did an incref when unboxing it
Py_DECREF(orig_queue);
// release the GIL
PyGILState_Release(gstate);
// We need to increase reference count because we are returning new
// reference to the same queue.
Py_INCREF(orig_queue);

return orig_queue;
}
Expand All @@ -1323,10 +1309,8 @@ static PyObject *DPEXRT_sycl_queue_to_python(queuestruct_t *queuestruct)
static int DPEXRT_sycl_event_from_python(PyObject *obj,
eventstruct_t *event_struct)
{

struct PySyclEventObject *event_obj = NULL;
DPCTLSyclEventRef event_ref = NULL;
PyGILState_STATE gstate;

// We are unconditionally casting obj to a struct PySyclEventObject*. If
// the obj is not a struct PySyclEventObject* then the SyclEvent_GetEventRef
Expand Down
23 changes: 5 additions & 18 deletions numba_dpex/dpnp_iface/_intrinsic.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,14 @@ def _get_queue_ref(
raise AssertionError(
"Expected the queue_arg to be an llvmir.PointerType"
)
# We are emulating queue boxing here to pass it as an argument.
# TODO: do we have a better way?
py_dpctl_sycl_queue = get_device_cached_queue(
returned_sycl_queue_ty.sycl_device
)
# TODO: make sure that queue is not getting garbage collected between
# lowering and executing.
# cache prevent it from happening but it is not clean way
(queue_ref, py_dpctl_sycl_queue_addr, pyapi) = make_queue(
context, builder, py_dpctl_sycl_queue
)
Expand Down Expand Up @@ -485,9 +490,6 @@ def codegen(context, builder, sig, args):
context, builder, sig, qref_payload.queue_ref, args
)

if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

return sig, codegen
Expand Down Expand Up @@ -564,8 +566,6 @@ def codegen(context, builder, sig, args):
qref_payload.queue_ref,
fill_value,
)
if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

Expand Down Expand Up @@ -644,8 +644,6 @@ def codegen(context, builder, sig, args):
qref_payload.queue_ref,
fill_value,
)
if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

Expand Down Expand Up @@ -730,8 +728,6 @@ def codegen(context, builder, sig, args):
qref_payload.queue_ref,
fill_value,
)
if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

Expand Down Expand Up @@ -812,9 +808,6 @@ def codegen(context, builder, sig, args):
context, builder, sig, qref_payload.queue_ref, args, is_like=True
)

if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

return sig, codegen
Expand Down Expand Up @@ -902,8 +895,6 @@ def codegen(context, builder, sig, args):
qref_payload.queue_ref,
fill_value,
)
if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

Expand Down Expand Up @@ -991,8 +982,6 @@ def codegen(context, builder, sig, args):
qref_payload.queue_ref,
fill_value,
)
if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

Expand Down Expand Up @@ -1084,8 +1073,6 @@ def codegen(context, builder, sig, args):
qref_payload.queue_ref,
fill_value,
)
if qref_payload.py_dpctl_sycl_queue_addr:
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)

return ary._getvalue()

Expand Down
91 changes: 0 additions & 91 deletions numba_dpex/tests/core/types/DpctlSyclEvent/test_box_unbox.py

This file was deleted.

27 changes: 0 additions & 27 deletions numba_dpex/tests/core/types/DpctlSyclQueue/test_box_unbox.py

This file was deleted.

34 changes: 0 additions & 34 deletions numba_dpex/tests/core/types/range_types/test_unbox_box.py

This file was deleted.

Loading

0 comments on commit 26518c3

Please sign in to comment.