@@ -64,12 +64,14 @@ DPEXRT_sycl_usm_ndarray_to_python_acqref(usmarystruct_t *arystruct,
64
64
int ndim ,
65
65
int writeable ,
66
66
PyArray_Descr * descr );
67
- static int DPEXRT_sycl_queue_from_python (PyObject * obj ,
67
+ static int DPEXRT_sycl_queue_from_python (NRT_api_functions * nrt ,
68
+ PyObject * obj ,
68
69
queuestruct_t * queue_struct );
69
70
static int DPEXRT_sycl_event_from_python (NRT_api_functions * nrt ,
70
71
PyObject * obj ,
71
72
eventstruct_t * event_struct );
72
- static PyObject * DPEXRT_sycl_queue_to_python (queuestruct_t * queuestruct );
73
+ static PyObject * DPEXRT_sycl_queue_to_python (NRT_api_functions * nrt ,
74
+ queuestruct_t * queuestruct );
73
75
static PyObject * DPEXRT_sycl_event_to_python (NRT_api_functions * nrt ,
74
76
eventstruct_t * eventstruct );
75
77
@@ -1216,7 +1218,8 @@ DPEXRT_sycl_usm_ndarray_to_python_acqref(usmarystruct_t *arystruct,
1216
1218
* represent a dpctl.SyclQueue inside Numba.
1217
1219
* @return {return} Return code indicating success (0) or failure (-1).
1218
1220
*/
1219
- static int DPEXRT_sycl_queue_from_python (PyObject * obj ,
1221
+ static int DPEXRT_sycl_queue_from_python (NRT_api_functions * nrt ,
1222
+ PyObject * obj ,
1220
1223
queuestruct_t * queue_struct )
1221
1224
{
1222
1225
struct PySyclQueueObject * queue_obj = NULL ;
@@ -1246,7 +1249,13 @@ static int DPEXRT_sycl_queue_from_python(PyObject *obj,
1246
1249
DPCTLDeviceMgr_GetDeviceInfoStr (device_ref ));
1247
1250
DPCTLDevice_Delete (device_ref ););
1248
1251
1249
- queue_struct -> parent = obj ;
1252
+ // We are doing incref here to ensure python does not release the object
1253
+ // while NRT references it. Coresponding decref is called by NRT in
1254
+ // NRT_MemInfo_pyobject_dtor once there is no reference to this object by
1255
+ // the code managed by NRT.
1256
+ Py_INCREF (queue_obj );
1257
+ queue_struct -> meminfo =
1258
+ nrt -> manage_memory (queue_obj , NRT_MemInfo_pyobject_dtor );
1250
1259
queue_struct -> queue_ref = queue_ref ;
1251
1260
1252
1261
return 0 ;
@@ -1275,11 +1284,12 @@ static int DPEXRT_sycl_queue_from_python(PyObject *obj,
1275
1284
* @return {return} A PyObject created from the queuestruct->parent, if
1276
1285
* the PyObject could not be created return NULL.
1277
1286
*/
1278
- static PyObject * DPEXRT_sycl_queue_to_python (queuestruct_t * queuestruct )
1287
+ static PyObject * DPEXRT_sycl_queue_to_python (NRT_api_functions * nrt ,
1288
+ queuestruct_t * queuestruct )
1279
1289
{
1280
1290
PyObject * orig_queue = NULL ;
1281
1291
1282
- orig_queue = queuestruct -> parent ;
1292
+ orig_queue = nrt -> get_data ( queuestruct -> meminfo ) ;
1283
1293
// FIXME: Better error checking is needed to enforce the boxing of the queue
1284
1294
// object. For now, only the minimal is done as the returning of SyclQueue
1285
1295
// from a dpjit function should not be a used often and the dpctl C API for
@@ -1291,9 +1301,13 @@ static PyObject *DPEXRT_sycl_queue_to_python(queuestruct_t *queuestruct)
1291
1301
return NULL ;
1292
1302
}
1293
1303
1304
+ // TODO: is there any way to release meminfo without calling dtor so we dont
1305
+ // call incref, decref one after another.
1294
1306
// We need to increase reference count because we are returning new
1295
1307
// reference to the same queue.
1296
1308
Py_INCREF (orig_queue );
1309
+ // We need to release meminfo since we are taking ownership back.
1310
+ nrt -> release (queuestruct -> meminfo );
1297
1311
1298
1312
return orig_queue ;
1299
1313
}
0 commit comments