Skip to content

Commit d843267

Browse files
suggestion from graham
Co-authored-by: Graham Markall <[email protected]>
1 parent 6775a69 commit d843267

File tree

3 files changed

+3
-61
lines changed

3 files changed

+3
-61
lines changed

numba_cuda/numba/cuda/np/arrayobj.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3643,6 +3643,8 @@ def constant_array(context, builder, ty, pyval):
36433643
"""
36443644
Create a constant array (mechanism is target-dependent).
36453645
"""
3646+
if isinstance(pyval, list):
3647+
pyval = np.asarray(pyval)
36463648
return context.make_constant_array(builder, ty, pyval)
36473649

36483650

@@ -3656,14 +3658,6 @@ def constant_record(context, builder, ty, pyval):
36563658
return cgutils.alloca_once_value(builder, val)
36573659

36583660

3659-
@lower_constant(types.List)
3660-
def constant_list(context, builder, ty, pyval):
3661-
"""
3662-
Create a constant list (mechanism is target-dependent).
3663-
"""
3664-
return context.make_constant_list(builder, ty, pyval)
3665-
3666-
36673661
@lower_constant(types.Bytes)
36683662
def constant_bytes(context, builder, ty, pyval):
36693663
"""

numba_cuda/numba/cuda/target.py

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -273,58 +273,6 @@ def mangler(self, name, argtypes, *, abi_tags=(), uid=None):
273273
name, argtypes, abi_tags=abi_tags, uid=uid
274274
)
275275

276-
def make_constant_list(self, builder, listty, lst):
277-
"""
278-
Create a list structure with data in constant address space.
279-
The list metadata is in normal memory but the data array is in constant memory.
280-
"""
281-
import numpy as np
282-
from numba.cuda.cpython.listobj import ListInstance
283-
284-
lmod = builder.module
285-
286-
# Convert to array and serialize
287-
arr = np.array(lst)
288-
nitems = len(arr)
289-
290-
constvals = [
291-
self.get_constant(types.byte, i)
292-
for i in iter(arr.tobytes(order="C"))
293-
]
294-
constaryty = ir.ArrayType(ir.IntType(8), len(constvals))
295-
constary = ir.Constant(
296-
constaryty, constvals
297-
) # constant llvm value with the values
298-
299-
# create a global variable
300-
addrspace = nvvm.ADDRSPACE_CONSTANT
301-
gv = cgutils.add_global_variable(
302-
lmod, constary.type, "_cudapy_clist", addrspace=addrspace
303-
)
304-
gv.linkage = "internal"
305-
gv.global_constant = True
306-
gv.initializer = (
307-
constary # put the gobal variable initializer to the constant array
308-
)
309-
310-
lldtype = self.get_data_type(listty.dtype)
311-
align = self.get_abi_sizeof(lldtype)
312-
gv.align = 2 ** (align - 1).bit_length()
313-
314-
ptrty = ir.PointerType(ir.IntType(8)) # an int8 pointer
315-
genptr = builder.addrspacecast(gv, ptrty, "generic")
316-
317-
list_inst = ListInstance.allocate(self, builder, listty, nitems)
318-
data_ptrty = self.get_data_type(listty.dtype).as_pointer()
319-
const_data_ptr = builder.bitcast(genptr, data_ptrty)
320-
payload = list_inst._payload
321-
322-
# replace with constant mem
323-
payload.data = builder.ptrtoint(const_data_ptr, payload.data.type)
324-
list_inst.size = self.get_constant(types.intp, nitems)
325-
326-
return list_inst.value
327-
328276
def make_constant_array(self, builder, aryty, arr):
329277
"""
330278
Unlike the parent version. This returns a a pointer in the constant

numba_cuda/numba/cuda/typing/typeof.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def _typeof_list(val, c):
193193
ty = typeof_impl(val[0], c)
194194
if ty is None:
195195
raise ValueError(f"Cannot type list element type {type(val[0])}")
196-
return types.List(ty, reflected=True)
196+
return ty[::1]
197197

198198

199199
@typeof_impl.register(set)

0 commit comments

Comments
 (0)