|
| 1 | +This file is automatically generated by assertExpectedJournal calls in test_random.py. |
| 2 | +Update expected outputs by running tests with the EXPECTTEST_ACCEPT=1 environment variable set. |
| 3 | + |
| 4 | +--- assertExpectedJournal(TestRandom.test_hl_rand_1d) |
| 5 | +from __future__ import annotations |
| 6 | + |
| 7 | +import torch |
| 8 | +import triton |
| 9 | +import triton.language as tl |
| 10 | +from helion.runtime import default_launcher as _default_launcher |
| 11 | + |
| 12 | +@triton.jit |
| 13 | +def _helion_rand_kernel_tiled_1d(output, output_stride_0, m, seed, _BLOCK_SIZE_0: tl.constexpr): |
| 14 | + pid_0 = tl.program_id(0) |
| 15 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 16 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 17 | + mask_0 = indices_0 < m |
| 18 | + rand = tl.rand(seed, indices_0) |
| 19 | + tl.store(output + indices_0 * output_stride_0, rand, mask_0) |
| 20 | + |
| 21 | +def rand_kernel_tiled_1d(x: torch.Tensor, seed: int, *, _launcher=_default_launcher): |
| 22 | + output = torch.zeros_like(x) |
| 23 | + m, = x.shape |
| 24 | + _BLOCK_SIZE_0 = 128 |
| 25 | + _launcher(_helion_rand_kernel_tiled_1d, (triton.cdiv(m, _BLOCK_SIZE_0),), output, output.stride(0), m, seed, _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 26 | + return output |
| 27 | + |
| 28 | +--- assertExpectedJournal(TestRandom.test_hl_rand_2d) |
| 29 | +from __future__ import annotations |
| 30 | + |
| 31 | +import torch |
| 32 | +import triton |
| 33 | +import triton.language as tl |
| 34 | +from helion.runtime import default_launcher as _default_launcher |
| 35 | + |
| 36 | +@triton.jit |
| 37 | +def _helion_rand_kernel_tiled_2d(output, output_stride_0, output_stride_1, m, n, seed, _BLOCK_SIZE_0: tl.constexpr, _BLOCK_SIZE_1: tl.constexpr): |
| 38 | + num_blocks_0 = tl.cdiv(m, _BLOCK_SIZE_0) |
| 39 | + pid_0 = tl.program_id(0) % num_blocks_0 |
| 40 | + pid_1 = tl.program_id(0) // num_blocks_0 |
| 41 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 42 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 43 | + mask_0 = indices_0 < m |
| 44 | + offset_1 = pid_1 * _BLOCK_SIZE_1 |
| 45 | + indices_1 = (offset_1 + tl.arange(0, _BLOCK_SIZE_1)).to(tl.int32) |
| 46 | + mask_1 = indices_1 < n |
| 47 | + rand = tl.rand(seed, indices_0[:, None] * n + indices_1[None, :]) |
| 48 | + tl.store(output + (indices_0[:, None] * output_stride_0 + indices_1[None, :] * output_stride_1), rand, mask_0[:, None] & mask_1[None, :]) |
| 49 | + |
| 50 | +def rand_kernel_tiled_2d(x: torch.Tensor, seed: int, *, _launcher=_default_launcher): |
| 51 | + output = torch.zeros_like(x) |
| 52 | + m, n = x.shape |
| 53 | + _BLOCK_SIZE_0 = 32 |
| 54 | + _BLOCK_SIZE_1 = 32 |
| 55 | + _launcher(_helion_rand_kernel_tiled_2d, (triton.cdiv(m, _BLOCK_SIZE_0) * triton.cdiv(n, _BLOCK_SIZE_1),), output, output.stride(0), output.stride(1), m, n, seed, _BLOCK_SIZE_0, _BLOCK_SIZE_1, num_warps=4, num_stages=3) |
| 56 | + return output |
| 57 | + |
| 58 | +--- assertExpectedJournal(TestRandom.test_hl_rand_3d) |
| 59 | +from __future__ import annotations |
| 60 | + |
| 61 | +import torch |
| 62 | +import triton |
| 63 | +import triton.language as tl |
| 64 | +from helion.runtime import default_launcher as _default_launcher |
| 65 | + |
| 66 | +@triton.jit |
| 67 | +def _helion_rand_kernel_tiled_3d(output, output_stride_0, output_stride_1, output_stride_2, b, m, n, seed, _BLOCK_SIZE_0: tl.constexpr, _BLOCK_SIZE_1: tl.constexpr, _BLOCK_SIZE_2: tl.constexpr): |
| 68 | + num_blocks_0 = tl.cdiv(b, _BLOCK_SIZE_0) |
| 69 | + num_blocks_1 = tl.cdiv(m, _BLOCK_SIZE_1) |
| 70 | + pid_0 = tl.program_id(0) % num_blocks_0 |
| 71 | + pid_1 = tl.program_id(0) // num_blocks_0 % num_blocks_1 |
| 72 | + pid_2 = tl.program_id(0) // (num_blocks_0 * num_blocks_1) |
| 73 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 74 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 75 | + mask_0 = indices_0 < b |
| 76 | + offset_1 = pid_1 * _BLOCK_SIZE_1 |
| 77 | + indices_1 = (offset_1 + tl.arange(0, _BLOCK_SIZE_1)).to(tl.int32) |
| 78 | + mask_1 = indices_1 < m |
| 79 | + offset_2 = pid_2 * _BLOCK_SIZE_2 |
| 80 | + indices_2 = (offset_2 + tl.arange(0, _BLOCK_SIZE_2)).to(tl.int32) |
| 81 | + mask_2 = indices_2 < n |
| 82 | + rand = tl.rand(seed, indices_0[:, None, None] * m * n + indices_1[None, :, None] * n + indices_2[None, None, :]) |
| 83 | + tl.store(output + (indices_0[:, None, None] * output_stride_0 + indices_1[None, :, None] * output_stride_1 + indices_2[None, None, :] * output_stride_2), rand, mask_0[:, None, None] & mask_1[None, :, None] & mask_2[None, None, :]) |
| 84 | + |
| 85 | +def rand_kernel_tiled_3d(x: torch.Tensor, seed: int, *, _launcher=_default_launcher): |
| 86 | + output = torch.zeros_like(x) |
| 87 | + b, m, n = x.shape |
| 88 | + _BLOCK_SIZE_0 = 16 |
| 89 | + _BLOCK_SIZE_1 = 16 |
| 90 | + _BLOCK_SIZE_2 = 16 |
| 91 | + _launcher(_helion_rand_kernel_tiled_3d, (triton.cdiv(b, _BLOCK_SIZE_0) * triton.cdiv(m, _BLOCK_SIZE_1) * triton.cdiv(n, _BLOCK_SIZE_2),), output, output.stride(0), output.stride(1), output.stride(2), b, m, n, seed, _BLOCK_SIZE_0, _BLOCK_SIZE_1, _BLOCK_SIZE_2, num_warps=4, num_stages=3) |
| 92 | + return output |
| 93 | + |
| 94 | +--- assertExpectedJournal(TestRandom.test_hl_rand_non_tiled_dimensions) |
| 95 | +from __future__ import annotations |
| 96 | + |
| 97 | +import torch |
| 98 | +import triton |
| 99 | +import triton.language as tl |
| 100 | +from helion.runtime import default_launcher as _default_launcher |
| 101 | + |
| 102 | +@triton.jit |
| 103 | +def _helion_rand_kernel_partial_tile(output, output_stride_0, output_stride_1, output_stride_2, m, n, seed, _BLOCK_SIZE_0: tl.constexpr, _BLOCK_SIZE_1: tl.constexpr, _RDIM_SIZE_2: tl.constexpr): |
| 104 | + num_blocks_0 = tl.cdiv(m, _BLOCK_SIZE_0) |
| 105 | + pid_0 = tl.program_id(0) % num_blocks_0 |
| 106 | + pid_1 = tl.program_id(0) // num_blocks_0 |
| 107 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 108 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 109 | + mask_0 = indices_0 < m |
| 110 | + offset_1 = pid_1 * _BLOCK_SIZE_1 |
| 111 | + indices_1 = (offset_1 + tl.arange(0, _BLOCK_SIZE_1)).to(tl.int32) |
| 112 | + mask_1 = indices_1 < n |
| 113 | + indices_2 = tl.arange(0, _RDIM_SIZE_2).to(tl.int32) |
| 114 | + rand = tl.rand(seed, indices_0[:, None, None] * n * _RDIM_SIZE_2 + indices_1[None, :, None] * _RDIM_SIZE_2 + tl.arange(0, _RDIM_SIZE_2)[None, None, :]) |
| 115 | + tl.store(output + (indices_0[:, None, None] * output_stride_0 + indices_1[None, :, None] * output_stride_1 + indices_2[None, None, :] * output_stride_2), rand, mask_0[:, None, None] & mask_1[None, :, None]) |
| 116 | + |
| 117 | +def rand_kernel_partial_tile(x: torch.Tensor, seed: int, *, _launcher=_default_launcher): |
| 118 | + output = torch.zeros_like(x) |
| 119 | + m, n, k = x.shape |
| 120 | + _BLOCK_SIZE_0 = 32 |
| 121 | + _BLOCK_SIZE_1 = 32 |
| 122 | + _RDIM_SIZE_2 = 8 |
| 123 | + _launcher(_helion_rand_kernel_partial_tile, (triton.cdiv(m, _BLOCK_SIZE_0) * triton.cdiv(n, _BLOCK_SIZE_1),), output, output.stride(0), output.stride(1), output.stride(2), m, n, seed, _BLOCK_SIZE_0, _BLOCK_SIZE_1, _RDIM_SIZE_2, num_warps=4, num_stages=3) |
| 124 | + return output |
0 commit comments