Skip to content

Commit 96dea84

Browse files
committed
Add python object creation for unboxing SyclQueue
1 parent 70ebc88 commit 96dea84

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

numba_dpex/core/runtime/_dpexrt_python.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,29 +1287,28 @@ static int DPEXRT_sycl_queue_from_python(NRT_api_functions *nrt,
12871287
static PyObject *DPEXRT_sycl_queue_to_python(NRT_api_functions *nrt,
12881288
queuestruct_t *queuestruct)
12891289
{
1290-
PyObject *orig_queue = NULL;
1291-
1292-
orig_queue = nrt->get_data(queuestruct->meminfo);
1293-
// FIXME: Better error checking is needed to enforce the boxing of the queue
1294-
// object. For now, only the minimal is done as the returning of SyclQueue
1295-
// from a dpjit function should not be a used often and the dpctl C API for
1296-
// type checking etc. is not ready.
1297-
if (orig_queue == NULL) {
1298-
PyErr_Format(PyExc_ValueError,
1299-
"In 'box_from_queuestruct_parent', "
1300-
"failed to create a new dpctl.SyclQueue object.");
1301-
return NULL;
1290+
PyObject *queue_obj = NULL;
1291+
1292+
queue_obj = nrt->get_data(queuestruct->meminfo);
1293+
1294+
if (queue_obj == NULL) {
1295+
// Make create copy of queue_ref so we don't need to manage nrt lifetime
1296+
// from python object.
1297+
queue_obj = SyclQueue_Make(queuestruct->queue_ref);
1298+
}
1299+
else {
1300+
// Unfortunately we can not optimize (nrt->release that triggers
1301+
// Py_DECREF() from the destructor) and Py_INCREF() because nrt may need
1302+
// the object even if we return it to python.
1303+
// We need to increase reference count because we are returning new
1304+
// reference to the same queue.
1305+
Py_INCREF(queue_obj);
13021306
}
13031307

1304-
// TODO: is there any way to release meminfo without calling dtor so we dont
1305-
// call incref, decref one after another.
1306-
// We need to increase reference count because we are returning new
1307-
// reference to the same queue.
1308-
Py_INCREF(orig_queue);
13091308
// We need to release meminfo since we are taking ownership back.
13101309
nrt->release(queuestruct->meminfo);
13111310

1312-
return orig_queue;
1311+
return queue_obj;
13131312
}
13141313

13151314
/*----------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)