Skip to content

Commit 26518c3

Browse files
authored
Merge pull request #1153 from IntelPython/fix/improve_unbox_box_tests
2 parents 6e6e6e3 + b3b7522 commit 26518c3

File tree

6 files changed

+153
-189
lines changed

6 files changed

+153
-189
lines changed

numba_dpex/core/runtime/_dpexrt_python.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,14 +1214,8 @@ DPEXRT_sycl_usm_ndarray_to_python_acqref(usmarystruct_t *arystruct,
12141214
static int DPEXRT_sycl_queue_from_python(PyObject *obj,
12151215
queuestruct_t *queue_struct)
12161216
{
1217-
12181217
struct PySyclQueueObject *queue_obj = NULL;
12191218
DPCTLSyclQueueRef queue_ref = NULL;
1220-
PyGILState_STATE gstate;
1221-
1222-
// Increment the ref count on obj to prevent CPython from garbage
1223-
// collecting the dpctl.SyclQueue object
1224-
Py_IncRef(obj);
12251219

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

12701259
return -1;
12711260
}
@@ -1284,7 +1273,6 @@ static int DPEXRT_sycl_queue_from_python(PyObject *obj,
12841273
static PyObject *DPEXRT_sycl_queue_to_python(queuestruct_t *queuestruct)
12851274
{
12861275
PyObject *orig_queue = NULL;
1287-
PyGILState_STATE gstate;
12881276

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

1301-
gstate = PyGILState_Ensure();
1302-
// decref the parent python object as we did an incref when unboxing it
1303-
Py_DECREF(orig_queue);
1304-
// release the GIL
1305-
PyGILState_Release(gstate);
1289+
// We need to increase reference count because we are returning new
1290+
// reference to the same queue.
1291+
Py_INCREF(orig_queue);
13061292

13071293
return orig_queue;
13081294
}
@@ -1323,10 +1309,8 @@ static PyObject *DPEXRT_sycl_queue_to_python(queuestruct_t *queuestruct)
13231309
static int DPEXRT_sycl_event_from_python(PyObject *obj,
13241310
eventstruct_t *event_struct)
13251311
{
1326-
13271312
struct PySyclEventObject *event_obj = NULL;
13281313
DPCTLSyclEventRef event_ref = NULL;
1329-
PyGILState_STATE gstate;
13301314

13311315
// We are unconditionally casting obj to a struct PySyclEventObject*. If
13321316
// the obj is not a struct PySyclEventObject* then the SyclEvent_GetEventRef

numba_dpex/dpnp_iface/_intrinsic.py

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,14 @@ def _get_queue_ref(
156156
raise AssertionError(
157157
"Expected the queue_arg to be an llvmir.PointerType"
158158
)
159+
# We are emulating queue boxing here to pass it as an argument.
160+
# TODO: do we have a better way?
159161
py_dpctl_sycl_queue = get_device_cached_queue(
160162
returned_sycl_queue_ty.sycl_device
161163
)
164+
# TODO: make sure that queue is not getting garbage collected between
165+
# lowering and executing.
166+
# cache prevent it from happening but it is not clean way
162167
(queue_ref, py_dpctl_sycl_queue_addr, pyapi) = make_queue(
163168
context, builder, py_dpctl_sycl_queue
164169
)
@@ -485,9 +490,6 @@ def codegen(context, builder, sig, args):
485490
context, builder, sig, qref_payload.queue_ref, args
486491
)
487492

488-
if qref_payload.py_dpctl_sycl_queue_addr:
489-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
490-
491493
return ary._getvalue()
492494

493495
return sig, codegen
@@ -564,8 +566,6 @@ def codegen(context, builder, sig, args):
564566
qref_payload.queue_ref,
565567
fill_value,
566568
)
567-
if qref_payload.py_dpctl_sycl_queue_addr:
568-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
569569

570570
return ary._getvalue()
571571

@@ -644,8 +644,6 @@ def codegen(context, builder, sig, args):
644644
qref_payload.queue_ref,
645645
fill_value,
646646
)
647-
if qref_payload.py_dpctl_sycl_queue_addr:
648-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
649647

650648
return ary._getvalue()
651649

@@ -730,8 +728,6 @@ def codegen(context, builder, sig, args):
730728
qref_payload.queue_ref,
731729
fill_value,
732730
)
733-
if qref_payload.py_dpctl_sycl_queue_addr:
734-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
735731

736732
return ary._getvalue()
737733

@@ -812,9 +808,6 @@ def codegen(context, builder, sig, args):
812808
context, builder, sig, qref_payload.queue_ref, args, is_like=True
813809
)
814810

815-
if qref_payload.py_dpctl_sycl_queue_addr:
816-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
817-
818811
return ary._getvalue()
819812

820813
return sig, codegen
@@ -902,8 +895,6 @@ def codegen(context, builder, sig, args):
902895
qref_payload.queue_ref,
903896
fill_value,
904897
)
905-
if qref_payload.py_dpctl_sycl_queue_addr:
906-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
907898

908899
return ary._getvalue()
909900

@@ -991,8 +982,6 @@ def codegen(context, builder, sig, args):
991982
qref_payload.queue_ref,
992983
fill_value,
993984
)
994-
if qref_payload.py_dpctl_sycl_queue_addr:
995-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
996985

997986
return ary._getvalue()
998987

@@ -1084,8 +1073,6 @@ def codegen(context, builder, sig, args):
10841073
qref_payload.queue_ref,
10851074
fill_value,
10861075
)
1087-
if qref_payload.py_dpctl_sycl_queue_addr:
1088-
qref_payload.pyapi.decref(qref_payload.py_dpctl_sycl_queue_addr)
10891076

10901077
return ary._getvalue()
10911078

numba_dpex/tests/core/types/DpctlSyclEvent/test_box_unbox.py

Lines changed: 0 additions & 91 deletions
This file was deleted.

numba_dpex/tests/core/types/DpctlSyclQueue/test_box_unbox.py

Lines changed: 0 additions & 27 deletions
This file was deleted.

numba_dpex/tests/core/types/range_types/test_unbox_box.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

0 commit comments

Comments
 (0)