@@ -45,20 +45,23 @@ static NRT_MemInfo *DPEXRT_MemInfo_fill(NRT_MemInfo *mi,
45
45
bool value_is_float ,
46
46
int64_t value ,
47
47
const DPCTLSyclQueueRef qref );
48
- static NRT_MemInfo * NRT_MemInfo_new_from_usmndarray (PyObject * ndarrobj ,
48
+ static NRT_MemInfo * NRT_MemInfo_new_from_usmndarray (NRT_api_functions * nrt ,
49
+ PyObject * ndarrobj ,
49
50
void * data ,
50
51
npy_intp nitems ,
51
52
npy_intp itemsize ,
52
53
DPCTLSyclQueueRef qref );
53
- static NRT_MemInfo * DPEXRT_MemInfo_alloc (npy_intp size ,
54
+ static NRT_MemInfo * DPEXRT_MemInfo_alloc (NRT_api_functions * nrt ,
55
+ npy_intp size ,
54
56
size_t usm_type ,
55
57
const DPCTLSyclQueueRef qref );
56
58
static void usmndarray_meminfo_dtor (void * ptr , size_t size , void * info );
57
59
static PyObject * box_from_arystruct_parent (usmarystruct_t * arystruct ,
58
60
int ndim ,
59
61
PyArray_Descr * descr );
60
62
61
- static int DPEXRT_sycl_usm_ndarray_from_python (PyObject * obj ,
63
+ static int DPEXRT_sycl_usm_ndarray_from_python (NRT_api_functions * nrt ,
64
+ PyObject * obj ,
62
65
usmarystruct_t * arystruct );
63
66
static PyObject *
64
67
DPEXRT_sycl_usm_ndarray_to_python_acqref (usmarystruct_t * arystruct ,
@@ -336,6 +339,11 @@ NRT_ExternalAllocator_new_for_usm(DPCTLSyclQueueRef qref, size_t usm_type)
336
339
static void usmndarray_meminfo_dtor (void * ptr , size_t size , void * info )
337
340
{
338
341
MemInfoDtorInfo * mi_dtor_info = NULL ;
342
+ // Warning: we are destructing sycl memory. MI destructor is called
343
+ // separately by numba.
344
+ DPEXRT_DEBUG (drt_debug_print ("DPEXRT-DEBUG: Call to "
345
+ "usmndarray_meminfo_dtor at %s, line %d\n" ,
346
+ __FILE__ , __LINE__ ));
339
347
340
348
// Sanity-check to make sure the mi_dtor_info is an actual pointer.
341
349
if (!(mi_dtor_info = (MemInfoDtorInfo * )info )) {
@@ -416,7 +424,8 @@ static MemInfoDtorInfo *MemInfoDtorInfo_new(NRT_MemInfo *mi, PyObject *owner)
416
424
* of the dpnp.ndarray was allocated.
417
425
* @return {return} A new NRT_MemInfo object
418
426
*/
419
- static NRT_MemInfo * NRT_MemInfo_new_from_usmndarray (PyObject * ndarrobj ,
427
+ static NRT_MemInfo * NRT_MemInfo_new_from_usmndarray (NRT_api_functions * nrt ,
428
+ PyObject * ndarrobj ,
420
429
void * data ,
421
430
npy_intp nitems ,
422
431
npy_intp itemsize ,
@@ -427,8 +436,9 @@ static NRT_MemInfo *NRT_MemInfo_new_from_usmndarray(PyObject *ndarrobj,
427
436
MemInfoDtorInfo * midtor_info = NULL ;
428
437
DPCTLSyclContextRef cref = NULL ;
429
438
430
- // Allocate a new NRT_MemInfo object
431
- if (!(mi = (NRT_MemInfo * )malloc (sizeof (NRT_MemInfo )))) {
439
+ // Allocate a new NRT_MemInfo object. By passing 0 we are just allocating
440
+ // MemInfo and not the `data` that the MemInfo object manages.
441
+ if (!(mi = (NRT_MemInfo * )nrt -> allocate (0 ))) {
432
442
DPEXRT_DEBUG (drt_debug_print (
433
443
"DPEXRT-ERROR: Could not allocate a new NRT_MemInfo "
434
444
"object at %s, line %d\n" ,
@@ -505,7 +515,8 @@ static NRT_MemInfo *NRT_MemInfo_new_from_usmndarray(PyObject *ndarrobj,
505
515
* @return {return} A new NRT_MemInfo object, NULL if no NRT_MemInfo
506
516
* object could be created.
507
517
*/
508
- static NRT_MemInfo * DPEXRT_MemInfo_alloc (npy_intp size ,
518
+ static NRT_MemInfo * DPEXRT_MemInfo_alloc (NRT_api_functions * nrt ,
519
+ npy_intp size ,
509
520
size_t usm_type ,
510
521
const DPCTLSyclQueueRef qref )
511
522
{
@@ -517,7 +528,7 @@ static NRT_MemInfo *DPEXRT_MemInfo_alloc(npy_intp size,
517
528
"DPEXRT-DEBUG: Inside DPEXRT_MemInfo_alloc %s, line %d\n" , __FILE__ ,
518
529
__LINE__ ));
519
530
// Allocate a new NRT_MemInfo object
520
- if (!(mi = (NRT_MemInfo * )malloc ( sizeof ( NRT_MemInfo ) ))) {
531
+ if (!(mi = (NRT_MemInfo * )nrt -> allocate ( 0 ))) {
521
532
DPEXRT_DEBUG (drt_debug_print (
522
533
"DPEXRT-ERROR: Could not allocate a new NRT_MemInfo object.\n" ));
523
534
goto error ;
@@ -795,7 +806,8 @@ static npy_intp product_of_shape(npy_intp *shape, npy_intp ndim)
795
806
* instance of a dpnp.ndarray
796
807
* @return {return} Error code representing success (0) or failure (-1).
797
808
*/
798
- static int DPEXRT_sycl_usm_ndarray_from_python (PyObject * obj ,
809
+ static int DPEXRT_sycl_usm_ndarray_from_python (NRT_api_functions * nrt ,
810
+ PyObject * obj ,
799
811
usmarystruct_t * arystruct )
800
812
{
801
813
struct PyUSMArrayObject * arrayobj = NULL ;
@@ -842,7 +854,7 @@ static int DPEXRT_sycl_usm_ndarray_from_python(PyObject *obj,
842
854
}
843
855
844
856
if (!(arystruct -> meminfo = NRT_MemInfo_new_from_usmndarray (
845
- obj , data , nitems , itemsize , qref )))
857
+ nrt , obj , data , nitems , itemsize , qref )))
846
858
{
847
859
DPEXRT_DEBUG (drt_debug_print (
848
860
"DPEXRT-ERROR: NRT_MemInfo_new_from_usmndarray failed "
0 commit comments