Skip to content

Commit

Permalink
Add convolve tests to improve c++ coverage (#1086)
Browse files Browse the repository at this point in the history
* Add convolve tests to improve c++ coverage

* Downsize shape to 4096 to fit in default fbmem.
  • Loading branch information
yimoj authored Nov 30, 2023
1 parent 3f17401 commit 6cf9e94
Showing 1 changed file with 62 additions and 6 deletions.
68 changes: 62 additions & 6 deletions tests/integration/test_convolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,66 @@
# limitations under the License.
#

import os

import numpy as np
import pytest
import scipy.signal as sig
from utils.comparisons import allclose

import cunumeric as num

SHAPES = [(100,), (10, 10), (10, 10, 10)]
FILTER_SHAPES = [(5,), (3, 5), (3, 5, 3)]
CUDA_TEST = os.environ.get("LEGATE_NEED_CUDA") == "1"

SHAPES = [(100,), (10, 10), (10, 10, 10), (32, 2, 32)]
FILTER_SHAPES = [(5,), (3, 5), (3, 5, 3), (32, 1, 32)]

LARGE_SHAPES = [
pytest.param(
(128, 2, 1024),
(64, 2, 512),
marks=pytest.mark.xfail(
not CUDA_TEST, run=False, reason="test hang on CPU variants"
),
),
pytest.param(
(1024, 2, 4096),
(128, 16, 64),
marks=pytest.mark.xfail(
not CUDA_TEST, run=False, reason="test hang on CPU variants"
),
),
pytest.param(
(1024, 2, 1024),
(5, 1, 5),
marks=pytest.mark.xfail(
CUDA_TEST, run=False, reason="GPU variant hits SIGABRT"
),
),
pytest.param(
(1024, 2, 1024),
(128, 1, 128),
marks=pytest.mark.xfail(
run=False, reason="GPU variant hits SIGFPE, CPU hangs"
),
),
]

DTYPES = [
np.int8,
np.int16,
np.int32,
np.int64,
np.uint8,
np.uint16,
np.uint32,
np.uint64,
np.float16,
np.float32,
np.float64,
np.complex64,
np.complex128,
]


@pytest.mark.xfail
Expand Down Expand Up @@ -68,7 +119,9 @@ def check_convolve(a, v):


@pytest.mark.parametrize(
"shape, filter_shape", zip(SHAPES, FILTER_SHAPES), ids=str
"shape, filter_shape",
list(zip(SHAPES, FILTER_SHAPES)) + LARGE_SHAPES,
ids=str,
)
def test_double(shape, filter_shape):
a = num.random.rand(*shape)
Expand All @@ -79,7 +132,9 @@ def test_double(shape, filter_shape):


@pytest.mark.parametrize(
"shape, filter_shape", zip(SHAPES, FILTER_SHAPES), ids=str
"shape, filter_shape",
list(zip(SHAPES, FILTER_SHAPES)) + LARGE_SHAPES,
ids=str,
)
def test_int(shape, filter_shape):
a = num.random.randint(0, 5, shape)
Expand All @@ -88,10 +143,11 @@ def test_int(shape, filter_shape):
check_convolve(a, v)


def test_dtype():
@pytest.mark.parametrize("dtype", DTYPES, ids=str)
def test_dtype(dtype):
shape = (5,) * 2
arr1 = num.random.randint(0, 5, shape, dtype=np.int64)
arr2 = num.random.random(shape)
arr2 = num.random.random(shape).astype(dtype)
out_num = num.convolve(arr1, arr2, mode="same")
out_np = np.convolve(arr1, arr2, mode="same")
assert allclose(out_num, out_np)
Expand Down

0 comments on commit 6cf9e94

Please sign in to comment.