|
11 | 11 | from helion._testing import RefEagerTestBase
|
12 | 12 | from helion._testing import TestCase
|
13 | 13 | from helion._testing import code_and_output
|
| 14 | +from helion._testing import skipIfLowVRAM |
14 | 15 | from helion._testing import skipIfNormalMode
|
15 | 16 | from helion._testing import skipIfRefEager
|
16 | 17 | from helion._testing import skipIfRocm
|
@@ -241,6 +242,73 @@ def test_block_size_access(x: torch.Tensor) -> torch.Tensor:
|
241 | 242 | expected = torch.full_like(x, 1, dtype=torch.int32)
|
242 | 243 | torch.testing.assert_close(result, expected)
|
243 | 244 |
|
| 245 | + @skipIfLowVRAM("Test allocates ~15GB across multiple CUDA tensors") |
| 246 | + def test_int32_offset_out_of_range_error(self): |
| 247 | + repro_config = helion.Config( |
| 248 | + block_sizes=[32, 32], |
| 249 | + flatten_loops=[False], |
| 250 | + indexing="pointer", |
| 251 | + l2_groupings=[1], |
| 252 | + loop_orders=[[0, 1]], |
| 253 | + num_stages=3, |
| 254 | + num_warps=4, |
| 255 | + pid_type="flat", |
| 256 | + range_flattens=[None], |
| 257 | + range_multi_buffers=[None], |
| 258 | + range_num_stages=[], |
| 259 | + range_unroll_factors=[0], |
| 260 | + range_warp_specializes=[], |
| 261 | + ) |
| 262 | + |
| 263 | + def make_kernel(*, index_dtype: torch.dtype): |
| 264 | + kwargs = dict(config=repro_config, static_shapes=False) |
| 265 | + kwargs["index_dtype"] = index_dtype |
| 266 | + decorator = helion.kernel(**kwargs) |
| 267 | + |
| 268 | + @decorator |
| 269 | + def repro_bf16_add(x: torch.Tensor, y: torch.Tensor) -> torch.Tensor: |
| 270 | + x, y = torch.broadcast_tensors(x, y) |
| 271 | + out = torch.empty( |
| 272 | + x.shape, |
| 273 | + dtype=torch.promote_types(x.dtype, y.dtype), |
| 274 | + device=x.device, |
| 275 | + ) |
| 276 | + for tile in hl.tile(out.size()): |
| 277 | + out[tile] = x[tile] + y[tile] |
| 278 | + return out |
| 279 | + |
| 280 | + return repro_bf16_add |
| 281 | + |
| 282 | + def run_case(shape, *, index_dtype, expect_int64=False, expect_error=False): |
| 283 | + kernel = make_kernel(index_dtype=index_dtype) |
| 284 | + x = torch.randn(*shape, device=DEVICE, dtype=torch.bfloat16) |
| 285 | + y = torch.randn(*shape, device=DEVICE, dtype=torch.bfloat16) |
| 286 | + torch.cuda.synchronize() |
| 287 | + if expect_error: |
| 288 | + with self.assertRaisesRegex( |
| 289 | + helion.exc.IndexOffsetOutOfRangeForInt32, |
| 290 | + f"index_dtype is {index_dtype}", |
| 291 | + ): |
| 292 | + code_and_output(kernel, (x, y)) |
| 293 | + torch.cuda.synchronize() |
| 294 | + return |
| 295 | + |
| 296 | + code, out = code_and_output(kernel, (x, y)) |
| 297 | + torch.cuda.synchronize() |
| 298 | + checker = self.assertIn if expect_int64 else self.assertNotIn |
| 299 | + checker("tl.int64", code) |
| 300 | + torch.cuda.synchronize() |
| 301 | + ref_out = torch.add(x, y) |
| 302 | + torch.cuda.synchronize() |
| 303 | + torch.testing.assert_close(out, ref_out, rtol=1e-2, atol=1e-2) |
| 304 | + |
| 305 | + small_shape = (128, 128) |
| 306 | + large_shape = (51200, 51200) |
| 307 | + |
| 308 | + run_case(small_shape, index_dtype=torch.int32) |
| 309 | + run_case(large_shape, index_dtype=torch.int32, expect_error=True) |
| 310 | + run_case(large_shape, index_dtype=torch.int64, expect_int64=True) |
| 311 | + |
244 | 312 | def test_assign_int(self):
|
245 | 313 | @helion.kernel
|
246 | 314 | def fn(x: torch.Tensor) -> torch.Tensor:
|
|
0 commit comments