Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 12 additions & 33 deletions cuda_core/tests/test_tensor_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
_coerce_tensor_map_descriptor_options,
)
from cuda.core._utils.cuda_utils import CUDAError
from cuda.core._utils.version import driver_version
from cuda.core._utils.version import BUILD_CUDA_MAJOR, driver_version
from cuda.core.utils import StridedMemoryView


Expand Down Expand Up @@ -713,6 +713,11 @@ def test_from_im2col_5d(self, dev, skip_if_no_tma):
assert desc is not None


# With no interleave, channels_per_pixel * element size must fit the swizzle span:
# 32 FLOAT32 channels fill the 128 bytes of the default SWIZZLE_128B.
_IM2COL_WIDE_CHANNELS = 32


class TestTensorMapIm2colWide:
"""Test im2col-wide TMA descriptor creation (compute capability 10.0+)."""

Expand All @@ -722,32 +727,9 @@ def skip_if_no_im2col_wide(self, dev):
if cc.major < 10:
pytest.skip("Device does not support im2col-wide (requires compute capability 10.0+)")

# Some environments in CI exercise this test module with a cuda.core
# build that does not include im2col-wide symbols (CUDA < 13 build),
# or with driver/GPU combinations that reject im2col-wide descriptor
# encoding for otherwise valid inputs. Probe once per test invocation
# and skip only for those known unsupported cases.
buf = dev.allocate(1 * 32 * 64 * 4, stream=dev.default_stream)
tensor = _DeviceArray(buf, (1, 32, 64))
try:
TensorMapDescriptor._from_im2col_wide(
_as_view(tensor),
pixel_box_lower_corner_width=0,
pixel_box_upper_corner_width=4,
channels_per_pixel=64,
pixels_per_column=4,
data_type=TensorMapDataType.FLOAT32,
)
except RuntimeError as e:
if "requires a CUDA 13+ build" in str(e):
pytest.skip("Im2col-wide requires cuda.core built with CUDA 13+")
raise
except Exception as e:
if "CUDA_ERROR_INVALID_VALUE" in str(e):
pytest.skip("Im2col-wide unsupported on this driver/GPU combination")
raise
if BUILD_CUDA_MAJOR < 13:
pytest.skip("Im2col-wide requires cuda.core built with CUDA 13+")

# This test is not currently run in any CI job
def test_from_im2col_wide_3d(self, dev, skip_if_no_im2col_wide):
# 3D tensor: batch=1, width=32, channels=64
buf = dev.allocate(1 * 32 * 64 * 4, stream=dev.default_stream)
Expand All @@ -756,13 +738,12 @@ def test_from_im2col_wide_3d(self, dev, skip_if_no_im2col_wide):
_as_view(tensor),
pixel_box_lower_corner_width=0,
pixel_box_upper_corner_width=4,
channels_per_pixel=64,
channels_per_pixel=_IM2COL_WIDE_CHANNELS,
pixels_per_column=4,
data_type=TensorMapDataType.FLOAT32,
)
assert desc is not None

# This test is not currently run in any CI job
def test_from_im2col_wide_4d(self, dev, skip_if_no_im2col_wide):
# NHWC layout: N=1, H=8, W=8, C=64
# Wide mode only uses scalar W corners, even with higher rank
Expand All @@ -773,12 +754,11 @@ def test_from_im2col_wide_4d(self, dev, skip_if_no_im2col_wide):
_as_view(tensor),
pixel_box_lower_corner_width=0,
pixel_box_upper_corner_width=4,
channels_per_pixel=64,
channels_per_pixel=_IM2COL_WIDE_CHANNELS,
pixels_per_column=16,
)
assert desc is not None

# This test is not currently run in any CI job
def test_from_im2col_wide_5d(self, dev, skip_if_no_im2col_wide):
# NDHWC layout: N=1, D=4, H=8, W=8, C=64
# Max rank boundary — verifies all 5 dim/stride slots are filled
Expand All @@ -789,20 +769,19 @@ def test_from_im2col_wide_5d(self, dev, skip_if_no_im2col_wide):
_as_view(tensor),
pixel_box_lower_corner_width=0,
pixel_box_upper_corner_width=4,
channels_per_pixel=64,
channels_per_pixel=_IM2COL_WIDE_CHANNELS,
pixels_per_column=32,
)
assert desc is not None

# This test is not currently run in any CI job
def test_from_im2col_wide_rank_validation(self, dev, skip_if_no_im2col_wide):
buf = dev.allocate(1024 * 4, stream=dev.default_stream)
with pytest.raises(ValueError, match="Im2col-wide tensor rank must be between 3 and 5"):
TensorMapDescriptor._from_im2col_wide(
_as_view(buf),
pixel_box_lower_corner_width=0,
pixel_box_upper_corner_width=4,
channels_per_pixel=64,
channels_per_pixel=_IM2COL_WIDE_CHANNELS,
pixels_per_column=4,
data_type=TensorMapDataType.FLOAT32,
)
Expand Down
Loading