Skip to content

Commit

Permalink
test: cuda integration tests (#3065)
Browse files Browse the repository at this point in the history
* fix: incompatible backends in ak.firsts

* refactor: variable name

* test: ak.firsts

* test: add tests

* tests: another batch of tests

* fix: failing tests

* fix: awkward_UnionArray_regular_index_getsize

* test: add unit tests for BitMaskeArray kernels

* fix: remove tests with OverflowError

* refactor: split test files

* test: add more tests

* tests: add and rearrange tests
  • Loading branch information
ManasviGoyal authored Apr 4, 2024
1 parent 548f6de commit 12a30f4
Show file tree
Hide file tree
Showing 9 changed files with 4,208 additions and 85 deletions.
15 changes: 14 additions & 1 deletion kernel-test-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -10629,7 +10629,7 @@
},
{
"name": "awkward_ListOffsetArray_rpad_axis1",
"status": true,
"status": false,
"tests": [
{
"error": false,
Expand Down Expand Up @@ -21966,6 +21966,19 @@
"toindex": []
}
},
{
"error": false,
"message": "",
"inputs": {
"bitmasklength": 1,
"frombitmask": [66],
"lsb_order": true,
"validwhen": false
},
"outputs": {
"toindex": [0, -1, 2, 3, 4, 5, -1, 7]
}
},
{
"error": false,
"message": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
// def f(grid, block, args):
// (size, fromtags, length, invocation_index, err_code) = args
// if length > 0:
// size[0] = cupy.max(fromtags)
// size[0] = 0 if cupy.all(fromtags < 0) else cupy.max(fromtags)
// else:
// size[0] = 0
// cuda_kernel_templates.get_function(fetch_specialization(["awkward_UnionArray_regular_index_getsize", size.dtype, fromtags.dtype]))(grid, block, (size, fromtags, length, invocation_index, err_code))
// out["awkward_UnionArray_regular_index_getsize", {dtype_specializations}] = None
// END PYTHON
Expand All @@ -18,6 +20,6 @@ awkward_UnionArray_regular_index_getsize(
uint64_t invocation_index,
uint64_t* err_code) {
if (err_code[0] == NO_ERROR) {
*size = length > 0 && *size > 0 ? *size + 1 : 1;
*size = *size + 1;
}
}
21 changes: 12 additions & 9 deletions src/awkward/contents/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,15 +669,18 @@ def _getitem(self, where):
return self._getitem_fields(list(where))

else:
layout = ak.operations.ak_to_layout._impl(
where,
allow_record=False,
allow_unknown=False,
none_policy="error",
regulararray=False,
use_from_iter=True,
primitive_policy="error",
string_policy="as-characters",
layout = ak.to_backend(
ak.operations.ak_to_layout._impl(
where,
allow_record=False,
allow_unknown=False,
none_policy="error",
regulararray=False,
use_from_iter=True,
primitive_policy="error",
string_policy="as-characters",
),
self._backend,
)
return self._getitem(layout)

Expand Down
3 changes: 2 additions & 1 deletion src/awkward/operations/ak_firsts.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def _impl(array, axis, highlevel, behavior, attrs):
# Build an integer-typed slice array, so that we can
# ensure we have advanced indexing for both length==0
# and length > 0 cases.
slicer = ak.from_iter([None, 0])
backend = ak.backend(array)
slicer = ak.to_backend(ak.from_iter([None, 0]), backend)
if layout.length == 0:
out = layout[slicer[[0]]][0]
else:
Expand Down
9 changes: 4 additions & 5 deletions tests-cuda/test_2922a_new_cuda_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
to_list = ak.operations.to_list


class ReversibleArray(ak.Array):
def reversed(self):
return self[..., ::-1]


def test_0184_concatenate_operation_records():
one = ak.highlevel.Array([[1, 2, 3], [None, 4], None, [None, 5]]).layout
two = ak.highlevel.Array([6, 7, 8]).layout
Expand Down Expand Up @@ -611,6 +606,10 @@ def test_2564_string_broadcast_regular_string_string_valid():


def test_2549_list_nominal_type_string_class():
class ReversibleArray(ak.Array):
def reversed(self):
return self[..., ::-1]

ak.behavior["reversible-string"] = ReversibleArray

strings = ak.with_parameter(["hi", "book", "cats"], "__list__", "reversible-string")
Expand Down
71 changes: 4 additions & 67 deletions tests-cuda/test_2922b_new_cuda_kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,11 @@ def test_0028_add_dressed_types_highlevel():
)


class Pointy(ak.highlevel.Record):
def __str__(self):
return "<{} {}>".format(self["x"], self["y"])


def test_0049_distinguish_record_and_recordarray_behaviors():
class Pointy(ak.highlevel.Record):
def __str__(self):
return "<{} {}>".format(self["x"], self["y"])

behavior = {}
behavior["__typestr__", "Point"] = "P"
behavior["Point"] = Pointy
Expand Down Expand Up @@ -1444,68 +1443,6 @@ def test_0193_is_none_axis_parameter():
]


def test_0023_regular_array_maybe_to_Numpy():
array = ak.highlevel.Array(
[0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9], check_valid=True
).layout
array2 = ak.highlevel.Array([3, 6, None, None, -2, 6], check_valid=True).layout

cuda_array = ak.to_backend(array, "cuda", highlevel=False)
cuda_array2 = ak.to_backend(array2, "cuda", highlevel=False)

assert to_list(cuda_array[cuda_array2]) == [
3.3,
6.6,
None,
None,
8.8,
6.6,
]
assert cuda_array.to_typetracer()[cuda_array2].form == cuda_array[cuda_array2].form

content = ak.contents.NumpyArray(
np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9, 10.0, 11.1, 999])
)
regulararray = ak.contents.RegularArray(content, 4, zeros_length=0)
cuda_regulararray = ak.to_backend(regulararray, "cuda", highlevel=False)

array3 = ak.highlevel.Array([2, 1, 1, None, -1], check_valid=True).layout
cuda_array3 = ak.to_backend(array3, "cuda", highlevel=False)

cuda_numpyarray = cuda_regulararray.maybe_to_NumpyArray()
# assert to_list(cuda_numpyarray[cuda_array3]) == [
# [8.8, 9.9, 10.0, 11.1],
# [4.4, 5.5, 6.6, 7.7],
# [4.4, 5.5, 6.6, 7.7],
# None,
# [8.8, 9.9, 10.0, 11.1],
# ]
assert (
cuda_numpyarray.to_typetracer()[cuda_array3].form
== cuda_numpyarray[cuda_array3].form
)
assert to_list(cuda_numpyarray[:, cuda_array3]) == [
[2.2, 1.1, 1.1, None, 3.3],
[6.6, 5.5, 5.5, None, 7.7],
[10.0, 9.9, 9.9, None, 11.1],
]

a = ak.contents.regulararray.RegularArray(
ak.contents.numpyarray.NumpyArray(
np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6])
),
3,
)
cuda_a = ak.to_backend(a, "cuda", highlevel=False)

assert len(cuda_a) == 2
cuda_a = cuda_a.maybe_to_NumpyArray()
assert isinstance(
cuda_a[1,],
ak.contents.numpyarray.NumpyArray,
)


def test_0023_regular_array_getitem():
content = ak.contents.NumpyArray(
np.array([0.0, 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9])
Expand Down
Loading

0 comments on commit 12a30f4

Please sign in to comment.