Skip to content

Commit 2cd6dc4

Browse files
[lang] Remove power-of-two constraint on vector types
Some NVVM intrinsics take vectors with non power of 2 size, so I guess we ought to remove this constraint. I don't see a big downside--the user might want to parameterize a kernel over many vector types and just get as many wide loads/stores as they can, even if it's not perfectly divisible by the widest possible vector. Signed-off-by: Asher Mancinelli <amancinelli@nvidia.com>
1 parent 0421031 commit 2cd6dc4

2 files changed

Lines changed: 2 additions & 14 deletions

File tree

experimental/cuda-lang/src/cuda/lang/_ir/type.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,10 @@
3131
from cuda.lang._exception import TileTypeError
3232

3333

34-
def _is_power_of_2(value: int) -> bool:
35-
assert isinstance(value, int)
36-
return value > 0 and value & (value - 1) == 0
37-
38-
3934
def is_vector_ty(ty: Type) -> bool:
4035
return (
4136
isinstance(ty, TileTy)
4237
and len(ty.shape) == 1
43-
and _is_power_of_2(ty.shape[0])
4438
)
4539

4640

@@ -49,10 +43,6 @@ def make_vector_ty(dtype: DType, length: int) -> TileTy:
4943
raise TileTypeError(
5044
f"Expected vector length to be an int, got {type(length).__name__}"
5145
)
52-
if not _is_power_of_2(length):
53-
raise TileTypeError(
54-
f"Expected vector length to be a positive power of two, got {length}"
55-
)
5646
return TileTy(dtype, (length,))
5747

5848

experimental/cuda-lang/test/test_vectors.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
import cuda.lang as cl
1111
from cuda.lang._datatype import to_torch_dtype
12-
from cuda.lang._exception import TileTypeError
1312
from cuda.tile import static_iter
1413

1514

@@ -295,11 +294,10 @@ def kernel(out):
295294
torch.testing.assert_close(out.cpu(), expected)
296295

297296

298-
def test_pointer_vector_count_must_be_power_of_two():
297+
def test_pointer_vector_count_can_be_non_power_of_two():
299298
@cl.kernel
300299
def kernel(out):
301300
out.get_base_pointer().load(count=3, alignment=4)
302301

303302
out = torch.zeros(3, dtype=torch.int32).cuda()
304-
with pytest.raises(TileTypeError, match="positive power of two"):
305-
cl.launch(torch.cuda.current_stream(), (1,), (1,), kernel, (out,))
303+
cl.launch(torch.cuda.current_stream(), (1,), (1,), kernel, (out,))

0 commit comments

Comments
 (0)