1010from numba .core import types
1111
1212import numba_dpex .utils as utils
13- from numba_dpex .core .exceptions import (
14- UnsupportedAccessQualifierError ,
15- UnsupportedKernelArgumentError ,
16- )
13+ from numba_dpex .core .exceptions import UnsupportedKernelArgumentError
1714from numba_dpex .core .types import USMNdArray
1815from numba_dpex .core .utils import get_info_from_suai
1916
@@ -28,42 +25,31 @@ def __init__(self, usm_mem, orig_val, packed_val, packed) -> None:
2825
2926class Packer :
3027 """Implements the functionality to unpack a Python object passed as an
31- argument to a numba_dpex kernel fucntion into corresponding ctype object.
28+ argument to a numba_dpex kernel function into corresponding ctype object.
3229 """
3330
34- # TODO: Remove after NumPy support is removed
35- _access_types = ("read_only" , "write_only" , "read_write" )
36-
37- def _check_for_invalid_access_type (self , array_val , access_type ):
38- if access_type and access_type not in Packer ._access_types :
39- raise UnsupportedAccessQualifierError (
40- self ._pyfunc_name ,
41- array_val ,
42- access_type ,
43- "," .join (Packer ._access_types ),
44- )
45-
46- def _unpack_array_helper (self , size , itemsize , buf , shape , strides , ndim ):
47- """
48- Implements the unpacking logic for array arguments.
31+ def _unpack_usm_array (self , val ):
32+ """Flattens an object of USMNdArray type into ctypes objects to be
33+ passed as kernel arguments.
4934
5035 Args:
51- size: Total number of elements in the array.
52- itemsize: Size in bytes of each element in the array.
53- buf: The pointer to the memory.
54- shape: The shape of the array.
55- ndim: Number of dimension.
36+ val : An object of dpctl.types.UsmNdArray type.
5637
5738 Returns:
58- A list a ctype value for each array attribute argument
39+ list: A list of ctype objects representing the flattened usm_ndarray
5940 """
6041 unpacked_array_attrs = []
61-
62- # meminfo (FIXME: should be removed and the USMNdArray type modified
63- # once NumPy support is removed)
42+ suai_attrs = get_info_from_suai (val )
43+ size = suai_attrs .size
44+ itemsize = suai_attrs .itemsize
45+ buf = suai_attrs .data
46+ shape = suai_attrs .shape
47+ strides = suai_attrs .strides
48+ ndim = suai_attrs .dimensions
49+
50+ # meminfo
6451 unpacked_array_attrs .append (ctypes .c_size_t (0 ))
65- # parent (FIXME: Evaluate if the attribute should be removed and the
66- # USMNdArray type modified once NumPy support is removed)
52+ # parent
6753 unpacked_array_attrs .append (ctypes .c_size_t (0 ))
6854 unpacked_array_attrs .append (ctypes .c_longlong (size ))
6955 unpacked_array_attrs .append (ctypes .c_longlong (itemsize ))
@@ -75,90 +61,7 @@ def _unpack_array_helper(self, size, itemsize, buf, shape, strides, ndim):
7561
7662 return unpacked_array_attrs
7763
78- def _unpack_usm_array (self , val ):
79- """Flattens an object of USMNdArray type into ctypes objects to be
80- passed as kernel arguments.
81-
82- Args:
83- val : An object of dpctl.types.UsmNdArray type.
84-
85- Returns:
86- list: A list of ctype objects representing the flattened usm_ndarray
87- """
88- suai_attrs = get_info_from_suai (val )
89-
90- return self ._unpack_array_helper (
91- size = suai_attrs .size ,
92- itemsize = suai_attrs .itemsize ,
93- buf = suai_attrs .data ,
94- shape = suai_attrs .shape ,
95- strides = suai_attrs .strides ,
96- ndim = suai_attrs .dimensions ,
97- )
98-
99- def _unpack_array (self , val , access_type ):
100- """Deprecated to be removed once NumPy array support in kernels is
101- removed.
102- """
103- packed_val = val
104- # Check if the NumPy array is backed by USM memory
105- usm_mem = utils .has_usm_memory (val )
106-
107- # If the NumPy array is not USM backed, then copy to a USM memory
108- # object. Add an entry to the repack_map so that on exit from kernel
109- # the data from the USM object can be copied back into the NumPy array.
110- if usm_mem is None :
111- self ._check_for_invalid_access_type (val , access_type )
112- usm_mem = utils .as_usm_obj (val , queue = self ._queue , copy = False )
113-
114- orig_val = val
115- packed = False
116- if not val .flags .c_contiguous :
117- # If the numpy.ndarray is not C-contiguous
118- # we pack the strided array into a packed array.
119- # This allows us to treat the data from here on as C-contiguous.
120- # While packing we treat the data as C-contiguous.
121- # We store the reference of both (strided and packed)
122- # array and during unpacking we use numpy.copyto() to copy
123- # the data back from the packed temporary array to the
124- # original strided array.
125- packed_val = val .flatten (order = "C" )
126- packed = True
127-
128- if access_type == "read_only" :
129- utils .copy_from_numpy_to_usm_obj (usm_mem , packed_val )
130- elif access_type == "read_write" :
131- utils .copy_from_numpy_to_usm_obj (usm_mem , packed_val )
132- # Store to the repack map
133- self ._repack_list .append (
134- _NumPyArrayPackerPayload (
135- usm_mem , orig_val , packed_val , packed
136- )
137- )
138- elif access_type == "write_only" :
139- self ._repack_list .append (
140- _NumPyArrayPackerPayload (
141- usm_mem , orig_val , packed_val , packed
142- )
143- )
144- else :
145- utils .copy_from_numpy_to_usm_obj (usm_mem , packed_val )
146- self ._repack_list .append (
147- _NumPyArrayPackerPayload (
148- usm_mem , orig_val , packed_val , packed
149- )
150- )
151-
152- return self ._unpack_array_helper (
153- packed_val .size ,
154- packed_val .dtype .itemsize ,
155- usm_mem ,
156- packed_val .shape ,
157- packed_val .strides ,
158- packed_val .ndim ,
159- )
160-
161- def _unpack_argument (self , ty , val , access_specifier ):
64+ def _unpack_argument (self , ty , val ):
16265 """
16366 Unpack a Python object into one or more ctype values using Numba's
16467 type-inference machinery.
@@ -176,8 +79,6 @@ def _unpack_argument(self, ty, val, access_specifier):
17679
17780 if isinstance (ty , USMNdArray ):
17881 return self ._unpack_usm_array (val )
179- elif isinstance (ty , types .Array ):
180- return self ._unpack_array (val , access_specifier )
18182 elif ty == types .int64 :
18283 return ctypes .c_longlong (val )
18384 elif ty == types .uint64 :
@@ -199,48 +100,22 @@ def _unpack_argument(self, ty, val, access_specifier):
199100 else :
200101 raise UnsupportedKernelArgumentError (ty , val , self ._pyfunc_name )
201102
202- def _pack_array (self ):
203- """
204- Deprecated to be removed once NumPy array support in kernels is
205- removed.
206- """
207- for obj in self ._repack_list :
208- utils .copy_to_numpy_from_usm_obj (obj ._usm_mem , obj ._packed_val )
209- if obj ._packed :
210- np .copyto (obj ._orig_val , obj ._packed_val )
211-
212- def __init__ (
213- self , kernel_name , arg_list , argty_list , access_specifiers_list , queue
214- ) -> None :
103+ def __init__ (self , kernel_name , arg_list , argty_list , queue ) -> None :
215104 """Initializes new Packer object and unpacks the input argument list.
216105
217106 Args:
107+ kernel_name (str): The kernel function name.
218108 arg_list (list): A list of arguments to be unpacked
219109 argty_list (list): A list of Numba inferred types for each argument.
220- access_specifiers_list(list): A list of access specifiers for
221- NumPy arrays to optimize host to device memory copy.
222- [Deprecated: can be removed along with NumPy array support]
223- queue (dpctl.SyclQueue): The SYCL queue where the kernel is to be
224- executed. The queue is required to allocate USM memory for NumPy
225- arrays.
226- [Deprecated: can be removed along with NumPy array support]
227110 """
228111 self ._pyfunc_name = kernel_name
229112 self ._arg_list = arg_list
230113 self ._argty_list = argty_list
231- self ._queue = queue
232- # Create a list to store the numpy arrays that need to be
233- # repacked beoe returning from a kernel.
234- self ._repack_list = []
235114
236115 # loop over the arg_list and generate the kernelargs list
237116 self ._unpacked_args = []
238117 for i , val in enumerate (arg_list ):
239- arg = self ._unpack_argument (
240- ty = argty_list [i ],
241- val = val ,
242- access_specifier = access_specifiers_list [i ],
243- )
118+ arg = self ._unpack_argument (ty = argty_list [i ], val = val )
244119 if type (arg ) == list :
245120 self ._unpacked_args .extend (arg )
246121 else :
@@ -250,9 +125,3 @@ def __init__(
250125 def unpacked_args (self ):
251126 """Returns the list of unpacked arguments created by a Packer object."""
252127 return self ._unpacked_args
253-
254- @property
255- def repacked_args (self ):
256- """Returns the list of NumPy"""
257- self ._pack_array ()
258- return self ._repack_list
0 commit comments