Replies: 2 comments 3 replies
-
Beta Was this translation helpful? Give feedback.
0 replies
-
@fstrug - could you please try to import cupy as cp
import numpy as np
import awkward as ak
def get_RecordForm(array):
fields = array.dtype.fields
form = ak.forms.RecordForm(
[ak.forms.NumpyForm(str(value[0]), form_key=f"node{i+1}")
for i, value in enumerate(fields.values())],
fields.keys(),
form_key="node0",
)
return form
def get_Container(array, form):
container = {}
fields = array.dtype.fields
reshaped = cp.ascontiguousarray(array.view("uint8")).reshape(-1, array.dtype.itemsize)
tracker = 0
for i, key in enumerate(fields.values()):
form_key = form.contents[i].form_key
data = reshaped[:, tracker:tracker + key[0].itemsize].view(key[0])
tracker += key[0].itemsize
container[f"{form_key}-data"] = cp.ascontiguousarray(data) # Enforce alignment
return container
def structured_cupy_to_ak(array):
length = array.shape[0]
form = get_RecordForm(array)
container = get_Container(array, form)
return ak.from_buffers(form, length, container, backend="cuda") |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Support for structured arrays in
cupy
has been an open request since 2019 cupy/cupy#2031. While it is possible to create a structuredcupy.ndarray
, once it is created you cannot interact with it in the same way as acupy.ndarray
. It is possible to copy back to the host as anumpy.ndarray
and get the expected behavior.In awkward, one can create an analogous awkward array with the cuda backend by calling
while calling
returns an error
TypeError: unsupported dtype: dtype([('index', '<i8'), ('tag', '<i4')])
.Potential Workaround
Since it is unclear what
cupy
will do in regards to this issue, it may be useful to provide a work around.This appears to give the same results as
but you get
CUDARuntimeError: cudaErrorMisalignedAddress: misaligned address
when you try to operate on theawkward.Array
constructed directly from thecupy.ndarray
slices. It would be nice to avoid bouncing the buffer back to the CPU if possible here, but that would require making contiguous copies from the slices? What are your thoughts here?Beta Was this translation helpful? Give feedback.
All reactions