|
| 1 | +This file is automatically generated by assertExpectedJournal calls in test_inline_asm_elementwise.py. |
| 2 | +Update expected outputs by running tests with the EXPECTTEST_ACCEPT=1 environment variable set. |
| 3 | + |
| 4 | +--- assertExpectedJournal(TestInlineAsmElementwise.test_inline_asm_basic_compilation) |
| 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 _kernel_basic_kernel(x, result, x_size_0, result_stride_0, x_stride_0, _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 < x_size_0 |
| 18 | + load = tl.load(x + indices_0 * x_stride_0, mask_0, other=0) |
| 19 | + result_val = tl.inline_asm_elementwise('mov.u32 $0, $1;', '=r,r', [load], tl.int32, True, 1) |
| 20 | + tl.store(result + indices_0 * result_stride_0, result_val, mask_0) |
| 21 | + |
| 22 | +def kernel_basic(x: torch.Tensor, *, _launcher=_default_launcher): |
| 23 | + result = torch.empty_like(x) |
| 24 | + _BLOCK_SIZE_0 = 16 |
| 25 | + _launcher(_kernel_basic_kernel, (triton.cdiv(x.size(0), _BLOCK_SIZE_0),), x, result, x.size(0), result.stride(0), x.stride(0), _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 26 | + return result |
| 27 | + |
| 28 | +--- assertExpectedJournal(TestInlineAsmElementwise.test_inline_asm_empty_args) |
| 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 _kernel_empty_args_kernel(result, x_size_0, result_stride_0, _BLOCK_SIZE_0: tl.constexpr): |
| 38 | + pid_0 = tl.program_id(0) |
| 39 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 40 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 41 | + mask_0 = indices_0 < x_size_0 |
| 42 | + result_val = tl.inline_asm_elementwise('mov.u32 $0, 42;', '=r', [], tl.int32, True, 1) |
| 43 | + tl.store(result + indices_0 * result_stride_0, result_val, mask_0) |
| 44 | + |
| 45 | +def kernel_empty_args(x: torch.Tensor, *, _launcher=_default_launcher): |
| 46 | + result = torch.empty_like(x) |
| 47 | + _BLOCK_SIZE_0 = 16 |
| 48 | + _launcher(_kernel_empty_args_kernel, (triton.cdiv(x.size(0), _BLOCK_SIZE_0),), result, x.size(0), result.stride(0), _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 49 | + return result |
| 50 | + |
| 51 | +--- assertExpectedJournal(TestInlineAsmElementwise.test_inline_asm_multiple_outputs) |
| 52 | +from __future__ import annotations |
| 53 | + |
| 54 | +import torch |
| 55 | +import triton |
| 56 | +import triton.language as tl |
| 57 | +from helion.runtime import default_launcher as _default_launcher |
| 58 | + |
| 59 | +@triton.jit |
| 60 | +def _kernel_multiple_outputs_kernel(a, b, result_c, result_d, a_size_0, a_stride_0, b_stride_0, result_c_stride_0, result_d_stride_0, _BLOCK_SIZE_0: tl.constexpr): |
| 61 | + pid_0 = tl.program_id(0) |
| 62 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 63 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 64 | + mask_0 = indices_0 < a_size_0 |
| 65 | + val_a = tl.load(a + indices_0 * a_stride_0, mask_0, other=0) |
| 66 | + val_b = tl.load(b + indices_0 * b_stride_0, mask_0, other=0) |
| 67 | + c_val = tl.inline_asm_elementwise('\n sub.u32 $0, $2, $3;\n sub.u32 $1, $3, $2;\n ', '=r,=r,r,r', [val_a, val_b], (tl.int32, tl.int32), True, 1)[0] |
| 68 | + d_val = tl.inline_asm_elementwise('\n sub.u32 $0, $2, $3;\n sub.u32 $1, $3, $2;\n ', '=r,=r,r,r', [val_a, val_b], (tl.int32, tl.int32), True, 1)[1] |
| 69 | + tl.store(result_c + indices_0 * result_c_stride_0, c_val, mask_0) |
| 70 | + tl.store(result_d + indices_0 * result_d_stride_0, d_val, mask_0) |
| 71 | + |
| 72 | +def kernel_multiple_outputs(a: torch.Tensor, b: torch.Tensor, *, _launcher=_default_launcher): |
| 73 | + result_c = torch.empty_like(a) |
| 74 | + result_d = torch.empty_like(a) |
| 75 | + _BLOCK_SIZE_0 = 64 |
| 76 | + _launcher(_kernel_multiple_outputs_kernel, (triton.cdiv(a.size(0), _BLOCK_SIZE_0),), a, b, result_c, result_d, a.size(0), a.stride(0), b.stride(0), result_c.stride(0), result_d.stride(0), _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 77 | + return (result_c, result_d) |
| 78 | + |
| 79 | +--- assertExpectedJournal(TestInlineAsmElementwise.test_inline_asm_packed) |
| 80 | +from __future__ import annotations |
| 81 | + |
| 82 | +import torch |
| 83 | +import triton |
| 84 | +import triton.language as tl |
| 85 | +from helion.runtime import default_launcher as _default_launcher |
| 86 | + |
| 87 | +@triton.jit |
| 88 | +def _kernel_packed_asm_kernel(x, result, x_size_0, result_stride_0, x_stride_0, _BLOCK_SIZE_0: tl.constexpr): |
| 89 | + pid_0 = tl.program_id(0) |
| 90 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 91 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 92 | + mask_0 = indices_0 < x_size_0 |
| 93 | + val = tl.load(x + indices_0 * x_stride_0, mask_0, other=0) |
| 94 | + result_val = tl.inline_asm_elementwise('and.b32 $0, $1, 0x1F1F1F1F; shl.b32 $0, $0, 3;', '=r,r', [val], tl.int8, True, 4) |
| 95 | + v_0 = result_val.to(tl.int8).to(tl.uint8) |
| 96 | + tl.store(result + indices_0 * result_stride_0, v_0, mask_0) |
| 97 | + |
| 98 | +def kernel_packed_asm(x: torch.Tensor, *, _launcher=_default_launcher): |
| 99 | + result = torch.empty_like(x) |
| 100 | + _BLOCK_SIZE_0 = 512 |
| 101 | + _launcher(_kernel_packed_asm_kernel, (triton.cdiv(x.size(0), _BLOCK_SIZE_0),), x, result, x.size(0), result.stride(0), x.stride(0), _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 102 | + return result |
| 103 | + |
| 104 | +--- assertExpectedJournal(TestInlineAsmElementwise.test_inline_asm_shift_operation) |
| 105 | +from __future__ import annotations |
| 106 | + |
| 107 | +import torch |
| 108 | +import triton |
| 109 | +import triton.language as tl |
| 110 | +from helion.runtime import default_launcher as _default_launcher |
| 111 | + |
| 112 | +@triton.jit |
| 113 | +def _kernel_shift_asm_kernel(x, y, result, x_size_0, result_stride_0, x_stride_0, y_stride_0, n, _BLOCK_SIZE_0: tl.constexpr): |
| 114 | + pid_0 = tl.program_id(0) |
| 115 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 116 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 117 | + mask_0 = indices_0 < x_size_0 |
| 118 | + val_x = tl.load(x + indices_0 * x_stride_0, mask_0, other=0) |
| 119 | + val_y = tl.load(y + indices_0 * y_stride_0, mask_0, other=0) |
| 120 | + shift_val = tl.full([_BLOCK_SIZE_0], n, tl.int32) |
| 121 | + result_val = tl.inline_asm_elementwise('shf.l.wrap.b32 $0, $1, $2, $3;', '=r,r,r,r', [val_x, val_y, shift_val], tl.int32, True, 1) |
| 122 | + tl.store(result + indices_0 * result_stride_0, result_val, mask_0) |
| 123 | + |
| 124 | +def kernel_shift_asm(x: torch.Tensor, y: torch.Tensor, n: int, *, _launcher=_default_launcher): |
| 125 | + result = torch.empty_like(x) |
| 126 | + _BLOCK_SIZE_0 = 128 |
| 127 | + _launcher(_kernel_shift_asm_kernel, (triton.cdiv(x.size(0), _BLOCK_SIZE_0),), x, y, result, x.size(0), result.stride(0), x.stride(0), y.stride(0), n, _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 128 | + return result |
| 129 | + |
| 130 | +--- assertExpectedJournal(TestInlineAsmElementwise.test_inline_asm_simple) |
| 131 | +from __future__ import annotations |
| 132 | + |
| 133 | +import torch |
| 134 | +import triton |
| 135 | +import triton.language as tl |
| 136 | +from helion.runtime import default_launcher as _default_launcher |
| 137 | + |
| 138 | +@triton.jit |
| 139 | +def _kernel_simple_asm_kernel(x, result, x_size_0, result_stride_0, x_stride_0, _BLOCK_SIZE_0: tl.constexpr): |
| 140 | + pid_0 = tl.program_id(0) |
| 141 | + offset_0 = pid_0 * _BLOCK_SIZE_0 |
| 142 | + indices_0 = (offset_0 + tl.arange(0, _BLOCK_SIZE_0)).to(tl.int32) |
| 143 | + mask_0 = indices_0 < x_size_0 |
| 144 | + val = tl.load(x + indices_0 * x_stride_0, mask_0, other=0) |
| 145 | + result_val = tl.inline_asm_elementwise('mov.u32 $0, $1;', '=r,r', [val], tl.int32, True, 1) |
| 146 | + tl.store(result + indices_0 * result_stride_0, result_val, mask_0) |
| 147 | + |
| 148 | +def kernel_simple_asm(x: torch.Tensor, *, _launcher=_default_launcher): |
| 149 | + result = torch.empty_like(x) |
| 150 | + _BLOCK_SIZE_0 = 16 |
| 151 | + _launcher(_kernel_simple_asm_kernel, (triton.cdiv(x.size(0), _BLOCK_SIZE_0),), x, result, x.size(0), result.stride(0), x.stride(0), _BLOCK_SIZE_0, num_warps=4, num_stages=3) |
| 152 | + return result |
0 commit comments