Skip to content

Commit aa35ca1

Browse files
authored
Mark CV-CUDA tests with needs_cvcuda (#9305)
1 parent 96e7797 commit aa35ca1

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

test/common_utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
IN_RE_WORKER = os.environ.get("INSIDE_RE_WORKER") is not None
3030
IN_FBCODE = os.environ.get("IN_FBCODE_TORCHVISION") == "1"
3131
CUDA_NOT_AVAILABLE_MSG = "CUDA device not available"
32+
CVCUDA_NOT_AVAILABLE_MSG = "CV-CUDA not available"
3233
MPS_NOT_AVAILABLE_MSG = "MPS device not available"
3334
OSS_CI_GPU_NO_CUDA_MSG = "We're in an OSS GPU machine, and this test doesn't need cuda."
3435

@@ -134,6 +135,12 @@ def needs_cuda(test_func):
134135
return pytest.mark.needs_cuda(test_func)
135136

136137

138+
def needs_cvcuda(test_func):
139+
import pytest # noqa
140+
141+
return pytest.mark.needs_cvcuda(test_func)
142+
143+
137144
def needs_mps(test_func):
138145
import pytest # noqa
139146

test/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import torch
66

77
from common_utils import (
8+
_is_cvcuda_available,
89
CUDA_NOT_AVAILABLE_MSG,
10+
CVCUDA_NOT_AVAILABLE_MSG,
911
IN_FBCODE,
1012
IN_OSS_CI,
1113
IN_RE_WORKER,
@@ -17,6 +19,7 @@
1719
def pytest_configure(config):
1820
# register an additional marker (see pytest_collection_modifyitems)
1921
config.addinivalue_line("markers", "needs_cuda: mark for tests that rely on a CUDA device")
22+
config.addinivalue_line("markers", "needs_cvcuda: mark for tests that rely on CV-CUDA")
2023
config.addinivalue_line("markers", "needs_mps: mark for tests that rely on a MPS device")
2124
config.addinivalue_line("markers", "dont_collect: mark for tests that should not be collected")
2225
config.addinivalue_line("markers", "opcheck_only_one: only opcheck one parametrization")
@@ -41,6 +44,9 @@ def pytest_collection_modifyitems(items):
4144
# @pytest.mark.parametrize('device', cpu_and_cuda())
4245
# the "instances" of the tests where device == 'cuda' will have the 'needs_cuda' mark,
4346
# and the ones with device == 'cpu' won't have the mark.
47+
needs_cvcuda = item.get_closest_marker("needs_cvcuda") is not None
48+
if needs_cvcuda:
49+
item.add_marker(pytest.mark.needs_cuda)
4450
needs_cuda = item.get_closest_marker("needs_cuda") is not None
4551
needs_mps = item.get_closest_marker("needs_mps") is not None
4652

@@ -52,6 +58,9 @@ def pytest_collection_modifyitems(items):
5258
if needs_mps and not torch.backends.mps.is_available():
5359
item.add_marker(pytest.mark.skip(reason=MPS_NOT_AVAILABLE_MSG))
5460

61+
if needs_cvcuda and not _is_cvcuda_available():
62+
item.add_marker(pytest.mark.skip(reason=CVCUDA_NOT_AVAILABLE_MSG))
63+
5564
if IN_FBCODE:
5665
# fbcode doesn't like skipping tests, so instead we just don't collect the test
5766
# so that they don't even "exist", hence the continue statements.

test/test_transforms_v2.py

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
make_video,
3838
make_video_tensor,
3939
needs_cuda,
40+
needs_cvcuda,
4041
set_rng_seed,
4142
)
4243

@@ -52,17 +53,8 @@
5253
from torchvision.transforms.v2 import functional as F
5354
from torchvision.transforms.v2._utils import check_type, is_pure_tensor
5455
from torchvision.transforms.v2.functional._geometry import _get_perspective_coeffs, _parallelogram_to_bounding_boxes
55-
from torchvision.transforms.v2.functional._utils import (
56-
_get_kernel,
57-
_import_cvcuda,
58-
_is_cvcuda_available,
59-
_register_kernel_internal,
60-
)
61-
56+
from torchvision.transforms.v2.functional._utils import _get_kernel, _import_cvcuda, _register_kernel_internal
6257

63-
CVCUDA_AVAILABLE = _is_cvcuda_available()
64-
if CVCUDA_AVAILABLE:
65-
cvcuda = _import_cvcuda()
6658

6759
# turns all warnings into errors for this module
6860
pytestmark = [pytest.mark.filterwarnings("error")]
@@ -1242,7 +1234,7 @@ def test_kernel_video(self):
12421234
make_image,
12431235
pytest.param(
12441236
make_image_cvcuda,
1245-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1237+
marks=pytest.mark.needs_cvcuda,
12461238
),
12471239
make_bounding_boxes,
12481240
make_segmentation_mask,
@@ -1262,7 +1254,7 @@ def test_functional(self, make_input):
12621254
pytest.param(
12631255
F._geometry._horizontal_flip_image_cvcuda,
12641256
None,
1265-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1257+
marks=pytest.mark.needs_cvcuda,
12661258
),
12671259
(F.horizontal_flip_bounding_boxes, tv_tensors.BoundingBoxes),
12681260
(F.horizontal_flip_mask, tv_tensors.Mask),
@@ -1283,7 +1275,7 @@ def test_functional_signature(self, kernel, input_type):
12831275
make_image,
12841276
pytest.param(
12851277
make_image_cvcuda,
1286-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1278+
marks=pytest.mark.needs_cvcuda,
12871279
),
12881280
make_bounding_boxes,
12891281
make_segmentation_mask,
@@ -1304,7 +1296,7 @@ def test_transform(self, make_input, device):
13041296
make_image,
13051297
pytest.param(
13061298
make_image_cvcuda,
1307-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1299+
marks=pytest.mark.needs_cvcuda,
13081300
),
13091301
],
13101302
)
@@ -1372,7 +1364,7 @@ def test_keypoints_correctness(self, fn):
13721364
make_image,
13731365
pytest.param(
13741366
make_image_cvcuda,
1375-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1367+
marks=pytest.mark.needs_cvcuda,
13761368
),
13771369
make_bounding_boxes,
13781370
make_segmentation_mask,
@@ -1884,7 +1876,7 @@ def test_kernel_video(self):
18841876
make_image,
18851877
pytest.param(
18861878
make_image_cvcuda,
1887-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1879+
marks=pytest.mark.needs_cvcuda,
18881880
),
18891881
make_bounding_boxes,
18901882
make_segmentation_mask,
@@ -1904,7 +1896,7 @@ def test_functional(self, make_input):
19041896
pytest.param(
19051897
F._geometry._vertical_flip_image_cvcuda,
19061898
None,
1907-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1899+
marks=pytest.mark.needs_cvcuda,
19081900
),
19091901
(F.vertical_flip_bounding_boxes, tv_tensors.BoundingBoxes),
19101902
(F.vertical_flip_mask, tv_tensors.Mask),
@@ -1925,7 +1917,7 @@ def test_functional_signature(self, kernel, input_type):
19251917
make_image,
19261918
pytest.param(
19271919
make_image_cvcuda,
1928-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1920+
marks=pytest.mark.needs_cvcuda,
19291921
),
19301922
make_bounding_boxes,
19311923
make_segmentation_mask,
@@ -1944,7 +1936,7 @@ def test_transform(self, make_input, device):
19441936
make_image,
19451937
pytest.param(
19461938
make_image_cvcuda,
1947-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
1939+
marks=pytest.mark.needs_cvcuda,
19481940
),
19491941
],
19501942
)
@@ -2008,7 +2000,7 @@ def test_keypoints_correctness(self, fn):
20082000
make_image,
20092001
pytest.param(
20102002
make_image_cvcuda,
2011-
marks=pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="CVCUDA is not available"),
2003+
marks=pytest.mark.needs_cvcuda,
20122004
),
20132005
make_bounding_boxes,
20142006
make_segmentation_mask,
@@ -6794,8 +6786,7 @@ def test_functional_error(self):
67946786
F.pil_to_tensor(object())
67956787

67966788

6797-
@pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
6798-
@needs_cuda
6789+
@needs_cvcuda
67996790
class TestToCVCUDATensor:
68006791
@pytest.mark.parametrize("image_type", (torch.Tensor, tv_tensors.Image))
68016792
@pytest.mark.parametrize("dtype", [torch.uint8, torch.uint16, torch.float32, torch.float64])
@@ -6813,7 +6804,7 @@ def test_functional_and_transform(self, image_type, dtype, device, color_space,
68136804
assert is_pure_tensor(image)
68146805
output = fn(image)
68156806

6816-
assert isinstance(output, cvcuda.Tensor)
6807+
assert isinstance(output, _import_cvcuda().Tensor)
68176808
assert F.get_size(output) == F.get_size(image)
68186809
assert output is not None
68196810

@@ -6856,9 +6847,8 @@ def test_round_trip(self, dtype, device, color_space, batch_size):
68566847
assert result_tensor.shape[0] == batch_size
68576848

68586849

6859-
@pytest.mark.skipif(not CVCUDA_AVAILABLE, reason="test requires CVCUDA")
6860-
@needs_cuda
6861-
class TestCVDUDAToTensor:
6850+
@needs_cvcuda
6851+
class TestCVCUDAToTensor:
68626852
@pytest.mark.parametrize("dtype", [torch.uint8, torch.uint16, torch.float32, torch.float64])
68636853
@pytest.mark.parametrize("device", cpu_and_cuda())
68646854
@pytest.mark.parametrize("color_space", ["RGB", "GRAY"])

0 commit comments

Comments
 (0)