[ { "uuid": "6d32b21d-530f-4d1d-a2b2-bb08a0c056cc", "file_name": "triton_matric_matmul.py", "repo_name": "elphinkuo/fast_matrix_multiplication", "file_path": "dot_product/on_gpu/Triton/triton_matric_matmul.py", "commit_hash": "4e875a17e95b7ccf9af102d2c0f8cc31ed9a29f3", "starcount": 0, "input": "@triton.jit\ndef _matmul_kernel(A, B, C, M, N, K, **meta):\n TILE_M = meta['BLOCK_M']\n TILE_N = meta['BLOCK_N']\n TILE_K = 128\n m = tl.program_id(0) * TILE_M + tl.arange(0, TILE_M)\n n = tl.program_id(1) * TILE_N + tl.arange(0, TILE_N)\n acc = tl.zeros((TILE_M, TILE_N), dtype=tl.float32)\n for k in range(0, K, TILE_K):\n a = tl.load(A + m[:, None] * K + k, mask=[m[:, None] < M, None],\n other=0.0)\n b = tl.load(B + k * N + n, mask=[None, n < N], other=0.0)\n acc += tl.dot(a, b)\n tl.store(C + m[:, None] * N + n, acc, mask=[m[:, None] < M, n < N])\n", "category": { "Functionality": [ "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/elphinkuo/fast_matrix_multiplication/blob/4e875a17e95b7ccf9af102d2c0f8cc31ed9a29f3/dot_product/on_gpu/Triton/triton_matric_matmul.py" }, { "uuid": "1325bcba-7d28-47b5-b18b-31e0f79878f5", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_2_softmax_kernel(input_ptr, output_ptr, offsets_row_ptr,\n offsets_col_ptr, offsets_overall_ptr, input_stride, output_stride,\n transpose, max_seq_len_row, max_seq_len_col, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n input shape is [sum_B(Ni * Hi)]\n output shape is [sum_B(Ni * Hi)]\n Padded version = [B, N, H]\n Calculate softmax alone N dim\n Each kernel calulates softmax for 1 sample and 1 head\n offsets_row.size == offsets_col.size == offsets_overall.size\n \"\"\"\n pid_batch = tl.program_id(0)\n pid_head = tl.program_id(1)\n begin = tl.load(offsets_overall_ptr + pid_batch)\n if transpose:\n N = tl.load(offsets_row_ptr + pid_batch + 1) - tl.load(\n offsets_row_ptr + pid_batch)\n H = tl.load(offsets_col_ptr + pid_batch + 1) - tl.load(\n offsets_col_ptr + pid_batch)\n stride_n = H\n stride_h = H // H\n H = tl.minimum(max_seq_len_col, H)\n N = tl.minimum(max_seq_len_row, N)\n else:\n N = tl.load(offsets_col_ptr + pid_batch + 1) - tl.load(\n offsets_col_ptr + pid_batch)\n H = tl.load(offsets_row_ptr + pid_batch + 1) - tl.load(\n offsets_row_ptr + pid_batch)\n stride_h = N\n stride_n = N // N\n H = tl.minimum(max_seq_len_row, H)\n N = tl.minimum(max_seq_len_col, N)\n if pid_head >= H:\n return\n if H == 0 or N == 0:\n return\n start_ptr = input_ptr + begin * input_stride\n offsets = tl.arange(0, BLOCK_SIZE)\n input_ptrs = (start_ptr + offsets * input_stride * stride_n + pid_head *\n input_stride * stride_h)\n row = tl.load(input_ptrs, mask=offsets < N, other=-float('inf'))\n row_mins_max = row - tl.max(row, axis=0)\n numerator = tl.exp(row_mins_max)\n denominator = tl.sum(numerator, axis=0)\n softmax_output = numerator / denominator\n output_start_ptr = output_ptr + begin * output_stride\n output_ptrs = (output_start_ptr + offsets * output_stride * stride_n + \n pid_head * output_stride * stride_h)\n tl.store(output_ptrs, softmax_output, mask=offsets < N)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "c5681889-cbdf-4c8c-b730-916ee6ccb0d9", "file_name": "triton_ops.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/triton_ops.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _MVUE24_approx_triton(dense_ptr, sparse_ptr, dense_row_stride,\n sparse_row_stride, dense_col_stride, sparse_col_stride, m, k, seed,\n BLOCK_SIZE: tl.constexpr, ARRAY_LAYOUT: tl.constexpr):\n if ARRAY_LAYOUT == 'row':\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1) * 4 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 4\n mask = col_idx < k\n elif ARRAY_LAYOUT == 'col':\n row_idx = tl.arange(0, BLOCK_SIZE) + tl.program_id(0) * BLOCK_SIZE\n col_idx = tl.program_id(1) * 4\n mask = row_idx < m\n dense_40 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 0) * dense_col_stride, mask=mask)\n dense_41 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 1) * dense_col_stride, mask=mask)\n dense_42 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 2) * dense_col_stride, mask=mask)\n dense_43 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 3) * dense_col_stride, mask=mask)\n if ARRAY_LAYOUT == 'row':\n seed0 = seed + (tl.program_id(0) + tl.program_id(1) * m) * 2\n seed1 = seed + (tl.program_id(0) + tl.program_id(1) * m) * 2 + 1\n else:\n seed0 = seed + (tl.program_id(0) * k // 16 + tl.program_id(1)) * 2\n seed1 = seed + (tl.program_id(0) * k // 16 + tl.program_id(1)) * 2 + 1\n random0 = tl.rand(seed0, tl.arange(0, BLOCK_SIZE), n_rounds=5)\n random1 = tl.rand(seed1, tl.arange(0, BLOCK_SIZE), n_rounds=5)\n dense_40, dense_41, dense_42, dense_43, m0, m1, m2, m3 = _MVUE24_approx(\n dense_40, dense_41, dense_42, dense_43, random0, random1)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 0) *\n sparse_col_stride, dense_40, mask=mask & m0)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 1) *\n sparse_col_stride, dense_41, mask=mask & m1)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 2) *\n sparse_col_stride, dense_42, mask=mask & m2)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 3) *\n sparse_col_stride, dense_43, mask=mask & m3)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32", "uint8" ], "Performance Objective": [ "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/triton_ops.py" }, { "uuid": "ae2cb3a3-be88-4b7a-bbba-b418ac601259", "file_name": "parallel_scan.py", "repo_name": "chengkai-liu/RecBLR", "file_path": "parallel_scan.py", "commit_hash": "66e520c26e28c05a5425ba2e81c9169b7e0176e2", "starcount": 0, "input": "@triton.jit\ndef unpack64(merged):\n tl.static_assert(merged.dtype == tl.uint64)\n b = (merged & 4294967295).to(tl.uint32).to(tl.float32, bitcast=True)\n a = (merged >> 32).to(tl.uint32).to(tl.float32, bitcast=True)\n return a, b\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengkai-liu/RecBLR/blob/66e520c26e28c05a5425ba2e81c9169b7e0176e2/parallel_scan.py" }, { "uuid": "f031d842-9ab5-40cf-b113-7fe0ef2ae51e", "file_name": "y_5.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_5.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef fifth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_9 = tl.load(sph_grad_ptr + output_row_offset + 9, mask=\n output_row_offset + 9 < output_numel)\n g_10 = tl.load(sph_grad_ptr + output_row_offset + 10, mask=\n output_row_offset + 10 < output_numel)\n CONST000 = 1.60565407233314\n CONST001 = 3.0\n CONST002 = 3.21130814466628\n CONST003 = 1.60565407233314\n CONST004 = 6.42261628933256\n CONST005 = 6.42261628933256\n CONST006 = 8.67152307844476\n CONST007 = 8.02827036166571\n CONST008 = 6.9372184627558\n CONST009 = 11.6340690431164\n CONST010 = 12.8452325786651\n CONST011 = 6.21867148191637\n CONST012 = 6.21867148191637\n CONST014 = 12.4373429638327\n CONST017 = 12.8452325786651\n CONST018 = 13.8744369255116\n CONST019 = 24.8746859276655\n CONST020 = 24.8746859276655\n CONST021 = 27.7488738510232\n CONST024 = 29.4321253055229\n CONST027 = 7.35803132638072\n CONST029 = 46.5362761724657\n CONST030 = 51.3809303146605\n CONST031 = 51.3809303146605\n CONST034 = 101.955872807799\n CONST036 = -8.67152307844475\n CONST037 = 3.4686092313779\n CONST038 = -88.2963759165686\n CONST039 = -83.2466215530696\n CONST040 = -69.8044142586986\n CONST041 = -50.9779364038993\n CONST042 = -50.9779364038993\n CONST043 = -46.5362761724657\n CONST044 = -44.1481879582843\n CONST045 = -41.6233107765348\n CONST046 = -38.5356977359954\n CONST047 = -38.5356977359954\n CONST048 = -33.166247903554\n CONST049 = -33.9852909359329\n CONST050 = 6.42261628933257\n CONST051 = -33.9852909359329\n CONST052 = -29.4321253055229\n CONST053 = -27.7488738510232\n CONST054 = -20.8116553882674\n CONST055 = -19.2678488679977\n CONST056 = -19.2678488679977\n CONST057 = -16.9926454679664\n CONST058 = -16.9926454679664\n CONST059 = -13.8744369255116\n CONST060 = -16.583123951777\n CONST061 = -8.49632273398321\n CONST062 = -6.9372184627558\n CONST063 = -5.20291384706685\n CONST064 = -3.4686092313779\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += g_0 * (CONST009 * VAR06 + CONST009 * VAR24 + CONST040 * VAR08 *\n VAR26) + g_1 * y * (CONST038 * VAR08 * z - CONST052 * VAR25) + g_10 * (\n CONST029 * VAR07 * z + CONST043 * VAR25 * x) + g_2 * (CONST001 *\n VAR08 * (CONST059 * VAR17 + CONST064 * VAR26) + CONST006 * VAR06 - \n CONST045 * VAR17 * VAR26 + CONST063 * VAR24) + g_3 * (CONST041 *\n VAR08 * y * z - CONST049 * VAR16 * z + CONST057 * VAR25 * y) + g_4 * (\n CONST000 * VAR24 + CONST001 * VAR08 * (CONST002 * VAR26 + CONST055 *\n VAR17) + CONST007 * VAR06 + CONST010 * VAR15 + CONST056 * VAR17 * VAR26\n ) + g_5 * (CONST048 * VAR16 * x + y * (CONST019 * VAR07 + CONST019 *\n VAR26 * x)) + g_6 * (CONST005 * VAR25 * x + z * (CONST004 * VAR07 +\n CONST046 * VAR17 * x)) + g_7 * (CONST049 * VAR16 * x - CONST051 *\n VAR07 * y) + g_8 * (CONST008 * VAR25 * x + z * (CONST039 * VAR17 *\n x - CONST054 * VAR07)) + g_9 * y * (CONST024 * VAR07 + CONST038 *\n VAR26 * x)\n g_y += g_1 * (CONST052 * VAR07 * z - CONST052 * VAR25 * x) + g_2 * (-\n CONST039 * VAR26 * x * y + CONST053 * VAR07 * y) + g_3 * (CONST058 *\n VAR07 * z + x * (CONST034 * VAR17 * z + CONST057 * VAR25)) + g_4 * (\n CONST047 * VAR07 * y + x * (CONST030 * VAR16 + CONST046 * VAR26 * y)\n ) + g_5 * (CONST001 * VAR17 * (CONST060 * VAR08 + CONST060 * VAR26) +\n CONST011 * VAR06 + CONST012 * VAR24 + CONST014 * VAR08 * VAR26 - \n CONST060 * VAR15) + g_6 * (CONST046 * VAR25 * y + z * (CONST031 *\n VAR16 + CONST046 * VAR08 * y)) + g_7 * (CONST001 * VAR17 * (\n CONST057 * VAR08 - CONST057 * VAR26) - CONST061 * VAR06 + CONST061 *\n VAR24) + g_8 * (CONST021 * VAR25 * y + CONST039 * VAR08 * y * z\n ) + g_9 * (CONST027 * VAR06 + CONST027 * VAR24 + CONST044 * VAR08 *\n VAR26)\n g_z += g_0 * (CONST029 * VAR25 * x + CONST043 * VAR07 * z) + g_1 * y * (\n -CONST038 * VAR26 * x + CONST052 * VAR07) + g_10 * (CONST009 *\n VAR06 + CONST009 * VAR24 + CONST040 * VAR08 * VAR26) + g_2 * (\n CONST062 * VAR07 * z + x * (-CONST039 * VAR17 * z + CONST054 * VAR25)\n ) + g_3 * (CONST058 * VAR07 * y + x * (CONST042 * VAR26 * y - \n CONST049 * VAR16)) + g_4 * (CONST005 * VAR07 * z + x * (CONST046 *\n VAR17 * z + CONST050 * VAR25)) + g_5 * (CONST048 * VAR16 * z + y *\n (CONST019 * VAR08 * z + CONST020 * VAR25)) + g_6 * (CONST001 *\n VAR26 * (CONST002 * VAR08 + CONST056 * VAR17) + CONST003 * VAR06 + \n CONST007 * VAR24 + CONST017 * VAR15 + CONST056 * VAR08 * VAR17\n ) + g_7 * (-CONST049 * VAR16 * z + CONST051 * VAR25 * y) + g_8 * (\n CONST001 * VAR26 * (CONST018 * VAR17 + CONST037 * VAR08) + CONST036 *\n VAR24 + CONST045 * VAR08 * VAR17 - CONST063 * VAR06) + g_9 * y * (\n CONST024 * VAR25 + CONST038 * VAR08 * z)\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_5.py" }, { "uuid": "e4b5235d-37a5-4b17-8c48-fa82e3aecf4f", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'UNROLL_FACTOR': uf}) for uf in [1,\n 2, 4, 8]], key=['POWER_OF_2_MAX_SEQ_LEN', 'QUERY_GROUP_SIZE',\n 'USE_PARTITIONING', 'BLOCK_SIZE', 'HEAD_SIZE', 'PARTITION_SIZE'])\n@triton.jit\ndef _paged_attn_wo_mma_kernel(exp_sums, max_logits, out, q, k_cache,\n v_cache, scale, block_tables, seq_lens, max_num_blocks_per_seq,\n alibi_slopes, stride_qm, stride_qn, stride_om, stride_on, stride_ok,\n stride_km, stride_kn, stride_kk, stride_exp_m, stride_exp_n, BLOCK_SIZE:\n tl.constexpr, HEAD_SIZE: tl.constexpr, QUERY_GROUP_SIZE: tl.constexpr,\n PARTITION_SIZE: tl.constexpr, POWER_OF_2_MAX_SEQ_LEN: tl.constexpr,\n USE_PARTITIONING: tl.constexpr, UNROLL_FACTOR: tl.constexpr):\n head_idx = tl.program_id(axis=0)\n kv_head_idx = head_idx // QUERY_GROUP_SIZE\n seq_idx = tl.program_id(axis=1)\n par_idx = tl.program_id(axis=2)\n seq_len = tl.load(seq_lens + seq_idx)\n if par_idx * PARTITION_SIZE >= seq_len:\n return\n num_context_blocks = tl.cdiv(seq_len, BLOCK_SIZE)\n if USE_PARTITIONING:\n num_blocks_per_par = PARTITION_SIZE // BLOCK_SIZE\n start_block_idx = par_idx * num_blocks_per_par\n end_block_idx = tl.minimum(start_block_idx + num_blocks_per_par,\n num_context_blocks)\n else:\n start_block_idx = 0\n end_block_idx = num_context_blocks\n if alibi_slopes is None:\n alibi_slope = 0.0\n else:\n alibi_slope = tl.load(alibi_slopes + head_idx)\n block_offs = tl.arange(0, BLOCK_SIZE)\n head_size_offs = tl.arange(0, HEAD_SIZE)\n q = tl.load(q + seq_idx * stride_qm + head_idx * stride_qn + head_size_offs\n )\n q = (q * scale).to(tl.float16)\n qkv = tl.zeros([BLOCK_SIZE, HEAD_SIZE], dtype=tl.float32)\n qk_max = float('-inf')\n exp_sum = 0.0\n fp16_0 = tl.zeros([1, 1], dtype=k_cache.dtype.element_ty)\n base_offs_kv = kv_head_idx * stride_kn + block_offs[:, None\n ] * stride_kk + head_size_offs[None, :]\n block_base_ptrs = block_tables + seq_idx * max_num_blocks_per_seq\n hi_unroll = (end_block_idx - 1) // UNROLL_FACTOR * UNROLL_FACTOR\n if UNROLL_FACTOR == 1:\n qkv, qk_max, exp_sum = _inner_paged_attn_unroll_0_kernel(q, k_cache,\n v_cache, stride_km, block_base_ptrs, base_offs_kv, alibi_slope,\n block_offs, seq_len, qkv, qk_max, exp_sum, BLOCK_SIZE,\n start_block_idx, hi_unroll)\n elif UNROLL_FACTOR == 2:\n qkv, qk_max, exp_sum = _inner_paged_attn_unroll_2_kernel(q, k_cache,\n v_cache, stride_km, block_base_ptrs, base_offs_kv, alibi_slope,\n block_offs, seq_len, qkv, qk_max, exp_sum, BLOCK_SIZE,\n start_block_idx, hi_unroll)\n elif UNROLL_FACTOR == 4:\n qkv, qk_max, exp_sum = _inner_paged_attn_unroll_4_kernel(q, k_cache,\n v_cache, stride_km, block_base_ptrs, base_offs_kv, alibi_slope,\n block_offs, seq_len, qkv, qk_max, exp_sum, BLOCK_SIZE,\n start_block_idx, hi_unroll)\n elif UNROLL_FACTOR == 8:\n qkv, qk_max, exp_sum = _inner_paged_attn_unroll_8_kernel(q, k_cache,\n v_cache, stride_km, block_base_ptrs, base_offs_kv, alibi_slope,\n block_offs, seq_len, qkv, qk_max, exp_sum, BLOCK_SIZE,\n start_block_idx, hi_unroll)\n tl.debug_barrier()\n for block_idx in range(hi_unroll, end_block_idx):\n physical_block_idx = tl.load(block_tables + seq_idx *\n max_num_blocks_per_seq + block_idx)\n mask = block_offs[:, None] < seq_len - block_idx * BLOCK_SIZE\n offs_kv = physical_block_idx * stride_km + base_offs_kv\n k = tl.load(k_cache + offs_kv, mask=mask, other=fp16_0)\n v = tl.load(v_cache + offs_kv, mask=mask, other=fp16_0)\n _qk = tl.sum((q[None, :] * k).to(tl.float32), axis=1)\n _qk = tl.where(block_offs < seq_len - block_idx * BLOCK_SIZE, _qk,\n float('-inf'))\n _qk += alibi_slope * (block_idx * BLOCK_SIZE + block_offs - seq_len + 1\n )\n _qk_max = tl.maximum(tl.max(_qk, axis=0), qk_max)\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(tl.exp(_qk -\n _qk_max), axis=0)\n qkv = qkv * (exp_sum * tl.exp(qk_max - _qk_max)) + tl.exp(_qk[:,\n None] - _qk_max) * v\n qkv = qkv / _exp_sum\n qk_max = _qk_max\n exp_sum = _exp_sum\n if USE_PARTITIONING:\n offs_exp = seq_idx * stride_exp_m + head_idx * stride_exp_n + par_idx\n tl.store(exp_sums + offs_exp, exp_sum)\n tl.store(max_logits + offs_exp, qk_max)\n offs_out = (seq_idx * stride_om + head_idx * stride_on + par_idx *\n stride_ok + head_size_offs)\n tl.store(out + offs_out, tl.sum(qkv, axis=0))\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Persistent Kernels" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "cd64708f-5721-4a20-be92-b7c64e1762ca", "file_name": "GELUglu.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/GELUglu.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _gelu_glu_fwd_kernel(output_ptr, input_ptr, output_row_stride,\n input_row_stride, output_col_stride, input_col_stride,\n output_page_stride, input_page_stride, n_pages, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1)\n x = tl.load(input_ptr + row_idx * input_row_stride + col_idx *\n input_col_stride + tl.arange(0, BLOCK_SIZE // 2) *\n input_page_stride, mask=tl.arange(0, BLOCK_SIZE // 2) < n_pages // \n 2, other=-float('inf'))\n gate = tl.load(input_ptr + row_idx * input_row_stride + col_idx *\n input_col_stride + (tl.arange(0, BLOCK_SIZE // 2) + n_pages // 2) *\n input_page_stride, mask=tl.arange(0, BLOCK_SIZE // 2) < n_pages // \n 2, other=-float('inf'))\n gate_cube = gate * gate * gate\n beta = 0.7978845608028654\n kappa = 0.044715\n inner = beta * (gate + kappa * gate_cube)\n inner_tanh = tanh(inner)\n gate_gelu = 0.5 * gate * (inner_tanh + 1)\n gelu_glu = gate_gelu * x\n tl.store(output_ptr + row_idx * output_row_stride + col_idx *\n output_col_stride + tl.arange(0, BLOCK_SIZE // 2) *\n output_page_stride, gelu_glu, mask=tl.arange(0, BLOCK_SIZE // 2) < \n n_pages // 2)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/GELUglu.py" }, { "uuid": "e3441201-2cc6-4bc0-b20c-0cd97d2fe333", "file_name": "triton_welford.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/welford/triton_welford.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'XBLOCK': 1, 'RBLOCK': 1024},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 1, 'RBLOCK': 2048},\n num_stages=1, num_warps=8)], key=['xnumel', 'rnumel'])\n@triton.jit\ndef triton_red_fused_native_layer_norm_0(in_out_ptr0, in_ptr0, in_ptr1,\n in_ptr2, out_ptr0, out_ptr1, xnumel, rnumel, XBLOCK: tl.constexpr,\n RBLOCK: tl.constexpr):\n xoffset = tl.program_id(0) * XBLOCK\n xindex = xoffset + tl.arange(0, XBLOCK)[:, None]\n xmask = xindex < xnumel\n rbase = tl.arange(0, RBLOCK)[None, :]\n x0 = xindex\n tmp3_mean = tl.zeros([XBLOCK, RBLOCK], tl.float32)\n tmp3_m2 = tl.zeros([XBLOCK, RBLOCK], tl.float32)\n tmp3_weight = tl.zeros([XBLOCK, RBLOCK], tl.float32)\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r1 = rindex\n tmp0 = tl.load(in_ptr0 + (r1 + rnumel * x0), rmask, eviction_policy\n ='evict_last').to(tl.float32)\n tmp1 = tmp0.to(tl.float32)\n tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])\n tmp3_mean_next, tmp3_m2_next, tmp3_weight_next = (triton_helpers.\n welford_reduce(tmp2, tmp3_mean, tmp3_m2, tmp3_weight, roffset == 0)\n )\n tmp3_mean = tl.where(rmask, tmp3_mean_next, tmp3_mean)\n tmp3_m2 = tl.where(rmask, tmp3_m2_next, tmp3_m2)\n tmp3_weight = tl.where(rmask, tmp3_weight_next, tmp3_weight)\n tmp3_tmp, tmp4_tmp, tmp5_tmp = triton_helpers.welford(tmp3_mean,\n tmp3_m2, tmp3_weight, 1)\n tmp3 = tmp3_tmp[:, None]\n tmp4 = tmp4_tmp[:, None]\n tmp5 = tmp5_tmp[:, None]\n tl.store(out_ptr0 + x0, tmp3, None)\n tmp6 = rnumel\n tmp7 = tmp4 / tmp6\n tmp8 = 1e-05\n tmp9 = tmp7 + tmp8\n tmp10 = libdevice.rsqrt(tmp9)\n tl.debug_barrier()\n tl.store(in_out_ptr0 + x0, tmp10, None)\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r1 = rindex\n tmp11 = tl.load(in_ptr0 + (r1 + rnumel * x0), rmask,\n eviction_policy='evict_first').to(tl.float32)\n tmp15 = tl.load(in_ptr1 + r1, rmask, eviction_policy='evict_last').to(\n tl.float32)\n tmp18 = tl.load(in_ptr2 + r1, rmask, eviction_policy='evict_last').to(\n tl.float32)\n tmp12 = tmp11.to(tl.float32)\n tmp13 = tmp12 - tmp3\n tmp14 = tmp13 * tmp10\n tmp16 = tmp15.to(tl.float32)\n tmp17 = tmp14 * tmp16\n tmp19 = tmp18.to(tl.float32)\n tmp20 = tmp17 + tmp19\n tmp21 = tmp20.to(tl.float32)\n tl.store(out_ptr1 + (r1 + rnumel * x0), tmp21, rmask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/welford/triton_welford.py" }, { "uuid": "b6bbdca6-8c98-4528-a967-b358c90a1d6f", "file_name": "triton_fused_local_attn.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_local_attn.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q, sm_scale, K_block_ptr, V_block_ptr,\n start_m, offs_m, offs_n, SEQLEN_K: tl.constexpr, WINDOW_SIZE: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, EVEN_MN: tl.\n constexpr, STAGE: tl.constexpr):\n if STAGE == 1:\n hi = start_m * BLOCK_M - WINDOW_SIZE + BLOCK_M\n lo = start_m * BLOCK_M - WINDOW_SIZE\n if hi < 0:\n hi = 0\n if lo < 0:\n lo = 0\n elif STAGE == 2:\n hi = start_m * BLOCK_M\n lo = start_m * BLOCK_M - WINDOW_SIZE + BLOCK_M\n if lo < 0:\n lo = 0\n else:\n lo, hi = start_m * BLOCK_M, (start_m + 1) * BLOCK_M\n lo = tl.multiple_of(lo, BLOCK_M)\n hi = min(hi, SEQLEN_K)\n EVEN_MASK_FREE = EVEN_MN & ((STAGE == 1) | (STAGE == 2))\n K_block_ptr = tl.advance(K_block_ptr, (0, lo))\n V_block_ptr = tl.advance(V_block_ptr, (lo, 0))\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_MASK_FREE:\n k = tl.load(K_block_ptr)\n else:\n k = tl.load(K_block_ptr, boundary_check=(1,), padding_option='zero'\n )\n qk = tl.dot(q, k) * (sm_scale * RCP_LN2)\n if STAGE == 1:\n mask = offs_m[:, None] <= start_n + WINDOW_SIZE + offs_n[None, :]\n qk += tl.where(mask, 0, NEGINF)\n elif STAGE == 3:\n mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk += tl.where(mask, 0, NEGINF)\n if not EVEN_MASK_FREE:\n qk += tl.where((start_n + offs_n)[None, :] < SEQLEN_K, 0, NEGINF)\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc *= alpha[:, None]\n if EVEN_MASK_FREE:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(1,), padding_option='zero'\n )\n acc += tl.dot(p.to(V_block_ptr.dtype.element_ty), v)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_local_attn.py" }, { "uuid": "362d6816-df21-46a1-b625-bc3f25aab424", "file_name": "06-fused-attention.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _attn_bwd_dkdv(dk, dv, Q, k, v, sm_scale, DO, M, D, stride_tok,\n stride_d, H, N_CTX, BLOCK_M1: tl.constexpr, BLOCK_N1: tl.constexpr,\n HEAD_DIM: tl.constexpr, start_n, start_m, num_steps, MASK: tl.constexpr):\n offs_m = start_m + tl.arange(0, BLOCK_M1)\n offs_n = start_n + tl.arange(0, BLOCK_N1)\n offs_k = tl.arange(0, HEAD_DIM)\n qT_ptrs = Q + offs_m[None, :] * stride_tok + offs_k[:, None] * stride_d\n do_ptrs = DO + offs_m[:, None] * stride_tok + offs_k[None, :] * stride_d\n tl.static_assert(BLOCK_N1 % BLOCK_M1 == 0)\n curr_m = start_m\n step_m = BLOCK_M1\n for blk_idx in range(num_steps):\n qT = tl.load(qT_ptrs)\n offs_m = curr_m + tl.arange(0, BLOCK_M1)\n m = tl.load(M + offs_m)\n qkT = tl.dot(k, qT)\n pT = tl.math.exp2(qkT - m[None, :])\n if MASK:\n mask = offs_m[None, :] >= offs_n[:, None]\n pT = tl.where(mask, pT, 0.0)\n do = tl.load(do_ptrs)\n ppT = pT\n ppT = ppT.to(tl.float16)\n dv += tl.dot(ppT, do)\n Di = tl.load(D + offs_m)\n dpT = tl.dot(v, tl.trans(do)).to(tl.float32)\n dsT = pT * (dpT - Di[None, :])\n dsT = dsT.to(tl.float16)\n dk += tl.dot(dsT, tl.trans(qT))\n curr_m += step_m\n qT_ptrs += step_m * stride_tok\n do_ptrs += step_m * stride_tok\n return dk, dv\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/06-fused-attention.py" }, { "uuid": "465954ee-4cfe-46e9-8668-a230f02bb257", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_dense_bmm_kernel(a_ptr, a_offset_ptr, b_ptr, c_ptr, N, K,\n stride_am, stride_ak, stride_bl, stride_bk, stride_bn, stride_cm,\n stride_cn, max_seq_len, allow_tf32: tl.constexpr, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (sum_B(M_i), K), B has shape (B, K, N) and C has shape (sum_B(M_i), N)\n \"\"\"\n pid_batch = tl.program_id(0)\n pid = tl.program_id(1)\n begin = tl.load(a_offset_ptr + pid_batch)\n end = tl.load(a_offset_ptr + pid_batch + 1)\n M = tl.minimum(end - begin, max_seq_len)\n if M == 0:\n return\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_m = pid // num_pid_n\n pid_n = pid % num_pid_n\n offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n if pid_m * BLOCK_SIZE_M >= M:\n return\n offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n if pid_n * BLOCK_SIZE_N >= N:\n return\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak + begin * stride_am)\n b_ptrs = b_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] *\n stride_bn + pid_batch * stride_bl)\n c = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, K, BLOCK_SIZE_K):\n updated_offset = k + offs_k\n a = tl.load(a_ptrs, mask=(updated_offset[None, :] < K) & (offs_am[:,\n None] < M), other=0.0)\n b = tl.load(b_ptrs, mask=(updated_offset[:, None] < K) & (offs_bn[\n None, :] < N), other=0.0)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n offs_m = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_n = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n mask = (offs_m[:, None] < M) & (offs_n[None, :] < N)\n c_ptrs = c_ptr + stride_cm * offs_m[:, None] + stride_cn * offs_n[None, :\n ] + begin * stride_cm\n tl.store(c_ptrs, c, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "ff383b02-6ac6-4d19-8a8c-ff80198f182f", "file_name": "z_order.py", "repo_name": "Kitsunetic/space-filling-pytorch", "file_path": "space_filling_pytorch/functional/z_order.py", "commit_hash": "0de955ad1036973ee7506c5a0124c208acec722d", "starcount": 0, "input": "@triton.jit\ndef _encode_z_kernel(xyz_ptr, distance_ptr, B, N, space_size, x_offset,\n y_offset, z_offset, str_xyz_B, str_xyz_N, str_xyz_C, BLK: tl.constexpr,\n ASSIGN_BATCH_INDEX: tl.constexpr):\n pid_b = tl.program_id(0)\n pid_n = tl.program_id(1)\n offs_n = pid_n * BLK + tl.arange(0, BLK)\n mask_n = offs_n < N\n xyz_ptrs = xyz_ptr + pid_b * str_xyz_B + offs_n * str_xyz_N\n fx = tl.load(xyz_ptrs + x_offset * str_xyz_C, mask=mask_n)\n fy = tl.load(xyz_ptrs + y_offset * str_xyz_C, mask=mask_n)\n fz = tl.load(xyz_ptrs + z_offset * str_xyz_C, mask=mask_n)\n ret = _calculate_zorder(fx, fy, fz, space_size)\n if ASSIGN_BATCH_INDEX:\n ret |= pid_b.to(tl.int64) << 48\n tl.store(distance_ptr + pid_b * N + offs_n, ret, mask=mask_n)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/space-filling-pytorch/blob/0de955ad1036973ee7506c5a0124c208acec722d/space_filling_pytorch/functional/z_order.py" }, { "uuid": "1f260b65-2aa3-4dd8-ad87-6f5bba941dd2", "file_name": "block_sparse_attention_lut.py", "repo_name": "sparklesea/sparse-quant", "file_path": "sparse-attention/muxi/playground/kernels/block_sparse_attention_lut.py", "commit_hash": "e3d8b6ecab208c31b744913ed8c3caaa43605f86", "starcount": 0, "input": "@triton.jit\ndef _sparse_attention_prefill_fwd_kernel(Q, K, V, sm_scale, Out, lut,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, stride_lz, stride_lh,\n stride_lx, Z, H, N_CTX, LT, NNZ: tl.constexpr, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n lut_indicator = tl.program_id(1) % H\n qvk_offset = off_hz * stride_qh\n lut_offset = lut_indicator * stride_lz\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(\n BLOCK_DMODEL, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504\n q = tl.load(Q_block_ptr, boundary_check=(0, 1), padding_option='zero')\n q = (q * qk_scale).to(tl.float16)\n last_nnz_id = -1\n for nnz_id in range(NNZ):\n present_nnz_id = tl.load(lut + lut_offset + start_m * stride_lh + \n nnz_id * stride_lx)\n start_n = present_nnz_id * BLOCK_N\n start_n = tl.multiple_of(start_n, BLOCK_N)\n present_nnz_id = present_nnz_id.to(tl.int32)\n k = tl.load(tl.advance(K_block_ptr, (0, start_n)), boundary_check=(\n 0, 1), padding_option='zero')\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n if LT:\n qk = tl.where(offs_m[:, None] >= start_n + offs_n[None, :], qk,\n float('-inf'))\n qk = tl.where((offs_m[:, None] < N_CTX) & ((start_n + offs_n)[None,\n :] < N_CTX), qk, float('-inf'))\n m_ij = tl.max(qk, 1)\n p = tl.math.exp2(qk - m_ij[:, None])\n p = tl.where(m_ij[:, None] == tl.full((BLOCK_M, BLOCK_N), float(\n '-inf'), tl.float32), 0.0, tl.math.exp2(qk - m_ij[:, None]))\n p = p * (last_nnz_id != present_nnz_id)\n l_ij = tl.sum(p, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n alpha = tl.math.exp2(m_i - m_i_new)\n beta = tl.math.exp2(m_ij - m_i_new)\n l_i *= alpha\n l_i_new = l_i + beta * l_ij\n p_scale = beta / l_i_new\n p = p * p_scale[:, None]\n acc_scale = l_i / l_i_new\n acc = acc * acc_scale[:, None]\n v = tl.load(tl.advance(V_block_ptr, (start_n, 0)), boundary_check=(\n 0, 1), padding_option='zero')\n p = p.to(tl.float16)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n last_nnz_id = present_nnz_id\n tl.store(O_block_ptr, acc.to(tl.float16), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache", "BSD" ], "github_url": "https://github.com/sparklesea/sparse-quant/blob/e3d8b6ecab208c31b744913ed8c3caaa43605f86/sparse-attention/muxi/playground/kernels/block_sparse_attention_lut.py" }, { "uuid": "33299f98-59f0-48e0-ae23-2da139cb499d", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_softmax_backward_kernel(grad_output_ptr, softmax_output_ptr,\n grad_input_ptr, input_offsets_ptr, grad_output_row_stride,\n grad_output_head_stride, softmax_output_row_stride,\n softmax_output_head_stride, grad_input_row_stride,\n grad_input_head_stride, max_seq_len: tl.constexpr, BLOCK_SIZE: tl.constexpr\n ):\n \"\"\"\n grad_output_ptr shpae is [SUM_B, H]\n softmax_output shape is [SUM_B, H]\n grad_input shape is [SUM_B, H]\n \"\"\"\n pid_batch = tl.program_id(0)\n pid_head = tl.program_id(1)\n row_begin = tl.load(input_offsets_ptr + pid_batch)\n row_end = tl.load(input_offsets_ptr + pid_batch + 1)\n N = tl.minimum(max_seq_len, row_end - row_begin)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n grad_output_ptrs = (grad_output_ptr + row_begin *\n grad_output_row_stride + col_offsets * grad_output_row_stride + \n pid_head * grad_output_head_stride)\n softmax_output_ptrs = (softmax_output_ptr + row_begin *\n softmax_output_row_stride + col_offsets * softmax_output_row_stride +\n pid_head * softmax_output_head_stride)\n grad_output_row = tl.load(grad_output_ptrs, mask=col_offsets < N, other=0.0\n )\n softmax_output_row = tl.load(softmax_output_ptrs, mask=col_offsets < N,\n other=0.0)\n sum_value = tl.sum(grad_output_row * softmax_output_row, axis=0)\n grad_input_row = (grad_output_row - sum_value) * softmax_output_row\n grad_input_ptrs = (grad_input_ptr + row_begin * grad_input_row_stride +\n col_offsets * grad_input_row_stride + pid_head * grad_input_head_stride\n )\n tl.store(grad_input_ptrs, grad_input_row, mask=col_offsets < N)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "a5dd6188-758a-4f75-ad16-7e404fe62595", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_linear_attn_fwd_kernel_h(k, v, h, h0, ht, s_k_h, s_k_t, s_k_d,\n s_v_h, s_v_t, s_v_d, s_h_h, s_h_t, T: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NT:\n tl.constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.\n constexpr):\n i_k, i_v, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_h += tl.dot(b_k, b_v, allow_tf32=False)\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/chunk.py" }, { "uuid": "e7e27939-c077-46e1-9632-7858a429dae5", "file_name": "k_layer_norm.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_layer_norm.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_non_affine_fw(X, Y, M, V, stride, N, eps, **META):\n _store(_layer_norm_non_affine(X, M, V, stride, N, eps, META), Y, stride,\n N, META)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_layer_norm.py" }, { "uuid": "a8c30808-d914-41b7-8bd2-094cbdbfcbd0", "file_name": "k_fused_matmul_bw.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_fused_matmul_bw.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.heuristics({'EVEN_N': lambda *args, **meta: args[3] % meta[\n 'BLOCK_COL'] == 0})\n@triton.autotune(configs=[triton.Config({'BLOCK_COL': 32}, num_stages=5,\n num_warps=2), triton.Config({'BLOCK_COL': 64}, num_stages=5, num_warps=\n 2), triton.Config({'BLOCK_COL': 128}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_COL': 256}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_COL': 512}, num_stages=3, num_warps=8), triton.Config({\n 'BLOCK_COL': 1024}, num_stages=3, num_warps=16)], key=['N'])\n@triton.jit\ndef kernel_bw(GRAD_ACT, GRAD_OUT, ACT_INPUTS, N, stride_gom, stride_aim, **META\n ):\n \"\"\"\n Go over all the activation inputs, compute the corresponding gradient\n \"\"\"\n BLOCK_N = META['BLOCK_COL']\n pid_m, pid_n = tl.program_id(axis=0), tl.program_id(axis=1)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n act_input_ptrs = ACT_INPUTS + pid_m * stride_aim + rn\n if META['EVEN_N']:\n act_in = tl.load(act_input_ptrs)\n else:\n act_in = tl.load(act_input_ptrs, mask=rn < N, other=0.0)\n grad_act = META['ACTIVATION_GRAD'](act_in)\n grad_out_ptrs = GRAD_OUT + pid_m * stride_gom + rn\n if META['EVEN_N']:\n grad_out = tl.load(grad_out_ptrs)\n else:\n grad_out = tl.load(grad_out_ptrs, mask=rn < N)\n grad_act *= grad_out\n grad_act_ptrs = GRAD_ACT + pid_m * stride_gom + rn\n tl.store(grad_act_ptrs, grad_act, mask=rn < N)\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_fused_matmul_bw.py" }, { "uuid": "e3fb6f4a-8ca3-4994-899f-d62d808652d3", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef store_1d(vals, ptr, sz: tl.constexpr, n, max, stride=1):\n \"\"\"Store 1d block into nth chunk of vector (defined by ptr), where each chunk has size sz\"\"\"\n offs = get_1d_offest(sz, n)\n mask = get_1d_mask(offs, max)\n tl.store(ptr + offs, vals, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "ad3e39e4-beb3-4789-856e-e24e65695e79", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8]], key=['BT', 'BK'])\n@triton.jit\ndef fwd_recompute_w_kernel(k, beta, w, A, offsets, indices, T: tl.constexpr,\n H: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_A = tl.load(p_A, boundary_check=(0, 1)).to(k.dtype.element_ty)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_w = tl.dot(b_A, b_kb, allow_tf32=False)\n tl.store(p_w, b_w.to(p_w.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/wy_fast.py" }, { "uuid": "02c185b4-ba6d-4e60-84de-9ccd865f78e9", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_intra_K(v, z, o, A, s_v_h, s_v_t, s_v_d, T: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BV: tl.\n constexpr, NC: tl.constexpr):\n i_v, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_t, i_i = i_c // NC, i_c % NC\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), ((i_t *\n BT + i_i * BC) * V + i_v * BV,), (BV,), (0,))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_o = tl.zeros([BC, BV], dtype=tl.float32)\n for i_j in range(0, i_i):\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_o += tl.dot(b_A, tl.exp(b_v - b_zn[None, :]).to(b_v.dtype),\n allow_tf32=False)\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_o *= tl.exp(b_zn[None, :] - b_z)\n o_i = tl.arange(0, BC)\n o_A = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_i * BC\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n for j in range(0, BC):\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T * V,), (1,), ((i_t *\n BT + i_i * BC + j) * V + i_v * BV,), (BV,), (0,))\n b_A = tl.load(A + o_A + j, mask=m_A, other=0)\n b_v = tl.load(p_v, boundary_check=(0,)).to(tl.float32)\n m_i = o_i[:, None] >= j\n b_o += tl.where(m_i, b_A[:, None] * tl.exp(b_v[None, :] - b_z), 0)\n p_o = tl.make_block_ptr(o + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "159f0cc5-72b0-4231-97dc-2a5e3f2c0d0b", "file_name": "hilbert.py", "repo_name": "Kitsunetic/space-filling-pytorch", "file_path": "space_filling_pytorch/functional/hilbert.py", "commit_hash": "0de955ad1036973ee7506c5a0124c208acec722d", "starcount": 0, "input": "@triton.jit\ndef _encode_hilbert_unpadded_kernel(xyz_ptr, batch_idx_ptr, code_ptr,\n space_size, x_offset, y_offset, z_offset, str_xyz_n, str_xyz_c, N, BLK:\n tl.constexpr, ASSIGN_BATCH_INDEX: tl.constexpr):\n pid = tl.program_id(0)\n offs_n = pid * BLK + tl.arange(0, BLK)\n mask = offs_n < N\n xyz_ptrs = xyz_ptr + offs_n * str_xyz_n\n fx = tl.load(xyz_ptrs + x_offset * str_xyz_c, mask=mask)\n fy = tl.load(xyz_ptrs + y_offset * str_xyz_c, mask=mask)\n fz = tl.load(xyz_ptrs + z_offset * str_xyz_c, mask=mask)\n ret = _calculate_hilbert_distance(fx, fy, fz, space_size)\n if ASSIGN_BATCH_INDEX:\n batch_idx_ptrs = batch_idx_ptr + offs_n\n batch_idx = tl.load(batch_idx_ptrs, mask=mask).to(tl.int64)\n ret |= batch_idx << 48\n code_ptrs = code_ptr + offs_n\n tl.store(code_ptrs, ret, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/space-filling-pytorch/blob/0de955ad1036973ee7506c5a0124c208acec722d/space_filling_pytorch/functional/hilbert.py" }, { "uuid": "2c6c706f-18a5-446c-bc50-dd5319c23177", "file_name": "triton_fused_local_attn_rerope.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_local_attn_rerope.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0})\n@triton.jit\ndef _fwd_kernel(Q1, Q2, K1, K2, V, Out, L, softmax_scale, stride_qb,\n stride_qh, stride_qm, stride_kb, stride_kh, stride_kn, stride_vb,\n stride_vh, stride_vn, stride_ob, stride_oh, stride_om, nheads, seqlen_q,\n seqlen_k, CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, WINDOW_SIZE: tl.\n constexpr, BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N:\n tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, WRITE_LSE:\n tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n Q1_block_ptr = tl.make_block_ptr(base=Q1 + (off_b * stride_qb + off_h *\n stride_qh), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_qm, 1),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_HEADDIM\n ), order=(1, 0))\n Q2_block_ptr = tl.make_block_ptr(base=Q2 + (off_b * stride_qb + off_h *\n stride_qh), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_qm, 1),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_HEADDIM\n ), order=(1, 0))\n K1_block_ptr = tl.make_block_ptr(base=K1 + (off_b * stride_kb + off_h *\n stride_kh), shape=(BLOCK_HEADDIM, seqlen_k), strides=(1, stride_kn),\n offsets=(0, 0), block_shape=(BLOCK_HEADDIM, BLOCK_N), order=(0, 1))\n K2_block_ptr = tl.make_block_ptr(base=K2 + (off_b * stride_kb + off_h *\n stride_kh), shape=(BLOCK_HEADDIM, seqlen_k), strides=(1, stride_kn),\n offsets=(0, 0), block_shape=(BLOCK_HEADDIM, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + (off_b * stride_vb + off_h *\n stride_vh), shape=(seqlen_k, BLOCK_HEADDIM), strides=(stride_vn, 1),\n offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M:\n q1 = tl.load(Q1_block_ptr)\n q2 = tl.load(Q2_block_ptr)\n else:\n q1 = tl.load(Q1_block_ptr, boundary_check=(0,), padding_option='zero')\n q2 = tl.load(Q2_block_ptr, boundary_check=(0,), padding_option='zero')\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q1, q2, softmax_scale,\n K1_block_ptr, K2_block_ptr, V_block_ptr, start_m, offs_m, offs_n,\n seqlen_k, WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 1)\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q1, q2, softmax_scale,\n K1_block_ptr, K2_block_ptr, V_block_ptr, start_m, offs_m, offs_n,\n seqlen_k, WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 2)\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q1, q2, softmax_scale,\n K1_block_ptr, K2_block_ptr, V_block_ptr, start_m, offs_m, offs_n,\n seqlen_k, WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 3)\n if WRITE_LSE:\n l_ptrs = L + off_hb * seqlen_q + offs_m\n tl.store(l_ptrs, m_i + tl.math.log2(l_i))\n acc = acc / l_i[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc)\n else:\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_local_attn_rerope.py" }, { "uuid": "295647f9-b805-4b3f-8f9a-72124ff188fd", "file_name": "relu.py", "repo_name": "daemyung/practice-triton", "file_path": "relu.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@staticmethod\n@triton.jit\ndef backward(grad_input_ptr, grad_output_ptr, input_ptr, size, block_size:\n tl.constexpr):\n pid = tl.program_id(0)\n offset = pid * block_size\n grad_input_block_ptr = tl.make_block_ptr(grad_input_ptr, shape=(size,),\n strides=(1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n grad_output_block_ptr = tl.make_block_ptr(grad_output_ptr, shape=(size,\n ), strides=(1,), offsets=(offset,), block_shape=(block_size,),\n order=(0,))\n input_block_ptr = tl.make_block_ptr(input_ptr, shape=(size,), strides=(\n 1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n grad_output = tl.load(grad_output_block_ptr, boundary_check=(0,))\n input = tl.load(input_block_ptr, boundary_check=(0,))\n condition = input >= 0\n grad_input = tl.where(condition, grad_output, 0)\n tl.store(grad_input_block_ptr, grad_input, boundary_check=(0,))\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/relu.py" }, { "uuid": "98f78d67-d8c7-4106-a9bc-6716d5cd0889", "file_name": "sb_varlen_fwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_fwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.jit\ndef compute_block(q, k, qk_scale, neg_log_acc, M_blk_idxs, N_blk_idxs, cm,\n on_band: tl.constexpr, ALLOW_TF32: tl.constexpr, backward: tl.constexpr,\n attend_current: tl.constexpr=False, use_cumsum: tl.constexpr=False,\n is_compiling: tl.constexpr=False):\n qk = tl.dot(q, tl.trans(k), allow_tf32=ALLOW_TF32) * qk_scale\n log_om_beta = -softplus(qk, is_compiling=is_compiling)\n if on_band:\n if attend_current:\n block_mask = M_blk_idxs[:, None] >= N_blk_idxs[None, :]\n else:\n block_mask = M_blk_idxs[:, None] > N_blk_idxs[None, :]\n log_om_beta = tl.where(block_mask, log_om_beta, 0.0)\n if backward:\n neg_log_acc -= tl.sum(log_om_beta, axis=1)\n log_p = qk + neg_log_acc[:, None]\n if use_cumsum:\n log_p += tl.cumsum(log_om_beta.to(q.dtype), axis=1, reverse=True)\n else:\n log_p = tl.dot(log_om_beta.to(q.dtype), cm, acc=log_p,\n allow_tf32=ALLOW_TF32)\n p = tl.math.exp2(log_p)\n p = tl.where(block_mask, p, 0.0)\n else:\n if backward:\n neg_log_acc -= tl.sum(log_om_beta, axis=1)\n log_p = qk + neg_log_acc[:, None]\n if use_cumsum:\n log_p += tl.cumsum(log_om_beta.to(q.dtype), axis=1, reverse=True)\n else:\n log_p = tl.dot(log_om_beta.to(q.dtype), cm, acc=log_p,\n allow_tf32=ALLOW_TF32)\n p = tl.math.exp2(log_p)\n if not backward:\n neg_log_acc += tl.sum(log_om_beta, axis=1)\n return p, log_om_beta, neg_log_acc\n", "category": { "Functionality": [ "Attention Mechanisms", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_fwd.py" }, { "uuid": "c3784dfb-4b90-4a4f-9175-4a69cc1f915d", "file_name": "fused_attn.py", "repo_name": "thunlp/Delta-CoMe", "file_path": "quant/fused_attn.py", "commit_hash": "646a1fbf3443295c4b04aba27334c6bc5aa3df4f", "starcount": 0, "input": "@triton.jit\ndef rotate_half_kernel(qk_seq_ptr, position_ids_ptr, qk_seq_stride,\n position_ids_batch_stride, seq_len, HEAD_DIM: tl.constexpr,\n BLOCK_HEIGHT: tl.constexpr, BLOCK_WIDTH: tl.constexpr, INV_BASE: tl.\n constexpr):\n HALF_HEAD: tl.constexpr = HEAD_DIM // 2\n STEPS_PER_ROW: tl.constexpr = HALF_HEAD // BLOCK_WIDTH\n batch_seq = tl.program_id(axis=0)\n row_blk_x_col_blk = tl.program_id(axis=1)\n row_blk = row_blk_x_col_blk // STEPS_PER_ROW\n row = row_blk * BLOCK_HEIGHT\n if BLOCK_WIDTH < HALF_HEAD:\n col_blk = row_blk_x_col_blk % STEPS_PER_ROW\n col = col_blk * BLOCK_WIDTH\n else:\n col: tl.constexpr = 0\n batch = batch_seq // seq_len\n seq = batch_seq % seq_len\n position_id = tl.load(position_ids_ptr + batch *\n position_ids_batch_stride + seq)\n freq = tl.libdevice.exp((col + tl.arange(0, BLOCK_WIDTH)).to(tl.float32\n ) * INV_BASE) * position_id\n cos = tl.cos(freq).to(tl.float32)\n sin = tl.sin(freq).to(tl.float32)\n col_offsets: tl.constexpr = tl.arange(0, BLOCK_WIDTH)\n embed_offsets = row * HEAD_DIM + col + col_offsets\n x_ptrs = qk_seq_ptr + batch_seq * qk_seq_stride + embed_offsets\n for k in range(0, BLOCK_HEIGHT):\n x = tl.load(x_ptrs).to(tl.float32)\n y = tl.load(x_ptrs + HALF_HEAD).to(tl.float32)\n out_x = x * cos - y * sin\n tl.store(x_ptrs, out_x)\n out_y = x * sin + y * cos\n tl.store(x_ptrs + HALF_HEAD, out_y)\n x_ptrs += HEAD_DIM\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/thunlp/Delta-CoMe/blob/646a1fbf3443295c4b04aba27334c6bc5aa3df4f/quant/fused_attn.py" }, { "uuid": "297bd9f8-dbf4-4cd4-b87b-6208c25245d1", "file_name": "pointwise.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/pointwise.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_copy_kernel(input_ptr, out_ptr, numel: tl.constexpr, block_size:\n tl.constexpr):\n block_start = tl.program_id(axis=0).to(tl.int64) * block_size\n offsets = block_start + tl.arange(0, block_size)\n mask = offsets < numel\n input_ = tl.load(input_ptr + offsets, mask=mask)\n tl.store(out_ptr + offsets, input_, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/pointwise.py" }, { "uuid": "c7b00225-9961-4819-bb21-d098a0681a35", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_N': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_N': 256,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 16}, num_stages=2, num_warps=8),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M':\n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M':\n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32, 'BLOCK_SIZE_M': \n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32, 'BLOCK_SIZE_M':\n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 16}, num_stages=2, num_warps=4)],\n key=['M', 'N', 'K'])\n@triton.jit\ndef rz_linear_backward_weight_grad_kernel_fp32(a_ptr, b_ptr, c_ptr,\n init_factor, M, N, K, H, stride_am, stride_ak, stride_bm, stride_bn, R7:\n int, R6: int, R5: int, R4: int, R3: int, R2: int, R1: int, R0: int,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_backward_weight_grad_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=\n c_ptr, init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=\n stride_am, stride_ak=stride_ak, stride_bm=stride_bm, stride_bn=\n stride_bn, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1, R0=R0,\n allow_tf32=False, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=\n BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "b43d035a-53a0-4ffb-8bee-abc8a227f8b9", "file_name": "ops.py", "repo_name": "shawntan/scattermoe", "file_path": "scattermoe/kernels/ops.py", "commit_hash": "63b76a2f5f28c052fb4cd7c34479a54158354052", "starcount": 0, "input": "@triton.autotune(configs=_scatter2scatter_configs(), key=['M', 'N', 'K'])\n@triton.heuristics({'NO_K_MASK': lambda args: args['K'] % args['BLOCK_K'] ==\n 0, 'NO_N_MASK': lambda args: args['N'] % args['BLOCK_N'] == 0})\n@triton.jit\ndef _scatter2scatter(X_ptr, stride_xm, stride_xk, W_ptr, stride_we,\n stride_wk, stride_wn, Y_ptr, stride_ym, stride_yn, grouped_idx_ptr,\n expert_idxs_ptr, block_start_idx_ptr, FAN_OUT: tl.constexpr, M, K: tl.\n constexpr, N: tl.constexpr, E: tl.constexpr, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, ACC_TYPE: tl.constexpr,\n OUT_M, allow_tf32: tl.constexpr, x_grouped: tl.constexpr, y_grouped: tl\n .constexpr, NO_K_MASK: tl.constexpr, NO_N_MASK: tl.constexpr):\n pid = tl.program_id(axis=0)\n N_BLOCK_COUNT = tl.cdiv(N, BLOCK_N)\n M_block_id = pid // N_BLOCK_COUNT\n N_block_id = pid % N_BLOCK_COUNT\n M_range = tl.arange(0, BLOCK_M)\n block_start_idx = tl.load(block_start_idx_ptr + M_block_id)\n M_block = tl.max_contiguous(block_start_idx + M_range, BLOCK_M)\n E_idxs = tl.load(expert_idxs_ptr + M_block, mask=M_block < FAN_OUT * M,\n other=E)\n E_idx = tl.min(E_idxs)\n E_mask = E_idxs == E_idx\n M_idx = tl.load(grouped_idx_ptr + M_block, mask=E_mask, other=0)\n if x_grouped:\n M_in_idx = M_block\n else:\n M_in_idx = M_idx // FAN_OUT\n if y_grouped:\n M_out_idx = M_block\n else:\n M_out_idx = M_idx\n K_block = tl.arange(0, BLOCK_K)\n N_block = N_block_id * BLOCK_N + tl.arange(0, BLOCK_N)\n N_mask = N_block < N\n X_blk_ptrs = X_ptr + M_in_idx[:, None] * stride_xm + K_block[None, :\n ] * stride_xk\n W_blk_ptrs = W_ptr + K_block[:, None] * stride_wk + N_block[None, :\n ] * stride_wn + E_idx * stride_we\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=ACC_TYPE)\n iters = tl.cdiv(K, BLOCK_K)\n for K_block_id in range(0, iters):\n if NO_K_MASK:\n x = tl.load(X_blk_ptrs, mask=E_mask[:, None])\n if NO_N_MASK or K_block_id < iters - 1:\n w = tl.load(W_blk_ptrs)\n else:\n w = tl.load(W_blk_ptrs, mask=N_mask[None, :])\n else:\n K_mask = K_block_id * BLOCK_K + K_block < K\n x = tl.load(X_blk_ptrs, mask=E_mask[:, None] & K_mask[None, :])\n w = tl.load(W_blk_ptrs, mask=K_mask[:, None] & N_mask[None, :])\n X_blk_ptrs += BLOCK_K * stride_xk\n W_blk_ptrs += BLOCK_K * stride_wk\n acc += tl.dot(x, w, allow_tf32=allow_tf32, out_dtype=ACC_TYPE)\n Y_blk_ptrs = Y_ptr + (M_out_idx[:, None] * stride_ym + N_block[None, :] *\n stride_yn)\n tl.store(Y_blk_ptrs, acc, mask=E_mask[:, None] & N_mask[None, :])\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/scattermoe/blob/63b76a2f5f28c052fb4cd7c34479a54158354052/scattermoe/kernels/ops.py" }, { "uuid": "98ed13e6-3d06-4b48-bf3b-55ccbee71cfb", "file_name": "dw_conv.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/dw_conv.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _DWConv_wgrad_cl3d_impl(grad_ptr, input_ptr, weight_grad_ptr, H, W, D,\n H_stride, W_stride, ACCTYPE: tl.constexpr, channels: tl.constexpr,\n D_block: tl.constexpr, WD_grid):\n H_cell = tl.program_id(0)\n W_D_cell = tl.program_id(1)\n D_gridsize = tl.cdiv(D, D_block)\n W_cell = W_D_cell // D_gridsize\n D_cell = W_D_cell % D_gridsize\n input_ptr += D_cell * D_block * channels\n grad_ptr += D_cell * D_block * channels\n weight_grad_ptr += (H_cell * WD_grid + W_D_cell) * 27 * channels\n channels_offset = tl.arange(0, channels)\n channels_offset = tl.max_contiguous(tl.multiple_of(channels_offset,\n channels), channels)\n d_offset = tl.arange(0, D_block)\n near_offset = tl.arange(0, 4) - 1\n offset = d_offset[None, None, :] * channels + channels_offset[None, :, None\n ] + near_offset[:, None, None] * channels\n mask = d_offset[None, None, :] + near_offset[:, None, None\n ] < D - D_block * D_cell\n mask = mask and d_offset[None, None, :] + near_offset[:, None, None\n ] >= 0 - D_block * D_cell\n mask = mask and near_offset[:, None, None] != 2\n in_offset = d_offset[None, None, :] * channels + channels_offset[None,\n :, None]\n in_mask = d_offset[None, None, :] < D - D_block * D_cell\n H1_load = 2 * H_cell + 1 < H\n W1_load = 2 * W_cell + 1 < W\n h0_w0 = tl.zeros([4, channels], dtype=ACCTYPE)\n h0_w1 = tl.zeros([4, channels], dtype=ACCTYPE)\n h0_w2 = tl.zeros([4, channels], dtype=ACCTYPE)\n h1_w0 = tl.zeros([4, channels], dtype=ACCTYPE)\n h1_w1 = tl.zeros([4, channels], dtype=ACCTYPE)\n h1_w2 = tl.zeros([4, channels], dtype=ACCTYPE)\n h2_w0 = tl.zeros([4, channels], dtype=ACCTYPE)\n h2_w1 = tl.zeros([4, channels], dtype=ACCTYPE)\n h2_w2 = tl.zeros([4, channels], dtype=ACCTYPE)\n tmp_input_ptr = input_ptr + 2 * H_cell * H_stride + 2 * W_cell * W_stride\n x_h0_w0 = tl.load(tmp_input_ptr + in_offset, mask=in_mask, other=0.0)\n tmp_input_ptr = input_ptr + (2 * H_cell + 1\n ) * H_stride + 2 * W_cell * W_stride\n x_h1_w0 = tl.load(tmp_input_ptr + in_offset, mask=in_mask and H1_load,\n other=0.0)\n tmp_input_ptr = input_ptr + 2 * H_cell * H_stride + (2 * W_cell + 1\n ) * W_stride\n x_h0_w1 = tl.load(tmp_input_ptr + in_offset, mask=in_mask and W1_load,\n other=0.0)\n tmp_input_ptr = input_ptr + (2 * H_cell + 1) * H_stride + (2 * W_cell + 1\n ) * W_stride\n x_h1_w1 = tl.load(tmp_input_ptr + in_offset, mask=in_mask and (W1_load and\n H1_load), other=0.0)\n gradw_offset = tl.arange(0, 4)[:, None] * channels + channels_offset[\n None, :]\n gradw_mask = near_offset[:, None] != 2\n load_next = (2 * H_cell - 1 < H and 2 * H_cell - 1 >= 0) and (2 *\n W_cell - 1 < W and 2 * W_cell - 1 >= 0)\n tmp_grad_ptr = grad_ptr + (2 * H_cell - 1) * H_stride + (2 * W_cell - 1\n ) * W_stride\n i = -1\n j = -1\n grad = tl.zeros([4, channels, D_block], dtype=tl.float16)\n if load_next:\n grad = tl.load(tmp_grad_ptr + offset, mask=mask)\n for k in tl.static_range(0, 16):\n if load_next:\n if i == -1 and j == -1:\n h2_w2 += tl.sum(grad * x_h0_w0, axis=2)\n elif i == -1 and j == 0:\n h2_w1 += tl.sum(grad * x_h0_w0, axis=2)\n h2_w2 += tl.sum(grad * x_h0_w1, axis=2)\n elif i == -1 and j == 1:\n h2_w0 += tl.sum(grad * x_h0_w0, axis=2)\n h2_w1 += tl.sum(grad * x_h0_w1, axis=2)\n elif i == -1 and j == 2:\n h2_w0 += tl.sum(grad * x_h0_w1, axis=2)\n elif i == 0 and j == -1:\n h1_w2 += tl.sum(grad * x_h0_w0, axis=2)\n h2_w2 += tl.sum(grad * x_h1_w0, axis=2)\n elif i == 0 and j == 0:\n h1_w1 += tl.sum(grad * x_h0_w0, axis=2)\n h2_w1 += tl.sum(grad * x_h1_w0, axis=2)\n h1_w2 += tl.sum(grad * x_h0_w1, axis=2)\n h2_w2 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 0 and j == 1:\n h1_w0 += tl.sum(grad * x_h0_w0, axis=2)\n h2_w0 += tl.sum(grad * x_h1_w0, axis=2)\n h1_w1 += tl.sum(grad * x_h0_w1, axis=2)\n h2_w1 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 0 and j == 2:\n h1_w0 += tl.sum(grad * x_h0_w1, axis=2)\n h2_w0 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 1 and j == -1:\n h0_w2 += tl.sum(grad * x_h0_w0, axis=2)\n h1_w2 += tl.sum(grad * x_h1_w0, axis=2)\n elif i == 1 and j == 0:\n h0_w1 += tl.sum(grad * x_h0_w0, axis=2)\n h1_w1 += tl.sum(grad * x_h1_w0, axis=2)\n h0_w2 += tl.sum(grad * x_h0_w1, axis=2)\n h1_w2 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 1 and j == 1:\n h0_w0 += tl.sum(grad * x_h0_w0, axis=2)\n h1_w0 += tl.sum(grad * x_h1_w0, axis=2)\n h0_w1 += tl.sum(grad * x_h0_w1, axis=2)\n h1_w1 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 1 and j == 2:\n h0_w0 += tl.sum(grad * x_h0_w1, axis=2)\n h1_w0 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 2 and j == -1:\n h0_w2 += tl.sum(grad * x_h1_w0, axis=2)\n elif i == 2 and j == 0:\n h0_w1 += tl.sum(grad * x_h1_w0, axis=2)\n h0_w2 += tl.sum(grad * x_h1_w1, axis=2)\n elif i == 2 and j == 1:\n h0_w0 += tl.sum(grad * x_h1_w0, axis=2)\n h0_w1 += tl.sum(grad * x_h1_w1, axis=2)\n else:\n h0_w0 += tl.sum(grad * x_h1_w1, axis=2)\n k_ = k + 1\n i = k_ % 4 - 1\n j = k_ // 4 - 1\n load_next = (2 * H_cell + i < H and 2 * H_cell + i >= 0) and (2 *\n W_cell + j < W and 2 * W_cell + j >= 0)\n tmp_grad_ptr = grad_ptr + (2 * H_cell + i) * H_stride + (2 * W_cell + j\n ) * W_stride\n if load_next and k_ < 16:\n grad = tl.load(tmp_grad_ptr + offset, mask=mask)\n tl.store(weight_grad_ptr + gradw_offset, h0_w0, mask=gradw_mask)\n tl.store(weight_grad_ptr + 3 * channels + gradw_offset, h0_w1, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 6 * channels + gradw_offset, h0_w2, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 9 * channels + gradw_offset, h1_w0, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 12 * channels + gradw_offset, h1_w1, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 15 * channels + gradw_offset, h1_w2, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 18 * channels + gradw_offset, h2_w0, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 21 * channels + gradw_offset, h2_w1, mask=\n gradw_mask)\n tl.store(weight_grad_ptr + 24 * channels + gradw_offset, h2_w2, mask=\n gradw_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/dw_conv.py" }, { "uuid": "2f63fe4e-4b75-45aa-b01f-c5b1eed17423", "file_name": "main_triton.py", "repo_name": "dwgan/GraphMST", "file_path": "main_triton.py", "commit_hash": "4d65ed0f108d339e3e4cfff25085a39adc6a48a2", "starcount": 0, "input": "@triton.jit\ndef find_kernel(parent, u, ret_ptr, BLOCK_SIZE: tl.constexpr):\n pu = tl.load(parent + u)\n while pu != u:\n u = pu\n pu = tl.load(parent + u)\n ret_ptr[u % BLOCK_SIZE] = pu\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dwgan/GraphMST/blob/4d65ed0f108d339e3e4cfff25085a39adc6a48a2/main_triton.py" }, { "uuid": "fee89749-a0a9-4316-87b5-75545363f010", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16]], key=['BK'])\n@triton.jit\ndef fwd_prepare_wy_repr_kernel_chunk32(k, beta, A, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BC: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.\n constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_A += tl.dot(b_kb, tl.trans(b_k), allow_tf32=False)\n b_A = -tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :],\n b_A, 0)\n for i in range(1, BT):\n mask = tl.arange(0, BT) == i\n b_a = tl.sum(tl.where(mask[:, None], b_A, 0), 0)\n b_a = b_a + tl.sum(b_a[:, None] * b_A, 0) * (tl.arange(0, BT) < i)\n b_A = tl.where(mask[:, None], b_a, b_A)\n b_A += tl.arange(0, BT)[:, None] == tl.arange(0, BT)[None, :]\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT, 0), (BT, BT), (1, 0))\n tl.store(p_A, b_A.to(p_A.dtype.element_ty), boundary_check=(0, 1))\n b_A = b_A.to(k.dtype.element_ty)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/wy_fast.py" }, { "uuid": "3ccfe00c-b0c4-4828-873a-fd5b2174ea1b", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_mean/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES_RAGGED, BLOCK_SIZES_M, NUM_WARPS,\n NUM_STAGES)], key=['M'])\n@triton.jit\ndef triton_jagged_mean_kernel_variable_length_loop_sum_then_buffer(\n input_ptr_values, input_ptr_offsets, output_ptr, M, BLOCK_SIZE_RAGGED:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_b = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((1, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_b), tl.load(\n input_ptr_offsets + (pid_b + 1))\n ragged_len = ragged_end - ragged_start\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer += tl.sum(input, axis=0)\n buffer_view = buffer.reshape((BLOCK_SIZE_M,))\n buffer_view_mean = buffer_view * (1 / ragged_len)\n output_offsets = offsets_m + pid_b * M\n output_mask = output_offsets < M * (pid_b + 1)\n tl.store(output_ptr + output_offsets, buffer_view_mean, mask=output_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_mean/kernels.py" }, { "uuid": "58fb14a4-ee5b-47db-b1e7-de8b3fd737be", "file_name": "fused_moe.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/model_executor/layers/fused_moe/fused_moe.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.jit\ndef fused_moe_kernel(a_ptr, b_ptr, c_ptr, a_scale_ptr, b_scale_ptr,\n topk_weights_ptr, sorted_token_ids_ptr, expert_ids_ptr,\n num_tokens_post_padded_ptr, N, K, EM, num_valid_tokens, stride_am,\n stride_ak, stride_be, stride_bk, stride_bn, stride_cm, stride_cn,\n stride_bse, stride_bsn, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M: tl.constexpr,\n MUL_ROUTED_WEIGHT: tl.constexpr, top_k: tl.constexpr, compute_type: tl.\n constexpr, use_fp8_w8a8: tl.constexpr, use_int8_w8a16: tl.constexpr):\n \"\"\"\n Implements the fused computation for a Mixture of Experts (MOE) using\n token and expert matrices.\n\n Key Parameters:\n - A: The input tensor representing tokens with shape (*, K), where '*' can\n be any shape representing batches and K is the feature dimension of\n each token.\n - B: The stacked MOE weight tensor with shape (E, N, K), where E is\n the number of experts, K is the input feature dimension, and N is\n the output feature dimension.\n - C: The output cache tensor with shape (M, topk, N), where M is the\n total number of tokens post padding, topk is the number of times\n each token is repeated, and N is the output feature dimension.\n - sorted_token_ids: A tensor containing the sorted indices of tokens,\n repeated topk times and arranged by the expert index they are\n assigned to.\n - expert_ids: A tensor containing the indices of the expert for each\n block. It determines which expert matrix from B should be used for\n each block in A.\n This kernel performs the multiplication of a token by its corresponding\n expert matrix as determined by `expert_ids`. The sorting of\n `sorted_token_ids` by expert index and padding ensures divisibility by\n BLOCK_SIZE_M, which is necessary to maintain consistency in block matrix\n multiplication across different blocks processed by the same expert.\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(EM, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n num_tokens_post_padded = tl.load(num_tokens_post_padded_ptr)\n if pid_m * BLOCK_SIZE_M >= num_tokens_post_padded:\n return\n offs_token_id = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)\n token_mask = offs_token < num_valid_tokens\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_token[:, None] // top_k * stride_am + offs_k[\n None, :] * stride_ak)\n off_experts = tl.load(expert_ids_ptr + pid_m)\n b_ptrs = b_ptr + off_experts * stride_be + (offs_k[:, None] * stride_bk +\n offs_bn[None, :] * stride_bn)\n if use_int8_w8a16:\n b_scale_ptrs = b_scale_ptr + off_experts * stride_bse + offs_bn[None, :\n ] * stride_bsn\n b_scale = tl.load(b_scale_ptrs)\n if use_fp8_w8a8:\n a_scale = tl.load(a_scale_ptr)\n b_scale = tl.load(b_scale_ptr + off_experts)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=token_mask[:, None] & (offs_k[None, :] < K -\n k * BLOCK_SIZE_K), other=0.0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < K - k * BLOCK_SIZE_K,\n other=0.0)\n if use_int8_w8a16:\n accumulator = tl.dot(a, b.to(compute_type), acc=accumulator)\n elif use_fp8_w8a8:\n accumulator = tl.dot(a, b, acc=accumulator)\n else:\n accumulator += tl.dot(a, b)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n if MUL_ROUTED_WEIGHT:\n moe_weight = tl.load(topk_weights_ptr + offs_token, mask=token_mask,\n other=0)\n accumulator = accumulator * moe_weight[:, None]\n if use_int8_w8a16:\n accumulator = (accumulator * b_scale).to(compute_type)\n elif use_fp8_w8a8:\n accumulator = (accumulator * a_scale * b_scale).to(compute_type)\n else:\n accumulator = accumulator.to(compute_type)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + stride_cm * offs_token[:, None] + stride_cn * offs_cn[\n None, :]\n c_mask = token_mask[:, None] & (offs_cn[None, :] < N)\n tl.store(c_ptrs, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Top-K Selection" ], "Data Type": [ "int8", "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/model_executor/layers/fused_moe/fused_moe.py" }, { "uuid": "b915901f-25e7-4e07-86fb-3ce11a600e0e", "file_name": "test_triton_varargs.py", "repo_name": "facebookresearch/xformers", "file_path": "tests/test_triton_varargs.py", "commit_hash": "a2f37f8c5f4e3ae0d3459a92e42cd1aeb45b03bc", "starcount": 0, "input": "@triton.jit\ndef kernel(x_ptrs: 'VAR_ARGS_ARRAY', y_ptrs: 'VAR_ARGS_ARRAY', numel,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n offsets = BLOCK_SIZE * pid + tl.arange(0, BLOCK_SIZE)\n mask = offsets < numel\n for i in range(len(x_ptrs)):\n x_ptr = x_ptrs[i]\n y_ptr = y_ptrs[i]\n data = tl.load(x_ptr + offsets, mask)\n result = data * data\n tl.store(y_ptr + offsets, result, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/facebookresearch/xformers/blob/a2f37f8c5f4e3ae0d3459a92e42cd1aeb45b03bc/tests/test_triton_varargs.py" }, { "uuid": "b5a86ee1-c573-4ef0-b121-3f8c69923b2c", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(list(filter(keep, configsWS)), key=['N_CTX'])\n@triton.jit\ndef _attn_fwd_ws(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v, desc_o,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.constexpr, STAGE: tl.\n constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE: tl.constexpr,\n ENABLE_WS: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n pid = tl.program_id(0)\n off_hz = tl.program_id(1)\n _attn_fwd_compute_ws(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid,\n Z, H, N_CTX, BLOCK_M, BLOCK_N, HEAD_DIM, STAGE, ENABLE_TMA,\n LOOP_SCHEDULE)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "ac3a79c4-8892-4afd-bc3a-b1376778c60f", "file_name": "parallel_scan.py", "repo_name": "chengkai-liu/RecBLR", "file_path": "parallel_scan.py", "commit_hash": "66e520c26e28c05a5425ba2e81c9169b7e0176e2", "starcount": 0, "input": "@triton.jit\ndef pack64(a, b):\n tl.static_assert(a.dtype == tl.float32)\n tl.static_assert(b.dtype == tl.float32)\n a = a.to(dtype=tl.uint32, bitcast=True).to(tl.uint64)\n a = a << 32\n b = b.to(dtype=tl.uint32, bitcast=True).to(tl.uint64)\n return a | b\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Register Intensive" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengkai-liu/RecBLR/blob/66e520c26e28c05a5425ba2e81c9169b7e0176e2/parallel_scan.py" }, { "uuid": "aeb1d88e-f7a3-4baf-ad05-a447c96fd287", "file_name": "nll_loss_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/nll_loss_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim',\n 'spatial_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_SPATIAL': lambda args: next_power_of_2(args['spatial_dim'])})\n@triton.jit\ndef nll_loss_forward_kernel(input_pointer, target_pointer, weight_pointer,\n sum_weights_pointer, output_pointer, batch_dim, spatial_dim,\n input_batch_stride, input_feat_stride, input_spatial_stride,\n target_batch_stride, target_spatial_stride, output_batch_stride,\n output_spatial_stride, reduction: tl.constexpr, weighted: tl.constexpr,\n BLOCK_SIZE_BATCH: tl.constexpr, BLOCK_SIZE_SPATIAL: tl.constexpr):\n \"\"\"\n Measures the negative log likelihood loss between the input and target,\n with optional reweighing of each class.\n\n Args:\n input_pointer: Pointer to the input.\n The input must be of shape [batch_dim, feat_dim, spatial_dim].\n target_pointer: Pointer to the target.\n The target must be of shape [batch_dim, spatial_dim].\n weight_pointer: Pointer to an optional class weight vector.\n The class weight vector, if provided, must be of shape [feat_dim].\n sum_weights_pointer: Pointer to a container the sum of the class weights is written to.\n The container must be of shape [batch_dim/BLOCK_SIZE_BATCH].\n output_pointer: Pointer to a container the loss is written to.\n The container must be of shape [batch_dim, spatial_dim] if reduction is 'none',\n and otherwise of shape [batch_dim/BLOCK_SIZE].\n batch_dim: Batch dimension.\n spatial_dim: Spatial dimension.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n input_spatial_stride: Stride necessary to jump one element along the\n input's spatial dimension.\n target_batch_stride: Stride necessary to jump one element along the\n target's batch dimension.\n target_spatial_stride: Stride necessary to jump one element along the\n target's spatial dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output container's batch dimension.\n output_spatial_stride: Stride necessary to jump one element along the\n output container's spatial dimension.\n reduction: Reduction strategy for the output.\n Options are 'none' for no reduction, 'mean' for averaging the loss\n across all entries, and 'sum' for summing the loss across all entries.\n If a reduction method is specified, the reduced result of each\n program is written to a separate index in the summed weights and\n output container, which should later be summed.\n weighted: Flag for weighing each class.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_SPATIAL: Block size across the spatial dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n spatial_offset = tl.arange(0, BLOCK_SIZE_SPATIAL)\n batch_mask = batch_offset < batch_dim\n spatial_mask = spatial_offset < spatial_dim\n target_pointer += target_batch_stride * batch_offset[:, None\n ] + target_spatial_stride * spatial_offset[None, :]\n target = tl.load(target_pointer, mask=batch_mask[:, None] &\n spatial_mask[None, :])\n input_pointer += (input_feat_stride * target + input_batch_stride *\n batch_offset[:, None] + input_spatial_stride * spatial_offset[None, :])\n input = tl.load(input_pointer, mask=batch_mask[:, None] & spatial_mask[\n None, :]).to(tl.float32)\n output = -input\n if weighted:\n weight = tl.load(weight_pointer + target, mask=batch_mask[:, None] &\n spatial_mask[None, :]).to(tl.float32)\n output *= weight\n if reduction == 'none':\n output_pointer += output_batch_stride * batch_offset[:, None\n ] + output_spatial_stride * spatial_offset[None, :]\n tl.store(output_pointer, output, mask=batch_mask[:, None] &\n spatial_mask[None, :])\n elif reduction == 'mean':\n if weighted:\n tl.store(sum_weights_pointer + batch_pid, tl.sum(weight))\n tl.store(output_pointer + batch_pid, tl.sum(output))\n else:\n tl.store(output_pointer + batch_pid, tl.sum(output) / (\n batch_dim * spatial_dim))\n elif reduction == 'sum':\n tl.store(output_pointer + batch_pid, tl.sum(output))\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/nll_loss_kernels.py" }, { "uuid": "f9da9e73-4afd-45c7-a28d-2725468622a1", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=warps) for warps in [\n 4, 8, 16]], key=['QUERY_GROUP_SIZE', 'HEAD_SIZE', 'NUM_PARTITIONS',\n 'PARTITION_SIZE'])\n@triton.jit\ndef _paged_attn_w_mma_v2_reduce_kernel(out_ptr, m_i_ptr, l_i_ptr,\n tmp_out_ptr, context_lens_ptr, max_num_partitions, stride_o0, stride_o1,\n stride_o2, HEAD_SIZE: tl.constexpr, QUERY_GROUP_SIZE: tl.constexpr,\n PADDED_QUERY_GROUP_SIZE: tl.constexpr, NUM_KV_HEADS: tl.constexpr,\n PARTITION_SIZE: tl.constexpr, NUM_PARTITIONS: tl.constexpr):\n seq_idx = tl.program_id(0)\n kv_head_idx = tl.program_id(1)\n context_len = tl.load(context_lens_ptr + seq_idx)\n num_partitions = tl.cdiv(context_len, PARTITION_SIZE)\n group_head_offset = tl.arange(0, PADDED_QUERY_GROUP_SIZE)[:, None\n ] * HEAD_SIZE + tl.arange(0, HEAD_SIZE)[None, :]\n group_mask = tl.arange(0, PADDED_QUERY_GROUP_SIZE)[:, None\n ] < QUERY_GROUP_SIZE\n if num_partitions == 1:\n tmp_out_offset = ((seq_idx * NUM_KV_HEADS + kv_head_idx) *\n max_num_partitions * QUERY_GROUP_SIZE * HEAD_SIZE +\n group_head_offset)\n tmp_out = tl.load(tmp_out_ptr + tmp_out_offset, mask=group_mask,\n other=0.0)\n out_offset = (seq_idx * stride_o0 + kv_head_idx * QUERY_GROUP_SIZE *\n stride_o1 + group_head_offset * stride_o2)\n tl.store(out_ptr + out_offset, tmp_out, mask=group_mask)\n return\n ml_offset = (seq_idx * NUM_KV_HEADS + kv_head_idx\n ) * max_num_partitions * QUERY_GROUP_SIZE + tl.arange(0, NUM_PARTITIONS\n )[:, None] * QUERY_GROUP_SIZE + tl.arange(0, PADDED_QUERY_GROUP_SIZE)[\n None, :]\n mask = (tl.arange(0, NUM_PARTITIONS)[:, None] < num_partitions) & (tl.\n arange(0, PADDED_QUERY_GROUP_SIZE)[None, :] < QUERY_GROUP_SIZE)\n m_i = tl.load(m_i_ptr + ml_offset, mask=mask, other=float('-inf'))\n m = tl.max(m_i, axis=0)\n l_i = tl.load(l_i_ptr + ml_offset, mask=mask, other=0.0)\n l_i *= tl.exp(m_i - m[None, :])\n l = tl.sum(l_i, axis=0)\n r = l_i / l[None, :]\n r = tl.reshape(r, (NUM_PARTITIONS, PADDED_QUERY_GROUP_SIZE, 1))\n tmp_out_offset = (seq_idx * NUM_KV_HEADS + kv_head_idx\n ) * max_num_partitions * QUERY_GROUP_SIZE * HEAD_SIZE + tl.arange(0,\n NUM_PARTITIONS)[:, None, None\n ] * QUERY_GROUP_SIZE * HEAD_SIZE + tl.arange(0, PADDED_QUERY_GROUP_SIZE\n )[None, :, None] * HEAD_SIZE + tl.arange(0, HEAD_SIZE)[None, None, :]\n tmp_out = tl.load(tmp_out_ptr + tmp_out_offset, mask=mask[:, :, None],\n other=0.0)\n out = tl.sum((tmp_out * r).to(tl.float32), axis=0)\n out_offset = (seq_idx * stride_o0 + kv_head_idx * QUERY_GROUP_SIZE *\n stride_o1 + group_head_offset * stride_o2)\n tl.store(out_ptr + out_offset, out, mask=group_mask)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "fbbb8e30-59c7-4345-a0af-c5932ca05a42", "file_name": "hello_triton.py", "repo_name": "gmgu/study-triton", "file_path": "1_hello_triton/hello_triton.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@triton.jit\ndef hello_kernel():\n print('Hello Triton Kernel!')\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/1_hello_triton/hello_triton.py" }, { "uuid": "89417c21-0b2b-4b0f-bb94-3113c88d8895", "file_name": "adam.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/adam.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_adam_kernel(params_ptr, grads_ptr, exp_avgs_ptr, exp_avg_sqs_ptr,\n noop_flag_ptr, scale_ptr, step_size, beta1, beta2, bias_correction,\n decay_factor, epsilon, numel: tl.constexpr, block_size: tl.constexpr):\n noop_flag = tl.load(noop_flag_ptr)\n if noop_flag != 0:\n return\n scale = tl.load(scale_ptr)\n block_start = tl.program_id(axis=0).to(tl.int64) * block_size\n offsets = block_start + tl.arange(0, block_size)\n mask = offsets < numel\n params = tl.load(params_ptr + offsets, mask=mask)\n grads = tl.load(grads_ptr + offsets, mask=mask)\n grads = scale * grads\n exp_avgs = tl.load(exp_avgs_ptr + offsets, mask=mask)\n exp_avgs = beta1 * exp_avgs + (1 - beta1) * grads\n tl.store(exp_avgs_ptr + offsets, exp_avgs, mask=mask)\n exp_avg_sqs = tl.load(exp_avg_sqs_ptr + offsets, mask=mask)\n exp_avg_sqs = beta2 * exp_avg_sqs + (1 - beta2) * grads * grads\n tl.store(exp_avg_sqs_ptr + offsets, exp_avg_sqs, mask=mask)\n params = decay_factor * params - step_size * exp_avgs / (tl.sqrt(\n exp_avg_sqs) / bias_correction + epsilon)\n tl.store(params_ptr + offsets, params, mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/adam.py" }, { "uuid": "b21323e3-f171-4003-9eda-bd4fcfee5aff", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef make_bounds(offs_m, offs_n, M, N, EVEN_M: tl.constexpr, EVEN_N: tl.\n constexpr):\n if EVEN_M:\n mask = offs_n[None, :] < N\n elif EVEN_N:\n mask = offs_m[:, None] < M\n else:\n mask = (offs_m[:, None] < M) & (offs_n[None, :] < N)\n return mask\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "5f6f1215-91df-4856-935d-ad21674c7526", "file_name": "rwkv_log.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/rwkv_log.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef logaddexp(a, b):\n max_ab = tl.maximum(a, b)\n return max_ab + tl.log(tl.exp(a - max_ab) + tl.exp(b - max_ab))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/rwkv_log.py" }, { "uuid": "aeaaa009-521f-43fd-884c-f286d78d2d44", "file_name": "fused_linear_cross_entropy.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_linear_cross_entropy.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef cross_entropy_kernel(logits, lse, target, loss, total, ignore_index,\n label_smoothing: tl.constexpr, logit_scale: tl.constexpr, reduction: tl\n .constexpr, V: tl.constexpr, BV: tl.constexpr):\n \"\"\"\n This kernel computes both cross entropy loss and the gradient of the input.\n We only consider hard label + mean reduction for now.\n Please refer to https://pytorch.org/docs/stable/generated/torch.nn.CrossEntropyLoss.html for the math.\n\n Args:\n logits:\n Pointer to logits tensor.\n lse:\n Pointer to logsumexp tensor.\n target: Pointer to target tensor.\n loss:\n Pointer to tensor to store the loss.\n V (int):\n The number of columns in the input tensor.\n total (int):\n The number of non-ignored classes.\n ignore_index (int):\n The index to ignore in the target.\n label_smoothing (float):\n The amount of smoothing when computing the loss, where 0.0 means no smoothing.\n reduction (str):\n The string for the reduction to apply\n BV (int):\n The block size for vocab.\n \"\"\"\n i_n = tl.program_id(0).to(tl.int64)\n NV = tl.cdiv(V, BV)\n b_y = tl.load(target + i_n)\n logits += i_n * V\n if b_y == ignore_index:\n for i in range(0, V, BV):\n o_v = i + tl.arange(0, BV)\n tl.store(logits + o_v, 0.0, mask=o_v < V)\n return\n b_l = tl.load(logits + b_y) * logit_scale\n b_lse = tl.load(lse + i_n)\n b_loss = b_lse - b_l\n b_z = 0.0\n eps = label_smoothing / V\n tl.debug_barrier()\n for iv in range(0, NV):\n o_v = iv * BV + tl.arange(0, BV)\n b_logits = tl.load(logits + o_v, mask=o_v < V, other=float('-inf')\n ) * logit_scale\n if label_smoothing > 0:\n b_z += tl.sum(tl.where(o_v < V, -eps * b_logits, 0.0))\n b_p = (tl.exp(b_logits - b_lse) - eps) * logit_scale\n if reduction == 'mean':\n b_p = b_p / total\n tl.store(logits + o_v, b_p, mask=o_v < V)\n tl.debug_barrier()\n if label_smoothing > 0:\n b_loss = b_loss * (1 - label_smoothing) + (b_z + label_smoothing *\n b_lse)\n b_l = tl.load(logits + b_y)\n if reduction == 'mean':\n b_loss = b_loss / total\n b_l += (label_smoothing - 1) / total * logit_scale\n else:\n b_l += (label_smoothing - 1) * logit_scale\n tl.store(loss + i_n, b_loss)\n tl.store(logits + b_y, b_l)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_linear_cross_entropy.py" }, { "uuid": "0259cfec-6015-444e-944d-75eaa64eb07f", "file_name": "y_4.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_4.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef fourth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor,\n block_size: tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.\n constexpr, col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST000 = 1.125\n CONST001 = 2.25\n CONST002 = 3.0\n CONST005 = 2.21852991866236\n CONST007 = 9.48683298050514\n CONST010 = 20.1246117974981\n CONST011 = -18.8248505970167\n CONST012 = -13.3111795119741\n CONST013 = -10.0623058987491\n CONST014 = -9.0\n CONST015 = -8.87411967464942\n CONST016 = -7.11512473537885\n CONST017 = -6.27495019900557\n CONST018 = -3.35410196624968\n CONST019 = -1.67705098312484\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n Y00 = CONST015 * VAR07 * z - CONST015 * VAR25 * x\n Y01 = y * (-CONST011 * VAR26 * x + CONST017 * VAR07)\n Y02 = CONST018 * VAR07 * z + x * (CONST010 * VAR17 * z + CONST018 * VAR25)\n Y03 = CONST016 * VAR07 * y + x * (CONST007 * VAR16 + CONST016 * VAR26 * y)\n Y04 = (CONST000 * VAR06 + CONST000 * VAR24 + CONST002 * VAR15 + \n CONST014 * VAR17 * VAR26 + VAR08 * (CONST001 * VAR26 + CONST014 *\n VAR17))\n Y05 = CONST016 * VAR25 * y + z * (CONST007 * VAR16 + CONST016 * VAR08 * y)\n Y06 = -CONST019 * VAR06 + CONST019 * VAR24 + VAR17 * (CONST013 * VAR08 -\n CONST013 * VAR26)\n Y07 = y * (CONST011 * VAR08 * z - CONST017 * VAR25)\n Y08 = CONST005 * VAR06 + CONST005 * VAR24 + CONST012 * VAR08 * VAR26\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_4.py" }, { "uuid": "99554c85-0a2d-42e8-ab1a-65744f560890", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BC'])\n@triton.jit\ndef chunk_gla_fwd_A_kernel_intra_sub_intra_merge(A, A2, offsets, indices, B:\n tl.constexpr, T: tl.constexpr, H: tl.constexpr, BT: tl.constexpr, BC:\n tl.constexpr, NK: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_t, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n if i_t * BT + i_c * BC >= T:\n return\n b_A = tl.zeros([BC, BC], dtype=tl.float32)\n for i_k in range(0, NK):\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + (i_k * B * H + i_bh) * T * BC, (T,\n BC), (BC, 1), (i_t * BT + i_c * BC, 0), (BC, BC), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (i_k * all + bos) * H * BC + i_h *\n BC, (T, BC), (H * BC, 1), (i_t * BT + i_c * BC, 0), (BC, BC\n ), (1, 0))\n b_A += tl.load(p_A, boundary_check=(0, 1))\n if HEAD_FIRST:\n p_A2 = tl.make_block_ptr(A2 + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_c * BC, i_c * BC), (BC, BC), (1, 0))\n else:\n p_A2 = tl.make_block_ptr(A2 + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT + i_c * BC, i_c * BC), (BC, BC), (1, 0))\n tl.store(p_A2, b_A.to(A2.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "58b3463b-151f-4a0e-bc35-134133839e16", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_V(q, v, z, h, o, A, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, s_h_h, s_h_t, s_h_d, scale, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_p = tl.maximum(i_t * BT - 1, 0)\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, s_h_d), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_zp = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), (i_p *\n K + i_k * BK,), (BK,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_zp = tl.load(p_zp, boundary_check=(0,))\n b_q = (b_q * tl.exp(b_zp[None, :] - b_z)).to(b_q.dtype)\n b_h = tl.load(p_h, boundary_check=(0, 1))\n if i_k >= 0:\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t * BT,\n 0), (BT, BT), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_o += tl.dot(b_A, b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "466944e0-8df6-43af-8e5a-f9a4513cce97", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef fwd_recompute_w_u_kernel(k, v, beta, w, u, Aw, Au, offsets, indices, T:\n tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl\n .constexpr, BK: tl.constexpr, BV: tl.constexpr, HEAD_FIRST: tl.\n constexpr, USE_OFFSETS: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_Au = tl.make_block_ptr(Au + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_Au = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_Au = tl.load(p_Au, boundary_check=(0, 1))\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_u = tl.make_block_ptr(u + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_u = tl.make_block_ptr(u + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_vb = (b_v * b_beta[:, None]).to(b_v.dtype)\n b_u = tl.dot(b_Au, b_vb, allow_tf32=False)\n tl.store(p_u, b_u.to(p_u.dtype.element_ty), boundary_check=(0, 1))\n tl.debug_barrier()\n b_Au = None\n if HEAD_FIRST:\n p_Aw = tl.make_block_ptr(Aw + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_Aw = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_Aw = tl.load(p_Aw, boundary_check=(0, 1))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_w = tl.dot(b_Aw, b_kb)\n tl.store(p_w, b_w.to(p_w.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/wy_fast.py" }, { "uuid": "b7a78b7c-edba-48ab-88b8-0d8b4fa84948", "file_name": "normalization.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/normalization.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_normalization_backward_kernel_2(grad_weight_partial_ptr,\n grad_bias_partial_ptr, grad_weight_ptr, grad_bias_ptr, m, n_cols,\n has_bias: tl.constexpr, accumulate_grad: tl.constexpr, block_size_m: tl\n .constexpr, block_size_n: tl.constexpr):\n pid = tl.program_id(0)\n cols = pid * block_size_n + tl.arange(0, block_size_n)\n grad_weight_partial_sum = tl.zeros((block_size_m, block_size_n), dtype=\n tl.float32)\n if has_bias:\n grad_bias_partial_sum = tl.zeros((block_size_m, block_size_n),\n dtype=tl.float32)\n col_mask = cols < n_cols\n for i in range(0, m, block_size_m):\n rows = i + tl.arange(0, block_size_m)\n mask = (rows[:, None] < m) & (cols[None, :] < n_cols)\n offsets = rows[:, None] * n_cols + cols[None, :]\n grad_weight_partial_sum += tl.load(grad_weight_partial_ptr +\n offsets, mask=mask, other=0.0)\n if has_bias:\n grad_bias_partial_sum += tl.load(grad_bias_partial_ptr +\n offsets, mask=mask, other=0.0)\n grad_weight = tl.sum(grad_weight_partial_sum, axis=0)\n if accumulate_grad:\n grad_weight = tl.load(grad_weight_ptr + cols, mask=col_mask\n ) + grad_weight\n tl.store(grad_weight_ptr + cols, grad_weight, mask=col_mask)\n if has_bias:\n grad_bias = tl.sum(grad_bias_partial_sum, axis=0)\n if accumulate_grad:\n grad_bias = tl.load(grad_bias_ptr + cols, mask=col_mask\n ) + grad_bias\n tl.store(grad_bias_ptr + cols, grad_bias, mask=col_mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/normalization.py" }, { "uuid": "26e4d111-f4aa-445c-91fa-fcdaff284554", "file_name": "k_layer_norm.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_layer_norm.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_no_affine_bwd(DX, DY, Y, V, stride, N, **META):\n row = tl.program_id(0)\n cols = tl.arange(0, META['BLOCK_SIZE_N'])\n y_ptrs = Y + row * stride + cols\n dy_ptrs = DY + row * stride + cols\n y = tl.load(y_ptrs, mask=cols < N, other=0).to(tl.float32)\n dy = tl.load(dy_ptrs, mask=cols < N, other=0).to(tl.float32)\n rstd = tl.load(V + row)\n xhat = tl.where(cols < N, y, 0.0)\n wdy = tl.where(cols < N, dy, 0.0)\n mean1 = tl.sum(xhat * wdy, axis=0) / N\n mean2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * mean1 + mean2)) * rstd\n _store(dx, DX, stride, N, META)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_layer_norm.py" }, { "uuid": "8cfb5a84-099f-41cc-9d64-f30e70e6e39b", "file_name": "quantization.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/quantization.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _QuantUint8Window_impl(input_ptr, output_ptr, numel, window, BLOCK_SIZE:\n tl.constexpr):\n tid = tl.program_id(0)\n input_ptr += tid * BLOCK_SIZE\n output_ptr += tid * BLOCK_SIZE\n offset = tl.arange(0, BLOCK_SIZE)\n mask = offset < numel - tid * BLOCK_SIZE\n input = tl.load(input_ptr + offset, mask=mask).to(tl.float32)\n input = tl.minimum(tl.maximum(input, -window), window)\n input = (input + window) / (2 * window)\n input *= 255\n input = input.to(tl.uint8)\n tl.store(output_ptr + offset, input, mask=mask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "uint8" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/quantization.py" }, { "uuid": "ecb649cc-99a1-47b3-abec-69aff2b74328", "file_name": "kernel_benchmark.py", "repo_name": "ruikangliu/FlatQuant", "file_path": "benchmarks/kernel_benchmark.py", "commit_hash": "9d3032065f1688cb3f71ebc8166df6d91440e871", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_stages=2, num_warps=4),\n triton.Config({}, num_stages=2, num_warps=2), triton.Config({},\n num_stages=3, num_warps=4), triton.Config({}, num_stages=3, num_warps=2\n ), triton.Config({}, num_stages=4, num_warps=4), triton.Config({},\n num_stages=4, num_warps=2)], key=['B', 'M', 'N'])\n@triton.jit\ndef matmul_kernel(a_ptr, b_ptr, c_ptr, res_ptr, output_scale, B, M: tl.\n constexpr, N: tl.constexpr, np2_M: tl.constexpr, np2_N: tl.constexpr,\n stride_am, stride_ak, stride_bb, stride_bk, stride_bn, stride_ck,\n stride_cn, stride_resb, stride_resm, stride_resn, BLOCK_SIZE_M: tl.\n constexpr, is_split: tl.constexpr):\n \"\"\"\n a @ b @ c\n\n a [M, M]\n b [B, M, N]\n c [N, N]\n\n now only supports BLOCK_SIZE_M == triton.next_power_of_2(BLOCK_SIZE_M)\n \"\"\"\n pid = tl.program_id(axis=0)\n batch_id = tl.program_id(axis=1) + tl.program_id(axis=2) * tl.num_programs(\n axis=1)\n pid_m = pid\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_bn = tl.arange(0, np2_N) % N\n offs_k = tl.arange(0, np2_M)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + batch_id * stride_bb.to(tl.int64) + (offs_k[:, None] *\n stride_bk + offs_bn[None, :] * stride_bn)\n accumulator = tl.zeros((BLOCK_SIZE_M, np2_N), dtype=tl.float32)\n a = tl.load(a_ptrs, mask=offs_k[None, :] < M, other=0.0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < M, other=0.0)\n accumulator += tl.dot(a, b)\n tmp_ab = accumulator.to(tl.float16)\n offs_cn = tl.arange(0, np2_N) % N\n offs_k = tl.arange(0, np2_N)\n c_ptrs = c_ptr + (offs_k[:, None] * stride_ck + offs_cn[None, :] *\n stride_cn)\n c = tl.load(c_ptrs, mask=offs_k[:, None] < N, other=0.0)\n accumulator = 0\n accumulator += tl.dot(tmp_ab, c)\n if is_split:\n res = accumulator.to(tl.float16)\n offs_resm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_resn = tl.arange(0, np2_N)\n res_ptrs = res_ptr + stride_resb.to(tl.int64\n ) * batch_id + stride_resm * offs_resm[:, None\n ] + stride_resn * offs_resn[None, :]\n res_mask = (offs_resm[:, None] < M) & (offs_resn[None, :] < N)\n tl.store(res_ptrs, res, mask=res_mask)\n else:\n abs_src_val = tl.abs(accumulator)\n max_src_val = tl.max(abs_src_val)\n scale = max_src_val / 7.0\n quant_val = libdevice.llrint(accumulator / scale)\n quant_val = max(-8, min(quant_val, 7))\n quant_val = quant_val.reshape(BLOCK_SIZE_M, np2_N // 2, 2,\n can_reorder=False)\n quant_val_even, quant_val_odd = quant_val.split()\n quant_val_odd = quant_val_odd << 4\n res = tl.zeros((BLOCK_SIZE_M, np2_N // 2), dtype=tl.int8)\n res = res | quant_val_odd & 240\n res = res | quant_val_even & 15\n offs_resm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_resn = tl.arange(0, np2_N // 2)\n res_ptrs = res_ptr + stride_resb.to(tl.int64\n ) * batch_id + stride_resm * offs_resm[:, None\n ] + stride_resn * offs_resn[None, :]\n res_mask = (offs_resm[:, None] < M) & (offs_resn[None, :] < N // 2)\n tl.store(res_ptrs, res, mask=res_mask)\n tl.store(output_scale + batch_id, scale.to(tl.float16))\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "fp32", "fp16", "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ruikangliu/FlatQuant/blob/9d3032065f1688cb3f71ebc8166df6d91440e871/benchmarks/kernel_benchmark.py" }, { "uuid": "06a01956-3562-48af-87d8-0ba21f8d29e7", "file_name": "fused_moe_a8w8.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/fused_moe_a8w8.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _fused_moe_a8w8_kernel(A, B, C, alpha_row_ptr, alpha_col_ptr,\n topk_weights_ptr, sorted_token_ids_ptr, expert_ids_ptr,\n num_tokens_post_padded_ptr, N, K, EM, num_valid_tokens, stride_am,\n stride_ak, stride_be, stride_bn, stride_bk, stride_cm, stride_cn,\n stride_scale_be, stride_scale_bn, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr, MUL_ROUTED_WEIGHT: tl.constexpr, top_k: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(EM, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n num_tokens_post_padded = tl.load(num_tokens_post_padded_ptr)\n if pid_m * BLOCK_SIZE_M >= num_tokens_post_padded:\n return\n offs_token_id = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)\n token_mask = offs_token < num_valid_tokens\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = A + (offs_token[:, None] // top_k * stride_am + offs_k[None, :\n ] * stride_ak)\n off_experts = tl.load(expert_ids_ptr + pid_m)\n b_ptrs = B + off_experts * stride_be + (offs_bn[None, :] * stride_bn + \n offs_k[:, None] * stride_bk)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.int32)\n _A0 = tl.zeros([1, 1], dtype=a_ptrs.dtype.element_ty)\n _B0 = tl.zeros([1, 1], dtype=b_ptrs.dtype.element_ty)\n lo = 0\n hi = tl.cdiv(K, BLOCK_SIZE_K)\n for k in range(lo, hi - 1):\n a = tl.load(a_ptrs, mask=token_mask[:, None], other=_A0)\n b = tl.load(b_ptrs)\n accumulator += tl.dot(a, b)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n for k in range(hi - 1, hi):\n a = tl.load(a_ptrs, mask=token_mask[:, None] & (offs_k[None, :] < K -\n k * BLOCK_SIZE_K), other=_A0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < K - k * BLOCK_SIZE_K,\n other=_B0)\n accumulator += tl.dot(a, b)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n offs_token_id = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)\n token_mask = offs_token < num_valid_tokens\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n alpha_row_ptrs = alpha_row_ptr + offs_token // top_k\n alpha_col_ptrs = alpha_col_ptr + off_experts * stride_scale_be + offs_cn\n _ALPHA0 = tl.zeros([1], dtype=alpha_row_ptr.dtype.element_ty)\n alpha_row = tl.load(alpha_row_ptrs, mask=token_mask, other=_ALPHA0).to(tl\n .float32)\n alpha_col = tl.load(alpha_col_ptrs, mask=offs_cn < N, other=_ALPHA0).to(tl\n .float32)\n accumulator = accumulator * alpha_row[:, None]\n accumulator = accumulator * alpha_col[None, :]\n if MUL_ROUTED_WEIGHT:\n moe_weight = tl.load(topk_weights_ptr + offs_token, mask=token_mask,\n other=0)\n accumulator = accumulator * moe_weight[:, None]\n accumulator = accumulator.to(tl.float16)\n c_ptrs = C + stride_cm * offs_token[:, None] + stride_cn * offs_cn[None, :]\n c_mask = token_mask[:, None] & (offs_cn[None, :] < N)\n tl.store(c_ptrs, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Top-K Selection" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/fused_moe_a8w8.py" }, { "uuid": "18bdbd68-3013-4acb-9efe-c2827d61c4ee", "file_name": "y_7.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_7.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef seventh_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_9 = tl.load(sph_grad_ptr + output_row_offset + 9, mask=\n output_row_offset + 9 < output_numel)\n g_10 = tl.load(sph_grad_ptr + output_row_offset + 10, mask=\n output_row_offset + 10 < output_numel)\n g_11 = tl.load(sph_grad_ptr + output_row_offset + 11, mask=\n output_row_offset + 11 < output_numel)\n g_12 = tl.load(sph_grad_ptr + output_row_offset + 12, mask=\n output_row_offset + 12 < output_numel)\n g_13 = tl.load(sph_grad_ptr + output_row_offset + 13, mask=\n output_row_offset + 13 < output_numel)\n g_14 = tl.load(sph_grad_ptr + output_row_offset + 14, mask=\n output_row_offset + 14 < output_numel)\n CONST000 = 1.66389743899677\n CONST001 = 3.0\n CONST003 = 5.0\n CONST004 = 3.32779487799353\n CONST009 = 11.7655316231354\n CONST012 = 16.5555704843566\n CONST014 = 20.4939015319192\n CONST016 = 22.0740939791422\n CONST018 = 23.5310632462709\n CONST019 = 20.4939015319192\n CONST020 = 27.1108834234519\n CONST022 = 33.1111409687132\n CONST024 = 36.7901566319036\n CONST025 = 36.7901566319036\n CONST026 = 38.4260653723485\n CONST027 = 38.4260653723485\n CONST029 = 38.4260653723485\n CONST030 = 44.1481879582843\n CONST032 = -4.9916923169903\n CONST037 = 47.0621264925417\n CONST039 = 56.2781179722634\n CONST044 = -441.481879582843\n CONST045 = -441.481879582843\n CONST048 = 76.852130744697\n CONST049 = 76.852130744697\n CONST050 = -8.47215106982872\n CONST054 = 110.370469895711\n CONST055 = 110.370469895711\n CONST056 = -399.335385359224\n CONST057 = 117.655316231354\n CONST058 = 122.963409191515\n CONST059 = 122.963409191515\n CONST061 = -376.497011940334\n CONST062 = -376.497011940334\n CONST064 = 141.186379477625\n CONST066 = 147.160626527614\n CONST067 = 153.704261489394\n CONST069 = -350.955726374425\n CONST072 = 203.331625675889\n CONST073 = 203.331625675889\n CONST074 = -307.408522978788\n CONST075 = -9.60651634308713\n CONST076 = -9.37968632871057\n CONST079 = -281.390589861317\n CONST080 = -1.66389743899677\n CONST081 = -266.223590239483\n CONST082 = -263.216794780819\n CONST084 = -263.216794780818\n CONST085 = -250.998007960223\n CONST089 = 281.390589861317\n CONST091 = -220.740939791422\n CONST092 = -220.740939791422\n CONST093 = -199.667692679612\n CONST094 = -1.60108605718119\n CONST095 = -187.593726574211\n CONST096 = -177.482393492989\n CONST097 = -9.60651634308712\n CONST098 = -9.1975391579759\n CONST100 = -153.704261489394\n CONST101 = -147.160626527614\n CONST102 = -140.695294930659\n CONST104 = -133.111795119741\n CONST105 = -133.111795119741\n CONST106 = -125.499003980111\n CONST107 = -125.499003980111\n CONST109 = -105.286717912327\n CONST110 = -101.665812837945\n CONST111 = -99.833846339806\n CONST112 = -101.665812837945\n CONST113 = -4.80325817154356\n CONST114 = -81.3326502703558\n CONST115 = -81.3326502703557\n CONST116 = -76.852130744697\n CONST117 = -75.2994023880668\n CONST119 = -70.5931897388126\n CONST121 = -66.2222819374265\n CONST122 = -66.5558975598707\n CONST123 = -66.5558975598707\n CONST124 = -62.7495019900557\n CONST125 = -56.2781179722634\n CONST126 = -55.1852349478554\n CONST127 = -55.1852349478554\n CONST128 = -50.8329064189723\n CONST129 = -50.8329064189723\n CONST130 = -562.781179722634\n CONST131 = -47.0621264925418\n CONST132 = -50.8329064189724\n CONST133 = -44.1481879582843\n CONST134 = -44.3705983732471\n CONST135 = -40.6663251351779\n CONST136 = -40.6663251351779\n CONST137 = -8.31948719498384\n CONST138 = -37.6497011940334\n CONST139 = -33.2779487799353\n CONST140 = -29.9501539019418\n CONST141 = -25.4164532094862\n CONST142 = -25.4164532094862\n CONST143 = -23.5310632462709\n CONST144 = -532.447180478965\n CONST145 = -19.2130326861743\n CONST146 = -17.5477863187212\n CONST147 = -12.8765548211663\n CONST148 = -11.6472820729774\n CONST149 = -11.2076024002683\n CONST150 = -9.1975391579759\n CONST151 = -11.0370469895711\n CONST152 = -11.7655316231354\n CONST153 = -12.8765548211663\n CONST154 = -4.80325817154356\n CONST155 = -3.32779487799353\n CONST156 = -1.60108605718119\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR16 = y * y * y\n VAR17 = y * y\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR15 = VAR17 * VAR17\n VAR25 = z * z * z\n VAR26 = z * z\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n VAR24 = VAR26 * VAR26\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += g_0 * (CONST082 * VAR08 * VAR24 - CONST084 * VAR06 * VAR26 + \n CONST146 * VAR04 - CONST146 * VAR22) + g_1 * y * (CONST039 * VAR23 +\n CONST089 * VAR06 * z + CONST130 * VAR08 * VAR25) + g_10 * (CONST155 *\n VAR23 * x + VAR25 * (-CONST105 * VAR17 * x + CONST139 * VAR07) + z *\n (-CONST056 * VAR07 * VAR17 + CONST081 * VAR15 * x + CONST140 * VAR05)\n ) + g_11 * (VAR16 * (CONST044 * VAR26 * x - CONST101 * VAR07) + y *\n (CONST054 * VAR24 * x - CONST091 * VAR07 * VAR26 + CONST121 * VAR05)\n ) + g_12 * (CONST022 * VAR23 * x + VAR25 * (CONST024 * VAR07 + \n CONST045 * VAR17 * x) + z * (-CONST044 * VAR07 * VAR17 + CONST126 *\n VAR05)) + g_13 * y * (CONST079 * VAR24 * x + CONST125 * VAR05 - \n CONST130 * VAR07 * VAR26) + g_14 * (-CONST069 * VAR07 * VAR25 + \n CONST109 * VAR05 * z + CONST109 * VAR23 * x) + g_2 * (CONST001 *\n VAR08 * (CONST091 * VAR17 * VAR26 - CONST150 * VAR24) + CONST003 *\n VAR06 * (CONST012 * VAR26 + CONST016 * VAR17) + CONST055 * VAR17 *\n VAR24 + CONST147 * VAR04 + CONST150 * VAR22) + g_3 * (VAR16 * (\n CONST044 * VAR08 * z + CONST066 * VAR25) + y * (-CONST091 * VAR06 *\n z + CONST133 * VAR23)) + g_4 * (CONST001 * VAR08 * (CONST122 *\n VAR17 * VAR26 + CONST134 * VAR15 - CONST137 * VAR24) + CONST003 *\n VAR06 * (CONST000 * VAR26 - CONST139 * VAR17) - CONST032 * VAR22 - \n CONST105 * VAR15 * VAR26 + CONST111 * VAR17 * VAR24 + CONST148 * VAR04\n ) + g_5 * (CONST001 * VAR08 * (CONST106 * VAR16 * z - CONST131 *\n VAR25 * y) + CONST057 * VAR06 * y * z + CONST107 * VAR16 * VAR25 - \n CONST117 * VAR14 * z - CONST143 * VAR23 * y) + g_6 * (CONST001 *\n VAR08 * (CONST116 * VAR15 - CONST116 * VAR17 * VAR26 + CONST154 *\n VAR24) + CONST003 * VAR06 * (CONST026 * VAR17 + CONST113 * VAR26) +\n CONST014 * VAR13 + CONST027 * VAR17 * VAR24 + CONST116 * VAR15 *\n VAR26 + CONST149 * VAR04 + CONST156 * VAR22) + g_7 * (CONST114 *\n VAR14 * x + VAR16 * (CONST072 * VAR07 + CONST073 * VAR26 * x) + y *\n (CONST110 * VAR07 * VAR26 + CONST128 * VAR05 + CONST129 * VAR24 * x)\n ) + g_8 * (CONST075 * VAR23 * x + VAR25 * (-CONST100 * VAR17 * x + \n CONST145 * VAR07) + z * (CONST067 * VAR07 * VAR17 + CONST097 *\n VAR05 + CONST100 * VAR15 * x)) + g_9 * (-CONST085 * VAR07 * VAR16 +\n CONST117 * VAR14 * x + y * (CONST018 * VAR24 * x + CONST119 * VAR05 +\n CONST131 * VAR07 * VAR26))\n g_y += g_1 * (CONST039 * VAR23 * x + CONST095 * VAR07 * VAR25 - \n CONST125 * VAR05 * z) + g_10 * (CONST123 * VAR23 * y + VAR25 * (-\n CONST096 * VAR16 - CONST105 * VAR08 * y) + z * (-CONST093 * VAR06 *\n y + CONST144 * VAR08 * VAR16)) + g_11 * (CONST001 * VAR17 * (\n CONST025 * VAR06 + CONST025 * VAR24 + CONST092 * VAR08 * VAR26) - \n CONST126 * VAR06 * VAR26 - CONST126 * VAR08 * VAR24 + CONST151 *\n VAR04 + CONST151 * VAR22) + g_12 * (CONST030 * VAR23 * y + CONST045 *\n VAR08 * VAR25 * y - CONST092 * VAR06 * y * z) + g_13 * (CONST076 *\n VAR04 - CONST076 * VAR22 - CONST102 * VAR06 * VAR26 + CONST102 *\n VAR08 * VAR24) + g_2 * (CONST030 * VAR05 * y + CONST045 * VAR07 *\n VAR26 * y - CONST092 * VAR24 * x * y) + g_3 * (CONST001 * VAR17 * (\n CONST066 * VAR25 * x + CONST101 * VAR07 * z) - CONST133 * VAR05 * z +\n CONST133 * VAR23 * x) + g_4 * (-CONST123 * VAR05 * y + VAR07 * (\n CONST096 * VAR16 + CONST104 * VAR26 * y) + x * (CONST093 * VAR24 *\n y - CONST144 * VAR16 * VAR26)) + g_5 * (-CONST143 * VAR05 * z + \n VAR07 * (CONST062 * VAR17 * z - CONST131 * VAR25) + x * (CONST061 *\n VAR17 * VAR25 - CONST062 * VAR15 * z - CONST143 * VAR23)) + g_6 * (\n CONST048 * VAR05 * y + VAR07 * (CONST074 * VAR16 - CONST100 * VAR26 *\n y) + x * (CONST058 * VAR14 + CONST074 * VAR16 * VAR26 - CONST116 *\n VAR24 * y)) + g_7 * (CONST001 * VAR17 * (-CONST112 * VAR08 * VAR26 -\n CONST128 * VAR06 - CONST128 * VAR24) + CONST003 * VAR15 * (CONST135 *\n VAR08 + CONST136 * VAR26) + CONST020 * VAR13 + CONST050 * VAR04 + \n CONST050 * VAR22 + CONST141 * VAR06 * VAR26 + CONST142 * VAR08 * VAR24\n ) + g_8 * (CONST048 * VAR23 * y + VAR25 * (CONST074 * VAR16 - \n CONST100 * VAR08 * y) + z * (CONST049 * VAR06 * y + CONST059 *\n VAR14 + CONST074 * VAR08 * VAR16)) + g_9 * (CONST001 * VAR17 * (-\n CONST124 * VAR06 + CONST124 * VAR24) + CONST003 * VAR15 * (CONST138 *\n VAR08 - CONST138 * VAR26) + CONST009 * VAR08 * VAR24 + CONST152 *\n VAR04 + CONST152 * VAR06 * VAR26 - CONST152 * VAR22)\n g_z += g_0 * (CONST069 * VAR07 * VAR25 - CONST109 * VAR05 * z - \n CONST109 * VAR23 * x) + g_1 * y * (-CONST079 * VAR24 * x - CONST125 *\n VAR05 + CONST130 * VAR07 * VAR26) + g_10 * (CONST001 * VAR26 * (-\n CONST123 * VAR08 * VAR17 - CONST134 * VAR15 + CONST137 * VAR06) + \n CONST003 * VAR24 * (CONST080 * VAR08 + CONST139 * VAR17) + CONST032 *\n VAR04 + CONST105 * VAR08 * VAR15 - CONST111 * VAR06 * VAR17 - \n CONST148 * VAR22) + g_11 * (VAR16 * (CONST044 * VAR08 * z - \n CONST101 * VAR25) + y * (CONST054 * VAR06 * z - CONST091 * VAR08 *\n VAR25 + CONST121 * VAR23)) + g_12 * (CONST001 * VAR26 * (CONST091 *\n VAR08 * VAR17 - CONST098 * VAR06) + CONST003 * VAR24 * (CONST012 *\n VAR08 + CONST016 * VAR17) + CONST055 * VAR06 * VAR17 + CONST098 *\n VAR04 + CONST153 * VAR22) + g_13 * y * (-CONST079 * VAR06 * z - \n CONST125 * VAR23 + CONST130 * VAR08 * VAR25) + g_14 * (-CONST082 *\n VAR06 * VAR26 + CONST084 * VAR08 * VAR24 + CONST146 * VAR04 - \n CONST146 * VAR22) + g_2 * (CONST022 * VAR05 * z + VAR07 * (CONST025 *\n VAR25 + CONST045 * VAR17 * z) + x * (-CONST044 * VAR17 * VAR25 + \n CONST127 * VAR23)) + g_3 * (VAR16 * (-CONST045 * VAR26 * x + \n CONST101 * VAR07) + y * (CONST091 * VAR24 * x - CONST133 * VAR05)\n ) + g_4 * (CONST004 * VAR05 * z + VAR07 * (CONST104 * VAR17 * z - \n CONST139 * VAR25) + x * (CONST056 * VAR17 * VAR25 - CONST081 *\n VAR15 * z - CONST140 * VAR23)) + g_5 * (-CONST143 * VAR05 * y + \n VAR07 * (CONST064 * VAR26 * y + CONST106 * VAR16) + x * (CONST057 *\n VAR24 * y + CONST061 * VAR16 * VAR26 - CONST117 * VAR14)) + g_6 * (\n CONST097 * VAR05 * z + VAR07 * (-CONST100 * VAR17 * z + CONST145 *\n VAR25) + x * (CONST075 * VAR23 + CONST100 * VAR15 * z - CONST100 *\n VAR17 * VAR25)) + g_7 * (CONST115 * VAR14 * z + VAR16 * (CONST072 *\n VAR25 + CONST073 * VAR08 * z) + y * (CONST112 * VAR08 * VAR25 + \n CONST128 * VAR23 + CONST132 * VAR06 * z)) + g_8 * (CONST001 * VAR26 *\n (-CONST116 * VAR08 * VAR17 + CONST116 * VAR15 + CONST154 * VAR06) +\n CONST003 * VAR24 * (CONST026 * VAR17 + CONST154 * VAR08) + CONST019 *\n VAR13 + CONST029 * VAR06 * VAR17 + CONST094 * VAR04 + CONST116 *\n VAR08 * VAR15 + CONST149 * VAR22) + g_9 * (CONST085 * VAR16 * VAR25 -\n CONST117 * VAR14 * z + y * (CONST037 * VAR08 * VAR25 - CONST119 *\n VAR23 + CONST143 * VAR06 * z))\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_7.py" }, { "uuid": "cf434cf1-eaa7-43a8-af57-ed65644e78a1", "file_name": "tritonFun.py", "repo_name": "microsoft/Givens-Orthogonal-Backprop", "file_path": "rotMat/triton/tritonFun.py", "commit_hash": "3040fa287aacbf07be56eb12ddd7c513f7800191", "starcount": 0, "input": "@triton.jit\ndef _forward_kernel(c_ptr, s_ptr, u_ptr, col_stride, row_stride, **meta):\n n, n_tilde, dead_index, d_max, tournament_step, BLOCK_SIZE = meta['N'\n ], meta['N_TILDE'], meta['DEAD_INDEX'], meta['D_MAX'], meta['STEP'\n ], meta['BLOCK_SIZE']\n pid_x = tl.program_id(axis=0)\n temp = n_tilde - 1\n i = pid_x + tournament_step\n if pid_x == 0:\n i = 0\n if i >= n_tilde:\n i -= temp\n j = temp - pid_x + tournament_step\n if j >= n_tilde:\n j -= temp\n if i > j:\n i, j = j, i\n if (j == dead_index) | (j > d_max) & (i > d_max):\n return\n theta_offset = i * n - (i + 2) * (i + 1) // 2 + j\n c = tl.load(c_ptr + theta_offset)\n s = tl.load(s_ptr + theta_offset)\n offsets = tl.program_id(axis=1) * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n output_offsets_i = i * row_stride + offsets * col_stride\n output_offsets_j = j * row_stride + offsets * col_stride\n maximum = n * row_stride + n * col_stride\n maski = output_offsets_i < maximum\n maskj = output_offsets_j < maximum\n ui = tl.load(u_ptr + output_offsets_i, mask=maski)\n uj = tl.load(u_ptr + output_offsets_j, mask=maskj)\n ioutput = ui * c - uj * s\n joutput = uj * c + ui * s\n ui = tl.store(u_ptr + output_offsets_i, ioutput, mask=maski)\n uj = tl.store(u_ptr + output_offsets_j, joutput, mask=maskj)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/microsoft/Givens-Orthogonal-Backprop/blob/3040fa287aacbf07be56eb12ddd7c513f7800191/rotMat/triton/tritonFun.py" }, { "uuid": "ba747cf4-08d3-4408-bf74-1154ad010718", "file_name": "triton_chunk.py", "repo_name": "NX-AI/xlstm-jax", "file_path": "xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py", "commit_hash": "6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7", "starcount": 0, "input": "@triton.jit\ndef chunk_mlstm_fwd_kernel_h(q, k, v, C, n, m, m_total, i, f, h, norm,\n s_qk_h, s_qk_t, s_qk_d, s_vh_h, s_vh_t, s_vh_d, s_C_h, s_C_t, s_n_h,\n scale, H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NT: tl\n .constexpr):\n i_v, i_t, i_bC = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n h_i = tl.arange(0, BT)\n m_s = h_i[:, None] >= h_i[None, :]\n b_h = tl.zeros([BT, BV], dtype=tl.float32)\n b_s = tl.zeros([BT, BT], dtype=tl.float32)\n b_norm = tl.zeros([BT, BV], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n p_q = tl.make_block_ptr(q + i_bC * s_qk_h, (T, K), (s_qk_t, s_qk_d),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bC * s_qk_h, (K, T), (s_qk_d, s_qk_t),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_C = tl.make_block_ptr(C + i_bC * s_C_h + i_t * K * V, (K, V), (\n s_C_t, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_n = tl.make_block_ptr(n + i_bC * s_n_h + i_t * K, (K, BV), (1, 0),\n (i_k * BK, 0), (BK, BV), (0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_C = tl.load(p_C, boundary_check=(0, 1))\n b_n = tl.load(p_n, boundary_check=(0,))\n b_h += tl.dot(b_q, b_C, allow_tf32=False)\n b_s += tl.dot(b_q, b_k, allow_tf32=False)\n b_n2 = tl.dot(b_q, b_n, allow_tf32=False)\n b_norm += b_n2\n p_f = f + i_bC * T + i_t * BT + tl.arange(0, BT)\n b_f = tl.load(p_f)\n p_i = i + i_bC * T + i_t * BT + tl.arange(0, BT)\n b_i = tl.load(p_i)\n b_m = tl.load(m + i_bC * (NT + 1) + i_t)\n b_logD = b_i[None, :] + b_f[:, None] - b_f[None, :]\n b_logD = tl.where(m_s, b_logD, -float('inf'))\n b_mlogD = tl.max(b_logD, axis=1)\n b_m_total = tl.maximum(b_f + b_m, b_mlogD)\n p_m_total = tl.make_block_ptr(m_total + T * i_bC, (T,), (1,), (i_t * BT\n ,), (BT,), (0,))\n tl.store(p_m_total, b_m_total.to(p_m_total.dtype.element_ty),\n boundary_check=(0,))\n b_D = tl.math.exp2(b_logD - b_m_total[:, None])\n b_h = b_h * tl.math.exp2(b_f + b_m - b_m_total)[:, None] * scale\n b_s = b_s * b_D * scale\n b_norm = b_norm * tl.math.exp2(b_f + b_m - b_m_total)[:, None] * scale\n b_s = tl.where(m_s, b_s, 0)\n b_norm += tl.sum(b_s, axis=1)[:, None]\n b_norm = tl.abs(b_norm)\n b_norm = tl.maximum(b_norm, tl.math.exp2(-b_m_total)[:, None])\n tl.store(norm + i_bC * T + i_t * BT + tl.arange(0, BT), tl.max(b_norm,\n axis=1))\n p_v = tl.make_block_ptr(v + i_bC * s_vh_h, (T, V), (s_vh_t, s_vh_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_h = (b_h + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)) / b_norm\n p_h = tl.make_block_ptr(h + i_bC * s_vh_h, (T, V), (s_vh_t, s_vh_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "Apache", "BSD" ], "github_url": "https://github.com/NX-AI/xlstm-jax/blob/6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7/xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py" }, { "uuid": "185656ec-3bff-4006-8c3e-b0f32117c386", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef array_jagged_bmm_kernel(a_ptr, b_ptr, c_ptr, a_offsets_ptr,\n b_offsets_ptr, c_offsets_ptr, D, stride_bk, stride_bn, stride_cm,\n stride_cn, transpose, max_seq_len, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, allow_tf32: tl.\n constexpr):\n pid_batch = tl.program_id(2)\n pid_m = tl.program_id(1)\n pid_n = tl.program_id(0)\n batch_offset_am = tl.load(a_offsets_ptr + pid_batch)\n batch_offset_bk = tl.load(b_offsets_ptr + pid_batch)\n batch_offset_cm = tl.load(c_offsets_ptr + pid_batch)\n batch_K = tl.load(b_offsets_ptr + pid_batch + 1) - batch_offset_bk\n batch_M = tl.load(c_offsets_ptr + pid_batch + 1) - batch_offset_cm\n stride_am = batch_M * (1 - transpose) + 1 * transpose\n stride_ak = batch_M * transpose + 1 * (1 - transpose)\n batch_K = tl.minimum(batch_K, max_seq_len)\n batch_M = tl.minimum(batch_M, max_seq_len)\n if batch_K == 0:\n return\n batch_N = D\n if pid_m * BLOCK_SIZE_M >= batch_M or pid_n * BLOCK_SIZE_N >= batch_N:\n return\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % batch_M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % batch_N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + batch_offset_am + (offs_am[:, None] * stride_am + \n offs_k[None, :] * stride_ak)\n b_ptrs = b_ptr + batch_offset_bk * stride_bk + (offs_k[:, None] *\n stride_bk + offs_bn[None, :] * stride_bn)\n c = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(batch_K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=offs_k[None, :] < batch_K - k *\n BLOCK_SIZE_K, other=0.0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < batch_K - k *\n BLOCK_SIZE_K, other=0.0)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + stride_cm * batch_offset_cm + stride_cm * offs_cm[:, None\n ] + stride_cn * offs_cn[None, :]\n c_mask = (offs_cm[:, None] < batch_M) & (offs_cn[None, :] < batch_N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "022c4cc0-b308-49be-b921-b32509712645", "file_name": "empty.py", "repo_name": "triton-lang/triton", "file_path": "python/examples/empty.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef kernel(X, stride_xm, stride_xn, BLOCK: tl.constexpr):\n pass\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/examples/empty.py" }, { "uuid": "e008b2d4-e5d7-4904-adbb-d6d877357da0", "file_name": "gemm_a16w8.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/gemm_a16w8.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _triton_gemm_a16w8_per_channel_kernel(A, B, C, scale_b, bias,\n zero_points, M, N, K, stride_am, stride_ak, stride_bn, stride_bk,\n stride_cm, stride_cn, stride_zpk, stride_zpn, stride_scalek,\n stride_scalen, add_bias: tl.constexpr, add_zero_points: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,\n GROUP_M: tl.constexpr, SPLIT_K: tl.constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rbn[:, None] * stride_bn + rk[None, :] * stride_bk)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n if add_zero_points:\n offs_zero_points = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n zero_points_ptrs = zero_points + offs_zero_points\n _ZERO_POINT0 = tl.zeros([1], dtype=zero_points.dtype.element_ty)\n zero_points_vals = tl.load(zero_points_ptrs, mask=offs_zero_points <\n N, other=_ZERO_POINT0)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n _A0 = tl.zeros((1, 1), dtype=A.dtype.element_ty)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_A0)\n _B0 = tl.zeros((1, 1), dtype=B.dtype.element_ty)\n b = tl.load(B, mask=rk[None, :] < k_remaining, other=_B0)\n if add_zero_points:\n b = b - zero_points_vals[:, None]\n b_fp = b.to(A.dtype.element_ty)\n b_fp = tl.trans(b_fp)\n acc += tl.dot(a, b_fp, out_dtype=tl.float32, allow_tf32=True)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n offs_scale = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n scale_ptrs = scale_b + offs_scale\n _SCALE0 = tl.zeros([1], dtype=scale_b.dtype.element_ty)\n scales = tl.load(scale_ptrs, mask=offs_scale < N, other=_SCALE0)\n acc *= scales\n acc = acc.to(C.dtype.element_ty)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if add_bias:\n offs_bias = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n bias_ptrs = bias + offs_bias\n _BIAS0 = tl.zeros([1], dtype=bias.dtype.element_ty)\n bias_vals = tl.load(bias_ptrs, mask=offs_bias < N, other=_BIAS0)\n if pid_z == 0:\n acc += bias_vals[None, :]\n if SPLIT_K == 1:\n tl.store(C, acc, mask=mask)\n else:\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/gemm_a16w8.py" }, { "uuid": "0193e573-d1a1-4efc-bba9-db1a33827ad0", "file_name": "z_order.py", "repo_name": "Kitsunetic/space-filling-pytorch", "file_path": "space_filling_pytorch/functional/z_order.py", "commit_hash": "0de955ad1036973ee7506c5a0124c208acec722d", "starcount": 0, "input": "@triton.jit\ndef _encode_z_unpadded_kernel(xyz_ptr, batch_idx_ptr, code_ptr, space_size,\n x_offset, y_offset, z_offset, str_xyz_n, str_xyz_c, N, BLK: tl.\n constexpr, ASSIGN_BATCH_INDEX: tl.constexpr):\n pid = tl.program_id(0)\n offs_n = pid * BLK + tl.arange(0, BLK)\n mask = offs_n < N\n xyz_ptrs = xyz_ptr + offs_n * str_xyz_n\n fx = tl.load(xyz_ptrs + x_offset * str_xyz_c, mask=mask)\n fy = tl.load(xyz_ptrs + y_offset * str_xyz_c, mask=mask)\n fz = tl.load(xyz_ptrs + z_offset * str_xyz_c, mask=mask)\n ret = _calculate_zorder(fx, fy, fz, space_size)\n if ASSIGN_BATCH_INDEX:\n batch_idx_ptrs = batch_idx_ptr + offs_n\n batch_idx = tl.load(batch_idx_ptrs, mask=mask).to(tl.int64)\n ret |= batch_idx << 48\n code_ptrs = code_ptr + offs_n\n tl.store(code_ptrs, ret, mask=mask)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/space-filling-pytorch/blob/0de955ad1036973ee7506c5a0124c208acec722d/space_filling_pytorch/functional/z_order.py" }, { "uuid": "86d2fa4b-e481-4a17-9385-cbf6f0389011", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_dense_flash_attention_fwd_kernel(q_ptr, k_ptr, v_ptr, ab_ptr,\n o_ptr, lse_ptr, jagged_offsets_ptr, max_seq_len, stride_ql, stride_qd,\n stride_kb, stride_kd, stride_kt, stride_vn, stride_vd, stride_ab_b,\n stride_ab_n, stride_ab_t, stride_ob, stride_ot, stride_od, D: tl.\n constexpr, T: tl.constexpr, allow_tf32: tl.constexpr, BLOCK_T: tl.\n constexpr, BLOCK_L: tl.constexpr, BLOCK_D: tl.constexpr):\n pid_t = tl.program_id(0)\n pid_batch = tl.program_id(1)\n begin = tl.load(jagged_offsets_ptr + pid_batch)\n end = tl.load(jagged_offsets_ptr + pid_batch + 1)\n length = end - begin\n length = tl.minimum(length, max_seq_len)\n if length == 0:\n return\n q_start_ptr = q_ptr + begin * stride_ql\n k_start_ptr = k_ptr + pid_batch * stride_kb\n ab_start_ptr = ab_ptr + pid_batch * stride_ab_b\n v_start_ptr = v_ptr + begin * stride_vn\n offs_t = pid_t * BLOCK_T + tl.arange(0, BLOCK_T)\n offs_d = tl.arange(0, BLOCK_D)\n ki_ptrs = k_start_ptr + offs_d[:, None] * stride_kd + offs_t[None, :\n ] * stride_kt\n ki = tl.load(ki_ptrs, mask=(offs_d[:, None] < D) & (offs_t[None, :] < T\n ), other=0.0)\n mi = tl.zeros([BLOCK_T], dtype=tl.float32) - float('inf')\n li = tl.zeros([BLOCK_T], dtype=tl.float32)\n oi = tl.zeros([BLOCK_T, BLOCK_D], dtype=tl.float32)\n for start_l in range(0, length, BLOCK_L):\n offs_l = start_l + tl.arange(0, BLOCK_L)\n qj_ptrs = q_start_ptr + offs_l[:, None] * stride_ql + offs_d[None, :\n ] * stride_qd\n qj = tl.load(qj_ptrs, mask=(offs_l[:, None] < length) & (offs_d[\n None, :] < D), other=0.0)\n qk = tl.dot(qj, ki, allow_tf32=allow_tf32)\n ab_ptrs = ab_start_ptr + offs_l[:, None] * stride_ab_n + offs_t[None, :\n ] * stride_ab_t\n abij = tl.load(ab_ptrs, mask=(offs_l[:, None] < length) & (offs_t[\n None, :] < T), other=0.0)\n qk = qk + abij\n mij_hat = tl.max(qk, axis=0)\n mi_new = tl.maximum(mi, mij_hat)\n pij_hat = tl.exp(qk - mi_new[None, :])\n pij_hat = tl.where((offs_l[:, None] < length) & (offs_t[None, :] <\n T), pij_hat, 0.0)\n lij_hat = tl.sum(pij_hat, axis=0)\n alpha = tl.exp(mi - mi_new)\n li_new = alpha * li + lij_hat\n oi = alpha[:, None] * oi\n vj_ptrs = v_start_ptr + offs_l[:, None] * stride_vn + offs_d[None, :\n ] * stride_vd\n vj = tl.load(vj_ptrs, mask=(offs_l[:, None] < length) & (offs_d[\n None, :] < D), other=0.0)\n pij_hat = pij_hat.to(v_ptr.dtype.element_ty)\n oi = oi + tl.dot(tl.trans(pij_hat), vj, allow_tf32=allow_tf32)\n mi = mi_new\n li = li_new\n oi = oi / li[:, None]\n lse_ptrs = lse_ptr + pid_batch * T + offs_t\n lse_i = mi + tl.log(li)\n tl.store(lse_ptrs, lse_i, mask=offs_t < T)\n attn_out_ptrs = o_ptr + pid_batch * stride_ob + offs_t[:, None\n ] * stride_ot + offs_d[None, :] * stride_od\n tl.store(attn_out_ptrs, oi, mask=(offs_t[:, None] < T) & (offs_d[None,\n :] < D))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "25c4864d-4f48-498d-bd92-b326c89bc547", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef nll_loss(input, size, reduction: tl.constexpr):\n \"\"\"\n Measures the negative log likelihood loss given log-probabilities of target class.\n\n Args:\n input: Input containing predicted log-probabilities corresponding to target class.\n The input can have arbitrary shape.\n size: Number of elements in the input.\n This value is used only if reduction is 'mean'.\n reduction: Reduction strategy for the output.\n Options are 'none' for no reduction, 'mean' for averaging the loss\n across all entries, and 'sum' for summing the loss across all entries.\n\n Returns:\n Loss.\n \"\"\"\n input = input.to(tl.float32)\n if reduction == 'none':\n output = -input\n elif reduction == 'mean':\n output = -tl.sum(input) / size\n elif reduction == 'sum':\n output = -tl.sum(input)\n return output\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency", "Single Instance" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "f9b8875f-1555-4a1e-a553-4f8289afd403", "file_name": "triton_fused_local_attn.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_local_attn.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0})\n@triton.jit\ndef _fwd_kernel(Q, K, V, Out, softmax_scale, stride_qb, stride_qh,\n stride_qm, stride_kb, stride_kh, stride_kn, stride_vb, stride_vh,\n stride_vn, stride_ob, stride_oh, stride_om, nheads, seqlen_q, seqlen_k,\n CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, WINDOW_SIZE: tl.constexpr,\n BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n Q_block_ptr = tl.make_block_ptr(base=Q + (off_b * stride_qb + off_h *\n stride_qh), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_qm, 1),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_HEADDIM\n ), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + (off_b * stride_kb + off_h *\n stride_kh), shape=(BLOCK_HEADDIM, seqlen_k), strides=(1, stride_kn),\n offsets=(0, 0), block_shape=(BLOCK_HEADDIM, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + (off_b * stride_vb + off_h *\n stride_vh), shape=(seqlen_k, BLOCK_HEADDIM), strides=(stride_vn, 1),\n offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M:\n q = tl.load(Q_block_ptr)\n else:\n q = tl.load(Q_block_ptr, boundary_check=(0,), padding_option='zero')\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, softmax_scale,\n K_block_ptr, V_block_ptr, start_m, offs_m, offs_n, seqlen_k,\n WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 1)\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, softmax_scale,\n K_block_ptr, V_block_ptr, start_m, offs_m, offs_n, seqlen_k,\n WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 2)\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, softmax_scale,\n K_block_ptr, V_block_ptr, start_m, offs_m, offs_n, seqlen_k,\n WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 3)\n acc = acc / l_i[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc)\n else:\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_local_attn.py" }, { "uuid": "d220be62-ce65-4110-8341-90c6b7412373", "file_name": "scatter_reduce.py", "repo_name": "pyg-team/pyg-lib", "file_path": "pyg_lib/ops/scatter_reduce.py", "commit_hash": "bdd392a7093c5016f42ec7ae1945ca77dbdd97db", "starcount": 0, "input": "@triton.jit\ndef _fused_scatter_reduce_forward_kernel(inputs_ptr, index_ptr, out_ptr,\n num_feats, num_reductions, numel, REDUCE0, REDUCE1, REDUCE2, REDUCE3,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < numel\n inputs = tl.load(inputs_ptr + offsets, mask=mask)\n index_offsets = offsets // num_feats\n index = tl.load(index_ptr + index_offsets, mask=mask)\n if REDUCE0 > 0:\n out_offsets = num_feats * num_reductions * index\n out_offsets = out_offsets + offsets % num_feats\n if REDUCE0 == 1:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE0 == 2:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE0 == 3:\n tl.atomic_min(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE0 == 4:\n tl.atomic_max(out_ptr + out_offsets, inputs, mask=mask)\n if REDUCE1 > 0:\n out_offsets = num_feats * num_reductions * index\n out_offsets = out_offsets + num_feats\n out_offsets = out_offsets + offsets % num_feats\n if REDUCE1 == 1:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE1 == 2:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE2 == 3:\n tl.atomic_min(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE3 == 4:\n tl.atomic_max(out_ptr + out_offsets, inputs, mask=mask)\n if REDUCE2 > 0:\n out_offsets = num_feats * num_reductions * index\n out_offsets = out_offsets + 2 * num_feats\n out_offsets = out_offsets + offsets % num_feats\n if REDUCE2 == 1:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE2 == 2:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE2 == 3:\n tl.atomic_min(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE2 == 4:\n tl.atomic_max(out_ptr + out_offsets, inputs, mask=mask)\n if REDUCE3 > 0:\n out_offsets = num_feats * num_reductions * index\n out_offsets = out_offsets + 3 * num_feats\n out_offsets = out_offsets + offsets % num_feats\n if REDUCE3 == 1:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE3 == 2:\n tl.atomic_add(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE3 == 3:\n tl.atomic_min(out_ptr + out_offsets, inputs, mask=mask)\n elif REDUCE3 == 4:\n tl.atomic_max(out_ptr + out_offsets, inputs, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/pyg-team/pyg-lib/blob/bdd392a7093c5016f42ec7ae1945ca77dbdd97db/pyg_lib/ops/scatter_reduce.py" }, { "uuid": "04221a8d-0acd-483c-9226-c62cc41c67fe", "file_name": "layer_norm.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/layer_norm.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_fwd_fused(X, Y, W, B, Mean, Rstd, stride: tl.constexpr, N:\n tl.constexpr, eps, BLOCK_SIZE: tl.constexpr):\n row = tl.program_id(0)\n Y += row * stride\n X += row * stride\n if BLOCK_SIZE >= N:\n cols = tl.arange(0, BLOCK_SIZE)\n x = tl.load(X + cols, mask=cols < N).to(tl.float32)\n m2_ = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)\n weight_ = (cols < N).to(tl.float32)\n _mean, _m2, _weight = x, m2_, weight_\n else:\n _mean = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)\n _m2 = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)\n _weight = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n x = tl.load(X + cols, mask=cols < N).to(tl.float32)\n m2_ = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)\n weight_ = (cols < N).to(tl.float32)\n if off == 0:\n _mean, _m2, _weight = x, m2_, weight_\n else:\n _mean, _m2, _weight = welford_combine(_mean, _m2, _weight,\n x, m2_, weight_)\n mean, m2, weight = tl.reduce((_mean, _m2, _weight), 0, welford_combine)\n var = m2 / weight\n rstd = 1 / tl.sqrt(var + eps)\n mean = mean.to(x.dtype)\n rstd = rstd.to(x.dtype)\n if Mean is not None:\n tl.store(Mean + row, mean)\n if Rstd is not None:\n tl.store(Rstd + row, rstd)\n if BLOCK_SIZE >= N:\n cols = tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n if W is None:\n w = tl.full((BLOCK_SIZE,), 1.0, dtype=x.dtype)\n else:\n w = tl.load(W + cols, mask=mask)\n if B is None:\n b = tl.zeros((BLOCK_SIZE,), dtype=x.dtype)\n else:\n b = tl.load(B + cols, mask=mask)\n x_hat = (x - mean) * rstd\n y = x_hat * w + b\n tl.store(Y + cols, y, mask=mask)\n else:\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n if W is None:\n w = tl.full((BLOCK_SIZE,), 1.0, dtype=x.dtype)\n else:\n w = tl.load(W + cols, mask=mask)\n if B is None:\n b = tl.zeros((BLOCK_SIZE,), dtype=x.dtype)\n else:\n b = tl.load(B + cols, mask=mask)\n x = tl.load(X + cols, mask=mask)\n x_hat = (x - mean) * rstd\n y = x_hat * w + b\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/layer_norm.py" }, { "uuid": "747983d8-2740-48f1-a5b4-0b2b362c5601", "file_name": "qkv_concat.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/ops/qkv_concat.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef triton_qkv_concat(txt_qkv, img_qkv, out_q_ptr, out_k_ptr, out_v_ptr,\n seq_len, num_heads, head_dim, hidden_dim, seq_txt_len, stride_txt_a,\n stride_txt_b, stride_img_a, stride_img_b, stride_output_a,\n stride_output_b, stride_output_c, XBLOCK: tl.constexpr):\n pid = tl.program_id(0)\n xoffset = pid * XBLOCK + tl.arange(0, XBLOCK)[:]\n seq_idx = xoffset // hidden_dim % seq_len\n batch_idx = xoffset // stride_output_a\n hidden_dim_idx = xoffset % hidden_dim\n headdim_idx = xoffset % head_dim\n head_idx = xoffset // head_dim % num_heads\n txt_seq_end = tl.full([1], seq_txt_len, tl.int64)\n txt_mask = seq_idx < txt_seq_end\n img_mask = seq_idx >= txt_seq_end\n txt_q_data = tl.load(txt_qkv + (hidden_dim * 0 + hidden_dim_idx + \n stride_txt_b * seq_idx + stride_txt_a * batch_idx), txt_mask, other=0.0\n ).to(tl.float32)\n zero_mask = tl.full(txt_q_data.shape, 0.0, txt_q_data.dtype)\n masked_txt_q = tl.where(txt_mask, txt_q_data, zero_mask)\n img_q_data = tl.load(img_qkv + (-stride_txt_a + hidden_dim * 0 +\n hidden_dim_idx + stride_img_b * seq_idx + stride_img_a * batch_idx),\n img_mask, other=0.0).to(tl.float32)\n zero_mask = tl.full(img_q_data.shape, 0.0, img_q_data.dtype)\n masked_img_q = tl.where(img_mask, img_q_data, zero_mask)\n out_q = tl.where(txt_mask, masked_txt_q, masked_img_q)\n tl.store(out_q_ptr + (headdim_idx + stride_output_c * seq_idx + \n stride_output_b * head_idx + stride_output_a * batch_idx), out_q, None)\n txt_k_data = tl.load(txt_qkv + (hidden_dim * 1 + hidden_dim_idx + \n stride_txt_b * seq_idx + stride_txt_a * batch_idx), txt_mask, other=0.0\n ).to(tl.float32)\n zero_mask = tl.full(txt_k_data.shape, 0.0, txt_k_data.dtype)\n masked_txt_q = tl.where(txt_mask, txt_k_data, zero_mask)\n img_k_data = tl.load(img_qkv + (-stride_txt_a + hidden_dim * 1 +\n hidden_dim_idx + stride_img_b * seq_idx + stride_img_a * batch_idx),\n img_mask, other=0.0).to(tl.float32)\n zero_mask = tl.full(img_k_data.shape, 0.0, img_k_data.dtype)\n masked_img_k = tl.where(img_mask, img_k_data, zero_mask)\n out_k = tl.where(txt_mask, masked_txt_q, masked_img_k)\n tl.store(out_k_ptr + (headdim_idx + stride_output_c * seq_idx + \n stride_output_b * head_idx + stride_output_a * batch_idx), out_k, None)\n txt_v_data = tl.load(txt_qkv + (hidden_dim * 2 + hidden_dim_idx + \n stride_txt_b * seq_idx + stride_txt_a * batch_idx), txt_mask, other=0.0\n ).to(tl.float32)\n zero_mask = tl.full(txt_v_data.shape, 0.0, txt_v_data.dtype)\n masked_txt_v = tl.where(txt_mask, txt_v_data, zero_mask)\n img_v_data = tl.load(img_qkv + (-stride_txt_a + hidden_dim * 2 +\n hidden_dim_idx + stride_img_b * seq_idx + stride_img_a * batch_idx),\n img_mask, other=0.0).to(tl.float32)\n zero_mask = tl.full(img_v_data.shape, 0.0, img_v_data.dtype)\n masked_img_q = tl.where(img_mask, img_v_data, zero_mask)\n output_v = tl.where(txt_mask, masked_txt_v, masked_img_q)\n tl.store(out_v_ptr + (headdim_idx + stride_output_c * seq_idx + \n stride_output_b * head_idx + stride_output_a * batch_idx), output_v,\n None)\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/ops/qkv_concat.py" }, { "uuid": "5d836130-3356-4d7b-9797-41b5b20290c8", "file_name": "fp8_matmul.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/fp8/fp8_matmul.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef apply_scaling(accumulator, a_scale, b_scale, ROW_WISE_SCALING: tl.\n constexpr, offs_cm, offs_cn, M, N, stride_a_scale_m, stride_b_scale_n):\n if ROW_WISE_SCALING:\n a_scales = tl.load(a_scale + offs_cm * stride_a_scale_m, mask=\n offs_cm < M, other=0.0)\n b_scales = tl.load(b_scale + offs_cn * stride_b_scale_n, mask=\n offs_cn < N, other=0.0)\n acc_scale = a_scales[:, None] * b_scales[None, :]\n else:\n acc_scale = a_scale * b_scale\n return accumulator * acc_scale\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/fp8/fp8_matmul.py" }, { "uuid": "da11f109-9ed7-4901-b57c-0a34d0fda019", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gsa/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef chunk_gsa_bwd_k_kernel_intra_dvg(v, g, o, A, do, dv, dg, offsets,\n indices, T: tl.constexpr, HQ: tl.constexpr, H: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BC: tl.constexpr, BV: tl.constexpr, NC: tl\n .constexpr, NG: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl\n .constexpr):\n i_v, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_bh // NG\n i_b, i_hq = i_bh // HQ, i_bh % HQ\n i_h = i_hq // NG\n i_t, i_i = i_c // NC, i_c % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n o_v = i_v * BV + tl.arange(0, BV)\n m_v = o_v < V\n if i_t * BT + i_i * BC > T:\n return\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + (min(i_t *\n BT + i_i * BC + BC, T) - 1) * V + o_v, BV), BV)\n else:\n p_gv = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V, 1\n ), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + min(i_t * BT + \n i_i * BC + BC, T) - 1) * H * V + i_h * V + o_v, BV), BV)\n b_gn = tl.load(p_gn, mask=m_v, other=0)\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_dv = tl.zeros([BC, BV], dtype=tl.float32)\n for i_j in range(i_i + 1, NC):\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (BT, T), (1, BT), (\n i_i * BC, i_t * BT + i_j * BC), (BC, BC), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n p_A = tl.make_block_ptr(A + (bos * HQ + i_hq) * BT, (BT, T), (1,\n HQ * BT), (i_i * BC, i_t * BT + i_j * BC), (BC, BC), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_g - b_gn[None, :])).to(b_do.dtype)\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_dv += tl.dot(b_A, b_do)\n b_dv *= tl.exp(b_gn[None, :] - b_gv)\n o_i = tl.arange(0, BC)\n o_c = i_i * BC + tl.arange(0, BC)\n if HEAD_FIRST:\n p_g = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + (i_t * BT +\n i_i * BC) * V + o_v, BV), BV)\n p_A = tl.max_contiguous(tl.multiple_of(A + i_bh * T * BT + (i_t *\n BT + i_i * BC) * BT + o_c, BC), BC)\n p_do = tl.max_contiguous(tl.multiple_of(do + i_bh * T * V + (i_t *\n BT + i_i * BC) * V + o_v, BV), BV)\n else:\n p_g = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + i_i *\n BC) * H * V + i_h * V + o_v, BV), BV)\n p_A = tl.max_contiguous(tl.multiple_of(A + (bos + i_t * BT + i_i *\n BC) * HQ * BT + i_hq * BT + o_c, BC), BC)\n p_do = tl.max_contiguous(tl.multiple_of(do + (bos + i_t * BT + i_i *\n BC) * HQ * V + i_hq * V + o_v, BV), BV)\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_A = tl.load(p_A)\n b_g = tl.load(p_g, mask=m_v, other=0)\n b_do = tl.load(p_do, mask=m_v, other=0)\n m_i = o_i[:, None] <= j\n b_dv += tl.where(m_i, tl.exp(b_g[None, :] - b_gv) * b_A[:, None] *\n b_do[None, :], 0.0)\n p_g += (1 if HEAD_FIRST else H) * V\n p_A += (1 if HEAD_FIRST else HQ) * BT\n p_do += (1 if HEAD_FIRST else HQ) * V\n if HEAD_FIRST:\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT +\n i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_v = tl.make_block_ptr(v + i_bg * T * V, (T, V), (V, 1), (i_t * BT +\n i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_dg = tl.make_block_ptr(dg + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_o = tl.make_block_ptr(o + (bos * HQ + i_hq) * V, (T, V), (HQ * V,\n 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (HQ *\n V, 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * HQ + i_hq) * V, (T, V), (HQ *\n V, 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_dg = tl.make_block_ptr(dg + (bos * HQ + i_hq) * V, (T, V), (HQ *\n V, 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n b_o = tl.load(p_o, boundary_check=(0, 1)).to(tl.float32)\n b_v = tl.load(p_v, boundary_check=(0, 1)).to(tl.float32)\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(tl.float32)\n b_dv = b_dv + tl.load(p_dv, boundary_check=(0, 1)).to(tl.float32)\n b_dg = b_o * b_do - b_v * b_dv\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gsa/chunk.py" }, { "uuid": "8dbbd600-4b51-4d60-9081-c24273378c71", "file_name": "y_0.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_0.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef zeroth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor,\n block_size: tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.\n constexpr, col_offset: tl.constexpr, output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, 1.0, mask=output_row_offset <\n output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_0.py" }, { "uuid": "98296604-5ff6-454d-b957-63e6735444c9", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_gla_bwd_kernel(q, k, v, g, do, dq, dk, dv, h0, s_k_h, s_k_t,\n s_k_d, s_v_h, s_v_t, s_v_d, scale, B: tl.constexpr, H: tl.constexpr, T:\n tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr, BV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr, CHECK:\n tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(h0 + i_bh * K * V, (V, K), (1, V), (i_v *\n BV, i_k * BK), (BV, BK), (0, 1))\n b_h += tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n mask = i_k * BK + tl.arange(0, BK) < K\n for i in range(0, tl.cdiv(T, BT)):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i * BT, i_k * BK), (BT, BK), (1, 0))\n p_db = g + i_bh * s_k_h + ((i + 1) * BT - 1\n ) * s_k_t + i_k * BK + tl.arange(0, BK)\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (\n i_v * BV, i * BT), (BV, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dq = tl.make_block_ptr(dq + (i_bh + i_v * B * H) * s_k_h, (T, K),\n (s_k_t, s_k_d), (i * BT, i_k * BK), (BT, BK), (1, 0))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n d_b = tl.load(p_db, mask=mask, other=0).to(tl.float32)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n if CHECK and i == 0:\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_h = b_h * tl.exp(d_b)[None, :] + tl.dot(b_v, b_k.to(b_v.dtype\n ), allow_tf32=False)\n else:\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_h = b_h * tl.exp(d_b)[None, :] + tl.dot(b_v, b_k.to(b_v.dtype\n ), allow_tf32=False)\n b_dq *= scale\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n b_h = None\n tl.debug_barrier()\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n for i in range(1, tl.cdiv(T, BT) + 1):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, T - i * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n T - i * BT, i_k * BK), (BT, BK), (1, 0))\n p_db = g + i_bh * s_k_h + (T - (i - 1) * BT - 1\n ) * s_k_t + i_k * BK + tl.arange(0, BK)\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n T - i * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (T - i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dk = tl.make_block_ptr(dk + (i_bh + i_v * B * H) * s_k_h, (T, K),\n (s_k_t, s_k_d), (T - i * BT, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + i_k * B * H) * s_v_h, (T, V),\n (s_v_t, s_v_d), (T - i * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_db = tl.load(p_db, mask=mask, other=0).to(tl.float32)\n if CHECK and i == 1:\n b_dk = tl.trans(tl.dot(b_dh.to(b_v.dtype), tl.trans(b_v),\n allow_tf32=False))\n b_dv = tl.dot(b_k.to(b_v.dtype), b_dh.to(b_v.dtype), allow_tf32\n =False)\n b_dh = b_dh * tl.exp(b_db)[:, None] + tl.dot(b_q.to(b_do.dtype),\n b_do, allow_tf32=False)\n else:\n b_dk = tl.trans(tl.dot(b_dh.to(b_v.dtype), tl.trans(b_v),\n allow_tf32=False))\n b_dv = tl.dot(b_k.to(b_v.dtype), b_dh.to(b_v.dtype), allow_tf32\n =False)\n b_dh = b_dh * tl.exp(b_db)[:, None] + tl.dot(b_q.to(b_do.dtype),\n b_do, allow_tf32=False)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/fused_chunk.py" }, { "uuid": "601dc13f-efe7-4189-8251-9423cd04334d", "file_name": "foward.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/dropconnect/foward.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.jit\ndef dropconnect_fwd_kernel(x_ptr, w_ptr, y_ptr, seed, M, K, N, stride_xm,\n stride_xk, stride_wk, stride_wn, stride_ym, stride_yn, stride_dm,\n stride_dk, stride_dn, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr, ALLOWTF32: tl.constexpr):\n pid_m = tl.program_id(0)\n pid_n = tl.program_id(1)\n offset_m = pid_m * BLOCK_SIZE_M\n offset_n = pid_n * BLOCK_SIZE_N\n offset_k = 0\n x_offsets = block_offsets_2d(M, K, stride_xm, stride_xk, offset_m,\n offset_k, BLOCK_SIZE_M, BLOCK_SIZE_K)\n w_offsets = block_offsets_2d(K, N, stride_wk, stride_wn, offset_k,\n offset_n, BLOCK_SIZE_K, BLOCK_SIZE_N)\n d_offsets = block_offsets_3d(M, K, N, stride_dm, stride_dk, stride_dn,\n offset_m, offset_k, offset_n, BLOCK_SIZE_M, BLOCK_SIZE_K, BLOCK_SIZE_N)\n x_offsets = x_offsets.reshape(BLOCK_SIZE_M, BLOCK_SIZE_K, 1)\n w_offsets = w_offsets.reshape(1, BLOCK_SIZE_K, BLOCK_SIZE_N)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n x_tile = x_ptr + x_offsets\n w_tile = w_ptr + w_offsets\n ASM: tl.constexpr = 'cvt.rna.tf32.f32 $0, $1;'\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n random_masks = tl.random.rand(seed, d_offsets) > 0.5\n k_mask = offs_k[None, :, None] < K - k * BLOCK_SIZE_K\n x_load = tl.load(x_tile, mask=k_mask, other=0.0)\n w_load = tl.load(w_tile, mask=k_mask, other=0.0)\n a = tl.where(random_masks, x_load, 0.0)\n b = tl.where(random_masks, w_load, 0.0)\n mul = a * b\n accumulator += tl.sum(mul, axis=1)\n x_tile += BLOCK_SIZE_K * stride_xk\n w_tile += BLOCK_SIZE_K * stride_wk\n d_offsets += BLOCK_SIZE_K * stride_dk\n y_offset, y_mask = block_offsets_2d(M, N, stride_ym, stride_yn,\n offset_m, offset_n, BLOCK_SIZE_M, BLOCK_SIZE_N, True)\n y_tile = y_ptr + y_offset\n y = accumulator.to(y_tile.dtype.element_ty)\n tl.store(y_tile, y, mask=y_mask)\n", "category": { "Functionality": [ "Elementwise Operations", "Quantization" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/dropconnect/foward.py" }, { "uuid": "eceee47a-7f5a-4c5d-a084-f79da7308114", "file_name": "bwd_inner_dq.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/bwd_inner_dq.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_inner_dq(dq, qk_scale, bias_scale, DB_block_ptr, store_db, q,\n kt_ptrs, k_stride, vt_ptrs, v_stride, B_block_ptr, do, Di, l_i,\n seqlen_q, seqlen_k, head_dim, start_q, lo, hi, dropout_p, dropout_scale,\n philox_seed, batch_philox_offset, max_seqlen_k, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, FULL_BLOCKS: tl.\n constexpr, CAUSAL: tl.constexpr, ENABLE_DROPOUT: tl.constexpr,\n PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.constexpr):\n offs_q = start_q + tl.arange(0, BLOCK_M)\n offs_k = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n ld_offs_d = None if not PADDED_HEAD else tl.arange(0, BLOCK_DMODEL)\n kt_ptrs += lo * k_stride\n vt_ptrs += lo * v_stride\n if BIAS_TYPE == 1:\n B_block_ptr = tl.advance(B_block_ptr, (0, lo))\n DB_block_ptr = tl.advance(DB_block_ptr, (0, lo))\n \"\"\"\n K1 K2 (d)V dO\n Q1 qk11 qk12 (d)v1 dO1\n Q2 qk21 qk22 (d)v2 dO2\n\n QK: (seqlen_q, seqlen_k)\n dO: (seqlen_q, hdim)\n dV: (seqlen_k, hdim)\n \"\"\"\n for start_k in range(lo, hi, BLOCK_N):\n offs_k_curr = offs_k[None, :] + start_k\n if not FULL_BLOCKS:\n kt = load_fn(kt_ptrs, ld_offs_d, offs_k + start_k, head_dim,\n seqlen_k)\n else:\n kt = load_fn(kt_ptrs, ld_offs_d, None, head_dim, seqlen_k)\n if not FULL_BLOCKS:\n vt = load_fn(vt_ptrs, ld_offs_d, offs_k + start_k, head_dim,\n seqlen_k)\n else:\n vt = load_fn(vt_ptrs, ld_offs_d, None, head_dim, seqlen_k)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += dot(BLOCK_M, BLOCK_DMODEL, BLOCK_DMODEL, q, kt)\n if not FULL_BLOCKS:\n k_boundary = tl.full((BLOCK_M,), seqlen_k, dtype=tl.int32)\n mask = offs_k_curr < k_boundary[:, None]\n qk = tl.where(mask, qk, float('-inf'))\n if CAUSAL:\n qk = tl.where(offs_q[:, None] >= offs_k_curr, qk, float('-inf'))\n if BIAS_TYPE == 0:\n pass\n elif BIAS_TYPE == 1:\n bias = tl.load(B_block_ptr, boundary_check=(0, 1),\n padding_option='zero')\n qk += bias * bias_scale\n else:\n tl.static_assert(False, f'Unsupported BIAS_TYPE {BIAS_TYPE}')\n p = tl.math.exp2(qk_scale * qk - l_i[:, None])\n if not FULL_BLOCKS or CAUSAL:\n if qk_scale == 0.0:\n p = tl.where(libdevice.isnan(p), 0.0, p)\n dp = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n dp += dot(BLOCK_M, BLOCK_DMODEL, BLOCK_DMODEL, do, vt)\n if ENABLE_DROPOUT:\n philox_offset = (batch_philox_offset + start_q * max_seqlen_k +\n start_k)\n keep = dropout_mask(philox_seed, philox_offset, dropout_p,\n BLOCK_M, BLOCK_N, max_seqlen_k)\n dp = tl.where(keep, dp * dropout_scale, 0)\n ds = p * (dp - Di[:, None])\n if BLOCK_M == 1:\n dq += tl.view(kt, [BLOCK_DMODEL]) * ds.to(q.type.element_ty)\n else:\n dq = tl.dot(ds.to(q.type.element_ty), tl.trans(kt), acc=dq)\n if BIAS_TYPE == 1:\n if store_db:\n tl.store(DB_block_ptr, ds.to(DB_block_ptr.type.element_ty),\n boundary_check=(0, 1))\n kt_ptrs += BLOCK_N * k_stride\n vt_ptrs += BLOCK_N * v_stride\n if BIAS_TYPE == 1:\n B_block_ptr = tl.advance(B_block_ptr, (0, BLOCK_N))\n DB_block_ptr = tl.advance(DB_block_ptr, (0, BLOCK_N))\n return dq\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Tiled Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/bwd_inner_dq.py" }, { "uuid": "774b2df7-3308-4be6-9859-ced86bcaa8fc", "file_name": "gemm_a16w4.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/gemm_a16w4.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _triton_gemm_a16w4_per_channel_kernel(A, B, C, scale_b, bias,\n zero_points, M, N, K, rescale_m, rescale_n, rescale_k, stride_am,\n stride_ak, stride_bn, stride_bk, stride_cm, stride_cn, stride_zpk,\n stride_zpn, stride_scalek, stride_scalen, add_bias: tl.constexpr,\n add_zero_points: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl.\n constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rbn[:, None] * stride_bn + rk[None, :] * stride_bk)\n acc_l = tl.zeros((BLOCK_N, BLOCK_M), dtype=tl.float32)\n acc_h = tl.zeros((BLOCK_N, BLOCK_M), dtype=tl.float32)\n _A0 = tl.zeros((1, 1), dtype=A.dtype.element_ty)\n _B0 = tl.zeros((1, 1), dtype=B.dtype.element_ty)\n if add_zero_points:\n offs_zero_points = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n zero_points_ptrs = zero_points + offs_zero_points\n _ZERO_POINT0 = tl.zeros([1], dtype=zero_points.dtype.element_ty)\n zero_points_vals = tl.load(zero_points_ptrs, mask=offs_zero_points <\n 2 * N, other=_ZERO_POINT0)\n zero_points_vals = tl.reshape(zero_points_vals, (BLOCK_N, 2))\n zp_l, zp_h = tl.split(zero_points_vals)\n offs_scale = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n scale_ptrs = scale_b + offs_scale\n _SCALE0 = tl.zeros([1], dtype=scale_b.dtype.element_ty)\n scales = tl.load(scale_ptrs, mask=offs_scale < 2 * N, other=_SCALE0)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n b_int4_two = tl.load(B, mask=rk[None, :] < k_remaining, other=_B0)\n b_int4_l = b_int4_two.__lshift__(4).to(tl.int8).__rshift__(4).to(A.\n dtype.element_ty)\n b_int4_h = b_int4_two.__rshift__(4).to(A.dtype.element_ty)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_A0)\n a = tl.trans(a)\n if add_zero_points:\n b_int4_l -= zp_l[:, None]\n b_int4_h -= zp_h[:, None]\n acc_l += tl.dot(b_int4_l, a, out_dtype=tl.float32, allow_tf32=True)\n acc_h += tl.dot(b_int4_h, a, out_dtype=tl.float32, allow_tf32=True)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n acc_l = tl.trans(acc_l)\n acc_h = tl.trans(acc_h)\n acc = tl.interleave(acc_l, acc_h)\n offs_scale = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n scale_ptrs = scale_b + offs_scale\n _SCALE0 = tl.zeros([1], dtype=scale_b.dtype.element_ty)\n scales = tl.load(scale_ptrs, mask=offs_scale < 2 * N, other=_SCALE0)\n acc *= scales[None, :]\n acc = acc.to(C.dtype.element_ty)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n mask = (rm < M)[:, None] & (rn < 2 * N)[None, :]\n if add_bias:\n offs_bias = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n bias_ptrs = bias + offs_bias\n _BIAS0 = tl.zeros([1], dtype=bias.dtype.element_ty)\n bias_vals = tl.load(bias_ptrs, mask=offs_bias < 2 * N, other=_BIAS0)\n if pid_z == 0:\n acc += bias_vals[None, :]\n if SPLIT_K == 1:\n tl.store(C + rm[:, None] * stride_cm + rn[None, :], acc, mask=mask)\n else:\n tl.atomic_add(C + rm[:, None] * stride_cm + rn[None, :], acc, mask=mask\n )\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "int8", "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/gemm_a16w4.py" }, { "uuid": "32a86171-95db-478d-aace-264ce85654bc", "file_name": "chunk_h_parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'\n ] is not None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=[\n 'BT', 'USE_G', 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_bwd_kernel_dh_parallel(q, g, gk, gv, do, dh, dht, dh0, offsets,\n indices, scale, T: tl.constexpr, HQ: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV:\n tl.constexpr, NG: tl.constexpr, USE_G: tl.constexpr, USE_GK: tl.\n constexpr, USE_GV: tl.constexpr, STORE_INITIAL_STATE_GRADIENT: tl.\n constexpr, USE_FINAL_STATE_GRADIENT: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_kv, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n NV = tl.cdiv(V, BV)\n i_k, i_v = i_kv // NV, i_kv % NV\n i_b, i_hq, i_bg = i_bh // HQ, i_bh % HQ, i_bh // NG\n i_h = i_hq // NG\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n bos, eos = i_b * T, i_b * T + T\n NT = tl.cdiv(T, BT)\n i_n, i_tg = i_b, i_b * NT + i_t\n i_nh = i_n * HQ + i_hq\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k * BK,\n i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + (i_bh * NT + i_t) * K * V, (K, V), (V,\n 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * HQ + i_hq) * K, (K, T), (1, HQ *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (HQ *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (K, V), (V,\n 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n if i_t == NT - 1:\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dh = tl.load(p_dht, boundary_check=(0, 1)).to(tl.float32)\n else:\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n if USE_G:\n if HEAD_FIRST:\n p_g = g + i_bg * T + i_t * BT + tl.arange(0, BT)\n p_g = tl.max_contiguous(tl.multiple_of(p_g, BT), BT)\n else:\n p_g = g + (bos + i_t * BT + tl.arange(0, BT)) * H + i_h\n b_g = tl.load(p_g, mask=i_t * BT + tl.arange(0, BT) < T, other=0.0)\n b_q = (b_q * tl.exp(b_g)[None, :]).to(b_q.dtype)\n if USE_GK:\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(gk + i_bg * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n else:\n p_gk = tl.make_block_ptr(gk + (bos * H + i_h) * K, (K, T), (1, \n H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_q = (b_q * tl.exp(b_gk)).to(b_q.dtype)\n if USE_GV:\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(gv + i_bg * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_gv = tl.make_block_ptr(gv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_gv)).to(b_do.dtype)\n b_dh = tl.dot(b_q, b_do)\n if i_t > 0:\n if HEAD_FIRST:\n p_dh = tl.make_block_ptr(dh + (i_bh * NT + i_t - 1) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_dh = tl.make_block_ptr(dh + ((i_tg - 1) * H + i_h) * K * V, (\n K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n elif STORE_INITIAL_STATE_GRADIENT:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Tiled Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_parallel.py" }, { "uuid": "10461b26-96c5-475b-b85e-1317b069b740", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef scan_op(x1, y1, x2, y2):\n z1 = x2 * x1\n z2 = x2 * y1 + y2\n return z1, z2\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "e72ea98e-3167-44ec-923d-f412cbff14b8", "file_name": "naive_associative_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/naive_associative_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _associative_scan_op(a_l, x_l, a_r, x_r):\n return a_r * a_l, a_r * x_l + x_r\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/naive_associative_rnn_scan.py" }, { "uuid": "489248a3-bb60-40d3-a95f-13874bdd6bf8", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_gated_delta_rule_bwd_kernel_dqkw(q, k, v, w, g, h, do, dh, dq, dk,\n dv, dw, dg, offsets, indices, scale, T: tl.constexpr, H: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr,\n BV: tl.constexpr, NT: tl.constexpr, USE_OFFSETS: tl.constexpr,\n HEAD_FIRST: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k * BK,\n i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H * K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_dw = tl.zeros([BT, BK], dtype=tl.float32)\n b_ds = tl.zeros([BT, BT], dtype=tl.float32)\n b_dg = tl.zeros([BT], dtype=tl.float32)\n b_dg_last = tl.zeros([1], dtype=tl.float32)\n last_idx = min((i_t + 1) * BT, T) - 1\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_bh * T + last_idx)\n else:\n b_g_last = tl.load(g + (bos + last_idx) * H + i_h)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * NT * K * V + i_t * K * V, (V,\n K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bh * NT * K * V + i_t * K * V,\n (V, K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dg_last += tl.sum(b_h * b_dh)\n b_ds += tl.dot(b_do, tl.trans(b_v), allow_tf32=False)\n b_dq += tl.dot(b_do, b_h, allow_tf32=False)\n b_dk += tl.dot(b_v, b_dh, allow_tf32=False)\n b_dv = tl.load(p_dv, boundary_check=(0, 1))\n b_dw += tl.dot(b_dv.to(b_v.dtype), b_h.to(b_v.dtype), allow_tf32=False)\n b_dg_last *= tl.exp(b_g_last)\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n p_dg = tl.make_block_ptr(dg + i_bh * T, (T,), (1,), (i_t * BT,), (\n BT,), (0,))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n p_dg = tl.make_block_ptr(dg + bos * H + i_h, (T,), (H,), (i_t * BT,\n ), (BT,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_w = tl.load(p_w, boundary_check=(0, 1))\n b_g_exp_qw = tl.exp(b_g)\n b_dq *= b_g_exp_qw[:, None] * scale\n b_dg += tl.sum(b_dq * b_q, axis=1)\n b_dw *= b_g_exp_qw[:, None]\n b_dg -= tl.sum(b_dw * b_w, axis=1)\n b_dk *= tl.exp(b_g_last - b_g)[:, None]\n b_dg -= tl.sum(b_dk * b_k, axis=1)\n b_dg_last += tl.sum(b_dk * b_k)\n b_g_exp_qw = None\n b_ds = tl.where(o_i[:, None] >= o_i[None, :], b_ds * scale * tl.exp(b_g\n [:, None] - b_g[None, :]), 0).to(b_q.dtype)\n b_dg_mask = tl.dot(b_q, tl.trans(b_k), allow_tf32=False) * b_ds\n b_dg += tl.sum(b_dg_mask, axis=1)\n b_dg -= tl.sum(b_dg_mask, axis=0)\n b_dq += tl.dot(b_ds, b_k, allow_tf32=False)\n b_dk += tl.trans(tl.dot(tl.trans(b_q), b_ds, allow_tf32=False))\n b_dg = tl.where(o_i < min(BT, T - i_t * BT) - 1, b_dg, b_dg + b_dg_last)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dw, -b_dw.to(p_dw.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/chunk.py" }, { "uuid": "ba1125e7-41b5-4aee-9a38-9f0cb8548a00", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef accum_linear(accum, input1, input2, fp16: tl.constexpr, tf32: tl.constexpr\n ):\n \"\"\"\n Accumulates matrix multiplications of input tensors for linear functions.\n\n Args:\n accum: Accumulator holding aggregation of matrix multiplications.\n The accumulator must be of shape [BLOCK_SIZE1, BLOCK_SIZE3].\n input1: First operand of matrix multiplication.\n The operand must be of shape [BLOCK_SIZE1, BLOCK_SIZE2].\n input2: Second operand of matrix multiplication.\n The operand must be of shape [BLOCK_SIZE2, BLOCK_SIZE3].\n fp16: Flag for converting operands to FP16.\n tf32: Flag for performing matrix multiplication in TF32.\n\n Returns:\n Accumulator with the result of the new matrix multiplication added to it.\n \"\"\"\n if fp16:\n input1 = input1.to(tl.float16)\n input2 = input2.to(tl.float16)\n return accum + tl.dot(input1, input2, allow_tf32=tf32)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "cecb82d3-5254-4b2d-9ca3-137d666bad12", "file_name": "tuned_bwd.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/tuned_bwd.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=TRITON_CONFIG_LIST_BWD, key=['BLOCK_DMODEL',\n 'max_seqlen_q', 'max_seqlen_k'])\n@triton.jit\ndef tuned_bwd_kernel_dk_dv(Q, K, V, B, sm_scale, Out, DO, DK, DV, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dkz, stride_dkh, stride_dkn, stride_dkk,\n stride_dvz, stride_dvh, stride_dvk, stride_dvn, cu_seqlens_q,\n cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k, head_dim,\n dropout_p, philox_seed, philox_offset_base, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.\n constexpr):\n bare_bwd_kernel_dk_dv(Q, K, V, B, sm_scale, Out, DO, DK, DV, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dkz, stride_dkh, stride_dkn,\n stride_dkk, stride_dvz, stride_dvh, stride_dvk, stride_dvn,\n cu_seqlens_q, cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k,\n head_dim, dropout_p, philox_seed, philox_offset_base, BLOCK_M,\n BLOCK_DMODEL, BLOCK_N, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD=\n PADDED_HEAD, BIAS_TYPE=BIAS_TYPE)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/tuned_bwd.py" }, { "uuid": "0bb116ff-c023-4106-b0ff-399e5628a32e", "file_name": "layernorm.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/layernorm.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'RECOMPUTE_OUTPUT': lambda args: args['Y'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N', 'HAS_DRESIDUAL', 'STORE_DRESIDUAL',\n 'IS_RMS_NORM', 'HAS_BIAS'])\n@triton.jit\ndef layer_norm_bwd_kernel(X, W, B, Y, DY, DX, DW, DB, DRESIDUAL,\n DRESIDUAL_IN, Mean, Rstd, stride_x_row, stride_y_row, stride_dy_row,\n stride_dx_row, stride_dres_row, stride_dres_in_row, M, N, G,\n rows_per_program, programs_per_group, IS_RMS_NORM: tl.constexpr,\n BLOCK_N: tl.constexpr, HAS_DRESIDUAL: tl.constexpr, STORE_DRESIDUAL: tl\n .constexpr, HAS_WEIGHT: tl.constexpr, HAS_BIAS: tl.constexpr,\n RECOMPUTE_OUTPUT: tl.constexpr):\n row_block_id = tl.program_id(0)\n group_id, program_id_in_group = (row_block_id // programs_per_group, \n row_block_id % programs_per_group)\n row_start = group_id + program_id_in_group * G * rows_per_program\n row_end = min(row_start + G * rows_per_program, M)\n cols = tl.arange(0, BLOCK_N)\n mask = cols < N\n if HAS_WEIGHT:\n w = tl.load(W + group_id * stride_x_row + cols, mask=mask).to(tl.\n float32)\n dw = tl.zeros((BLOCK_N,), dtype=tl.float32)\n if RECOMPUTE_OUTPUT and HAS_BIAS:\n b = tl.load(B + group_id * stride_x_row + cols, mask=mask, other=0.0\n ).to(tl.float32)\n if HAS_BIAS:\n db = tl.zeros((BLOCK_N,), dtype=tl.float32)\n for row in range(row_start, row_end, G):\n x = tl.load(X + row * stride_x_row + cols, mask=mask, other=0).to(tl\n .float32)\n dy = tl.load(DY + row * stride_dy_row + cols, mask=mask, other=0).to(tl\n .float32)\n if not IS_RMS_NORM:\n mean = tl.load(Mean + row)\n rstd = tl.load(Rstd + row)\n xhat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n xhat = tl.where(mask, xhat, 0.0)\n if RECOMPUTE_OUTPUT:\n y = xhat * w if HAS_WEIGHT else xhat\n if HAS_BIAS:\n y = y + b\n tl.store(Y + row * stride_y_row + cols, y, mask=mask)\n wdy = dy\n if HAS_WEIGHT:\n wdy = dy * w\n dw += dy * xhat\n if HAS_BIAS:\n db += dy\n if not IS_RMS_NORM:\n c1 = tl.sum(xhat * wdy, axis=0) / N\n c2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * c1 + c2)) * rstd\n else:\n c1 = tl.sum(xhat * wdy, axis=0) / N\n dx = (wdy - xhat * c1) * rstd\n if HAS_DRESIDUAL:\n dres = tl.load(DRESIDUAL + row * stride_dres_row + cols, mask=\n mask, other=0).to(tl.float32)\n dx += dres\n if STORE_DRESIDUAL:\n tl.store(DRESIDUAL_IN + row * stride_dres_in_row + cols, dx,\n mask=mask)\n tl.store(DX + row * stride_dx_row + cols, dx, mask=mask)\n if HAS_WEIGHT:\n tl.store(DW + row_block_id * N + cols, dw, mask=mask)\n if HAS_BIAS:\n tl.store(DB + row_block_id * N + cols, db, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/layernorm.py" }, { "uuid": "bbfcb74d-d097-408e-89dc-20d7bdf56c4b", "file_name": "09-experimental-tma-matrix-multiplication.py", "repo_name": "hgl71964/SIP", "file_path": "benchmarks/09-experimental-tma-matrix-multiplication.py", "commit_hash": "767ed720d4bd5cee21670b125b62c434258c532b", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 8}, num_stages\n =7, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel(a_ptr, b_ptr, z_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_zm, stride_zn, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr, A_ORDER_0: tl.constexpr, A_ORDER_1: tl.constexpr,\n B_ORDER_0: tl.constexpr, B_ORDER_1: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n block_offset_m = pid_m * BLOCK_SIZE_M\n block_offset_n = pid_n * BLOCK_SIZE_N\n a_tile_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(block_offset_m, 0), block_shape=(\n BLOCK_SIZE_M, BLOCK_SIZE_K), order=(A_ORDER_0, A_ORDER_1))\n b_tile_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, block_offset_n), block_shape=(\n BLOCK_SIZE_K, BLOCK_SIZE_N), order=(B_ORDER_0, B_ORDER_1))\n z = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n offs_m = block_offset_m + tl.arange(0, BLOCK_SIZE_M)\n offs_n = block_offset_n + tl.arange(0, BLOCK_SIZE_N)\n z_ptrs = z_ptr + offs_m[:, None] * stride_zm + offs_n[None, :] * stride_zn\n mask = (offs_m < M)[:, None] & (offs_n < N)[None, :]\n for k in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_tile_ptr)\n b = tl.load(b_tile_ptr)\n z += tl.dot(a, b)\n a_tile_ptr = tl.advance(a_tile_ptr, [0, BLOCK_SIZE_K])\n b_tile_ptr = tl.advance(b_tile_ptr, [BLOCK_SIZE_K, 0])\n z = z.to(tl.float16)\n tl.store(z_ptrs, z, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/hgl71964/SIP/blob/767ed720d4bd5cee21670b125b62c434258c532b/benchmarks/09-experimental-tma-matrix-multiplication.py" }, { "uuid": "6901e5d7-7826-4fb5-b04f-6731b4bdf651", "file_name": "lstm_bw.py", "repo_name": "NX-AI/flashrnn", "file_path": "flashrnn/flashrnn/triton_fused/lstm_bw.py", "commit_hash": "3fca666a81c8740af4878d7bc5e2a51900e4fe14", "starcount": 0, "input": "@triton.jit\ndef _backward_sequence_kernel(delta_states_all_outside,\n delta_states_last_outside, R, states_all, gates_all,\n delta_states_initial, delta_Wx, delta_R, delta_b, T: tl.constexpr, NS:\n tl.constexpr, B: tl.constexpr, NH: tl.constexpr, DH: tl.constexpr, NGI:\n tl.constexpr, NGR: tl.constexpr, siz_B: tl.constexpr, DTYPE: tl.\n constexpr=tl.float32, backward_recurrent_clip_val: tl.constexpr=-1.0):\n idx_b_NH, idx_b_B = tl.program_id(0), tl.program_id(1)\n str_matR_B = NH * NGR * DH * DH\n str_matR_NH = NGR * DH * DH\n str_matR_NGR = DH * DH\n str_matStatesAll_NH = (T + 1) * NS * B * DH\n str_matStatesAll_T = NS * B * DH\n str_matGatesAll_NH = T * NGI * B * DH\n str_matGatesAll_T = NGI * B * DH\n str_delta_states_all_outside_NH = T * NS * B * DH\n str_delta_states_all_outside_T = NS * B * DH\n str_matDeltaWx_NH = T * NGI * B * DH\n str_matDeltaWx_T = NGI * B * DH\n matDeltaHtrans_last_ptr = tl.make_block_ptr(base=\n delta_states_last_outside + idx_b_NH * NS * B * DH + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matDeltaH_tplus1 = tl.load(matDeltaHtrans_last_ptr).to(tl.float32)\n matDeltaCtrans_last_ptr = tl.make_block_ptr(base=\n delta_states_last_outside + idx_b_NH * NS * B * DH + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matDeltaC_tplus1 = tl.load(matDeltaCtrans_last_ptr).to(tl.float32)\n matR_i_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 0 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_i = tl.load(matR_i_ptr)\n matR_f_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 1 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_f = tl.load(matR_f_ptr)\n matR_z_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 2 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_z = tl.load(matR_z_ptr)\n matR_o_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 3 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_o = tl.load(matR_o_ptr)\n matDeltaR_i = tl.zeros((DH, DH), dtype=tl.float32)\n matDeltaR_f = tl.zeros((DH, DH), dtype=tl.float32)\n matDeltaR_z = tl.zeros((DH, DH), dtype=tl.float32)\n matDeltaR_o = tl.zeros((DH, DH), dtype=tl.float32)\n vecDeltaB_i = tl.zeros((DH,), dtype=tl.float32)\n vecDeltaB_f = tl.zeros((DH,), dtype=tl.float32)\n vecDeltaB_z = tl.zeros((DH,), dtype=tl.float32)\n vecDeltaB_o = tl.zeros((DH,), dtype=tl.float32)\n for idx_t in range(T - 1, -1, -1):\n matG_i_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_i = tl.load(matG_i_ptr)\n matG_f_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_f = tl.load(matG_f_ptr)\n matG_z_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 2 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_z = tl.load(matG_z_ptr)\n matG_o_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 3 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_o = tl.load(matG_o_ptr)\n matC_t_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 1 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n matC_t = tl.load(matC_t_ptr)\n matC_tminus1_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + idx_t * str_matStatesAll_T + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matC_tminus1 = tl.load(matC_tminus1_ptr)\n matH_tminus1_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + idx_t * str_matStatesAll_T + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matH_tminus1 = tl.load(matH_tminus1_ptr)\n matDeltaCtrans_out_t_ptr = tl.make_block_ptr(base=\n delta_states_all_outside + idx_b_NH *\n str_delta_states_all_outside_NH + idx_t *\n str_delta_states_all_outside_T + 1 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matDeltaCtrans_out_t = tl.load(matDeltaCtrans_out_t_ptr)\n matDeltaHtrans_out_t_ptr = tl.make_block_ptr(base=\n delta_states_all_outside + idx_b_NH *\n str_delta_states_all_outside_NH + idx_t *\n str_delta_states_all_outside_T + 0 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matDeltaHtrans_out_t = tl.load(matDeltaHtrans_out_t_ptr)\n matDeltaH_t = matDeltaHtrans_out_t + matDeltaH_tplus1\n matDeltaC_t = matDeltaCtrans_out_t + matDeltaC_tplus1\n matCtrans_t_tanh = triton_tanh(matC_t)\n matDeltaC_t = matDeltaC_t + matDeltaH_t * matG_o * (1 - \n matCtrans_t_tanh * matCtrans_t_tanh)\n matDeltaGI = matDeltaC_t * matG_z * (1 - matG_i) * matG_i\n matDeltaGF = matDeltaC_t * matC_tminus1 * (1 - matG_f) * matG_f\n matDeltaGZ = matDeltaC_t * matG_i * (1 - matG_z * matG_z)\n matDeltaGO = matDeltaH_t * matCtrans_t_tanh * (1 - matG_o) * matG_o\n matDeltaC_tminus1 = matDeltaC_t * matG_f\n matDeltaH_tminus1 = tl.dot(matDeltaGI.to(DTYPE), matR_i)\n matDeltaH_tminus1 += tl.dot(matDeltaGF.to(DTYPE), matR_f)\n matDeltaH_tminus1 += tl.dot(matDeltaGZ.to(DTYPE), matR_z)\n matDeltaH_tminus1 += tl.dot(matDeltaGO.to(DTYPE), matR_o)\n matDeltaR_i += tl.dot(tl.trans(matDeltaGI.to(DTYPE)), matH_tminus1)\n matDeltaR_f += tl.dot(tl.trans(matDeltaGF.to(DTYPE)), matH_tminus1)\n matDeltaR_z += tl.dot(tl.trans(matDeltaGZ.to(DTYPE)), matH_tminus1)\n matDeltaR_o += tl.dot(tl.trans(matDeltaGO.to(DTYPE)), matH_tminus1)\n vecDeltaB_i += tl.sum(matDeltaGI, axis=0)\n vecDeltaB_f += tl.sum(matDeltaGF, axis=0)\n vecDeltaB_z += tl.sum(matDeltaGZ, axis=0)\n vecDeltaB_o += tl.sum(matDeltaGO, axis=0)\n matDeltaGI_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGI_ptr, matDeltaGI.to(DTYPE))\n matDeltaGF_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGF_ptr, matDeltaGF.to(DTYPE))\n matDeltaGZ_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 2 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGZ_ptr, matDeltaGZ.to(DTYPE))\n matDeltaGO_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 3 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGO_ptr, matDeltaGO.to(DTYPE))\n matDeltaH_tplus1 = matDeltaH_tminus1\n matDeltaC_tplus1 = matDeltaC_tminus1\n matDeltaHtrans_initial_ptr = tl.make_block_ptr(base=\n delta_states_initial + idx_b_NH * NS * B * DH + 0 * B * DH, shape=(\n B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=\n (siz_B, DH), order=(0, 1))\n tl.store(matDeltaHtrans_initial_ptr, matDeltaH_tplus1.to(DTYPE))\n matDeltaCtrans_initial_ptr = tl.make_block_ptr(base=\n delta_states_initial + idx_b_NH * NS * B * DH + 1 * B * DH, shape=(\n B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=\n (siz_B, DH), order=(0, 1))\n tl.store(matDeltaCtrans_initial_ptr, matDeltaC_tplus1.to(DTYPE))\n matDeltaR_i_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 0 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_i_ptr, matDeltaR_i.to(DTYPE))\n matDeltaR_f_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 1 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_f_ptr, matDeltaR_f.to(DTYPE))\n matDeltaR_z_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 2 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_z_ptr, matDeltaR_z.to(DTYPE))\n matDeltaR_o_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 3 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_o_ptr, matDeltaR_o.to(DTYPE))\n vecDeltaB_i_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 0 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_i_ptr, vecDeltaB_i.to(DTYPE))\n vecDeltaB_f_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 1 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_f_ptr, vecDeltaB_f.to(DTYPE))\n vecDeltaB_z_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 2 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_z_ptr, vecDeltaB_z.to(DTYPE))\n vecDeltaB_o_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 3 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_o_ptr, vecDeltaB_o.to(DTYPE))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT", "BSD" ], "github_url": "https://github.com/NX-AI/flashrnn/blob/3fca666a81c8740af4878d7bc5e2a51900e4fe14/flashrnn/flashrnn/triton_fused/lstm_bw.py" }, { "uuid": "67e19a21-a90d-4dc1-acd6-5034e67c1d5c", "file_name": "FleetAttention_triton.py", "repo_name": "Computational-Machine-Intelligence/LeetDecoding", "file_path": "leetDecoding/methods/FleetAttention_triton.py", "commit_hash": "1b545c2f5bacc155255250d1f70ac9484744559a", "starcount": 0, "input": "@triton.jit\ndef FleetAttention_kernel(B_ptr, C_ptr, V_ptr, ans_ptr, seqlen: tl.\n constexpr, dim: tl.constexpr, rank: tl.constexpr, stride_vbh: tl.\n constexpr, stride_bbh: tl.constexpr, dim_BLOCK: tl.constexpr):\n rank_idx = tl.program_id(axis=0)\n bz = tl.program_id(axis=1)\n dim_block_idx = tl.program_id(axis=2)\n off_b = tl.arange(0, 1)\n off_dim = tl.arange(0, dim_BLOCK)\n cv = tl.zeros([1, dim_BLOCK], dtype=tl.float32)\n o = tl.zeros([1, dim_BLOCK], dtype=tl.float32)\n for seq_idx in range(seqlen):\n offs_bc = bz * stride_bbh + seq_idx * rank + rank_idx + off_b[None, :]\n offs_v = (bz * stride_vbh + seq_idx * dim + dim_block_idx *\n dim_BLOCK + off_dim[None, :])\n ans_ptrs = (ans_ptr + bz * stride_vbh + seq_idx * dim + \n dim_block_idx * dim_BLOCK + off_dim[None, :])\n v_ptrs = V_ptr + offs_v\n b_ptr = B_ptr + offs_bc\n c_ptr = C_ptr + offs_bc\n b = tl.load(b_ptr, mask=off_b[None, :] < 1, other=0)\n c = tl.load(c_ptr, mask=off_b[None, :] < 1, other=0)\n v = tl.load(v_ptrs, mask=off_dim[None, :] < dim, other=0)\n cv = c * v + cv\n o = b * cv\n ans = tl.load(ans_ptrs, mask=off_dim[None, :] < dim, other=0)\n tl.store(ans_ptrs, ans + o, mask=off_dim[None, :] < dim)\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Computational-Machine-Intelligence/LeetDecoding/blob/1b545c2f5bacc155255250d1f70ac9484744559a/leetDecoding/methods/FleetAttention_triton.py" }, { "uuid": "1352a7a5-ebd7-4fa6-b706-8efe63475295", "file_name": "fwd_kernel.py", "repo_name": "ROCm/aotriton", "file_path": "test/fwd_kernel.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr, V_block_ptr, start_m,\n seqlen_q, seqlen_k, dropout_p, philox_seed, batch_philox_offset,\n encoded_softmax_block_ptr, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.\n constexpr, BLOCK_N: tl.constexpr, STAGE: tl.constexpr, offs_m: tl.\n constexpr, offs_n: tl.constexpr, pre_load_v: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, RETURN_ENCODED_SOFTMAX: tl.constexpr):\n if STAGE == 1:\n lo, hi = 0, min(seqlen_k, start_m * BLOCK_M)\n elif STAGE == 2:\n lo, hi = start_m * BLOCK_M, min(seqlen_k, start_m * BLOCK_M + BLOCK_M)\n lo = tl.multiple_of(lo, BLOCK_M)\n K_block_ptr = tl.advance(K_block_ptr, (0, lo))\n V_block_ptr = tl.advance(V_block_ptr, (lo, 0))\n if RETURN_ENCODED_SOFTMAX:\n encoded_softmax_block_ptr = tl.advance(encoded_softmax_block_ptr,\n (0, lo))\n else:\n lo, hi = 0, seqlen_k\n for start_n in range(lo, hi, BLOCK_N):\n if STAGE == 1 or STAGE == 3:\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(K_block_ptr)\n if pre_load_v:\n v = tl.load(V_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n if STAGE == 2:\n mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk = tl.where(mask, qk, float('-inf'))\n if BLOCK_M == 1:\n qk += tl.sum(tl.view(q, [BLOCK_DMODEL]) * tl.view(k, [\n BLOCK_DMODEL]))\n else:\n qk += tl.dot(q, k)\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n qk = qk - m_ij[:, None]\n p = tl.math.exp2(qk)\n l_ij = tl.sum(p, 1)\n if ENABLE_DROPOUT:\n philox_offset = (batch_philox_offset + start_m * BLOCK_M *\n seqlen_k + start_n)\n keep = dropout_mask(philox_seed, philox_offset, dropout_p,\n BLOCK_M, BLOCK_N, seqlen_k)\n if RETURN_ENCODED_SOFTMAX:\n tl.store(encoded_softmax_block_ptr, tl.where(keep, p, -p).\n to(encoded_softmax_block_ptr.type.element_ty))\n p = tl.where(keep, p, 0.0)\n elif RETURN_ENCODED_SOFTMAX:\n tl.store(encoded_softmax_block_ptr, p.to(\n encoded_softmax_block_ptr.type.element_ty))\n alpha = tl.math.exp2(m_i - m_ij)\n acc = acc * alpha[:, None]\n if not pre_load_v:\n v = tl.load(V_block_ptr)\n \"\"\"\n if ENABLE_DROPOUT:\n v = (v / (1.0 - dropout_p)).to(V_block_ptr.type.element_ty)\n \"\"\"\n l_i = l_i * alpha + l_ij\n m_i = m_ij\n if BLOCK_M == 1:\n acc += tl.view(p.to(V_block_ptr.type.element_ty), [1]) * tl.view(v,\n [BLOCK_DMODEL])\n else:\n acc += tl.dot(p.to(V_block_ptr.type.element_ty), v)\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n if RETURN_ENCODED_SOFTMAX:\n encoded_softmax_block_ptr = tl.advance(encoded_softmax_block_ptr,\n (0, BLOCK_N))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/fwd_kernel.py" }, { "uuid": "1310b43a-9ced-4062-b861-4e7f7c35f090", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BS': BS}, num_warps=num_warps) for\n BS in [16, 32, 64] for num_warps in [2, 4, 8]], key=['S', 'BT'])\n@triton.jit\ndef chunk_local_cumsum_vector_kernel(s, o, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, S: tl.constexpr, BT: tl.constexpr, BS: tl.\n constexpr, HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_s, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_s = tl.where(o_i[:, None] >= o_i[None, :], 1.0, 0.0)\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T * S, (T, S), (S, 1), (i_t * BT,\n i_s * BS), (BT, BS), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * S, (T, S), (S, 1), (i_t * BT,\n i_s * BS), (BT, BS), (1, 0))\n else:\n p_s = tl.make_block_ptr(s + (bos * H + i_h) * S, (T, S), (H * S, 1),\n (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * S, (T, S), (H * S, 1),\n (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_o = tl.dot(m_s, b_s, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "5f884ba7-afb8-4c7b-b7f8-8c0bdc99e57f", "file_name": "gemm_streamk_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32)], key=['M', 'N', 'K'])\n@triton.jit\ndef first_wave(a_ptr, b_ptr, c_ptr, M: tl.constexpr, N: tl.constexpr, K: tl\n .constexpr, stride_am: tl.constexpr, stride_ak: tl.constexpr, stride_bk:\n tl.constexpr, stride_bn: tl.constexpr, stride_cm: tl.constexpr,\n stride_cn: tl.constexpr, full_tiles, partial_tiles, iters_per_tile,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n start_iter = pid * full_tiles + tl.minimum(pid, partial_tiles)\n last_iter = (pid + 1) * full_tiles + tl.minimum(pid + 1, partial_tiles)\n while start_iter < last_iter:\n end_iter = start_iter + (iters_per_tile - start_iter % iters_per_tile)\n end_iter = tl.minimum(end_iter, last_iter)\n mac_loop(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_cm, stride_cn, iters_per_tile,\n start_iter, end_iter, BLOCK_SIZE_M, BLOCK_SIZE_N, BLOCK_SIZE_K,\n GROUP_SIZE_M)\n start_iter = end_iter\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py" }, { "uuid": "76e5f84e-91fd-40d6-b973-5c5374ec218d", "file_name": "triton_fused_attn.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_attn.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0})\n@triton.jit\ndef _fwd_kernel(Q, K, V, Out, softmax_scale, stride_qb, stride_qh,\n stride_qm, stride_kb, stride_kh, stride_kn, stride_vb, stride_vh,\n stride_vn, stride_ob, stride_oh, stride_om, nheads, seqlen_q, seqlen_k,\n CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, IS_CAUSAL: tl.constexpr,\n BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n q_ptrs = Q + off_b * stride_qb + off_h * stride_qh + (offs_m[:, None] *\n stride_qm + offs_d[None, :])\n k_ptrs = K + off_b * stride_kb + off_h * stride_kh + (offs_n[:, None] *\n stride_kn + offs_d[None, :])\n v_ptrs = V + off_b * stride_vb + off_h * stride_vh + (offs_n[:, None] *\n stride_vn + offs_d[None, :])\n lse_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc_o = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M:\n q = tl.load(q_ptrs)\n else:\n q = tl.load(q_ptrs, mask=offs_m[:, None] < seqlen_q, other=0.0)\n end_n = seqlen_k if not IS_CAUSAL else tl.minimum((start_m + 1) *\n BLOCK_M, seqlen_k)\n for start_n in range(0, end_n, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_N & EVEN_M:\n k = tl.load(k_ptrs + start_n * stride_kn)\n else:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=(start_n +\n offs_n)[:, None] < seqlen_k, other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, tl.trans(k))\n if not EVEN_N:\n qk += tl.where((start_n + offs_n)[None, :] < seqlen_k, 0, NEGINF)\n if IS_CAUSAL:\n qk += tl.where(offs_m[:, None] >= (start_n + offs_n)[None, :], \n 0, NEGINF)\n m_ij = tl.maximum(tl.max(qk, 1) * softmax_scale, lse_i)\n p = tl.exp(qk * softmax_scale - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n acc_o_scale = tl.exp(m_i - m_ij)\n acc_o = acc_o * acc_o_scale[:, None]\n if EVEN_N & EVEN_M:\n v = tl.load(v_ptrs + start_n * stride_vn)\n else:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=(start_n +\n offs_n)[:, None] < seqlen_k, other=0.0)\n p = p.to(v.dtype)\n acc_o += tl.dot(p, v)\n m_i = m_ij\n l_i_new = tl.exp(lse_i - m_ij) + l_ij\n lse_i = m_ij + tl.log(l_i_new)\n o_scale = tl.exp(m_i - lse_i)\n acc_o = acc_o * o_scale[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n lse_ptrs = Lse + off_hb * seqlen_q_rounded + offs_m\n tl.store(lse_ptrs, lse_i)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc_o)\n else:\n tl.store(out_ptrs, acc_o, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_attn.py" }, { "uuid": "fbe7dd6a-e642-49e2-85ae-30c92f1c7dd6", "file_name": "gemm_preop_exp_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_preop_exp_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32), triton.Config({'BLOCK_SIZE_M': \n 256, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4,\n 'grf_mode': 'large'}, num_stages=3, num_warps=32), triton.Config({\n 'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32\n ), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =2, num_warps=32)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers(a_ptr, b_ptr, c_ptr, M: tl.constexpr,\n N: tl.constexpr, K: tl.constexpr, stride_am: tl.constexpr, stride_ak:\n tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.constexpr,\n stride_cm: tl.constexpr, stride_cn: tl.constexpr, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n a_block_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n a = a.to(tl.float32)\n a = tl.math.exp(a)\n a = a.to(tl.bfloat16)\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c = accumulator.to(tl.float32)\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "bf16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_preop_exp_benchmark.py" }, { "uuid": "8fbd1eee-ae83-4f46-9244-6b0b3bf3bee6", "file_name": "softmax_online_v1.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v1.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v1(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((), value=-float('inf'), dtype=output_ptr.dtype.element_ty)\n z = tl.full((), value=0, dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, tl.max(inp, 0))\n new_z = tl.exp(m - new_m) * z + tl.sum(tl.exp(inp - new_m), 0)\n m = new_m\n z = new_z\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v1.py" }, { "uuid": "1370ad45-ebfb-4938-8f50-14f7af621077", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_linear_attn_fwd_kernel(q, k, v, o, h0, ht, s_k_h, s_v_h,\n scale, B, H, T, K: tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV:\n tl.constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.\n constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_v = v + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_o = o + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV)\n mask_bk = i_k * BK + tl.arange(0, BK) < K\n mask_bv = i_v * BV + tl.arange(0, BV) < V\n mask_kv = mask_bk[None, :] & mask_bv[:, None]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n b_h += tl.load(p_h0, mask=mask_kv, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_bk, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_bv, other=0).to(tl.float32)\n b_q = tl.load(p_q, mask=mask_bk, other=0).to(tl.float32) * scale\n b_h += b_k[None, :] * b_v[:, None]\n b_o = b_h * b_q[None, :]\n b_o = tl.sum(b_o, axis=1)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), mask=mask_bv)\n p_q += K\n p_k += K\n p_o += V\n p_v += V\n if STORE_FINAL_STATE:\n p_ht = ht + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask_kv)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/fused_recurrent.py" }, { "uuid": "8bddc46d-3ecf-45eb-88d1-ea5dd55dfb8c", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _kernel_quantize_fp8_block(A, A_scale, A_fp8, scale_ub, M, K, stride_am,\n stride_ak, stride_om, stride_ok, stride_a_scale_m, stride_a_scale_k,\n TL_FP8_DTYPE: tl.constexpr, MAX_FP8: tl.constexpr, EPS: tl.constexpr,\n CLAMP_MAX: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_K: tl.constexpr\n ) ->None:\n \"\"\"Quantize and scale each [BLOCK_M, BLOCK_K] block.\n\n Scale per block i, j is computed as 1 / (MAX_FP8 / max(abs(A[i:i+BLOCK_M, j:j+BLOCK_K])))\n\n Kernel naively iterates through matrix with [BLOCK_M, BLOCK_K] tiles.\n\n Todo:\n * Better tiling and ordering schemes.\n\n Args:\n A (Tensor): [M, K] higher precision input tensor.\n A_scale (Tensor): [cdiv(M, BLOCK_M), cdiv(K, BLOCK_K)] reciprocal scale tensor per block.\n A_fp8 (Tensor): [M, K] fp8 scaled tensor. A_fp8 = A * a_scale\n scale_ub (Tensor): [1] Maximum allowed value for scale.\n M (int): Number of rows.\n K (int): Number of columns.\n stride_am (int): Stride of m dimension of A.\n stride_ak (int): Stride of k dimension of A.\n stride_om (int): Stride of m dimension of output.\n stride_ok (int): Stride of k dimension of output.\n stride_a_scale_m (int): Stride of m dimension of A_scale.\n stride_a_scale_k (int): Stride of k dimension of A_scale.\n TL_FP8_DTYPE (tl.dtype): Target fp8 datatype.\n MAX_FP8 (float): Maxmimum expressible value for FP8.\n EPS (float): Epsilon value for numerical stability.\n CLAMP_MAX (bool): Whether to apply scale_ub.\n BLOCK_M (int): Block size for M dimension of A_scale and kernel.\n BLOCK_K (int): Block size for K dimension of A_scale and kernel.\n \"\"\"\n pid = tl.program_id(0)\n grid_k = tl.cdiv(K, BLOCK_K)\n block_m = pid // grid_k\n block_k = pid % grid_k\n rm = block_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rk = block_k * BLOCK_K + tl.arange(0, BLOCK_K)\n a_offset = rm[:, None] * stride_am + rk[None, :] * stride_ak\n out_offset = rm[:, None] * stride_om + rk[None, :] * stride_ok\n a_mask = (rm < M)[:, None] & (rk < K)[None, :]\n a_block = tl.load(A + a_offset, mask=a_mask, other=0.0)\n block_max = tl.max(tl.abs(a_block))\n if CLAMP_MAX:\n ub = tl.load(scale_ub)\n block_max = tl.clamp(block_max, EPS, ub)\n else:\n block_max = tl.maximum(block_max, EPS)\n scale = MAX_FP8 / block_max\n tl.store(A_scale + block_m * stride_a_scale_m + block_k *\n stride_a_scale_k, 1.0 / scale)\n a_fp8 = a_block * scale\n a_fp8 = tl.clamp(a_fp8, -MAX_FP8, MAX_FP8)\n a_fp8.to(TL_FP8_DTYPE)\n tl.store(A_fp8 + out_offset, a_fp8, mask=a_mask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "26a51175-e022-44f8-9ec3-2d92fe596611", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_retention_bwd_kernel_dq(i_bh, i_t, i_k, i_v, i_h, k, v, do, dq,\n scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BS: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr):\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (0, i_k * BK),\n (BS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (V, T), (1, V), (i_v * BV, 0),\n (BV, BS), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i_t * BT, \n i_v * BV), (BT, BV), (1, 0))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n d_b = tl.math.exp2(b_b * BS)\n d_h = tl.math.exp2((BS - tl.arange(0, BS)) * b_b)\n for i in range(0, i_t * BT, BS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_ds = tl.dot(b_do, b_v, allow_tf32=False) * d_h[None, :]\n if i != 0:\n b_dq *= d_b\n b_dq += tl.dot(b_ds.to(b_v.dtype), b_k, allow_tf32=False)\n p_k = tl.advance(p_k, (BS, 0))\n p_v = tl.advance(p_v, (0, BS))\n b_dq *= tl.math.exp2(tl.arange(0, BT) * b_b)[:, None] * scale\n o_q = tl.arange(0, BT)\n o_k = tl.arange(0, BS)\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT, \n i_k * BK), (BS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (V, T), (1, V), (i_v * BV, \n i_t * BT), (BV, BS), (0, 1))\n for _ in range(i_t * BT, (i_t + 1) * BT, BS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n m_s = o_q[:, None] >= o_k[None, :]\n d_s = tl.where(m_s, tl.math.exp2((o_q[:, None] - o_k[None, :]) *\n b_b), 0)\n b_ds = tl.dot(b_do, b_v, allow_tf32=False) * d_s * scale\n b_dq += tl.dot(b_ds.to(b_k.dtype), b_k, allow_tf32=False)\n p_k = tl.advance(p_k, (BS, 0))\n p_v = tl.advance(p_v, (0, BS))\n o_k += BS\n p_dq = tl.make_block_ptr(dq + (i_bh + B * H * i_v) * T * K, (T, K), (K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/parallel.py" }, { "uuid": "96564198-2f7d-486f-97bf-e992926034e9", "file_name": "paged_attn_v2.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn_v2.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _single_query_cached_kv_attention_v2(exp_sums, max_logits, out, q,\n k_cache, v_cache, head_mapping, scale, block_tables, seq_lens,\n partiton_size, max_num_blocks_per_seq, alibi_slopes, stride_qm,\n stride_qn, stride_om, stride_on, stride_ok, stride_km, stride_kn,\n stride_kk, stride_exp_m, stride_exp_n, BLOCK_SIZE: tl.constexpr,\n HEAD_SIZE: tl.constexpr):\n seq_idx = tl.program_id(axis=1)\n par_idx = tl.program_id(axis=2)\n seq_len = tl.load(seq_lens + seq_idx)\n if par_idx * partiton_size >= seq_len:\n return\n num_context_blocks = tl.cdiv(seq_len, BLOCK_SIZE)\n num_blocks_per_par = partiton_size // BLOCK_SIZE\n start_block_idx = par_idx * num_blocks_per_par\n end_block_idx = tl.minimum(start_block_idx + num_blocks_per_par,\n num_context_blocks)\n head_idx = tl.program_id(axis=0)\n kv_head_idx = tl.load(head_mapping + head_idx)\n if alibi_slopes is None:\n alibi_slope = 0.0\n else:\n alibi_slope = tl.load(alibi_slopes + head_idx)\n block_offs = tl.arange(0, BLOCK_SIZE)\n head_size_offs = tl.arange(0, HEAD_SIZE)\n q = tl.load(q + seq_idx * stride_qm + head_idx * stride_qn + head_size_offs\n )\n q = (q * scale).to(tl.float16)\n qkv = tl.zeros([BLOCK_SIZE, HEAD_SIZE], dtype=tl.float32)\n qk_max = float('-inf')\n exp_sum = 0.0\n fp16_0 = tl.zeros([1, 1], dtype=k_cache.dtype.element_ty)\n base_offs_kv = kv_head_idx * stride_kn + block_offs[:, None\n ] * stride_kk + head_size_offs[None, :]\n for block_idx in range(start_block_idx, end_block_idx):\n physical_block_idx = tl.load(block_tables + seq_idx *\n max_num_blocks_per_seq + block_idx)\n mask = (block_offs[:, None] < seq_len - block_idx * BLOCK_SIZE) & (\n head_size_offs[None, :] < HEAD_SIZE)\n offs_kv = physical_block_idx * stride_km + base_offs_kv\n k = tl.load(k_cache + offs_kv, mask=mask, other=fp16_0)\n v = tl.load(v_cache + offs_kv, mask=mask, other=fp16_0)\n _qk = tl.sum((q[None, :] * k).to(tl.float32), axis=1)\n _qk += alibi_slope * (block_idx * BLOCK_SIZE + block_offs - seq_len + 1\n )\n _qk_max = tl.maximum(tl.max(_qk, axis=0), qk_max)\n qk = tl.where(block_offs[:, None] < seq_len - block_idx *\n BLOCK_SIZE, _qk[:, None], float('-inf'))\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(tl.exp(_qk -\n _qk_max), axis=0)\n qkv = qkv * (exp_sum * tl.exp(qk_max - _qk_max) / _exp_sum) + tl.exp(\n qk - _qk_max) / _exp_sum * v\n qk_max = _qk_max\n exp_sum = _exp_sum\n offs_exp = seq_idx * stride_exp_m + head_idx * stride_exp_n + par_idx\n tl.store(exp_sums + offs_exp, exp_sum)\n tl.store(max_logits + offs_exp, qk_max)\n offs_out = (seq_idx * stride_om + head_idx * stride_on + par_idx *\n stride_ok + head_size_offs)\n tl.store(out + offs_out, tl.sum(qkv, axis=0))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn_v2.py" }, { "uuid": "b70199cf-0316-4688-b762-de62481ca266", "file_name": "bwd_split_kernel.py", "repo_name": "ROCm/aotriton", "file_path": "test/bwd_split_kernel.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_kernel_dq(Q, K, V, sm_scale, Out, DO, DQ, L, D, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vk, stride_vn, seqlen_q,\n seqlen_k, dropout_p, philox_seed, philox_offset_base, BLOCK_M: tl.\n constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL:\n tl.constexpr, ENABLE_DROPOUT: tl.constexpr):\n start_m = tl.program_id(0) * BLOCK_M\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n num_h = tl.num_programs(1)\n num_z = tl.num_programs(2)\n offs_m = start_m + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n q_offset = off_h * stride_qh + off_z * stride_qz\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n k_offset = off_h * stride_kh + off_z * stride_kz\n K_block_ptr = tl.make_block_ptr(base=K + k_offset, shape=(BLOCK_DMODEL,\n seqlen_k), strides=(stride_kk, stride_kn), offsets=(0, 0),\n block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n v_offset = off_h * stride_vh + off_z * stride_vz\n V_block_ptr = tl.make_block_ptr(base=V + v_offset, shape=(BLOCK_DMODEL,\n seqlen_k), strides=(stride_vn, stride_vk), offsets=(0, 0),\n block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n DO_block_ptr = tl.make_block_ptr(base=DO + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n off_zh = off_z * num_h + off_h * 1\n D_ptrs = D + off_zh * seqlen_q\n l_ptrs = L + off_zh * seqlen_q\n qk_scale = sm_scale * 1.44269504\n q = tl.load(Q_block_ptr)\n q = (q * qk_scale).to(Q_block_ptr.type.element_ty)\n do = tl.load(DO_block_ptr)\n Di = tl.load(D_ptrs + offs_m)\n l_i = tl.load(l_ptrs + offs_m)\n dq = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n lo = 0\n hi = min(start_m + BLOCK_M, seqlen_k) if CAUSAL else seqlen_k\n batch_philox_offset = philox_offset_base + off_zh * seqlen_q * seqlen_k\n \"\"\"\n K1 K2 (d)V dO\n Q1 qk11 qk12 (d)v1 dO1\n Q2 qk21 qk22 (d)v2 dO2\n\n QK: (seqlen_q, seqlen_k)\n dO: (seqlen_q, hdim)\n dV: (seqlen_k, hdim)\n \"\"\"\n for start_n in range(lo, hi, BLOCK_N):\n kt = tl.load(K_block_ptr)\n vt = tl.load(V_block_ptr)\n qk = dot(BLOCK_M, BLOCK_DMODEL, BLOCK_DMODEL, q, kt)\n if CAUSAL:\n qk = tl.where(offs_m[:, None] >= offs_n[None, :] + start_n, qk,\n float('-inf'))\n p = tl.math.exp2(qk - l_i[:, None])\n dp = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n dp += dot(BLOCK_M, BLOCK_DMODEL, BLOCK_DMODEL, do, vt)\n if ENABLE_DROPOUT:\n philox_offset = batch_philox_offset + start_m * seqlen_k + start_n\n keep = dropout_mask(philox_seed, philox_offset, dropout_p,\n BLOCK_M, BLOCK_N, seqlen_k)\n dp = tl.where(keep, dp / (1 - dropout_p), 0)\n ds = p * (dp - Di[:, None])\n if BLOCK_M == 1:\n dq += tl.view(kt, [BLOCK_DMODEL]) * ds.to(Q.type.element_ty)\n else:\n dq += tl.dot(ds.to(Q.type.element_ty), tl.trans(kt))\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (0, BLOCK_N))\n DQ_block_ptr = tl.make_block_ptr(base=DQ + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n tl.store(DQ_block_ptr, (dq * sm_scale).to(DQ_block_ptr.type.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Matrix Multiplication", "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/bwd_split_kernel.py" }, { "uuid": "01fdb3bd-4c8f-4387-a609-7db94baec8e2", "file_name": "geglu.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/geglu.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef cosh(x):\n return (tl.exp(x) + tl.exp(-x)) * 0.5\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Non-Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/geglu.py" }, { "uuid": "5abc2eaa-cbaa-4445-b0ea-d0fd89b0f5ac", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_dq(k, rk, ck, dq, ds, s_qk_h, s_qk_t, s_qk_d,\n s_sk_h, s_sk_t, s_sk_m, T, BT: tl.constexpr, BK: tl.constexpr, BM: tl.\n constexpr, DK: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_k, i_m, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n p_k = tl.make_block_ptr(k + i_bh * s_qk_h, (T, DK), (s_qk_t, s_qk_d), (\n 0, i_k * BK), (BT, BK), (1, 0))\n p_rk = tl.make_block_ptr(rk + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_ck = tl.make_block_ptr(ck + i_bh * s_sk_h, (DM, T), (s_sk_m, s_sk_t),\n (i_m * BM, 0), (BM, BT), (0, 1))\n p_dq = tl.make_block_ptr(dq + (i_m * n_bh + i_bh) * s_qk_h, (T, DK), (\n s_qk_t, s_qk_d), (0, i_k * BK), (BT, BK), (1, 0))\n p_ds = tl.make_block_ptr(ds + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n (0, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_hk = tl.zeros([BM, BK], dtype=tl.float32)\n for _ in range(NT):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_rk = tl.load(p_rk, boundary_check=(0,))\n b_ck = tl.load(p_ck, boundary_check=(0, 1))\n b_ds = tl.load(p_ds, boundary_check=(0, 1))\n b_inter = tl.dot((b_ds * b_rk[None, :]).to(b_k.dtype), b_hk.to(b_k.\n dtype), allow_tf32=False)\n b_intra = tl.dot(tl.where(m_s, tl.dot(b_ds, b_ck, allow_tf32=False),\n 0).to(b_k.dtype), b_k, allow_tf32=False)\n b_dq = b_inter + b_intra\n b_hk = b_hk * b_rk[:, None] + tl.dot(b_ck, b_k, allow_tf32=False)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n p_k = tl.advance(p_k, (BT, 0))\n p_rk = tl.advance(p_rk, (DM,))\n p_ck = tl.advance(p_ck, (0, BT))\n p_dq = tl.advance(p_dq, (BT, 0))\n p_ds = tl.advance(p_ds, (BT, 0))\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "4eae1f4c-27a6-472e-83b1-3c5bb1e82ddf", "file_name": "bwd_preprocess.py", "repo_name": "ROCm/aotriton", "file_path": "test/bwd_preprocess.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_preprocess(Out, DO, Delta, stride_oz, stride_oh, stride_om,\n stride_on, stride_doz, stride_doh, stride_dom, stride_don, seqlen_q,\n BLOCK_M: tl.constexpr, D_HEAD: tl.constexpr):\n off_m = tl.program_id(0) * BLOCK_M\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n num_h = tl.num_programs(1)\n o_offset = off_h * stride_oh + off_z * stride_oz\n O_block_ptr = tl.make_block_ptr(base=Out + o_offset, shape=(seqlen_q,\n D_HEAD), strides=(stride_om, stride_on), offsets=(off_m, 0),\n block_shape=(BLOCK_M, D_HEAD), order=(1, 0))\n do_offset = off_h * stride_doh + off_z * stride_doz\n DO_block_ptr = tl.make_block_ptr(base=DO + do_offset, shape=(seqlen_q,\n D_HEAD), strides=(stride_dom, stride_don), offsets=(off_m, 0),\n block_shape=(BLOCK_M, D_HEAD), order=(1, 0))\n o = tl.load(O_block_ptr).to(tl.float32)\n do = tl.load(DO_block_ptr).to(tl.float32)\n delta = tl.sum(o * do, axis=1)\n off_zh = off_z * num_h + off_h * 1\n tl.store(Delta + off_zh * seqlen_q + off_m + tl.arange(0, BLOCK_M), delta)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/bwd_preprocess.py" }, { "uuid": "b3fcb89f-85fb-4bab-969a-d45fd9c5cb9e", "file_name": "ln_linear_triton.py", "repo_name": "ethansmith2000/fused-layer-norm", "file_path": "ln_linear_triton.py", "commit_hash": "84fe243a829364acdcfd7cd70b699db04838af0f", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_fwd_fused(X_ptr, Y_ptr, W_ptr, B_ptr, Mean_ptr, RSTD_ptr,\n stride, n_cols, eps, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n Y_ptr += row_idx * stride\n X_ptr += row_idx * stride\n Mean_ptr += row_idx\n RSTD_ptr += row_idx\n X_row = tl.load(X_ptr + col_offsets, mask=mask, other=0)\n W_row = tl.load(W_ptr + col_offsets, mask=mask, other=0)\n B_row = tl.load(B_ptr + col_offsets, mask=mask, other=0)\n mean = tl.sum(X_row, axis=0) / n_cols\n demeaned = X_row - mean\n var = tl.sum(demeaned * demeaned, axis=0) / n_cols\n rstd = rsqrt(var + eps)\n tl.store(Mean_ptr, mean)\n tl.store(RSTD_ptr, rstd)\n Y_row = tl.fma(demeaned * rstd, W_row, B_row)\n tl.store(Y_ptr + col_offsets, Y_row, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ethansmith2000/fused-layer-norm/blob/84fe243a829364acdcfd7cd70b699db04838af0f/ln_linear_triton.py" }, { "uuid": "be6a1d21-b2db-4870-b6b3-b6ac680f6a72", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef mlstm_triton_scan(Q, K, V, F, I, O, F_REDUCED, C, N, M, H, NH: tl.\n constexpr, S: tl.constexpr, D: tl.constexpr, SB: tl.constexpr, VB: tl.\n constexpr):\n bh_id = tl.program_id(0)\n sb_id = tl.program_id(1)\n vb_id = tl.program_id(2)\n num_sequence_blocks = tl.num_programs(1)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n v_range = tl.arange(0, VB) + vb_id * VB\n v_range_3d = v_range[None, :, None]\n k_range = tl.arange(0, VB)\n sb_range = tl.arange(0, SB)\n sb_range_2d = tl.arange(0, SB)[:, None]\n sb_range_3d = tl.arange(0, SB)[:, None, None]\n sb_range_offset = tl.arange(0, SB) + sb_id * SB\n sb_range_offset_2d = sb_range_offset[:, None]\n batch_offset_fi = batch_id * NH * S + head_id * S\n batch_offset_f_reduced = (batch_id * NH * num_sequence_blocks + head_id *\n num_sequence_blocks)\n batch_offset_qkv = batch_id * NH * S * D + head_id * S * D\n batch_offset_n = (batch_id * NH * num_sequence_blocks * D + head_id *\n num_sequence_blocks * D)\n batch_offset_c = (batch_id * NH * num_sequence_blocks * D * D + head_id *\n num_sequence_blocks * D * D)\n f = tl.load(F + batch_offset_fi + sb_range_offset, sb_range_offset < S)\n i = tl.load(I + batch_offset_fi + sb_range_offset, sb_range_offset < S)\n f_reduced_range = batch_offset_f_reduced + sb_range * 0 + sb_id - 1\n f_reduced_mask = (sb_range == 0) & (sb_id != 0)\n f_reduced = tl.load(F_REDUCED + f_reduced_range, f_reduced_mask, other=1.0)\n vo_range = batch_offset_qkv + sb_range_offset_2d * D + v_range[None, :]\n vo_mask = (sb_range_offset_2d < S) & (v_range[None, :] < D)\n v = tl.load(V + vo_range, vo_mask)\n normalizer = tl.zeros((SB,), dtype=tl.float32)\n h = tl.zeros((SB, VB), dtype=tl.float32)\n k_scale_factor = tl.sqrt(tl.full((1,), D, dtype=tl.float32))\n for j in tl.range(tl.cdiv(D, VB)):\n k_range_ = batch_offset_qkv + sb_range_offset_2d * D + k_range[None, :]\n k_mask = (sb_range_offset_2d < S) & (k_range[None, :] < D)\n k = tl.load(K + k_range_, k_mask) / k_scale_factor\n q = tl.load(Q + k_range_, k_mask)\n c_range = batch_offset_c + sb_range_3d + (sb_id - 1\n ) * D * D + v_range_3d * D + k_range[None, None, :]\n c_mask = (sb_range_3d == 0) & (v_range_3d < D) & (k_range[None,\n None, :] < D) & (sb_id != 0)\n c_reduced = tl.load(C + c_range, c_mask, other=0)\n vk = v[:, :, None] * k[:, None, :] * i[:, None, None]\n f_tmp, vk_tmp = scan_op(f_reduced[:, None, None], c_reduced, f[:,\n None, None], vk)\n f_tmp = tl.broadcast_to(f_tmp, (SB, VB, VB))\n _, c = tl.associative_scan((f_tmp, vk_tmp), 0, scan_op)\n h += tl.sum(c * q[:, None, :], -1)\n n_range = batch_offset_n + sb_range_2d + (sb_id - 1) * D + k_range[\n None, :]\n n_mask = (sb_range_2d == 0) & (k_range[None, :] < D) & (sb_id != 0)\n n = tl.load(N + n_range, n_mask, other=0.0)\n f_tmp, n_tmp = scan_op(f_reduced[:, None], n, f[:, None], k * i[:,\n None])\n _, n = tl.associative_scan((tl.broadcast_to(f_tmp, (SB, VB)), n_tmp\n ), 0, scan_op)\n normalizer += tl.sum(n * q, -1)\n k_range += VB\n m = tl.load(M + batch_offset_fi + sb_range_offset, sb_range_offset < S)\n o = tl.load(O + vo_range, vo_mask)\n normalizer = tl.maximum(tl.abs(normalizer), tl.exp(-m))[:, None] + 1e-06\n h = h / normalizer * silu(o)\n tl.store(H + vo_range, h, vo_mask)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "8e56e989-ac16-4909-9f0e-4ab0f6c13dae", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef glu(input1, input2, param, act_func: tl.constexpr):\n \"\"\"\n Applies the gated linear unit with an arbitrary activation function\n to the input.\n\n Args:\n input1: First half of input to gate.\n The first half must be of the same shape as the second half.\n input2: Second half of input to gate.\n The second half must be of the same shape as the first half.\n param: Parameter in the case of parameterized activation functions.\n act_func: Name of activation function to apply.\n Options are 'sigmoid', 'tanh', 'relu', 'gelu', 'silu',\n 'relu6', 'hardsigmoid', 'hardswish', 'selu', 'mish', and 'leaky_relu'.\n param: Parameter in the case of parameterized activation functions.\n\n Args:\n Input transformed by the gated linear unit\n with an arbitrary activation function.\n \"\"\"\n return input1 * apply_act_func(input2, None, None, None, param,\n act_func, False)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "fdd2e0b1-dd78-4f2b-8862-5b13f1fc1f97", "file_name": "k_layer_norm.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_layer_norm.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _affine(W, B, N, x, META):\n cols = tl.arange(0, META['BLOCK_SIZE_N'])\n w = tl.load(W + cols, mask=cols < N, other=1.0)\n zero = 0.0\n zero = zero.to(w.dtype)\n w = tl.where(cols < N, w, zero)\n b = tl.load(B + cols, mask=cols < N, other=0.0)\n b = tl.where(cols < N, b, zero)\n y = x * w + b\n return y\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_layer_norm.py" }, { "uuid": "6d3ee5b8-898b-438e-a16f-c87c7ce98c84", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _jagged_dense_flash_attention_bwd_dk_kernel(q_ptr, k_ptr, v_ptr, ab_ptr,\n jagged_offsets_ptr, out_ptr, do_ptr, lse_ptr, delta_ptr, dq_ptr, dk_ptr,\n dv_ptr, dbias_ptr, max_seq_len, stride_ql, stride_qd, stride_kb,\n stride_kd, stride_kt, stride_vl, stride_vd, stride_ab_b, stride_ab_l,\n stride_ab_t, stride_ob, stride_ot, stride_od, stride_dk_b, stride_dk_d,\n stride_dk_t, stride_do_b, stride_do_t, stride_do_d, D, T: tl.constexpr,\n BLOCK_T: tl.constexpr, BLOCK_L: tl.constexpr, BLOCK_D: tl.constexpr,\n allow_tf32: tl.constexpr):\n pid_t = tl.program_id(0)\n pid_b = tl.program_id(1)\n begin = tl.load(jagged_offsets_ptr + pid_b)\n end = tl.load(jagged_offsets_ptr + pid_b + 1)\n seqlen = end - begin\n seqlen = tl.minimum(seqlen, max_seq_len)\n if seqlen == 0:\n return\n q_start_ptr = q_ptr + begin * stride_ql\n k_start_ptr = k_ptr + pid_b * stride_kb\n ab_start_ptr = ab_ptr + pid_b * stride_ab_b\n v_start_ptr = v_ptr + begin * stride_vl\n do_start_ptr = do_ptr + pid_b * stride_do_b\n dk_start_ptr = dk_ptr + pid_b * stride_dk_b\n delta_ptrs = delta_ptr + pid_b * T\n lse_ptrs = lse_ptr + pid_b * T\n offs_t_curr = pid_t * BLOCK_T + tl.arange(0, BLOCK_T)\n offs_d = tl.arange(0, BLOCK_D)\n k_ptrs = k_start_ptr + offs_d[:, None] * stride_kd + offs_t_curr[None, :\n ] * stride_kt\n do_ptrs = do_start_ptr + offs_t_curr[:, None] * stride_do_t + offs_d[\n None, :] * stride_do_d\n dk_ptrs = dk_start_ptr + offs_d[:, None] * stride_dk_d + offs_t_curr[\n None, :] * stride_dk_t\n dk = tl.zeros([BLOCK_D, BLOCK_T], dtype=tl.float32)\n k = tl.load(k_ptrs, mask=(offs_t_curr[None, :] < T) & (offs_d[:, None] <\n BLOCK_D), other=0.0)\n start_l = 0\n while start_l < seqlen:\n offs_l_curr = start_l + tl.arange(0, BLOCK_L)\n q_ptrs = q_start_ptr + offs_l_curr[:, None] * stride_ql + offs_d[\n None, :] * stride_qd\n q = tl.load(q_ptrs, mask=offs_l_curr[:, None] < seqlen, other=0.0)\n v_ptrs = v_start_ptr + offs_l_curr[:, None] * stride_vl + offs_d[\n None, :] * stride_vd\n v = tl.load(v_ptrs, mask=offs_l_curr[:, None] < seqlen, other=0.0)\n qk = tl.zeros([BLOCK_L, BLOCK_T], dtype=tl.float32)\n qk = tl.dot(q, k, allow_tf32=allow_tf32)\n qk = tl.where((offs_l_curr[:, None] < seqlen) & (offs_t_curr[None,\n :] < T), qk, 0.0)\n ab_ptrs = ab_start_ptr + offs_l_curr[:, None\n ] * stride_ab_l + offs_t_curr[None, :] * stride_ab_t\n ab = tl.load(ab_ptrs, mask=(offs_l_curr[:, None] < seqlen) & (\n offs_t_curr[None, :] < T), other=0.0)\n qk = qk + ab\n qk_mask = (offs_l_curr[:, None] < seqlen) & (offs_t_curr[None, :] < T)\n qk = tl.where(qk_mask, qk, float('-inf'))\n lse_t = tl.load(lse_ptrs + offs_t_curr, mask=offs_t_curr < T)\n p = tl.exp(qk - lse_t[None, :])\n p = tl.where(qk_mask, p, 0.0)\n do = tl.load(do_ptrs, mask=offs_t_curr[:, None] < T, other=0.0)\n delta = tl.load(delta_ptrs + offs_t_curr, mask=offs_t_curr < T)\n dp = tl.trans(tl.dot(do, tl.trans(v), allow_tf32=allow_tf32))\n ds = p * (dp - delta[None, :])\n dk += tl.dot(tl.trans(q), ds, allow_tf32=allow_tf32)\n start_l += BLOCK_L\n tl.store(dk_ptrs, dk, mask=offs_t_curr[None, :] < T)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "8c7b91e8-cc8f-40fc-afce-459f1f8214bf", "file_name": "lightning_attn2.py", "repo_name": "OpenNLPLab/lightning-attention", "file_path": "lightning_attn/ops/triton/lightning_attn2.py", "commit_hash": "d7439519541e966084eeaaf3ffd63eecc216f414", "starcount": 0, "input": "@triton.jit\ndef _bwd_intra_kernel(Q, K, V, S, DO, DQ, DK, DV, b: tl.constexpr, h: tl.\n constexpr, n: tl.constexpr, d: tl.constexpr, e: tl.constexpr, BLOCK: tl\n .constexpr, NUM_BLOCK: tl.constexpr, CBLOCK: tl.constexpr, NUM_CBLOCK:\n tl.constexpr):\n off_bh = tl.program_id(0)\n off_block = tl.program_id(1)\n off_h = off_bh % h\n qk_offset = off_bh * n * d\n v_offset = off_bh * n * e\n o_offset = off_bh * n * e\n block_offset = off_block * BLOCK + tl.arange(0, BLOCK)\n Q_trans_block_ptr = Q + qk_offset + block_offset[None, :] * d + tl.arange(\n 0, d)[:, None]\n K_block_ptr = K + qk_offset + block_offset[:, None] * d + tl.arange(0, d)[\n None, :]\n V_trans_block_ptr = V + v_offset + block_offset[None, :] * e + tl.arange(\n 0, e)[:, None]\n DQ_block_ptr = DQ + qk_offset + block_offset[:, None] * d + tl.arange(0, d\n )[None, :]\n DK_trans_block_ptr = DK + qk_offset + block_offset[None, :\n ] * d + tl.arange(0, d)[:, None]\n DV_block_ptr = DV + v_offset + block_offset[:, None] * e + tl.arange(0, e)[\n None, :]\n DO_block_ptr = DO + o_offset + block_offset[:, None] * e + tl.arange(0, e)[\n None, :]\n S_block_ptr = S + off_h\n s = tl.load(S_block_ptr)\n array = tl.arange(0, BLOCK).to(tl.float32)\n index = array[:, None] - array[None, :]\n s_index = s * index\n s_index = tl.where(index >= 0, -s_index, float('-inf'))\n diag_decay = tl.exp(s_index)\n diag_decay_trans = tl.trans(diag_decay)\n k = tl.load(K_block_ptr, mask=block_offset[:, None] < n, other=0.0).to(tl\n .float32)\n v_trans = tl.load(V_trans_block_ptr, mask=block_offset[None, :] < n,\n other=0.0).to(tl.float32)\n do = tl.load(DO_block_ptr, mask=block_offset[:, None] < n, other=0.0).to(tl\n .float32)\n q_trans = tl.load(Q_trans_block_ptr, mask=block_offset[None, :] < n,\n other=0.0).to(tl.float32)\n dqk = tl.dot(do, v_trans) * diag_decay\n dq_intra = tl.dot(dqk, k)\n dk_intra_trans = tl.dot(q_trans, dqk)\n qk_trans = tl.dot(k, q_trans) * diag_decay_trans\n dv_intra = tl.dot(qk_trans, do)\n dq = dq_intra\n dk_trans = dk_intra_trans\n dv = dv_intra\n tl.store(DQ_block_ptr, dq.to(DQ_block_ptr.dtype.element_ty), mask=\n block_offset[:, None] < n)\n tl.store(DK_trans_block_ptr, dk_trans.to(DK_trans_block_ptr.dtype.\n element_ty), mask=block_offset[None, :] < n)\n tl.store(DV_block_ptr, dv.to(DV_block_ptr.dtype.element_ty), mask=\n block_offset[:, None] < n)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/OpenNLPLab/lightning-attention/blob/d7439519541e966084eeaaf3ffd63eecc216f414/lightning_attn/ops/triton/lightning_attn2.py" }, { "uuid": "4fcdc1d3-596d-431c-b62b-3f6a8a65e5a1", "file_name": "k_dropout.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_dropout.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _drop_and_scale(SEEDS, row, p, offsets, x):\n seed = SEEDS + row\n random = tl.rand(seed.to(tl.int32), offsets)\n x_keep = random > p\n zero = 0.0\n zero = zero.to(x.dtype)\n return tl.where(x_keep, (x / (1 - p)).to(x.dtype), zero)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_dropout.py" }, { "uuid": "83c7f330-658f-46b1-b1f2-1cd74b5122b4", "file_name": "triton_welford.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/welford/triton_welford.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'XBLOCK': 1, 'RBLOCK': 1024},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 1, 'RBLOCK': 2048},\n num_stages=1, num_warps=8)], key=['xnumel', 'rnumel'])\n@triton.jit\ndef triton_red_fused_native_layer_norm_no_welford(in_out_ptr0, in_out_ptr1,\n in_ptr0, in_ptr1, in_ptr2, out_ptr0, xnumel, rnumel, XBLOCK: tl.\n constexpr, RBLOCK: tl.constexpr):\n xoffset = tl.program_id(0) * XBLOCK\n xindex = xoffset + tl.arange(0, XBLOCK)[:, None]\n xmask = xindex < xnumel\n rbase = tl.arange(0, RBLOCK)[None, :]\n x0 = xindex\n _tmp3 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r1 = rindex\n tmp0 = tl.load(in_ptr0 + (r1 + rnumel * x0), rmask, eviction_policy\n ='evict_last').to(tl.float32)\n tmp1 = tmp0.to(tl.float32)\n tmp2 = tl.broadcast_to(tmp1, [XBLOCK, RBLOCK])\n tmp4 = _tmp3 + tmp2\n _tmp3 = tmp4\n tmp3 = tl.sum(_tmp3, 1)[:, None]\n tmp5 = rnumel\n tmp6 = tmp3 / tmp5\n tl.debug_barrier()\n tl.store(in_out_ptr0 + x0, tmp6, None)\n _tmp12 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r1 = rindex\n tmp7 = tl.load(in_ptr0 + (r1 + rnumel * x0), rmask, eviction_policy\n ='evict_last').to(tl.float32)\n tmp8 = tmp7.to(tl.float32)\n tmp9 = tmp8 - tmp6\n tmp10 = tmp9 * tmp9\n tmp11 = tl.broadcast_to(tmp10, [XBLOCK, RBLOCK])\n tmp13 = _tmp12 + tmp11\n _tmp12 = tmp13\n tmp12 = tl.sum(_tmp12, 1)[:, None]\n tmp14 = rnumel\n tmp15 = tmp12 / tmp14\n tmp16 = 1e-05\n tmp17 = tmp15 + tmp16\n tmp18 = libdevice.rsqrt(tmp17)\n tl.debug_barrier()\n tl.store(in_out_ptr1 + x0, tmp18, None)\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r1 = rindex\n tmp19 = tl.load(in_ptr0 + (r1 + rnumel * x0), rmask,\n eviction_policy='evict_first').to(tl.float32)\n tmp23 = tl.load(in_ptr1 + r1, rmask, eviction_policy='evict_last').to(\n tl.float32)\n tmp26 = tl.load(in_ptr2 + r1, rmask, eviction_policy='evict_last').to(\n tl.float32)\n tmp20 = tmp19.to(tl.float32)\n tmp21 = tmp20 - tmp6\n tmp22 = tmp21 * tmp18\n tmp24 = tmp23.to(tl.float32)\n tmp25 = tmp22 * tmp24\n tmp27 = tmp26.to(tl.float32)\n tmp28 = tmp25 + tmp27\n tmp29 = tmp28.to(tl.float32)\n tl.store(out_ptr0 + (r1 + rnumel * x0), tmp29, rmask)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/welford/triton_welford.py" }, { "uuid": "c8059c9e-a8e6-4564-86fd-169f523010dc", "file_name": "positional_embedding.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/kernels/positional_embedding.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef _rope_fwd(q_ptr, k_ptr, f_ptr, oq_ptr, ok_ptr, stride, d, BLOCK_SIZE:\n tl.constexpr):\n bh_idx = tl.program_id(0)\n s_idx = tl.program_id(1)\n q_start_ptr = q_ptr + bh_idx * stride\n k_start_ptr = k_ptr + bh_idx * stride\n oq_start_ptr = oq_ptr + bh_idx * stride\n ok_start_ptr = ok_ptr + bh_idx * stride\n d_half = d // 2\n col_offsets = tl.arange(0, BLOCK_SIZE)\n col_offsets2 = tl.arange(0, BLOCK_SIZE * 2)\n f0_ptrs = f_ptr + s_idx * d * 2 + col_offsets2 * 2\n f1_ptrs = f_ptr + s_idx * d * 2 + col_offsets2 * 2 + 1\n f0 = tl.load(f0_ptrs, mask=col_offsets2 < d, other=0.0).reshape(BLOCK_SIZE,\n 2)\n f1 = tl.load(f1_ptrs, mask=col_offsets2 < d, other=0.0).reshape(BLOCK_SIZE,\n 2)\n q0_ptrs = q_start_ptr + s_idx * d + col_offsets * 2\n q1_ptrs = q_start_ptr + s_idx * d + col_offsets * 2 + 1\n q0 = tl.load(q0_ptrs, mask=col_offsets < d_half, other=0.0).reshape(\n BLOCK_SIZE, 1)\n q1 = tl.load(q1_ptrs, mask=col_offsets < d_half, other=0.0).reshape(\n BLOCK_SIZE, 1)\n k0_ptrs = k_start_ptr + s_idx * d + col_offsets * 2\n k1_ptrs = k_start_ptr + s_idx * d + col_offsets * 2 + 1\n k0 = tl.load(k0_ptrs, mask=col_offsets < d_half, other=0.0).reshape(\n BLOCK_SIZE, 1)\n k1 = tl.load(k1_ptrs, mask=col_offsets < d_half, other=0.0).reshape(\n BLOCK_SIZE, 1)\n oq = f0 * q0 + f1 * q1\n ok = f0 * k0 + f1 * k1\n oq_ptrs = oq_start_ptr + s_idx * d + col_offsets2\n ok_ptrs = ok_start_ptr + s_idx * d + col_offsets2\n tl.store(oq_ptrs, oq.reshape(BLOCK_SIZE * 2), mask=col_offsets2 < d)\n tl.store(ok_ptrs, ok.reshape(BLOCK_SIZE * 2), mask=col_offsets2 < d)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/kernels/positional_embedding.py" }, { "uuid": "ae45fb44-d0d9-48b0-8661-e897c1327370", "file_name": "seqlen_utils.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/seqlen_utils.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef seqlen_to_index_kernel(seqlen_ptr, idx_ptr, BLK: tl.constexpr):\n pid = tl.program_id(0)\n i = tl.load(seqlen_ptr + pid)\n j = tl.load(seqlen_ptr + pid + 1)\n idx = tl.arange(0, BLK)\n tl.store(idx_ptr + i + idx, idx, mask=idx < j - i)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "uint8" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/seqlen_utils.py" }, { "uuid": "510db266-e82a-4bbf-b760-757bb9b99da6", "file_name": "special.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/special.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef joint_second_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor,\n block_size: tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.\n constexpr):\n \"\"\"\n This Triton implementation includes l=0, 1, 2 within the\n same kernel, as it would be a common operation.\n \"\"\"\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST_00 = 3.87298334620742\n CONST_01 = 2.23606797749979\n CONST_02 = -1.11803398874989\n CONST_03 = 1.93649167310371\n CONST_04 = tl.sqrt(3.0)\n Y10 = CONST_04 * x\n Y11 = CONST_04 * y\n Y12 = CONST_04 * z\n Y20 = CONST_00 * x * z\n Y21 = CONST_00 * x * y\n Y23 = CONST_00 * y * z\n Y22 = CONST_02 * x * x + CONST_01 * y * y + CONST_02 * z * z\n Y24 = -CONST_03 * x * x + CONST_03 * z * z\n output_stride = 9\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = output_striding + block_size * output_stride * block_id\n tl.store(output_ptr + output_row_offset, 1.0, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y10, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y11, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y12, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y20, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y21, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y22, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y23, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y24, mask=\n output_row_offset + 7 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/special.py" }, { "uuid": "4e1ee352-1659-4bdb-be7f-7b5f64c2a6f8", "file_name": "triton_fused_vq_attn.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_vq_attn.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.jit\ndef _vq_attn_fwd_inner(acc, l_i, m_i, q, sm_scale, K_block_ptr,\n K_VQC_block_ptr, VVQI_block_ptr, V_VQ, stride_vvq_n, CODEBOOK_SIZE: tl.\n constexpr, BLOCK_HEADDIM: tl.constexpr, BLOCK_N: tl.constexpr):\n for _ in range(0, CODEBOOK_SIZE, BLOCK_N):\n k = tl.load(K_block_ptr)\n qk = tl.dot(q, k) * (sm_scale * RCP_LN2)\n k_vq_cnt = tl.load(K_VQC_block_ptr)\n mask = k_vq_cnt != 0.0\n qk = tl.where(mask[None, :], qk, NEGINF)\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc *= alpha[:, None]\n v_vq_index = tl.load(VVQI_block_ptr)\n v_ptr = V_VQ + (v_vq_index[:, None] * stride_vvq_n + tl.arange(0,\n BLOCK_HEADDIM)[None, :])\n v = tl.load(v_ptr)\n acc += tl.dot(p.to(v.dtype), v)\n l_i = l_i * alpha + tl.sum(p.to(v.dtype) * k_vq_cnt[None, :], axis=1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n K_VQC_block_ptr = tl.advance(K_VQC_block_ptr, (BLOCK_N,))\n VVQI_block_ptr = tl.advance(VVQI_block_ptr, (BLOCK_N,))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_vq_attn.py" }, { "uuid": "912d1872-d2e5-4a37-9f11-a8df42e90f66", "file_name": "y_10.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_10.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef tenth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_9 = tl.load(sph_grad_ptr + output_row_offset + 9, mask=\n output_row_offset + 9 < output_numel)\n g_10 = tl.load(sph_grad_ptr + output_row_offset + 10, mask=\n output_row_offset + 10 < output_numel)\n g_11 = tl.load(sph_grad_ptr + output_row_offset + 11, mask=\n output_row_offset + 11 < output_numel)\n g_12 = tl.load(sph_grad_ptr + output_row_offset + 12, mask=\n output_row_offset + 12 < output_numel)\n g_13 = tl.load(sph_grad_ptr + output_row_offset + 13, mask=\n output_row_offset + 13 < output_numel)\n g_14 = tl.load(sph_grad_ptr + output_row_offset + 14, mask=\n output_row_offset + 14 < output_numel)\n g_15 = tl.load(sph_grad_ptr + output_row_offset + 15, mask=\n output_row_offset + 15 < output_numel)\n g_16 = tl.load(sph_grad_ptr + output_row_offset + 16, mask=\n output_row_offset + 16 < output_numel)\n g_17 = tl.load(sph_grad_ptr + output_row_offset + 17, mask=\n output_row_offset + 17 < output_numel)\n g_18 = tl.load(sph_grad_ptr + output_row_offset + 18, mask=\n output_row_offset + 18 < output_numel)\n g_19 = tl.load(sph_grad_ptr + output_row_offset + 19, mask=\n output_row_offset + 19 < output_numel)\n g_20 = tl.load(sph_grad_ptr + output_row_offset + 20, mask=\n output_row_offset + 20 < output_numel)\n CONST000 = 2.0\n CONST002 = 4.0\n CONST003 = 4.82870805793735\n CONST004 = 6.0\n CONST005 = 4.9743298563255\n CONST006 = 8.0\n CONST007 = 4.9743298563255\n CONST008 = 10.5521471197994\n CONST009 = 3.0\n CONST010 = 5.0\n CONST011 = 7.0\n CONST012 = 13.264879616868\n CONST014 = 12.1657520803952\n CONST015 = 16.7271353825295\n CONST016 = -2030.35546709287\n CONST017 = 19.3148322317494\n CONST018 = -6131.53904851919\n CONST019 = 22.862985426232\n CONST020 = 23.213539329519\n CONST021 = 24.6216766128653\n CONST022 = 17.5869118663323\n CONST024 = 28.9722483476241\n CONST025 = 33.9852909359329\n CONST026 = 33.9852909359329\n CONST027 = 35.5238206489124\n CONST028 = 6180.7463141598\n CONST029 = 38.6296644634988\n CONST030 = 39.794638850604\n CONST031 = 38.6296644634988\n CONST032 = -2007.25624590353\n CONST033 = -2007.25624590353\n CONST034 = 45.8257569495584\n CONST035 = 45.725970852464\n CONST037 = 56.3871618715269\n CONST038 = 56.2781179722634\n CONST039 = -1989.33395633909\n CONST040 = -1989.33395633909\n CONST041 = 59.691958275906\n CONST042 = 66.9085415301178\n CONST043 = 69.640617988557\n CONST044 = -8121.42186837148\n CONST045 = 77.2593289269976\n CONST046 = 78.6510608948335\n CONST047 = -1969.73412902922\n CONST048 = 77.3468749368712\n CONST049 = -1969.73412902922\n CONST050 = -9.65741611587469\n CONST051 = 90.1358837481638\n CONST053 = 94.9693240781945\n CONST055 = 96.5741611587469\n CONST057 = 98.486706451461\n CONST058 = 100.362812295177\n CONST059 = 101.517773354644\n CONST060 = 106.571461946737\n CONST061 = 106.571461946737\n CONST062 = 109.491768723557\n CONST063 = 109.491768723557\n CONST064 = 112.774323743054\n CONST065 = 112.774323743054\n CONST067 = 2165.26701586663\n CONST070 = 133.817083060236\n CONST071 = 139.281235977114\n CONST072 = 139.281235977114\n CONST073 = 141.5719096107\n CONST074 = 142.09528259565\n CONST075 = 147.730059677192\n CONST076 = 150.544218442765\n CONST077 = 150.074981259369\n CONST079 = 2202.22970505534\n CONST080 = -3939.46825805844\n CONST081 = -5968.00186901728\n CONST082 = 176.592751833137\n CONST083 = 176.178376404427\n CONST085 = 185.708314636152\n CONST087 = 196.973412902922\n CONST089 = 225.548647486108\n CONST090 = 225.548647486108\n CONST091 = 4330.53403173327\n CONST093 = 244.831037842559\n CONST094 = -1804.38917988886\n CONST095 = -1804.38917988886\n CONST097 = 2317.77986780993\n CONST098 = 278.562471954228\n CONST100 = 284.190565191299\n CONST101 = -1761.78376404427\n CONST103 = -9946.66978169547\n CONST104 = 9.948659712651\n CONST108 = -7878.93651611688\n CONST111 = 338.322971229162\n CONST112 = 360.877835977772\n CONST114 = -1671.37483172537\n CONST116 = 2436.42656051144\n CONST119 = 393.946825805844\n CONST120 = -1648.19901710928\n CONST121 = 401.451249180707\n CONST122 = 406.071093418574\n CONST123 = 412.04975427732\n CONST125 = -1624.2843736743\n CONST126 = 426.285847786949\n CONST127 = 426.285847786948\n CONST128 = 2486.66744542387\n CONST130 = 451.097294972216\n CONST131 = 451.097294972216\n CONST132 = 451.097294972215\n CONST133 = 6606.68911516602\n CONST134 = 6606.68911516602\n CONST135 = -1575.78730322338\n CONST136 = -1575.78730322338\n CONST137 = -3608.77835977772\n CONST139 = -1545.18657853995\n CONST140 = -1545.18657853995\n CONST142 = 535.268332240943\n CONST143 = 4635.55973561985\n CONST144 = 541.428124558099\n CONST145 = -3545.5214322526\n CONST146 = 557.124943908456\n CONST147 = -3523.56752808854\n CONST148 = -5571.24943908456\n CONST151 = 15.7883647328499\n CONST153 = 2642.67564606641\n CONST154 = 2642.67564606641\n CONST155 = 2676.34166120471\n CONST156 = 629.208487158668\n CONST158 = 4727.36190967013\n CONST159 = -1392.81235977114\n CONST160 = -1390.66792068596\n CONST162 = 663.111318779698\n CONST163 = -3427.63452979582\n CONST164 = -1378.81389032045\n CONST165 = 676.645942458323\n CONST167 = -1338.17083060236\n CONST168 = -1338.17083060236\n CONST169 = 721.755671955545\n CONST171 = 2785.62471954228\n CONST173 = 772.593289269975\n CONST175 = 787.893651611688\n CONST176 = 787.893651611688\n CONST177 = 6.632439808434\n CONST178 = 812.142186837148\n CONST180 = -1218.21328025572\n CONST181 = -1202.92611992591\n CONST182 = -1202.92611992591\n CONST183 = -3248.56874734859\n CONST184 = -3248.56874734859\n CONST185 = -5285.35129213281\n CONST186 = -1181.84047741753\n CONST190 = 2936.30627340712\n CONST192 = 2954.60119354383\n CONST193 = -1114.24988781691\n CONST194 = -16.581099521085\n CONST195 = -1101.11485252767\n CONST196 = -1081.63060497797\n CONST197 = 15.7302121789667\n CONST199 = 984.86706451461\n CONST202 = -1027.70719569249\n CONST203 = -1021.9231747532\n CONST204 = -3065.7695242596\n CONST205 = -1015.17773354644\n CONST206 = 3090.3731570799\n CONST207 = -994.666978169547\n CONST208 = -984.86706451461\n CONST209 = -984.86706451461\n CONST210 = -979.324151370235\n CONST211 = 1070.53666448189\n CONST212 = -979.324151370235\n CONST213 = 3151.57460644675\n CONST216 = -927.111947123971\n CONST217 = -927.11194712397\n CONST218 = -5.63871618715269\n CONST219 = -2954.60119354383\n CONST220 = -902.194589944431\n CONST221 = -900.449887556215\n CONST222 = -880.891882022136\n CONST223 = -880.891882022136\n CONST224 = -875.934149788456\n CONST226 = -4944.59705132784\n CONST228 = 3248.56874734859\n CONST229 = -835.687415862684\n CONST230 = 1218.21328025572\n CONST231 = -824.099508554641\n CONST232 = -824.863625092051\n CONST233 = -824.863625092051\n CONST234 = -812.142186837148\n CONST235 = 5352.68332240943\n CONST236 = -787.893651611688\n CONST237 = -787.893651611688\n CONST238 = -772.593289269976\n CONST239 = -742.833258544608\n CONST240 = -2785.62471954228\n CONST241 = -734.07656835178\n CONST242 = 1321.3378230332\n CONST243 = 1321.3378230332\n CONST244 = -706.371007332549\n CONST245 = -696.40617988557\n CONST246 = 1353.29188491665\n CONST247 = -675.337415667161\n CONST248 = -675.337415667161\n CONST250 = 3427.63452979582\n CONST251 = -669.085415301178\n CONST252 = -669.085415301178\n CONST253 = -669.085415301178\n CONST255 = -663.111318779698\n CONST256 = -2707.14062279049\n CONST258 = 1392.81235977114\n CONST259 = 1412.7420146651\n CONST260 = -4727.36190967013\n CONST261 = -2676.34166120471\n CONST262 = -618.07463141598\n CONST263 = -611.735236846792\n CONST264 = -611.735236846792\n CONST265 = 1443.51134391109\n CONST266 = -590.920238708766\n CONST267 = -10828.562491162\n CONST268 = -580.101562026534\n CONST269 = -2626.31217203896\n CONST272 = 5571.24943908456\n CONST273 = -12.8765548211663\n CONST274 = -557.124943908456\n CONST275 = -557.124943908456\n CONST277 = -541.428124558099\n CONST278 = -6685.49932690147\n CONST279 = 7664.42381064899\n CONST280 = -525.262434407792\n CONST281 = 1532.8847621298\n CONST283 = -497.333489084773\n CONST284 = -497.333489084773\n CONST285 = -492.433532257305\n CONST286 = 1575.78730322338\n CONST287 = 1575.78730322338\n CONST288 = -463.555973561985\n CONST289 = -450.224943778107\n CONST290 = -450.224943778107\n CONST291 = -450.224943778108\n CONST292 = -437.967074894228\n CONST293 = -2472.29852566392\n CONST294 = 1624.2843736743\n CONST295 = -2472.29852566392\n CONST296 = -406.071093418574\n CONST297 = -393.946825805844\n CONST298 = -393.946825805844\n CONST299 = -2436.42656051144\n CONST300 = -386.296644634988\n CONST301 = -386.296644634988\n CONST302 = -4456.99955126765\n CONST303 = -337.668707833581\n CONST304 = -337.668707833581\n CONST305 = -331.555659389849\n CONST306 = -331.555659389849\n CONST307 = -2363.68095483506\n CONST309 = -309.03731570799\n CONST310 = -4404.45941011068\n CONST311 = -309.03731570799\n CONST312 = -305.867618423396\n CONST313 = -305.867618423396\n CONST314 = -305.867618423396\n CONST315 = -300.731529981477\n CONST316 = 9946.66978169547\n CONST318 = -290.050781013267\n CONST319 = -284.190565191299\n CONST320 = -278.562471954228\n CONST321 = -278.562471954228\n CONST322 = -2317.77986780993\n CONST323 = -10505.2486881558\n CONST324 = -251.683394863467\n CONST325 = -251.683394863467\n CONST326 = -246.216766128653\n CONST327 = -244.831037842559\n CONST328 = -2285.08968653055\n CONST329 = -2285.08968653055\n CONST330 = 3862.96644634988\n CONST331 = -223.028471767059\n CONST332 = -220.222970505534\n CONST333 = -206.215906273013\n CONST334 = -203.035546709287\n CONST335 = -196.973412902922\n CONST336 = -196.973412902922\n CONST337 = -182.903883409856\n CONST338 = -2228.49977563382\n CONST340 = 16.4144510752435\n CONST341 = 3939.46825805844\n CONST342 = 3939.46825805844\n CONST343 = -154.518657853995\n CONST344 = -154.518657853995\n CONST345 = -150.074981259369\n CONST346 = -147.730059677191\n CONST347 = -146.815313670356\n CONST348 = -142.09528259565\n CONST349 = -131.315608601948\n CONST350 = -131.315608601948\n CONST351 = -130.52285145597\n CONST352 = -125.841697431734\n CONST353 = -125.841697431734\n CONST354 = -112.556235944527\n CONST355 = -103.107953136506\n CONST356 = -101.517773354644\n CONST357 = 1949.9373036796\n CONST358 = -98.486706451461\n CONST359 = -98.486706451461\n CONST360 = -2141.07332896377\n CONST361 = -2141.07332896377\n CONST362 = -92.854157318076\n CONST363 = -88.2963759165686\n CONST366 = -77.3468749368713\n CONST367 = 8121.42186837148\n CONST369 = -67.6645942458323\n CONST372 = -59.691958275906\n CONST373 = -49.2433532257305\n CONST374 = -49.2433532257305\n CONST375 = -45.1097294972216\n CONST376 = -45.1097294972216\n CONST377 = -42.2085884791976\n CONST378 = -27.2034486491732\n CONST379 = -24.6216766128653\n CONST380 = -22.862985426232\n CONST381 = -19.7354559160624\n CONST383 = -17.5869118663323\n CONST384 = -16.4144510752435\n CONST385 = -16.0956935264578\n CONST386 = -14.5025390506634\n CONST388 = -16.581099521085\n CONST389 = -15.7883647328499\n CONST390 = -14.0695294930659\n CONST391 = -11.2774323743054\n CONST392 = -11.2774323743054\n CONST393 = -13.264879616868\n CONST394 = -6.632439808434\n CONST395 = -5.63871618715269\n CONST396 = -4.82870805793735\n CONST397 = -3.21913870529156\n CONST398 = -11.2774323743054\n VAR05 = x * x * x * x * x\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR01 = VAR05 * VAR06\n VAR02 = VAR06 * VAR06\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR14 = y * y * y * y * y\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR10 = VAR14 * VAR15\n VAR11 = VAR15 * VAR15\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR23 = z * z * z * z * z\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR19 = VAR23 * VAR24\n VAR20 = VAR24 * VAR24\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += g_0 * (CONST093 * VAR02 * z + CONST210 * VAR08 * VAR21 + \n CONST250 * VAR06 * VAR23 + CONST328 * VAR04 * VAR25 - CONST378 * VAR19\n ) + g_1 * y * (CONST062 * VAR20 + CONST063 * VAR02 + CONST204 *\n VAR04 * VAR26 + CONST204 * VAR08 * VAR22 + CONST279 * VAR06 * VAR24\n ) + g_10 * (CONST000 * x * (CONST089 * VAR17 * VAR22 + CONST169 *\n VAR13 * VAR26 + CONST220 * VAR15 * VAR24 + CONST355 * VAR11 + \n CONST395 * VAR20) + CONST002 * VAR07 * (CONST111 * VAR17 * VAR24 + \n CONST112 * VAR13 + CONST220 * VAR15 * VAR26 + CONST392 * VAR22) + \n CONST004 * VAR05 * (CONST090 * VAR17 * VAR26 + CONST315 * VAR15 + \n CONST392 * VAR24) + CONST006 * VAR03 * (CONST037 * VAR17 + CONST218 *\n VAR26) + CONST391 * VAR01) + g_11 * (CONST070 * VAR21 * x * y + \n VAR23 * (CONST121 * VAR07 * y + CONST168 * VAR16 * x) + VAR25 * (\n CONST121 * VAR05 * y + CONST261 * VAR07 * VAR16 - CONST361 * VAR14 *\n x) + z * (CONST070 * VAR03 * y + CONST167 * VAR05 * VAR16 + \n CONST263 * VAR12 * x - CONST361 * VAR07 * VAR14)) + g_12 * (\n CONST000 * x * (CONST003 * VAR20 - CONST301 * VAR15 * VAR24 + \n CONST343 * VAR17 * VAR22 + CONST363 * VAR11) + CONST002 * VAR07 * (\n CONST123 * VAR13 + CONST300 * VAR15 * VAR26 - CONST397 * VAR22) + \n CONST004 * VAR05 * (CONST301 * VAR15 - CONST344 * VAR17 * VAR26 + \n CONST397 * VAR24) + CONST006 * VAR03 * (CONST045 * VAR17 + CONST396 *\n VAR26) + CONST385 * VAR01) + g_13 * (CONST221 * VAR12 * x * z + \n VAR14 * (-CONST260 * VAR07 * z + CONST286 * VAR25 * x) + VAR16 * (\n CONST080 * VAR07 * VAR25 + CONST145 * VAR05 * z + CONST297 * VAR23 *\n x) + y * (-CONST237 * VAR05 * VAR25 - CONST297 * VAR07 * VAR23 - \n CONST298 * VAR03 * z)) + g_14 * (CONST000 * x * (CONST005 * VAR20 -\n CONST159 * VAR15 * VAR24 + CONST193 * VAR13 * VAR26 + CONST320 *\n VAR17 * VAR22) + CONST002 * VAR07 * (CONST020 * VAR22 + CONST085 *\n VAR13 + CONST245 * VAR17 * VAR24 + CONST258 * VAR15 * VAR26) + \n CONST004 * VAR05 * (CONST020 * VAR24 + CONST320 * VAR15 + CONST320 *\n VAR17 * VAR26) + CONST006 * VAR03 * (CONST007 * VAR26 + CONST043 *\n VAR17) + CONST388 * VAR01) + g_15 * (VAR14 * (-CONST147 * VAR07 * z +\n CONST147 * VAR25 * x) + VAR16 * (CONST153 * VAR23 * x + CONST190 *\n VAR07 * VAR25 + CONST310 * VAR05 * z) + y * (CONST156 * VAR03 * z +\n CONST222 * VAR07 * VAR23 + CONST324 * VAR21 * x)) + g_16 * (\n CONST000 * x * (CONST047 * VAR15 * VAR24 + CONST175 * VAR17 * VAR22 +\n CONST380 * VAR20) + CONST002 * VAR07 * (-CONST047 * VAR15 * VAR26 +\n CONST379 * VAR22) + CONST004 * VAR05 * (CONST021 * VAR24 + CONST236 *\n VAR17 * VAR26 + CONST349 * VAR15) + CONST006 * VAR03 * (CONST019 *\n VAR26 + CONST038 * VAR17) + CONST383 * VAR01) + g_17 * (VAR16 * (\n CONST183 * VAR23 * x + CONST184 * VAR05 * z - CONST267 * VAR07 *\n VAR25) + y * (CONST178 * VAR03 * z + CONST234 * VAR07 * VAR23 - \n CONST268 * VAR21 * x + CONST299 * VAR05 * VAR25)) + g_18 * (\n CONST060 * VAR20 * x + CONST126 * VAR03 * VAR26 + CONST283 * VAR05 *\n VAR24 + CONST305 * VAR07 * VAR22 + CONST381 * VAR01 + VAR17 * (\n CONST039 * VAR22 * x + CONST081 * VAR05 * VAR26 + CONST316 * VAR07 *\n VAR24 - CONST319 * VAR03)) + g_19 * y * (CONST018 * VAR05 * VAR25 -\n CONST018 * VAR07 * VAR23 - CONST224 * VAR03 * z + CONST224 * VAR21 * x\n ) + g_2 * (CONST074 * VAR02 * z + CONST100 * VAR08 * VAR21 + \n CONST255 * VAR04 * VAR25 + CONST389 * VAR19 + VAR17 * (CONST040 *\n VAR04 * z + CONST081 * VAR08 * VAR23 - CONST103 * VAR06 * VAR25 - \n CONST319 * VAR21)) + g_20 * (CONST163 * VAR05 * VAR24 - CONST212 *\n VAR03 * VAR26 + CONST327 * VAR20 * x - CONST329 * VAR07 * VAR22 + \n CONST378 * VAR01) + g_3 * (VAR16 * (CONST044 * VAR08 * VAR24 + \n CONST144 * VAR22 + CONST277 * VAR04 + CONST367 * VAR06 * VAR26) + y *\n (CONST016 * VAR04 * VAR26 - CONST205 * VAR06 * VAR24 + CONST230 *\n VAR08 * VAR22 - CONST351 * VAR02 + CONST356 * VAR20)) + g_4 * (\n CONST008 * VAR19 + CONST009 * VAR08 * (CONST175 * VAR17 * VAR23 + \n CONST269 * VAR15 * VAR25 + CONST390 * VAR21) + CONST010 * VAR06 * (\n CONST175 * VAR15 * z + CONST176 * VAR17 * VAR25 + CONST373 * VAR23) +\n CONST011 * VAR04 * (CONST303 * VAR17 * z + CONST390 * VAR25) + \n CONST053 * VAR02 * z + CONST175 * VAR15 * VAR23 + CONST304 * VAR17 *\n VAR21) + g_5 * (VAR14 * (CONST185 * VAR08 * VAR26 - CONST222 *\n VAR06 - CONST223 * VAR24) + VAR16 * (CONST079 * VAR08 * VAR24 + \n CONST133 * VAR06 * VAR26 + CONST202 * VAR04 + CONST241 * VAR22) + y *\n (CONST046 * VAR20 + CONST073 * VAR02 + CONST195 * VAR06 * VAR24 + \n CONST222 * VAR04 * VAR26)) + g_6 * (CONST009 * VAR08 * (CONST098 *\n VAR17 * VAR23 + CONST239 * VAR13 * z + CONST393 * VAR21) + CONST010 *\n VAR06 * (-CONST193 * VAR15 * z + CONST320 * VAR17 * VAR25) + \n CONST011 * VAR04 * (CONST012 * VAR25 + CONST321 * VAR17 * z) + \n CONST041 * VAR02 * z + CONST098 * VAR17 * VAR21 + CONST193 * VAR15 *\n VAR23 - CONST239 * VAR13 * VAR25 + CONST394 * VAR19) + g_7 * (VAR12 *\n (CONST289 * VAR08 - CONST290 * VAR26) + VAR14 * (-CONST049 * VAR06 +\n CONST186 * VAR24 + CONST307 * VAR08 * VAR26) + VAR16 * (CONST164 *\n VAR04 + CONST192 * VAR08 * VAR24 + CONST199 * VAR06 * VAR26 - \n CONST266 * VAR22) + y * (CONST075 * VAR02 + CONST285 * VAR06 *\n VAR24 + CONST297 * VAR08 * VAR22 + CONST374 * VAR20)) + g_8 * (\n CONST009 * VAR08 * (-CONST140 * VAR15 * VAR25 + CONST231 * VAR13 *\n z - CONST273 * VAR21 + CONST288 * VAR17 * VAR23) + CONST010 * VAR06 *\n (CONST017 * VAR23 + CONST173 * VAR15 * z + CONST288 * VAR17 * VAR25\n ) + CONST011 * VAR04 * (-CONST273 * VAR25 + CONST344 * VAR17 * z) +\n CONST024 * VAR02 * z + CONST082 * VAR11 * z + CONST173 * VAR15 *\n VAR23 + CONST231 * VAR13 * VAR25 + CONST344 * VAR17 * VAR21 - \n CONST397 * VAR19) + g_9 * (CONST009 * VAR08 * (CONST042 * VAR22 * y +\n CONST211 * VAR14 * VAR26 + CONST251 * VAR16 * VAR24 + CONST312 *\n VAR12) + CONST010 * VAR06 * (CONST058 * VAR24 * y + CONST142 *\n VAR14 + CONST252 * VAR16 * VAR26) + CONST011 * VAR04 * (CONST042 *\n VAR26 * y + CONST331 * VAR16) + CONST015 * VAR20 * y + CONST025 *\n VAR10 + CONST076 * VAR02 * y + CONST142 * VAR14 * VAR24 + CONST312 *\n VAR12 * VAR26 + CONST331 * VAR16 * VAR22)\n g_y += CONST000 * g_18 * y * (CONST027 * VAR02 + CONST027 * VAR20 + \n CONST128 * VAR06 * VAR24 + CONST207 * VAR04 * VAR26 + CONST207 *\n VAR08 * VAR22) + CONST000 * g_2 * y * (-CONST039 * VAR05 * VAR25 + \n CONST039 * VAR07 * VAR23 + CONST319 * VAR03 * z - CONST319 * VAR21 * x\n ) + g_1 * (CONST014 * VAR01 + CONST062 * VAR20 * x + CONST203 *\n VAR07 * VAR22 + CONST281 * VAR05 * VAR24 + CONST292 * VAR03 * VAR26\n ) + g_10 * (CONST034 * VAR10 + CONST064 * VAR20 * y + CONST065 *\n VAR02 * y + CONST067 * VAR14 * VAR24 + CONST182 * VAR16 * VAR22 + \n CONST233 * VAR12 * VAR26 + VAR04 * (CONST131 * VAR26 * y + CONST181 *\n VAR16) + VAR06 * (CONST067 * VAR14 + CONST137 * VAR16 * VAR26 + \n CONST165 * VAR24 * y) + VAR08 * (CONST091 * VAR14 * VAR26 + \n CONST130 * VAR22 * y + CONST137 * VAR16 * VAR24 + CONST232 * VAR12)\n ) + g_11 * (CONST015 * VAR19 + VAR21 * (CONST042 * VAR08 + CONST253 *\n VAR17) + VAR23 * (CONST033 * VAR08 * VAR17 + CONST058 * VAR06 + \n CONST155 * VAR15) + VAR25 * (CONST032 * VAR06 * VAR17 + CONST042 *\n VAR04 + CONST235 * VAR08 * VAR15 + CONST361 * VAR13) + z * (\n CONST015 * VAR02 + CONST155 * VAR06 * VAR15 + CONST253 * VAR04 *\n VAR17 - CONST312 * VAR11 + CONST360 * VAR08 * VAR13)) + g_12 * (-\n CONST140 * VAR16 * VAR22 - CONST244 * VAR12 * VAR26 + CONST293 *\n VAR14 * VAR24 + CONST343 * VAR20 * y - CONST344 * VAR02 * y + VAR04 *\n (CONST140 * VAR16 - CONST311 * VAR26 * y) + VAR06 * (CONST139 *\n VAR16 * VAR26 - CONST295 * VAR14) + VAR08 * (-CONST140 * VAR16 *\n VAR24 + CONST244 * VAR12 + CONST309 * VAR22 * y)) + g_13 * (\n CONST009 * VAR17 * (CONST208 * VAR06 * VAR25 + CONST266 * VAR04 * z +\n CONST335 * VAR08 * VAR23 - CONST336 * VAR21) + CONST010 * VAR15 * (\n CONST176 * VAR08 * VAR25 - CONST186 * VAR06 * z + CONST298 * VAR23) +\n CONST011 * VAR13 * (CONST077 * VAR25 + CONST290 * VAR08 * z) - \n CONST350 * VAR04 * VAR25 - CONST358 * VAR06 * VAR23 - CONST374 *\n VAR02 * z + CONST384 * VAR19) + g_14 * (CONST071 * VAR02 * y + \n CONST072 * VAR20 * y - CONST193 * VAR14 * VAR24 + CONST193 * VAR16 *\n VAR22 + VAR04 * (CONST193 * VAR16 + CONST274 * VAR26 * y) + VAR06 *\n (CONST159 * VAR24 * y - CONST193 * VAR14 + CONST272 * VAR16 * VAR26\n ) + VAR08 * (-CONST148 * VAR16 * VAR24 + CONST274 * VAR22 * y + \n CONST278 * VAR14 * VAR26)) + g_15 * (CONST009 * VAR17 * (CONST241 *\n VAR04 * z - CONST241 * VAR06 * VAR25 + CONST242 * VAR08 * VAR23 + \n CONST347 * VAR21) + CONST010 * VAR15 * (CONST083 * VAR23 + CONST101 *\n VAR08 * VAR25 - CONST223 * VAR06 * z) + CONST046 * VAR02 * z + \n CONST197 * VAR19 + CONST332 * VAR06 * VAR23 + CONST352 * VAR08 * VAR21\n ) + g_16 * (-CONST108 * VAR06 * VAR16 * VAR26 - CONST280 * VAR16 *\n VAR22 - CONST354 * VAR02 * y + CONST354 * VAR20 * y + VAR04 * (\n CONST135 * VAR26 * y + CONST280 * VAR16) + VAR08 * (CONST108 *\n VAR16 * VAR24 + CONST287 * VAR22 * y)) + g_17 * (CONST009 * VAR17 *\n (CONST048 * VAR21 + CONST125 * VAR08 * VAR23 - CONST256 * VAR06 *\n VAR25 + CONST277 * VAR04 * z) + CONST059 * VAR02 * z + CONST296 *\n VAR04 * VAR25 - CONST318 * VAR08 * VAR21 + CONST334 * VAR06 * VAR23 +\n CONST386 * VAR19) + g_19 * (CONST014 * VAR19 + CONST062 * VAR02 * z +\n CONST203 * VAR04 * VAR25 + CONST281 * VAR06 * VAR23 + CONST292 *\n VAR08 * VAR21) + g_3 * (CONST009 * VAR17 * (CONST144 * VAR22 * x + \n CONST256 * VAR07 * VAR24 + CONST294 * VAR05 * VAR26 + CONST366 *\n VAR03) + CONST122 * VAR07 * VAR22 + CONST318 * VAR03 * VAR26 - \n CONST334 * VAR05 * VAR24 + CONST356 * VAR20 * x - CONST386 * VAR01\n ) + g_4 * (CONST248 * VAR03 * y * z + VAR05 * (CONST213 * VAR16 * z +\n CONST286 * VAR25 * y) + VAR07 * (CONST287 * VAR23 * y + CONST323 *\n VAR16 * VAR25) + x * (CONST213 * VAR16 * VAR23 + CONST247 * VAR21 * y)\n ) + g_5 * (CONST009 * VAR17 * (-CONST241 * VAR07 * VAR24 + CONST241 *\n VAR22 * x + CONST243 * VAR05 * VAR26 + CONST347 * VAR03) + CONST010 *\n VAR15 * (CONST083 * VAR05 + CONST101 * VAR07 * VAR26 - CONST223 *\n VAR24 * x) + CONST046 * VAR20 * x + CONST197 * VAR01 + CONST332 *\n VAR05 * VAR24 + CONST353 * VAR03 * VAR26) + g_6 * (CONST275 * VAR03 *\n y * z + VAR05 * (CONST274 * VAR25 * y - CONST302 * VAR16 * z) + \n VAR07 * (CONST146 * VAR23 * y + CONST302 * VAR14 * z) + x * (\n CONST146 * VAR21 * y - CONST302 * VAR14 * VAR25 + CONST302 * VAR16 *\n VAR23)) + g_7 * (CONST009 * VAR17 * (CONST087 * VAR05 * VAR26 - \n CONST209 * VAR07 * VAR24 - CONST266 * VAR22 * x + CONST336 * VAR03) +\n CONST010 * VAR15 * (CONST186 * VAR24 * x + CONST237 * VAR07 * VAR26 -\n CONST298 * VAR05) + CONST011 * VAR13 * (-CONST290 * VAR26 * x + \n CONST345 * VAR07) + CONST340 * VAR01 + CONST350 * VAR07 * VAR22 + \n CONST358 * VAR05 * VAR24 + CONST374 * VAR20 * x) + g_8 * (CONST311 *\n VAR03 * y * z + VAR05 * (CONST206 * VAR16 * z + CONST216 * VAR25 *\n y) + VAR07 * (CONST028 * VAR16 * VAR25 + CONST216 * VAR23 * y + \n CONST226 * VAR14 * z) + x * (CONST206 * VAR16 * VAR23 + CONST226 *\n VAR14 * VAR25 + CONST259 * VAR12 * z + CONST311 * VAR21 * y)) + g_9 * (\n CONST015 * VAR01 + VAR03 * (CONST042 * VAR26 + CONST253 * VAR17) + \n VAR05 * (CONST033 * VAR17 * VAR26 + CONST058 * VAR24 + CONST155 *\n VAR15) + VAR07 * (CONST032 * VAR17 * VAR24 + CONST042 * VAR22 + \n CONST235 * VAR15 * VAR26 + CONST361 * VAR13) + x * (CONST015 *\n VAR20 + CONST155 * VAR15 * VAR24 + CONST253 * VAR17 * VAR22 - \n CONST314 * VAR11 + CONST361 * VAR13 * VAR26))\n g_z += g_0 * (CONST093 * VAR20 * x + CONST210 * VAR03 * VAR26 + \n CONST250 * VAR05 * VAR24 + CONST328 * VAR07 * VAR22 - CONST378 * VAR01\n ) + g_1 * y * (-CONST018 * VAR05 * VAR25 + CONST018 * VAR07 * VAR23 +\n CONST224 * VAR03 * z - CONST224 * VAR21 * x) + g_10 * (CONST095 *\n VAR15 * VAR23 + CONST132 * VAR17 * VAR21 + CONST265 * VAR13 * VAR25 +\n CONST333 * VAR11 * z + CONST391 * VAR19 + CONST398 * VAR02 * z + \n VAR04 * (CONST131 * VAR17 * z + CONST376 * VAR25) + VAR06 * (\n CONST094 * VAR15 * z + CONST246 * VAR17 * VAR25 + CONST369 * VAR23) +\n VAR08 * (CONST137 * VAR15 * VAR25 + CONST246 * VAR17 * VAR23 + \n CONST265 * VAR13 * z + CONST375 * VAR21)) + g_11 * (CONST009 *\n VAR26 * (CONST042 * VAR04 * y + CONST211 * VAR08 * VAR14 + CONST251 *\n VAR06 * VAR16 + CONST313 * VAR12) + CONST010 * VAR24 * (CONST058 *\n VAR06 * y + CONST142 * VAR14 + CONST252 * VAR08 * VAR16) + CONST011 *\n VAR22 * (CONST042 * VAR08 * y + CONST331 * VAR16) + CONST015 *\n VAR02 * y + CONST026 * VAR10 + CONST076 * VAR20 * y + CONST142 *\n VAR06 * VAR14 + CONST314 * VAR08 * VAR12 + CONST331 * VAR04 * VAR16\n ) + g_12 * (CONST050 * VAR02 * z + CONST082 * VAR11 * z + CONST097 *\n VAR15 * VAR23 + CONST120 * VAR13 * VAR25 + CONST262 * VAR17 * VAR21 -\n CONST385 * VAR19 + VAR04 * (CONST273 * VAR25 - CONST311 * VAR17 * z\n ) + VAR06 * (CONST017 * VAR23 + CONST238 * VAR15 * z) + VAR08 * (\n CONST029 * VAR21 - CONST140 * VAR15 * VAR25 + CONST217 * VAR17 * VAR23)\n ) + g_13 * (VAR12 * (CONST290 * VAR08 - CONST290 * VAR26) + VAR14 *\n (CONST049 * VAR24 - CONST186 * VAR06 - CONST307 * VAR08 * VAR26) + \n VAR16 * (-CONST164 * VAR22 + CONST209 * VAR08 * VAR24 + CONST219 *\n VAR06 * VAR26 + CONST266 * VAR04) + y * (-CONST285 * VAR06 * VAR24 -\n CONST297 * VAR04 * VAR26 + CONST346 * VAR20 - CONST374 * VAR02)\n ) + g_14 * (CONST104 * VAR02 * z + CONST114 * VAR15 * VAR23 + \n CONST146 * VAR17 * VAR21 + CONST194 * VAR19 - CONST239 * VAR13 *\n VAR25 + VAR04 * (CONST274 * VAR17 * z - CONST362 * VAR25) + VAR06 *\n (CONST072 * VAR23 + CONST171 * VAR15 * z + CONST240 * VAR17 * VAR25\n ) + VAR08 * (CONST030 * VAR21 + CONST114 * VAR17 * VAR23 - CONST148 *\n VAR15 * VAR25 + CONST338 * VAR13 * z)) + g_15 * (VAR14 * (CONST185 *\n VAR08 * VAR26 - CONST222 * VAR24 - CONST223 * VAR06) + VAR16 * (\n CONST079 * VAR06 * VAR26 + CONST134 * VAR08 * VAR24 + CONST202 *\n VAR22 + CONST241 * VAR04) + y * (CONST046 * VAR02 + CONST073 *\n VAR20 + CONST195 * VAR06 * VAR24 + CONST223 * VAR08 * VAR22)\n ) + g_16 * (CONST022 * VAR19 + CONST035 * VAR02 * z + CONST175 *\n VAR15 * VAR23 + CONST291 * VAR17 * VAR21 + VAR04 * (CONST057 *\n VAR25 + CONST135 * VAR17 * z) + VAR06 * (CONST341 * VAR15 * z + \n CONST346 * VAR23) + VAR08 * (CONST108 * VAR15 * VAR25 + CONST158 *\n VAR17 * VAR23 + CONST337 * VAR21)) + g_17 * (VAR16 * (-CONST044 *\n VAR06 * VAR26 + CONST044 * VAR08 * VAR24 + CONST144 * VAR22 + \n CONST277 * VAR04) + y * (-CONST016 * VAR08 * VAR22 + CONST059 *\n VAR02 + CONST180 * VAR04 * VAR26 + CONST205 * VAR06 * VAR24 + \n CONST351 * VAR20)) + g_18 * (CONST061 * VAR02 * z + CONST127 *\n VAR08 * VAR21 + CONST284 * VAR06 * VAR23 + CONST306 * VAR04 * VAR25 +\n CONST381 * VAR19 + VAR17 * (CONST039 * VAR04 * z + CONST081 * VAR08 *\n VAR23 + CONST316 * VAR06 * VAR25 - CONST319 * VAR21)) + g_19 * y * (\n CONST062 * VAR02 + CONST063 * VAR20 + CONST204 * VAR04 * VAR26 + \n CONST204 * VAR08 * VAR22 + CONST279 * VAR06 * VAR24) + g_2 * (\n CONST151 * VAR01 + CONST162 * VAR07 * VAR22 + CONST319 * VAR03 *\n VAR26 + CONST348 * VAR20 * x + VAR17 * (-CONST040 * VAR22 * x - \n CONST081 * VAR05 * VAR26 + CONST103 * VAR07 * VAR24 + CONST319 * VAR03)\n ) + g_20 * (-CONST163 * VAR06 * VAR23 + CONST212 * VAR08 * VAR21 - \n CONST327 * VAR02 * z + CONST329 * VAR04 * VAR25 - CONST378 * VAR19\n ) + g_3 * (VAR16 * (-CONST183 * VAR23 * x + CONST228 * VAR05 * z + \n CONST267 * VAR07 * VAR25) + y * (CONST116 * VAR07 * VAR23 - \n CONST234 * VAR05 * VAR25 + CONST234 * VAR21 * x + CONST268 * VAR03 * z)\n ) + g_4 * (CONST008 * VAR01 + VAR03 * (CONST303 * VAR17 + CONST377 *\n VAR26) + VAR05 * (CONST175 * VAR15 - CONST307 * VAR17 * VAR26 + \n CONST326 * VAR24) + VAR07 * (CONST108 * VAR15 * VAR26 + CONST341 *\n VAR17 * VAR24 + CONST359 * VAR22) + x * (CONST053 * VAR20 + \n CONST307 * VAR17 * VAR22 + CONST341 * VAR15 * VAR24)) + g_5 * (\n VAR14 * (CONST147 * VAR07 * z - CONST147 * VAR25 * x) + VAR16 * (\n CONST154 * VAR05 * z + CONST190 * VAR07 * VAR25 + CONST310 * VAR23 *\n x) + y * (CONST156 * VAR21 * x + CONST222 * VAR05 * VAR25 + \n CONST325 * VAR03 * z)) + g_6 * (CONST177 * VAR01 + VAR03 * (\n CONST030 * VAR26 + CONST321 * VAR17) + VAR05 * (-CONST193 * VAR15 +\n CONST229 * VAR17 * VAR26) + VAR07 * (CONST239 * VAR13 + CONST258 *\n VAR17 * VAR24 + CONST362 * VAR22) + x * (CONST148 * VAR15 * VAR24 -\n CONST338 * VAR13 * VAR26 + CONST357 * VAR17 * VAR22 + CONST372 * VAR20)\n ) + g_7 * (-CONST221 * VAR12 * x * z + VAR14 * (CONST136 * VAR07 *\n z + CONST260 * VAR25 * x) + VAR16 * (CONST119 * VAR05 * z - \n CONST145 * VAR23 * x + CONST342 * VAR07 * VAR25) + y * (CONST237 *\n VAR07 * VAR23 + CONST297 * VAR05 * VAR25 + CONST298 * VAR21 * x)\n ) + g_8 * (-CONST397 * VAR01 + VAR03 * (CONST031 * VAR26 + CONST344 *\n VAR17) + VAR05 * (CONST055 * VAR24 + CONST160 * VAR17 * VAR26 + \n CONST173 * VAR15) + VAR07 * (CONST051 * VAR22 + CONST143 * VAR15 *\n VAR26 + CONST231 * VAR13 + CONST322 * VAR17 * VAR24) + x * (\n CONST024 * VAR20 + CONST082 * VAR11 + CONST196 * VAR17 * VAR22 + \n CONST295 * VAR13 * VAR26 + CONST330 * VAR15 * VAR24)) + g_9 * (\n CONST070 * VAR03 * y * z + VAR05 * (CONST121 * VAR25 * y + CONST168 *\n VAR16 * z) + VAR07 * (CONST121 * VAR23 * y + CONST261 * VAR16 *\n VAR25 - CONST361 * VAR14 * z) + x * (CONST070 * VAR21 * y + \n CONST167 * VAR16 * VAR23 + CONST264 * VAR12 * z - CONST361 * VAR14 *\n VAR25))\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_10.py" }, { "uuid": "de16e6fe-5490-4908-ad00-f28cbf3e7e54", "file_name": "dropout.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/dropout.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef _seeded_dropout(x_ptr, output_ptr, n_elements, p, seed, BLOCK_SIZE: tl.\n constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE * 4\n offset = block_start + tl.arange(0, BLOCK_SIZE)\n r0, r1, r2, r3 = tl.random.rand4x(seed, offset)\n scale = 1.0 / (1.0 - p)\n for i in tl.static_range(4):\n curr_offset = offset + BLOCK_SIZE * i\n mask = curr_offset < n_elements\n x = tl.load(x_ptr + curr_offset, mask=mask)\n r = tl.where(i == 0, r0, tl.where(i == 1, r1, tl.where(i == 2, r2, r3))\n )\n keep = r > p\n output = tl.where(keep, x * scale, 0.0)\n tl.store(output_ptr + curr_offset, output, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/dropout.py" }, { "uuid": "732ba6cd-e311-45e1-a903-5a7a6189d148", "file_name": "fused_kl_div.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_kl_div.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef elementwise_mul_kernel(x, g, N: tl.constexpr, B: tl.constexpr):\n \"\"\"\n This function multiplies each element of the tensor pointed by x with the value pointed by g.\n The multiplication is performed in-place on the tensor pointed by x.\n\n Parameters:\n x:\n Pointer to the input tensor.\n g:\n Pointer to the gradient output value.\n N (int):\n The number of columns in the input tensor.\n B (int):\n The block size for Triton operations.\n \"\"\"\n i_x = tl.program_id(0).to(tl.int64)\n o_x = i_x * B + tl.arange(0, B)\n b_g = tl.load(g)\n b_x = tl.load(x + o_x, mask=o_x < N)\n tl.store(x + o_x, b_x * b_g, mask=o_x < N)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_kl_div.py" }, { "uuid": "1db7555b-32ef-4cc2-9217-8ecf0ada9c85", "file_name": "cross_entropy_loss_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/cross_entropy_loss_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef cross_entropy_loss_backward_kernel(output_grad_pointer, target_pointer,\n input_pointer, weight_pointer, sum_weights_pointer, input_grad_pointer,\n batch_dim, feat_dim, input_batch_stride, input_feat_stride,\n input_grad_batch_stride, input_grad_feat_stride, weighted: tl.constexpr,\n BLOCK_SIZE_BATCH: tl.constexpr, BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Calculates the input gradient of cross entropy loss.\n\n Args:\n output_grad_pointer: Pointer to the loss's output gradients.\n The output gradient must be a scalar.\n target_pointer: Pointer to the target.\n The target must be of shape [batch_dim].\n input_pointer: Pointer to the input.\n The input must be of shape [batch_dim, feat_dim].\n weight_pointer: Pointer to an optional class weight vector.\n The class weight vector, if provided, must be of shape [feat_dim].\n sum_weights_pointer: Pointer to the sum of the class weights if the classes were weighed.\n The sum of weights must be a scalar.\n input_grad_pointer: Pointer to a container the input's gradients are written to.\n The container must be of shape [batch_dim, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n input_grad_batch_stride: Stride necessary to jump one element along the\n input gradient container's batch dimension.\n input_grad_feat_stride: Stride necessary to jump one element along the\n input gradient container's feature dimension.\n weighted: Flag for weighing each class.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n input_grad_pointer += input_grad_batch_stride * batch_offset[:, None\n ] + input_grad_feat_stride * feat_offset[None, :]\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :], other=-float('inf')).to(tl.float32)\n input -= tl.max(input, axis=1)[:, None]\n numerator = tl.exp(input)\n softmax = numerator / tl.sum(numerator, axis=1)[:, None]\n output_grad = tl.load(output_grad_pointer).to(tl.float32)\n target = tl.load(target_pointer + batch_offset, mask=batch_mask)\n broadcasted_feat_offset = tl.broadcast_to(feat_offset[None, :], (\n BLOCK_SIZE_BATCH, BLOCK_SIZE_FEAT))\n broadcasted_target = tl.broadcast_to(target[:, None], (BLOCK_SIZE_BATCH,\n BLOCK_SIZE_FEAT))\n input_grad = output_grad * (softmax - (broadcasted_feat_offset ==\n broadcasted_target))\n if weighted:\n weight = tl.load(weight_pointer + target, mask=batch_mask).to(tl.\n float32)\n sum_weights = tl.load(sum_weights_pointer)\n input_grad *= weight[:, None] / sum_weights\n else:\n input_grad /= batch_dim\n tl.store(input_grad_pointer, input_grad, mask=batch_mask[:, None] &\n feat_mask[None, :])\n", "category": { "Functionality": [ "Backpropagation", "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput", "Batch-Oriented" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/cross_entropy_loss_kernels.py" }, { "uuid": "f3a6e3a3-92be-4174-ade1-4a029fd7be9b", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BV': BV}, num_warps=num_warps,\n num_stages=num_stages) for BV in [32, 64, 128] for num_warps in [2, 4] for\n num_stages in [2, 3, 4]], key=['BT'])\n@triton.jit\ndef chunk_retention_bwd_kernel_dqkv(q, k, v, h, do, dh, dq, dk, dv, offsets,\n indices, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV:\n tl.constexpr, NT: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n o_i = tl.arange(0, BT)\n d_q, d_k = tl.math.exp2((o_i + 1) * b_b), tl.math.exp2((min(BT, T - i_t *\n BT) - o_i - 1) * b_b)\n d_q = (d_q * scale).to(d_q.dtype)\n m_s = o_i[:, None] >= o_i[None, :]\n d_s = tl.where(m_s, tl.math.exp2((o_i[:, None] - o_i[None, :]) * b_b), 0\n ) * scale\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k * BK,\n i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H * K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_s = tl.dot(b_k, b_q, allow_tf32=False) * tl.trans(d_s)\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_ds = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * B * H + i_bh) * T * V, (T,\n V), (V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + ((i_k * all + bos) * H + i_h) * V,\n (T, V), (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_ds += tl.dot(b_do, tl.trans(b_v), allow_tf32=False)\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_dk += tl.dot(b_v, tl.trans(b_dh).to(b_v.dtype), allow_tf32=False)\n b_dv = tl.dot(b_k, b_dh, allow_tf32=False) * d_k[:, None] + tl.dot(b_s\n .to(b_q.dtype), b_do, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n b_ds = (b_ds * d_s).to(b_q.dtype)\n b_dq = b_dq * d_q[:, None] + tl.dot(b_ds, b_k, allow_tf32=False)\n b_dk = b_dk * d_k[:, None] + tl.trans(tl.dot(b_q, b_ds, allow_tf32=False))\n if HEAD_FIRST:\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/chunk.py" }, { "uuid": "4cb7f10c-e876-4404-a8ee-8dfb7a2f3050", "file_name": "sparse_copy.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_copy.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef copy_sparse_to_dense_grad_score_kernel(input_ptr, grad_output_ptr,\n grad_scores_ptr, sparse_rows_ptr, num_columns: tl.constexpr,\n num_experts_per_token: tl.constexpr, block_size: tl.constexpr):\n dense_row = tl.program_id(0)\n top_index = tl.program_id(1)\n sparse_row = tl.load(sparse_rows_ptr + dense_row *\n num_experts_per_token + top_index)\n grad_output_ptr += dense_row * num_columns\n input_ptr += sparse_row * num_columns\n offsets = tl.arange(0, block_size)\n if num_columns % block_size == 0:\n grad_scores = tl.load(input_ptr + offsets).to(tl.float32) * tl.load(\n grad_output_ptr + offsets).to(tl.float32)\n else:\n mask = offsets < num_columns\n grad_scores = tl.load(input_ptr + offsets, mask=mask).to(tl.float32\n ) * tl.load(grad_output_ptr + offsets, mask=mask).to(tl.float32)\n for i in range(1, tl.cdiv(num_columns, block_size)):\n offsets += block_size\n if num_columns % block_size == 0:\n grad_scores += tl.load(input_ptr + offsets).to(tl.float32\n ) * tl.load(grad_output_ptr + offsets).to(tl.float32)\n else:\n mask = offsets < num_columns\n grad_scores += tl.load(input_ptr + offsets, mask=mask).to(tl.\n float32) * tl.load(grad_output_ptr + offsets, mask=mask).to(tl\n .float32)\n tl.store(grad_scores_ptr + dense_row * num_experts_per_token +\n top_index, tl.sum(grad_scores))\n", "category": { "Functionality": [ "Elementwise Operations", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_copy.py" }, { "uuid": "0958dea2-dc46-4f8c-9895-f76364fbcc17", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'NV': lambda args: triton.cdiv(args['V'], args['BV']),\n 'OUTPUT_ATTENTIONS': lambda args: args['attn'] is not None})\n@triton.jit\ndef parallel_retention_fwd_kernel(q, k, v, o, attn, scale, B: tl.constexpr,\n H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT:\n tl.constexpr, BS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NV:\n tl.constexpr, OUTPUT_ATTENTIONS: tl.constexpr):\n i_kv, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_k, i_v = i_kv // NV, i_kv % NV\n i_h = i_bh % H\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n o_k = tl.arange(0, BS)\n d_h = tl.math.exp2((BS - o_k) * b_b)\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT, \n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k * BK, 0),\n (BK, BS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (0, i_v * BV),\n (BS, BV), (1, 0))\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(attn + (i_k * B * H + i_bh) * T * T, (T, T),\n (T, 1), (i_t * BT, 0), (BT, BS), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n for i in range(0, i_t * BT, BS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_s = tl.dot(b_q, b_k, allow_tf32=False) * d_h\n if i > 0:\n b_o = b_o * tl.math.exp2(b_b * BS)\n b_o += tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n p_k = tl.advance(p_k, (0, BS))\n p_v = tl.advance(p_v, (BS, 0))\n if OUTPUT_ATTENTIONS:\n tl.store(p_a, b_s.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n p_a = tl.advance(p_a, (0, BS))\n tl.debug_barrier()\n o_q = tl.arange(0, BT)\n d_q = tl.math.exp2(tl.arange(0, BT) * b_b)\n b_o *= d_q[:, None]\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k * BK, \n i_t * BT), (BK, BS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT, \n i_v * BV), (BS, BV), (1, 0))\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(attn + (i_k * B * H + i_bh) * T * T, (T, T),\n (T, 1), (i_t * BT, i_t * BT), (BT, BS), (1, 0))\n for _ in range(i_t * BT, (i_t + 1) * BT, BS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n m_s = o_q[:, None] >= o_k[None, :]\n d_s = tl.where(m_s, tl.math.exp2((o_q[:, None] - o_k[None, :]) *\n b_b), 0)\n b_s = tl.dot(b_q, b_k, allow_tf32=False) * d_s\n b_o += tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n if OUTPUT_ATTENTIONS:\n tl.store(p_a, b_s.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n p_a = tl.advance(p_a, (0, BS))\n p_k = tl.advance(p_k, (0, BS))\n p_v = tl.advance(p_v, (BS, 0))\n o_k += BS\n p_o = tl.make_block_ptr(o + (i_bh + B * H * i_k) * T * V, (T, V), (V, 1\n ), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/parallel.py" }, { "uuid": "509c75fc-fcc7-4a43-b0ef-aa00f4263dba", "file_name": "slstm_fw.py", "repo_name": "NX-AI/flashrnn", "file_path": "flashrnn/flashrnn/triton_fused/slstm_fw.py", "commit_hash": "3fca666a81c8740af4878d7bc5e2a51900e4fe14", "starcount": 0, "input": "@triton.autotune(configs, key=['siz_B', 'T', 'B', 'NH', 'DH'])\n@triton.jit\ndef _forward_sequence_kernel(states_initial, Wx, R, b, states_all,\n gates_all, T: tl.constexpr, NS: tl.constexpr, B: tl.constexpr, NH: tl.\n constexpr, DH: tl.constexpr, NGI: tl.constexpr, NGR: tl.constexpr,\n siz_B: tl.constexpr, OUTPUT_GATES: tl.constexpr, DTYPE: tl.constexpr=tl\n .float32):\n idx_b_NH, idx_b_B = tl.program_id(0), tl.program_id(1)\n str_matWx_NH = T * NGI * B * DH\n str_matWx_T = NGI * B * DH\n str_matStatesAll_NH = (T + 1) * NS * B * DH\n str_matStatesAll_T = NS * B * DH\n str_matGatesAll_NH = T * NGI * B * DH\n str_matGatesAll_T = NGI * B * DH\n matHtrans_initial_ptr = tl.make_block_ptr(base=states_initial + \n idx_b_NH * NS * B * DH + 0 * B * DH, shape=(B, DH), strides=(DH, 1),\n offsets=(idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n matHtrans = tl.load(matHtrans_initial_ptr).to(tl.float32)\n matCtrans_initial_ptr = tl.make_block_ptr(base=states_initial + \n idx_b_NH * NS * B * DH + 1 * B * DH, shape=(B, DH), strides=(DH, 1),\n offsets=(idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n matCtrans = tl.load(matCtrans_initial_ptr).to(tl.float32)\n matNtrans_initial_ptr = tl.make_block_ptr(base=states_initial + \n idx_b_NH * NS * B * DH + 2 * B * DH, shape=(B, DH), strides=(DH, 1),\n offsets=(idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n matNtrans = tl.load(matNtrans_initial_ptr).to(tl.float32)\n matMtrans_initial_ptr = tl.make_block_ptr(base=states_initial + \n idx_b_NH * NS * B * DH + 3 * B * DH, shape=(B, DH), strides=(DH, 1),\n offsets=(idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n matMtrans = tl.load(matMtrans_initial_ptr).to(tl.float32)\n matHtrans_initial_store_ptr = tl.make_block_ptr(base=states_all + \n idx_b_NH * str_matStatesAll_NH + 0 * str_matStatesAll_T + 0 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matHtrans_initial_store_ptr, matHtrans.to(DTYPE))\n matCtrans_initial_store_ptr = tl.make_block_ptr(base=states_all + \n idx_b_NH * str_matStatesAll_NH + 0 * str_matStatesAll_T + 1 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matCtrans_initial_store_ptr, matCtrans.to(DTYPE))\n matNtrans_initial_store_ptr = tl.make_block_ptr(base=states_all + \n idx_b_NH * str_matStatesAll_NH + 0 * str_matStatesAll_T + 2 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matNtrans_initial_store_ptr, matNtrans.to(DTYPE))\n matMtrans_initial_store_ptr = tl.make_block_ptr(base=states_all + \n idx_b_NH * str_matStatesAll_NH + 0 * str_matStatesAll_T + 3 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matMtrans_initial_store_ptr, matMtrans.to(DTYPE))\n matRtrans_i_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 0 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_i = tl.load(matRtrans_i_ptr)\n matRtrans_f_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 1 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_f = tl.load(matRtrans_f_ptr)\n matRtrans_z_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 2 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_z = tl.load(matRtrans_z_ptr)\n matRtrans_o_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 3 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_o = tl.load(matRtrans_o_ptr)\n vecB_i_ptr = b + idx_b_NH * NGI * DH + 0 * DH + tl.arange(0, DH)\n vecB_i = tl.load(vecB_i_ptr)\n vecB_f_ptr = b + idx_b_NH * NGI * DH + 1 * DH + tl.arange(0, DH)\n vecB_f = tl.load(vecB_f_ptr)\n vecB_z_ptr = b + idx_b_NH * NGI * DH + 2 * DH + tl.arange(0, DH)\n vecB_z = tl.load(vecB_z_ptr)\n vecB_o_ptr = b + idx_b_NH * NGI * DH + 3 * DH + tl.arange(0, DH)\n vecB_o = tl.load(vecB_o_ptr)\n for idx_t in range(T):\n matIxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 0 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matIxtrans = tl.load(matIxtrans_ptr)\n matFxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 1 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matFxtrans = tl.load(matFxtrans_ptr)\n matZxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 2 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matZxtrans = tl.load(matZxtrans_ptr)\n matOxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 3 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matOxtrans = tl.load(matOxtrans_ptr)\n matRhtrans_i = tl.dot(matHtrans.to(DTYPE), matRtrans_i)\n matRhtrans_f = tl.dot(matHtrans.to(DTYPE), matRtrans_f)\n matRhtrans_z = tl.dot(matHtrans.to(DTYPE), matRtrans_z)\n matRhtrans_o = tl.dot(matHtrans.to(DTYPE), matRtrans_o)\n matIbar = matIxtrans + matRhtrans_i + vecB_i[None, :]\n matFbar = matFxtrans + matRhtrans_f + vecB_f[None, :]\n matZbar = matZxtrans + matRhtrans_z + vecB_z[None, :]\n matObar = matOxtrans + matRhtrans_o + vecB_o[None, :]\n matLogFplusM = matMtrans + tl.log(tl.sigmoid(matFbar))\n matMtrans_next = tl.where(matNtrans == 0.0, matIbar, tl.maximum(\n matIbar, matLogFplusM))\n matI = tl.exp(matIbar - matMtrans_next)\n matF = tl.exp(matLogFplusM - matMtrans_next)\n matZ = triton_tanh(matZbar)\n matO = tl.sigmoid(matObar)\n matCtrans_next = matF * matCtrans + matI * matZ\n matNtrans_next = tl.maximum(matF * matNtrans + matI, 1.0)\n matHtrans_next = matO * (matCtrans_next / matNtrans_next)\n matHtrans_next_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 0 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matHtrans_next_ptr, matHtrans_next.to(DTYPE))\n matCtrans_next_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 1 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matCtrans_next_ptr, matCtrans_next.to(DTYPE))\n matNtrans_next_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 2 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matNtrans_next_ptr, matNtrans_next.to(DTYPE))\n matMtrans_next_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 3 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matMtrans_next_ptr, matMtrans_next.to(DTYPE))\n if OUTPUT_GATES:\n matGatesItrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 0 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesItrans_ptr, matIbar.to(DTYPE))\n matGatesFtrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 1 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesFtrans_ptr, matFbar.to(DTYPE))\n matGatesZtrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 2 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesZtrans_ptr, matZ.to(DTYPE))\n matGatesOtrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 3 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesOtrans_ptr, matO.to(DTYPE))\n matCtrans = matCtrans_next\n matHtrans = matHtrans_next\n matNtrans = matNtrans_next\n matMtrans = matMtrans_next\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT", "BSD" ], "github_url": "https://github.com/NX-AI/flashrnn/blob/3fca666a81c8740af4878d7bc5e2a51900e4fe14/flashrnn/flashrnn/triton_fused/slstm_fw.py" }, { "uuid": "8404cde9-7803-4d09-a284-c110eb62f90a", "file_name": "mlp.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/mlp.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_mlp_activation_forward_kernel(input_ptr, output_ptr, gated: tl.\n constexpr, activation_type: tl.constexpr, n_cols: tl.constexpr,\n block_size: tl.constexpr):\n row_idx = tl.program_id(0).to(tl.int64)\n columns = tl.program_id(1) * block_size + tl.arange(0, block_size)\n output_offsets = n_cols * row_idx + columns\n input_offsets = 2 * n_cols * row_idx + columns if gated else output_offsets\n input_ptr = input_ptr + input_offsets\n mask = columns < n_cols\n input_ = tl.load(input_ptr, mask=mask).to(tl.float32)\n if activation_type == _TritonActivationType.gelu.value:\n tanh_input = 0.79788456 * input_ * (1 + 0.044715 * input_ * input_)\n tanh = 1 - 2 / (1 + tl.exp(2 * tanh_input))\n out = input_ * 0.5 * (1.0 + tanh)\n elif activation_type == _TritonActivationType.silu.value:\n out = input_ / (1 + tl.exp(-input_))\n elif activation_type == _TritonActivationType.relu.value:\n out = tl.where(input_ > 0, input_, 0)\n elif activation_type == _TritonActivationType.squared_relu:\n relu_out = tl.where(input_ > 0, input_, 0)\n out = relu_out * relu_out\n else:\n raise NotImplementedError()\n if gated:\n other = tl.load(input_ptr + n_cols, mask=mask)\n out = out * other\n tl.store(output_ptr + output_offsets, out, mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/mlp.py" }, { "uuid": "83293d43-8c29-4602-b2d3-8e55f706ba6a", "file_name": "normalization.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/kernels/normalization.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef _rms_norm_fwd(X, Y, W, Rstd, N, eps, BLOCK_M: tl.constexpr, BLOCK_N: tl\n .constexpr):\n row_offset = tl.program_id(0) * BLOCK_M\n row_index = row_offset + tl.arange(0, BLOCK_M)[:, None]\n col_index = tl.arange(0, BLOCK_N)[None, :]\n col_mask = col_index < N\n x = tl.load(X + N * row_index + col_index, col_mask, other=0.0)\n w = tl.load(W + col_index, col_mask, eviction_policy='evict_last',\n other=0.0)\n xx = x * x\n xx = tl.broadcast_to(xx, [BLOCK_M, BLOCK_N])\n mean = tl.sum(xx, axis=1)[:, None] / N\n rstd = tl.rsqrt(mean + eps)\n y = x * rstd * w\n tl.store(Rstd + row_index, rstd)\n tl.store(Y + N * row_index + col_index, y, col_mask)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/kernels/normalization.py" }, { "uuid": "87e4c097-d2ca-4b41-ab22-ac0e29843a3c", "file_name": "RzLinearForward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearForward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_forward_kernel_notune(a_ptr, b_ptr, c_ptr, init_factor, M, N,\n K, H, stride_am, stride_ak, stride_cm, stride_cn, allow_tf32: tl.\n constexpr, R7: int, R6: int, R5: int, R4: int, R3: int, R2: int, R1:\n int, R0: int, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_forward_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=c_ptr,\n init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=stride_am,\n stride_ak=stride_ak, stride_cm=stride_cm, stride_cn=stride_cn,\n allow_tf32=allow_tf32, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1\n =R1, R0=R0, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=BLOCK_SIZE_N,\n BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearForward.py" }, { "uuid": "7971a4d5-d72d-49a0-8810-4b44d3e7eab4", "file_name": "real_rnn_tie_input_gate.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef fwd_sequential_scan(v, f1, hidden, B, L, C, BLOCK_M: tl.constexpr):\n offset_b = tl.program_id(0)\n if offset_b >= B:\n return\n offset_n = tl.program_id(1)\n ptr = tl.arange(0, BLOCK_M) + offset_b * L * C + offset_n * BLOCK_M\n h1 = tl.zeros([BLOCK_M], dtype=tl.float32)\n for _ in range(L):\n x0 = tl.load(v + ptr).to(tl.float32)\n decay1 = tl.load(f1 + ptr).to(tl.float32)\n h1 = (h1 - x0) * decay1 + x0\n tl.store(hidden + ptr, h1.to(hidden.dtype.element_ty))\n ptr += C\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py" }, { "uuid": "88e83a8a-262f-4bec-a1fa-c5f9b43f17d6", "file_name": "relu.py", "repo_name": "daemyung/practice-triton", "file_path": "relu.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@staticmethod\n@triton.jit\ndef forward(output_ptr, input_ptr, size, block_size: tl.constexpr):\n pid = tl.program_id(0)\n offset = pid * block_size\n input_block_ptr = tl.make_block_ptr(input_ptr, shape=(size,), strides=(\n 1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n output_block_ptr = tl.make_block_ptr(output_ptr, shape=(size,), strides\n =(1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n input = tl.load(input_block_ptr, boundary_check=(0,))\n condition = input >= 0\n output = tl.where(condition, input, 0)\n tl.store(output_block_ptr, output, boundary_check=(0,))\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/relu.py" }, { "uuid": "88873c2a-b635-4908-bbff-feff8674e931", "file_name": "rotary_embedding.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/rotary_embedding.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _rotary_embedding_kernel(q_rot_ptr, k_rot_ptr, q_ptr, k_ptr, cos_ptr,\n sin_ptr, seq_len, batch_size, num_heads, num_kv, hidden_size, q_strides,\n q_strideb, q_strideh, q_strided, k_strides, k_strideb, k_stridekv,\n k_strided, seq_offset, BLOCK_SIZE_SEQ: tl.constexpr, BLOCK_SIZE_BH: tl.\n constexpr, BLOCK_SIZE_D: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_bh_blocks = tl.cdiv(batch_size * num_heads, BLOCK_SIZE_BH)\n num_d_blocks = tl.cdiv(hidden_size // 2, BLOCK_SIZE_D)\n bh_id = pid % num_bh_blocks\n d_id = pid // num_bh_blocks % num_d_blocks\n seq_block_id = pid // num_bh_blocks // num_d_blocks\n seq_offs = seq_offset + seq_block_id * BLOCK_SIZE_SEQ + tl.arange(0,\n BLOCK_SIZE_SEQ)\n bh_offs = bh_id * BLOCK_SIZE_BH + tl.arange(0, BLOCK_SIZE_BH)\n q_common_offs = seq_offs[:, None, None] * q_strides + bh_offs[None, :, None\n ] * q_strideh\n k_common_offs = seq_offs[:, None, None] * k_strides + bh_offs[None, :, None\n ] // (num_heads // num_kv) * k_stridekv\n q_base_offs, qo_base_offs = (q_ptr + q_common_offs, q_rot_ptr +\n q_common_offs)\n k_base_offs, ko_base_offs = (k_ptr + k_common_offs, k_rot_ptr +\n k_common_offs)\n c_base_offs = cos_ptr + seq_offs[:, None] * hidden_size\n s_base_offs = sin_ptr + seq_offs[:, None] * hidden_size\n hidden_block_range = tl.arange(0, BLOCK_SIZE_D)\n hidden_offs_l = d_id * BLOCK_SIZE_D + hidden_block_range\n hidden_offs_r = hidden_size // 2 + hidden_offs_l\n mask_l, mask_r = (hidden_offs_l < hidden_size // 2, hidden_offs_r <\n hidden_size)\n mask_bh = bh_offs < batch_size * num_heads\n mask_seq = seq_offs < seq_len\n mask_bh_seq = mask_bh[None, :, None] & mask_seq[:, None, None]\n q_l, k_l = tl.load(q_base_offs + hidden_offs_l[None, None, :] *\n q_strided, mask=mask_l[None, None, :] & mask_bh_seq, other=0), tl.load(\n k_base_offs + hidden_offs_l[None, None, :] * k_strided, mask=mask_l\n [None, None, :] & mask_bh_seq, other=0)\n q_r, k_r = tl.load(q_base_offs + hidden_offs_r[None, None, :] *\n q_strided, mask=mask_r[None, None, :] & mask_bh_seq, other=0), tl.load(\n k_base_offs + hidden_offs_r[None, None, :] * k_strided, mask=mask_r\n [None, None, :] & mask_bh_seq, other=0)\n cos_l, cos_r = tl.load(c_base_offs + hidden_offs_l[None, :], mask=\n mask_l[None, :], other=0)[:, None, :], tl.load(c_base_offs +\n hidden_offs_r[None, :], mask=mask_r[None, :], other=0)[:, None, :]\n sin_l, sin_r = tl.load(s_base_offs + hidden_offs_l[None, :], mask=\n mask_l[None, :], other=0)[:, None, :], tl.load(s_base_offs +\n hidden_offs_r[None, :], mask=mask_r[None, :], other=0)[:, None, :]\n qo_l = q_l * cos_l - q_r * sin_l\n tl.store(qo_base_offs + hidden_offs_l, qo_l, mask=mask_l[None, None, :] &\n mask_bh_seq)\n qo_r = q_r * cos_r + q_l * sin_r\n tl.store(qo_base_offs + hidden_offs_r, qo_r, mask=mask_r[None, None, :] &\n mask_bh_seq)\n ko_l = k_l * cos_l - k_r * sin_l\n tl.store(ko_base_offs + hidden_offs_l, ko_l, mask=mask_l[None, None, :] &\n mask_bh_seq)\n ko_r = k_r * cos_r + k_l * sin_r\n tl.store(ko_base_offs + hidden_offs_r, ko_r, mask=mask_r[None, None, :] &\n mask_bh_seq)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/rotary_embedding.py" }, { "uuid": "1629adb1-4300-4648-8f28-5969b18864d5", "file_name": "block_ptr.py", "repo_name": "daemyung/practice-triton", "file_path": "block_ptr.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@triton.jit\ndef add_kernel(x_ptr, y_ptr, z_ptr, size, block_size: tl.constexpr):\n offset = tl.program_id(0) * block_size\n x_block_ptr = tl.make_block_ptr(x_ptr, shape=(size,), strides=(1,),\n offsets=(offset,), block_shape=(block_size,), order=(0,))\n y_block_ptr = tl.make_block_ptr(y_ptr, shape=(size,), strides=(1,),\n offsets=(offset,), block_shape=(block_size,), order=(0,))\n x = tl.load(x_block_ptr, boundary_check=(0,))\n y = tl.load(y_block_ptr, boundary_check=(0,))\n z = x + y\n z_block_ptr = tl.make_block_ptr(z_ptr, shape=(size,), strides=(1,),\n offsets=(offset,), block_shape=(block_size,), order=(0,))\n tl.store(z_block_ptr, z, boundary_check=(0,))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/block_ptr.py" }, { "uuid": "df24c070-c472-4437-97d2-8959ecc59778", "file_name": "cross_entropy.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/cross_entropy.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef cross_entropy_fwd_bwd_kernel(output_loss_ptr, output_logit_grad_ptr,\n input_logit_ptr, input_targ_ptr, input_divisor_ptr, output_loss_stride,\n output_logit_grad_stride, input_logit_stride, input_targ_stride, n_cols,\n ignore_index, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n logit_grad_row_start_ptr = (output_logit_grad_ptr + row_idx *\n output_logit_grad_stride)\n logit_row_start_ptr = input_logit_ptr + row_idx * input_logit_stride\n targ_ptr = input_targ_ptr + row_idx * input_targ_stride\n loss_ptr = output_loss_ptr + row_idx * output_loss_stride\n col_offsets = tl.arange(0, BLOCK_SIZE)\n logit_row_ptrs = logit_row_start_ptr + col_offsets\n logit_grad_row_ptrs = logit_grad_row_start_ptr + col_offsets\n logit_row = tl.load(logit_row_ptrs, mask=col_offsets < n_cols, other=\n float('-Inf'))\n targ = tl.load(targ_ptr)\n divisor = tl.load(input_divisor_ptr)\n logit_row = logit_row - tl.max(logit_row, axis=0)\n exp_logit_row = tl.exp(logit_row)\n sum_exp_logit_row = tl.sum(exp_logit_row, axis=0)\n log_sum_exp_logit_row = tl.log(sum_exp_logit_row)\n logit_gt_logit = tl.sum(tl.where(targ == col_offsets, logit_row, 0.0))\n loss = log_sum_exp_logit_row - logit_gt_logit\n loss = loss / divisor\n loss = tl.where(targ == ignore_index, 0.0, loss)\n tl.store(loss_ptr, loss)\n targ_one_hot = tl.where(targ == col_offsets, 1.0, 0.0)\n grad = exp_logit_row / sum_exp_logit_row - targ_one_hot\n grad = grad / divisor\n grad = tl.where(targ == ignore_index, 0.0, grad)\n tl.store(logit_grad_row_ptrs, grad, mask=col_offsets < n_cols)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/cross_entropy.py" }, { "uuid": "d1bbad34-33d0-441b-b7e1-fbac372c752f", "file_name": "chunk_h_split.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_split.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'\n ] is not None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=['BT', 'USE_G',\n 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_bwd_kernel_dh_reduction(g, gk, gv, dhs, dhr, dh0, offsets,\n split_offsets, T: tl.constexpr, S: tl.constexpr, H: tl.constexpr, HQ:\n tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr, BV: tl.constexpr, NG: tl.constexpr, USE_G: tl.constexpr,\n USE_GK: tl.constexpr, USE_GV: tl.constexpr,\n STORE_INITIAL_STATE_GRADIENT: tl.constexpr, USE_OFFSETS: tl.constexpr,\n HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_hq = i_nh // HQ, i_nh % HQ\n i_ng, i_h = i_nh // NG, i_hq // NG\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NS = tl.cdiv(T, S)\n boh = tl.load(split_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NS = tl.cdiv(T, S)\n boh = i_n * NS\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n for i_s in range(NS - 2, -1, -1):\n p_dhs = tl.make_block_ptr(dhs + ((boh + i_s + 1) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dhr = tl.make_block_ptr(dhr + ((boh + i_s) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dhs, boundary_check=(0, 1)).to(tl.float32)\n tl.store(p_dhr, b_dh.to(p_dhr.dtype.element_ty), boundary_check=(0, 1))\n for i_t in range(tl.cdiv(min(i_s * S + S, T), BT) - 1, tl.cdiv(i_s *\n S, BT) - 1, -1):\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_ng * T + last_idx)\n else:\n b_g_last = tl.load(g + (bos + last_idx) * H + i_h)\n b_dh *= tl.exp(b_g_last)\n if USE_GK:\n if HEAD_FIRST:\n p_gk_last = gk + (i_ng * T + last_idx\n ) * K + i_k * BK + tl.arange(0, BK)\n else:\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK\n )\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0,\n BK) < K, other=0.0)\n b_dh *= tl.exp(b_gk_last)[:, None]\n if USE_GV:\n if HEAD_FIRST:\n p_gv_last = gv + (i_ng * T + last_idx\n ) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV\n )\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0,\n BV) < V, other=0.0)\n b_dh *= tl.exp(b_gv_last)[None, :]\n if NS > 1:\n if STORE_INITIAL_STATE_GRADIENT:\n p_dhs = tl.make_block_ptr(dhs + (boh * H + i_h) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dhs, boundary_check=(0, 1)).to(tl.float32)\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check\n =(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_split.py" }, { "uuid": "12456573-9f7c-4e65-b821-93e96495dd34", "file_name": "quant_triton.py", "repo_name": "CompendiumLabs/ziggy", "file_path": "ziggy/backends/quant_triton.py", "commit_hash": "bd12fe50ca3475743f62ae26d4c184108e441e03", "starcount": 0, "input": "@triton.jit\ndef clamp(x, a, b):\n return tl.maximum(a, tl.minimum(b, x))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/CompendiumLabs/ziggy/blob/bd12fe50ca3475743f62ae26d4c184108e441e03/ziggy/backends/quant_triton.py" }, { "uuid": "434a7a78-d4a9-4a24-a028-0bbe017c400b", "file_name": "masks.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/flash/masks.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef score_modification(score, offs_m, start_n, offs_n, off_hz, num_heads, q,\n k, mask_block_ptr, BIAS_CHOICE: tl.constexpr, DEBUG_MASK: tl.constexpr,\n IS_CAUSAL: tl.constexpr, MATMUL_PRECISION: tl.constexpr=tl.float16):\n batch = off_hz // num_heads\n head = off_hz % num_heads\n seq_len_q = offs_m[:, None]\n seq_len_kv = start_n + offs_n[None, :]\n if BIAS_CHOICE == BiasMode.rel_pos.value:\n score = rel_attention_triton(score, batch, head, seq_len_q, seq_len_kv)\n elif BIAS_CHOICE == BiasMode.alibi.value:\n score = alibi_attention_triton(score, batch, head, seq_len_q,\n seq_len_kv, num_heads)\n elif BIAS_CHOICE == BiasMode.inverse_causal.value:\n score = inverse_causal_mask_triton(score, batch, head, seq_len_q,\n seq_len_kv)\n elif BIAS_CHOICE == BiasMode.causal.value:\n score = causal_mask_triton(score, batch, head, seq_len_q, seq_len_kv)\n if DEBUG_MASK and BIAS_CHOICE != BiasMode.none:\n mask = score - tl.dot(q.to(MATMUL_PRECISION), k.to(MATMUL_PRECISION))\n tl.store(mask_block_ptr, mask)\n return score\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/flash/masks.py" }, { "uuid": "049b3fe1-f26d-423e-844f-bef45e5755b6", "file_name": "masks.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/flash/masks.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef rel_attention_triton(score, batch, head, seq_len_q, seq_len_kv):\n bias = seq_len_kv - seq_len_q\n score = score + bias\n return score\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/flash/masks.py" }, { "uuid": "5ff91ea0-293b-4837-826f-44c0fe4e319c", "file_name": "triton_kernels.py", "repo_name": "vkuzo/pytorch_scripts", "file_path": "reduction_hack/triton_kernels.py", "commit_hash": "15322fe2a72fbebe1b9d9e38978cb6476da3bf70", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE': 512}), triton.Config\n ({'BLOCK_SIZE': 1024}), triton.Config({'BLOCK_SIZE': 2048}), triton.\n Config({'BLOCK_SIZE': 8192}), triton.Config({'BLOCK_SIZE': 16384})],\n key=['n_elements'])\n@triton.jit\ndef max_with_atomics_kernel(in_ptr0, out_ptr, n_elements, BLOCK_SIZE:\n 'tl.constexpr'):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n x = tl.load(in_ptr0 + offsets, mask=mask)\n x_max = tl.max(x)\n tl.atomic_max(out_ptr, x_max)\n", "category": { "Functionality": [ "Top-K Selection" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/vkuzo/pytorch_scripts/blob/15322fe2a72fbebe1b9d9e38978cb6476da3bf70/reduction_hack/triton_kernels.py" }, { "uuid": "c2fc4d8e-023b-46eb-8021-911d529c03b8", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef fused_recurrent_delta_rule_fwd_kernel(q, k, v, u, beta, o, h0, ht,\n offsets, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.constexpr,\n IS_BETA_HEADWISE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n p_u = u + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n if IS_BETA_HEADWISE:\n p_beta = beta + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_beta = beta + i_nh * T\n p_o = o + (i_k * B * H + i_nh) * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n p_u = u + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n if IS_BETA_HEADWISE:\n p_beta = beta + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_beta = beta + bos * H + i_h\n p_o = o + ((i_k * all + bos) * H + i_h) * V + i_v * BV + tl.arange(\n 0, BV)\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n mask_h = mask_k[None, :] & mask_v[:, None]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_v_minus = tl.sum(b_h * b_k[None, :], axis=1)\n b_v -= b_v_minus\n if IS_BETA_HEADWISE:\n b_beta = tl.load(p_beta, mask=mask_v, other=0).to(tl.float32)\n else:\n b_beta = tl.load(p_beta).to(tl.float32)\n tl.store(p_u, b_v.to(p_v.dtype.element_ty), mask=mask_v)\n b_v *= b_beta\n b_h += b_k[None, :] * b_v[:, None]\n b_o = b_h * b_q[None, :]\n b_o = tl.sum(b_o, axis=1)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), mask=mask_v)\n p_q += K if HEAD_FIRST else H * K\n p_k += K if HEAD_FIRST else H * K\n p_o += V if HEAD_FIRST else H * V\n p_v += V if HEAD_FIRST else H * V\n p_u += V if HEAD_FIRST else H * V\n p_beta += (1 if HEAD_FIRST else H) * (V if IS_BETA_HEADWISE else 1)\n if STORE_FINAL_STATE:\n p_ht = ht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Latency Sensitive" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/fused_recurrent.py" }, { "uuid": "6222b5ee-b5c3-4653-81db-38b9198dc016", "file_name": "rms_norm_dquant.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/rms_norm_dquant.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _rms_norm_dquant_kernel(X, Y, W, scale, stride, N, eps, BLOCK_SIZE: tl.\n constexpr):\n row = tl.program_id(0)\n Y += row * stride\n X += row * stride\n _var = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n _var += x * x\n var = tl.sum(_var, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n _max_x = 0.0\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n x = tl.load(X + cols, mask=mask, other=0.0).to(tl.float32)\n w = tl.load(W + cols, mask=mask)\n norm = x * rstd * w\n _max_x = tl.maximum(_max_x, tl.max(tl.abs(norm), axis=0))\n scale_x = _max_x / 127.0\n tl.store(scale + row, scale_x)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n x = tl.load(X + cols, mask=mask, other=0.0).to(tl.float32)\n w = tl.load(W + cols, mask=mask)\n norm = x * rstd * w\n norm = norm / scale_x\n norm = tl.where(norm > 0, norm + 0.5, norm - 0.5)\n tl.store(Y + cols, norm.to(tl.int8), mask=mask)\n", "category": { "Functionality": [ "Normalization", "Quantization" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/rms_norm_dquant.py" }, { "uuid": "cfcb2dbd-a045-4be5-8067-8ff20faf4034", "file_name": "seqlen_utils.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/seqlen_utils.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef seqlen_to_batch_index_kernel(seqlen_ptr, idx_ptr, BLK: tl.constexpr):\n pid = tl.program_id(0)\n i = tl.load(seqlen_ptr + pid)\n j = tl.load(seqlen_ptr + pid + 1)\n idx = tl.arange(0, BLK)\n tl.store(idx_ptr + i + idx, pid, mask=idx < j - i)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/seqlen_utils.py" }, { "uuid": "272fdc2b-cbf6-4942-9981-90ca27a426e6", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef fused_recurrent_delta_rule_bwd_kernel(q, k, v, beta, h0, dh0, dht, do,\n dq, dk, dv, db, offsets, scale, B: tl.constexpr, T: tl.constexpr, H: tl\n .constexpr, K: tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr, NK: tl.constexpr, IS_BETA_HEADWISE: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, USE_FINAL_STATE_GRADIENT: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_k = k + i_nh * T * K + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_v = v + i_nh * T * V + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_do = do + i_nh * T * V + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_dk = dk + (i_v * B * H + i_nh) * T * K + i_k * BK + tl.arange(0, BK\n ) + (T - 1) * K\n p_dv = dv + (i_k * B * H + i_nh) * T * V + i_v * BV + tl.arange(0, BV\n ) + (T - 1) * V\n if IS_BETA_HEADWISE:\n p_beta = beta + i_nh * T * V + i_v * BV + tl.arange(0, BV) + (T - 1\n ) * V\n p_dbeta = db + (i_v * NK * B * H + i_k * B * H + i_nh\n ) * T * V + tl.arange(0, BV) + (T - 1) * V\n else:\n p_beta = beta + i_nh * T + T - 1\n p_dbeta = db + (i_v * B * H + i_nh) * T + T - 1\n else:\n p_q = q + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK) + (T - 1\n ) * H * K\n p_k = k + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK) + (T - 1\n ) * H * K\n p_v = v + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV) + (T - 1\n ) * H * V\n p_do = do + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV) + (T - 1\n ) * H * V\n p_dk = dk + ((i_v * all + bos) * H + i_h) * K + i_k * BK + tl.arange(\n 0, BK) + (T - 1) * H * K\n p_dv = dv + ((i_k * all + bos) * H + i_h) * V + i_v * BV + tl.arange(\n 0, BV) + (T - 1) * H * V\n if IS_BETA_HEADWISE:\n p_beta = beta + (bos + T - 1\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_dbeta = db + ((i_v * NK + i_k) * all + bos + T - 1\n ) * H * V + i_h * V + tl.arange(0, BV)\n else:\n p_beta = beta + (bos + T - 1) * H + i_h\n p_dbeta = db + (i_v * all + bos + T - 1) * H + i_h\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_ht = dht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_dh += tl.load(p_ht, mask=mask_k[:, None] & mask_v[None, :], other=0\n ).to(tl.float32)\n for _ in range(T):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n if IS_BETA_HEADWISE:\n b_beta = tl.load(p_beta, mask=mask_v, other=0).to(tl.float32)\n else:\n b_beta = tl.load(p_beta).to(tl.float32)\n b_dh += b_q[:, None] * b_do[None, :]\n b_dk = tl.sum(b_dh * (b_v * b_beta)[None, :], axis=1)\n b_dv = tl.sum(b_dh * b_k[:, None], axis=0)\n b_db = b_dv * b_v if IS_BETA_HEADWISE else tl.sum(b_dv * b_v)\n b_dv = b_dv * b_beta\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), mask=mask_k)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), mask=mask_v)\n if IS_BETA_HEADWISE:\n tl.store(p_dbeta, b_db.to(p_dbeta.dtype.element_ty), mask=mask_v)\n else:\n tl.store(p_dbeta, b_db.to(p_dbeta.dtype.element_ty))\n b_dh -= b_k[:, None] * b_dv[None, :]\n p_q -= K if HEAD_FIRST else H * K\n p_k -= K if HEAD_FIRST else H * K\n p_v -= V if HEAD_FIRST else H * V\n p_do -= V if HEAD_FIRST else H * V\n p_dk -= K if HEAD_FIRST else H * K\n p_dv -= V if HEAD_FIRST else H * V\n p_dbeta -= (1 if HEAD_FIRST else H) * (V if IS_BETA_HEADWISE else 1)\n p_beta -= (1 if HEAD_FIRST else H) * (V if IS_BETA_HEADWISE else 1)\n if USE_INITIAL_STATE:\n p_dh0 = dh0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), mask=mask_k[:,\n None] & mask_v[None, :])\n tl.debug_barrier()\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n if IS_BETA_HEADWISE:\n p_beta = beta + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_beta = beta + i_nh * T\n p_do = do + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_v * B * H + i_nh) * T * K + i_k * BK + tl.arange(0, BK)\n p_dk = dk + (i_v * B * H + i_nh) * T * K + i_k * BK + tl.arange(0, BK)\n p_dv = dv + (i_k * B * H + i_nh) * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n if IS_BETA_HEADWISE:\n p_beta = beta + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_beta = beta + bos * H + i_h\n p_do = do + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n p_dq = dq + ((i_v * all + bos) * H + i_h) * K + i_k * BK + tl.arange(\n 0, BK)\n p_dk = dk + ((i_v * all + bos) * H + i_h) * K + i_k * BK + tl.arange(\n 0, BK)\n p_dv = dv + ((i_k * all + bos) * H + i_h) * V + i_v * BV + tl.arange(\n 0, BV)\n if USE_INITIAL_STATE:\n mask_h = mask_k[:, None] & mask_v[None, :]\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_dk = tl.load(p_dk, mask=mask_k, other=0).to(tl.float32)\n b_dv = tl.load(p_dv, mask=mask_v, other=0).to(tl.float32)\n b_dk -= tl.sum(b_dv[None, :] * b_h, axis=1)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), mask=mask_k)\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n if IS_BETA_HEADWISE:\n b_beta = tl.load(p_beta, mask=mask_v, other=0).to(tl.float32)\n else:\n b_beta = tl.load(p_beta).to(tl.float32)\n b_v *= b_beta\n b_h += b_k[:, None] * b_v[None, :]\n b_dq = b_h * b_do[None, :]\n d_q = tl.sum(b_dq, axis=1) * scale\n tl.store(p_dq, d_q.to(p_dq.dtype.element_ty), mask=mask_k)\n p_k += K if HEAD_FIRST else H * K\n p_v += V if HEAD_FIRST else H * V\n p_do += V if HEAD_FIRST else H * V\n p_dq += K if HEAD_FIRST else H * K\n p_dk += K if HEAD_FIRST else H * K\n p_dv += V if HEAD_FIRST else H * V\n p_beta += (1 if HEAD_FIRST else H) * (V if IS_BETA_HEADWISE else 1)\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/fused_recurrent.py" }, { "uuid": "6737d4e9-b985-4927-a44a-82cdfbceeae6", "file_name": "fused_cross_entropy.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_cross_entropy.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'HAS_SMOOTHING': lambda args: args['label_smoothing'] >\n 0.0})\n@triton.jit\ndef cross_entropy_bwd_kernel(dlogits_ptr, dloss_ptr, logits_ptr, lse_ptr,\n labels_ptr, label_smoothing, logit_scale, lse_square_scale,\n ignore_index, total_classes, class_start_idx, n_cols, logits_row_stride,\n dlogits_row_stride, dloss_row_stride, BLOCK_SIZE: tl.constexpr,\n HAS_SMOOTHING: tl.constexpr):\n row_idx = tl.program_id(0)\n col_block_idx = tl.program_id(1)\n logits_ptr = logits_ptr + row_idx * logits_row_stride.to(tl.int64)\n dlogits_ptr = dlogits_ptr + row_idx * dlogits_row_stride.to(tl.int64)\n col_offsets = col_block_idx * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n label_idx = tl.load(labels_ptr + row_idx)\n if label_idx != ignore_index:\n dloss = tl.load(dloss_ptr + row_idx * dloss_row_stride)\n else:\n dloss = 0.0\n logits = tl.load(logits_ptr + col_offsets, mask=col_offsets < n_cols,\n other=-float('inf')).to(tl.float32) * logit_scale\n lse = tl.load(lse_ptr + row_idx)\n probs = tl.exp(logits - lse)\n probs += 2.0 * lse_square_scale * lse * probs\n label_idx -= class_start_idx\n if HAS_SMOOTHING:\n smooth_negative = label_smoothing / total_classes\n probs = tl.where(col_offsets == label_idx, probs - (1 -\n label_smoothing), probs) - smooth_negative\n else:\n probs = tl.where(col_offsets == label_idx, probs - 1.0, probs)\n tl.store(dlogits_ptr + col_offsets, dloss * logit_scale * probs, mask=\n col_offsets < n_cols)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_cross_entropy.py" }, { "uuid": "b912e62b-afb4-4422-890d-6fb1182bfd6e", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BT': BT}, num_warps=num_warps) for\n BT in [16, 32, 64] for num_warps in [2, 4, 8]], key=['S'])\n@triton.jit\ndef chunk_global_cumsum_vector_kernel(s, z, offsets, T: tl.constexpr, H: tl\n .constexpr, S: tl.constexpr, BT: tl.constexpr, BS: tl.constexpr,\n HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_s, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_b).to(tl.int32), tl.load(offsets +\n i_b + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n o_i = tl.arange(0, BT)\n m_s = tl.where(o_i[:, None] >= o_i[None, :], 1.0, 0.0)\n b_z = tl.zeros([BS], dtype=tl.float32)\n for i_t in range(tl.cdiv(T, BT)):\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T * S, (T, S), (S, 1), (i_t *\n BT, i_s * BS), (BT, BS), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * T * S, (T, S), (S, 1), (i_t *\n BT, i_s * BS), (BT, BS), (1, 0))\n else:\n p_s = tl.make_block_ptr(s + (bos * H + i_h) * S, (T, S), (H * S,\n 1), (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n p_z = tl.make_block_ptr(z + (bos * H + i_h) * S, (T, S), (H * S,\n 1), (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_c = b_z[None, :] + tl.dot(m_s, b_s, allow_tf32=False)\n tl.store(p_z, b_c.to(p_z.dtype.element_ty), boundary_check=(0, 1))\n if i_t >= 0:\n b_z += tl.sum(b_s, 0)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "6a835470-58ab-445d-b53c-4296e4297b79", "file_name": "triton_kernel.py", "repo_name": "yann-Choho/projet_PPML", "file_path": "notebooks/triton_kernel.py", "commit_hash": "9274e0561443b01f029ee6e0737f922f71d2da39", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['n_elements'])\n@triton.jit\ndef triple_mul_kernel(A_ptr, B_ptr, C_ptr, output_ptr, n_elements,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n A = tl.load(A_ptr + offsets, mask=mask)\n B = tl.load(B_ptr + offsets, mask=mask)\n C = tl.load(C_ptr + offsets, mask=mask)\n output = A * B * C\n tl.store(output_ptr + offsets, output, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/yann-Choho/projet_PPML/blob/9274e0561443b01f029ee6e0737f922f71d2da39/notebooks/triton_kernel.py" }, { "uuid": "1162e2ac-eec4-4b6a-ac17-f648e706e5b4", "file_name": "heuristics.py", "repo_name": "daemyung/practice-triton", "file_path": "heuristics.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@triton.heuristics({'boundary_check': lambda args: args['x_size'] % args[\n 'block_size']})\n@triton.jit\ndef add_kernel(x_ptr, y_ptr, z_ptr, size, block_size: tl.constexpr,\n boundary_check: tl.constexpr):\n offset = tl.program_id(0) * block_size\n x_block_ptr = tl.make_block_ptr(x_ptr, shape=(size,), strides=(1,),\n offsets=(offset,), block_shape=(block_size,), order=(0,))\n y_block_ptr = tl.make_block_ptr(y_ptr, shape=(size,), strides=(1,),\n offsets=(offset,), block_shape=(block_size,), order=(0,))\n if boundary_check:\n x = tl.load(x_block_ptr, boundary_check=(0,))\n y = tl.load(y_block_ptr, boundary_check=(0,))\n else:\n x = tl.load(x_block_ptr)\n y = tl.load(y_block_ptr)\n z = x + y\n z_block_ptr = tl.make_block_ptr(z_ptr, shape=(size,), strides=(1,),\n offsets=(offset,), block_shape=(block_size,), order=(0,))\n if boundary_check:\n tl.store(z_block_ptr, z, boundary_check=(0,))\n else:\n tl.store(z_block_ptr, z)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/heuristics.py" }, { "uuid": "79923ee4-c50b-4734-a499-56f92bffc35b", "file_name": "sized_tuned_bwd.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/sized_tuned_bwd.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=TRITON_CONFIG_LIST_BWD_SIZED, key=['BLOCK_DMODEL',\n 'max_seqlen_q', 'max_seqlen_k'])\n@triton.jit\ndef sized_tuned_bwd_kernel_dk_dv(Q, K, V, B, sm_scale, Out, DO, DK, DV, L,\n D, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dkz, stride_dkh, stride_dkn, stride_dkk,\n stride_dvz, stride_dvh, stride_dvk, stride_dvn, cu_seqlens_q,\n cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k, head_dim,\n dropout_p, philox_seed, philox_offset_base, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.\n constexpr):\n bare_bwd_kernel_dk_dv(Q, K, V, B, sm_scale, Out, DO, DK, DV, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dkz, stride_dkh, stride_dkn,\n stride_dkk, stride_dvz, stride_dvh, stride_dvk, stride_dvn,\n cu_seqlens_q, cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k,\n head_dim, dropout_p, philox_seed, philox_offset_base, BLOCK_M,\n BLOCK_DMODEL, BLOCK_N, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD=\n PADDED_HEAD, BIAS_TYPE=BIAS_TYPE)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/sized_tuned_bwd.py" }, { "uuid": "eef87b29-d8f2-420d-a9a1-7f119fb0bc3c", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef bwd_prepare_wy_repr_kernel(k, v, beta, g, Aw, Au, dw, du, dk, dv, dbeta,\n dg, offsets, indices, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr,\n V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n b_dbeta = tl.zeros([BT], dtype=tl.float32)\n b_dA = tl.zeros([BT, BT], dtype=tl.float32)\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_A = tl.make_block_ptr(Aw + i_bh * T * BT, (BT, T), (1, BT), (0, \n i_t * BT), (BT, BT), (0, 1))\n else:\n p_beta = tl.make_block_ptr(beta + (bos * H + i_h), (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_A = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (BT, T), (1, H *\n BT), (0, i_t * BT), (BT, BT), (0, 1))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_k_beta = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_dw = tl.load(p_dw, boundary_check=(0, 1))\n b_dA += tl.dot(b_dw, tl.trans(b_k_beta), allow_tf32=False)\n b_dk_beta = tl.dot(b_A, b_dw, allow_tf32=False)\n b_dk = b_dk_beta * b_beta[:, None]\n b_dbeta += tl.sum(b_dk_beta * b_k, 1)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n b_dA = tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :],\n b_dA, 0)\n b_dA = tl.dot(b_dA.to(b_A.dtype), b_A)\n b_dA = tl.dot(b_A, b_dA.to(b_A.dtype))\n b_dA = tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :], \n -b_dA, 0).to(k.dtype.element_ty)\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(Au + i_bh * T * BT, (BT, T), (1, BT), (0, \n i_t * BT), (BT, BT), (0, 1))\n else:\n p_A = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (BT, T), (1, H *\n BT), (0, i_t * BT), (BT, BT), (0, 1))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_dA2 = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_du = tl.make_block_ptr(du + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_du = tl.make_block_ptr(du + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_v_beta = (b_v * b_beta[:, None]).to(b_v.dtype)\n b_du = tl.load(p_du, boundary_check=(0, 1))\n b_dA2 += tl.dot(b_du, tl.trans(b_v_beta), allow_tf32=False)\n b_dv_beta = tl.dot(b_A, b_du, allow_tf32=False)\n b_dv = b_dv_beta * b_beta[:, None]\n b_dbeta += tl.sum(b_dv_beta * b_v, 1)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n b_dA2 = tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :],\n b_dA2, 0)\n b_dA2 = tl.dot(b_dA2.to(b_A.dtype), b_A)\n b_dA2 = tl.dot(b_A, b_dA2.to(b_A.dtype))\n b_dA2 = tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :],\n -b_dA2, 0).to(k.dtype.element_ty)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n else:\n p_g = tl.make_block_ptr(g + (bos * H + i_h), (T,), (H,), (i_t * BT,\n ), (BT,), (0,))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_dA += b_dA2 * tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[\n None, :], tl.exp(b_g[:, None] - b_g[None, :]), 0)\n b_dA = b_dA.to(k.dtype.element_ty)\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dk = tl.load(p_dk, boundary_check=(0, 1))\n b_k_beta = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_A += tl.dot(b_k_beta, tl.trans(b_k))\n b_dk_beta = tl.dot(b_dA, b_k, allow_tf32=False)\n b_dbeta += tl.sum(b_dk_beta * b_k, 1)\n b_dk += tl.dot(tl.trans(b_dA), b_k_beta, allow_tf32=False)\n b_dk += b_dk_beta * b_beta[:, None]\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n b_A = b_A * tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None,\n :], tl.exp(b_g[:, None] - b_g[None, :]), 0)\n b_A *= b_dA2\n b_dg = tl.sum(b_A, axis=1) - tl.sum(b_A, axis=0)\n if HEAD_FIRST:\n p_dg = tl.make_block_ptr(dg + i_bh * T, (T,), (1,), (i_t * BT,), (\n BT,), (0,))\n p_dbeta = tl.make_block_ptr(dbeta + i_bh * T, (T,), (1,), (i_t * BT\n ,), (BT,), (0,))\n else:\n p_dg = tl.make_block_ptr(dg + (bos * H + i_h), (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_dbeta = tl.make_block_ptr(dbeta + (bos * H + i_h), (T,), (H,), (\n i_t * BT,), (BT,), (0,))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0,))\n tl.store(p_dbeta, b_dbeta.to(p_dbeta.dtype.element_ty), boundary_check=(0,)\n )\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/wy_fast.py" }, { "uuid": "bf07f58b-4dc1-4f3e-8074-7f90a37688c0", "file_name": "naive_associative_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/naive_associative_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _naive_associative_rnn_scan_bwd_kernel():\n pass\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/naive_associative_rnn_scan.py" }, { "uuid": "6008f8eb-f05d-46b8-ba50-eaf48490ed4d", "file_name": "rand_init.py", "repo_name": "gmgu/study-triton", "file_path": "6_random/rand_init.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@triton.jit\ndef rand_init(out_ptr, n, seed, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n\n random = tl.rand(seed, offsets)\n tl.store(out_ptr + offsets, random, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/6_random/rand_init.py" }, { "uuid": "af1c833d-4eeb-4313-a034-3b8bf3198b9d", "file_name": "main_triton.py", "repo_name": "dwgan/GraphMST", "file_path": "main_triton.py", "commit_hash": "4d65ed0f108d339e3e4cfff25085a39adc6a48a2", "starcount": 0, "input": "@triton.jit\ndef union_kernel(parent, rank, u, v, BLOCK_SIZE: tl.constexpr):\n root_u = tl.zeros((BLOCK_SIZE,), dtype=tl.int32)\n root_v = tl.zeros((BLOCK_SIZE,), dtype=tl.int32)\n find_kernel(parent, u, root_u, BLOCK_SIZE=BLOCK_SIZE)\n find_kernel(parent, v, root_v, BLOCK_SIZE=BLOCK_SIZE)\n tl.syncwarp()\n root_u = root_u[0]\n root_v = root_v[0]\n if root_u != root_v:\n ru_rank = tl.load(rank + root_u)\n rv_rank = tl.load(rank + root_v)\n if ru_rank > rv_rank:\n tl.store(parent, root_v, root_u)\n elif ru_rank < rv_rank:\n tl.store(parent, root_u, root_v)\n else:\n tl.store(parent, root_v, root_u)\n tl.atomic_add(rank, root_u, 1)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Shared Memory Intensive" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dwgan/GraphMST/blob/4d65ed0f108d339e3e4cfff25085a39adc6a48a2/main_triton.py" }, { "uuid": "faf1b309-5072-4c15-ba21-d9fb5786455c", "file_name": "06-fused-attention.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _attn_bwd(Q, K, V, sm_scale, DO, DQ, DK, DV, M, D, stride_z, stride_h,\n stride_tok, stride_d, H, N_CTX, BLOCK_M1: tl.constexpr, BLOCK_N1: tl.\n constexpr, BLOCK_M2: tl.constexpr, BLOCK_N2: tl.constexpr,\n BLK_SLICE_FACTOR: tl.constexpr, HEAD_DIM: tl.constexpr):\n LN2: tl.constexpr = 0.6931471824645996\n bhid = tl.program_id(2)\n off_chz = (bhid * N_CTX).to(tl.int64)\n adj = (stride_h * (bhid % H) + stride_z * (bhid // H)).to(tl.int64)\n pid = tl.program_id(0)\n Q += adj\n K += adj\n V += adj\n DO += adj\n DQ += adj\n DK += adj\n DV += adj\n M += off_chz\n D += off_chz\n offs_k = tl.arange(0, HEAD_DIM)\n start_n = pid * BLOCK_N1\n start_m = start_n\n MASK_BLOCK_M1: tl.constexpr = BLOCK_M1 // BLK_SLICE_FACTOR\n offs_n = start_n + tl.arange(0, BLOCK_N1)\n dv = tl.zeros([BLOCK_N1, HEAD_DIM], dtype=tl.float32)\n dk = tl.zeros([BLOCK_N1, HEAD_DIM], dtype=tl.float32)\n k = tl.load(K + offs_n[:, None] * stride_tok + offs_k[None, :] * stride_d)\n v = tl.load(V + offs_n[:, None] * stride_tok + offs_k[None, :] * stride_d)\n num_steps = BLOCK_N1 // MASK_BLOCK_M1\n dk, dv = _attn_bwd_dkdv(dk, dv, Q, k, v, sm_scale, DO, M, D, stride_tok,\n stride_d, H, N_CTX, MASK_BLOCK_M1, BLOCK_N1, HEAD_DIM, start_n,\n start_m, num_steps, MASK=True)\n start_m += num_steps * MASK_BLOCK_M1\n num_steps = (N_CTX - start_m) // BLOCK_M1\n dk, dv = _attn_bwd_dkdv(dk, dv, Q, k, v, sm_scale, DO, M, D, stride_tok,\n stride_d, H, N_CTX, BLOCK_M1, BLOCK_N1, HEAD_DIM, start_n, start_m,\n num_steps, MASK=False)\n dv_ptrs = DV + offs_n[:, None] * stride_tok + offs_k[None, :] * stride_d\n tl.store(dv_ptrs, dv)\n dk *= sm_scale\n dk_ptrs = DK + offs_n[:, None] * stride_tok + offs_k[None, :] * stride_d\n tl.store(dk_ptrs, dk)\n start_m = pid * BLOCK_M2\n end_n = start_m + BLOCK_M2\n MASK_BLOCK_N2: tl.constexpr = BLOCK_N2 // BLK_SLICE_FACTOR\n offs_m = start_m + tl.arange(0, BLOCK_M2)\n q = tl.load(Q + offs_m[:, None] * stride_tok + offs_k[None, :] * stride_d)\n dq = tl.zeros([BLOCK_M2, HEAD_DIM], dtype=tl.float32)\n do = tl.load(DO + offs_m[:, None] * stride_tok + offs_k[None, :] * stride_d\n )\n m = tl.load(M + offs_m)\n m = m[:, None]\n num_steps = BLOCK_M2 // MASK_BLOCK_N2\n dq = _attn_bwd_dq(dq, q, K, V, do, m, D, stride_tok, stride_d, H, N_CTX,\n BLOCK_M2, MASK_BLOCK_N2, HEAD_DIM, start_m, end_n - num_steps *\n MASK_BLOCK_N2, num_steps, MASK=True)\n end_n -= num_steps * MASK_BLOCK_N2\n num_steps = end_n // BLOCK_N2\n dq = _attn_bwd_dq(dq, q, K, V, do, m, D, stride_tok, stride_d, H, N_CTX,\n BLOCK_M2, BLOCK_N2, HEAD_DIM, start_m, end_n - num_steps * BLOCK_N2,\n num_steps, MASK=False)\n dq_ptrs = DQ + offs_m[:, None] * stride_tok + offs_k[None, :] * stride_d\n dq *= LN2\n tl.store(dq_ptrs, dq)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/06-fused-attention.py" }, { "uuid": "21eb0b3f-9ba8-480f-bb96-a5685bc5fff5", "file_name": "snake.py", "repo_name": "falkaer/multi-scale-music", "file_path": "snake.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16)], reset_to_zero=['DYDA',\n 'DYDC'], key=['C'])\n@triton.jit\ndef _snake_bwd_triton(X, OUT, ALPHA, CR, GRAD, DYDX, DYDA, DYDC, X_stride1,\n X_stride2, X_stride3, OUT_stride1, OUT_stride2, OUT_stride3,\n GRAD_stride1, GRAD_stride2, GRAD_stride3, DYDX_stride1, DYDX_stride2,\n DYDX_stride3, DYDA_stride, DYDC_stride, ALPHA_stride, CR_stride, C, N,\n CORR: tl.constexpr, X_NEEDS_GRAD: tl.constexpr, ALPHA_NEEDS_GRAD: tl.\n constexpr, CR_NEEDS_GRAD: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(0)\n batch_idx = pid // C\n channel_idx = pid % C\n block_start = tl.program_id(1) * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n GRAD = GRAD + batch_idx * GRAD_stride1 + channel_idx * GRAD_stride2\n grad = tl.load(GRAD + offsets * GRAD_stride3, mask=offsets < N, other=0)\n if CORR:\n cr = tl.load(CR + channel_idx * CR_stride)\n if ALPHA_NEEDS_GRAD | CR_NEEDS_GRAD:\n OUT = OUT + batch_idx * OUT_stride1 + channel_idx * OUT_stride2\n out = tl.load(OUT + offsets * OUT_stride3, mask=offsets < N, other=0)\n outgrad = tl.sum(out * grad, axis=0)\n if X_NEEDS_GRAD | ALPHA_NEEDS_GRAD:\n X = X + batch_idx * X_stride1 + channel_idx * X_stride2\n x = tl.load(X + offsets * X_stride3, mask=offsets < N, other=0)\n alpha = tl.load(ALPHA + channel_idx * ALPHA_stride)\n sin2ax = tl.sin((2 * alpha * x).to(tl.float32)).to(x.type)\n dydx = (sin2ax + 1) * grad\n if CORR:\n dydx = dydx / cr\n if X_NEEDS_GRAD:\n DYDX = DYDX + batch_idx * DYDX_stride1 + channel_idx * DYDX_stride2\n tl.store(DYDX + offsets * DYDX_stride3, dydx, mask=offsets < N)\n if ALPHA_NEEDS_GRAD:\n dyda = (tl.sum(x * dydx, axis=0) - outgrad) / alpha\n tl.atomic_add(DYDA + channel_idx * DYDA_stride, dyda)\n if CR_NEEDS_GRAD:\n dydc = -outgrad / cr\n tl.atomic_add(DYDC + channel_idx * DYDC_stride, dydc)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Shared Memory Intensive" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/snake.py" }, { "uuid": "b98029f7-6d1d-4960-8e62-6b7ea5e45c0e", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_dh(q, z, do, dh, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t,\n s_v_d, s_h_h, s_h_t, s_h_d, scale, T: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NT:\n tl.constexpr, NORMK: tl.constexpr):\n i_k, i_v, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n b_zp = tl.full([BK if NORMK else BV], float('inf'), dtype=tl.float32)\n for i_t in range(NT - 1, -1, -1):\n i_p = tl.maximum(i_t * BT - 1, 0)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, s_h_d), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n if NORMK:\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (K, T), (s_k_d, s_k_t\n ), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_zc = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,),\n (i_p * K + i_k * BK,), (BK,), (0,))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_r, b_zp = tl.exp(b_zc - b_zp), b_zc\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_q = (b_q * tl.exp(b_zc[:, None] - b_z)).to(b_q.dtype)\n b_dh = b_dh * b_r[:, None]\n else:\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d\n ), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_zc = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,),\n (i_p * V + i_v * BV,), (BV,), (0,))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_r, b_zp = tl.exp(b_zc - b_zp), b_zc\n b_z = tl.load(p_z, boundary_check=(0,))\n b_do = (b_do * tl.exp(b_zc[None, :] - b_z)).to(b_do.dtype)\n b_dh = b_dh * b_r[None, :]\n b_dh += tl.dot(b_q, b_do, allow_tf32=False)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "4ff74bb4-943c-4c66-937e-646014c4ff27", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef softmax(input, log: tl.constexpr):\n \"\"\"\n Normalizes the input using softmax along the last dimension.\n\n Args:\n input: Input to normalize.\n The input must be of shape [BLOCK_SIZE1, BLOCK_SIZE2].\n log: Flag for indicating if the log of softmax should be taken.\n\n Returns:\n Input normalized by softmax.\n \"\"\"\n input = input.to(tl.float32)\n input = input - tl.max(input, axis=1)[:, None]\n numerator = tl.exp(input)\n denominator = tl.sum(numerator, axis=1)[:, None]\n if log:\n output = input - tl.log(denominator)\n else:\n output = numerator / denominator\n return output\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "7dd66f4e-95eb-48ec-8b08-1f9ced106147", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/based/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef _parallel_based_bwd_dq(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dq,\n s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, B, H, T, scale, BTL: tl.\n constexpr, BTS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, K: tl\n .constexpr, V: tl.constexpr):\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_c * BTL, i_v * BV), (BTL, BV), (1, 0))\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTL, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_q = (b_q * scale).to(b_q.dtype)\n b_dq = tl.zeros([BTL, BK], dtype=tl.float32)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (0, \n i_k * BK), (BTS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (i_v *\n BV, 0), (BV, BTS), (0, 1))\n p_dz = dz + i_bh * T + i_c * BTL + tl.arange(0, BTL)\n b_dz = tl.load(p_dz, mask=i_c * BTL + tl.arange(0, BTL) < T)\n for _ in range(0, i_c * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[:, None]\n else:\n b_ds = b_ds\n b_s = tl.dot(b_q, tl.trans(b_k), allow_tf32=False)\n b_dq += tl.dot((b_ds * (1 + b_s)).to(b_v.dtype), b_k, allow_tf32=False)\n p_k = tl.advance(p_k, (BTS, 0))\n p_v = tl.advance(p_v, (0, BTS))\n b_dq *= scale\n o_q = tl.arange(0, BTL)\n o_k = tl.arange(0, BTS)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (i_v *\n BV, i_c * BTL), (BV, BTS), (0, 1))\n for _ in range(i_c * BTL, (i_c + 1) * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n m_s = o_q[:, None] >= o_k[None, :]\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[:, None]\n else:\n b_ds = b_ds\n b_ds = tl.where(m_s, b_ds, 0) * scale\n b_s = tl.dot(b_q, tl.trans(b_k), allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n b_dq += tl.dot((b_ds + b_ds * b_s).to(b_k.dtype), b_k, allow_tf32=False\n )\n p_k = tl.advance(p_k, (BTS, 0))\n p_v = tl.advance(p_v, (0, BTS))\n o_k += BTS\n p_dq = tl.make_block_ptr(dq + (i_bh + B * H * i_v) * s_k_h, (T, K), (\n s_k_t, s_k_d), (i_c * BTL, i_k * BK), (BTL, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n return\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/based/parallel.py" }, { "uuid": "35bf1229-189c-4ad2-b417-b760322afbf3", "file_name": "positional_embedding.py", "repo_name": "sjjeong94/ai_compiler_study", "file_path": "aicom/positional_embedding.py", "commit_hash": "e87284aab74acab704e2d192190be446e328e1c6", "starcount": 0, "input": "@triton.jit\ndef rope_bw(dx_ptr, f_ptr, dt_ptr, dx_s_stride, f_s_stride, dt_s_stride, d,\n d2, BLOCK_SIZE: tl.constexpr):\n s_idx = tl.program_id(0)\n bh_idx = tl.program_id(1)\n dx_start_ptr = dx_ptr + s_idx * dx_s_stride\n f_start_ptr = f_ptr + s_idx * f_s_stride\n dt_start_ptr = dt_ptr + s_idx * dt_s_stride\n d2_half = d2 // 2\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < d2_half\n f0_ptrs = f_start_ptr + col_offsets\n f1_ptrs = f_start_ptr + col_offsets + d2_half\n f0 = tl.load(f0_ptrs, mask=mask, other=0.0)\n cos0 = tl.cos(f0)\n sin0 = tl.sin(f0)\n f1 = tl.load(f1_ptrs, mask=mask, other=0.0)\n cos1 = tl.cos(f1)\n sin1 = tl.sin(f1)\n dx0_ptrs = dx_start_ptr + bh_idx * d + col_offsets\n dx1_ptrs = dx_start_ptr + bh_idx * d + col_offsets + d2_half\n dx0 = tl.load(dx0_ptrs, mask=mask, other=0.0)\n dx1 = tl.load(dx1_ptrs, mask=mask, other=0.0)\n dt0 = dx0 * cos0 + dx1 * sin1\n dt1 = dx1 * cos1 - dx0 * sin0\n dt0_ptrs = dt_start_ptr + bh_idx * d + col_offsets\n dt1_ptrs = dt_start_ptr + bh_idx * d + col_offsets + d2_half\n tl.store(dt0_ptrs, dt0, mask=mask)\n tl.store(dt1_ptrs, dt1, mask=mask)\n if d2 < d:\n remainder = d - d2\n q, r = remainder // BLOCK_SIZE, remainder % BLOCK_SIZE\n for i in range(q):\n dx2_ptrs = (dx_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * i)\n dt2_ptrs = (dt_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * i)\n dx2 = tl.load(dx2_ptrs)\n tl.store(dt2_ptrs, dx2)\n if r > 0:\n dx2_ptrs = (dx_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * q)\n dt2_ptrs = (dt_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * q)\n mask = col_offsets < r\n dx2 = tl.load(dx2_ptrs, mask=mask, other=0.0)\n tl.store(dt2_ptrs, dx2, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sjjeong94/ai_compiler_study/blob/e87284aab74acab704e2d192190be446e328e1c6/aicom/positional_embedding.py" }, { "uuid": "f0a324aa-5bec-4ba9-8dee-d1c6f875aff3", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef triton_jagged_to_dense(jagged_value_ptr, jagged_offsets_ptr,\n jagged_value_row_stride, output_dense_ptr, dense_indices_ptr,\n dense_col_stride, dense_row_stride, dense_matrix_stride, JAGGED_DIM: tl\n .constexpr, thread_block_row_size: tl.constexpr, thread_block_col_size:\n tl.constexpr, operation_function: tl.constexpr, operation_dense) ->None:\n pid = tl.program_id(0)\n begin = tl.load(jagged_offsets_ptr + pid)\n end = tl.load(jagged_offsets_ptr + (pid + 1))\n jagged_value_ptr += begin * jagged_value_row_stride\n if JAGGED_DIM > 2:\n dense_indice = tl.load(dense_indices_ptr + pid)\n if dense_indice == -1:\n return\n output_dense_ptr += dense_indice\n if operation_function is not None:\n operation_dense += dense_indice\n else:\n output_dense_ptr += pid * dense_matrix_stride\n if operation_function is not None:\n operation_dense += pid * dense_matrix_stride\n offset_row = tl.arange(0, thread_block_row_size)\n N = tl.minimum(dense_row_stride, jagged_value_row_stride)\n M = tl.minimum(dense_matrix_stride // dense_row_stride, end - begin)\n for _i in range(begin, end, thread_block_row_size):\n offset_col = tl.arange(0, thread_block_col_size)\n block_offset = offset_row[:, None] * dense_row_stride + offset_col[\n None, :] * dense_col_stride\n for _j in range(0, N, thread_block_col_size):\n mask = (offset_row[:, None] < M) & (offset_col[None, :] < N)\n jagged_val = tl.load(jagged_value_ptr + block_offset, mask=mask,\n other=0)\n if operation_function is not None:\n val1 = jagged_val\n val2 = tl.load(operation_dense + block_offset, mask=mask,\n other=0)\n if operation_function == 'add':\n jagged_val = tensor_elementwise_add(val1, val2)\n else:\n jagged_val = tensor_elementwise_mul(val1, val2)\n tl.store(output_dense_ptr + block_offset, jagged_val, mask=mask)\n offset_col += thread_block_col_size\n block_offset += thread_block_col_size\n offset_row += thread_block_row_size\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "7373edff-5262-4dfe-8b20-5d8d947fc6be", "file_name": "triton_chunk.py", "repo_name": "NX-AI/xlstm-jax", "file_path": "xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py", "commit_hash": "6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7", "starcount": 0, "input": "@triton.jit\ndef chunk_mlstm_fwd_kernel_C(k, v, C, n, m, i, f, initial_C, initial_n,\n initial_m, final_C, final_n, final_m, s_qk_h, s_qk_t, s_qk_d, s_vh_h,\n s_vh_t, s_vh_d, s_C_h, s_C_t, s_n_h, H: tl.constexpr, T: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr,\n BV: tl.constexpr, NT: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n STORE_FINAL_STATE: tl.constexpr):\n i_k, i_v, i_bC = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n if USE_INITIAL_STATE:\n p_C0 = tl.make_block_ptr(initial_C + i_bC * K * V, (K, V), (V, 1),\n (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_n0 = tl.make_block_ptr(initial_n + i_bC * K, (K,), (1,), (i_k *\n BK,), (BK,), (0,))\n p_m0 = initial_m\n b_C = tl.load(p_C0, boundary_check=(0, 1)).to(tl.float32)\n b_n = tl.load(p_n0, boundary_check=(0,)).to(tl.float32)\n b_m = tl.load(p_m0).to(tl.float32)\n else:\n b_C = tl.zeros([BK, BV], dtype=tl.float32)\n b_n = tl.zeros([BK], dtype=tl.float32)\n b_m = 0.0\n b_m_next = 0.0\n for i_t in range(NT):\n p_k = tl.make_block_ptr(k + i_bC * s_qk_h, (K, T), (s_qk_d, s_qk_t),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bC * s_vh_h, (T, V), (s_vh_t, s_vh_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_C = tl.make_block_ptr(C + i_bC * s_C_h + i_t * K * V, (K, V), (\n s_C_t, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_n = tl.make_block_ptr(n + i_bC * s_n_h + i_t * K, (K,), (1,), (\n i_k * BK,), (BK,), (0,))\n tl.store(p_C, b_C.to(p_C.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_n, b_n.to(p_n.dtype.element_ty), boundary_check=(0,))\n tl.store(m + i_bC * (NT + 1) + i_t, b_m)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_f_last = tl.load(f + i_bC * T + i_t * BT + BT - 1)\n b_f = tl.load(f + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_i = tl.load(i + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_g = b_i + b_f_last - b_f\n b_m_next, _ = tl.max(b_g)\n b_m_next = tl.maximum(b_f_last + b_m, b_m_next)\n b_C *= tl.math.exp2(b_f_last - b_m_next + b_m)\n b_n *= tl.math.exp2(b_f_last - b_m_next + b_m)\n b_C += tl.dot(b_k, (b_v * tl.math.exp2(b_g - b_m_next)[:, None]).to\n (b_k.dtype), allow_tf32=False)\n b_n += tl.sum(b_k * tl.math.exp2(b_g - b_m_next), axis=1)\n b_m = b_m_next\n if STORE_FINAL_STATE:\n p_Ct = tl.make_block_ptr(final_C + i_bC * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_n = tl.make_block_ptr(final_n + i_bC * K, (K,), (1,), (i_k * BK,),\n (BK,), (0,))\n tl.store(p_Ct, b_C.to(p_Ct.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_n, b_n.to(p_n.dtype.element_ty), boundary_check=(0,))\n tl.store(final_m + i_bC, b_m)\n tl.store(m + i_bC * (NT + 1) + NT, b_m)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Low Latency" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache", "BSD" ], "github_url": "https://github.com/NX-AI/xlstm-jax/blob/6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7/xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py" }, { "uuid": "0d15dee4-56b7-4d6d-bb33-39e4b5938078", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=MATMUL_CONFIGS, key=['m_key', 'n_key', 'k_key'],\n prune_configs_by={'early_config_prune': early_config_prune,\n 'perf_model': estimate_matmul_time, 'top_k': 10})\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.jit\ndef _kernel_matmul_fp8_block_slowacc(A, B, C, M, N, K, m_key, n_key, k_key,\n A_scale, B_scale, scale_block_m: tl.constexpr, scale_block_n: tl.\n constexpr, scale_block_k: tl.constexpr, stride_am, stride_ak, stride_bn,\n stride_bk, stride_cm, stride_cn, stride_scale_am, stride_scale_ak,\n stride_scale_bn, stride_scale_bk, dot_out_dtype: tl.constexpr,\n allow_tf32: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,\n BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl.constexpr,\n EVEN_K: tl.constexpr, AB_DTYPE: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with block-wise scales\n\n Performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles and\n A and B scaled by a scaling factor per [scale_block_m, scale_block_k] and\n [scale_block_n, scale_block_k] tiles\n respectively.\n\n Todo:\n * Support scale_block_{mnk} < BLOCK{MNK} for each dim.\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n m_key (int): Autotuning key for M dimension of input tensor.\n n_key (int): Autotuning key for N dimension of input tensor.\n k_key (int): Autotuning key for K dimension of input tensor.\n A_scale (TensorWrapper): [cdiv(M, scale_block_m), cdiv(K, scale_block_k)] reciprocal scale tensor per block. A * A_scale = original A\n B_scale (TensorWrapper): [cdiv(N, scale_block_n), cdiv(K, scale_block_k)] reciprocal scale tensor per block. B * B_scale = original B\n scale_block_m (int): Block size for M dimension of A_scale.\n scale_block_n (int): Block size for N dimension of B_scale.\n scale_block_k (int): Block size for K dimension of A_scale and B_scale.\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n stride_scale_am (int): Stride of M dimension of A_scale.\n stride_scale_ak (int): Stride of K dimension of A_scale.\n stride_scale_bn (int): Stride of N dimension of B_scale.\n stride_scale_bk (int): Stride of K dimension of B_scale.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n assert BLOCK_M < scale_block_m\n assert BLOCK_N < scale_block_n\n assert BLOCK_K < scale_block_k\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n scale_m = pid_m * BLOCK_M // scale_block_m\n scale_n = pid_n * BLOCK_N // scale_block_n\n _0 = tl.zeros((1, 1), dtype=C.dtype.element_ty)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n pid_k = k * SPLIT_K + pid_z\n scale_k = pid_k * BLOCK_K // scale_block_k\n a_scale = tl.load(A_scale + scale_m * stride_scale_am + scale_k *\n stride_scale_ak)\n b_scale = tl.load(B_scale + scale_n * stride_scale_bn + scale_k *\n stride_scale_bk)\n scale = a_scale * b_scale\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_0)\n b = tl.load(B, mask=rk[:, None] < k_remaining, other=_0)\n if AB_DTYPE:\n a = a.to(C.dtype.element_ty)\n b = b.to(C.dtype.element_ty)\n acc += tl.dot(a, b, out_dtype=dot_out_dtype, allow_tf32=allow_tf32\n ) * scale\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n acc = acc.to(C.dtype.element_ty)\n c = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if SPLIT_K == 1:\n tl.store(c, acc, mask=mask)\n else:\n tl.atomic_add(c, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "9c7bbe01-fd64-4864-80d0-e77e220fab0a", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef fused_chunk_delta_rule_bwd_kernel(q, k, v, d, dht, dh0, do, dq, dk, dv,\n dd, initial_state, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, B, H, T,\n scale, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, DK: tl.\n constexpr, DV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr, USE_DHT:\n tl.constexpr, USE_DHO: tl.constexpr, CHECK: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_DHT:\n p_dht = tl.make_block_ptr(dht + i_bh * DK * DV, (DK, DV), (DV, 1),\n (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1)).to(tl.float32)\n m_s = o_i[:, None] <= o_i[None, :]\n for i in range(tl.cdiv(T, BT) - 1, -1, -1):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (DK, T), (s_k_d, s_k_t),\n (i_k * BK, i * BT), (BK, BT), (0, 1))\n p_d = tl.make_block_ptr(d + i_bh * s_k_h, (DK, T), (s_k_d, s_k_t),\n (i_k * BK, i * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, DK), (s_k_t, s_k_d),\n (i * BT, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, DV), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, DV), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dk = tl.make_block_ptr(dk + (i_bh + i_v * B * H) * s_k_h, (T, DK),\n (s_k_t, s_k_d), (i * BT, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + i_k * B * H) * s_v_h, (T, DV),\n (s_v_t, s_v_d), (i * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False)\n b_ds = tl.where(m_s, b_ds, 0).to(b_q.dtype)\n b_s = tl.dot(b_k, b_q, allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0).to(b_q.dtype)\n b_dk = tl.dot(b_ds, tl.trans(b_q), allow_tf32=False)\n b_dv = tl.dot(b_s, b_do, allow_tf32=False)\n b_d = tl.load(p_d, boundary_check=(0, 1))\n b_dk += tl.dot(b_v, tl.trans(b_dh).to(b_v.dtype), allow_tf32=False)\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False)\n b_dh += tl.dot(b_q, b_do, allow_tf32=False)\n b_dh -= tl.dot(b_d, b_dv.to(b_d.dtype), allow_tf32=False)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n if USE_DHO:\n p_dh0 = tl.make_block_ptr(dh0 + i_bh * DK * DV, (DK, DV), (DV, 1),\n (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n b_h = None\n tl.debug_barrier()\n m_s = o_i[:, None] >= o_i[None, :]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(initial_state + i_bh * DK * DV, (DV, DK), (\n 1, DV), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n b_h += tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n NT = tl.cdiv(T, BT)\n for i in range(0, NT):\n p_dv = tl.make_block_ptr(dv + i_bh * s_v_h, (T, DV), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n b_dv = tl.load(p_dv, boundary_check=(0, 1))\n b_dd = tl.dot(b_dv.to(k.dtype.element_ty), b_h.to(k.dtype.\n element_ty), allow_tf32=False)\n p_dd = tl.make_block_ptr(dd + (i_bh + i_v * B * H) * s_k_h, (T, DK),\n (s_k_t, s_k_d), (i * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dd, -b_dd.to(p_dd.dtype.element_ty), boundary_check=(0, 1))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, DK), (s_k_t, s_k_d),\n (i * BT, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (DV, T), (s_v_d, s_v_t),\n (i_v * BV, i * BT), (BV, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, DV), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dq = tl.make_block_ptr(dq + (i_bh + i_v * B * H) * s_k_h, (T, DK),\n (s_k_t, s_k_d), (i * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n b_ds = tl.where(m_s, b_ds, 0)\n b_dq = tl.dot(b_ds.to(b_k.dtype), b_k, allow_tf32=False)\n if CHECK and i == 0:\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_v, b_k, allow_tf32=False)\n else:\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_v, b_k, allow_tf32=False)\n b_dq *= scale\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/fused_chunk.py" }, { "uuid": "16c05989-05bd-492f-89cf-86a814ede982", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef d_silu(x, o):\n sig = tl.sigmoid(x)\n return sig + o * (1 - sig)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "fd1f4159-2938-4d88-91f3-e1646ab75398", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef calc_mean_and_inv_std(input, last_dim, eps, last_dim_mask: tl.constexpr):\n \"\"\"\n Calculates the mean and inverse standard deviation of the input\n along the last dimension.\n\n Args:\n input: Input whose mean and inverse standard deviation are calculated.\n The input must be of shape [BLOCK_SIZE1, BLOCK_SIZE2].\n last_dim: Size of the last dimension of input.\n eps: Epsilon added in the square root in the denominator\n to avoid division by zero.\n last_dim_mask: Mask for the last dimension indicating\n which elements should be included in the calculations.\n The mask must be of shape [BLOCK_SIZE2].\n\n Returns:\n Mean and inverse standard deviation of the input.\n \"\"\"\n input = input.to(tl.float32)\n mean = tl.sum(input, axis=1) / last_dim\n diff = tl.where(last_dim_mask[None, :], input - mean[:, None], 0)\n inv_std = tl.rsqrt(tl.sum(diff * diff, axis=1) / last_dim + eps)\n return mean, inv_std\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "dc7321dc-32fb-4fed-9ba5-5273d19cb153", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES, BLOCK_SIZES, NUM_WARPS, NUM_STAGES)],\n key=['M'])\n@triton.jit\ndef triton_jagged_sum_kernel_variable_length_loop_sum_then_buffer(\n input_ptr_values, input_ptr_offsets, output_ptr, M, BLOCK_SIZE_RAGGED:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_b = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((1, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_b), tl.load(\n input_ptr_offsets + (pid_b + 1))\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer += tl.sum(input, axis=0)\n buffer_view = buffer.reshape((BLOCK_SIZE_M,))\n output_offsets = offsets_m + pid_b * M\n output_mask = output_offsets < M * (pid_b + 1)\n tl.store(output_ptr + output_offsets, buffer_view, mask=output_mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_sum/kernels.py" }, { "uuid": "e1d634ae-75e9-4158-a173-e373bc727999", "file_name": "triton_fused_attn_rerope.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_attn_rerope.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0})\n@triton.jit\ndef _fwd_kernel(Q1, Q2, K1, K2, V, sm_scale, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, seqlen_q, seqlen_k, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, IS_CAUSAL: tl.\n constexpr, WINDOW: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr\n ):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n q_offset = off_hz * stride_qh\n kv_offset = off_hz * stride_kh\n Q1_block_ptr = tl.make_block_ptr(base=Q1 + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n Q2_block_ptr = tl.make_block_ptr(base=Q2 + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K1_block_ptr = tl.make_block_ptr(base=K1 + kv_offset, shape=(\n BLOCK_DMODEL, seqlen_k), strides=(stride_kk, stride_kn), offsets=(0,\n 0), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n K2_block_ptr = tl.make_block_ptr(base=K2 + kv_offset, shape=(\n BLOCK_DMODEL, seqlen_k), strides=(stride_kk, stride_kn), offsets=(0,\n 0), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + kv_offset, shape=(seqlen_k,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504\n if EVEN_M:\n q1 = tl.load(Q1_block_ptr)\n q2 = tl.load(Q2_block_ptr)\n else:\n q1 = tl.load(Q1_block_ptr, boundary_check=(0,), padding_option='zero')\n q2 = tl.load(Q2_block_ptr, boundary_check=(0,), padding_option='zero')\n lo = 0\n hi = tl.minimum((start_m + 1) * BLOCK_M, seqlen_k\n ) if IS_CAUSAL else seqlen_k\n for start_n in range(lo, hi, BLOCK_N):\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n if IS_CAUSAL:\n qk = tl.where(offs_m[:, None] >= start_n + offs_n[None, :], qk,\n float('-inf'))\n if not EVEN_N:\n qk = tl.where(start_n + offs_n[None, :] < seqlen_k, qk, float(\n '-inf'))\n if start_n <= start_m * BLOCK_M - WINDOW - BLOCK_N or start_n >= (\n start_m + 1) * BLOCK_M + WINDOW:\n if EVEN_N & EVEN_M:\n k2 = tl.load(K2_block_ptr)\n else:\n k2 = tl.load(K2_block_ptr, boundary_check=(1,),\n padding_option='zero')\n qk += tl.dot(q2, k2)\n elif start_n > (start_m + 1\n ) * BLOCK_M - WINDOW and start_n < start_m * BLOCK_M + WINDOW - BLOCK_N:\n if EVEN_N & EVEN_M:\n k1 = tl.load(K1_block_ptr)\n else:\n k1 = tl.load(K1_block_ptr, boundary_check=(1,),\n padding_option='zero')\n qk += tl.dot(q1, k1)\n else:\n if EVEN_N & EVEN_M:\n k1 = tl.load(K1_block_ptr)\n k2 = tl.load(K2_block_ptr)\n else:\n k1 = tl.load(K1_block_ptr, boundary_check=(1,),\n padding_option='zero')\n k2 = tl.load(K2_block_ptr, boundary_check=(1,),\n padding_option='zero')\n qk1 = tl.dot(q1, k1)\n qk2 = tl.dot(q2, k2)\n qk += tl.where(tl.abs(offs_m[:, None] - (start_n + offs_n[None,\n :])) < WINDOW, qk1, qk2)\n qk *= qk_scale\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc_scale = l_i * 0 + alpha\n acc *= acc_scale[:, None]\n if EVEN_N & EVEN_M:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(0,), padding_option='zero'\n )\n v = tl.load(V_block_ptr)\n acc += tl.dot(p.to(v.dtype), v)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K1_block_ptr = tl.advance(K1_block_ptr, (0, BLOCK_N))\n K2_block_ptr = tl.advance(K2_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n acc = acc / l_i[:, None]\n O_block_ptr = tl.make_block_ptr(base=Out + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n offs_d = tl.arange(0, BLOCK_DMODEL)\n out_ptrs = Out + q_offset + (offs_m[:, None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc)\n else:\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_attn_rerope.py" }, { "uuid": "77311a94-8d98-4965-a46c-7c601a7fd275", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES, BLOCK_SIZES, NUM_WARPS, NUM_STAGES)],\n key=['M'])\n@triton.jit\ndef triton_jagged_sum_kernel_simple_fused_sum_then_buffer(input_ptr_values,\n input_ptr_offsets, output_ptr, M, MAX_SEQLEN, BLOCK_SIZE_RAGGED: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_ragged = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((1, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_ragged\n ), tl.load(input_ptr_offsets + (pid_ragged + 1))\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer += tl.sum(input, axis=0)\n buffer_view = buffer.reshape((BLOCK_SIZE_M,))\n output_offsets = offsets_m + pid_ragged * M\n output_mask = output_offsets < M * (pid_ragged + 1)\n tl.store(output_ptr + output_offsets, buffer_view, mask=output_mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_sum/kernels.py" }, { "uuid": "454eebde-6921-487e-b8e0-ee204d96b580", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'\n ] is not None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=[\n 'BT'])\n@triton.jit\ndef chunk_retention_bwd_kernel_dh(q, do, dh, dh0, dht, offsets,\n chunk_offsets, scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr,\n V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n STORE_INITIAL_STATE_GRADIENT: tl.constexpr, USE_FINAL_STATE_GRADIENT:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n o_i = tl.arange(0, BT)\n d_i = tl.math.exp2((o_i + 1) * b_b)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT - 1, -1, -1):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_nh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + ((boh + i_t) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n d_b = tl.math.exp2(min(BT, T - i_t * BT) * b_b)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dh = d_b * b_dh + tl.dot(b_q, (b_do * d_i[:, None]).to(b_q.dtype),\n allow_tf32=False)\n if STORE_INITIAL_STATE_GRADIENT:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/chunk.py" }, { "uuid": "4ca187d4-705d-426a-ab32-956f78d4d117", "file_name": "sb_fwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_attn/sb_fwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.autotune(configs=get_configs(), key=['token_size', 'head_size'])\n@triton.jit\ndef _forward(Q_ptr, stride_qb, stride_qh, stride_qm: tl.constexpr,\n stride_qd: tl.constexpr, K_ptr, stride_kb, stride_kh, stride_kn: tl.\n constexpr, stride_kd: tl.constexpr, V_ptr, stride_vb, stride_vh,\n stride_vn: tl.constexpr, stride_vd: tl.constexpr, O_ptr, stride_ob,\n stride_oh, stride_om: tl.constexpr, stride_od: tl.constexpr, R_ptr,\n stride_rb, stride_rh, stride_rm: tl.constexpr, A_ptr, stride_ab,\n stride_ah, stride_am: tl.constexpr, W_ptr, stride_wb, stride_wh,\n stride_wm, stride_wn, logit_scale: tl.constexpr, attend_current: tl.\n constexpr, batch_size, token_size, head_size: tl.constexpr, num_heads:\n tl.constexpr, BLOCK_D: tl.constexpr, NO_D_MASK: tl.constexpr, NO_M_MASK:\n tl.constexpr, NO_N_MASK: tl.constexpr, ALLOW_TF32: tl.constexpr,\n inv_log2: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,\n no_grad: tl.constexpr=False, acc_dtype: tl.constexpr=tl.float32,\n return_attention: tl.constexpr=False, is_compiling: tl.constexpr=False):\n tl.static_assert(BLOCK_M % BLOCK_N == 0)\n batch_id = tl.program_id(0)\n head_pid = tl.program_id(1)\n prog_id = tl.program_id(2)\n tl.num_programs(2)\n seq_length = token_size\n qk_scale = inv_log2 * logit_scale\n M_range = tl.arange(0, BLOCK_M)\n N_range = tl.arange(0, BLOCK_N)\n D_range = tl.arange(0, BLOCK_D)\n D_mask = D_range < head_size\n cm = tl.where(N_range[:, None] >= N_range[None, :], 1.0, 0.0).to(Q_ptr.\n type.element_ty)\n head_id = head_pid\n seq_prog_id = prog_id\n Q_head_seq_ptr = Q_ptr + stride_qb * batch_id + stride_qh * head_id\n K_head_seq_ptr = K_ptr + stride_kb * batch_id + stride_kh * head_id\n V_head_seq_ptr = V_ptr + stride_vb * batch_id + stride_vh * head_id\n O_head_seq_ptr = O_ptr + stride_ob * batch_id + stride_oh * head_id\n R_head_seq_ptr = R_ptr + stride_rb * batch_id + stride_rh * head_id\n A_head_seq_ptr = A_ptr + stride_ab * batch_id + stride_ah * head_id\n W_head_seq_ptr = W_ptr + stride_wb * batch_id + stride_wh * head_id\n _forward_one_row(seq_prog_id, seq_length, qk_scale, M_range, N_range,\n D_range, D_mask, cm, Q_head_seq_ptr, stride_qm, stride_qd,\n K_head_seq_ptr, stride_kn, stride_kd, V_head_seq_ptr, stride_vn,\n stride_vd, O_head_seq_ptr, stride_om, stride_od, R_head_seq_ptr,\n stride_rm, A_head_seq_ptr, stride_am, W_head_seq_ptr, stride_wm,\n stride_wn, BLOCK_D, NO_D_MASK, NO_M_MASK, NO_N_MASK, ALLOW_TF32,\n BLOCK_M, BLOCK_N, no_grad, acc_dtype, return_attention,\n attend_current=attend_current, is_compiling=is_compiling)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Batch-Oriented" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_attn/sb_fwd.py" }, { "uuid": "4a35494c-3b38-474a-8c6f-d0bfb320f8b8", "file_name": "swiglu.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/swiglu.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_swiglu_backward(grad_output_ptr, input_a_ptr, input_b_ptr,\n row_stride, num_columns: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n prog_id = tl.program_id(0).to(tl.int64)\n grad_output_ptr += prog_id * row_stride\n input_a_ptr += prog_id * row_stride\n input_b_ptr += prog_id * row_stride\n column_offsets = tl.arange(0, BLOCK_SIZE)\n active_mask = column_offsets < num_columns\n grad_output_row = tl.load(grad_output_ptr + column_offsets, mask=\n active_mask, other=0)\n input_a_row = tl.load(input_a_ptr + column_offsets, mask=active_mask,\n other=0).to(tl.float32)\n input_b_row = tl.load(input_b_ptr + column_offsets, mask=active_mask,\n other=0)\n sigmoid_a = tl.sigmoid(input_a_row)\n silu_a = input_a_row * sigmoid_a\n grad_b_row = grad_output_row * silu_a\n grad_a_row = grad_output_row * (silu_a * (1 - sigmoid_a) + sigmoid_a\n ) * input_b_row\n tl.store(input_a_ptr + column_offsets, grad_a_row, mask=active_mask)\n tl.store(input_b_ptr + column_offsets, grad_b_row, mask=active_mask)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/swiglu.py" }, { "uuid": "c669de30-862b-4b20-b39f-b1ab212762b0", "file_name": "test_triton_basics.py", "repo_name": "tucommenceapousser/xformers", "file_path": "tests/test_triton_basics.py", "commit_hash": "c97e3d917cfdad4a38acd4e9d776030d25ab9141", "starcount": 0, "input": "@triton.jit\ndef k_rand(X, Y, SEED_X, SEED_Y, stride_x, stride_y, N: tl.constexpr):\n \"\"\"\n Check the random number generation\n \"\"\"\n row = tl.program_id(0)\n rand_offsets = tl.arange(0, N)\n seed_x = tl.load(SEED_X + row)\n randx, _, _, _ = tl.randint4x(seed_x, rand_offsets)\n rand_offsets = tl.arange(0, N)\n seed_y = tl.load(SEED_Y + row)\n randy, _, _, _ = tl.randint4x(seed_y, rand_offsets)\n tl.store(X + row * stride_x + tl.arange(0, N), randx)\n tl.store(Y + row * stride_y + tl.arange(0, N), randy)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/tucommenceapousser/xformers/blob/c97e3d917cfdad4a38acd4e9d776030d25ab9141/tests/test_triton_basics.py" }, { "uuid": "1f159cd8-6426-4d71-9d99-6e0ba4030389", "file_name": "matrix-vector-multiplication.py", "repo_name": "northstreet12/triton-cpu", "file_path": "python/tutorials/matrix-vector-multiplication.py", "commit_hash": "bfb302ffc5fde3b9efe040cb452ddac0454dbb98", "starcount": 0, "input": "@triton.jit\ndef gemv_kernel(Y, A, X, M, N, stride_am, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr):\n start_m = tl.program_id(0)\n rm = start_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n rn = tl.arange(0, BLOCK_SIZE_N)\n A = A + (rm[:, None] * stride_am + rn[None, :])\n X = X + rn\n acc = tl.zeros((BLOCK_SIZE_M,), dtype=tl.float32)\n for n in range(N, 0, -BLOCK_SIZE_N):\n a = tl.load(A)\n x = tl.load(X)\n acc += tl.sum(a * x[None, :], axis=1)\n A += BLOCK_SIZE_N\n X += BLOCK_SIZE_N\n Y = Y + rm\n tl.store(Y, acc)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/northstreet12/triton-cpu/blob/bfb302ffc5fde3b9efe040cb452ddac0454dbb98/python/tutorials/matrix-vector-multiplication.py" }, { "uuid": "36107a2c-caa6-4ebc-98a8-495698ac5780", "file_name": "multi_head_attention_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/multi_head_attention_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef _bwd_kernel_one_col_block(Q, K, V, sm_scale, qk_scale, Out, DO, DQ, DK,\n DV, L, D, Q_block_ptr, K_block_ptr, V_block_ptr, DO_block_ptr,\n DQ_block_ptr, DK_block_ptr, DV_block_ptr, stride_dqa, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vn, stride_vk, Z, H, N_CTX,\n off_h, off_z, off_hz, start_n, num_block, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, SEQUENCE_PARALLEL:\n tl.constexpr, CAUSAL: tl.constexpr, MMA_V3: tl.constexpr):\n if CAUSAL:\n lo = start_n * BLOCK_M\n else:\n lo = 0\n Q_offset = (off_z * stride_qz + off_h * stride_qh) // stride_qm\n DQ_offset = off_z * stride_qz + off_h * stride_qh\n K_offset = (off_z * stride_kz + off_h * stride_kh) // stride_kn\n V_offset = (off_z * stride_vz + off_h * stride_vh) // stride_vn\n if SEQUENCE_PARALLEL:\n DQ_offset += stride_dqa * start_n\n DQ_offset = DQ_offset // stride_qm\n Q_block_ptr = tl.advance(Q_block_ptr, (lo + Q_offset, 0))\n K_block_ptr = tl.advance(K_block_ptr, (start_n * BLOCK_M + K_offset, 0))\n V_block_ptr = tl.advance(V_block_ptr, (start_n * BLOCK_M + V_offset, 0))\n DO_block_ptr = tl.advance(DO_block_ptr, (lo + Q_offset, 0))\n DQ_block_ptr = tl.advance(DQ_block_ptr, (lo + DQ_offset, 0))\n DK_block_ptr = tl.advance(DK_block_ptr, (start_n * BLOCK_M + K_offset, 0))\n DV_block_ptr = tl.advance(DV_block_ptr, (start_n * BLOCK_M + V_offset, 0))\n offs_n = start_n * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_m = tl.arange(0, BLOCK_N)\n D_ptrs = D + off_hz * N_CTX\n l_ptrs = L + off_hz * N_CTX\n dv = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n dk = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n k = tl.load(K_block_ptr)\n v = tl.load(V_block_ptr)\n for start_m in range(lo, num_block * BLOCK_M, BLOCK_M):\n offs_m_curr = start_m + offs_m\n q = tl.load(Q_block_ptr)\n if CAUSAL:\n qk = tl.where(offs_m_curr[:, None] >= offs_n[None, :], float(\n 0.0), float('-inf'))\n else:\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, tl.trans(k))\n qk *= qk_scale\n l_i = tl.load(l_ptrs + offs_m_curr)\n p = tl.math.exp2(qk - l_i[:, None])\n do = tl.load(DO_block_ptr)\n dv += tl.dot(tl.trans(p.to(Q.dtype.element_ty)), do)\n Di = tl.load(D_ptrs + offs_m_curr)\n dp = tl.dot(do, tl.trans(v))\n ds = (p * (dp - Di[:, None]) * sm_scale).to(Q.dtype.element_ty)\n dk += tl.dot(tl.trans(ds), q)\n if not SEQUENCE_PARALLEL:\n dq = tl.load(DQ_block_ptr)\n dq += tl.dot(ds, k)\n tl.store(DQ_block_ptr, dq.to(Q.dtype.element_ty))\n elif SEQUENCE_PARALLEL:\n if MMA_V3:\n dq = tl.dot(ds, k)\n else:\n dq = tl.trans(tl.dot(tl.trans(k), tl.trans(ds)))\n tl.store(DQ_block_ptr, dq.to(Q.dtype.element_ty))\n DQ_block_ptr = tl.advance(DQ_block_ptr, (BLOCK_M, 0))\n Q_block_ptr = tl.advance(Q_block_ptr, (BLOCK_M, 0))\n DO_block_ptr = tl.advance(DO_block_ptr, (BLOCK_M, 0))\n tl.store(DV_block_ptr, dv.to(V.dtype.element_ty))\n tl.store(DK_block_ptr, dk.to(K.dtype.element_ty))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/multi_head_attention_kernels.py" }, { "uuid": "a03e38da-ffa6-4c28-bae7-c2831152756e", "file_name": "bwd_kernel_dq.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/bwd_kernel_dq.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_kernel_dq(Q, K, V, B, sm_scale, Out, DO, DQ, DB, L, D, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vk, stride_vn, stride_bz,\n stride_bh, stride_bm, stride_bn, stride_oz, stride_oh, stride_om,\n stride_ok, stride_dqz, stride_dqh, stride_dqm, stride_dqk, stride_dbz,\n stride_dbh, stride_dbm, stride_dbn, num_head_q: 'i32', num_head_k:\n 'i32', cu_seqlens_q, cu_seqlens_k, num_seqlens, max_seqlen_q,\n max_seqlen_k, head_dim, dropout_p, philox_seed_ptr, philox_offset1:\n '*u32', philox_offset2: 'u32', BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.\n constexpr, BLOCK_N: tl.constexpr, CAUSAL: tl.constexpr, ENABLE_DROPOUT:\n tl.constexpr, PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.constexpr):\n philox_seed = 0\n philox_offset_base = philox_offset2\n if ENABLE_DROPOUT:\n philox_seed = tl.load(philox_seed_ptr)\n philox_offset_base += tl.load(philox_offset1)\n start_q = tl.program_id(0) * BLOCK_M\n off_h_q = tl.program_id(1)\n off_h_k = off_h_q if num_head_q == num_head_k else off_h_q // (num_head_q\n // num_head_k)\n off_z = tl.program_id(2)\n num_z = tl.num_programs(2)\n off_zh = off_z * num_head_q + off_h_q * 1\n offs_q = start_q + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n ld_offs_d = None if not PADDED_HEAD else tl.arange(0, BLOCK_DMODEL)\n cu_seqlens_q_start = 0\n cu_seqlens_k_start = 0\n seqlen_q = max_seqlen_q\n seqlen_k = max_seqlen_k\n batch_index = off_z\n if num_seqlens > 0:\n cu_seqlens_q_start = tl.load(cu_seqlens_q + off_z)\n cu_seqlens_q_end = tl.load(cu_seqlens_q + off_z + 1)\n seqlen_q = cu_seqlens_q_end - cu_seqlens_q_start\n if start_q >= seqlen_q:\n return\n cu_seqlens_k_start = tl.load(cu_seqlens_k + off_z)\n cu_seqlens_k_end = tl.load(cu_seqlens_k + off_z + 1)\n seqlen_k = cu_seqlens_k_end - cu_seqlens_k_start\n batch_index = 0\n if num_seqlens < 0:\n cu_seqlens_q_start = tl.load(cu_seqlens_q + off_z)\n cu_seqlens_q_end = tl.load(cu_seqlens_q + off_z + 1)\n seqlen_q = cu_seqlens_q_end - cu_seqlens_q_start\n if start_q >= seqlen_q:\n return\n cu_seqlens_k_start = tl.load(cu_seqlens_k + off_z)\n cu_seqlens_k_end = tl.load(cu_seqlens_k + off_z + 1)\n seqlen_k = cu_seqlens_k_end - cu_seqlens_k_start\n cu_seqlens_q_start = 0\n cu_seqlens_k_start = 0\n batch_index = off_z\n q_offset = (off_h_q * stride_qh + batch_index * stride_qz + \n cu_seqlens_q_start * stride_qm)\n Q += q_offset\n q_ptrs = Q + offs_q[:, None] * stride_qm + offs_d[None, :] * stride_qk\n if start_q + BLOCK_M <= seqlen_q:\n q = load_fn(q_ptrs, None, ld_offs_d, seqlen_q, head_dim)\n else:\n q = load_fn(q_ptrs, offs_q, ld_offs_d, seqlen_q, head_dim)\n qk_scale = sm_scale * 1.44269504089\n bias_scale = 1.0 / sm_scale\n k_offset = (off_h_k * stride_kh + batch_index * stride_kz + \n cu_seqlens_k_start * stride_kn)\n K += k_offset\n kt_ptrs = K + offs_d[:, None] * stride_kk + offs_n[None, :] * stride_kn\n v_offset = (off_h_k * stride_vh + batch_index * stride_vz + \n cu_seqlens_k_start * stride_vk)\n V += v_offset\n vt_ptrs = V + offs_d[:, None] * stride_vn + offs_n[None, :] * stride_vk\n do_offset = (off_h_q * stride_oh + batch_index * stride_oz + \n cu_seqlens_q_start * stride_om)\n DO += do_offset\n do_ptrs = DO + offs_q[:, None] * stride_om + offs_d[None, :] * stride_ok\n if start_q + BLOCK_M <= seqlen_q:\n do = load_fn(do_ptrs, None, ld_offs_d, seqlen_q, head_dim)\n else:\n do = load_fn(do_ptrs, offs_q, ld_offs_d, seqlen_q, head_dim)\n D_ptrs = D + off_zh * max_seqlen_q\n l_ptrs = L + off_zh * max_seqlen_q\n if ENABLE_DROPOUT:\n batch_philox_offset = (philox_offset_base + off_zh * max_seqlen_q *\n max_seqlen_k)\n else:\n batch_philox_offset = 0\n dq_offset = (batch_index * stride_dqz + off_h_q * stride_dqh + \n cu_seqlens_q_start * stride_dqm)\n DQ += dq_offset\n store_db = True\n if BIAS_TYPE == 0:\n B_block_ptr = 0\n DB_block_ptr = 0\n elif BIAS_TYPE == 1:\n B_block_ptr = tl.make_block_ptr(base=B + off_h_q * stride_bh + \n batch_index * stride_bz, shape=(seqlen_q, seqlen_k), strides=(\n stride_bm, stride_bn), offsets=(start_q, 0), block_shape=(\n BLOCK_M, BLOCK_N), order=(1, 0))\n if (stride_dbz == 0 and stride_dbh == 0) and stride_dbm == 0:\n store_db = False\n DB_block_ptr = tl.make_block_ptr(base=DB + off_h_q * stride_dbh + \n batch_index * stride_dbz, shape=(seqlen_q, seqlen_k), strides=(\n stride_dbm, stride_dbn), offsets=(start_q, 0), block_shape=(\n BLOCK_M, BLOCK_N), order=(1, 0))\n else:\n tl.static_assert(False, f'Unsupported BIAS_TYPE {BIAS_TYPE}')\n k_lo = 0\n k_hi = min(start_q + BLOCK_M, seqlen_k) if CAUSAL else seqlen_k\n real_seqlen_k = k_hi - k_lo\n n_blocks = tl.cdiv(k_hi - k_lo, BLOCK_N)\n n_extra_tokens = 0\n if real_seqlen_k < BLOCK_N:\n n_extra_tokens = BLOCK_N - real_seqlen_k\n elif real_seqlen_k % BLOCK_N:\n n_extra_tokens = real_seqlen_k % BLOCK_N\n is_irregular_k = n_extra_tokens != 0\n n_full_blocks = (k_hi - k_lo) // BLOCK_N\n leading_masked_blocks = 0\n trailing_masked_blocks = 0\n if CAUSAL:\n mask_top_edge = min(start_q, seqlen_k)\n n_full_blocks = (mask_top_edge - k_lo) // BLOCK_N\n trailing_masked_blocks = n_blocks - n_full_blocks\n else:\n trailing_masked_blocks = 1 if is_irregular_k else 0\n q_boundary = tl.full((BLOCK_M,), seqlen_q, dtype=tl.int32)\n d_lse_ptrs_mask = offs_q < q_boundary\n Di = tl.load(D_ptrs + offs_q, mask=d_lse_ptrs_mask, other=0.0)\n l_i = tl.load(l_ptrs + offs_q, mask=d_lse_ptrs_mask, other=0.0)\n dropout_scale = 1.0 / (1.0 - dropout_p) if ENABLE_DROPOUT else 1.0\n dq = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n if n_full_blocks > 0:\n lo = 0\n hi = n_full_blocks * BLOCK_N\n dq = bwd_inner_dq(dq, qk_scale, bias_scale, DB_block_ptr, store_db,\n q, kt_ptrs, stride_kn, vt_ptrs, stride_vk, B_block_ptr, do, Di,\n l_i, seqlen_q, seqlen_k, head_dim, start_q, lo, hi, dropout_p,\n dropout_scale, philox_seed, batch_philox_offset, max_seqlen_k,\n BLOCK_M, BLOCK_DMODEL, BLOCK_N, True, False, ENABLE_DROPOUT,\n PADDED_HEAD, BIAS_TYPE)\n if trailing_masked_blocks > 0:\n lo = n_full_blocks * BLOCK_N\n hi = k_hi\n tl.debug_barrier()\n dq = bwd_inner_dq(dq, qk_scale, bias_scale, DB_block_ptr, store_db,\n q, kt_ptrs, stride_kn, vt_ptrs, stride_vk, B_block_ptr, do, Di,\n l_i, seqlen_q, seqlen_k, head_dim, start_q, lo, hi, dropout_p,\n dropout_scale, philox_seed, batch_philox_offset, max_seqlen_k,\n BLOCK_M, BLOCK_DMODEL, BLOCK_N, False, CAUSAL, ENABLE_DROPOUT,\n PADDED_HEAD, BIAS_TYPE)\n dq = (dq * sm_scale).to(dq.type.element_ty)\n mstore2d(dq, BLOCK_M, BLOCK_DMODEL, o_base=DQ, o_start_row=start_q,\n o_start_col=0, o_rows=seqlen_q, o_cols=head_dim, stride_row=\n stride_dqm, stride_col=stride_dqk)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/bwd_kernel_dq.py" }, { "uuid": "1bc0dab2-df5d-49d7-8357-25c023511ef4", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/hgrn/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BD': BD}, num_warps=num_warps) for\n BD in [32, 64, 128] for num_warps in [1, 2, 4, 8]], key=['D'])\n@triton.jit\ndef fused_recurrent_hgrn_bwd_kernel(g, o, h0, dx, dg, do, dht, dh0, offsets,\n T: tl.constexpr, D: tl.constexpr, BD: tl.constexpr, USE_INITIAL_STATE:\n tl.constexpr, USE_FINAL_STATE_GRADIENT: tl.constexpr, USE_OFFSETS: tl.\n constexpr):\n i_d, i_n = tl.program_id(0), tl.program_id(1)\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n o_d = i_d * BD + tl.arange(0, BD)\n mask = o_d < D\n p_g = g + (bos + T - 1) * D + o_d\n p_o = o + (bos + T - 2) * D + o_d\n p_dx = dx + (bos + T - 1) * D + o_d\n p_dg = dg + (bos + T - 1) * D + o_d\n p_do = do + (bos + T - 1) * D + o_d\n b_dh = tl.zeros([BD], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = dht + i_n * D + o_d\n b_dh += tl.load(p_dht, mask=mask, other=0).to(tl.float32)\n for i in range(T - 1, -1, -1):\n b_g = tl.load(p_g, mask=mask, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask, other=0).to(tl.float32)\n if i > 0:\n b_o = tl.load(p_o, mask=mask, other=0).to(tl.float32)\n elif USE_INITIAL_STATE:\n b_o = tl.load(h0 + i_n * D + o_d, mask=mask, other=0).to(tl.float32\n )\n else:\n b_o = tl.zeros([BD], dtype=tl.float32)\n b_dh = b_dh + b_do\n b_dx = b_dh\n b_dh = b_dh * tl.exp(b_g)\n b_dg = b_dh * b_o\n tl.store(p_dx, b_dx.to(p_dx.dtype.element_ty), mask=mask)\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), mask=mask)\n p_g -= D\n p_o -= D\n p_dx -= D\n p_dg -= D\n p_do -= D\n if USE_INITIAL_STATE:\n p_dh0 = dh0 + i_n * D + o_d\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), mask=mask)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/hgrn/fused_recurrent.py" }, { "uuid": "4f77ab02-60d6-4972-ba32-de199f864ca3", "file_name": "blocksparse_logsumexp.py", "repo_name": "kimiasa/Experiments", "file_path": "src/models/attention/blocksparse_logsumexp.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.heuristics({'num_warps': lambda *args, **meta: num_warps(args[5] *\n meta['BLOCK'])})\n@triton.heuristics({'TN': lambda *args, **meta: next_power_of_2(args[5]) *\n meta['BLOCK']})\n@triton.jit\ndef _backward(X, OUT, DX, DOUT, LUT, sizemax, stride_zx, stride_zout,\n stride_hout, stride_zdx, stride_zdout, stride_hdout, **meta):\n pidhm = tl.program_id(0)\n pidz = tl.program_id(1)\n TN = meta['TN']\n BLOCK = meta['BLOCK']\n rxm = pidhm % BLOCK\n rbm = pidhm // BLOCK\n rxn = tl.arange(0, TN) % BLOCK\n rbn = tl.arange(0, TN) // BLOCK\n header = LUT + rbm * 2\n size = tl.load(header + 0)\n offset = tl.load(header + 1)\n check = rbn < size\n rbmn = tl.where(check, rbn, size - 1)\n blockid = tl.load(LUT + offset + rbmn * 4)\n rowid = tl.load(LUT + offset + rbmn * 4 + 2)\n headid = tl.load(LUT + offset + rbmn * 4 + 3)\n px = X + pidz * stride_zx + blockid * BLOCK * BLOCK + rxm * BLOCK + rxn\n pdx = DX + pidz * stride_zdx + blockid * BLOCK * BLOCK + rxm * BLOCK + rxn\n pout = (OUT + pidz * stride_zout + headid * stride_hout + rowid * BLOCK +\n rxm)\n pdout = (DOUT + pidz * stride_zdout + headid * stride_hdout + rowid *\n BLOCK + rxm)\n x = tl.load(px, mask=check, other=-float('inf'))\n out = tl.load(pout)\n dout = tl.load(pdout)\n x = x.to(tl.float32)\n out = out.to(tl.float32)\n dout = dout.to(tl.float32)\n dx = dout * tl.exp(-(out - x))\n tl.store(pdx, dx, mask=check)\n", "category": { "Functionality": [ "Backpropagation", "Softmax", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/models/attention/blocksparse_logsumexp.py" }, { "uuid": "97d8600e-0e67-46a3-81b1-9dc82a69f084", "file_name": "vector_add3.py", "repo_name": "danielpyon/ml-kernels", "file_path": "triton/vector_add3.py", "commit_hash": "506186b419335b590da538ffb388aea2c7c26c03", "starcount": 0, "input": "@triton.jit\ndef add_kernel(x, y, out, n, BLOCK_SIZE: tl.constexpr):\n start = BLOCK_SIZE * tl.program_id(axis=0)\n offsets = start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n\n xs = tl.load(x + offsets, mask=mask)\n ys = tl.load(y + offsets, mask=mask)\n tl.store(out + offsets, xs + ys, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT", "BSD" ], "github_url": "https://github.com/danielpyon/ml-kernels/blob/506186b419335b590da538ffb388aea2c7c26c03/triton/vector_add3.py" }, { "uuid": "965bd139-0aa6-4b52-b2f1-093fcc0ab9b0", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rebased/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef _parallel_rebased_bwd_dq(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dq,\n s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, scale, B: tl.constexpr, H: tl\n .constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BTL: tl.\n constexpr, BTS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_c * BTL, i_v * BV), (BTL, BV), (1, 0))\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTL, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_q = (b_q * scale).to(b_q.dtype)\n b_dq = tl.zeros([BTL, BK], dtype=tl.float32)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (0, \n i_k * BK), (BTS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (i_v *\n BV, 0), (BV, BTS), (0, 1))\n p_dz = dz + i_bh * T + i_c * BTL + tl.arange(0, BTL)\n b_dz = tl.load(p_dz, mask=i_c * BTL + tl.arange(0, BTL) < T)\n for _ in range(0, i_c * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[:, None]\n else:\n b_ds = b_ds\n b_s = tl.dot(b_q, tl.trans(b_k), allow_tf32=False)\n b_dq += tl.dot((2 * b_ds * b_s).to(b_v.dtype), b_k, allow_tf32=False)\n p_k = tl.advance(p_k, (BTS, 0))\n p_v = tl.advance(p_v, (0, BTS))\n b_dq *= scale\n o_q = tl.arange(0, BTL)\n o_k = tl.arange(0, BTS)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (i_v *\n BV, i_c * BTL), (BV, BTS), (0, 1))\n for _ in range(i_c * BTL, (i_c + 1) * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n m_s = o_q[:, None] >= o_k[None, :]\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[:, None]\n else:\n b_ds = b_ds\n b_ds = tl.where(m_s, b_ds, 0) * scale\n b_s = tl.dot(b_q, tl.trans(b_k), allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n b_dq += tl.dot((2 * b_ds * b_s).to(b_k.dtype), b_k, allow_tf32=False)\n p_k = tl.advance(p_k, (BTS, 0))\n p_v = tl.advance(p_v, (0, BTS))\n o_k += BTS\n p_dq = tl.make_block_ptr(dq + (i_bh + B * H * i_v) * s_k_h, (T, K), (\n s_k_t, s_k_d), (i_c * BTL, i_k * BK), (BTL, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n return\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rebased/parallel.py" }, { "uuid": "30b6c5be-8933-4c72-b749-323b8c021e41", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef fused_recurrent_retention_bwd_kernel(q, k, v, h0, do, dq, dk, dv, dh0,\n dht, offsets, scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n REVERSE: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n USE_FINAL_STATE_GRADIENT: tl.constexpr, USE_OFFSETS: tl.constexpr,\n HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n b_b = 1 - tl.math.exp2(-5 - i_h * 1.0)\n if HEAD_FIRST:\n p_k = k + i_nh * T * K + ((T - 1) * K if REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_do = do + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if REVERSE else\n 0) + i_k * BK + tl.arange(0, BK)\n else:\n p_k = k + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_do = do + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_v * all + bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n mask_h = mask_k[:, None] & mask_v[None, :]\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n b_h = b_b * b_h + b_k[:, None] * b_v[None, :]\n b_dq = tl.sum(b_h * b_do[None, :], axis=1) * scale\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), mask=mask_k)\n p_k += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_do += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_dq += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n tl.debug_barrier()\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + ((T - 1) * K if not REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + ((T - 1) * K if not REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + ((T - 1) * V if not REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_do = do + i_nh * T * V + ((T - 1) * V if not REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_dk = dk + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if not\n REVERSE else 0) + i_k * BK + tl.arange(0, BK)\n p_dv = dv + (i_k * B * H + i_nh) * T * V + ((T - 1) * V if not\n REVERSE else 0) + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_do = do + (bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_dk = dk + (i_v * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_dv = dv + (i_k * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_ht = dht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_dh += tl.load(p_ht, mask=mask_h, other=0).to(tl.float32)\n for _ in range(T):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n b_dh += b_q[:, None] * b_do[None, :]\n b_dk = tl.sum(b_dh * b_v[None, :], axis=1)\n b_dv = tl.sum(b_dh * b_k[:, None], axis=0)\n b_dh *= b_b\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), mask=mask_k)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), mask=mask_v)\n p_q += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n p_k += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n p_v += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n p_do += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n p_dk += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n p_dv += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n if USE_INITIAL_STATE:\n p_dh0 = dh0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/fused_recurrent.py" }, { "uuid": "256c710f-0067-4c80-b37c-d4bbf785d671", "file_name": "block_offsets.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/block_offsets.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.jit\ndef block_offsets_3d(shape_x, shape_y, shape_z, stride_x, stride_y,\n stride_z, offset_x, offset_y, offset_z, block_shape_x, block_shape_y,\n block_shape_z, require_mask=False):\n offs_x = tl.arange(0, block_shape_x) + offset_x\n offs_y = tl.arange(0, block_shape_y) + offset_y\n offs_z = tl.arange(0, block_shape_z) + offset_z\n ptrs = offs_x[:, None, None] * stride_x + offs_y[None, :, None\n ] * stride_y + offs_z[None, None, :] * stride_z\n if require_mask:\n mask = (offs_x[:, None, None] < shape_x) & (offs_y[None, :, None] <\n shape_y) & (offs_z[None, None, :] < shape_z)\n return ptrs, mask\n else:\n return ptrs\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access", "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/block_offsets.py" }, { "uuid": "a0e121c3-7ebc-4eb8-bdeb-cb903a4b9850", "file_name": "softmax.py", "repo_name": "Nagi-ovo/diy", "file_path": "OpenAI-Triton/softmax.py", "commit_hash": "d7c119aa762b9103109d29abaebee345246fe5d7", "starcount": 0, "input": "@triton.jit\ndef _softmax_fwd_kernel(output_ptr, stride_output_rop, input_ptr,\n stride_input_row, num_cols, block_size: tl.constexpr):\n row_index = tl.program_id(0)\n row_start_ptr = input_ptr + row_index * stride_input_row\n col_offsets = tl.arange(0, block_size)\n input_pointers = row_start_ptr + col_offsets\n row_mask = col_offsets < num_cols\n row = tl.load(input_pointers, mask=row_mask, other=float('-inf'))\n safe_row = row - tl.max(row, axis=0)\n numerator = tl.exp(safe_row)\n denominator = tl.sum(numerator, axis=0)\n sm_out = numerator / denominator\n output_row_ptr = output_ptr + row_index * stride_output_rop\n output_pointers = output_row_ptr + col_offsets\n tl.store(output_pointers, sm_out, mask=row_mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Nagi-ovo/diy/blob/d7c119aa762b9103109d29abaebee345246fe5d7/OpenAI-Triton/softmax.py" }, { "uuid": "735e0114-467d-4933-bae8-e10228aac0d5", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_rcum_intra(s, z, ss, doo, s_s_h, s_s_t, s_s_d, T:\n tl.constexpr, S: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BS:\n tl.constexpr, NC: tl.constexpr):\n i_s, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_t, i_i = i_c // NC, i_c % NC\n o_i = tl.arange(0, BC)\n m_o = tl.full([BC, BC], 1.0, dtype=tl.float32)\n p_s = tl.make_block_ptr(s + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (i_t *\n BT + i_i * BC, i_s * BS), (BC, BS), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_s_h, (T * S,), (s_s_d,), ((i_t *\n BT + i_i * BC + BC - 1) * S + i_s * BS,), (BS,), (0,))\n p_doo = tl.make_block_ptr(doo + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (\n i_t * BT + i_i * BC, i_s * BS), (BC, BS), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_doo = tl.zeros([BC, BS], dtype=tl.float32)\n for i_j in range(i_i + 1, NC):\n p_z = tl.make_block_ptr(z + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (\n i_t * BT + i_j * BC, i_s * BS), (BC, BS), (1, 0))\n p_ss = tl.make_block_ptr(ss + i_bh * s_s_h, (T, S), (s_s_t, s_s_d),\n (i_t * BT + i_j * BC, i_s * BS), (BC, BS), (1, 0))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_ss = tl.load(p_ss, boundary_check=(0, 1))\n b_doo += b_ss * tl.exp(b_zn[None, :] - b_z)\n b_doo = tl.exp(b_s - b_zn[None, :]) * tl.dot(m_o.to(b_s.dtype), b_doo.\n to(b_s.dtype), allow_tf32=False)\n for j in range(0, BC):\n p_z = tl.make_block_ptr(z + i_bh * s_s_h, (T * S,), (1,), ((i_t *\n BT + i_i * BC + j) * S + i_s * BS,), (BS,), (0,))\n p_ss = tl.make_block_ptr(ss + i_bh * s_s_h, (T * S,), (1,), ((i_t *\n BT + i_i * BC + j) * S + i_s * BS,), (BS,), (0,))\n b_z = tl.load(p_z, boundary_check=(0,))\n b_ss = tl.load(p_ss, boundary_check=(0,))\n m_i = o_i[:, None] <= j\n b_doo += tl.where(m_i, tl.exp(b_s - b_z[None, :]) * b_ss[None, :], 0.0)\n b_doo += tl.load(p_doo, boundary_check=(0, 1))\n tl.store(p_doo, b_doo.to(p_doo.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "e64784a5-f146-4390-946f-2befee210aea", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef triton_batched_dense_vec_jagged_2d_matmul(jagged_tensor_ptr, dense_ptr,\n jagged_offset, thread_block_col_size: tl.constexpr, dense_row_stride,\n jagged_value_row_stride, D, H: tl.constexpr, output_ptr) ->None:\n pid = tl.program_id(0)\n GRID_DIM_COL = (D + thread_block_col_size - 1) // thread_block_col_size\n output_row_idx = pid // GRID_DIM_COL\n jagged_offset_id = output_row_idx // H\n D_refer_idx = output_row_idx % H\n group_id = pid % GRID_DIM_COL\n offset = group_id * thread_block_col_size + tl.arange(0,\n thread_block_col_size)\n begin = tl.load(jagged_offset + jagged_offset_id)\n end = tl.load(jagged_offset + (jagged_offset_id + 1))\n dense_ptr += output_row_idx * dense_row_stride\n jagged_tensor_ptr += begin * jagged_value_row_stride + D_refer_idx * D\n output_ptr += D * output_row_idx\n num_row = tl.minimum(end - begin, dense_row_stride)\n acc = tl.zeros((thread_block_col_size,), dtype=tl.float32)\n mask = offset < D\n for i in range(num_row):\n val1 = tl.load(dense_ptr + i)\n val2 = tl.load(jagged_tensor_ptr + offset, mask=mask, other=0.0)\n result = val1 * val2\n acc += result\n jagged_tensor_ptr += jagged_value_row_stride\n tl.store(output_ptr + offset, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "fae6dfee-0856-48f2-8c09-198c2bf008d0", "file_name": "mse.py", "repo_name": "l1351868270/implicit_gemm.triton", "file_path": "triton_kernel/mse.py", "commit_hash": "64eb8548ccf4576883c928f6315be8b24680a455", "starcount": 0, "input": "@triton.jit\ndef _ld_mse_bwd_kernel(grad_ptr, input_ptr, target_ptr, grad_output,\n grad_row_stride, input_row_stride, target_row_stride, n_rows, n_cols,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n grad_ptrs = grad_ptr + pid * grad_row_stride + col_offsets\n input_ptrs = input_ptr + pid * input_row_stride + col_offsets\n target_ptrs = target_ptr + pid * target_row_stride + col_offsets\n input = tl.load(input_ptrs, mask=mask, other=0.0)\n target = tl.load(target_ptrs, mask=mask, other=0.0)\n grad_ = (input - target) * 2 * grad_output / (n_rows * n_cols)\n tl.store(grad_ptrs, grad_, mask=mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/l1351868270/implicit_gemm.triton/blob/64eb8548ccf4576883c928f6315be8b24680a455/triton_kernel/mse.py" }, { "uuid": "d2319479-4740-45ba-a17c-d0a3e92ef405", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef bwd_decay_global_cumsum(dq_inner, dq_inter, dk_inner, dk_inter, q, k, g,\n dg, s_k_h, BT: tl.constexpr, BK: tl.constexpr, K: tl.constexpr):\n i_k, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (i_c * BT + BT - 1\n ) * K\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (i_c * BT + BT - 1\n ) * K\n p_g = g + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (i_c * BT + BT - 1\n ) * K\n p_dg = dg + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (i_c * BT + BT - 1\n ) * K\n p_dq_inner = dq_inner + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (\n i_c * BT + BT - 1) * K\n p_dk_inner = dk_inner + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (\n i_c * BT + BT - 1) * K\n p_dq_inter = dq_inter + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (\n i_c * BT + BT - 1) * K\n p_dk_inter = dk_inter + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (\n i_c * BT + BT - 1) * K\n cum_grad_dg = tl.zeros([BK], dtype=tl.float32)\n mask = i_k * BK + tl.arange(0, BK) < K\n last_g = tl.zeros([BK], dtype=tl.float32)\n for j in range(BT - 1, -1, -1):\n _g = tl.load(p_g, mask=mask, other=0).to(tl.float32)\n if j == BT - 1:\n last_g = _g\n b_dq1 = tl.load(p_dq_inner, mask=mask, other=0)\n b_dq2 = tl.load(p_dq_inter, mask=mask, other=0)\n b_dq2 *= tl.exp(_g)\n b_dq = b_dq1 + b_dq2\n tl.store(p_dq_inter, b_dq, mask=mask)\n b_dk1 = tl.load(p_dk_inner, mask=mask, other=0)\n b_dk2 = tl.load(p_dk_inter, mask=mask, other=0)\n b_dk2 *= tl.exp(last_g - _g)\n b_dk = b_dk1 + b_dk2\n tl.store(p_dk_inter, b_dk, mask=mask)\n b_q = tl.load(p_q, mask=mask, other=0)\n b_k = tl.load(p_k, mask=mask, other=0)\n b_dg = b_dq * b_q - b_dk * b_k\n cum_grad_dg += b_dg\n tl.store(p_dg, cum_grad_dg.to(p_dg.dtype.element_ty), mask=mask)\n p_g -= K\n p_k -= K\n p_q -= K\n p_dq_inner -= K\n p_dk_inner -= K\n p_dq_inter -= K\n p_dk_inter -= K\n p_dg -= K\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/fused_chunk.py" }, { "uuid": "c043b3cc-fffa-49f1-90d0-c95423a99f18", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_NON_REDUCE_DIM': b,\n 'BLOCK_SIZE_REDUCE_DIM': b}, num_warps=w) for b, w in itertools.product\n ([2, 4, 8, 16], [2, 4, 8])], key=['M', 'N'])\n@triton.jit\ndef triton_sum_kernel_1D_result_buffer_then_sum(input_ptr, output_ptr, M, N,\n BLOCK_SIZE_NON_REDUCE_DIM: tl.constexpr, BLOCK_SIZE_REDUCE_DIM: tl.\n constexpr, dim: tl.constexpr):\n \"\"\"\n Add blocks of input to a buffer and sum the buffer using Triton\n \"\"\"\n pid = tl.program_id(axis=0)\n reduce_dim_len = M if dim == 0 else N\n non_reduce_dim_len = N if dim == 0 else M\n buffer = tl.zeros((BLOCK_SIZE_REDUCE_DIM, BLOCK_SIZE_NON_REDUCE_DIM),\n dtype=tl.float32)\n block_start_non_reduce_dim = pid * BLOCK_SIZE_NON_REDUCE_DIM\n offsets_non_reduce_dim = block_start_non_reduce_dim + tl.arange(0,\n BLOCK_SIZE_NON_REDUCE_DIM)\n mask_non_reduce_dim = offsets_non_reduce_dim < non_reduce_dim_len\n for block_start_reduce_dim in range(0, reduce_dim_len,\n BLOCK_SIZE_REDUCE_DIM):\n offsets_reduce_dim = block_start_reduce_dim + tl.arange(0,\n BLOCK_SIZE_REDUCE_DIM)\n mask_reduce_dim = offsets_reduce_dim < reduce_dim_len\n idxs, mask = None, None\n if dim == 0:\n idxs = offsets_reduce_dim[:, None\n ] * non_reduce_dim_len + offsets_non_reduce_dim\n mask = mask_reduce_dim[:, None] & mask_non_reduce_dim\n elif dim == 1:\n idxs = offsets_non_reduce_dim[:, None\n ] * reduce_dim_len + offsets_reduce_dim\n mask = mask_non_reduce_dim[:, None] & mask_reduce_dim\n buffer += tl.load(input_ptr + idxs, mask=mask, other=mask)\n buffer_sum = tl.sum(buffer, axis=dim)\n buffer_view = buffer_sum.reshape((BLOCK_SIZE_NON_REDUCE_DIM,))\n tl.store(output_ptr + offsets_non_reduce_dim, buffer_view, mask=\n mask_non_reduce_dim)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/sum/kernels.py" }, { "uuid": "1204a122-b1ff-4519-8d58-a59f218f6150", "file_name": "batched_matmul.py", "repo_name": "MichaelWei7/torch", "file_path": "_inductor/triton_ops/batched_matmul.py", "commit_hash": "4bfe6988308edc9544ddae94bfdcf83a4326b04a", "starcount": 0, "input": "@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.autotune(configs=[triton.Config({'BLOCK_M': 128, 'BLOCK_N': 256,\n 'BLOCK_K': 32, 'SPLIT_K': 1}, num_stages=3, num_warps=8), triton.Config\n ({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K': 32, 'SPLIT_K': 1},\n num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 256, 'BLOCK_N': \n 64, 'BLOCK_K': 32, 'SPLIT_K': 1}, num_stages=4, num_warps=4), triton.\n Config({'BLOCK_M': 64, 'BLOCK_N': 256, 'BLOCK_K': 32, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 128, 'BLOCK_K': 32, 'SPLIT_K': 1}, num_stages=4, num_warps=4), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'BLOCK_K': 32, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': \n 128, 'BLOCK_K': 32, 'SPLIT_K': 1}, num_stages=4, num_warps=4), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 32, 'BLOCK_K': 32, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': 32,\n 'BLOCK_K': 32, 'SPLIT_K': 1}, num_stages=5, num_warps=2), triton.Config\n ({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 256, 'BLOCK_N': \n 128, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_M': 256, 'BLOCK_N': 64, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': \n 256, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=2, num_warps=4), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=2, num_warps=4), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 256, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=1, num_warps=8), triton.\n Config({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=1, num_warps=8), triton.Config({'BLOCK_M': 256, 'BLOCK_N': \n 64, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=1, num_warps=4), triton.\n Config({'BLOCK_M': 64, 'BLOCK_N': 256, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 128, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=1, num_warps=4), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': \n 128, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=4, num_warps=4), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 32, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': 32,\n 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=5, num_warps=2), triton.Config\n ({'BLOCK_M': 128, 'BLOCK_N': 64, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': \n 128, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=1, num_warps=4), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 32, 'BLOCK_K': 64, 'SPLIT_K': 1},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': 32,\n 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=1, num_warps=2)], key=['M',\n 'N', 'K'])\n@triton.jit\ndef _kernel(A, B, C, M, N, K, stride_am, stride_ak, stride_bk, stride_bn,\n stride_cm, stride_cn, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,\n BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl.constexpr,\n EVEN_K: tl.constexpr, ACC_TYPE: tl.constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n bid = tl.program_id(2)\n grid_m = (M + BLOCK_M - 1) // BLOCK_M\n grid_n = (N + BLOCK_N - 1) // BLOCK_N\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n A += bid * M * K\n B += bid * K * N\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=ACC_TYPE)\n for k in range(K, 0, -BLOCK_K * SPLIT_K):\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n a = tl.load(A, mask=rk[None, :] < k, other=0.0)\n b = tl.load(B, mask=rk[:, None] < k, other=0.0)\n acc += tl.dot(a, b)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n acc = acc.to(C.dtype.element_ty)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n C += bid * M * N\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if SPLIT_K == 1:\n tl.store(C, acc, mask=mask)\n else:\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "int32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/MichaelWei7/torch/blob/4bfe6988308edc9544ddae94bfdcf83a4326b04a/_inductor/triton_ops/batched_matmul.py" }, { "uuid": "b5fecd23-5b89-4b3c-8fad-037f53bf7408", "file_name": "prefix_sums.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/prefix_sums.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef scan_kernel(x_ptr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, AXIS: tl.constexpr):\n range_m = tl.arange(0, BLOCK_SIZE_M)\n range_n = tl.arange(0, BLOCK_SIZE_N)\n x = tl.load(x_ptr + range_m[:, None] * BLOCK_SIZE_N + range_n[None, :])\n x = tl.cumsum(x, axis=AXIS)\n tl.store(x_ptr + range_m[:, None] * BLOCK_SIZE_N + range_n[None, :], x)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/prefix_sums.py" }, { "uuid": "3a506554-8ef0-4725-a568-9de1c8c01198", "file_name": "layer_norm_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/layer_norm_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef layer_norm_forward_kernel(input_pointer, weight_pointer, bias_pointer,\n mean_pointer, inv_std_pointer, output_pointer, batch_dim, feat_dim,\n input_batch_stride, input_feat_stride, output_batch_stride,\n output_feat_stride, eps, scale_by_weight: tl.constexpr, add_bias: tl.\n constexpr, save_stats: tl.constexpr, BLOCK_SIZE_BATCH: tl.constexpr,\n BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Layer-normalizes the input.\n\n Args:\n input_pointer: Pointer to the input to layer-normalize.\n The input must be of shape [batch_dim, feat_dim].\n weight_pointer: Pointer to optional weights for affine transform.\n The weights, if provided, must be of shape [feat_dim].\n bias_pointer: Pointer to an optional bias vector for affine transform.\n The bias vector, if provided, must be of shape [feat_dim].\n mean_pointer: Pointer to an optional container the input's mean\n is written to if save_stats is True.\n The container, if provided, must be of shape [batch_dim].\n inv_std_pointer: Pointer to an optional container the input's inverse\n standard deviation is written to if save_stats is True.\n The container, if provided, must be of shape [batch_dim].\n output_pointer: Pointer to a container the result is written to.\n The container must be of shape [batch_dim, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output container's batch dimension.\n output_feat_stride: Stride necessary to jump one element along the\n output container's feature dimension.\n eps: Epsilon added in the square root in the denominator\n to avoid division by zero.\n scale_by_weight: Flag for scaling the normalized output by weights.\n add_bias: Flag for adding a bias vector to the normalized output\n if scale_by_weight is True.\n save_stats: Flag for saving the mean and standard deviation.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n output_pointer += output_batch_stride * batch_offset[:, None\n ] + output_feat_stride * feat_offset[None, :]\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :]).to(tl.float32)\n mean = tl.sum(input, axis=1) / feat_dim\n diff = tl.where(feat_mask[None, :], input - mean[:, None], 0)\n inv_std = tl.rsqrt(tl.sum(diff * diff, axis=1) / feat_dim + eps)\n if save_stats:\n tl.store(mean_pointer + batch_offset, mean, mask=batch_mask)\n tl.store(inv_std_pointer + batch_offset, inv_std, mask=batch_mask)\n output = diff * inv_std[:, None]\n if scale_by_weight:\n weight = tl.load(weight_pointer + feat_offset, mask=feat_mask)\n output *= weight\n if add_bias:\n bias = tl.load(bias_pointer + feat_offset, mask=feat_mask)\n output += bias\n tl.store(output_pointer, output, mask=batch_mask[:, None] & feat_mask[\n None, :])\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/layer_norm_kernels.py" }, { "uuid": "77b783f4-944a-4989-ab38-630883cdbda5", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fwd_inner_chunk(q, k, g, A, s_k_h, s_k_t, s_k_d, scale, B: tl.constexpr,\n H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n p_g = tl.make_block_ptr(g + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0, 1)).to(tl.float32)\n mask = i_k * BK + tl.arange(0, BK) < K\n o_i = tl.arange(0, BT)\n p_q = q + i_bh * s_k_h + i_k * BK + i_t * BT * K + tl.arange(0, BK)\n p_gq = g + i_bh * s_k_h + i_k * BK + i_t * BT * K + tl.arange(0, BK)\n p_A = A + (i_bh + i_k * B * H) * (tl.cdiv(T, BT) * BT * BT\n ) + i_t * BT * BT + tl.arange(0, BT)\n for i in range(BT):\n _q = tl.load(p_q, mask=mask, other=0) * scale\n gq = tl.load(p_gq, mask=mask, other=0).to(tl.float32)\n s = _q[None, :] * b_k * tl.exp(gq[None, :] - b_g)\n score = tl.sum(s, axis=1)\n score = tl.where(o_i <= i, score, 0)\n tl.store(p_A, score.to(p_A.dtype.element_ty))\n p_q += K\n p_gq += K\n p_A += BT\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/fused_chunk.py" }, { "uuid": "034eebc4-faf8-4f0a-b847-5d898fd31da7", "file_name": "lstm_bw.py", "repo_name": "NX-AI/flashrnn", "file_path": "flashrnn/flashrnn/triton_fused/lstm_bw.py", "commit_hash": "3fca666a81c8740af4878d7bc5e2a51900e4fe14", "starcount": 0, "input": "@triton.jit\ndef triton_tanh(x):\n return (1.0 - tl.exp(-2.0 * x)) / (1.0 + tl.exp(-2.0 * x))\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT", "BSD" ], "github_url": "https://github.com/NX-AI/flashrnn/blob/3fca666a81c8740af4878d7bc5e2a51900e4fe14/flashrnn/flashrnn/triton_fused/lstm_bw.py" }, { "uuid": "33a2ed2a-c830-4a48-9359-fe4d01c30f36", "file_name": "causal_conv1d_varlen.py", "repo_name": "shaielc/MambaLinearCode", "file_path": "causal-conv1d/causal_conv1d/causal_conv1d_varlen.py", "commit_hash": "567fc4ae197064540c1a558bbb60c78f55b95fef", "starcount": 0, "input": "@triton.jit\ndef _causal_conv1d_varlen_states(X, CU_SEQLENS, STATES, state_len, dim,\n stride_x_seqlen, stride_x_dim, stride_states_batch,\n stride_states_seqlen, stride_states_dim, BLOCK_M: tl.constexpr, BLOCK_N:\n tl.constexpr):\n batch_idx = tl.program_id(2)\n STATES += batch_idx * stride_states_batch\n end_idx = tl.load(CU_SEQLENS + batch_idx + 1)\n start_idx = tl.maximum(tl.load(CU_SEQLENS + batch_idx), end_idx - state_len\n )\n rows = end_idx - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(0, BLOCK_M)\n cols = tl.program_id(0) * BLOCK_N + tl.arange(0, BLOCK_N)\n x = tl.load(X + rows[:, None] * stride_x_seqlen + cols[None, :] *\n stride_x_dim, mask=(rows[:, None] >= start_idx) & (cols[None, :] <\n dim), other=0)\n rows_states = state_len - (tl.program_id(1) + 1) * BLOCK_M + tl.arange(\n 0, BLOCK_M)\n tl.store(STATES + rows_states[:, None] * stride_states_seqlen + cols[\n None, :] * stride_states_dim, x, mask=(rows_states[:, None] >= 0) &\n (cols[None, :] < dim))\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "Apache" ], "github_url": "https://github.com/shaielc/MambaLinearCode/blob/567fc4ae197064540c1a558bbb60c78f55b95fef/causal-conv1d/causal_conv1d/causal_conv1d_varlen.py" }, { "uuid": "fc92abc9-d8fd-4398-8a22-d121aebc63d3", "file_name": "logcumsumexp.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/logcumsumexp.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BT': 16}, num_warps=2), triton.\n Config({'BT': 16}, num_warps=4), triton.Config({'BT': 16}, num_warps=8),\n triton.Config({'BT': 32}, num_warps=2), triton.Config({'BT': 32},\n num_warps=4), triton.Config({'BT': 32}, num_warps=8), triton.Config({\n 'BT': 64}, num_warps=2), triton.Config({'BT': 64}, num_warps=4), triton\n .Config({'BT': 64}, num_warps=8)], key=['S'])\n@triton.jit\ndef logcumsumexp_fwd_kernel(s, z, s_s_h, s_s_t, s_s_d, T: tl.constexpr, S:\n tl.constexpr, BT: tl.constexpr):\n i_bh = tl.program_id(0)\n o_i = tl.arange(0, BT)\n m_s = tl.where(o_i[:, None] >= o_i[None, :], 1.0, 0.0)\n b_mp = tl.full([S], float('-inf'), dtype=tl.float32)\n b_zp = tl.zeros([S], dtype=tl.float32)\n for i_t in range(tl.cdiv(T, BT)):\n p_s = tl.make_block_ptr(s + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (\n i_t * BT, 0), (BT, S), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (\n i_t * BT, 0), (BT, S), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_mc = tl.max(b_s, 0)\n if i_t > 0:\n b_mc = tl.maximum(b_mp, b_mc)\n b_zp = b_zp * tl.exp(b_mp - b_mc)\n b_s = tl.exp(b_s - b_mc)\n b_z = tl.dot(m_s, b_s, allow_tf32=False) + b_zp\n b_zc = tl.max(b_z, 0)\n b_mp = b_mc\n b_zp = b_zc\n b_z = tl.log(tl.where(b_z != 0, b_z, 1e-20)) + b_mc\n tl.store(p_z, b_z.to(p_z.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/logcumsumexp.py" }, { "uuid": "bea526aa-fd9a-4f16-8749-f490743aecce", "file_name": "attn_qk_int8_per_block_h64.py", "repo_name": "rodjjo/editorium", "file_path": "editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_h64.py", "commit_hash": "7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q, q_scale, K_ptrs, K_scale_ptr, V_ptrs,\n start_m, BLOCK_M: tl.constexpr, HEAD_DIM: tl.constexpr, BLOCK_N: tl.\n constexpr, STAGE: tl.constexpr, offs_m: tl.constexpr, offs_n: tl.\n constexpr, N_CTX: tl.constexpr):\n lo, hi = 0, N_CTX\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k_mask = offs_n[None, :] < N_CTX - start_n\n k = tl.load(K_ptrs, mask=k_mask)\n k_scale = tl.load(K_scale_ptr)\n qk = tl.dot(q, k).to(tl.float32) * q_scale * k_scale\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n qk = qk - m_ij[:, None]\n p = tl.math.exp2(qk)\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp2(m_i - m_ij)\n l_i = l_i * alpha + l_ij\n acc = acc * alpha[:, None]\n v = tl.load(V_ptrs, mask=offs_n[:, None] < N_CTX - start_n)\n p = p.to(tl.float16)\n acc += tl.dot(p, v, out_dtype=tl.float16)\n m_i = m_ij\n K_ptrs += BLOCK_N * HEAD_DIM\n K_scale_ptr += 1\n V_ptrs += BLOCK_N * HEAD_DIM\n return acc, l_i\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/rodjjo/editorium/blob/7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694/editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_h64.py" }, { "uuid": "eef6506d-e789-4c85-8695-427fcf745d3f", "file_name": "atomic.py", "repo_name": "daemyung/practice-triton", "file_path": "atomic.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@triton.jit\ndef atomic_kernel(x_ptr, increment):\n tl.atomic_add(x_ptr, increment)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "uint8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/atomic.py" }, { "uuid": "c87e2484-0947-436e-9ac0-d1273f24b0a3", "file_name": "rmsnorm.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/rmsnorm.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_rmsnorm_backward(dY_ptr, dY_row_stride, X_ptr, X_row_stride,\n X_dtype: tl.constexpr, W_ptr, RSTD_ptr, RSTD_row_stride, dW_ptr,\n dW_row_stride, n_rows, n_cols, offset, rows_per_program: tl.constexpr,\n BLOCK_SIZE: tl.constexpr):\n row_block_id = tl.program_id(0)\n row_start = row_block_id * rows_per_program\n row_end = min((row_block_id + 1) * rows_per_program, n_rows)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n dW_row = tl.zeros((BLOCK_SIZE,), dtype=tl.float32)\n dY_ptr += row_start * dY_row_stride\n X_ptr += row_start * X_row_stride\n RSTD_ptr += row_start\n W_row = tl.load(W_ptr + col_offsets, mask=mask, other=0.0)\n W_row = W_row + offset\n for _ in range(row_start, row_end):\n dY_row = tl.load(dY_ptr + col_offsets, mask=mask, other=0.0)\n X_row = tl.load(X_ptr + col_offsets, mask=mask, other=0.0)\n rstd_row = tl.load(RSTD_ptr)\n X_row = X_row.to(tl.float32)\n m = (dY_row * W_row).to(tl.float32)\n dX_row = rstd_row * m\n dX_row += rstd_row * (-(1 / n_cols) * rstd_row * rstd_row * tl.sum(\n m * X_row, axis=0) * X_row)\n dW_row += dY_row * (X_row * rstd_row).to(X_dtype)\n tl.store(dY_ptr + col_offsets, dX_row.to(X_dtype), mask=mask)\n dY_ptr += dY_row_stride\n X_ptr += X_row_stride\n RSTD_ptr += RSTD_row_stride\n tl.store(dW_ptr + row_block_id * dW_row_stride + col_offsets, dW_row,\n mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/rmsnorm.py" }, { "uuid": "61fe3795-54b0-4858-973e-4e780e63884b", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/based/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_based_bwd_kernel(q, k, v, do, dz, dq, dk, dv, s_k_h, s_k_t,\n s_k_d, s_v_h, s_v_t, s_v_d, scale, B: tl.constexpr, H: tl.constexpr, T:\n tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr, BV: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_h_1o = tl.zeros([BV, BK], dtype=tl.float32)\n b_h_2o = tl.zeros([BV, BK * BK], dtype=tl.float32)\n k_1o = tl.zeros([1, BK], dtype=tl.float32)\n k_2o = tl.zeros([1, BK * BK], dtype=tl.float32)\n for i in range(0, tl.cdiv(T, BT)):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i * BT, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (\n i_v * BV, i * BT), (BV, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dq = tl.make_block_ptr(dq + (i_bh + i_v * B * H) * s_k_h, (T, K),\n (s_k_t, s_k_d), (i * BT, i_k * BK), (BT, BK), (1, 0))\n p_dz = dz + i_bh * T + tl.arange(0, BT) + i * BT\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_dz = tl.load(p_dz, mask=tl.arange(0, BT) + i * BT < T)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_dq += tl.dot(b_do, b_h_1o.to(b_do.dtype), allow_tf32=False)\n if i_v == 0:\n b_dq += b_dz[:, None] * k_1o\n b_dq_2o = tl.dot(b_do, b_h_2o.to(b_do.dtype), allow_tf32=False) * 0.5\n if i_v == 0:\n b_dq_2o += b_dz[:, None] * k_2o * 0.5\n b_dq_2o = tl.reshape(b_dq_2o, [BT, BK, BK])\n b_dq += tl.sum(b_dq_2o * b_q[:, :, None], axis=1)\n b_dq += tl.sum(b_dq_2o * b_q[:, None, :], axis=2)\n b_dq *= scale\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[:, None]\n b_ds = tl.where(m_s, b_ds, 0) * scale\n b_s = tl.dot(b_q, tl.trans(b_k), allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n b_dq += tl.dot((b_ds * (1 + b_s)).to(b_q.dtype), b_k, allow_tf32=False)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n b_k_2o = b_k[:, :, None] * b_k[:, None, :]\n b_k_2o = tl.reshape(b_k_2o, [BT, BK * BK]).to(b_k.dtype)\n b_h_2o = b_h_2o + tl.dot(b_v, b_k_2o.to(b_v.dtype), allow_tf32=False)\n b_h_1o = b_h_1o + tl.dot(b_v, b_k, allow_tf32=False)\n if i_v == 0:\n k_1o += tl.sum(b_k, axis=0)[None, :]\n k_2o += tl.sum(b_k_2o, axis=0)[None, :]\n tl.debug_barrier()\n b_h_1o = None\n b_h_2o = None\n b_dh_1o = tl.zeros([BK, BV], dtype=tl.float32)\n b_dh_2o = tl.zeros([BK * BK, BV], dtype=tl.float32)\n b_dh_0o = tl.zeros([BV], dtype=tl.float32)\n m_s = tl.arange(0, BT)[:, None] <= tl.arange(0, BT)[None, :]\n dq_1o = tl.zeros([1, BK], dtype=tl.float32)\n dq_2o = tl.zeros([BK * BK, 1], dtype=tl.float32)\n for i in range(tl.cdiv(T, BT) * BT - BT, -BT, -BT):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i, i_v * BV), (BT, BV), (1, 0))\n p_dk = tl.make_block_ptr(dk + (i_bh + i_v * B * H) * s_k_h, (T, K),\n (s_k_t, s_k_d), (i, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + i_k * B * H) * s_v_h, (T, V),\n (s_v_t, s_v_d), (i, i_v * BV), (BT, BV), (1, 0))\n p_dz = dz + i_bh * T + tl.arange(0, BT) + i\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_dv = tl.zeros([BT, BV], dtype=tl.float32)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_dz = tl.load(p_dz, mask=tl.arange(0, BT) + i < T)\n b_q = (b_q * scale).to(b_k.dtype)\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[None, :]\n b_ds = tl.where(m_s, b_ds, 0)\n b_s = tl.dot(b_k, b_q, allow_tf32=False)\n b_s2 = 1 + b_s + 0.5 * b_s * b_s\n b_s = tl.where(m_s, b_s, 0)\n b_s2 = tl.where(m_s, b_s2, 0)\n b_ds *= 1 + b_s\n b_dk += tl.dot(b_ds.to(b_k.dtype), tl.trans(b_q), allow_tf32=False)\n b_dv += tl.dot(b_s2.to(b_do.dtype), b_do, allow_tf32=False)\n b_k_2o = b_k[:, :, None] * b_k[:, None, :]\n b_k_2o = tl.reshape(b_k_2o, [BT, BK * BK]).to(b_k.dtype)\n b_dv += tl.dot(b_k, b_dh_1o.to(b_k.dtype), allow_tf32=False)\n b_dv += tl.dot(b_k_2o, b_dh_2o.to(b_k.dtype), allow_tf32=False)\n b_dv += b_dh_0o\n b_dk += tl.dot(b_v, tl.trans(b_dh_1o).to(b_k.dtype), allow_tf32=False)\n if i_v == 0:\n b_dk += dq_1o\n b_dk_2o = tl.dot(b_dh_2o.to(b_k.dtype), tl.trans(b_v), allow_tf32=False\n )\n if i_v == 0:\n b_dk_2o += dq_2o\n b_dk_2o = tl.reshape(b_dk_2o, [BK, BK, BT])\n b_k_fp32 = tl.trans(b_k.to(tl.float32))\n b_dk2 = tl.sum(b_dk_2o * b_k_fp32[:, None, :], axis=0)\n b_dk2 += tl.sum(b_dk_2o * b_k_fp32[None, :, :], axis=1)\n b_dk += tl.trans(b_dk2)\n b_dh_0o += tl.sum(b_do, axis=0)\n b_dh_1o = b_dh_1o + tl.dot(b_q, b_do, allow_tf32=False)\n b_q_2o = b_q[None, :, :] * b_q[:, None, :]\n b_q_2o = tl.reshape(b_q_2o, [BK * BK, BT]).to(b_k.dtype)\n b_dh_2o = b_dh_2o + tl.dot(b_q_2o, b_do, allow_tf32=False) * 0.5\n if i_v == 0:\n dq_1o += tl.sum(b_dz[None, :] * b_q, axis=1)[None, :]\n dq_2o += (tl.sum(b_dz[None, :] * b_q_2o, axis=1) * 0.5)[:, None]\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/based/fused_chunk.py" }, { "uuid": "f8d8edc6-bf70-4ed3-b262-9a5b4a3846e7", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_simple_gla_bwd_kernel_dkv(i_bh, i_t, i_k, i_v, i_kv, q, k, v,\n g, do, dk, dv, dg, s_k_h, s_k_t, s_v_h, s_v_t, scale, B: tl.constexpr,\n H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT:\n tl.constexpr, BS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_gk = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,), (0,)\n )\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_dv = tl.zeros([BT, BV], dtype=tl.float32)\n b_gk = tl.load(p_gk, boundary_check=(0,))\n NTS = tl.cdiv(T, BS)\n b_kg = (b_k * tl.exp(tl.load(g + i_bh * T + min(i_t * BT + BT, T) - 1) -\n b_gk)[:, None]).to(b_k.dtype)\n for i_s in range(NTS * BS - BS, (i_t + 1) * BT - BS, -BS):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_s,\n i_k * BK), (BS, BK), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, 1), (\n i_s, i_v * BV), (BS, BV), (1, 0))\n p_gq = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_s,), (BS,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_gq = tl.load(p_gq, boundary_check=(0,))\n b_gp = tl.load(g + i_bh * T + min(i_s + BS, T) - 1)\n b_gn = tl.load(g + i_bh * T + i_s - 1) if i_s % BT > 0 else 0.0\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_gq - b_gn)[:, None]).to(b_do.dtype)\n b_dk *= tl.exp(b_gp - b_gn)\n b_dv *= tl.exp(b_gp - b_gn)\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False)\n b_s = tl.dot(b_kg, tl.trans(b_q), allow_tf32=False)\n b_dk += tl.dot(b_ds.to(b_q.dtype), b_q, allow_tf32=False)\n b_dv += tl.dot(b_s.to(b_do.dtype), b_do, allow_tf32=False)\n b_dk *= tl.exp(tl.load(g + i_bh * T + min(T, i_t * BT + BT) - 1) - b_gk)[\n :, None] * scale\n b_dv *= scale\n tl.debug_barrier()\n o_q = i_t * BT + tl.arange(0, BS)\n o_k = i_t * BT + tl.arange(0, BT)\n for i_s in range(i_t * BT, min((i_t + 1) * BT, T), BS):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_s,\n i_k * BK), (BS, BK), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, 1), (\n i_s, i_v * BV), (BS, BV), (1, 0))\n p_gq = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_s,), (BS,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_gq = tl.load(p_gq, boundary_check=(0,))\n m_s = o_k[:, None] <= o_q[None, :]\n d_s = tl.where(m_s, tl.exp(-b_gk[:, None] + b_gq[None, :]), 0) * scale\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False) * d_s\n b_s = tl.dot(b_k, tl.trans(b_q), allow_tf32=False) * d_s\n b_dk += tl.dot(b_ds.to(b_q.dtype), b_q, allow_tf32=False)\n b_dv += tl.dot(b_s.to(b_q.dtype), b_do, allow_tf32=False)\n o_q += BS\n p_dk = tl.make_block_ptr(dk + (i_v * B * H + i_bh) * s_k_h, (T, K), (\n s_k_t, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * B * H + i_bh) * s_v_h, (T, V), (\n s_v_t, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dg = tl.make_block_ptr(dg + (i_kv * B * H + i_bh) * T, (T,), (1,), (\n i_t * BT,), (BT,), (0,))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n b_dg = tl.load(p_dg, boundary_check=(0,))\n b_dg -= tl.sum(b_dk * b_k, 1)\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/parallel.py" }, { "uuid": "eb17d738-56f7-4b95-9035-3e3775974f90", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_retention_bwd_kernel(q, k, v, do, dq, dk, dv, h0, scale, B:\n tl.constexpr, H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, CHECK: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_h = i_bh % H\n o_i = tl.arange(0, BT)\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n d_q, d_k = tl.math.exp2((o_i + 1) * b_b) * scale, tl.math.exp2((BT -\n o_i - 1) * b_b)\n d_b = tl.math.exp2(BT * b_b)\n m_s = o_i[:, None] >= o_i[None, :]\n d_s = tl.where(m_s, tl.math.exp2((o_i[:, None] - o_i[None, :]) * b_b), 0\n ) * scale\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(h0 + i_bh * K * V, (V, K), (1, V), (i_v *\n BV, i_k * BK), (BV, BK), (0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n for i in range(0, tl.cdiv(T, BT)):\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i * BT, \n i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (V, T), (1, V), (i_v * BV,\n i * BT), (BV, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_dq = tl.make_block_ptr(dq + (i_bh + i_v * B * H) * T * K, (T, K),\n (K, 1), (i * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dd = (b_do * d_q[:, None]).to(b_do.dtype)\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n b_ds = (b_ds * d_s).to(b_k.dtype)\n b_dq = tl.dot(b_ds, b_k, allow_tf32=False)\n if CHECK and i == 0:\n b_dq += tl.dot(b_dd, b_h.to(b_k.dtype), allow_tf32=False)\n b_h = d_b * b_h + tl.dot((b_v * d_k[None, :]).to(b_k.dtype),\n b_k, allow_tf32=False)\n else:\n b_dq += tl.dot(b_dd, b_h.to(b_k.dtype), allow_tf32=False)\n b_h = d_b * b_h + tl.dot((b_v * d_k[None, :]).to(b_k.dtype),\n b_k, allow_tf32=False)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n b_h = None\n tl.debug_barrier()\n d_s = tl.trans(d_s)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n for i in range(1, tl.cdiv(T, BT) + 1):\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k * BK,\n T - i * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (T - i *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (T - i *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (T - i *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_dk = tl.make_block_ptr(dk + (i_bh + i_v * B * H) * T * K, (T, K),\n (K, 1), (T - i * BT, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + i_k * B * H) * T * V, (T, V),\n (V, 1), (T - i * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dd = (b_do * d_q[:, None]).to(b_do.dtype)\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False)\n b_ds = (b_ds * d_s).to(b_k.dtype)\n b_s = tl.dot(b_k, b_q, allow_tf32=False) * d_s\n b_dk = tl.dot(b_ds, tl.trans(b_q), allow_tf32=False)\n b_dv = tl.dot(b_s.to(b_q.dtype), b_do, allow_tf32=False)\n if CHECK and i == 1:\n b_dk += tl.dot(b_v, tl.trans(b_dh).to(b_v.dtype), allow_tf32=False\n ) * d_k[:, None]\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False) * d_k[\n :, None]\n b_dh = d_b * b_dh + tl.dot(b_q, b_dd, allow_tf32=False)\n else:\n b_dk += tl.dot(b_v, tl.trans(b_dh).to(b_v.dtype), allow_tf32=False\n ) * d_k[:, None]\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False) * d_k[\n :, None]\n b_dh = d_b * b_dh + tl.dot(b_q, b_dd, allow_tf32=False)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/fused_chunk.py" }, { "uuid": "fdc8c514-97dc-4a5b-b5ee-8cb84a245397", "file_name": "lightseq_async_attn.py", "repo_name": "EvolvingLMMs-Lab/LongVA", "file_path": "easy_context/dist_flash_attn/lightseq_async_attn.py", "commit_hash": "76b7c33946936361eeb5a18b2c9fcc5fe63e9434", "starcount": 0, "input": "@triton.jit\ndef _rescale_kernel(peer_m, m, peer_l, l, peer_o, o, L, stride_oz,\n stride_oh, stride_om, stride_on, Z, H, N_CTX, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, LAST_STEP: tl.constexpr\n ):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n o_offset = off_hz * stride_oh\n peer_o_block_ptr = tl.make_block_ptr(base=peer_o + o_offset, shape=(\n N_CTX, BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(\n start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(\n 1, 0))\n o_block_ptr = tl.make_block_ptr(base=o + o_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n peer_m_ptrs = peer_m + off_hz * N_CTX + offs_m\n m_ptrs = m + off_hz * N_CTX + offs_m\n peer_l_ptrs = peer_l + off_hz * N_CTX + offs_m\n l_ptrs = l + off_hz * N_CTX + offs_m\n peer_m_i = tl.load(peer_m_ptrs)\n peer_m_i = peer_m_i.to(tl.float32)\n m_i = tl.load(m_ptrs)\n m_i = m_i.to(tl.float32)\n peer_l_i = tl.load(peer_l_ptrs)\n peer_l_i = peer_l_i.to(tl.float32)\n l_i = tl.load(l_ptrs)\n l_i = l_i.to(tl.float32)\n peer_acc = tl.load(peer_o_block_ptr)\n peer_acc = peer_acc.to(tl.float32)\n acc = tl.load(o_block_ptr)\n acc = acc.to(tl.float32)\n lo = 0\n hi = N_CTX\n m_i_sync = tl.maximum(m_i, peer_m_i)\n alpha = tl.math.exp2(m_i - m_i_sync)\n peer_alpha = tl.math.exp2(peer_m_i - m_i_sync)\n acc_scale = l_i * 0 + alpha\n peer_acc_scale = peer_l_i * 0 + peer_alpha\n acc *= acc_scale[:, None]\n peer_acc *= peer_acc_scale[:, None]\n acc += peer_acc\n l_i = l_i * acc_scale + peer_l_i * peer_acc_scale\n tl.store(m_ptrs, m_i_sync)\n tl.store(l_ptrs, l_i)\n if LAST_STEP:\n acc = acc / l_i[:, None]\n L_ptrs = L + off_hz * N_CTX + offs_m\n tl.store(L_ptrs, m_i_sync / 1.44269504 + tl.math.log(l_i))\n tl.store(o_block_ptr, acc.to(tl.bfloat16))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/EvolvingLMMs-Lab/LongVA/blob/76b7c33946936361eeb5a18b2c9fcc5fe63e9434/easy_context/dist_flash_attn/lightseq_async_attn.py" }, { "uuid": "04b500e9-43c3-4a8d-8bdf-3fa2cecce9bc", "file_name": "prefix_prefill.py", "repo_name": "IBM/vllm", "file_path": "vllm/attention/ops/prefix_prefill.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel(Q, K, V, K_cache, V_cache, B_Loc, sm_scale, k_scale,\n v_scale, B_Start_Loc, B_Seqlen, B_Ctxlen, block_size, x, Out,\n stride_b_loc_b, stride_b_loc_s, stride_qbs, stride_qh, stride_qd,\n stride_kbs, stride_kh, stride_kd, stride_vbs, stride_vh, stride_vd,\n stride_obs, stride_oh, stride_od, stride_k_cache_bs, stride_k_cache_h,\n stride_k_cache_d, stride_k_cache_bl, stride_k_cache_x,\n stride_v_cache_bs, stride_v_cache_h, stride_v_cache_d,\n stride_v_cache_bl, num_queries_per_kv: int, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_DMODEL_PADDED: tl.constexpr, BLOCK_N:\n tl.constexpr, SLIDING_WINDOW: tl.constexpr):\n cur_batch = tl.program_id(0)\n cur_head = tl.program_id(1)\n start_m = tl.program_id(2)\n cur_kv_head = cur_head // num_queries_per_kv\n cur_batch_ctx_len = tl.load(B_Ctxlen + cur_batch)\n cur_batch_seq_len = tl.load(B_Seqlen + cur_batch)\n cur_batch_in_all_start_index = tl.load(B_Start_Loc + cur_batch)\n cur_batch_query_len = cur_batch_seq_len - cur_batch_ctx_len\n block_start_loc = BLOCK_M * start_m\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL_PADDED)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n off_q = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_qbs + cur_head * stride_qh + offs_d[None, :] * stride_qd\n dim_mask = tl.where(tl.arange(0, BLOCK_DMODEL_PADDED) < BLOCK_DMODEL, 1, 0\n ).to(tl.int1)\n q = tl.load(Q + off_q, mask=dim_mask[None, :] & (offs_m[:, None] <\n cur_batch_query_len), other=0.0)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL_PADDED], dtype=tl.float32)\n for start_n in range(0, cur_batch_ctx_len, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n bn = tl.load(B_Loc + cur_batch * stride_b_loc_b + (start_n + offs_n\n ) // block_size * stride_b_loc_s, mask=start_n + offs_n <\n cur_batch_ctx_len, other=0)\n off_k = bn[None, :\n ] * stride_k_cache_bs + cur_kv_head * stride_k_cache_h + offs_d[\n :, None] // x * stride_k_cache_d + (start_n + offs_n[None, :]\n ) % block_size * stride_k_cache_bl + offs_d[:, None\n ] % x * stride_k_cache_x\n off_v = bn[:, None\n ] * stride_v_cache_bs + cur_kv_head * stride_v_cache_h + offs_d[\n None, :] * stride_v_cache_d + (start_n + offs_n[:, None]\n ) % block_size * stride_v_cache_bl\n k_load = tl.load(K_cache + off_k, mask=dim_mask[:, None] & (start_n +\n offs_n[None, :] < cur_batch_ctx_len), other=0.0)\n if k_load.dtype.is_fp8():\n k = (k_load.to(tl.float32) * k_scale).to(q.dtype)\n else:\n k = k_load\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n qk = tl.where(start_n + offs_n[None, :] < cur_batch_ctx_len, qk,\n float('-inf'))\n qk *= sm_scale\n if SLIDING_WINDOW > 0:\n qk = tl.where(cur_batch_ctx_len + offs_m[:, None] - (start_n +\n offs_n[None, :]) < SLIDING_WINDOW, qk, -10000)\n m_ij = tl.max(qk, 1)\n p = tl.exp(qk - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n alpha = tl.exp(m_i - m_i_new)\n beta = tl.exp(m_ij - m_i_new)\n l_i_new = alpha * l_i + beta * l_ij\n p_scale = beta / l_i_new\n p = p * p_scale[:, None]\n acc_scale = l_i / l_i_new * alpha\n acc = acc * acc_scale[:, None]\n v_load = tl.load(V_cache + off_v, mask=dim_mask[None, :] & (start_n +\n offs_n[:, None] < cur_batch_ctx_len), other=0.0)\n if v_load.dtype.is_fp8():\n v = (v_load.to(tl.float32) * v_scale).to(q.dtype)\n else:\n v = v_load\n p = p.to(v.dtype)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n off_k = offs_n[None, :] * stride_kbs + cur_kv_head * stride_kh + offs_d[\n :, None] * stride_kd\n off_v = offs_n[:, None] * stride_vbs + cur_kv_head * stride_vh + offs_d[\n None, :] * stride_vd\n k_ptrs = K + off_k\n v_ptrs = V + off_v\n block_mask = tl.where(block_start_loc < cur_batch_query_len, 1, 0)\n for start_n in range(0, block_mask * (start_m + 1) * BLOCK_M, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(k_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_kbs, mask=dim_mask[:, None] & (start_n + offs_n[None, :] <\n cur_batch_query_len), other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n qk *= sm_scale\n qk = tl.where(offs_m[:, None] >= start_n + offs_n[None, :], qk,\n float('-inf'))\n if SLIDING_WINDOW > 0:\n qk = tl.where(offs_m[:, None] - (start_n + offs_n[None, :]) <\n SLIDING_WINDOW, qk, -10000)\n m_ij = tl.max(qk, 1)\n p = tl.exp(qk - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n alpha = tl.exp(m_i - m_i_new)\n beta = tl.exp(m_ij - m_i_new)\n l_i_new = alpha * l_i + beta * l_ij\n p_scale = beta / l_i_new\n p = p * p_scale[:, None]\n acc_scale = l_i / l_i_new * alpha\n acc = acc * acc_scale[:, None]\n v = tl.load(v_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_vbs, mask=dim_mask[None, :] & (start_n + offs_n[:, None] <\n cur_batch_query_len), other=0.0)\n p = p.to(v.dtype)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n off_o = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_obs + cur_head * stride_oh + offs_d[None, :] * stride_od\n out_ptrs = Out + off_o\n tl.store(out_ptrs, acc, mask=dim_mask[None, :] & (offs_m[:, None] <\n cur_batch_query_len))\n return\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/attention/ops/prefix_prefill.py" }, { "uuid": "2f8b0d83-5616-4c9c-832e-4472431e9e84", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _inner_paged_attn_unroll_0_kernel(q, k_cache, v_cache, stride_km,\n block_base_ptrs, base_offs_kv, alibi_slope, block_offs, seq_len, qkv,\n qk_max, exp_sum, BLOCK_SIZE: tl.constexpr, LO: tl.constexpr, HI: tl.\n constexpr):\n for block_idx in range(LO, HI, 1):\n offs_kv_0 = tl.load(block_base_ptrs + block_idx + 0\n ) * stride_km + base_offs_kv\n k_0 = tl.load(k_cache + offs_kv_0)\n v_0 = tl.load(v_cache + offs_kv_0)\n _qk_0 = tl.sum((q[None, :] * k_0).to(tl.float32), axis=1)\n if alibi_slope is not None:\n _qk_0 += alibi_slope * ((block_idx + 0) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_max = tl.maximum(tl.max(_qk_0, axis=0), qk_max)\n exp_tmp = tl.exp(_qk_0 - _qk_max)\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(exp_tmp, axis=0)\n qkv_sum_tmp = tl.exp(_qk_0[:, None] - _qk_max).to(v_cache.dtype.\n element_ty) * v_0\n qkv = (qkv * (exp_sum * tl.exp(qk_max - _qk_max)) + qkv_sum_tmp\n ) / _exp_sum\n qk_max = _qk_max\n exp_sum = _exp_sum\n return qkv, qk_max, exp_sum\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "5ae29aea-e9ab-4b04-990c-d208c7ac02ac", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.jit\ndef triton_sum_kernel_scalar_result(input_ptr, output_ptr, M, BLOCK_SIZE_M:\n tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE_M\n offsets = block_start + tl.arange(0, BLOCK_SIZE_M)\n mask = offsets < M\n x = tl.load(input_ptr + offsets, mask=mask, other=mask)\n output = tl.sum(x)\n output_offsets = tl.arange(0, 1)\n tl.store(output_ptr + output_offsets, output)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/sum/kernels.py" }, { "uuid": "09deca13-45a1-459d-85c5-acec7312d548", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2)], key=['BT'])\n@triton.jit\ndef save_intra_chunk_attn(A, A_local, T: tl.constexpr, BT: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n p_A = tl.make_block_ptr(A + i_bh * T * T, (T, T), (T, 1), (i_t * BT, \n i_t * BT), (BT, BT), (1, 0))\n p_A_local = tl.make_block_ptr(A_local + i_bh * T * BT, (T, BT), (BT, 1),\n (i_t * BT, 0), (BT, BT), (1, 0))\n b_A_local = tl.load(p_A_local, boundary_check=(0, 1))\n tl.store(p_A, b_A_local.to(p_A.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/parallel.py" }, { "uuid": "9c1a7f44-002d-4db7-b1da-ef6ca965c300", "file_name": "blocksparse_sum.py", "repo_name": "kimiasa/Experiments", "file_path": "src/models/attention/blocksparse_sum.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.heuristics({'num_warps': lambda *args, **meta: num_warps(args[3] *\n meta['BLOCK'])})\n@triton.heuristics({'TN': lambda *args, **meta: next_power_of_2(args[3] *\n meta['BLOCK'])})\n@triton.jit\ndef _forward(X, OUT, LUT, sizemax, stride_zx, stride_zout, stride_hout, **meta\n ):\n TN = meta['TN']\n BLOCK = meta['BLOCK']\n pidhm = tl.program_id(0)\n pidz = tl.program_id(1)\n rxm = pidhm % BLOCK\n rbm = pidhm // BLOCK\n rxn = tl.arange(0, TN) % BLOCK\n rbn = tl.arange(0, TN) // BLOCK\n header = LUT + rbm * 2\n size = tl.load(header + 0)\n offset = tl.load(header + 1)\n check = rbn < size\n rbmn = tl.where(check, rbn, size - 1)\n blockid = tl.load(LUT + offset + rbmn * 4 + 0)\n rowid = tl.load(LUT + offset + rbmn * 4 + 2)\n headid = tl.load(LUT + offset + rbmn * 4 + 3)\n px = X + pidz * stride_zx + blockid * BLOCK * BLOCK + rxm * BLOCK + rxn\n x = tl.load(px, mask=check, other=0)\n x = x.to(tl.float32)\n out = tl.sum(x, axis=0)\n pout = (OUT + pidz * stride_zout + headid * stride_hout + rowid * BLOCK +\n rxm)\n tl.store(pout, out)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/models/attention/blocksparse_sum.py" }, { "uuid": "3d84e0a7-71fe-46f5-a28a-531bf86d60ad", "file_name": "06-fused-attention.py", "repo_name": "2lambda123/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "09e27725b89043a07f49c440db6a9aedcfba8432", "starcount": 0, "input": "@triton.jit\ndef _bwd_kernel(Q, K, V, sm_scale, Out, DO, DQ, DK, DV, L, D, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vk, stride_vn, Z, H, N_CTX,\n num_block, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N:\n tl.constexpr, CAUSAL: tl.constexpr):\n off_hz = tl.program_id(0)\n off_z = off_hz // H\n off_h = off_hz % H\n qk_scale = sm_scale * 1.44269504\n Q += off_z * stride_qz + off_h * stride_qh\n K += off_z * stride_qz + off_h * stride_qh\n V += off_z * stride_qz + off_h * stride_qh\n DO += off_z * stride_qz + off_h * stride_qh\n DQ += off_z * stride_qz + off_h * stride_qh\n DK += off_z * stride_qz + off_h * stride_qh\n DV += off_z * stride_qz + off_h * stride_qh\n for start_n in range(0, num_block):\n if CAUSAL:\n lo = start_n * BLOCK_M\n else:\n lo = 0\n offs_qm = lo + tl.arange(0, BLOCK_M)\n offs_n = start_n * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_m = tl.arange(0, BLOCK_N)\n offs_k = tl.arange(0, BLOCK_DMODEL)\n q_ptrs = Q + (offs_qm[:, None] * stride_qm + offs_k[None, :] *\n stride_qk)\n k_ptrs = K + (offs_n[:, None] * stride_kn + offs_k[None, :] * stride_kk\n )\n v_ptrs = V + (offs_n[:, None] * stride_qm + offs_k[None, :] * stride_qk\n )\n do_ptrs = DO + (offs_qm[:, None] * stride_qm + offs_k[None, :] *\n stride_qk)\n dq_ptrs = DQ + (offs_qm[:, None] * stride_qm + offs_k[None, :] *\n stride_qk)\n D_ptrs = D + off_hz * N_CTX\n l_ptrs = L + off_hz * N_CTX\n dv = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n dk = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n k = tl.load(k_ptrs)\n v = tl.load(v_ptrs)\n for start_m in range(lo, num_block * BLOCK_M, BLOCK_M):\n offs_m_curr = start_m + offs_m\n q = tl.load(q_ptrs)\n if CAUSAL:\n qk = tl.where(offs_m_curr[:, None] >= offs_n[None, :],\n float(0.0), float('-inf'))\n else:\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, tl.trans(k))\n qk *= qk_scale\n l_i = tl.load(l_ptrs + offs_m_curr)\n p = tl.math.exp2(qk - l_i[:, None])\n do = tl.load(do_ptrs)\n dv += tl.dot(tl.trans(p.to(Q.dtype.element_ty)), do)\n Di = tl.load(D_ptrs + offs_m_curr)\n dp = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32) - Di[:, None]\n dp += tl.dot(do, tl.trans(v))\n ds = p * dp * sm_scale\n dk += tl.dot(tl.trans(ds.to(Q.dtype.element_ty)), q)\n dq = tl.load(dq_ptrs)\n dq += tl.dot(ds.to(Q.dtype.element_ty), k)\n tl.store(dq_ptrs, dq)\n dq_ptrs += BLOCK_M * stride_qm\n q_ptrs += BLOCK_M * stride_qm\n do_ptrs += BLOCK_M * stride_qm\n dv_ptrs = DV + (offs_n[:, None] * stride_qm + offs_k[None, :] *\n stride_qk)\n dk_ptrs = DK + (offs_n[:, None] * stride_kn + offs_k[None, :] *\n stride_kk)\n tl.store(dv_ptrs, dv)\n tl.store(dk_ptrs, dk)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/2lambda123/triton/blob/09e27725b89043a07f49c440db6a9aedcfba8432/python/tutorials/06-fused-attention.py" }, { "uuid": "02bde305-1b40-42a5-b808-be8ee0f8f362", "file_name": "outer_softmax_online.py", "repo_name": "iclementine/optimize_softmax", "file_path": "outer_softmax_online.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef next_multiple_of(a, b):\n return tl.cidv(a, b) * b\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "int8" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/outer_softmax_online.py" }, { "uuid": "35ba6a63-cf05-402d-aa41-8b691e1e0c2e", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef bounds_mask(offs_m, offs_n, M, N, EVEN_M: tl.constexpr, EVEN_N: tl.\n constexpr):\n if EVEN_M & EVEN_N:\n val = 0\n else:\n mask = make_bounds(offs_m, offs_n, M, N, EVEN_M, EVEN_N)\n val = tl.where(mask, 0, float('-inf'))\n return val\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Latency Sensitive" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "e0ec9d80-09d9-4544-b5fb-203ac2fa2c98", "file_name": "test_inductor.py", "repo_name": "triton-lang/kernels", "file_path": "test/test_inductor.py", "commit_hash": "eeeebdd8be7d13629de22d600621e6234057eed3", "starcount": 0, "input": "@triton.jit\ndef fn(out_ptr0, rnumel, RBLOCK: tl.constexpr):\n rbase = tl.arange(0, RBLOCK)[None, :]\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n tmp3 = tl.where(rmask, 1, 0)\n tmp6 = tl.cumsum(tmp3, 1)\n tl.store(out_ptr0 + rindex, tmp6, rmask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/kernels/blob/eeeebdd8be7d13629de22d600621e6234057eed3/test/test_inductor.py" }, { "uuid": "c629a162-a019-40d7-b34a-4b77786b3e07", "file_name": "RzLinearIdx.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearIdx.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_idx_kernel(bh_ptr, b_ptr, K, N, H, R3, R2, R1, R0, stride_bk,\n stride_bn, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr):\n pid = tl.program_id(axis=0)\n grid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_k = pid // grid_n\n pid_n = pid % grid_n\n bh_offset = bh_ptr + tl.arange(0, BLOCK_SIZE_K)[:, None\n ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]\n bh_ptrs = bh_offset + (pid_k * R3 + pid_n * R2 + R1) % R0 % (H - \n BLOCK_SIZE_K * BLOCK_SIZE_N)\n b_ptrs = (b_ptr + pid_k * BLOCK_SIZE_K * stride_bk + pid_n *\n BLOCK_SIZE_N * stride_bn + tl.arange(0, BLOCK_SIZE_K)[:, None] *\n stride_bk + tl.arange(0, BLOCK_SIZE_N)[None, :])\n bh = tl.load(bh_ptrs)\n tl.store(b_ptrs, bh)\n", "category": { "Functionality": [], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Transposed Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearIdx.py" }, { "uuid": "c5940182-0af6-4902-b164-e9d9776bf1ee", "file_name": "_quantize.py", "repo_name": "IBM/qattn", "file_path": "qattn/nn/functional/_quantize.py", "commit_hash": "07ceda0aceb9afd299d622325944c0c0471827fe", "starcount": 0, "input": "@triton.jit\ndef clamp(x: tl.tensor, min_val, max_val) ->tl.tensor:\n \"\"\"Clamps all elements in `x` into range [min, max].\n\n Args:\n x (tl.tensor): the input tensor.\n min_val (Number): lower bound of the range.\n max_val (Number): upper bound of the range.\n\n Returns:\n tl.tensor: the output tensor.\n \"\"\"\n return tl.math.min(tl.math.max(x, min_val), max_val)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/IBM/qattn/blob/07ceda0aceb9afd299d622325944c0c0471827fe/qattn/nn/functional/_quantize.py" }, { "uuid": "cb753c39-8d4d-492d-af54-91bdf9d9f3a8", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(list(filter(keep, configsTmaWS)), key=['N_CTX'])\n@triton.jit\ndef _attn_fwd_tma_ws(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.constexpr,\n STAGE: tl.constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE: tl.\n constexpr, ENABLE_WS: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n pid = tl.program_id(0)\n off_hz = tl.program_id(1)\n _attn_fwd_compute_ws(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid,\n Z, H, N_CTX, BLOCK_M, BLOCK_N, HEAD_DIM, STAGE, ENABLE_TMA,\n LOOP_SCHEDULE)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "9391ce5d-adac-414a-92ce-2ca0faecd484", "file_name": "copy_strided.py", "repo_name": "triton-lang/triton", "file_path": "python/examples/copy_strided.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef kernel(X, stride_xm, Z, stride_zn, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr):\n off_m = tl.arange(0, BLOCK_M)\n off_n = tl.arange(0, BLOCK_N)\n Xs = X + off_m[:, None] * stride_xm + off_n[None, :] * 1\n Zs = Z + off_m[:, None] * 1 + off_n[None, :] * stride_zn\n tl.store(Zs, tl.load(Xs))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/examples/copy_strided.py" }, { "uuid": "04bd883d-3bc8-46e4-9259-5f5271e53a83", "file_name": "y_7.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_7.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef seventh_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor,\n block_size: tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.\n constexpr, col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST002 = 3.87298334620742\n CONST008 = 11.7655316231354\n CONST010 = 16.5555704843566\n CONST012 = 20.4939015319192\n CONST013 = 20.4939015319192\n CONST014 = 22.0740939791422\n CONST015 = 23.5310632462709\n CONST017 = 36.7901566319036\n CONST019 = 38.4260653723485\n CONST020 = 38.4260653723485\n CONST021 = 38.4260653723485\n CONST023 = -4.9916923169903\n CONST025 = 47.0621264925418\n CONST026 = 50.8329064189723\n CONST028 = 55.1852349478554\n CONST029 = 56.2781179722634\n CONST030 = 56.2781179722634\n CONST032 = 66.5558975598707\n CONST033 = 75.2994023880668\n CONST037 = 101.665812837945\n CONST038 = 110.370469895711\n CONST041 = 147.160626527614\n CONST042 = -1.66389743899677\n CONST043 = -9.37968632871057\n CONST044 = -1.66389743899677\n CONST045 = -220.740939791422\n CONST046 = -220.740939791422\n CONST047 = -1.60108605718119\n CONST048 = -187.593726574211\n CONST049 = -9.1975391579759\n CONST050 = -1.83950783159518\n CONST051 = -1.83950783159518\n CONST052 = -4.80325817154356\n CONST053 = -147.160626527614\n CONST054 = -140.695294930659\n CONST055 = -133.111795119741\n CONST056 = -125.499003980111\n CONST057 = -125.499003980111\n CONST058 = -99.833846339806\n CONST059 = -87.7389315936062\n CONST060 = -76.852130744697\n CONST061 = -66.5558975598707\n CONST062 = -62.7495019900557\n CONST063 = -52.6433589561637\n CONST064 = -44.1481879582843\n CONST065 = -44.3705983732471\n CONST066 = -40.6663251351779\n CONST067 = -40.6663251351779\n CONST068 = -8.31948719498384\n CONST069 = -37.6497011940334\n CONST070 = -33.2779487799353\n CONST071 = -25.4164532094862\n CONST072 = -25.4164532094862\n CONST073 = -17.5477863187212\n CONST074 = -11.7655316231354\n CONST075 = -11.0370469895711\n CONST076 = -9.1975391579759\n CONST077 = -8.47215106982872\n CONST078 = -4.80325817154356\n CONST079 = -2.50682661696018\n CONST080 = -1.60108605718119\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n Y00 = (CONST059 * VAR07 * VAR24 - CONST063 * VAR05 * VAR26 - CONST073 *\n VAR22 * x + CONST079 * VAR03)\n Y01 = y * (CONST029 * VAR23 * x + CONST030 * VAR05 * z + CONST048 *\n VAR07 * VAR25)\n Y02 = CONST050 * VAR03 + VAR05 * (CONST010 * VAR26 + CONST014 * VAR17\n ) + VAR07 * (CONST045 * VAR17 * VAR26 - CONST076 * VAR24) + x * (\n CONST038 * VAR17 * VAR24 + CONST076 * VAR22)\n Y03 = VAR16 * (CONST041 * VAR25 * x + CONST053 * VAR07 * z) + y * (-\n CONST064 * VAR05 * z + CONST064 * VAR23 * x)\n Y04 = CONST042 * VAR03 + VAR05 * (-CONST042 * VAR26 - CONST070 * VAR17\n ) + VAR07 * (CONST061 * VAR17 * VAR26 + CONST065 * VAR15 - CONST068 *\n VAR24) + x * (-CONST023 * VAR22 - CONST055 * VAR15 * VAR26 + \n CONST058 * VAR17 * VAR24)\n Y05 = CONST015 * VAR05 * y * z + VAR07 * (CONST025 * VAR25 * y + \n CONST057 * VAR16 * z) + x * (CONST015 * VAR23 * y + CONST033 *\n VAR14 * z + CONST056 * VAR16 * VAR25)\n Y06 = CONST047 * VAR03 + VAR05 * (CONST020 * VAR17 + CONST078 * VAR26\n ) + VAR07 * (CONST052 * VAR24 + CONST060 * VAR15 - CONST060 * VAR17 *\n VAR26) + x * (CONST012 * VAR13 + CONST019 * VAR17 * VAR24 + \n CONST060 * VAR15 * VAR26 + CONST080 * VAR22)\n Y07 = CONST002 * VAR12 + VAR14 * (CONST066 * VAR08 + CONST067 * VAR26\n ) + VAR16 * (CONST026 * VAR06 + CONST026 * VAR24 + CONST037 * VAR08 *\n VAR26) + y * (CONST071 * VAR06 * VAR26 + CONST072 * VAR08 * VAR24 +\n CONST077 * VAR04 + CONST077 * VAR22)\n Y08 = CONST047 * VAR21 + VAR23 * (CONST020 * VAR17 + CONST052 * VAR08\n ) + VAR25 * (CONST052 * VAR06 - CONST060 * VAR08 * VAR17 + CONST060 *\n VAR15) + z * (CONST013 * VAR13 + CONST021 * VAR06 * VAR17 + \n CONST047 * VAR04 + CONST060 * VAR08 * VAR15)\n Y09 = VAR14 * (CONST069 * VAR08 - CONST069 * VAR26) + VAR16 * (-\n CONST062 * VAR06 + CONST062 * VAR24) + y * (CONST008 * VAR08 *\n VAR24 + CONST074 * VAR04 + CONST074 * VAR06 * VAR26 - CONST074 * VAR22)\n Y10 = -CONST042 * VAR21 + VAR23 * (CONST044 * VAR08 + CONST070 * VAR17\n ) + VAR25 * (CONST032 * VAR08 * VAR17 - CONST065 * VAR15 + CONST068 *\n VAR06) + z * (CONST023 * VAR04 + CONST055 * VAR08 * VAR15 - \n CONST058 * VAR06 * VAR17)\n Y11 = VAR16 * (CONST017 * VAR06 + CONST017 * VAR24 + CONST046 * VAR08 *\n VAR26) + y * (CONST028 * VAR06 * VAR26 + CONST028 * VAR08 * VAR24 +\n CONST075 * VAR04 + CONST075 * VAR22)\n Y12 = CONST051 * VAR21 + VAR23 * (CONST010 * VAR08 + CONST014 * VAR17\n ) + VAR25 * (CONST045 * VAR08 * VAR17 - CONST049 * VAR06) + z * (\n CONST038 * VAR06 * VAR17 + CONST049 * VAR04)\n Y13 = y * (CONST043 * VAR04 - CONST043 * VAR22 - CONST054 * VAR06 *\n VAR26 + CONST054 * VAR08 * VAR24)\n Y14 = (-CONST059 * VAR06 * VAR25 + CONST063 * VAR08 * VAR23 + CONST073 *\n VAR04 * z - CONST079 * VAR21)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n tl.store(output_ptr + output_row_offset + 9, Y09, mask=\n output_row_offset + 9 < output_numel)\n tl.store(output_ptr + output_row_offset + 10, Y10, mask=\n output_row_offset + 10 < output_numel)\n tl.store(output_ptr + output_row_offset + 11, Y11, mask=\n output_row_offset + 11 < output_numel)\n tl.store(output_ptr + output_row_offset + 12, Y12, mask=\n output_row_offset + 12 < output_numel)\n tl.store(output_ptr + output_row_offset + 13, Y13, mask=\n output_row_offset + 13 < output_numel)\n tl.store(output_ptr + output_row_offset + 14, Y14, mask=\n output_row_offset + 14 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_7.py" }, { "uuid": "ad543ac2-d2ac-447e-8a53-c871539d272e", "file_name": "y_2.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_2.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef second_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n CONST_00 = 3.87298334620742\n CONST_01 = 2.23606797749979\n CONST_02 = 4.47213595499958\n g_Y20 = tl.load(sph_grad_ptr + output_row_offset, mask=\n output_row_offset < output_numel)\n g_Y21 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_Y22 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_Y23 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_Y24 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += (CONST_00 * g_Y20 * z + CONST_00 * g_Y21 * y - CONST_01 * g_Y22 *\n x - CONST_00 * g_Y24 * x)\n g_y += CONST_00 * g_Y21 * x + CONST_02 * g_Y22 * y + CONST_00 * g_Y23 * z\n g_z += (CONST_00 * g_Y20 * x - CONST_01 * g_Y22 * z + CONST_00 * g_Y23 *\n y + CONST_00 * g_Y24 * z)\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_2.py" }, { "uuid": "28f5b112-be8c-4f0b-8096-f9ab7e3bb85c", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef _mlp_wide_kernel_bwd_dx(dx, pid_h, pid_b, x_ptr, w1_ptr, w2_ptr, o_ptr,\n dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D: tl.constexpr, E, stride_xb,\n stride_xd, stride_w1d, stride_w1e, stride_w2e, stride_w2d, stride_ob,\n stride_od, stride_dxb, stride_dxd, stride_dw1d, stride_dw1e,\n stride_dw2e, stride_dw2d, stride_dob, stride_dod, BLOCK_SIZE_B: tl.\n constexpr, BLOCK_SIZE_E: tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp_bwd_dx\n Z = X @ W1, H = f(Z), O = H @ W2\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n - dX has shape (B, D)\n - dW1 has shape (D, E)\n - dW2 has shape (E, D)\n - dO has shape (B, D)\n \"\"\"\n TARGET_TYPE = x_ptr.type.element_ty\n offs_b = tl.arange(0, BLOCK_SIZE_B)\n offs_d = tl.arange(0, D)\n offs_e = tl.arange(0, BLOCK_SIZE_E)\n x_ptrs = x_ptr + ((pid_h * B + pid_b * BLOCK_SIZE_B + offs_b[:, None]) *\n stride_xb + offs_d[None, :] * stride_xd)\n x_mask = (offs_b[:, None] < B - pid_b * BLOCK_SIZE_B) & (offs_d[None, :\n ] < D)\n do_ptrs = do_ptr + ((pid_h * B + pid_b * BLOCK_SIZE_B + offs_b[:, None]\n ) * stride_dob + offs_d[None, :] * stride_dod)\n do_mask = (offs_b[:, None] < B - pid_b * BLOCK_SIZE_B) & (offs_d[None,\n :] < D)\n w1_ptrs = w1_ptr + ((pid_h * D + offs_d[:, None]) * stride_w1d + offs_e\n [None, :] * stride_w1e)\n w2_ptrs = w2_ptr + ((pid_h * E + offs_e[:, None]) * stride_w2e + offs_d\n [None, :] * stride_w2d)\n dw1_ptrs = dw1_ptr + ((pid_h * D + offs_d[:, None]) * stride_dw1d + \n offs_e[None, :] * stride_dw1e)\n dw2_ptrs = dw2_ptr + ((pid_h * E + offs_e[:, None]) * stride_dw2e + \n offs_d[None, :] * stride_dw2d)\n x = tl.load(x_ptrs, mask=x_mask, other=0.0)\n do = tl.load(do_ptrs, mask=do_mask, other=0.0)\n for e in range(0, tl.cdiv(E, BLOCK_SIZE_E)):\n w1_mask = (offs_d[:, None] < D) & (offs_e[None, :] < E - e *\n BLOCK_SIZE_E)\n w2_mask = (offs_e[:, None] < E - e * BLOCK_SIZE_E) & (offs_d[None,\n :] < D)\n w1 = tl.load(w1_ptrs, mask=w1_mask, other=0.0)\n w2 = tl.load(w2_ptrs, mask=w2_mask, other=0.0)\n z = tl.dot(x, w1, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n h = leaky_relu(z).to(TARGET_TYPE)\n elif ACTIVATION == 'silu':\n h = silu(z).to(TARGET_TYPE)\n elif ACTIVATION == 'sigmoid':\n h = tl.sigmoid(z).to(TARGET_TYPE)\n else:\n h = z.to(TARGET_TYPE)\n dh = tl.dot(do, tl.trans(w2), out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n dz = (dh * d_leacky_relu(z)).to(TARGET_TYPE)\n elif ACTIVATION == 'silu':\n dz = (dh * d_silu(z, h)).to(TARGET_TYPE)\n elif ACTIVATION == 'sigmoid':\n dz = (dh * d_sigmoid(h)).to(TARGET_TYPE)\n else:\n dz = dh.to(TARGET_TYPE)\n dx += tl.dot(dz, tl.trans(w1), out_dtype=tl.float32)\n w1_ptrs += BLOCK_SIZE_E * stride_w1e\n w2_ptrs += BLOCK_SIZE_E * stride_w2e\n dw1_ptrs += BLOCK_SIZE_E * stride_dw1e\n dw2_ptrs += BLOCK_SIZE_E * stride_dw2e\n return dx\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "9a05112d-23d7-43f7-92f8-e3e2e3cd9ee0", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef _bwd_kernel(Q, K, V, S, sm_scale, DO, DQ, DK, DV, M, D, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vn, stride_vk, stride_doz,\n stride_doh, stride_dom, stride_dok, stride_dqz, stride_dqh, stride_dqm,\n stride_dqk, stride_dkz, stride_dkh, stride_dkn, stride_dkk, stride_dvz,\n stride_dvh, stride_dvn, stride_dvk, stride_mz, stride_mh, stride_mm,\n stride_dz, stride_dh, stride_dm, M_Q, N_CTX, BLOCK_DMODEL: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, EVEN_M: tl.constexpr,\n EVEN_N: tl.constexpr, CAUSAL: tl.constexpr, USE_ALIBI: tl.constexpr):\n off_h = tl.program_id(0)\n off_z = tl.program_id(1)\n Q += off_z * stride_qz + off_h * stride_qh\n K += off_z * stride_kz + off_h * stride_kh\n V += off_z * stride_vz + off_h * stride_vh\n DO += off_z * stride_doz + off_h * stride_doh\n DQ += off_z * stride_dqz + off_h * stride_dqh\n DK += off_z * stride_dkz + off_h * stride_dkh\n DV += off_z * stride_dvz + off_h * stride_dvh\n if USE_ALIBI:\n slope = tl.load(S + off_h)\n for start_n in range(0, N_CTX, BLOCK_N):\n offs_n_curr = start_n + tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n offs_m = tl.arange(0, BLOCK_M)\n k_ptrs = K + (offs_n_curr[:, None] * stride_kn + offs_d[None, :] *\n stride_kk)\n v_ptrs = V + (offs_n_curr[:, None] * stride_vn + offs_d[None, :] *\n stride_vk)\n q_ptrs = Q + (offs_m[:, None] * stride_qm + offs_d[None, :] * stride_qk\n )\n dq_ptrs = DQ + (offs_m[:, None] * stride_dqm + offs_d[None, :] *\n stride_dqk)\n do_ptrs = DO + (offs_m[:, None] * stride_dom + offs_d[None, :] *\n stride_dok)\n m_ptrs = M + off_z * stride_mz + off_h * stride_mh + offs_m * stride_mm\n D_ptrs = D + off_z * stride_dz + off_h * stride_dh + offs_m * stride_dm\n dv = tl.zeros([BLOCK_N, BLOCK_DMODEL], dtype=tl.float32)\n dk = tl.zeros([BLOCK_N, BLOCK_DMODEL], dtype=tl.float32)\n if EVEN_N:\n k = tl.load(k_ptrs)\n v = tl.load(v_ptrs)\n else:\n k = tl.load(k_ptrs, mask=offs_n_curr[:, None] < N_CTX, other=0)\n v = tl.load(v_ptrs, mask=offs_n_curr[:, None] < N_CTX, other=0)\n k = k.to(tl.float16)\n v = v.to(tl.float16)\n if CAUSAL:\n begin = start_n + M_Q - N_CTX\n dq_ptrs += begin * stride_dqm\n q_ptrs += begin * stride_qm\n do_ptrs += begin * stride_dom\n m_ptrs += begin * stride_mm\n D_ptrs += begin * stride_dm\n else:\n begin = 0\n for start_m in range(begin, M_Q, BLOCK_M):\n offs_m_curr = start_m + offs_m\n if EVEN_M:\n q = tl.load(q_ptrs)\n else:\n q = tl.load(q_ptrs, mask=offs_m_curr[:, None] < M_Q, other=0)\n q = q.to(tl.float16)\n qk = tl.dot(q, k, trans_b=True)\n qk *= sm_scale\n if USE_ALIBI & CAUSAL:\n qk += causal_alibi_mask(slope, offs_m_curr, offs_n_curr,\n M_Q, N_CTX, EVEN_M, EVEN_N)\n elif USE_ALIBI:\n qk += symmetric_alibi_mask(slope, offs_m_curr, offs_n_curr,\n M_Q, N_CTX, EVEN_M, EVEN_N)\n elif CAUSAL:\n qk += causal_mask(offs_m_curr, offs_n_curr, M_Q, N_CTX,\n EVEN_M, EVEN_N)\n if EVEN_M:\n m = tl.load(m_ptrs)\n Di = tl.load(D_ptrs)\n do = tl.load(do_ptrs)\n else:\n m = tl.load(m_ptrs, mask=offs_m_curr < M_Q, other=0)\n Di = tl.load(D_ptrs, mask=offs_m_curr < M_Q, other=0)\n do = tl.load(do_ptrs, mask=offs_m_curr[:, None] < M_Q, other=0)\n do = do.to(tl.float16)\n p = tl.exp(qk - m[:, None])\n dv += tl.dot(p.to(tl.float16), do, trans_a=True)\n dp = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32) - Di[:, None]\n dp += tl.dot(do, v, trans_b=True)\n ds = p * dp * sm_scale\n dk += tl.dot(ds.to(tl.float16), q, trans_a=True)\n if EVEN_M:\n dq = tl.load(dq_ptrs, eviction_policy='evict_last')\n else:\n dq = tl.load(dq_ptrs, mask=offs_m_curr[:, None] < M_Q,\n other=0, eviction_policy='evict_last')\n dq += tl.dot(ds.to(tl.float16), k)\n if EVEN_M:\n tl.store(dq_ptrs, dq, eviction_policy='evict_last')\n else:\n tl.store(dq_ptrs, dq, mask=offs_m_curr[:, None] < M_Q,\n eviction_policy='evict_last')\n q_ptrs += BLOCK_M * stride_qm\n dq_ptrs += BLOCK_M * stride_dqm\n do_ptrs += BLOCK_M * stride_dom\n m_ptrs += BLOCK_M * stride_mm\n D_ptrs += BLOCK_M * stride_dm\n offs_d = tl.arange(0, BLOCK_DMODEL)\n dv_ptrs = DV + (offs_n_curr[:, None] * stride_dvn + offs_d[None, :] *\n stride_dvk)\n dk_ptrs = DK + (offs_n_curr[:, None] * stride_dkn + offs_d[None, :] *\n stride_dkk)\n if EVEN_N:\n tl.store(dv_ptrs, dv)\n tl.store(dk_ptrs, dk)\n else:\n tl.store(dv_ptrs, dv, mask=offs_n_curr[:, None] < N_CTX)\n tl.store(dk_ptrs, dk, mask=offs_n_curr[:, None] < N_CTX)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "4db0e91c-60b7-4181-91a9-99d1f7995e1e", "file_name": "flash_triton.py", "repo_name": "MayDomine/Burst-Attention", "file_path": "burst_attn/flash_triton.py", "commit_hash": "b088c554072935074ea9c643de5ee363be5ab1f6", "starcount": 0, "input": "@triton.jit\ndef _bwd_store_dk_dv(dk_ptrs, dv_ptrs, dk, dv, offs_n, offs_d, seqlen_k,\n headdim, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr, EVEN_HEADDIM: tl.\n constexpr):\n if EVEN_N & EVEN_M:\n if EVEN_HEADDIM:\n tl.store(dv_ptrs, dv)\n tl.store(dk_ptrs, dk)\n else:\n tl.store(dv_ptrs, dv, mask=offs_d[None, :] < headdim)\n tl.store(dk_ptrs, dk, mask=offs_d[None, :] < headdim)\n elif EVEN_HEADDIM:\n tl.store(dv_ptrs, dv, mask=offs_n[:, None] < seqlen_k)\n tl.store(dk_ptrs, dk, mask=offs_n[:, None] < seqlen_k)\n else:\n tl.store(dv_ptrs, dv, mask=(offs_n[:, None] < seqlen_k) & (offs_d[\n None, :] < headdim))\n tl.store(dk_ptrs, dk, mask=(offs_n[:, None] < seqlen_k) & (offs_d[\n None, :] < headdim))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MayDomine/Burst-Attention/blob/b088c554072935074ea9c643de5ee363be5ab1f6/burst_attn/flash_triton.py" }, { "uuid": "743113b7-b1b8-41f3-ae0c-36089061283a", "file_name": "matmul.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/matmul.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'HAS_INPUT': lambda args: args['input'] is not None,\n 'HAS_ALPHA': lambda args: args['alpha'] is not None, 'HAS_BETA': lambda\n args: args['beta'] is not None})\n@triton.autotune(configs=[triton.Config({'BM': 128, 'BK': 64, 'BN': 256,\n 'G': 4}, num_stages=3, num_warps=8), triton.Config({'BM': 64, 'BK': 32,\n 'BN': 256, 'G': 4}, num_stages=4, num_warps=4), triton.Config({'BM': \n 128, 'BK': 32, 'BN': 128, 'G': 4}, num_stages=4, num_warps=4), triton.\n Config({'BM': 128, 'BK': 32, 'BN': 64, 'G': 4}, num_stages=4, num_warps\n =4), triton.Config({'BM': 64, 'BK': 32, 'BN': 128, 'G': 4}, num_stages=\n 4, num_warps=4), triton.Config({'BM': 128, 'BK': 32, 'BN': 32, 'G': 4},\n num_stages=4, num_warps=4), triton.Config({'BM': 64, 'BK': 32, 'BN': 32,\n 'G': 4}, num_stages=5, num_warps=2), triton.Config({'BM': 32, 'BK': 32,\n 'BN': 64, 'G': 4}, num_stages=5, num_warps=2), triton.Config({'BM': 128,\n 'BK': 128, 'BN': 256, 'G': 4}, num_stages=3, num_warps=8), triton.\n Config({'BM': 256, 'BK': 128, 'BN': 128, 'G': 4}, num_stages=3,\n num_warps=8), triton.Config({'BM': 256, 'BK': 128, 'BN': 64, 'G': 4},\n num_stages=4, num_warps=4), triton.Config({'BM': 64, 'BK': 128, 'BN': \n 256, 'G': 4}, num_stages=4, num_warps=4), triton.Config({'BM': 128,\n 'BK': 128, 'BN': 128, 'G': 4}, num_stages=4, num_warps=4), triton.\n Config({'BM': 128, 'BK': 64, 'BN': 64, 'G': 4}, num_stages=4, num_warps\n =4), triton.Config({'BM': 64, 'BK': 64, 'BN': 128, 'G': 4}, num_stages=\n 4, num_warps=4), triton.Config({'BM': 128, 'BK': 64, 'BN': 32, 'G': 4},\n num_stages=4, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel(a, b, c, input, alpha, beta, M, N, K, s_am, s_ak, s_bk,\n s_bn, s_cm, s_cn, BM: tl.constexpr, BK: tl.constexpr, BN: tl.constexpr,\n G: tl.constexpr, ACTIVATION: tl.constexpr, HAS_INPUT: tl.constexpr,\n HAS_ALPHA: tl.constexpr, HAS_BETA: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (M, K), B has shape (K, N) and C has shape (M, N)\n \"\"\"\n NM, NN = tl.num_programs(0), tl.num_programs(1)\n i_m, i_n = tl.program_id(0), tl.program_id(1)\n i_m, i_n = tl.swizzle2d(i_m, i_n, NM, NN, G)\n o_am = (i_m * BM + tl.arange(0, BM)) % M\n o_bn = (i_n * BN + tl.arange(0, BN)) % N\n o_k = tl.arange(0, BK)\n p_a = a + (o_am[:, None] * s_am + o_k[None, :] * s_ak)\n p_b = b + (o_k[:, None] * s_bk + o_bn[None, :] * s_bn)\n b_acc = tl.zeros((BM, BN), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BK)):\n b_a = tl.load(p_a, mask=o_k[None, :] < K - k * BK, other=0.0)\n b_b = tl.load(p_b, mask=o_k[:, None] < K - k * BK, other=0.0)\n b_acc += tl.dot(b_a, b_b, allow_tf32=False)\n p_a += BK * s_ak\n p_b += BK * s_bk\n o_cm = i_m * BM + tl.arange(0, BM)\n o_cn = i_n * BN + tl.arange(0, BN)\n mask = (o_cm[:, None] < M) & (o_cn[None, :] < N)\n b_c = b_acc\n if ACTIVATION == 'leaky_relu':\n b_c = leaky_relu(b_c)\n if HAS_ALPHA:\n b_c *= tl.load(alpha)\n if HAS_INPUT:\n p_i = input + s_cm * o_cm[:, None] + s_cn * o_cn[None, :]\n b_i = tl.load(p_i, mask=mask, other=0.0).to(tl.float32)\n if HAS_BETA:\n b_i *= tl.load(beta)\n b_c += b_i\n p_c = c + s_cm * o_cm[:, None] + s_cn * o_cn[None, :]\n tl.store(p_c, b_c.to(c.dtype.element_ty), mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/matmul.py" }, { "uuid": "41d7f9ea-8351-46ef-aa36-57ca4cdd7d75", "file_name": "06-fused-attention.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _attn_bwd_dq(dq, q, K, V, do, m, D, stride_tok, stride_d, H, N_CTX,\n BLOCK_M2: tl.constexpr, BLOCK_N2: tl.constexpr, HEAD_DIM: tl.constexpr,\n start_m, start_n, num_steps, MASK: tl.constexpr):\n offs_m = start_m + tl.arange(0, BLOCK_M2)\n offs_n = start_n + tl.arange(0, BLOCK_N2)\n offs_k = tl.arange(0, HEAD_DIM)\n kT_ptrs = K + offs_n[None, :] * stride_tok + offs_k[:, None] * stride_d\n vT_ptrs = V + offs_n[None, :] * stride_tok + offs_k[:, None] * stride_d\n Di = tl.load(D + offs_m)\n tl.static_assert(BLOCK_M2 % BLOCK_N2 == 0)\n curr_n = start_n\n step_n = BLOCK_N2\n for blk_idx in range(num_steps):\n kT = tl.load(kT_ptrs)\n vT = tl.load(vT_ptrs)\n qk = tl.dot(q, kT)\n p = tl.math.exp2(qk - m)\n if MASK:\n offs_n = curr_n + tl.arange(0, BLOCK_N2)\n mask = offs_m[:, None] >= offs_n[None, :]\n p = tl.where(mask, p, 0.0)\n dp = tl.dot(do, vT).to(tl.float32)\n ds = p * (dp - Di[:, None])\n ds = ds.to(tl.float16)\n dq += tl.dot(ds, tl.trans(kT))\n curr_n += step_n\n kT_ptrs += step_n * stride_tok\n vT_ptrs += step_n * stride_tok\n return dq\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/06-fused-attention.py" }, { "uuid": "f12f4856-2ba8-4fdf-accd-606056062839", "file_name": "sparse_linear.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_linear.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.autotune(configs=autotune_configs, key=['row_dense_dim',\n 'row_sparse_dim', 'col_dim'])\n@triton.jit\ndef input_row_sparse_matmul_kernel(lhs_ptr, rhs_ptr, out_ptr,\n expert_ends_ptr, expert_pad_begins_ptr, row_dense_dim: tl.constexpr,\n row_sparse_dim: tl.constexpr, col_dim: tl.constexpr, inner_dim: tl.\n constexpr, lhs_stride_row: tl.constexpr, lhs_stride_inner: tl.constexpr,\n rhs_stride_inner: tl.constexpr, rhs_stride_col: tl.constexpr,\n out_stride_row: tl.constexpr, out_stride_col: tl.constexpr, accumulate:\n tl.constexpr, block_size_row: tl.constexpr, block_size_col: tl.\n constexpr, block_size_inner: tl.constexpr, group_size_row: tl.constexpr):\n tl.static_assert(row_sparse_dim % block_size_row == 0)\n tl.static_assert(col_dim % block_size_col == 0)\n tl.static_assert(inner_dim % block_size_inner == 0)\n tl.static_assert(row_dense_dim % row_sparse_dim == 0)\n pid_row, pid_col = tl.swizzle2d(tl.program_id(axis=0), tl.program_id(\n axis=1), row_dense_dim // block_size_row, col_dim // block_size_col,\n group_size_row)\n row_dense_offset = pid_row * block_size_row\n sparse_index = row_dense_offset // row_sparse_dim\n row_sparse_offset = row_dense_offset % row_sparse_dim\n col_offset = pid_col * block_size_col\n inner_begin = tl.load(expert_ends_ptr + sparse_index - 1, mask=\n sparse_index > 0, other=0)\n inner_end = tl.load(expert_pad_begins_ptr + sparse_index)\n inner_offset = inner_begin // block_size_inner * block_size_inner\n row_range = tl.arange(0, block_size_row)[:, None]\n col_range = tl.arange(0, block_size_col)[None, :]\n inner_range = tl.arange(0, block_size_inner) + inner_offset\n lhs_ptr += (row_sparse_offset + row_range) * lhs_stride_row\n rhs_ptr += (col_offset + col_range) * rhs_stride_col\n out_ptr += (row_dense_offset + row_range) * out_stride_row + (col_offset +\n col_range) * out_stride_col\n mask = (inner_begin <= inner_range) & (inner_range < inner_end)\n out = tl.dot(tl.load(lhs_ptr + inner_range[None, :] * lhs_stride_inner,\n mask=mask[None, :], other=0), tl.load(rhs_ptr + inner_range[:, None\n ] * rhs_stride_inner, mask=mask[:, None], other=0))\n for i in range(1, tl.cdiv(inner_end - inner_offset, block_size_inner)):\n inner_range += block_size_inner\n mask = (inner_begin <= inner_range) & (inner_range < inner_end)\n out += tl.dot(tl.load(lhs_ptr + inner_range[None, :] *\n lhs_stride_inner, mask=mask[None, :], other=0), tl.load(rhs_ptr +\n inner_range[:, None] * rhs_stride_inner, mask=mask[:, None],\n other=0))\n if accumulate:\n out += tl.load(out_ptr)\n tl.store(out_ptr, out)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_linear.py" }, { "uuid": "45c898a1-7e30-4f2d-bdf7-18b7ae8654ae", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef load_2d(ptr, sz0: tl.constexpr, sz1: tl.constexpr, n0, n1, max0, max1,\n stride0=None, stride1=1):\n \"\"\"Chunk 2d matrix (defined by ptr) into 2d grid, where each chunk has size (sz0,sz1).\n Load the (n0,n1)th chunk. Ie, load [n0*sz0,...,(n0+1)*sz0-1] x [n1*sz1,...,(n1+1)*sz1-1].\n \"\"\"\n stride0 = stride0 or sz1\n offs0 = get_1d_offest(sz0, n0)\n offs1 = get_1d_offest(sz1, n1)\n offs = get_2d_offset(offs0, offs1, stride0, stride1)\n mask = get_2d_mask(offs0, offs1, max0, max1)\n return tl.load(ptr + offs, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "5558131b-8910-430e-bfcb-0a8e3e1e1a06", "file_name": "pointwise.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/pointwise.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_add_kernel(input_ptr, other_ptr, out_ptr, numel: tl.constexpr,\n block_size: tl.constexpr):\n block_start = tl.program_id(axis=0).to(tl.int64) * block_size\n offsets = block_start + tl.arange(0, block_size)\n mask = offsets < numel\n input_ = tl.load(input_ptr + offsets, mask=mask)\n other = tl.load(other_ptr + offsets, mask=mask)\n tl.store(out_ptr + offsets, input_ + other, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/pointwise.py" }, { "uuid": "3ba95bb3-c419-4af2-b7ce-b7e0d81c14fd", "file_name": "group_norm.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/group_norm.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@eval(\n \"\"\"triton.heuristics({\n 'BLOCK_SIZE':\n lambda kwargs: triton.next_power_of_2(kwargs['cluster_num']),\n})\"\"\"\n )\n@eval(\n \"\"\"triton.heuristics({\n 'num_warps':\n lambda kwargs: max(1, min(16, kwargs['BLOCK_SIZE'] // 128)),\n})\"\"\"\n )\n@triton.jit\ndef group_norm_4d_channels_last_forward_collect_stats_kernel_stage_2(\n cluster_mean_ptr, cluster_m2_ptr, cluster_weight_ptr, N, groups,\n cluster_num, eps, mean_ptr, rstd_ptr, BLOCK_SIZE: tl.constexpr):\n group = tl.program_id(0)\n pid_batch = tl.program_id(1)\n block = tl.arange(0, BLOCK_SIZE)\n mask = block < cluster_num\n offset = pid_batch * groups * cluster_num + group * cluster_num + block\n cluster_mean = tl.load(cluster_mean_ptr + offset, mask=mask)\n cluster_m2 = tl.load(cluster_m2_ptr + offset, mask=mask)\n cluster_weight = tl.load(cluster_weight_ptr + offset, mask=mask)\n mean, m2, weight = tl.reduce((cluster_mean, cluster_m2, cluster_weight),\n 0, welford_combine)\n var = m2 / weight\n rstd = 1.0 / tl.sqrt(var + eps)\n offset = pid_batch * groups + group\n tl.store(mean_ptr + offset, mean)\n tl.store(rstd_ptr + offset, rstd)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/group_norm.py" }, { "uuid": "5e7d7488-136e-4938-aca1-8982d4c280bf", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _inner_paged_attn_unroll_2_kernel(q, k_cache, v_cache, stride_km,\n block_base_ptrs, base_offs_kv, alibi_slope, block_offs, seq_len, qkv,\n qk_max, exp_sum, BLOCK_SIZE: tl.constexpr, LO: tl.constexpr, HI: tl.\n constexpr):\n for block_idx in range(LO, HI, 2):\n offs_kv_0 = tl.load(block_base_ptrs + block_idx + 0\n ) * stride_km + base_offs_kv\n offs_kv_1 = tl.load(block_base_ptrs + block_idx + 1\n ) * stride_km + base_offs_kv\n k_0 = tl.load(k_cache + offs_kv_0)\n k_1 = tl.load(k_cache + offs_kv_1)\n v_0 = tl.load(v_cache + offs_kv_0)\n v_1 = tl.load(v_cache + offs_kv_1)\n _qk_0 = tl.sum((q[None, :] * k_0).to(tl.float32), axis=1)\n _qk_1 = tl.sum((q[None, :] * k_1).to(tl.float32), axis=1)\n if alibi_slope is not None:\n _qk_0 += alibi_slope * ((block_idx + 0) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_1 += alibi_slope * ((block_idx + 1) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_max = tl.maximum(tl.max(_qk_0, axis=0), qk_max)\n _qk_max = tl.maximum(tl.max(_qk_1, axis=0), _qk_max)\n exp_tmp = tl.exp(_qk_0 - _qk_max) + tl.exp(_qk_1 - _qk_max)\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(exp_tmp, axis=0)\n qkv_sum_tmp = tl.exp(_qk_0[:, None] - _qk_max).to(v_cache.dtype.\n element_ty) * v_0 + tl.exp(_qk_1[:, None] - _qk_max).to(v_cache\n .dtype.element_ty) * v_1\n qkv = (qkv * (exp_sum * tl.exp(qk_max - _qk_max)) + qkv_sum_tmp\n ) / _exp_sum\n qk_max = _qk_max\n exp_sum = _exp_sum\n return qkv, qk_max, exp_sum\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "3db55c15-f4b1-4305-b51b-6e73a82136ea", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'USE_INITIAL_STATE': lambda args: args['dh0'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_delta_rule_bwd_kernel_dhu(q, k, d, dht, dh0, do, dh, dv, dv2,\n offsets, chunk_offsets, scale, T: tl.constexpr, H: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, USE_FINAL_STATE_GRADIENT: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1))\n for i_t in range(NT - 1, -1, -1):\n if HEAD_FIRST:\n p_dh = tl.make_block_ptr(dh + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_dh = tl.make_block_ptr(dh + ((boh + i_t) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n b_dh_tmp = tl.zeros([BK, BV], dtype=tl.float32)\n for i_c in range(tl.cdiv(BT, BC) - 1, -1, -1):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_k = tl.make_block_ptr(k + i_nh * T * K, (T, K), (K, 1), (\n i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_d = tl.make_block_ptr(d + i_nh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_dv = tl.make_block_ptr(dv + i_nh * T * V, (T, V), (V, 1),\n (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_nh * T * V, (T, V), (V, 1),\n (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_dv2 = tl.make_block_ptr(dv2 + i_nh * T * V, (T, V), (V, 1\n ), (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1,\n H * K), (i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_d = tl.make_block_ptr(d + (bos * H + i_h) * K, (K, T), (1,\n H * K), (i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV),\n (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV),\n (1, 0))\n p_dv2 = tl.make_block_ptr(dv2 + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV),\n (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_d = tl.load(p_d, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dv = tl.load(p_dv, boundary_check=(0, 1))\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False)\n tl.store(p_dv2, b_dv.to(p_dv.dtype.element_ty), boundary_check=\n (0, 1))\n b_dh_tmp += tl.dot(b_q, b_do.to(b_q.dtype), allow_tf32=False)\n b_dh_tmp -= tl.dot(b_d, b_dv.to(b_q.dtype), allow_tf32=False)\n b_dh += b_dh_tmp\n if USE_INITIAL_STATE:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/chunk.py" }, { "uuid": "1e01284c-e8e1-42a2-b16b-7529e9d7459b", "file_name": "cross_entropy_loss.py", "repo_name": "tdrussell/qlora-pipe", "file_path": "kernels/cross_entropy_loss.py", "commit_hash": "6fb7c8eeae52a0e36c41f00628985f29d8330684", "starcount": 0, "input": "@triton.heuristics({'DO_LOGIT_SCALING': lambda args: args['DO_LOGIT_SCALING']})\n@triton.jit\ndef _cross_entropy_forward(logits_ptr, logits_row_stride, loss_ptr,\n logsumexp_ptr, labels_ptr, VOCAB_SIZE: tl.constexpr, BLOCK_SIZE: tl.\n constexpr, DO_LOGIT_SCALING: tl.constexpr, LOGIT_SCALE: tl.constexpr):\n \"\"\"\n Cross Entropy Loss = 1/n sum [ -yi log(Pi) ]\n Pi = exp(xi) / sum(exp(xi))\n CE_i = -y log(p) = -y log[ exp(x) / sum(exp(x)) ]\n = -y [ x - log[sum(exp(x))] ]\n = y * (log[sum(exp(x))] - x)\n If y == 0: CE_i = 0\n If y == 1: CE_i = logsumexp - x\n\n logsumexp is also stable\n Take y = log[sum(exp(x))]\n exp(y) = sum(exp(x))\n exp(y) = sum(exp(x - c)*exp(c)) Since e^(x-c)*e^c = e^x\n exp(y) = exp(c)*sum(exp(x - c))\n y = log(exp(c)*sum(exp(x - c)))\n y = c + log[sum(exp(x - c))]\n This means we can set c = max(x) to make sure\n exp(x - c) always is exp(x - max(x)).\n This ensures exp(x - max(x))'s maximum is 1 as exp(0) = 1.\n \"\"\"\n row_idx = tl.program_id(0)\n logits_ptr += row_idx * logits_row_stride.to(tl.int64)\n loss_ptr += row_idx\n logsumexp_ptr += row_idx\n labels_ptr += row_idx\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < VOCAB_SIZE\n label_idx = tl.load(labels_ptr).to(tl.int32)\n logits = tl.load(logits_ptr + col_offsets, mask=mask, other=-float('inf')\n ).to(tl.float32)\n if DO_LOGIT_SCALING:\n logits = LOGIT_SCALE * logits\n pass\n c = tl.max(logits, 0)\n logsumexp = c + tl.log(tl.sum(tl.exp(logits - c), 0))\n if label_idx != -100:\n x = tl.load(logits_ptr + label_idx).to(tl.float32)\n if DO_LOGIT_SCALING:\n x = LOGIT_SCALE * x\n pass\n loss = logsumexp - x\n else:\n loss = 0.0\n tl.store(logsumexp_ptr, logsumexp)\n tl.store(loss_ptr, loss)\n", "category": { "Functionality": [ "Softmax", "Cross Entropy" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/tdrussell/qlora-pipe/blob/6fb7c8eeae52a0e36c41f00628985f29d8330684/kernels/cross_entropy_loss.py" }, { "uuid": "da158db8-4576-47cc-be40-fffdcc99f725", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BS': 16}, num_warps=2), triton.\n Config({'BS': 16}, num_warps=4), triton.Config({'BS': 16}, num_warps=8),\n triton.Config({'BS': 32}, num_warps=2), triton.Config({'BS': 32},\n num_warps=4), triton.Config({'BS': 32}, num_warps=8), triton.Config({\n 'BS': 64}, num_warps=2), triton.Config({'BS': 64}, num_warps=4), triton\n .Config({'BS': 64}, num_warps=8)], key=['S', 'BT'])\n@triton.jit\ndef chunk_rwkv6_fwd_cumsum_kernel(s, oi, oe, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, S: tl.constexpr, BT: tl.constexpr, BS: tl.\n constexpr, HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_s, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_i = tl.where(o_i[:, None] >= o_i[None, :], 1.0, 0.0)\n m_e = tl.where(o_i[:, None] > o_i[None, :], 1.0, 0.0)\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T * S, (T, S), (S, 1), (i_t * BT,\n i_s * BS), (BT, BS), (1, 0))\n p_oi = tl.make_block_ptr(oi + i_bh * T * S, (T, S), (S, 1), (i_t *\n BT, i_s * BS), (BT, BS), (1, 0))\n p_oe = tl.make_block_ptr(oe + i_bh * T * S, (T, S), (S, 1), (i_t *\n BT, i_s * BS), (BT, BS), (1, 0))\n else:\n p_s = tl.make_block_ptr(s + (bos * H + i_h) * S, (T, S), (H * S, 1),\n (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n p_oi = tl.make_block_ptr(oi + (bos * H + i_h) * S, (T, S), (H * S, \n 1), (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n p_oe = tl.make_block_ptr(oe + (bos * H + i_h) * S, (T, S), (H * S, \n 1), (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_oi = tl.dot(m_i, b_s, allow_tf32=False)\n b_oe = tl.dot(m_e, b_s, allow_tf32=False)\n tl.store(p_oi, b_oi.to(p_oi.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_oe, b_oe.to(p_oe.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "8312c2c2-b06b-4313-beab-8941ed39ad2b", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_jagged_elementwise_arithmetic_ops(x_ptr, y_ptr, M: tl.constexpr,\n N: tl.constexpr, stride_row: tl.constexpr, stride_col: tl.constexpr,\n output, thread_block_row_size: tl.constexpr, thread_block_col_size: tl.\n constexpr, ops_func: tl.constexpr) ->None:\n pid = tl.program_id(0)\n num_group_n = (N + thread_block_col_size - 1) // thread_block_col_size\n pid_n = pid % num_group_n\n pid_m = pid // num_group_n\n offset_m = pid_m * thread_block_row_size + tl.arange(0,\n thread_block_row_size)\n offset_n = pid_n * thread_block_col_size + tl.arange(0,\n thread_block_col_size)\n mask = (offset_m[:, None] < M) & (offset_n[None, :] < N)\n offset = offset_m[:, None] * stride_row + offset_n[None, :] * stride_col\n x_ptr += offset\n y_ptr += offset\n x = tl.load(x_ptr, mask=mask)\n y = tl.load(y_ptr, mask=mask)\n if ops_func == 'add':\n z = tensor_elementwise_add(x, y)\n else:\n z = tensor_elementwise_mul(x, y)\n output += offset\n tl.store(output, z, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "e91acd67-c457-4e0b-98c0-f49971d6f6da", "file_name": "simulate.py", "repo_name": "Aalanli/AMDGPUExperiments", "file_path": "simulate.py", "commit_hash": "2a6fd9e1e81d1916e3d87db4dda930e2fa417527", "starcount": 0, "input": "@triton.jit\ndef simulate_kernel(output, n_steps, seed, p, start, block_size: tl.constexpr):\n n_program = tl.num_programs(axis=0)\n pid = tl.program_id(axis=0)\n block_start = pid * block_size\n offsets = block_start + tl.arange(0, block_size)\n state = tl.full([block_size], start, dtype=tl.uint32)\n for _ in range(n_steps):\n this_seed = tl.randint(seed, pid)\n rand = tl.rand(this_seed, offsets)\n state = tl.where(state == 0, state, tl.where(rand < p, state - 1, \n state + 1))\n pid += n_program\n fall_off = state == 0\n prob = tl.sum(fall_off.to(tl.int64))\n tl.store(output + tl.program_id(0), prob)\n", "category": { "Functionality": [ "Elementwise Operations", "Recurrent Neural Networks" ], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Aalanli/AMDGPUExperiments/blob/2a6fd9e1e81d1916e3d87db4dda930e2fa417527/simulate.py" }, { "uuid": "caf594ae-0007-42f3-a11f-df8a6e031d08", "file_name": "triton_fused_local_attn2.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_local_attn2.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q, sm_scale, K_block_ptr, V_block_ptr,\n start_m, offs_m, offs_n, SEQLEN_K: tl.constexpr, WINDOW_SIZE: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, EVEN_MN: tl.\n constexpr, STAGE: tl.constexpr):\n if STAGE == 1:\n lo = start_m * BLOCK_M - WINDOW_SIZE\n hi = start_m * BLOCK_M\n if lo < 0:\n lo = 0\n else:\n lo, hi = start_m * BLOCK_M, (start_m + 1) * BLOCK_M\n lo = tl.multiple_of(lo, BLOCK_M)\n hi = min(hi, SEQLEN_K)\n EVEN_MASK_FREE = EVEN_MN & ((STAGE == 1) | (STAGE == 2))\n K_block_ptr = tl.advance(K_block_ptr, (0, lo))\n V_block_ptr = tl.advance(V_block_ptr, (lo, 0))\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_MASK_FREE:\n k = tl.load(K_block_ptr)\n else:\n k = tl.load(K_block_ptr, boundary_check=(1,), padding_option='zero'\n )\n qk = tl.dot(q, k) * (sm_scale * RCP_LN2)\n if STAGE == 3:\n mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk += tl.where(mask, 0, NEGINF)\n if not EVEN_MASK_FREE:\n qk += tl.where((start_n + offs_n)[None, :] < SEQLEN_K, 0, NEGINF)\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc *= alpha[:, None]\n if EVEN_MASK_FREE:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(1,), padding_option='zero'\n )\n acc += tl.dot(p.to(V_block_ptr.dtype.element_ty), v)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Coalesced", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_local_attn2.py" }, { "uuid": "85d4ae25-63a1-4dfe-83dc-04295de1183a", "file_name": "copy.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/copy.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@eval(\n \"\"\"triton.heuristics({\n 'BLOCK_M': lambda kwargs: min(64, triton.next_power_of_2(kwargs['size_inp_0'])),\n 'BLOCK_N': lambda kwargs: min(64, triton.next_power_of_2(kwargs['size_inp_1'])),\n 'BATCH_STRIDE_INP_IS_1': lambda kwargs: kwargs['batch_stride_inp'] == 1,\n 'STRIDE_INP_0_IS_1': lambda kwargs: kwargs['stride_inp_0'] == 1,\n 'STRIDE_INP_1_IS_1': lambda kwargs: kwargs['stride_inp_1'] == 1,\n 'BATCH_STRIDE_OUT_IS_1': lambda kwargs: kwargs['batch_stride_out'] == 1,\n 'STRIDE_OUT_0_IS_1': lambda kwargs: kwargs['stride_out_0'] == 1,\n 'STRIDE_OUT_1_IS_1': lambda kwargs: kwargs['stride_out_1'] == 1,\n})\"\"\"\n )\n@eval(\n \"\"\"triton.heuristics({\n 'num_warps': lambda kwargs: max(1, min(16, kwargs['BLOCK_M'] * kwargs['BLOCK_N'] // 32)),\n})\"\"\"\n )\n@triton.jit\ndef copy_3d_kernel(output_ptr, input_ptr, bs, size_inp_0, size_inp_1,\n batch_stride_inp, stride_inp_0, stride_inp_1, batch_stride_out,\n stride_out_0, stride_out_1, BATCH_STRIDE_INP_IS_1: tl.constexpr,\n STRIDE_INP_0_IS_1: tl.constexpr, STRIDE_INP_1_IS_1: tl.constexpr,\n BATCH_STRIDE_OUT_IS_1: tl.constexpr, STRIDE_OUT_0_IS_1: tl.constexpr,\n STRIDE_OUT_1_IS_1: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr):\n pid = tl.program_id(0)\n pid_batch = tl.program_id(1)\n grid_m = tl.cdiv(size_inp_0, BLOCK_M)\n grid_n = tl.cdiv(size_inp_1, BLOCK_N)\n pid_m = pid // grid_n\n pid_n = pid - pid_m * grid_n\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n A = input_ptr + (1 if BATCH_STRIDE_INP_IS_1 else batch_stride_inp\n ) * pid_batch + (rm[:, None] * (1 if STRIDE_INP_0_IS_1 else\n stride_inp_0) + rn[None, :] * (1 if STRIDE_INP_1_IS_1 else\n stride_inp_1))\n B = output_ptr + (1 if BATCH_STRIDE_OUT_IS_1 else batch_stride_out\n ) * pid_batch + (rm[:, None] * (1 if STRIDE_OUT_0_IS_1 else\n stride_out_0) + rn[None, :] * (1 if STRIDE_OUT_1_IS_1 else\n stride_out_1))\n mask = (rm < size_inp_0)[:, None] & (rn < size_inp_1)[None, :]\n a = tl.load(A, mask=mask)\n tl.store(B, a, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/copy.py" }, { "uuid": "0ba1eec5-4ae0-4399-a078-20d80cf2ab46", "file_name": "gemm_postop_gelu_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef gelu(x):\n \"\"\"\n GeLU_ activation - Gaussian error linear unit\n\n .. _GeLU: https://arxiv.org/pdf/1606.08415.pdf\n \"\"\"\n return 0.5 * x * (1 + tanh(kAlpha * (x + 0.044715 * x * x * x)))\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py" }, { "uuid": "1e8d66ac-783c-4e08-bacd-8c8629067011", "file_name": "softmax_online_v2_spec_rev.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v2_spec_rev.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n prev_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, prev_multiple, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs).to(output_ptr.dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n for start_n in range(prev_multiple, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n final_m = tl.max(m, 0)\n z = tl.sum(tl.exp(m - final_m) * z)\n m = final_m\n prev_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, TILE_N, TILE_N):\n n_offsets = prev_multiple - start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n for start_n in range(TILE_N, N, TILE_N):\n n_offsets = prev_multiple - start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs).to(output_ptr.dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out)\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v2_spec_rev.py" }, { "uuid": "a454fb7a-be17-4207-aa7f-74a5ac3b9ee8", "file_name": "attn_qk_int8_per_block_hd128_causal.py", "repo_name": "rodjjo/editorium", "file_path": "editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_hd128_causal.py", "commit_hash": "7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q, q_scale, K_ptrs, K_scale_ptr, V_ptrs,\n start_m, BLOCK_M: tl.constexpr, HEAD_DIM: tl.constexpr, BLOCK_N: tl.\n constexpr, STAGE: tl.constexpr, offs_m: tl.constexpr, offs_n: tl.\n constexpr, N_CTX: tl.constexpr):\n if STAGE == 1:\n lo, hi = 0, start_m * BLOCK_M\n elif STAGE == 2:\n lo, hi = start_m * BLOCK_M, (start_m + 1) * BLOCK_M\n lo = tl.multiple_of(lo, BLOCK_M)\n K_scale_ptr += lo // BLOCK_N\n K_ptrs += HEAD_DIM * lo\n V_ptrs += HEAD_DIM * lo\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k_mask = offs_n[None, :] < N_CTX - start_n\n k = tl.load(K_ptrs, mask=k_mask)\n k_scale = tl.load(K_scale_ptr)\n qk = tl.dot(q, k).to(tl.float32) * q_scale * k_scale\n if STAGE == 2:\n mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk = qk + tl.where(mask, 0, -1000000.0)\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n qk -= m_ij[:, None]\n else:\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n qk = qk - m_ij[:, None]\n p = tl.math.exp2(qk)\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp2(m_i - m_ij)\n l_i = l_i * alpha + l_ij\n acc = acc * alpha[:, None]\n v = tl.load(V_ptrs, mask=offs_n[:, None] < N_CTX - start_n)\n p = p.to(tl.float16)\n acc += tl.dot(p, v, out_dtype=tl.float16)\n m_i = m_ij\n K_ptrs += BLOCK_N * HEAD_DIM\n K_scale_ptr += 1\n V_ptrs += BLOCK_N * HEAD_DIM\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Coalesced", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/rodjjo/editorium/blob/7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694/editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_hd128_causal.py" }, { "uuid": "4149e45f-a98a-46f3-9ba5-1d39130b86ec", "file_name": "sparse_linear.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_linear.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.autotune(configs=autotune_configs, key=['col_sparse_dim',\n 'inner_dim', 'sparse_dim'])\n@triton.jit\ndef output_sparse_matmul_kernel(lhs_ptr, rhs_ptr, out_ptr, expert_ends_ptr,\n row_dim: tl.constexpr, col_sparse_dim: tl.constexpr, inner_dim: tl.\n constexpr, sparse_dim: tl.constexpr, padded_sparse_dim: tl.constexpr,\n lhs_stride_row: tl.constexpr, lhs_stride_inner: tl.constexpr,\n rhs_stride_inner: tl.constexpr, rhs_stride_col: tl.constexpr,\n out_stride_row: tl.constexpr, out_stride_col: tl.constexpr, accumulate:\n tl.constexpr, block_size_row: tl.constexpr, block_size_col: tl.\n constexpr, block_size_inner: tl.constexpr, group_size_row: tl.constexpr):\n tl.static_assert(row_dim % block_size_row == 0)\n tl.static_assert(col_sparse_dim % block_size_col == 0)\n tl.static_assert(inner_dim % block_size_inner == 0)\n tl.static_assert(sparse_dim <= padded_sparse_dim)\n pid_row, pid_col = tl.swizzle2d(tl.program_id(axis=0), tl.program_id(\n axis=1), row_dim // block_size_row, col_sparse_dim //\n block_size_col, group_size_row)\n row_offset = pid_row * block_size_row\n col_sparse_offset = pid_col * block_size_col\n sparse_range = tl.arange(0, padded_sparse_dim)\n expert_ends = tl.load(expert_ends_ptr + sparse_range, mask=sparse_range <\n sparse_dim, other=row_dim)\n sparse_index = tl.sum((expert_ends <= row_offset).to(tl.int64))\n if sparse_index == sparse_dim:\n return\n col_dense_offset = col_sparse_offset + sparse_index * col_sparse_dim\n row_range = tl.arange(0, block_size_row)[:, None]\n col_range = tl.arange(0, block_size_col)[None, :]\n inner_range = tl.arange(0, block_size_inner)\n lhs_ptr += (row_offset + row_range) * lhs_stride_row + inner_range[None, :\n ] * lhs_stride_inner\n rhs_ptr += inner_range[:, None] * rhs_stride_inner + (col_dense_offset +\n col_range) * rhs_stride_col\n out_ptr += (row_offset + row_range) * out_stride_row + (col_sparse_offset +\n col_range) * out_stride_col\n out = tl.dot(tl.load(lhs_ptr), tl.load(rhs_ptr), out_dtype=tl.float32)\n for k in range(1, inner_dim // block_size_inner):\n lhs_ptr += block_size_inner * lhs_stride_inner\n rhs_ptr += block_size_inner * rhs_stride_inner\n out += tl.dot(tl.load(lhs_ptr), tl.load(rhs_ptr))\n if accumulate:\n out += tl.load(out_ptr)\n tl.store(out_ptr, out)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Blocked Access", "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_linear.py" }, { "uuid": "c4bde555-085f-4158-9b7e-4d8f039195cf", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef mlstm_matmul_kernel_df(dF, F, NH: tl.constexpr, S: tl.constexpr):\n bh_id = tl.program_id(0)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n batch_offset_f = batch_id * NH * S + head_id * S\n offset_f = tl.arange(0, S)\n df = tl.load(dF + batch_offset_f + offset_f, offset_f < S)\n df = tl.associative_scan(df, 0, scan_add_op)\n f = tl.load(F + batch_offset_f + offset_f, offset_f < S)\n df = tl.sigmoid(-f) * df\n tl.store(dF + batch_offset_f + offset_f, df, offset_f < S)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations", "Activation Functions" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "5b75cd56-ee47-4e6f-a821-a5604495112c", "file_name": "test_triton_varargs.py", "repo_name": "facebookresearch/xformers", "file_path": "tests/test_triton_varargs.py", "commit_hash": "a2f37f8c5f4e3ae0d3459a92e42cd1aeb45b03bc", "starcount": 0, "input": "@triton.jit\ndef sumN(output_ptr, scaling_ptr, *inputs, BLOCK_SIZE: tl.constexpr):\n offset = tl.arange(0, BLOCK_SIZE)\n output = tl.zeros([BLOCK_SIZE], tl.float32)\n scaling: 'VAR_ARGS_ARRAY'\n for i in range(len(scaling)):\n scaling[i] = tl.load(scaling_ptr + i)\n for i in range(2):\n for j in range(len(inputs)):\n output = output + tl.load(inputs[j] + offset) * scaling[j]\n tl.store(output_ptr + offset, output)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/facebookresearch/xformers/blob/a2f37f8c5f4e3ae0d3459a92e42cd1aeb45b03bc/tests/test_triton_varargs.py" }, { "uuid": "f62e413e-399f-406a-a6fb-44c3e664e00d", "file_name": "dw.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/dropconnect/dw.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.jit\ndef dropconnect_dx_kernel(dy_ptr, x_ptr, dw_ptr, seed, M, K, N, stride_dym,\n stride_dyn, stride_xm, stride_xk, stride_dm, stride_dk, stride_dn,\n stride_dwk, stride_dwn, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr, ALLOWTF32: tl.constexpr):\n \"\"\" \n dY_m = Y.grad\n dO_m = dY_m.view(M,1,N).broadcast_to(M,K,N)\n dWD_m = dO_m * x_m_cast\n dw_m_cast = dWD_m * D\n dw_m = dw_m_cast.sum(dim=0) \"\"\"\n pid_k = tl.program_id(0)\n pid_n = tl.program_id(1)\n offset_m = 0\n offset_k = pid_k * BLOCK_SIZE_K\n offset_n = pid_n * BLOCK_SIZE_N\n dy_offsets = block_offsets_2d(M, N, stride_dym, stride_dyn, offset_m,\n offset_n, BLOCK_SIZE_M, BLOCK_SIZE_N)\n x_offsets = block_offsets_2d(M, K, stride_xm, stride_xk, offset_m,\n offset_k, BLOCK_SIZE_M, BLOCK_SIZE_K)\n d_offsets = block_offsets_3d(M, K, N, stride_dm, stride_dk, stride_dn,\n offset_m, offset_k, offset_n, BLOCK_SIZE_M, BLOCK_SIZE_K, BLOCK_SIZE_N)\n dy_offsets = dy_offsets.reshape(BLOCK_SIZE_M, 1, BLOCK_SIZE_N)\n x_offsets = x_offsets.reshape(BLOCK_SIZE_M, BLOCK_SIZE_K, 1)\n offs_m = tl.arange(0, BLOCK_SIZE_M)\n dy_tile = dy_ptr + dy_offsets\n x_tile = x_ptr + x_offsets\n ASM: tl.constexpr = 'cvt.rna.tf32.f32 $0, $1;'\n accumulator = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_N), dtype=tl.float32)\n for m in range(0, tl.cdiv(M, BLOCK_SIZE_M)):\n random_masks = tl.random.rand(seed, d_offsets) > 0.5\n m_mask = offs_m[:, None, None] < M - m * BLOCK_SIZE_M\n dy_load = tl.load(dy_tile, mask=m_mask, other=0.0)\n x_load = tl.load(x_tile, mask=m_mask, other=0.0)\n dy = tl.where(random_masks, dy_load, 0.0)\n wd = tl.where(random_masks, x_load, 0.0)\n mul = dy * wd\n accumulator += tl.sum(mul, axis=0)\n dy_tile += BLOCK_SIZE_M * stride_dym\n x_tile += BLOCK_SIZE_M * stride_xm\n d_offsets += BLOCK_SIZE_M * stride_dm\n dw_offset, dw_mask = block_offsets_2d(K, N, stride_dwk, stride_dwn,\n offset_k, offset_n, BLOCK_SIZE_K, BLOCK_SIZE_N, True)\n dw_tile = dw_ptr + dw_offset\n dw = accumulator.to(dw_tile.dtype.element_ty)\n tl.store(dw_tile, dw, mask=dw_mask)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/dropconnect/dw.py" }, { "uuid": "0ef41aca-fbb5-44bb-ae73-f97ff2bac77e", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4)], key=['BT', 'BK'])\n@triton.jit\ndef fused_chunk_delta_rule_fwd_kernel(q, k, v, v_new, d, o, initial_state,\n final_state, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, B, H, T, scale,\n BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, DK: tl.constexpr,\n DV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE:\n tl.constexpr, CHECK: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, DK), (s_k_t, s_k_d), (0, \n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (DK, T), (s_k_d, s_k_t), (i_k *\n BK, 0), (BK, BT), (0, 1))\n p_d = tl.make_block_ptr(d + i_bh * s_k_h, (T, DK), (s_k_t, s_k_d), (0, \n i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, DV), (s_v_t, s_v_d), (0, \n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (i_bh + i_k * B * H) * s_v_h, (T, DV), (\n s_v_t, s_v_d), (0, i_v * BV), (BT, BV), (1, 0))\n p_v_new = tl.make_block_ptr(v_new + i_bh * s_v_h, (T, DV), (s_v_t,\n s_v_d), (0, i_v * BV), (BT, BV), (1, 0))\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(initial_state + i_bh * DK * DV, (DK, DV), (\n DV, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n for i in range(0, tl.cdiv(T, BT)):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_d = tl.load(p_d, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_k.dtype)\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n b_v_prime = tl.dot(b_d, b_h.to(b_q.dtype), allow_tf32=False)\n b_v = b_v - b_v_prime\n tl.store(p_v_new, b_v.to(p_v.dtype.element_ty), boundary_check=(0, 1))\n b_o = tl.dot(b_s.to(b_q.dtype), b_v.to(b_q.dtype), allow_tf32=False)\n if CHECK and i == 0:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_k, b_v.to(b_k.dtype), allow_tf32=False)\n else:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_k, b_v.to(b_k.dtype), allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_q = tl.advance(p_q, (BT, 0))\n p_k = tl.advance(p_k, (0, BT))\n p_v = tl.advance(p_v, (BT, 0))\n p_v_new = tl.advance(p_v_new, (BT, 0))\n p_o = tl.advance(p_o, (BT, 0))\n p_d = tl.advance(p_d, (BT, 0))\n if STORE_FINAL_STATE:\n p_final = tl.make_block_ptr(final_state + i_bh * DK * DV, (DK, DV),\n (DV, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_final, b_h.to(p_final.dtype.element_ty), boundary_check=\n (0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Coalesced", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/fused_chunk.py" }, { "uuid": "07031280-262d-4433-ae3a-7a2222f9099b", "file_name": "gemm_postop_gelu_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32), triton.Config({'BLOCK_SIZE_M': \n 256, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4,\n 'grf_mode': 'large'}, num_stages=3, num_warps=32), triton.Config({\n 'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32\n ), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =2, num_warps=32), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': \n 128, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'},\n num_stages=2, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers_batched(a_ptr, b_ptr, c_ptr, B: tl.\n constexpr, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr, stride_az:\n tl.constexpr, stride_am: tl.constexpr, stride_ak: tl.constexpr,\n stride_bz: tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.\n constexpr, stride_cz: tl.constexpr, stride_cm: tl.constexpr, stride_cn:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n bid = tl.program_id(axis=0)\n pid = tl.program_id(axis=1)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offset_a = bid.to(tl.int64) * stride_az\n offset_b = bid.to(tl.int64) * stride_bz\n a_block_ptr = tl.make_block_ptr(base=a_ptr + offset_a, shape=(M, K),\n strides=(stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr + offset_b, shape=(K, N),\n strides=(stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c = gelu(accumulator)\n offset_c = bid.to(tl.int64) * stride_cz\n c_block_ptr = tl.make_block_ptr(base=c_ptr + offset_c, shape=(M, N),\n strides=(stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, \n pid_n * BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N),\n order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication", "Activation Functions" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Blocked Access", "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py" }, { "uuid": "1fa87111-7ad0-4833-a0b9-b14824dfba0a", "file_name": "dequant_kernel.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/quant/dequant_kernel.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef dequantize(inputs, nf4_lut):\n \"\"\"Dequantizes the nf4 data to bfloat16\"\"\"\n return tl.load(nf4_lut + inputs)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "bf16" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/quant/dequant_kernel.py" }, { "uuid": "c184d15a-84bd-4dc9-90d1-69aa80226eab", "file_name": "gemm_postop_addmatrix_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_postop_addmatrix_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32), triton.Config({'BLOCK_SIZE_M': \n 256, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4,\n 'grf_mode': 'large'}, num_stages=3, num_warps=32), triton.Config({\n 'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32\n ), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =2, num_warps=32), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': \n 128, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'},\n num_stages=2, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers_batched(a_ptr, b_ptr, c_ptr, d_ptr, B:\n tl.constexpr, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr,\n stride_az: tl.constexpr, stride_am: tl.constexpr, stride_ak: tl.\n constexpr, stride_bz: tl.constexpr, stride_bk: tl.constexpr, stride_bn:\n tl.constexpr, stride_cz: tl.constexpr, stride_cm: tl.constexpr,\n stride_cn: tl.constexpr, stride_dz: tl.constexpr, stride_dm: tl.\n constexpr, stride_dn: tl.constexpr, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr):\n bid = tl.program_id(axis=0)\n pid = tl.program_id(axis=1)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offset_a = bid.to(tl.int64) * stride_az\n offset_b = bid.to(tl.int64) * stride_bz\n a_block_ptr = tl.make_block_ptr(base=a_ptr + offset_a, shape=(M, K),\n strides=(stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr + offset_b, shape=(K, N),\n strides=(stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n offset_d = bid.to(tl.int64) * stride_dz\n d_block_ptr = tl.make_block_ptr(base=d_ptr + offset_d, shape=(M, N),\n strides=(stride_dm, stride_dn), offsets=(pid_m * BLOCK_SIZE_M, \n pid_n * BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N),\n order=(1, 0))\n d = tl.load(d_block_ptr, boundary_check=(0, 1))\n c = accumulator + d\n offset_c = bid.to(tl.int64) * stride_cz\n c_block_ptr = tl.make_block_ptr(base=c_ptr + offset_c, shape=(M, N),\n strides=(stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, \n pid_n * BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N),\n order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_postop_addmatrix_benchmark.py" }, { "uuid": "e1abcb7f-d624-4f0f-adf5-1a9471e35d14", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=MATMUL_CONFIGS, key=['m_key', 'n_key', 'k_key'])\n@triton.jit\ndef _kernel_matmul_fp8_row(A_ptr, B_ptr, C_ptr, M, N, K, m_key, n_key,\n k_key, A_scale, B_scale, Bias, stride_am, stride_ak, stride_bn,\n stride_bk, stride_cm, stride_cn, dot_out_dtype: tl.constexpr,\n allow_tf32: tl.constexpr, fp8_fast_accum: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.\n constexpr, SPLIT_K: tl.constexpr, USE_BIAS: tl.constexpr, AB_DTYPE: tl.\n constexpr, NUM_SMS: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with row-wise scales\n\n performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles.\n\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n m_key (int): Autotuning key for M dimension of input tensor.\n n_key (int): Autotuning key for N dimension of input tensor.\n k_key (int): Autotuning key for K dimension of input tensor.\n A_scale (TensorWrapper): [M] reciprocal scale tensor per row. A * A_scale = original A.\n B_scale (TensorWrapper): [N] reciprocal scale tensor per row. B * B_scale = original B.\n Bias (tensorWrapper): [N] Optional bias tensor.\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n USE_BIAS (bool): Whether to use bias.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n start_pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_M)\n num_pid_n = tl.cdiv(N, BLOCK_N)\n k_tiles = tl.cdiv(K, BLOCK_K)\n num_tiles = num_pid_m * num_pid_n\n tiles_per_SM = num_tiles // NUM_SMS\n if start_pid < num_tiles % NUM_SMS:\n tiles_per_SM += 1\n tile_id = start_pid - NUM_SMS\n ki = -1\n offs_k_for_mask = tl.arange(0, BLOCK_K)\n num_pid_in_group = GROUP_M * num_pid_n\n pid_m = 0\n pid_n = 0\n offs_am = tl.arange(0, BLOCK_M)\n offs_bn = tl.arange(0, BLOCK_N)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n for _ in range(0, k_tiles * tiles_per_SM):\n ki = tl.where(ki == k_tiles - 1, 0, ki + 1)\n if ki == 0:\n tile_id += NUM_SMS\n group_id = tile_id // num_pid_in_group\n first_pid_m = group_id * GROUP_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_M)\n pid_m = first_pid_m + tile_id % group_size_m\n pid_n = tile_id % num_pid_in_group // group_size_m\n start_m = pid_m * BLOCK_M\n start_n = pid_n * BLOCK_N\n offs_am = start_m + tl.arange(0, BLOCK_M)\n offs_bn = start_n + tl.arange(0, BLOCK_N)\n offs_am = tl.where(offs_am < M, offs_am, 0)\n offs_bn = tl.where(offs_bn < N, offs_bn, 0)\n offs_am = tl.max_contiguous(tl.multiple_of(offs_am, BLOCK_M),\n BLOCK_M)\n offs_bn = tl.max_contiguous(tl.multiple_of(offs_bn, BLOCK_N),\n BLOCK_N)\n offs_k = ki * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] * stride_ak\n )\n B = B_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] * stride_bn\n )\n a = tl.load(A, mask=offs_k_for_mask[None, :] < K - ki * BLOCK_K,\n other=0.0)\n b = tl.load(B, mask=offs_k_for_mask[:, None] < K - ki * BLOCK_K,\n other=0.0)\n acc = tl.dot(a, b, acc, out_dtype=dot_out_dtype, allow_tf32=allow_tf32)\n if ki == k_tiles - 1:\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n a_scale = tl.load(A_scale + rm, mask=rm < M)\n b_scale = tl.load(B_scale + rn, mask=rn < N)\n scale = a_scale[:, None] * b_scale[None, :]\n acc *= scale\n if USE_BIAS:\n bias = tl.load(Bias + rn, mask=rn < N)\n acc += bias[None, :]\n acc = acc.to(C_ptr.dtype.element_ty)\n C = C_ptr + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n tl.store(C, acc, mask=mask)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "2923d2d3-cffb-4408-8fa9-e9794bb2be61", "file_name": "05-layer-norm.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/05-layer-norm.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_bwd_dwdb(DW, DB, FINAL_DW, FINAL_DB, M, N, BLOCK_SIZE_M: tl\n .constexpr, BLOCK_SIZE_N: tl.constexpr):\n pid = tl.program_id(0)\n cols = pid * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n dw = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n db = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for i in range(0, M, BLOCK_SIZE_M):\n rows = i + tl.arange(0, BLOCK_SIZE_M)\n mask = (rows[:, None] < M) & (cols[None, :] < N)\n offs = rows[:, None] * N + cols[None, :]\n dw += tl.load(DW + offs, mask=mask, other=0.0)\n db += tl.load(DB + offs, mask=mask, other=0.0)\n sum_dw = tl.sum(dw, axis=0)\n sum_db = tl.sum(db, axis=0)\n tl.store(FINAL_DW + cols, sum_dw, mask=cols < N)\n tl.store(FINAL_DB + cols, sum_db, mask=cols < N)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/05-layer-norm.py" }, { "uuid": "d99050b5-9c96-4233-a447-a34ac46ac1f1", "file_name": "_semi_structured_conversions.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/_semi_structured_conversions.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _sparse_semi_structured_to_dense_kernel(sparse_ptr, meta_reordered_ptr,\n dense_ptr, m, k, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n group, interweave = 32, 4\n dest_row = row_idx // 32 * 32 + row_idx % 8 * 4 + row_idx % group // 8\n if dest_row % 2 == 0:\n dest_row_ = (row_idx // 32 * 32 + row_idx % 8 * 4 + row_idx % group //\n 8 + tl.arange(0, BLOCK_SIZE // 16) % 2)\n dest_col_ = tl.arange(0, BLOCK_SIZE // 16) // 2 * 2\n index = dest_col_ // 2 * m * 2 + dest_row_ * 2 + dest_col_ % 2\n meta = tl.load(meta_reordered_ptr + index, mask=tl.arange(0, \n BLOCK_SIZE // 16) < k // 16, other=-float('inf'))\n else:\n dest_row_ = (row_idx // 32 * 32 + row_idx % 8 * 4 + row_idx % group //\n 8 - (tl.arange(0, BLOCK_SIZE // 16) + 1) % 2)\n dest_col_ = tl.arange(0, BLOCK_SIZE // 16) // 2 * 2 + 1\n index = dest_col_ // 2 * m * 2 + dest_row_ * 2 + dest_col_ % 2\n meta = tl.load(meta_reordered_ptr + index, mask=tl.arange(0, \n BLOCK_SIZE // 16) < k // 16, other=-float('inf'))\n meta_20 = (meta & 3) + (row_idx * k + 16 * tl.arange(0, BLOCK_SIZE // 16))\n meta_21 = (meta >> 2 & 3) + (row_idx * k + 16 * tl.arange(0, BLOCK_SIZE //\n 16))\n meta_22 = (meta >> 4 & 3) + (row_idx * k + 16 * tl.arange(0, BLOCK_SIZE //\n 16) + 4)\n meta_23 = (meta >> 6 & 3) + (row_idx * k + 16 * tl.arange(0, BLOCK_SIZE //\n 16) + 4)\n meta_24 = (meta >> 8 & 3) + (row_idx * k + 16 * tl.arange(0, BLOCK_SIZE //\n 16) + 8)\n meta_25 = (meta >> 10 & 3) + (row_idx * k + 16 * tl.arange(0, \n BLOCK_SIZE // 16) + 8)\n meta_26 = (meta >> 12 & 3) + (row_idx * k + 16 * tl.arange(0, \n BLOCK_SIZE // 16) + 12)\n meta_27 = (meta >> 14 & 3) + (row_idx * k + 16 * tl.arange(0, \n BLOCK_SIZE // 16) + 12)\n row0 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16), mask=tl.arange(0, BLOCK_SIZE // 16) < k // 16,\n other=-float('inf'))\n row1 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 1, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n row2 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 2, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n row3 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 3, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n row4 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 4, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n row5 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 5, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n row6 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 6, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n row7 = tl.load(sparse_ptr + row_idx * k // 2 + 8 * tl.arange(0, \n BLOCK_SIZE // 16) + 7, mask=tl.arange(0, BLOCK_SIZE // 16) < k // \n 16, other=-float('inf'))\n tl.store(dense_ptr + meta_20, row0, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_21, row1, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_22, row2, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_23, row3, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_24, row4, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_25, row5, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_26, row6, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n tl.store(dense_ptr + meta_27, row7, mask=tl.arange(0, BLOCK_SIZE // 16) <\n k // 16)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Transposed Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/_semi_structured_conversions.py" }, { "uuid": "0fff7131-f1c9-4588-b8ed-1ddc2f4a032b", "file_name": "mas_triton.py", "repo_name": "uthree/tts_impl", "file_path": "src/tts_impl/functional/monotonic_align/mas_triton.py", "commit_hash": "a9d9a66b26a0de4694e502dedfdff7be26d99ddd", "starcount": 0, "input": "@triton.jit\ndef _maximum_path(path, value, t_x, t_y, B, T, S, max_neg_val, BLOCK_SIZE_X:\n tl.constexpr):\n batch = tl.program_id(axis=0)\n path += batch * T * S\n value += batch * T * S\n x_length = tl.load(t_x + batch)\n y_length = tl.load(t_y + batch)\n offs_prev = tl.arange(0, BLOCK_SIZE_X)\n init = tl.where(offs_prev == 0, tl.load(value), max_neg_val)\n tl.store(value + offs_prev * S, init, mask=offs_prev < x_length)\n for j in range(1, y_length, 1):\n v_cur = tl.load(value + offs_prev * S + (j - 1), mask=offs_prev <\n x_length, other=max_neg_val)\n v_prev = tl.load(value + (offs_prev - 1) * S + (j - 1), mask=(0 <\n offs_prev) & (offs_prev < x_length), other=max_neg_val)\n v = tl.maximum(v_cur, v_prev) + tl.load(value + offs_prev * S + j,\n mask=offs_prev < x_length)\n tl.store(value + offs_prev * S + j, v, mask=offs_prev < x_length)\n index = x_length - 1\n for j in range(y_length - 1, -1, -1):\n tl.store(path + index * S + j, 1)\n if index > 0:\n v_left = tl.load(value + index * S + j - 1)\n v_leftdown = tl.load(value + (index - 1) * S + j - 1)\n if v_left < v_leftdown:\n index += -1\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/uthree/tts_impl/blob/a9d9a66b26a0de4694e502dedfdff7be26d99ddd/src/tts_impl/functional/monotonic_align/mas_triton.py" }, { "uuid": "031b0c3d-1c3a-4448-87a8-dbf9c6afc3b9", "file_name": "cross_entropy_loss.py", "repo_name": "tdrussell/qlora-pipe", "file_path": "kernels/cross_entropy_loss.py", "commit_hash": "6fb7c8eeae52a0e36c41f00628985f29d8330684", "starcount": 0, "input": "@triton.heuristics({'DO_LOGIT_SCALING': lambda args: args['DO_LOGIT_SCALING']})\n@triton.jit\ndef _cross_entropy_backward(logits_ptr, logits_row_stride, dloss_ptr,\n dloss_row_stride, logsumexp_ptr, labels_ptr, VOCAB_SIZE: tl.constexpr,\n BLOCK_SIZE: tl.constexpr, DO_LOGIT_SCALING: tl.constexpr, LOGIT_SCALE:\n tl.constexpr):\n \"\"\"\n CE_i = -y log(P) = y * (log[sum(exp(x))] - x)\n dC/dx = d/dx (y * log[sum(exp(x))] - x * y)\n\n From https://en.wikipedia.org/wiki/LogSumExp\n d/dx logsumexp = exp(x) / sum(exp(x)) = softmax(x)\n\n dC/dx = y * exp(x) / sum(exp(x)) - d/dx (x * y)\n dC/dx = y * exp[ log[exp(x) / sum(exp(x))] ] using x = exp(log(x)) trick\n dC/dx = y * exp[x - logsumexp] - d/dx (x * y)\n\n If y == 0: dC/dx = 0\n If y == 1 and x == label: dC/dlabel = exp[x - logsumexp] - 1\n If y == 1 and x != label: dC/dx = exp[x - logsumexp]\n \"\"\"\n row_idx = tl.program_id(0)\n block_idx = tl.program_id(1)\n logits_ptr += row_idx * logits_row_stride.to(tl.int64)\n dloss_ptr += row_idx * dloss_row_stride\n col_offsets = block_idx * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < VOCAB_SIZE\n label_idx = tl.load(labels_ptr + row_idx).to(tl.int32)\n if label_idx != -100:\n dloss = tl.load(dloss_ptr)\n else:\n dloss = 0.0\n x = tl.load(logits_ptr + col_offsets, mask=mask, other=-float('inf')).to(tl\n .float32)\n if DO_LOGIT_SCALING:\n x = LOGIT_SCALE * x\n pass\n logsumexp = tl.load(logsumexp_ptr + row_idx)\n y = tl.exp(x - logsumexp)\n y = tl.where(col_offsets == label_idx, y - 1.0, y)\n if DO_LOGIT_SCALING:\n y = LOGIT_SCALE * y\n pass\n tl.store(logits_ptr + col_offsets, dloss * y, mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/tdrussell/qlora-pipe/blob/6fb7c8eeae52a0e36c41f00628985f29d8330684/kernels/cross_entropy_loss.py" }, { "uuid": "0269e925-e1dc-4528-851c-455458868afd", "file_name": "sb_varlen_fwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_fwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.jit\ndef load_kv(K_blk_ptrs, V_blk_ptrs, N_mask, NO_N_MASK, D_mask, NO_D_MASK:\n tl.constexpr):\n if NO_D_MASK:\n if NO_N_MASK:\n k = tl.load(K_blk_ptrs)\n v = tl.load(V_blk_ptrs)\n else:\n k = tl.load(K_blk_ptrs, mask=N_mask[:, None])\n v = tl.load(V_blk_ptrs, mask=N_mask[:, None])\n else:\n mask = N_mask[:, None] & D_mask[None, :]\n k = tl.load(K_blk_ptrs, mask=mask)\n v = tl.load(V_blk_ptrs, mask=mask)\n return k, v\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_fwd.py" }, { "uuid": "d237c845-8362-47df-b7e1-eaff14494c4f", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_B': 32, 'BLOCK_SIZE_E':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_B': 64,\n 'BLOCK_SIZE_E': 32}, num_stages=2, num_warps=4), triton.Config({\n 'BLOCK_SIZE_B': 32, 'BLOCK_SIZE_E': 64}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_B': 64, 'BLOCK_SIZE_E': 64}, num_stages=2,\n num_warps=4)], key=['H', 'B', 'D', 'E'])\n@triton.jit\ndef mlp_wide_kernel_bwd2(x_ptr, w1_ptr, w2_ptr, o_ptr, dx_ptr, dw1_ptr,\n dw2_ptr, do_ptr, H, B, D: tl.constexpr, E, stride_xb, stride_xd,\n stride_w1d, stride_w1e, stride_w2e, stride_w2d, stride_ob, stride_od,\n stride_dxb, stride_dxd, stride_dw1d, stride_dw1e, stride_dw2e,\n stride_dw2d, stride_dob, stride_dod, BLOCK_SIZE_B: tl.constexpr,\n BLOCK_SIZE_E: tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp\n Z = X @ W1, H = f(Z), O = H @ W2\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n - dX has shape (B, D)\n - dW1 has shape (D, E)\n - dW2 has shape (E, D)\n - dO has shape (B, D)\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_x_w = 0\n batch_groups_e = tl.cdiv(E, BLOCK_SIZE_E)\n batch_groups_b = tl.cdiv(B, BLOCK_SIZE_B)\n idx = pid % (batch_groups_e + batch_groups_b)\n pid_h = pid // (batch_groups_e + batch_groups_b)\n TARGET_TYPE = x_ptr.type.element_ty\n offs_b = tl.arange(0, BLOCK_SIZE_B)\n offs_d = tl.arange(0, D)\n offs_e = tl.arange(0, BLOCK_SIZE_E)\n if idx >= batch_groups_e:\n pid_b = idx - batch_groups_e\n dx_ptrs = dx_ptr + ((pid_h * B + pid_b * BLOCK_SIZE_B + offs_b[:,\n None]) * stride_dxb + offs_d[None, :] * stride_dxd)\n dx_mask = (offs_b[:, None] < B - pid_b * BLOCK_SIZE_B) & (offs_d[\n None, :] < D)\n dx = tl.zeros((BLOCK_SIZE_B, D), dtype=tl.float32)\n dx = _mlp_wide_kernel_bwd_dx(dx, pid_h, pid_b, x_ptr, w1_ptr,\n w2_ptr, o_ptr, dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D, E,\n stride_xb, stride_xd, stride_w1d, stride_w1e, stride_w2e,\n stride_w2d, stride_ob, stride_od, stride_dxb, stride_dxd,\n stride_dw1d, stride_dw1e, stride_dw2e, stride_dw2d, stride_dob,\n stride_dod, BLOCK_SIZE_B, BLOCK_SIZE_E, ACTIVATION)\n tl.store(dx_ptrs, dx.to(TARGET_TYPE), mask=dx_mask)\n else:\n pid_e = idx\n dw1_ptrs = dw1_ptr + ((pid_h * D + offs_d[:, None]) * stride_dw1d +\n (pid_e * BLOCK_SIZE_E + offs_e[None, :]) * stride_dw1e)\n dw1_mask = (offs_d[:, None] < D) & (offs_e[None, :] < E - pid_e *\n BLOCK_SIZE_E)\n dw2_ptrs = dw2_ptr + ((pid_h * E + pid_e * BLOCK_SIZE_E + offs_e[:,\n None]) * stride_dw2e + offs_d[None, :] * stride_dw2d)\n dw2_mask = (offs_e[:, None] < E - pid_e * BLOCK_SIZE_E) & (offs_d[\n None, :] < D)\n dw1 = tl.zeros((D, BLOCK_SIZE_E), dtype=tl.float32)\n dw2 = tl.zeros((BLOCK_SIZE_E, D), dtype=tl.float32)\n dw1, dw2 = _mlp_wide_kernel_bwd_dw1w2(dw1, dw2, pid_h, pid_e, x_ptr,\n w1_ptr, w2_ptr, o_ptr, dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B,\n D, E, stride_xb, stride_xd, stride_w1d, stride_w1e, stride_w2e,\n stride_w2d, stride_ob, stride_od, stride_dxb, stride_dxd,\n stride_dw1d, stride_dw1e, stride_dw2e, stride_dw2d, stride_dob,\n stride_dod, BLOCK_SIZE_B, BLOCK_SIZE_E, ACTIVATION)\n tl.store(dw1_ptrs, dw1.to(TARGET_TYPE), mask=dw1_mask)\n tl.store(dw2_ptrs, dw2.to(TARGET_TYPE), mask=dw2_mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "a20e0fd8-9354-44cf-b64c-1476d6ce796a", "file_name": "fused_norm_gate.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_norm_gate.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'RECOMPUTE_OUTPUT': lambda args: args['Y'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N', 'HAS_DRESIDUAL', 'STORE_DRESIDUAL',\n 'IS_RMS_NORM', 'HAS_BIAS'])\n@triton.jit\ndef layer_norm_bwd_kernel(X, O, W, B, Y, DY, DX, DO, DW, DB, DRESIDUAL,\n DRESIDUAL_IN, Mean, Rstd, stride_x_row, stride_y_row, stride_dy_row,\n stride_dx_row, stride_dres_row, stride_dres_in_row, M, N, eps,\n rows_per_program, IS_RMS_NORM: tl.constexpr, BLOCK_N: tl.constexpr,\n HAS_DRESIDUAL: tl.constexpr, STORE_DRESIDUAL: tl.constexpr, HAS_WEIGHT:\n tl.constexpr, HAS_BIAS: tl.constexpr, RECOMPUTE_OUTPUT: tl.constexpr):\n row_block_id = tl.program_id(0)\n row_start = row_block_id * rows_per_program\n cols = tl.arange(0, BLOCK_N)\n mask = cols < N\n X += row_start * stride_x_row\n O += row_start * stride_x_row\n if HAS_DRESIDUAL:\n DRESIDUAL += row_start * stride_dres_row\n if STORE_DRESIDUAL:\n DRESIDUAL_IN += row_start * stride_dres_in_row\n DY += row_start * stride_dy_row\n DX += row_start * stride_dx_row\n DO += row_start * stride_dx_row\n if RECOMPUTE_OUTPUT:\n Y += row_start * stride_y_row\n if HAS_WEIGHT:\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n dw = tl.zeros((BLOCK_N,), dtype=tl.float32)\n if RECOMPUTE_OUTPUT and HAS_BIAS:\n b = tl.load(B + cols, mask=mask, other=0.0).to(tl.float32)\n if HAS_BIAS:\n db = tl.zeros((BLOCK_N,), dtype=tl.float32)\n row_end = min((row_block_id + 1) * rows_per_program, M)\n for row in range(row_start, row_end):\n x = tl.load(X + cols, mask=mask, other=0).to(tl.float32)\n o = tl.load(O + cols, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + cols, mask=mask, other=0).to(tl.float32)\n if not IS_RMS_NORM:\n mean = tl.load(Mean + row)\n rstd = tl.load(Rstd + row)\n xhat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n xhat = tl.where(mask, xhat, 0.0)\n y = xhat * w if HAS_WEIGHT else xhat\n if HAS_BIAS:\n y = y + b\n if RECOMPUTE_OUTPUT:\n tl.store(Y + cols, y, mask=mask)\n sigmoid_o = tl.sigmoid(o)\n do = dy * y * (sigmoid_o + o * sigmoid_o * (1 - sigmoid_o))\n dy = dy * o * sigmoid_o\n wdy = dy\n if HAS_WEIGHT:\n wdy = dy * w\n dw += dy * xhat\n if HAS_BIAS:\n db += dy\n if not IS_RMS_NORM:\n c1 = tl.sum(xhat * wdy, axis=0) / N\n c2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * c1 + c2)) * rstd\n else:\n c1 = tl.sum(xhat * wdy, axis=0) / N\n dx = (wdy - xhat * c1) * rstd\n if HAS_DRESIDUAL:\n dres = tl.load(DRESIDUAL + cols, mask=mask, other=0).to(tl.float32)\n dx += dres\n if STORE_DRESIDUAL:\n tl.store(DRESIDUAL_IN + cols, dx, mask=mask)\n tl.store(DX + cols, dx, mask=mask)\n tl.store(DO + cols, do, mask=mask)\n X += stride_x_row\n O += stride_x_row\n if HAS_DRESIDUAL:\n DRESIDUAL += stride_dres_row\n if STORE_DRESIDUAL:\n DRESIDUAL_IN += stride_dres_in_row\n if RECOMPUTE_OUTPUT:\n Y += stride_y_row\n DY += stride_dy_row\n DX += stride_dx_row\n DO += stride_dx_row\n if HAS_WEIGHT:\n tl.store(DW + row_block_id * N + cols, dw, mask=mask)\n if HAS_BIAS:\n tl.store(DB + row_block_id * N + cols, db, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_norm_gate.py" }, { "uuid": "d5f138ed-d6b1-4147-92bd-4d9d2bf1a5a2", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'NV': lambda args: triton.cdiv(args['V'], args['BV']),\n 'OUTPUT_ATTENTIONS': lambda args: args['attn'] is not None})\n@triton.jit\ndef parallel_simple_gla_fwd_kernel(q, k, v, g, o, attn, s_k_h, s_k_t, s_v_h,\n s_v_t, scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BS: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, NV: tl.constexpr, OUTPUT_ATTENTIONS: tl.\n constexpr):\n i_kv, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_k, i_v = i_kv // NV, i_kv % NV\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(attn + (i_k * B * H + i_bh) * T * T, (T, T),\n (T, 1), (i_t * BT, 0), (BT, BS), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n for i_s in range(0, i_t * BT, BS):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (1, s_k_t), (i_k *\n BK, i_s), (BK, BS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, 1), (i_s,\n i_v * BV), (BS, BV), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_s,), (BS,), (0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_gn = tl.load(g + i_bh * T + min(i_s + BS, T) - 1)\n b_gp = tl.load(g + i_bh * T + i_s - 1) if i_s % BT > 0 else 0.0\n b_kg = (b_k * tl.exp(b_gn - b_g)).to(b_k.dtype)\n b_s = tl.dot(b_q, b_kg, allow_tf32=False)\n if i_s > 0:\n b_o = b_o * tl.exp(b_gn - b_gp)\n b_o += tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n if OUTPUT_ATTENTIONS:\n tl.store(p_a, b_s.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n p_a = tl.advance(p_a, (0, BS))\n tl.debug_barrier()\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,), (0,))\n b_gq = tl.load(p_g, boundary_check=(0,))\n b_o *= tl.exp(b_gq)[:, None]\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(attn + (i_k * B * H + i_bh) * T * T, (T, T),\n (T, 1), (i_t * BT, i_t * BT), (BT, BS), (1, 0))\n o_q = i_t * BT + tl.arange(0, BT)\n o_k = i_t * BT + tl.arange(0, BS)\n for i_s in range(i_t * BT, min((i_t + 1) * BT, T), BS):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (1, s_k_t), (i_k *\n BK, i_s), (BK, BS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, 1), (i_s,\n i_v * BV), (BS, BV), (1, 0))\n p_gk = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_s,), (BS,), (0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0,))\n m_s = o_q[:, None] >= o_k[None, :]\n b_s = tl.where(m_s, tl.dot(b_q, b_k, allow_tf32=False) * tl.exp(\n b_gq[:, None] - b_gk[None, :]), 0)\n b_o += tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n if OUTPUT_ATTENTIONS:\n tl.store(p_a, b_s.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n p_a = tl.advance(p_a, (0, BS))\n o_k += BS\n p_o = tl.make_block_ptr(o + (i_bh + B * H * i_k) * s_v_h, (T, V), (\n s_v_t, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/parallel.py" }, { "uuid": "24e6a887-0de6-4d46-817d-187228e035a0", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gsa/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef chunk_gsa_fwd_k_kernel_intra(v, g, o, A, offsets, indices, T: tl.\n constexpr, HQ: tl.constexpr, H: tl.constexpr, V: tl.constexpr, BT: tl.\n constexpr, BC: tl.constexpr, BV: tl.constexpr, NC: tl.constexpr, NG: tl\n .constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_bh // NG\n i_b, i_hq = i_bh // HQ, i_bh % HQ\n i_h = i_hq // NG\n i_t, i_i = i_c // NC, i_c % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n o_v = i_v * BV + tl.arange(0, BV)\n m_v = o_v < V\n if i_t * BT + i_i * BC > T:\n return\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t * BT +\n i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + min(i_t *\n BT + i_i * BC, T) * V + o_v, BV), BV)\n else:\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + min(i_t * BT + \n i_i * BC, T)) * H * V + i_h * V + o_v, BV), BV)\n b_gn = tl.load(p_gn, mask=m_v, other=0)\n b_o = tl.zeros([BC, BV], dtype=tl.float32)\n for i_j in range(0, i_i):\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n p_v = tl.make_block_ptr(v + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n p_gv = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (bos * HQ + i_hq) * BT, (T, BT), (\n HQ * BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n p_gv = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_vg = (b_v * tl.exp(b_gn[None, :] - b_gv)).to(b_v.dtype)\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_o += tl.dot(b_A, b_vg)\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_o *= tl.exp(b_g - b_gn[None, :])\n o_i = tl.arange(0, BC)\n if HEAD_FIRST:\n o_A = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_i * BC\n else:\n o_A = (bos + i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * HQ * BT + i_hq * BT + i_i * BC\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n if HEAD_FIRST:\n p_v = tl.max_contiguous(tl.multiple_of(v + i_bg * T * V + (i_t *\n BT + i_i * BC + j) * V + o_v, BV), BV)\n p_gv = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + (i_t *\n BT + i_i * BC + j) * V + o_v, BV), BV)\n else:\n p_v = tl.max_contiguous(tl.multiple_of(v + (bos + i_t * BT + \n i_i * BC + j) * H * V + i_h * V + o_v, BV), BV)\n p_gv = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + \n i_i * BC + j) * H * V + i_h * V + o_v, BV), BV)\n b_A = tl.load(A + o_A + j, mask=m_A, other=0)\n b_v = tl.load(p_v, mask=m_v, other=0).to(tl.float32)\n b_gv = tl.load(p_gv, mask=m_v, other=0).to(tl.float32)\n b_vg = b_v[None, :] * tl.exp(b_g - b_gv[None, :])\n b_o += tl.where(o_i[:, None] >= j, b_A[:, None] * b_vg, 0.0)\n if HEAD_FIRST:\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT +\n i_i * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_o = tl.make_block_ptr(o + (bos * HQ + i_hq) * V, (T, V), (HQ * V,\n 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n b_o += tl.load(p_o, boundary_check=(0, 1))\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gsa/chunk.py" }, { "uuid": "7a21ee06-6228-4111-8cca-8a85dc7cb97b", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged2_to_padded_dense_kernel(x_ptr, lengths_ptr, offsets_ptr,\n output_dense_ptr, stride_b, stride_m, stride_n, max_length, BLOCK_M: tl\n .constexpr, BLOCK_N: tl.constexpr):\n pid_batch = tl.program_id(2)\n pid_m = tl.program_id(0)\n pid_n = tl.program_id(1)\n begin = tl.load(offsets_ptr + pid_batch)\n seqlen = tl.load(lengths_ptr + pid_batch)\n seqlen = tl.minimum(seqlen, max_length)\n if seqlen == 0:\n return\n offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n x_ptrs = x_ptr + begin + offs_m[:, None] * seqlen + offs_n[None, :]\n x = tl.load(x_ptrs, mask=(offs_m[:, None] < seqlen) & (offs_n[None, :] <\n seqlen))\n out_ptrs = output_dense_ptr + pid_batch * stride_b + offs_m[:, None\n ] * stride_m + offs_n[None, :] * stride_n\n tl.store(out_ptrs, x, mask=(offs_m[:, None] < seqlen) & (offs_n[None, :\n ] < seqlen))\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "1bcc5bf5-0201-4106-9714-19fc02c62ac9", "file_name": "p_loss_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/p_loss_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=element_wise_kernel_configs(), key=['size'])\n@triton.jit\ndef p_loss_backward_kernel(output_grad_pointer, input_pointer,\n target_pointer, input_grad_pointer, target_grad_pointer, size, p_loss:\n tl.constexpr, reduction: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n Calculates the input gradient of the mean absolute error or\n mean squared error.\n\n Args:\n output_grad_pointer: Pointer to the error's output gradients.\n The output gradients must be a scalar or of shape [size].\n input_pointer: Pointer to the input.\n The input must be of shape [size].\n target_pointer: Pointer to the target.\n The target must be of shape [size].\n input_grad_pointer: Pointer to a container the input's gradients are written to.\n The container must be of shape [size].\n target_grad_pointer: Pointer to a container the target's gradients are written to.\n The container must be of shape [size].\n size: Number of elements in the input and target.\n p_loss: p-norm used to compute the error whose gradient is calculated.\n Options are 1 for MAE and 2 for MSE.\n reduction: Reduction strategy for the output whose gradient is calculated.\n Options are 'none' for no reduction, 'mean' for averaging the error\n across all entries, and 'sum' for summing the error across all entries.\n BLOCK_SIZE: Block size.\n \"\"\"\n pid = tl.program_id(axis=0)\n offset = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offset < size\n output_grad_mask = None\n if reduction == 'none':\n output_grad_pointer += offset\n output_grad_mask = mask\n input = tl.load(input_pointer + offset, mask=mask).to(tl.float32)\n target = tl.load(target_pointer + offset, mask=mask).to(tl.float32)\n output_grad = tl.load(output_grad_pointer, mask=output_grad_mask).to(tl\n .float32)\n if p_loss == 1:\n input_grad = tl.where(target <= input, 1, -1)\n elif p_loss == 2:\n input_grad = 2 * (input - target)\n if reduction == 'mean':\n input_grad /= size\n input_grad *= output_grad\n tl.store(input_grad_pointer + offset, input_grad, mask=mask)\n tl.store(target_grad_pointer + offset, -input_grad, mask=mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/p_loss_kernels.py" }, { "uuid": "1e4b6bf4-c537-4599-9578-cf786aca1b31", "file_name": "single.py", "repo_name": "shawntan/scattermoe", "file_path": "scattermoe/kernels/single.py", "commit_hash": "63b76a2f5f28c052fb4cd7c34479a54158354052", "starcount": 0, "input": "@triton.jit\ndef _single2scatter(X_ptr, stride_xm, stride_xk, W_ptr, stride_we,\n stride_wk, stride_wn, Y_ptr, stride_ym, stride_yn, expert_idxs_ptr,\n FAN_OUT: tl.constexpr, K: tl.constexpr, N: tl.constexpr, E: tl.\n constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, ACC_TYPE: tl.\n constexpr):\n pid0 = tl.program_id(axis=0)\n pid1 = tl.program_id(axis=1)\n N_block_id = pid0\n if FAN_OUT == 1:\n in_idx = pid1\n else:\n in_idx = 0\n out_idx = pid1\n K_block = tl.arange(0, BLOCK_K)\n N_block = tl.max_contiguous(tl.multiple_of((N_block_id * BLOCK_N + tl.\n arange(0, BLOCK_N)) % N, BLOCK_N), BLOCK_N)\n E_idx = tl.load(expert_idxs_ptr + pid1)\n X_blk_ptrs = X_ptr + in_idx * stride_xm + K_block[:, None] * stride_xk\n W_blk_ptrs = W_ptr + E_idx * stride_we + K_block[:, None\n ] * stride_wk + N_block[None, :] * stride_wn\n acc = tl.zeros((1, BLOCK_N), dtype=ACC_TYPE)\n for K_block_id in range(0, tl.cdiv(K, BLOCK_K)):\n x = tl.load(X_blk_ptrs)\n w = tl.load(W_blk_ptrs)\n acc += tl.sum(x * w, axis=0)[None, :]\n X_blk_ptrs += BLOCK_K * stride_xk\n W_blk_ptrs += BLOCK_K * stride_wk\n Y_blk_ptrs = Y_ptr + out_idx * stride_ym + N_block[None, :] * stride_yn\n tl.store(Y_blk_ptrs, acc)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/scattermoe/blob/63b76a2f5f28c052fb4cd7c34479a54158354052/scattermoe/kernels/single.py" }, { "uuid": "4a649b03-1ebe-4b88-b47e-1980960298a0", "file_name": "W4A16_MatMul.py", "repo_name": "MDK8888/GPTFast", "file_path": "GPTFast/Kernels/Triton/GPTQ/Matmul/W4A16_MatMul.py", "commit_hash": "926b7553cfbaf1ec2a702a4bfb477132ce98c2e1", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 16, 'BLOCK_N': 32,\n 'BLOCK_K': 64}, num_stages=2, num_warps=2), triton.Config({'BLOCK_M': \n 16, 'BLOCK_N': 32, 'BLOCK_K': 64}, num_stages=3, num_warps=4), triton.\n Config({'BLOCK_M': 32, 'BLOCK_N': 32, 'BLOCK_K': 64}, num_stages=2,\n num_warps=2), triton.Config({'BLOCK_M': 16, 'BLOCK_N': 32, 'BLOCK_K': \n 64}, num_stages=3, num_warps=4)], key=[])\n@triton.jit\ndef int4_matmul_kernel_3d(a_ptr, b_ptr, c_ptr, scales_ptr, zeros_ptr,\n stride_am, stride_ak, stride_bk, stride_bn, stride_cm, stride_cn,\n stride_scales_n, stride_scales_g, stride_zeros_n, stride_zeros_g, M, N,\n K, groupsize, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl\n .constexpr):\n m_id = tl.program_id(0)\n n_id = tl.program_id(1)\n k_id = tl.program_id(2)\n offs_am = m_id * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_bn = n_id * BLOCK_N + tl.arange(0, BLOCK_N)\n offs_k = k_id * BLOCK_K + tl.arange(0, BLOCK_K)\n mask_m = offs_am < M\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + offs_k[:, None] // 8 * stride_bk + offs_bn[None, :\n ] * stride_bn\n scales_ptrs = scales_ptr + offs_bn[None, :] * stride_scales_n + offs_k[\n :, None] // groupsize * stride_scales_g\n zeros_ptrs = zeros_ptr + offs_bn[None, :] * stride_zeros_n + offs_k[:, None\n ] // groupsize * stride_zeros_g\n a = tl.load(a_ptrs, mask=mask_m[:, None], other=0.0)\n b = tl.load(b_ptrs)\n scales = tl.load(scales_ptrs)\n zeros = tl.load(zeros_ptrs)\n mask = tl.arange(0, BLOCK_K)[:, None] % 8\n b = b >> mask * 4 & 15\n b = (b - 8) * scales + zeros\n acc = tl.dot(a, b.to(tl.float16))\n c_ptrs = c_ptr + (offs_am[:, None] * stride_cm + offs_bn[None, :] *\n stride_cn)\n tl.atomic_add(c_ptrs, acc.to(tl.float16))\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MDK8888/GPTFast/blob/926b7553cfbaf1ec2a702a4bfb477132ce98c2e1/GPTFast/Kernels/Triton/GPTQ/Matmul/W4A16_MatMul.py" }, { "uuid": "ecca4ed7-6a0c-4e5e-845f-085135f8040b", "file_name": "ops.py", "repo_name": "shawntan/scattermoe", "file_path": "scattermoe/kernels/ops.py", "commit_hash": "63b76a2f5f28c052fb4cd7c34479a54158354052", "starcount": 0, "input": "@triton.autotune(configs=_config_XtY(), key=['M', 'N', 'K'])\n@triton.heuristics({'NO_K_MASK': lambda args: args['K'] % args['BLOCK_K'] ==\n 0, 'NO_N_MASK': lambda args: args['N'] % args['BLOCK_N'] == 0})\n@triton.jit\ndef _groupXtY(DY_ptr, stride_dym, stride_dyk, X_ptr, stride_xm, stride_xn,\n DW_ptr, stride_dwe, stride_dwk, stride_dwn, expert_offsets_ptr, M, K:\n tl.constexpr, N: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr, BLOCK_K: tl.constexpr, ACC_TYPE: tl.constexpr, allow_tf32:\n tl.constexpr, NO_K_MASK: tl.constexpr, NO_N_MASK: tl.constexpr):\n pid0 = tl.program_id(axis=0)\n pid1 = tl.program_id(axis=1)\n num0 = tl.num_programs(0)\n num1 = tl.num_programs(1)\n pid0, pid1 = tl.swizzle2d(pid0, pid1, num0, num1, 4)\n K_BLOCK_COUNT = tl.cdiv(K, BLOCK_K)\n E_idx = pid0 // K_BLOCK_COUNT\n K_block_id = pid0 % K_BLOCK_COUNT\n N_block_id = pid1\n if E_idx == 0:\n start_idx = 0\n else:\n start_idx = tl.load(expert_offsets_ptr + E_idx - 1).to(tl.int32)\n end_idx = tl.load(expert_offsets_ptr + E_idx).to(tl.int32)\n if end_idx > start_idx:\n M_block = tl.max_contiguous(start_idx + tl.arange(0, BLOCK_M), BLOCK_M)\n K_block = K_block_id * BLOCK_K + tl.arange(0, BLOCK_K)\n K_mask = K_block < K\n K_block = tl.max_contiguous(tl.multiple_of(K_block % K, BLOCK_K),\n BLOCK_K)\n N_block = N_block_id * BLOCK_N + tl.arange(0, BLOCK_N)\n N_mask = N_block < N\n N_block = tl.max_contiguous(tl.multiple_of(N_block % N, BLOCK_N),\n BLOCK_N)\n M_idxs = M_block\n xt_blk_ptrs = X_ptr + K_block[:, None] * stride_xn + M_idxs[None, :\n ] * stride_xm\n dy_blk_ptrs = DY_ptr + M_idxs[:, None] * stride_dym + N_block[None, :\n ] * stride_dyk\n acc = tl.zeros((BLOCK_K, BLOCK_N), dtype=ACC_TYPE)\n iters = tl.cdiv(end_idx - start_idx, BLOCK_M)\n for i in range(0, iters):\n M_mask = i * BLOCK_M + M_block < end_idx\n if NO_K_MASK:\n xt = tl.load(xt_blk_ptrs, mask=M_mask[None, :])\n else:\n xt = tl.load(xt_blk_ptrs, mask=K_mask[:, None] & M_mask[\n None, :])\n if NO_N_MASK:\n dy = tl.load(dy_blk_ptrs, mask=M_mask[:, None])\n else:\n dy = tl.load(dy_blk_ptrs, mask=M_mask[:, None] & N_mask[\n None, :])\n xt_blk_ptrs += BLOCK_M * stride_xm\n dy_blk_ptrs += BLOCK_M * stride_dym\n acc += tl.dot(xt, dy, out_dtype=ACC_TYPE, allow_tf32=allow_tf32)\n DW_blk_ptrs = DW_ptr + E_idx * stride_dwe + K_block[:, None\n ] * stride_dwk + N_block[None, :] * stride_dwn\n acc = acc.to(DW_blk_ptrs.dtype.element_ty)\n tl.store(DW_blk_ptrs, acc, mask=K_mask[:, None] & N_mask[None, :])\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/scattermoe/blob/63b76a2f5f28c052fb4cd7c34479a54158354052/scattermoe/kernels/ops.py" }, { "uuid": "87fdafb5-a70c-4967-b40f-bb70db039d6c", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef apply_dropout(x, offsets, p, seed, mask_val=float('-inf')):\n rand = tl.rand(seed, offsets)\n scale = 1 / (1 - p)\n return tl.where(rand > p, x * scale, mask_val)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "0f85b722-d956-44c9-8c49-e98decba5b86", "file_name": "y_3.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_3.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef third_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n CONST002 = 6.48074069840786\n CONST005 = 12.9614813968157\n CONST007 = -3.96862696659689\n CONST008 = -12.5499003980111\n CONST009 = -10.2469507659596\n CONST010 = -7.93725393319377\n CONST011 = -6.27495019900557\n CONST012 = -5.1234753829798\n CONST013 = -4.8605555238059\n CONST014 = -3.24037034920393\n CONST015 = -1.62018517460197\n VAR08 = x * x\n VAR17 = y * y\n VAR26 = z * z\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += (CONST008 * g_6 * x * z - CONST009 * g_1 * y * z + CONST009 *\n g_5 * x * y + CONST010 * g_3 * x * y + CONST014 * g_4 * x * z + g_0 *\n (CONST011 * VAR08 - CONST011 * VAR26) + g_2 * (CONST002 * VAR17 + \n CONST013 * VAR08 + CONST015 * VAR26))\n g_y += (CONST005 * g_2 * x * y + CONST005 * g_4 * y * z - CONST009 *\n g_1 * x * z + g_3 * (CONST007 * VAR08 + CONST007 * VAR26 - CONST010 *\n VAR17) + g_5 * (CONST012 * VAR08 - CONST012 * VAR26))\n g_z += (-CONST008 * g_0 * x * z - CONST009 * g_1 * x * y - CONST009 *\n g_5 * y * z + CONST010 * g_3 * y * z + CONST014 * g_2 * x * z + g_4 *\n (CONST002 * VAR17 + CONST013 * VAR26 + CONST015 * VAR08) + g_6 * (\n CONST011 * VAR08 - CONST011 * VAR26))\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_3.py" }, { "uuid": "08bb518c-fbda-4604-9322-dfac40c7b421", "file_name": "apply_token_bitmask_inplace_triton.py", "repo_name": "mlc-ai/xgrammar", "file_path": "python/xgrammar/kernels/apply_token_bitmask_inplace_triton.py", "commit_hash": "49655f4e5992a0c00183c9bd43d78b49c4e668ab", "starcount": 0, "input": "@triton.jit\ndef apply_token_bitmask_inplace_kernel(logits_ptr, bitmask_ptr, indices_ptr,\n num_rows, vocab_size, bitmask_size, NUM_SMS: tl.constexpr, BLOCK_SIZE:\n tl.constexpr):\n pid = tl.program_id(0)\n num_blocks = tl.cdiv(vocab_size, BLOCK_SIZE)\n for work_id in tl.range(pid, num_rows * num_blocks, NUM_SMS):\n block_offset = work_id % num_blocks * BLOCK_SIZE\n row_id = work_id // num_blocks\n batch_id = tl.load(indices_ptr + row_id)\n offsets = block_offset + tl.arange(0, BLOCK_SIZE)\n bitmask_offsets = block_offset // 32 + tl.arange(0, BLOCK_SIZE // 32)\n vocab_mask = offsets < vocab_size\n packed_bitmask_mask = bitmask_offsets < bitmask_size\n packed_bitmask = tl.load(bitmask_ptr + batch_id * bitmask_size +\n bitmask_offsets, packed_bitmask_mask)\n bitmask = packed_bitmask[:, None] >> tl.arange(0, 32)[None, :] & 1 == 0\n bitmask = bitmask.reshape(BLOCK_SIZE)\n tl.store(logits_ptr + batch_id * vocab_size + offsets, -float('inf'\n ), vocab_mask & bitmask)\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/mlc-ai/xgrammar/blob/49655f4e5992a0c00183c9bd43d78b49c4e668ab/python/xgrammar/kernels/apply_token_bitmask_inplace_triton.py" }, { "uuid": "e7510983-2f6d-4849-8c80-611f47f2a9cc", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps) for BK in [32, 64] for BV in [64, 128] for num_warps in [2, \n 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_gla_bwd_kernel_inter(q, k, v, h, g, do, dh, dq, dk, dq2, dk2, dg,\n offsets, indices, scale, T: tl.constexpr, H: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bh * T * K + (min(T, \n i_t * BT + BT) - 1) * K + o_k, BK), BK)\n else:\n p_gk = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K, 1\n ), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + min(T, i_t * BT +\n BT) - 1) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_dgk = tl.zeros([BK], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * NT * K * V + i_t * K * V, (V,\n K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bh * NT * K * V + i_t * K * V,\n (V, K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dgk += tl.sum(b_h * b_dh, axis=0)\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype))\n b_dk += tl.dot(b_v, b_dh.to(b_v.dtype))\n b_dgk *= tl.exp(b_gn)\n b_dq *= scale\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_dq = b_dq * tl.exp(b_gk)\n b_dk = b_dk * tl.exp(b_gn[None, :] - b_gk)\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dgk += tl.sum(b_dk * b_k, axis=0)\n b_dq += tl.load(p_dq, boundary_check=(0, 1))\n b_dk += tl.load(p_dk, boundary_check=(0, 1))\n b_dg = b_q * b_dq - b_k * b_dk\n b_dg = b_dg - tl.cumsum(b_dg, axis=0) + tl.sum(b_dg, axis=0)[None, :\n ] + b_dgk[None, :]\n if HEAD_FIRST:\n p_dq = tl.make_block_ptr(dq2 + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk2 + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_dq = tl.make_block_ptr(dq2 + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk2 + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "735840ce-064d-4ebd-af98-c2aba99b4e2a", "file_name": "copy.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/copy.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@eval(\n \"\"\"triton.heuristics({\n 'BLOCK_M': lambda kwargs: min(32, triton.next_power_of_2(kwargs['size_inp_0'])),\n 'BLOCK_N': lambda kwargs: min(32, triton.next_power_of_2(kwargs['size_inp_1'])),\n 'BLOCK_K': lambda kwargs: min(32, triton.next_power_of_2(kwargs['size_inp_2'])),\n 'BATCH_STRIDE_INP_IS_1': lambda kwargs: kwargs['batch_stride_inp'] == 1,\n 'STRIDE_INP_0_IS_1': lambda kwargs: kwargs['stride_inp_0'] == 1,\n 'STRIDE_INP_1_IS_1': lambda kwargs: kwargs['stride_inp_1'] == 1,\n 'STRIDE_INP_2_IS_1': lambda kwargs: kwargs['stride_inp_2'] == 1,\n 'BATCH_STRIDE_OUT_IS_1': lambda kwargs: kwargs['batch_stride_out'] == 1,\n 'STRIDE_OUT_0_IS_1': lambda kwargs: kwargs['stride_out_0'] == 1,\n 'STRIDE_OUT_1_IS_1': lambda kwargs: kwargs['stride_out_1'] == 1,\n 'STRIDE_OUT_2_IS_1': lambda kwargs: kwargs['stride_out_2'] == 1,\n})\"\"\"\n )\n@eval(\n \"\"\"triton.heuristics({\n 'num_warps': lambda kwargs: max(1, min(16, kwargs['BLOCK_M'] * kwargs['BLOCK_N'] * kwargs['BLOCK_K'] // 32)),\n})\"\"\"\n )\n@triton.jit\ndef copy_4d_kernel(output_ptr, input_ptr, bs, size_inp_0, size_inp_1,\n size_inp_2, batch_stride_inp, stride_inp_0, stride_inp_1, stride_inp_2,\n batch_stride_out, stride_out_0, stride_out_1, stride_out_2,\n BATCH_STRIDE_INP_IS_1: tl.constexpr, STRIDE_INP_0_IS_1: tl.constexpr,\n STRIDE_INP_1_IS_1: tl.constexpr, STRIDE_INP_2_IS_1: tl.constexpr,\n BATCH_STRIDE_OUT_IS_1: tl.constexpr, STRIDE_OUT_0_IS_1: tl.constexpr,\n STRIDE_OUT_1_IS_1: tl.constexpr, STRIDE_OUT_2_IS_1: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr):\n pid = tl.program_id(0)\n pid_batch = tl.program_id(1)\n grid_m = tl.cdiv(size_inp_0, BLOCK_M)\n grid_n = tl.cdiv(size_inp_1, BLOCK_N)\n grid_k = tl.cdiv(size_inp_2, BLOCK_K)\n pid_m = pid // (grid_n * grid_k)\n pid_nk = pid - pid_m * (grid_n * grid_k)\n pid_n = pid_nk // grid_k\n pid_k = pid_nk - pid_n * grid_k\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n rk = pid_k * BLOCK_K + tl.arange(0, BLOCK_K)\n A = input_ptr + (1 if BATCH_STRIDE_INP_IS_1 else batch_stride_inp\n ) * pid_batch + (rm[:, None, None] * (1 if STRIDE_INP_0_IS_1 else\n stride_inp_0) + rn[None, :, None] * (1 if STRIDE_INP_1_IS_1 else\n stride_inp_1) + rk[None, None, :] * (1 if STRIDE_INP_2_IS_1 else\n stride_inp_2))\n B = output_ptr + (1 if BATCH_STRIDE_OUT_IS_1 else batch_stride_out\n ) * pid_batch + (rm[:, None, None] * (1 if STRIDE_OUT_0_IS_1 else\n stride_out_0) + rn[None, :, None] * (1 if STRIDE_OUT_1_IS_1 else\n stride_out_1) + rk[None, None, :] * (1 if STRIDE_OUT_2_IS_1 else\n stride_out_2))\n mask = (rm < size_inp_0)[:, None, None] & (rn < size_inp_1)[None, :, None\n ] & (rk < size_inp_2)[None, None, :]\n a = tl.load(A, mask=mask)\n tl.store(B, a, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/copy.py" }, { "uuid": "7856aa29-242e-4335-8d5c-122814a3f128", "file_name": "attn_torch_function.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/attn_torch_function.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=TRITON_CONFIG_LIST_FWD, key=['max_seqlen_q',\n 'max_seqlen_k', 'CAUSAL'])\n@triton.jit\ndef tuned_attn_fwd(Q, K, V, B, sm_scale, M, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_bz, stride_bh,\n stride_bm, stride_bn, stride_oz, stride_oh, stride_om, stride_on,\n num_head_q, num_head_k, cu_seqlens_q, cu_seqlens_k, num_seqlens,\n max_seqlen_q, max_seqlen_k, head_dim, dropout_p, philox_seed_ptr,\n philox_offset1, philox_offset2, philox_seed_output,\n philox_offset_output, encoded_softmax, CAUSAL: tl.constexpr, BLOCK_M:\n tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr,\n pre_load_v: tl.constexpr, ENABLE_DROPOUT: tl.constexpr,\n RETURN_ENCODED_SOFTMAX: tl.constexpr, PADDED_HEAD: tl.constexpr,\n BIAS_TYPE: tl.constexpr):\n bare_attn_fwd(Q, K, V, B, sm_scale, M, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_bz, stride_bh,\n stride_bm, stride_bn, stride_oz, stride_oh, stride_om, stride_on,\n num_head_q, num_head_k, cu_seqlens_q, cu_seqlens_k, num_seqlens,\n max_seqlen_q, max_seqlen_k, head_dim, dropout_p, philox_seed_ptr,\n philox_offset1, philox_offset2, philox_seed_output,\n philox_offset_output, encoded_softmax, CAUSAL, BLOCK_M,\n BLOCK_DMODEL, BLOCK_N, pre_load_v, ENABLE_DROPOUT,\n RETURN_ENCODED_SOFTMAX, PADDED_HEAD, BIAS_TYPE=BIAS_TYPE)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/attn_torch_function.py" }, { "uuid": "cda10c52-c03b-4cd3-bcd2-bf5e77672cfe", "file_name": "triton_rms_norm.py", "repo_name": "vladmandic/dcae", "file_path": "dcae/nn/triton_rms_norm.py", "commit_hash": "5223970c7e6c6acfe282e18be7e3821b61511673", "starcount": 0, "input": "@triton.jit\ndef _rms_norm_2d_bwd_dx_fused(DX, DY, DW, DB, X, W, B, Rrms, M, C, N,\n num_blocks, eps, GROUP_SIZE_M: tl.constexpr, BLOCK_SIZE: tl.constexpr,\n BLOCK_SIZE_C: tl.constexpr):\n m_n = tl.program_id(0)\n m, n = m_n // num_blocks, m_n % num_blocks\n X += m * C * N\n DY += m * C * N\n DX += m * C * N\n Rrms += m * N\n cols = n * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n DW = DW + m_n * C\n DB = DB + m_n * C\n rrms = tl.load(Rrms + cols, mask=mask, other=1)\n c1 = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, C):\n pos = off * N + cols\n x = tl.load(X + pos, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + pos, mask=mask, other=0).to(tl.float32)\n w = tl.load(W + off).to(tl.float32)\n xhat = x * rrms\n wdy = w * dy\n xhat = tl.where(mask, xhat, 0.0)\n wdy = tl.where(mask, wdy, 0.0)\n c1 += xhat * wdy\n tl.store(DW + off, tl.sum((dy * xhat).to(w.dtype), axis=0))\n tl.store(DB + off, tl.sum(dy.to(w.dtype), axis=0))\n c1 /= C\n for off in range(0, C):\n pos = off * N + cols\n x = tl.load(X + pos, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + pos, mask=mask, other=0).to(tl.float32)\n w = tl.load(W + off).to(tl.float32)\n xhat = x * rrms\n wdy = w * dy\n dx = (wdy - xhat * c1) * rrms\n tl.store(DX + pos, dx, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/vladmandic/dcae/blob/5223970c7e6c6acfe282e18be7e3821b61511673/dcae/nn/triton_rms_norm.py" }, { "uuid": "f37fbd18-5828-4317-9496-ead47311db58", "file_name": "partition_k.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/gemm/partition_k.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N':\n 32, 'BLOCK_SIZE_K': 64}, num_stages=4, num_warps=2), triton.Config({\n 'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 64}, num_stages\n =5, num_warps=2), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 64}, num_stages=6, num_warps=2), triton.Config({\n 'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 128},\n num_stages=4, num_warps=2), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 128}, num_stages=5, num_warps=2),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 128}, num_stages=6, num_warps=2)], key=['M', 'N', 'K', 'PK'])\n@triton.jit\ndef _matmul_partition_k(a_ptr, b_ptr, c_buf_ptr, M, N, K, PK, PK_SIZE,\n stride_am, stride_ak, stride_bk, stride_bn, stride_cb_m, stride_cb_n,\n stride_cb_k, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (M, K), B has shape (K, N) and C has shape (M, N)\n \"\"\"\n pid_m = tl.program_id(axis=0)\n pid_n = tl.program_id(axis=1)\n pid_pk = tl.program_id(axis=2)\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = (pid_pk * PK_SIZE + tl.arange(0, BLOCK_SIZE_K)) % K\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] *\n stride_bn)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(PK_SIZE, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs)\n b = tl.load(b_ptrs)\n accumulator += tl.dot(a, b)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n acc = accumulator.to(tl.float16)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_ck = pid_pk\n c_buf_ptrs = c_buf_ptr + stride_cb_m * offs_cm[:, None, None\n ] + stride_cb_n * offs_cn[None, :, None] + stride_cb_k * offs_ck[\n None, None, :]\n tl.store(c_buf_ptrs, acc[:, :, None])\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/gemm/partition_k.py" }, { "uuid": "c8196583-7032-4955-b22f-e6dfe1c1f392", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_backward_weight_grad_kernel_notune(a_ptr, b_ptr, c_ptr,\n init_factor, M, N, K, H, stride_am, stride_ak, stride_bm, stride_bn, R7:\n int, R6: int, R5: int, R4: int, R3: int, R2: int, R1: int, R0: int,\n allow_tf32: tl.constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_backward_weight_grad_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=\n c_ptr, init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=\n stride_am, stride_ak=stride_ak, stride_bm=stride_bm, stride_bn=\n stride_bn, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1, R0=R0,\n allow_tf32=allow_tf32, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=\n BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "4ee02cfd-0063-451e-9188-dd563dfe40c5", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_retention_fwd_kernel(q, k, v, o, h0, ht, scale, B: tl.\n constexpr, H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.constexpr, CHECK:\n tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_h = i_bh % H\n o_i = tl.arange(0, BT)\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n d_b, d_o, d_h = tl.math.exp2(BT * b_b), tl.math.exp2((o_i + 1) * b_b\n ), tl.math.exp2((BT - o_i - 1) * b_b)\n m_s = o_i[:, None] >= o_i[None, :]\n d_s = tl.where(m_s, tl.math.exp2((o_i[:, None] - o_i[None, :]) * b_b), 0)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (0, i_k * BK),\n (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k * BK, 0),\n (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (0, i_v * BV),\n (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (i_bh + i_k * B * H) * T * V, (T, V), (V, 1\n ), (0, i_v * BV), (BT, BV), (1, 0))\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(h0 + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n NT = tl.cdiv(T, BT)\n for i in range(0, NT):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_k.dtype)\n b_s = tl.dot(b_q, b_k, allow_tf32=False) * d_s\n b_o = tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n if CHECK and i == 0:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False) * d_o[:,\n None]\n b_h = d_b * b_h + tl.dot(b_k, (b_v * d_h[:, None]).to(b_k.dtype\n ), allow_tf32=False)\n else:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False) * d_o[:,\n None]\n if i == NT - 1 and T % BT != 0:\n d_b = tl.math.exp2(T % BT * b_b)\n d_h = tl.math.exp2((T % BT - o_i - 1) * b_b)\n b_h = d_b * b_h + tl.dot(b_k, (b_v * d_h[:, None]).to(b_k.dtype\n ), allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_q = tl.advance(p_q, (BT, 0))\n p_k = tl.advance(p_k, (0, BT))\n p_v = tl.advance(p_v, (BT, 0))\n p_o = tl.advance(p_o, (BT, 0))\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/fused_chunk.py" }, { "uuid": "dbd509cd-7029-42a7-9a9f-50d56a9e82f4", "file_name": "normalization.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/kernels/normalization.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef _rms_norm_bwd(dY, dX, dW, X, W, Rstd, stride, N, BLOCK_SIZE: tl.constexpr):\n row = tl.program_id(0)\n X += row * stride\n dY += row * stride\n dX += row * stride\n dW += row * stride\n cols = tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n dy = tl.load(dY + cols, mask=mask, other=0.0)\n x = tl.load(X + cols, mask=mask, other=0.0)\n w = tl.load(W + cols, mask=mask, other=0.0)\n rstd = tl.load(Rstd + row)\n m = dy * w\n dx = rstd * m\n dx += rstd * -(1 / N) * rstd * rstd * tl.sum(m * x, axis=0) * x\n dw = dy * (x * rstd)\n tl.store(dX + cols, dx, mask=mask)\n tl.store(dW + cols, dw, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/kernels/normalization.py" }, { "uuid": "10c2ce56-9173-429f-9c4d-35c04a889c0f", "file_name": "triton_ops.py", "repo_name": "imoneoi/bf16_fused_adam", "file_path": "bf16_fused_adam/triton_ops.py", "commit_hash": "66375343b528a00a483646a58a8a851a90834f9e", "starcount": 0, "input": "@triton.jit\ndef bit_split_kernel(x_ptr, output_hi_ptr, output_lo_ptr, n_elements,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n x = tl.load(x_ptr + offsets, mask=mask).to(tl.uint32, bitcast=True)\n output_hi = (x >> 16).to(tl.uint16).to(tl.bfloat16, bitcast=True)\n output_lo = x.to(tl.uint16).to(tl.bfloat16, bitcast=True)\n tl.store(output_hi_ptr + offsets, output_hi, mask=mask)\n tl.store(output_lo_ptr + offsets, output_lo, mask=mask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "bf16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/imoneoi/bf16_fused_adam/blob/66375343b528a00a483646a58a8a851a90834f9e/bf16_fused_adam/triton_ops.py" }, { "uuid": "f5633053-7e55-4be5-a160-add1d765c266", "file_name": "test_autodiff.py", "repo_name": "srush/triton-autodiff", "file_path": "tests/test_autodiff.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef ub1(X, Y):\n r = tl.arange(0, 16)\n r2 = tl.arange(0, 32)\n x = tl.load(X + 16 * r2[:, None] + r)\n y = triton_unbroadcast(x, tl.arange(0, 16).shape)\n tl.store(Y + r, y)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/tests/test_autodiff.py" }, { "uuid": "0a8208c8-85ba-4efb-b976-49ac81225dd3", "file_name": "chunk_h.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [1, 2, 4, 8] for num_stages in [2, 3, 4]], key=['BT',\n 'USE_G', 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_fwd_kernel_h(k, v, h, g, gk, gv, h0, ht, offsets, chunk_offsets,\n T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT:\n tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_G: tl.constexpr,\n USE_GK: tl.constexpr, USE_GV: tl.constexpr, USE_INITIAL_STATE: tl.\n constexpr, STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr,\n HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_nh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + ((boh + i_t) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n last_idx = min((i_t + 1) * BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_nh * T + last_idx)\n p_g = g + i_nh * T + i_t * BT + tl.arange(0, BT)\n p_g = tl.max_contiguous(tl.multiple_of(p_g, BT), BT)\n else:\n b_g_last = tl.load(g + bos * H + last_idx * H + i_h)\n p_g = g + bos * H + (i_t * BT + tl.arange(0, BT)) * H + i_h\n b_h *= tl.exp(b_g_last)\n b_g = tl.load(p_g, mask=i_t * BT + tl.arange(0, BT) < T, other=0.0)\n b_v = (b_v * tl.exp(b_g_last - b_g)[:, None]).to(b_v.dtype)\n if USE_GK:\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(gk + i_nh * T * K, (K, T), (1, K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = (gk + i_nh * T * K + last_idx * K + i_k * BK +\n tl.arange(0, BK))\n else:\n p_gk = tl.make_block_ptr(gk + (bos * H + i_h) * K, (K, T),\n (1, H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) <\n K, other=0.0)\n b_h *= tl.exp(b_gk_last)[:, None]\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_k = (b_k * tl.exp(b_gk_last[:, None] - b_gk)).to(b_k.dtype)\n if USE_GV:\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(gv + i_nh * T * V, (T, V), (V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = (gv + i_nh * T * V + last_idx * V + i_v * BV +\n tl.arange(0, BV))\n else:\n p_gv = tl.make_block_ptr(gv + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) <\n V, other=0.0)\n b_h *= tl.exp(b_gv_last)[None, :]\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_v = (b_v * tl.exp(b_gv_last[None, :] - b_gv)).to(b_v.dtype)\n b_h += tl.dot(b_k, b_v)\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h.py" }, { "uuid": "bd50fa8d-7a93-45f1-be5a-1848956128a7", "file_name": "matmul.py", "repo_name": "jax-ml/jax-triton", "file_path": "examples/matmul.py", "commit_hash": "859cc392bec876d132bd0790ea6c00b6c246dd2b", "starcount": 0, "input": "@triton.jit\ndef relu(x):\n return tl.where(x >= 0, x, 0)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/jax-ml/jax-triton/blob/859cc392bec876d132bd0790ea6c00b6c246dd2b/examples/matmul.py" }, { "uuid": "24bff4b0-3174-46f7-90f5-71dbb3e12644", "file_name": "softmax_naive.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_naive.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr):\n pid_m = tl.program_id(0)\n n_offsets = tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n m = tl.max(inp, 0)\n e = tl.exp(inp - m)\n z = tl.sum(e, 0)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_naive.py" }, { "uuid": "8a498a79-9878-41b0-9e3c-3a83716b2886", "file_name": "swiglu.py", "repo_name": "shauray8/continuity", "file_path": "continuity/diffusion_engine/models/triton_kernels/swiglu.py", "commit_hash": "a52ad077e4ed3162576c7417f302e792ccdf5eca", "starcount": 0, "input": "@triton.jit\ndef _fg_kernel(e, g, h, n_elements, BLOCK_SIZE: tl.constexpr):\n block_idx = tl.program_id(0)\n offsets = block_idx * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n e_row = tl.load(e + offsets, mask=mask, other=0).to(tl.float32)\n g_row = tl.load(g + offsets, mask=mask, other=0)\n f_row = e_row * tl.sigmoid(e_row)\n f_row = f_row.to(g_row.dtype)\n h_row = f_row * g_row\n tl.store(h + offsets, h_row, mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/shauray8/continuity/blob/a52ad077e4ed3162576c7417f302e792ccdf5eca/continuity/diffusion_engine/models/triton_kernels/swiglu.py" }, { "uuid": "891bbd59-6bf6-4383-a905-e03f4293b257", "file_name": "ops.py", "repo_name": "srush/triton-autodiff", "file_path": "triton_autodiff/ops.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef add_grad(left, right):\n right = triton_unbroadcast(right, left.shape)\n return left + right\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/triton_autodiff/ops.py" }, { "uuid": "f4342a00-1b63-4e9d-90eb-9cd669123177", "file_name": "activation.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/activation.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@triton.jit\ndef gelu(x):\n return 0.5 * x * (1.0 + tl.tanh(0.7978845608028654 * (x + 0.044715 * x *\n x * x)))\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/activation.py" }, { "uuid": "1f58dd3e-6916-457c-a58e-f4b968d69485", "file_name": "activation.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/activation.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@triton.jit\ndef identity(x):\n return x\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/activation.py" }, { "uuid": "810d1a75-8358-49ce-890d-2b567c12cecf", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=4)], key=['BT', 'BK',\n 'BV'])\n@triton.jit\ndef chunk_gated_delta_rule_fwd_kernel_o(q, k, v, h, g, o, offsets, indices,\n scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_s = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (\n V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n b_s += tl.dot(b_q, b_k, allow_tf32=False)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n else:\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_o = b_o * tl.exp(b_g)[:, None]\n b_s = b_s * tl.exp(b_g[:, None] - b_g[None, :])\n b_s = tl.where(m_s, b_s, 0)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_o = (b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)) * scale\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/chunk.py" }, { "uuid": "f634d81f-eff7-4c83-ac4b-f2cf21f8ff28", "file_name": "rope.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/rope.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_rope(q_buffer, q_buffer_stride, k_buffer, k_buffer_stride,\n cos_values, cos_values_stride, sin_values, sin_values_stride,\n seq_length, batch_size: tl.constexpr, num_q_heads: tl.constexpr,\n num_k_heads: tl.constexpr, head_dim: tl.constexpr, padded_num_q_heads:\n tl.constexpr, padded_num_k_heads: tl.constexpr, padded_head_dim: tl.\n constexpr, TILE_SIZE: tl.constexpr, IS_BACKWARD: tl.constexpr=False):\n prog_id = tl.program_id(0)\n q_buffer = q_buffer + prog_id * q_buffer_stride\n k_buffer = k_buffer + prog_id * k_buffer_stride\n cos_index = prog_id % seq_length\n cos_values = cos_values + cos_index * cos_values_stride\n sin_values = sin_values + cos_index * sin_values_stride\n cos_indices = tl.arange(0, padded_head_dim // 2)\n cos_active_mask = cos_indices < head_dim // 2\n cos_vec = tl.load(cos_values + cos_indices, mask=cos_active_mask, other=0)\n sin_vec = tl.load(sin_values + cos_indices, mask=cos_active_mask, other=0)\n q_half_offsets = tl.arange(0, padded_num_q_heads)[:, None\n ] * head_dim + tl.arange(0, padded_head_dim // 2)[None, :]\n k_half_offsets = tl.arange(0, padded_num_k_heads)[:, None\n ] * head_dim + tl.arange(0, padded_head_dim // 2)[None, :]\n q_mask = (tl.arange(0, padded_num_q_heads)[:, None] < num_q_heads) & (tl\n .arange(0, padded_head_dim // 2)[None, :] < head_dim // 2)\n k_mask = (tl.arange(0, padded_num_k_heads)[:, None] < num_k_heads) & (tl\n .arange(0, padded_head_dim // 2)[None, :] < head_dim // 2)\n q_tile_part1 = tl.load(q_buffer + q_half_offsets, mask=q_mask, other=0).to(\n sin_vec.dtype)\n k_tile_part1 = tl.load(k_buffer + k_half_offsets, mask=k_mask, other=0).to(\n sin_vec.dtype)\n q_half2_offsets = q_half_offsets + head_dim // 2\n k_half2_offsets = k_half_offsets + head_dim // 2\n q_half2_mask = q_mask\n k_half2_mask = k_mask\n q_tile_part2 = tl.load(q_buffer + q_half2_offsets, mask=q_half2_mask,\n other=0).to(sin_vec.dtype)\n k_tile_part2 = tl.load(k_buffer + k_half2_offsets, mask=k_half2_mask,\n other=0).to(sin_vec.dtype)\n if not IS_BACKWARD:\n updated_q_part1 = q_tile_part1 * cos_vec - q_tile_part2 * sin_vec\n tl.store(q_buffer + q_half_offsets, updated_q_part1, mask=q_mask)\n updated_q_part2 = q_tile_part2 * cos_vec + q_tile_part1 * sin_vec\n tl.store(q_buffer + q_half2_offsets, updated_q_part2, mask=q_half2_mask\n )\n updated_k_part1 = k_tile_part1 * cos_vec - k_tile_part2 * sin_vec\n tl.store(k_buffer + k_half_offsets, updated_k_part1, mask=k_mask)\n updated_k_part2 = k_tile_part2 * cos_vec + k_tile_part1 * sin_vec\n tl.store(k_buffer + k_half2_offsets, updated_k_part2, mask=k_half2_mask\n )\n else:\n reversed_q_part1 = q_tile_part1 * cos_vec + q_tile_part2 * sin_vec\n tl.store(q_buffer + q_half_offsets, reversed_q_part1, mask=q_mask)\n reversed_q_part2 = q_tile_part2 * cos_vec - q_tile_part1 * sin_vec\n tl.store(q_buffer + q_half2_offsets, reversed_q_part2, mask=\n q_half2_mask)\n reversed_k_part1 = k_tile_part1 * cos_vec + k_tile_part2 * sin_vec\n tl.store(k_buffer + k_half_offsets, reversed_k_part1, mask=k_mask)\n reversed_k_part2 = k_tile_part2 * cos_vec - k_tile_part1 * sin_vec\n tl.store(k_buffer + k_half2_offsets, reversed_k_part2, mask=\n k_half2_mask)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/rope.py" }, { "uuid": "9636248c-a664-44e8-a77b-6cdc6b314b7e", "file_name": "silu.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/ops/silu.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef triton_silu(x_ptr, b_ptr, xnumel, XBLOCK: tl.constexpr):\n xoffset = tl.program_id(0) * XBLOCK\n xindex = xoffset + tl.arange(0, XBLOCK)[:]\n xmask = xindex < xnumel\n x0 = xindex\n x = tl.load(x_ptr + x0, mask=xmask).to(tl.float32)\n output = (x * tl.sigmoid(x)).to(tl.float32)\n tl.store(b_ptr + x0, output, xmask)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/ops/silu.py" }, { "uuid": "736db1ea-c332-43df-a318-da529e0545d7", "file_name": "rms_norm.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/rms_norm.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef rmsnorm_forward(Y, Y_row_stride, X, X_row_stride, W, r, n_cols, eps,\n BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n Y_ptr = Y + row_idx * Y_row_stride\n X_ptr = X + row_idx * X_row_stride\n r_ptr = r + row_idx\n X_row = tl.load(X_ptr + col_offsets, mask=mask, other=0).to(tl.float32)\n W_row = tl.load(W + col_offsets, mask=mask, other=0).to(tl.float32)\n X_squared = X_row * X_row\n mean_X_squared = tl.sum(X_squared, axis=0) / n_cols\n rms = tl.math.rsqrt(mean_X_squared + eps)\n tl.store(r_ptr, rms)\n output = X_row * rms * W_row\n tl.store(Y_ptr + col_offsets, output, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/rms_norm.py" }, { "uuid": "395d36cc-ba19-422f-b9e3-4d3f977cec4b", "file_name": "block_sparse_attention_lut.py", "repo_name": "sparklesea/sparse-quant", "file_path": "sparse-attention/muxi/playground/kernels/block_sparse_attention_lut.py", "commit_hash": "e3d8b6ecab208c31b744913ed8c3caaa43605f86", "starcount": 0, "input": "@triton.jit\ndef _sparse_attention_decode_fwd_kernel(Q, K, V, sm_scale, Out, L, M,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX, stride_luth,\n NNZ: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, lut):\n start_n = tl.program_id(0)\n off_hz = tl.program_id(1)\n start_nnz = tl.load(lut + off_hz * stride_luth + start_n)\n kv_offset = off_hz * stride_kh\n q_offset = off_hz * stride_qh\n o_offset = off_hz * stride_oh\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(1,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(0, 0),\n block_shape=(1, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + kv_offset, shape=(BLOCK_DMODEL,\n N_CTX), strides=(stride_kk, stride_kn), offsets=(0, start_nnz *\n BLOCK_N), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + kv_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(start_nnz *\n BLOCK_N, 0), block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n O_block_ptr = tl.make_block_ptr(base=Out + o_offset, shape=(NNZ,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_n, 0),\n block_shape=(1, BLOCK_DMODEL), order=(1, 0))\n qk_scale = sm_scale * 1.44269504\n q = tl.load(Q_block_ptr)\n q = (q * qk_scale).to(tl.float16)\n k = tl.load(K_block_ptr)\n qk = tl.expand_dims(tl.sum(tl.trans(q) * k, axis=0), axis=0).to(tl.float32)\n k_indices = start_nnz * BLOCK_N + tl.arange(0, BLOCK_N)\n qk = tl.where(k_indices < N_CTX, qk, float('-inf'))\n m = tl.max(qk, axis=1, return_indices=False)\n p = tl.math.exp2(qk - m)\n l = tl.sum(p, axis=1)\n v = tl.load(V_block_ptr).to(tl.float16)\n p = p.to(tl.float16)\n acc = tl.expand_dims(tl.sum(tl.trans(p) * v, axis=0), axis=0)\n tl.store(O_block_ptr, acc)\n l_ptrs = L + off_hz * NNZ + start_n + tl.arange(0, 1)\n m_ptrs = M + off_hz * NNZ + start_n + tl.arange(0, 1)\n tl.store(l_ptrs, l)\n tl.store(m_ptrs, m)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Transposed Access" ] }, "licenses": [ "Apache", "BSD" ], "github_url": "https://github.com/sparklesea/sparse-quant/blob/e3d8b6ecab208c31b744913ed8c3caaa43605f86/sparse-attention/muxi/playground/kernels/block_sparse_attention_lut.py" }, { "uuid": "89a686ef-90d0-45ff-bfe3-19e9d5250c8f", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16]], key=['BK'])\n@triton.jit\ndef fwd_prepare_wy_repr_kernel_chunk64(k, beta, A, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BC: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.\n constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n b_A = tl.zeros([BC, BC], dtype=tl.float32)\n b_A2 = tl.zeros([BC, BC], dtype=tl.float32)\n b_A3 = tl.zeros([BC, BC], dtype=tl.float32)\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BC,), (0,))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BC,), (0,))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n if HEAD_FIRST:\n p_beta2 = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT +\n BC,), (BC,), (0,))\n else:\n p_beta2 = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT + BC,), (BC,), (0,))\n b_beta2 = tl.load(p_beta2, boundary_check=(0,))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BC, BK), (1, 0))\n p_k2 = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + BC, i_k * BK), (BC, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BC, BK), (1, 0))\n p_k2 = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + BC, i_k * BK), (BC, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_k2 = tl.load(p_k2, boundary_check=(0, 1))\n b_kb2 = (b_k2 * b_beta2[:, None]).to(b_k2.dtype)\n b_A += tl.dot(b_kb, tl.trans(b_k), allow_tf32=False)\n b_A2 += tl.dot(b_kb2, tl.trans(b_k2), allow_tf32=False)\n b_A3 += tl.dot(b_kb2, tl.trans(b_k), allow_tf32=False)\n b_A = -tl.where(tl.arange(0, BC)[:, None] > tl.arange(0, BC)[None, :],\n b_A, 0)\n b_A2 = -tl.where(tl.arange(0, BC)[:, None] > tl.arange(0, BC)[None, :],\n b_A2, 0)\n for i in range(1, BC):\n mask = tl.arange(0, BC) == i\n b_a = tl.sum(tl.where(mask[:, None], b_A, 0), 0)\n b_a2 = tl.sum(tl.where(mask[:, None], b_A2, 0), 0)\n b_a = b_a + tl.sum(b_a[:, None] * b_A, 0) * (tl.arange(0, BC) < i)\n b_a2 = b_a2 + tl.sum(b_a2[:, None] * b_A2, 0) * (tl.arange(0, BC) < i)\n b_A = tl.where(mask[:, None], b_a, b_A)\n b_A2 = tl.where(mask[:, None], b_a2, b_A2)\n b_A += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_A2 += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_A3 = -tl.dot(tl.dot(b_A2, b_A3, allow_tf32=False), b_A, allow_tf32=False)\n if HEAD_FIRST:\n p_A1 = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BC, BC), (1, 0))\n p_A2 = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + BC, BC), (BC, BC), (1, 0))\n p_A3 = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + BC, 0), (BC, BC), (1, 0))\n p_A4 = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, BC), (BC, BC), (1, 0))\n else:\n p_A1 = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT, 0), (BC, BC), (1, 0))\n p_A2 = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT + BC, BC), (BC, BC), (1, 0))\n p_A3 = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT + BC, 0), (BC, BC), (1, 0))\n p_A4 = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT, BC), (BC, BC), (1, 0))\n tl.store(p_A1, b_A.to(p_A1.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_A2, b_A2.to(p_A2.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_A3, b_A3.to(p_A3.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_A4, tl.zeros([BC, BC], dtype=tl.float32).to(p_A4.dtype.\n element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/wy_fast.py" }, { "uuid": "6ed4de31-dcc6-4dc9-a02d-409ffb40b3d9", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef update_ema(prev_ema, new_val, momentum):\n \"\"\"\n Updates exponential moving average.\n\n Args:\n prev_ema: Previous exponential moving average.\n new_val: Value used to update the exponential moving average.\n momentum: Momentum.\n\n Returns:\n Updated running statistic.\n \"\"\"\n return (1 - momentum) * prev_ema + momentum * new_val\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Single Instance" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "f6af2c0f-1b6e-4f7e-a6be-7ccf22bd5782", "file_name": "y_3.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_3.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef third_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor, block_size:\n tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.constexpr,\n col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST000 = 2.64575131106459\n CONST002 = 5.1234753829798\n CONST004 = 6.48074069840786\n CONST005 = 10.2469507659596\n CONST006 = -2.09165006633519\n CONST007 = -1\n CONST008 = -6.27495019900557\n CONST009 = -3.96862696659689\n CONST010 = -1.62018517460197\n VAR07 = x * x * x\n VAR08 = x * x\n VAR16 = y * y * y\n VAR17 = y * y\n VAR25 = z * z * z\n VAR26 = z * z\n Y00 = CONST006 * VAR07 - CONST008 * VAR26 * x\n Y01 = CONST005 * x * y * z\n Y02 = CONST010 * VAR07 + x * (CONST004 * VAR17 + CONST010 * VAR26)\n Y03 = CONST000 * VAR16 + CONST009 * VAR08 * y + CONST009 * VAR26 * y\n Y04 = CONST010 * VAR25 + z * (CONST004 * VAR17 + CONST010 * VAR08)\n Y05 = CONST002 * y * (CONST007 * VAR08 + VAR26)\n Y06 = -CONST006 * VAR25 + CONST008 * VAR08 * z\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_3.py" }, { "uuid": "318e31bb-32df-41cc-97f5-6c170ad3dd15", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_third_order_bwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, g_x_ptr: tl.tensor, g_y_ptr: tl.tensor, g_z_ptr: tl.tensor,\n g_1_0_ptr: tl.tensor, g_1_1_ptr: tl.tensor, g_1_2_ptr: tl.tensor,\n g_2_0_ptr: tl.tensor, g_2_1_ptr: tl.tensor, g_2_2_ptr: tl.tensor,\n g_2_3_ptr: tl.tensor, g_2_4_ptr: tl.tensor, g_3_0_ptr: tl.tensor,\n g_3_1_ptr: tl.tensor, g_3_2_ptr: tl.tensor, g_3_3_ptr: tl.tensor,\n g_3_4_ptr: tl.tensor, g_3_5_ptr: tl.tensor, g_3_6_ptr: tl.tensor,\n BLOCK_SIZE: tl.constexpr, vector_length: tl.constexpr):\n sqrt_3 = 3 ** 0.5\n sqrt_5 = 5 ** 0.5\n sqrt_15 = 15 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n g_1_0 = tl.load(g_1_0_ptr + offset, mask=offset < vector_length)\n g_1_1 = tl.load(g_1_1_ptr + offset, mask=offset < vector_length)\n g_1_2 = tl.load(g_1_2_ptr + offset, mask=offset < vector_length)\n g_x = sqrt_3 * g_1_0\n g_y = sqrt_3 * g_1_1\n g_z = sqrt_3 * g_1_2\n g_2_0 = tl.load(g_2_0_ptr + offset, mask=offset < vector_length)\n g_2_1 = tl.load(g_2_1_ptr + offset, mask=offset < vector_length)\n g_2_2 = tl.load(g_2_2_ptr + offset, mask=offset < vector_length)\n g_2_3 = tl.load(g_2_3_ptr + offset, mask=offset < vector_length)\n g_2_4 = tl.load(g_2_4_ptr + offset, mask=offset < vector_length)\n g_x += sqrt_15 * z * g_2_0\n g_z += sqrt_15 * x * g_2_0\n g_x += sqrt_15 * y * g_2_1\n g_y += sqrt_15 * x * g_2_1\n g_y += sqrt_15 * z * g_2_2\n g_z += sqrt_15 * y * g_2_2\n g_x += -1.0 * sqrt_5 * x * g_2_3\n g_y += 2.0 * sqrt_5 * y * g_2_3\n g_z += -1.0 * sqrt_5 * z * g_2_3\n g_x += -1.0 * sqrt_15 * x * g_2_4\n g_z += sqrt_15 * z * g_2_4\n g_3_0 = tl.load(g_3_0_ptr + offset, mask=offset < vector_length)\n g_3_1 = tl.load(g_3_1_ptr + offset, mask=offset < vector_length)\n g_3_2 = tl.load(g_3_2_ptr + offset, mask=offset < vector_length)\n g_3_3 = tl.load(g_3_3_ptr + offset, mask=offset < vector_length)\n g_3_4 = tl.load(g_3_4_ptr + offset, mask=offset < vector_length)\n g_3_5 = tl.load(g_3_5_ptr + offset, mask=offset < vector_length)\n g_3_6 = tl.load(g_3_6_ptr + offset, mask=offset < vector_length)\n sq_x = x * x\n sq_y = y * y\n sq_z = z * z\n g_x += sqrt_15 * g_3_0 * (-1.62018517460196 * sq_x + 1.08012344973464 *\n sq_z + 0.540061724867322 * sq_z)\n g_x += 2.64575131106459 * sqrt_15 * g_3_1 * y * z\n g_x -= g_3_2 * (4.8605555238059 * sq_x - 6.48074069840786 * sq_y + \n 1.62018517460197 * sq_z)\n g_x -= 7.93725393319377 * g_3_3 * x * y\n g_x -= 3.24037034920393 * g_3_4 * x * z\n g_x -= 2.64575131106459 * sqrt_15 * g_3_5 * x * y\n g_x -= sqrt_15 * g_3_6 * z * (1.08012344973464 * x + 2.16024689946929 * x)\n g_y += 2.64575131106459 * sqrt_15 * g_3_1 * x * z\n g_y += 12.9614813968157 * g_3_2 * x * y\n g_y -= g_3_3 * (3.96862696659689 * sq_x - 7.93725393319377 * sq_y + \n 3.96862696659689 * sq_z)\n g_y += 12.9614813968157 * g_3_4 * y * z\n g_y -= 1.3228756555323 * sqrt_15 * g_3_5 * (sq_x - sq_z)\n g_z += sqrt_15 * g_3_0 * x * (1.08012344973464 * z + 2.16024689946929 * z)\n g_z += 2.64575131106459 * sqrt_15 * g_3_1 * x * y\n g_z -= 3.24037034920393 * g_3_2 * x * z\n g_z -= 7.93725393319377 * g_3_3 * y * z\n g_z -= g_3_4 * (1.62018517460197 * sq_x - 6.48074069840786 * sq_y + \n 4.8605555238059 * sq_z)\n g_z += 2.64575131106459 * sqrt_15 * g_3_5 * y * z\n g_z -= sqrt_15 * g_3_6 * (1.08012344973464 * sq_x + 0.540061724867322 *\n sq_x - 1.62018517460196 * sq_z)\n tl.store(g_x_ptr + offset, g_x, mask=offset < vector_length)\n tl.store(g_y_ptr + offset, g_y, mask=offset < vector_length)\n tl.store(g_z_ptr + offset, g_z, mask=offset < vector_length)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "6927aecc-280a-412c-8568-2e3046c2cd1c", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef triton_jagged_to_dense_optimization_2d(input_jagged_values_ptr,\n input_jagged_offset_ptr, input_jagged_row_stride, output_dense_ptr,\n output_dense_row_stride, output_dense_matrix_stride,\n thread_block_row_size: tl.constexpr, thread_block_col_size: tl.\n constexpr, padded_value, operation_function: tl.constexpr, operation_dense\n ) ->None:\n pid = tl.program_id(0)\n offset_idx = pid\n begin = tl.load(input_jagged_offset_ptr + offset_idx)\n end = tl.load(input_jagged_offset_ptr + offset_idx + 1)\n cur_jagged_tensor_row_size = end - begin\n output_dense_ptr += pid * output_dense_matrix_stride\n input_jagged_values_ptr += begin * input_jagged_row_stride\n if operation_function is not None:\n operation_dense += pid * output_dense_matrix_stride\n offset_row = tl.arange(0, thread_block_row_size)\n dense_col_size = output_dense_row_stride\n dense_row_size = output_dense_matrix_stride // output_dense_row_stride\n for _i in range(0, dense_row_size, thread_block_row_size):\n offset_col = tl.arange(0, thread_block_col_size)\n block_offset = offset_row[:, None\n ] * output_dense_row_stride + offset_col[None, :]\n for _j in range(0, dense_col_size, thread_block_col_size):\n dense_mask = (offset_row[:, None] < dense_row_size) & (offset_col\n [None, :] < dense_col_size)\n jagged_mask = (offset_row[:, None] < cur_jagged_tensor_row_size\n ) & (offset_col[None, :] < input_jagged_row_stride)\n jagged_val = tl.load(input_jagged_values_ptr + block_offset,\n mask=jagged_mask, other=padded_value)\n if operation_function is not None:\n operation_dense_val = tl.load(operation_dense +\n block_offset, mask=dense_mask, other=0.0)\n jagged_val = operation_function(operation_dense_val, jagged_val\n )\n tl.store(output_dense_ptr + block_offset, jagged_val, mask=\n dense_mask)\n offset_col += thread_block_col_size\n block_offset += thread_block_col_size\n offset_row += thread_block_row_size\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "d73689df-125b-497e-b758-19f7ab9950f4", "file_name": "06-fused-attention.py", "repo_name": "2lambda123/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "09e27725b89043a07f49c440db6a9aedcfba8432", "starcount": 0, "input": "@triton.jit\ndef _bwd_preprocess(Out, DO, Delta, BLOCK_M: tl.constexpr, D_HEAD: tl.constexpr\n ):\n off_m = tl.program_id(0) * BLOCK_M + tl.arange(0, BLOCK_M)\n off_n = tl.arange(0, D_HEAD)\n o = tl.load(Out + off_m[:, None] * D_HEAD + off_n[None, :]).to(tl.float32)\n do = tl.load(DO + off_m[:, None] * D_HEAD + off_n[None, :]).to(tl.float32)\n delta = tl.sum(o * do, axis=1)\n tl.store(Delta + off_m, delta)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/2lambda123/triton/blob/09e27725b89043a07f49c440db6a9aedcfba8432/python/tutorials/06-fused-attention.py" }, { "uuid": "8f081f68-2198-4cce-a6f5-0e54650bd725", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef padded_dense_to_jagged2_kernel(x_ptr, lengths_ptr, offsets_ptr,\n output_jagged_ptr, stride_b, stride_m, stride_n, max_length, BLOCK_M:\n tl.constexpr, BLOCK_N: tl.constexpr):\n pid_batch = tl.program_id(2)\n pid_m = tl.program_id(0)\n pid_n = tl.program_id(1)\n begin = tl.load(offsets_ptr + pid_batch)\n seqlen = tl.load(lengths_ptr + pid_batch)\n seqlen = tl.minimum(seqlen, max_length)\n if seqlen == 0:\n return\n offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n x_ptrs = x_ptr + pid_batch * stride_b + offs_m[:, None\n ] * stride_m + offs_n[None, :] * stride_n\n x = tl.load(x_ptrs, mask=(offs_m[:, None] < seqlen) & (offs_n[None, :] <\n seqlen))\n out_ptrs = output_jagged_ptr + begin + offs_m[:, None] * seqlen + offs_n[\n None, :]\n tl.store(out_ptrs, x, mask=(offs_m[:, None] < seqlen) & (offs_n[None, :\n ] < seqlen))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "6d81ba3a-93a7-42c4-af16-ccbd76925f55", "file_name": "05-layer-norm.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/05-layer-norm.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_bwd_dx_fused(DX, DY, DW, DB, X, W, Mean, Rstd, Lock, stride,\n N, GROUP_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr):\n row = tl.program_id(0)\n cols = tl.arange(0, BLOCK_SIZE_N)\n mask = cols < N\n X += row * stride\n DY += row * stride\n DX += row * stride\n lock_id = row % GROUP_SIZE_M\n Lock += lock_id\n Count = Lock + GROUP_SIZE_M\n DW = DW + lock_id * N + cols\n DB = DB + lock_id * N + cols\n x = tl.load(X + cols, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + cols, mask=mask, other=0).to(tl.float32)\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n mean = tl.load(Mean + row)\n rstd = tl.load(Rstd + row)\n xhat = (x - mean) * rstd\n wdy = w * dy\n xhat = tl.where(mask, xhat, 0.0)\n wdy = tl.where(mask, wdy, 0.0)\n c1 = tl.sum(xhat * wdy, axis=0) / N\n c2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * c1 + c2)) * rstd\n tl.store(DX + cols, dx, mask=mask)\n partial_dw = (dy * xhat).to(w.dtype)\n partial_db = dy.to(w.dtype)\n while tl.atomic_cas(Lock, 0, 1) == 1:\n pass\n count = tl.load(Count)\n if count == 0:\n tl.atomic_xchg(Count, 1)\n else:\n partial_dw += tl.load(DW, mask=mask)\n partial_db += tl.load(DB, mask=mask)\n tl.store(DW, partial_dw, mask=mask)\n tl.store(DB, partial_db, mask=mask)\n tl.atomic_xchg(Lock, 0)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/05-layer-norm.py" }, { "uuid": "5d85d5a2-0693-4087-ad1a-4430132d743a", "file_name": "gemm_splitk_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_splitk_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 256, 'BLOCK_N': 256,\n 'BLOCK_K': 32, 'GROUP_M': 4, 'SPLIT_K': 4, 'grf_mode': 'large'},\n num_stages=4, num_warps=32)], key=['M', 'N', 'K'])\n@triton.jit\ndef _kernel(A, B, C, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr,\n stride_am: tl.constexpr, stride_ak: tl.constexpr, stride_bk: tl.\n constexpr, stride_bn: tl.constexpr, stride_cm: tl.constexpr, stride_cn:\n tl.constexpr, acc_dtype: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N:\n tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl\n .constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n a_block_ptr = tl.make_block_ptr(base=A, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_M, pid_z * BLOCK_K),\n block_shape=(BLOCK_M, BLOCK_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=B, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(pid_z * BLOCK_K, pid_n * BLOCK_N),\n block_shape=(BLOCK_K, BLOCK_N), order=(1, 0))\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=acc_dtype)\n for _ in range(0, K, BLOCK_K * SPLIT_K):\n a = tl.load(a_block_ptr)\n b = tl.load(b_block_ptr)\n acc += tl.dot(a, b, out_dtype=acc_dtype)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_K * SPLIT_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_K * SPLIT_K, 0))\n acc = acc.to(C.dtype.element_ty)\n if SPLIT_K == 1:\n c_block_ptr = tl.make_block_ptr(base=C, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_M, pid_n *\n BLOCK_N), block_shape=(BLOCK_M, BLOCK_N), order=(1, 0))\n tl.store(c_block_ptr, acc, boundary_check=(0, 1))\n else:\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_splitk_benchmark.py" }, { "uuid": "ff71555a-07ff-4b43-bde0-81003adfcfab", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef causal_mask(offs_m, offs_n, M, N, EVEN_M: tl.constexpr, EVEN_N: tl.\n constexpr):\n shift = N - M\n mask = shift + offs_m[:, None] >= offs_n[None, :]\n if not EVEN_M & EVEN_N:\n mask = mask & make_bounds(offs_m, offs_n, M, N, EVEN_M, EVEN_N)\n return tl.where(mask, 0, float('-inf'))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Latency Sensitive" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "658e3aea-d371-4a6d-8906-df02e8f90b5c", "file_name": "blocksparse_attention_kernel.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/attention/ops/blocksparse_attention/blocksparse_attention_kernel.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel_inner(acc, l_i, m_i, q, Q, k_block_col_idx, layout_col_ptr,\n layout_col_stride_h, layout_col_stride_m, k_ptrs, v_ptrs, off_h, offs_m,\n offs_n, offs_d, stride_kt, stride_vt, sm_scale, k_seqlen, past_len,\n LAST_K_BLOCK: tl.constexpr, BLOCK_M_LOADING: tl.constexpr, BLOCK_N: tl.\n constexpr, D_HEAD: tl.constexpr, EVEN_D: tl.constexpr, M_LT_N: tl.constexpr\n ):\n k_block_id = tl.load(layout_col_ptr + off_h * layout_col_stride_h + \n k_block_col_idx * layout_col_stride_m).to(tl.int32)\n start_n = k_block_id * BLOCK_N\n if LAST_K_BLOCK:\n if EVEN_D:\n k = tl.load(k_ptrs + start_n * stride_kt, mask=offs_n[None, :] +\n start_n < k_seqlen)\n else:\n k = tl.load(k_ptrs + start_n * stride_kt, mask=(offs_n[None, :] +\n start_n < k_seqlen) & (offs_d[:, None] < D_HEAD))\n elif EVEN_D:\n k = tl.load(k_ptrs + start_n * stride_kt)\n else:\n k = tl.load(k_ptrs + start_n * stride_kt, mask=offs_d[:, None] < D_HEAD\n )\n qk = tl.zeros([BLOCK_M_LOADING, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n qk *= sm_scale\n if LAST_K_BLOCK | M_LT_N:\n qk += tl.where(offs_m[:, None] + past_len >= start_n + offs_n[None,\n :], 0, float('-inf'))\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n p = tl.math.exp2(qk - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp2(m_i - m_ij)\n acc = acc * alpha[:, None]\n m_i = m_ij\n l_i = l_i * alpha + l_ij\n p = p.to(Q.dtype.element_ty)\n if LAST_K_BLOCK:\n if EVEN_D:\n v = tl.load(v_ptrs + start_n * stride_vt, mask=offs_n[:, None] +\n start_n < k_seqlen)\n else:\n v = tl.load(v_ptrs + start_n * stride_vt, mask=(offs_n[:, None] +\n start_n < k_seqlen) & (offs_d[None, :] < D_HEAD))\n elif EVEN_D:\n v = tl.load(v_ptrs + start_n * stride_vt)\n else:\n v = tl.load(v_ptrs + start_n * stride_vt, mask=offs_d[None, :] < D_HEAD\n )\n acc += tl.dot(p, v)\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Latency Sensitive" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/attention/ops/blocksparse_attention/blocksparse_attention_kernel.py" }, { "uuid": "ca7c4674-22d1-465d-8d7e-f908478548b8", "file_name": "sparse_copy.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_copy.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef sparse_map_kernel(top_experts_ptr, expert_ends_ptr,\n expert_pad_begins_ptr, sparse_rows_ptr, num_sparse_rows: tl.constexpr,\n num_experts: tl.constexpr, pad_to_multiple: tl.constexpr, block_size:\n tl.constexpr, block_size_expert: tl.constexpr, dtype: tl.constexpr):\n \"\"\"\n Since the methods we want (histogram, argsort) are not readily available in triton,\n we use a one-hot representation to get the quantities we want.\n TODO: Next triton release will support tl.histogram, maybe argsort.\n \"\"\"\n block_range = tl.arange(0, block_size)\n expert_range = tl.arange(0, block_size_expert)\n expert_mask = (None if block_size_expert == num_experts else \n expert_range < num_experts)\n if num_sparse_rows >= block_size:\n expert_index = tl.load(top_experts_ptr + block_range)\n else:\n expert_index = tl.load(top_experts_ptr + block_range, mask=\n block_range < num_sparse_rows, other=num_experts)\n expert_counts = tl.sum((expert_index[:, None] == expert_range[None, :])\n .to(dtype), 0)\n for i in range(1, tl.cdiv(num_sparse_rows, block_size)):\n block_range += block_size\n if num_sparse_rows % block_size == 0:\n expert_index = tl.load(top_experts_ptr + block_range)\n else:\n expert_index = tl.load(top_experts_ptr + block_range, mask=\n block_range < num_sparse_rows, other=num_experts)\n expert_counts += tl.sum((expert_index[:, None] == expert_range[None,\n :]).to(dtype), 0)\n if pad_to_multiple is None:\n expert_counts_padded = expert_counts\n else:\n expert_counts_padded = (expert_counts + pad_to_multiple - 1\n ) // pad_to_multiple * pad_to_multiple\n expert_ends = tl.cumsum(expert_counts_padded)\n expert_begins = expert_ends - expert_counts_padded\n if expert_ends_ptr is not None:\n tl.store(expert_ends_ptr + expert_range, expert_ends, mask=expert_mask)\n if expert_pad_begins_ptr is not None:\n tl.store(expert_pad_begins_ptr + expert_range, expert_begins +\n expert_counts, mask=expert_mask)\n if sparse_rows_ptr is not None:\n block_range = tl.arange(0, block_size)\n for i in range(tl.cdiv(num_sparse_rows, block_size)):\n if num_sparse_rows % block_size == 0:\n mask = None\n expert_index = tl.load(top_experts_ptr + block_range)\n else:\n mask = block_range < num_sparse_rows\n expert_index = tl.load(top_experts_ptr + block_range, mask=\n mask, other=num_experts)\n expert_one_hot = (expert_index[:, None] == expert_range[None, :]\n ).to(dtype)\n expert_offsets = (tl.cumsum(expert_one_hot, 0) + expert_begins[\n None, :]) * expert_one_hot\n tl.store(sparse_rows_ptr + block_range, tl.sum(expert_offsets, \n 1) - 1, mask=mask)\n expert_begins += tl.sum(expert_one_hot, 0)\n block_range += block_size\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_copy.py" }, { "uuid": "8a2be484-de09-45f5-adcd-8c5f11a156e6", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES, BLOCK_SIZES, NUM_WARPS, NUM_STAGES)],\n key=['M'])\n@triton.jit\ndef triton_jagged_sum_kernel_simple_fused_buffer_then_sum(input_ptr_values,\n input_ptr_offsets, output_ptr, M, MAX_SEQLEN, BLOCK_SIZE_RAGGED: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_ragged = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_ragged\n ), tl.load(input_ptr_offsets + (pid_ragged + 1))\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n buffer += tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer_sum = tl.sum(buffer, axis=0)\n buffer_view = buffer_sum.reshape((BLOCK_SIZE_M,))\n output_offsets = offsets_m + pid_ragged * M\n output_mask = output_offsets < M * (pid_ragged + 1)\n tl.store(output_ptr + output_offsets, buffer_view, mask=output_mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_sum/kernels.py" }, { "uuid": "942e12b2-81c0-40e4-966c-b945f0b6e59f", "file_name": "parallel_scan.py", "repo_name": "chengkai-liu/RecBLR", "file_path": "parallel_scan.py", "commit_hash": "66e520c26e28c05a5425ba2e81c9169b7e0176e2", "starcount": 0, "input": "@triton.jit\ndef forward_scan(gates, tokens, outputs, SEQUENCE_LENGTH: tl.constexpr):\n sequence_id = tl.num_programs(axis=1) * tl.program_id(axis=0\n ) + tl.program_id(axis=1)\n strides = tl.arange(0, SEQUENCE_LENGTH) + sequence_id * SEQUENCE_LENGTH\n tokens_ = tl.load(tokens + strides)\n gates_ = tl.load(gates + strides)\n tuples = pack64(tokens_, gates_)\n output_tuples_ = tl.associative_scan(tuples, axis=0, combine_fn=\n first_order_op)\n output_tokens_, output_gates_ = unpack64(output_tuples_)\n tl.store(outputs + strides, output_tokens_)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengkai-liu/RecBLR/blob/66e520c26e28c05a5425ba2e81c9169b7e0176e2/parallel_scan.py" }, { "uuid": "7d8a010b-7cc8-4d82-8e78-3e637e19e741", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_mean/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES_RAGGED, BLOCK_SIZES_M, NUM_WARPS,\n NUM_STAGES)], key=['M'])\n@triton.jit\ndef triton_jagged_mean_kernel_simple_fused_sum_then_buffer(input_ptr_values,\n input_ptr_offsets, output_ptr, M, MAX_SEQLEN, BLOCK_SIZE_RAGGED: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_b = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((1, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_b), tl.load(\n input_ptr_offsets + (pid_b + 1))\n ragged_len = ragged_end - ragged_start\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer += tl.sum(input, axis=0)\n buffer_view = buffer.reshape((BLOCK_SIZE_M,))\n buffer_view_mean = buffer_view * (1 / ragged_len)\n output_offsets = offsets_m + pid_b * M\n output_mask = output_offsets < M * (pid_b + 1)\n tl.store(output_ptr + output_offsets, buffer_view_mean, mask=output_mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_mean/kernels.py" }, { "uuid": "fbeec137-387e-4b5f-a767-2a50d629e0ce", "file_name": "bwd_inner_dk_dv.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/bwd_inner_dk_dv.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_inner_dk_dv(dk, dv, qk_scale, bias_scale, q_ptrs, q_stride, kt, vt,\n B_block_ptr, do_ptrs, do_stride, l_ptrs, D_ptrs, seqlen_q, seqlen_k,\n head_dim, start_k, lo, hi, overflow_size, dropout_p, dropout_scale,\n philox_seed, batch_philox_offset, max_seqlen_k, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, FULL_BLOCKS: tl.\n constexpr, CAUSAL: tl.constexpr, ENABLE_DROPOUT: tl.constexpr,\n PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.constexpr):\n offs_k = start_k + tl.arange(0, BLOCK_N)\n offs_q = tl.arange(0, BLOCK_M)\n ld_offs_d = None if not PADDED_HEAD else tl.arange(0, BLOCK_DMODEL)\n q_ptrs += lo * q_stride\n do_ptrs += lo * do_stride\n if BIAS_TYPE == 1:\n B_block_ptr = tl.advance(B_block_ptr, (lo, 0))\n \"\"\"\n K1 K2 (d)V dO\n Q1 qk11 qk12 (d)v1 dO1\n Q2 qk21 qk22 (d)v2 dO2\n\n QK: (seqlen_q, seqlen_k)\n dO: (seqlen_q, hdim)\n dV: (seqlen_k, hdim)\n\n dV = (QK)^T dO\n\n dV1 = qk11 dO1 + qk21 dO2 = q1 k1 dO1 + q2 k1 dO2\n dV2 = qk12 dO1 + qk22 dO2 = q1 k2 dO1 + q2 k2 dO2\n ~~~~~ = 0\n start_k: select k and dV\n start_q: select q and dO\n \"\"\"\n for start_q in range(lo, hi, BLOCK_M):\n offs_q_curr = offs_q[:, None] + start_q\n if not FULL_BLOCKS:\n q = load_fn(q_ptrs, offs_q + start_q, ld_offs_d, seqlen_q, head_dim\n )\n else:\n q = load_fn(q_ptrs, None, ld_offs_d, seqlen_q, head_dim)\n if not FULL_BLOCKS:\n do = load_fn(do_ptrs, offs_q + start_q, ld_offs_d, seqlen_q,\n head_dim)\n else:\n do = load_fn(do_ptrs, None, ld_offs_d, seqlen_q, head_dim)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n if not FULL_BLOCKS:\n if overflow_size > 0:\n boundary_n = tl.full((BLOCK_N,), seqlen_q, dtype=tl.int32)\n mask = offs_q_curr < boundary_n[None, :]\n qk = tl.where(mask, qk, float('-inf'))\n if CAUSAL:\n qk = tl.where(offs_q_curr >= offs_k[None, :], qk, float('-inf'))\n if BIAS_TYPE == 0:\n pass\n elif BIAS_TYPE == 1:\n bias = tl.load(B_block_ptr, boundary_check=(0, 1),\n padding_option='zero')\n qk += bias * bias_scale\n else:\n tl.static_assert(False, f'Unsupported BIAS_TYPE {BIAS_TYPE}')\n qk += dot(BLOCK_M, BLOCK_DMODEL, BLOCK_DMODEL, q, kt)\n if FULL_BLOCKS:\n Di = tl.load(D_ptrs + offs_q_curr)\n l_i = tl.load(l_ptrs + offs_q_curr)\n else:\n boundary = tl.full((BLOCK_M,), BLOCK_M - overflow_size, dtype=\n tl.int32)\n d_lse_ptrs_mask = boundary > tl.arange(0, BLOCK_M)\n d_lse_padding = tl.full((BLOCK_M,), 0, dtype=tl.float32)\n Di = tl.load(D_ptrs + offs_q_curr, mask=d_lse_ptrs_mask[:, None\n ], other=d_lse_padding[:, None])\n l_i = tl.load(l_ptrs + offs_q_curr, mask=d_lse_ptrs_mask[:,\n None], other=d_lse_padding[:, None])\n p = tl.math.exp2(qk_scale * qk - l_i)\n if not FULL_BLOCKS or CAUSAL:\n if qk_scale == 0.0:\n p = tl.where(libdevice.isnan(p), 0.0, p)\n if ENABLE_DROPOUT:\n philox_offset = (batch_philox_offset + start_q * max_seqlen_k +\n start_k)\n keep = dropout_mask(philox_seed, philox_offset, dropout_p,\n BLOCK_M, BLOCK_N, max_seqlen_k)\n if BLOCK_M == 1:\n dv += tl.where(keep, p * dropout_scale, 0.0).to(q_ptrs.\n dtype.element_ty) * do\n else:\n dv += tl.dot(tl.trans(tl.where(keep, p * dropout_scale, 0.0\n )).to(q_ptrs.dtype.element_ty), do)\n elif BLOCK_M == 1:\n dv += p.to(q_ptrs.dtype.element_ty) * do\n else:\n dv += tl.dot(tl.trans(p.to(do.dtype)), do)\n dp = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n dp += tl.dot(do, vt)\n if ENABLE_DROPOUT:\n dp = tl.where(keep, dp * dropout_scale, 0)\n ds = p * (dp - Di)\n if BLOCK_M == 1:\n dk += ds.to(q_ptrs.dtype.element_ty) * q\n else:\n dk += tl.dot(tl.trans(ds.to(q_ptrs.dtype.element_ty)), q)\n q_ptrs += q_stride * BLOCK_M\n do_ptrs += do_stride * BLOCK_M\n if BIAS_TYPE == 1:\n B_block_ptr = tl.advance(B_block_ptr, (BLOCK_M, 0))\n return dk, dv\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/bwd_inner_dk_dv.py" }, { "uuid": "b20ebc56-6a89-4549-b7b7-605c742067fe", "file_name": "flash_attention.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/flash/flash_attention.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef masked_row(rows):\n \"\"\"rows is BLOCK_M slice of the QK score\n Returns:\n BLOCK_M vector of boolean values indicating whether this\n Query x Key position is fully masked\n\n \"\"\"\n return rows == float('-inf')\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/flash/flash_attention.py" }, { "uuid": "3536e65e-9891-4926-b200-b5960ac48099", "file_name": "triton_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/template_attention/triton_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64,\n 'BLOCK_DMODEL': 64}, num_stages=3, num_warps=4)], key=['num_queries'])\n@triton.jit\ndef triton_tem_fused_no_exp2(arg_Q, arg_K, arg_V, out_ptr0, num_queries: tl\n .constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_DMODEL:\n tl.constexpr):\n Q = arg_Q\n K = arg_K\n V = arg_V\n stride_qz = 4194304\n stride_qh = 262144\n stride_qm = 64\n stride_qk = 1\n stride_kz = 4194304\n stride_kh = 262144\n stride_kn = 64\n stride_kk = 1\n stride_vz = 4194304\n stride_vh = 262144\n stride_vk = 64\n stride_vn = 1\n Z = 16\n H = 16\n N_CTX = 4096\n qk_scale = 1.0\n MATMUL_PRECISION = tl.float16\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n qkv_offset = off_hz * stride_qh\n Q_block_ptr = tl.make_block_ptr(base=Q + qkv_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qkv_offset, shape=(\n BLOCK_DMODEL, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + qkv_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n q = tl.load(Q_block_ptr)\n q = (q * qk_scale).to(MATMUL_PRECISION)\n lo = 0\n hi = N_CTX\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(K_block_ptr)\n v = tl.load(V_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k.to(MATMUL_PRECISION))\n tmp0 = tl.full([1], 1024, tl.int64)\n tmp1 = offs_m[:, None] <= tmp0\n tmp2 = start_n + offs_n[None, :] <= tmp0\n tmp3 = tmp1 & tmp2\n tmp4 = offs_m[:, None] >= start_n + offs_n[None, :]\n tmp5 = tmp3 | tmp4\n tmp6 = float('-inf')\n tmp7 = tmp6.to(tl.float32)\n tmp8 = tl.where(tmp5, qk, tmp7)\n qk = tmp8\n row_max = tl.max(qk, 1)\n m_i_new = tl.maximum(m_i, row_max)\n masked_out_rows = m_i_new == float('-inf')\n alpha = tl.math.exp(m_i - m_i_new)\n alpha = tl.where(masked_out_rows, 0, alpha)\n p = tl.math.exp(qk - m_i_new[:, None])\n p = tl.where(masked_out_rows[:, None], 0, p)\n acc_scale = l_i * 0 + alpha\n acc *= acc_scale[:, None]\n acc += tl.dot(p.to(MATMUL_PRECISION), v.to(MATMUL_PRECISION))\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n acc = acc / l_i[:, None]\n idx_z = tl.program_id(1) // H\n idx_h = tl.program_id(1) % H\n idx_m = offs_m[:, None]\n idx_d = tl.arange(0, BLOCK_DMODEL)[None, :]\n mask = (idx_m != -1) & (idx_d != -1)\n xindex = idx_d + 64 * idx_m + 262144 * idx_h + 4194304 * idx_z\n tl.store(out_ptr0 + xindex, acc, None)\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/template_attention/triton_attention.py" }, { "uuid": "2b4627a5-61b5-4d4b-aacb-1b0565738910", "file_name": "masks.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/flash/masks.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef alibi_attention_triton(score, batch, head, seq_len_q, seq_len_kv, num_heads\n ):\n alibi_scale = tl.math.exp2(-((head + 1) * 8.0 / num_heads))\n bias = seq_len_kv - seq_len_q\n score = score + alibi_scale * bias\n return score\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/flash/masks.py" }, { "uuid": "6b120d1b-0950-4333-ad5e-5a0ff072d2b4", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(list(filter(keep, configsTma)), key=['N_CTX'])\n@triton.jit\ndef _attn_fwd_tma(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v, desc_o,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.constexpr, STAGE: tl.\n constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE: tl.constexpr,\n ENABLE_WS: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n pid = tl.program_id(0)\n off_hz = tl.program_id(1)\n _attn_fwd_compute(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid,\n Z, H, N_CTX, BLOCK_M, BLOCK_N, HEAD_DIM, STAGE, ENABLE_TMA,\n LOOP_SCHEDULE)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "ffd4e13b-2976-4dd9-bf5e-79d064300709", "file_name": "08-grouped-gemm.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/08-grouped-gemm.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32, 'NUM_SM': 84}), triton.Config(\n {'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32, 'NUM_SM':\n 128}), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 32, 'NUM_SM': 84}), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32, 'NUM_SM': 128})], key=[\n 'group_size'])\n@triton.jit\ndef grouped_matmul_kernel(group_a_ptrs, group_b_ptrs, group_c_ptrs,\n group_gemm_sizes, g_lds, group_size, NUM_SM: tl.constexpr, BLOCK_SIZE_M:\n tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr):\n tile_idx = tl.program_id(0)\n last_problem_end = 0\n for g in range(group_size):\n gm = tl.load(group_gemm_sizes + g * 3)\n gn = tl.load(group_gemm_sizes + g * 3 + 1)\n gk = tl.load(group_gemm_sizes + g * 3 + 2)\n num_m_tiles = tl.cdiv(gm, BLOCK_SIZE_M)\n num_n_tiles = tl.cdiv(gn, BLOCK_SIZE_N)\n num_tiles = num_m_tiles * num_n_tiles\n while (tile_idx >= last_problem_end and tile_idx < last_problem_end +\n num_tiles):\n k = gk\n lda = tl.load(g_lds + g * 3)\n ldb = tl.load(g_lds + g * 3 + 1)\n ldc = tl.load(g_lds + g * 3 + 2)\n a_ptr = tl.load(group_a_ptrs + g).to(tl.pointer_type(tl.float16))\n b_ptr = tl.load(group_b_ptrs + g).to(tl.pointer_type(tl.float16))\n c_ptr = tl.load(group_c_ptrs + g).to(tl.pointer_type(tl.float16))\n tile_idx_in_gemm = tile_idx - last_problem_end\n tile_m_idx = tile_idx_in_gemm // num_n_tiles\n tile_n_idx = tile_idx_in_gemm % num_n_tiles\n offs_am = tile_m_idx * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_bn = tile_n_idx * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + offs_am[:, None] * lda + offs_k[None, :]\n b_ptrs = b_ptr + offs_k[:, None] * ldb + offs_bn[None, :]\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.\n float32)\n for kk in range(0, tl.cdiv(k, BLOCK_SIZE_K)):\n tl.multiple_of(a_ptrs, [16, 16])\n tl.multiple_of(b_ptrs, [16, 16])\n a = tl.load(a_ptrs)\n b = tl.load(b_ptrs)\n accumulator += tl.dot(a, b)\n a_ptrs += BLOCK_SIZE_K\n b_ptrs += BLOCK_SIZE_K * ldb\n c = accumulator.to(tl.float16)\n offs_cm = tile_m_idx * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = tile_n_idx * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + ldc * offs_cm[:, None] + offs_cn[None, :]\n tl.store(c_ptrs, c)\n tile_idx += NUM_SM\n last_problem_end = last_problem_end + num_tiles\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/08-grouped-gemm.py" }, { "uuid": "ea89f9e0-302f-4fd2-a737-0aff546ce52f", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_N': b_n,\n 'BLOCK_SIZE_K': b_k}, num_warps=w) for b_n, b_k, w in itertools.product\n ([(4 ** n) for n in range(6)], [(4 ** n) for n in range(4)], [2, 4, 8])\n ], key=['N'])\n@triton.jit\ndef triton_sum_kernel_2D_result_dim_1_sum_then_buffer(input_ptr, output_ptr,\n M: tl.constexpr, N: tl.constexpr, K: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr):\n \"\"\"\n Modification to triton_sum_kernel_2D_result_dim_1() which uses a buffer to store intermediate results,\n enabling reducing over a large middle dimension for 3D input tensors\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_m = pid // tl.cdiv(K, BLOCK_SIZE_K)\n pid_k = pid % tl.cdiv(K, BLOCK_SIZE_K)\n buffer = tl.zeros((1, BLOCK_SIZE_K), dtype=tl.float32)\n block_start_k = pid_k * BLOCK_SIZE_K\n offsets_k = block_start_k + tl.arange(0, BLOCK_SIZE_K)\n mask_k = offsets_k < K\n for block_start_n in range(0, N, BLOCK_SIZE_N):\n offsets_n = block_start_n + tl.arange(0, BLOCK_SIZE_N)\n mask_n = offsets_n < N\n idxs_base = offsets_n[:, None] * K + offsets_k\n idxs = idxs_base + pid_m * N * K\n mask = mask_n[:, None] & mask_k\n input = tl.load(input_ptr + idxs, mask=mask, other=0)\n buffer += tl.sum(input, axis=0)\n buffer_view = buffer.reshape((BLOCK_SIZE_K,))\n output_offsets = pid_m * K + offsets_k\n tl.store(output_ptr + output_offsets, buffer_view, mask=mask_k)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "Batch-Oriented" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/sum/kernels.py" }, { "uuid": "0d8babf1-950f-4d42-b5a5-310a8413e616", "file_name": "fused_moe_fp16.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/fused_moe_fp16.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _fused_moe_kernel(A, B, C, topk_weights_ptr, sorted_token_ids_ptr,\n expert_ids_ptr, num_tokens_post_padded_ptr, N, K, EM, num_valid_tokens,\n stride_am, stride_ak, stride_be, stride_bn, stride_bk, stride_cm,\n stride_cn, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M: tl.constexpr,\n MUL_ROUTED_WEIGHT: tl.constexpr, top_k: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(EM, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n num_tokens_post_padded = tl.load(num_tokens_post_padded_ptr)\n if pid_m * BLOCK_SIZE_M >= num_tokens_post_padded:\n return\n offs_token_id = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)\n token_mask = offs_token < num_valid_tokens\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = A + (offs_token[:, None] // top_k * stride_am + offs_k[None, :\n ] * stride_ak)\n off_experts = tl.load(expert_ids_ptr + pid_m)\n b_ptrs = B + off_experts * stride_be + (offs_k[:, None] * stride_bk + \n offs_bn[None, :] * stride_bn)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n _A0 = tl.zeros([1, 1], dtype=a_ptrs.dtype.element_ty)\n _B0 = tl.zeros([1, 1], dtype=b_ptrs.dtype.element_ty)\n for k in range(tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=token_mask[:, None] & (offs_k[None, :] < K -\n k * BLOCK_SIZE_K), other=_A0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < K - k * BLOCK_SIZE_K,\n other=_B0)\n accumulator += tl.dot(a, b)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n if MUL_ROUTED_WEIGHT:\n moe_weight = tl.load(topk_weights_ptr + offs_token, mask=token_mask,\n other=0)\n accumulator = accumulator * moe_weight[:, None]\n accumulator = accumulator.to(A.dtype.element_ty)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = C + stride_cm * offs_token[:, None] + stride_cn * offs_cn[None, :]\n c_mask = token_mask[:, None] & (offs_cn[None, :] < N)\n tl.store(c_ptrs, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Top-K Selection" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput", "Batch-Oriented" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/fused_moe_fp16.py" }, { "uuid": "90a00adc-8b7b-4112-b132-f300bfc18a2a", "file_name": "rwkv_vanilla.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/rwkv_vanilla.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef wkv_triton_vanilla_backward_kernel(w_ptr, w_s_c, u_ptr, u_s_c, k_ptr,\n k_s_b, k_s_t, k_s_c, v_ptr, v_s_b, v_s_t, v_s_c, state_ptr, state_s_b,\n state_s_ab, state_s_t, state_s_c, gwkv_ptr, gwkv_s_b, gwkv_s_t,\n gwkv_s_c, gstate_out_ptr, gstate_out_s_b, gstate_out_s_ab,\n gstate_out_s_c, gw_ptr, gw_s_c, gu_ptr, gu_s_c, gk_ptr, gk_s_b, gk_s_t,\n gk_s_c, gv_ptr, gv_s_b, gv_s_t, gv_s_c, gstate_ptr, gstate_s_b,\n gstate_s_ab, gstate_s_c, tsz, chans, BLOCK_SIZE_C: tl.constexpr):\n b_idx = tl.program_id(0)\n c_idx = tl.program_id(1)\n cs = c_idx * BLOCK_SIZE_C + tl.arange(0, BLOCK_SIZE_C)\n cmask = cs < chans\n k_ptr = k_ptr + b_idx * k_s_b\n v_ptr = v_ptr + b_idx * v_s_b\n alpha_ptr = state_ptr + b_idx * state_s_b\n beta_ptr = state_ptr + b_idx * state_s_b + state_s_ab\n gk_ptr = gk_ptr + b_idx * gk_s_b\n gv_ptr = gv_ptr + b_idx * gv_s_b\n gwkv_ptr = gwkv_ptr + b_idx * gwkv_s_b\n galpha_out_ptr = gstate_out_ptr + b_idx * gstate_out_s_b\n gbeta_out_ptr = gstate_out_ptr + b_idx * gstate_out_s_b + gstate_out_s_ab\n galpha = tl.load(galpha_out_ptr + gstate_out_s_c * cs, mask=cmask).to(tl\n .float32)\n gbeta = tl.load(gbeta_out_ptr + gstate_out_s_c * cs, mask=cmask).to(tl.\n float32)\n w = tl.load(w_ptr + w_s_c * cs, mask=cmask).to(tl.float32)\n u = tl.load(u_ptr + u_s_c * cs, mask=cmask).to(tl.float32)\n ew = tl.exp(w)\n gw = tl.zeros_like(w)\n gu = tl.zeros_like(u)\n for t in range(tsz):\n tc = tsz - t - 1\n kt = tl.load(k_ptr + tc * k_s_t + k_s_c * cs, mask=cmask).to(tl.float32\n )\n vt = tl.load(v_ptr + tc * v_s_t + v_s_c * cs, mask=cmask).to(tl.float32\n )\n alpha_prev = tl.load(alpha_ptr + tc * state_s_t + state_s_c * cs,\n mask=cmask).to(tl.float32)\n beta_prev = tl.load(beta_ptr + tc * state_s_t + state_s_c * cs,\n mask=cmask).to(tl.float32)\n euk = tl.exp(u + kt)\n ek = tl.exp(kt)\n denom = beta_prev + euk\n denom_sq = denom * denom\n gwkvt = tl.load(gwkv_ptr + tc * gwkv_s_t + gwkv_s_c * cs, mask=cmask\n ).to(tl.float32)\n guk = gwkvt * euk * (beta_prev * vt - alpha_prev) / denom_sq\n gu += guk\n gk = guk\n gv = gwkvt * euk / denom\n galpha_wkv = gwkvt / denom\n gbeta_wkv = -gwkvt * (euk * vt + alpha_prev) / denom_sq\n gw += galpha * ew * alpha_prev\n gk += galpha * ek * vt\n gv += galpha * ek\n gw += gbeta * ew * beta_prev\n gk += gbeta * ek\n tl.store(gk_ptr + tc * gk_s_t + gk_s_c * cs, gk, mask=cmask)\n tl.store(gv_ptr + tc * gv_s_t + gv_s_c * cs, gv, mask=cmask)\n galpha = galpha * ew + galpha_wkv\n gbeta = gbeta * ew + gbeta_wkv\n galpha_ptr = gstate_ptr + b_idx * gstate_s_b\n gbeta_ptr = gstate_ptr + b_idx * gstate_s_b + gstate_s_ab\n tl.store(galpha_ptr + gstate_s_c * cs, galpha, mask=cmask)\n tl.store(gbeta_ptr + gstate_s_c * cs, gbeta, mask=cmask)\n tl.atomic_add(gw_ptr + gw_s_c * cs, gw, mask=cmask)\n tl.atomic_add(gu_ptr + gu_s_c * cs, gu, mask=cmask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Batch-Oriented" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/rwkv_vanilla.py" }, { "uuid": "52b81982-1106-4fa0-9262-3ccc64858017", "file_name": "gemm_postop_gelu_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef tanh(x):\n return 2 * tl.sigmoid(2 * x) - 1\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Low Latency", "Single Instance" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py" }, { "uuid": "a830e503-24c8-412e-a532-a0dc3f91630f", "file_name": "k_softmax_dropout.py", "repo_name": "kimiasa/Experiments", "file_path": "src/ops/triton/k_softmax_dropout.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['K'])\n@triton.heuristics({'DEPTH': lambda nargs: get_depth(nargs['K'])})\n@triton.heuristics({'IS_FP16': lambda nargs: nargs['GradIn'].dtype == torch\n .float16})\n@triton.jit\ndef _softmax_dropout_backward(GradIn, GradOut, Out, DropoutMask,\n dropout_prob, stride_bm, stride_bn, stride_gm, stride_gn, stride_om,\n stride_on, stride_mm, stride_mn, K, CAUSAL: tl.constexpr, DEPTH: tl.\n constexpr, IS_FP16: tl.constexpr):\n \"\"\"\n Compute the softmax gradients.\n ..Note: Not autotuning for now because this would lead to broken accumulated gradients\n \"\"\"\n m = tl.program_id(0)\n n = tl.program_id(1)\n k = tl.arange(0, DEPTH)\n grad_out_ptrs = GradOut + m * stride_gm + n * stride_gn + k\n out_ptrs = Out + m * stride_om + n * stride_on + k\n dropout_mask_ptrs = DropoutMask + m * stride_mm + n * stride_mn + k\n io_mask = k < K\n if CAUSAL:\n io_mask = io_mask & (k <= n)\n g = tl.load(grad_out_ptrs, mask=io_mask, other=float(0))\n o = tl.load(out_ptrs, mask=io_mask, other=float(0))\n zero = float(0)\n zero = zero.to(g.dtype)\n if CAUSAL:\n g = tl.where(k > n, zero, g)\n o = tl.where(k > n, zero, o)\n dropout_mask = tl.load(dropout_mask_ptrs, mask=io_mask, other=float(0))\n g = tl.where(dropout_mask != 0, g / (1 - dropout_prob), zero)\n s = tl.sum(g * o, 0)\n grad_in = o * (g - s)\n grad_in_ptrs = GradIn + m * stride_bm + n * stride_bn + k\n tl.store(grad_in_ptrs, grad_in, mask=k < K)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/ops/triton/k_softmax_dropout.py" }, { "uuid": "bef108ba-facf-4f6f-b328-e31add9c646e", "file_name": "real_rnn_tie_input_gate.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef bwd_sequential_scan(grad_output, v, f, h, B, L, C, BLOCK_M: tl.constexpr):\n offset_b = tl.program_id(0)\n if offset_b >= B:\n return\n offset_n = tl.program_id(1)\n ptr = tl.arange(0, BLOCK_M) + offset_b * L * C + (L - 1\n ) * C + offset_n * BLOCK_M\n grad_h = tl.zeros([BLOCK_M], dtype=tl.float32)\n for time_step in range(L - 1, -1, -1):\n grad = tl.load(grad_output + ptr).to(tl.float32)\n grad_h += grad\n decay = tl.load(f + ptr).to(tl.float32)\n input = tl.load(v + ptr).to(tl.float32)\n grad_v = (1 - decay) * grad_h\n tl.store(v + ptr, grad_v.to(v.dtype.element_ty))\n hidden_state = tl.load(h + ptr - C, mask=ptr >= offset_b * L * C +\n C, other=0.0).to(tl.float32)\n grad_f = grad_h * (hidden_state - input)\n tl.store(f + ptr, grad_f.to(f.dtype.element_ty))\n grad_h *= decay\n ptr -= C\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Batch-Oriented" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py" }, { "uuid": "a0a75d1e-5e2f-47cc-b051-e6ae5e19ac3a", "file_name": "normalization.py", "repo_name": "rosinality/halite", "file_path": "src/halite/nn/normalization.py", "commit_hash": "0653355c3dac8cfa80d66ec5a82c202c49c64205", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N'])\n@triton.jit\ndef _rms_norm_bwd_kernel_sm(X, stride_x, W, DY, stride_dy, DX, stride_dx,\n Rstd, DW, eps, M, N, rows_per_program, block_N: tl.constexpr):\n row_block_id = tl.program_id(0)\n row_start = row_block_id * rows_per_program\n cols = tl.arange(0, block_N)\n mask = cols < N\n w = tl.load(W + cols, mask=mask, other=0.0).to(tl.float32)\n dw = tl.zeros((block_N,), dtype=tl.float32)\n row_end = min(row_start + rows_per_program, M)\n for row in range(row_start, row_end):\n x = tl.load(X + row * stride_x + cols, mask=mask, other=0.0).to(tl.\n float32)\n dy = tl.load(DY + row * stride_dy + cols, mask=mask, other=0.0).to(tl\n .float32)\n rstd = tl.load(Rstd + row)\n x_hat = x * rstd\n wdy = w * dy\n dw += dy * x_hat\n c1 = tl.sum(x_hat * wdy, axis=0) / N\n dx = (wdy - x_hat * c1) * rstd\n tl.store(DX + row * stride_dx + cols, dx, mask=mask)\n tl.store(DW + row_block_id * N + cols, dw, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/rosinality/halite/blob/0653355c3dac8cfa80d66ec5a82c202c49c64205/src/halite/nn/normalization.py" }, { "uuid": "69397af9-0c6f-44c6-9f5b-a774c749f5b4", "file_name": "linear.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/ops/linear.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef triton_linear(a_ptr, b_ptr, c_ptr, out_ptr, M, N, K, stride_am,\n stride_ak, stride_bk, stride_bn, GROUP_M: tl.constexpr, EVEN_K: tl.\n constexpr, ALLOW_TF32: tl.constexpr, ACC_TYPE: tl.constexpr,\n B_PROLOGUE_CAST_TYPE: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr, BLOCK_K: tl.constexpr):\n pid = tl.program_id(0)\n grid_m = (M + BLOCK_M - 1) // BLOCK_M\n grid_n = (N + BLOCK_N - 1) // BLOCK_N\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n offset_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offset_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n if stride_am == 1 and stride_ak == M or stride_am == K and stride_ak == 1:\n offset_am = tl.max_contiguous(tl.multiple_of(offset_m % M, BLOCK_M),\n BLOCK_M)\n else:\n offset_am = offset_m % M\n if stride_bk == 1 and stride_bn == K or stride_bk == N and stride_bn == 1:\n offset_bn = tl.max_contiguous(tl.multiple_of(offset_n % N, BLOCK_N),\n BLOCK_N)\n else:\n offset_bn = offset_n % N\n offset_k = tl.arange(0, BLOCK_K)\n a_ptrs = a_ptr + (offset_am[:, None] * stride_am + offset_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + (offset_k[:, None] * stride_bk + offset_bn[None, :] *\n stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=ACC_TYPE)\n for k in range(K, 0, -BLOCK_K):\n if EVEN_K:\n a = tl.load(a_ptrs)\n b = tl.load(b_ptrs)\n else:\n a = tl.load(a_ptrs, mask=offset_k[None, :] < k, other=0.0)\n b = tl.load(b_ptrs, mask=offset_k[:, None] < k, other=0.0)\n if B_PROLOGUE_CAST_TYPE is not None:\n b = b.to(B_PROLOGUE_CAST_TYPE)\n acc += tl.dot(a, b, allow_tf32=ALLOW_TF32)\n a_ptrs += BLOCK_K * stride_ak\n b_ptrs += BLOCK_K * stride_bk\n offset_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offset_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n idx_m = offset_m[:, None]\n idx_n = offset_n[None, :]\n mask = (idx_m < M) & (idx_n < N)\n xindex = idx_n + N * idx_m\n c = tl.load(c_ptr + tl.broadcast_to(idx_n, mask.shape), mask,\n eviction_policy='evict_last').to(tl.float32)\n out = acc + c\n tl.store(out_ptr + tl.broadcast_to(xindex, mask.shape), out, mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/ops/linear.py" }, { "uuid": "ec7504ed-22fc-448a-af45-338b981af454", "file_name": "slstm_bw.py", "repo_name": "NX-AI/flashrnn", "file_path": "flashrnn/flashrnn/triton_fused/slstm_bw.py", "commit_hash": "3fca666a81c8740af4878d7bc5e2a51900e4fe14", "starcount": 0, "input": "@triton.jit\ndef _backward_sequence_kernel(delta_states_all_outside,\n delta_states_last_outside, R, states_all, gates_all,\n delta_states_initial, delta_Wx, delta_R, delta_b, T: tl.constexpr, NS:\n tl.constexpr, B: tl.constexpr, NH: tl.constexpr, DH: tl.constexpr, NGI:\n tl.constexpr, NGR: tl.constexpr, siz_B: tl.constexpr, DTYPE: tl.\n constexpr=tl.float32, backward_recurrent_clip_val: tl.constexpr=-1.0):\n idx_b_NH, idx_b_B = tl.program_id(0), tl.program_id(1)\n str_matR_B = NH * NGR * DH * DH\n str_matR_NH = NGR * DH * DH\n str_matR_NGR = DH * DH\n str_matStatesAll_NH = (T + 1) * NS * B * DH\n str_matStatesAll_T = NS * B * DH\n str_matGatesAll_NH = T * NGI * B * DH\n str_matGatesAll_T = NGI * B * DH\n str_delta_states_all_outside_NH = T * NS * B * DH\n str_delta_states_all_outside_T = NS * B * DH\n str_matDeltaWx_NH = T * NGI * B * DH\n str_matDeltaWx_T = NGI * B * DH\n matDeltaHtrans_last_ptr = tl.make_block_ptr(base=\n delta_states_last_outside + idx_b_NH * NS * B * DH + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matDeltaH_tplus1 = tl.load(matDeltaHtrans_last_ptr).to(tl.float32)\n matDeltaCtrans_last_ptr = tl.make_block_ptr(base=\n delta_states_last_outside + idx_b_NH * NS * B * DH + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matDeltaC_tplus1 = tl.load(matDeltaCtrans_last_ptr).to(tl.float32)\n matDeltaNtrans_last_ptr = tl.make_block_ptr(base=\n delta_states_last_outside + idx_b_NH * NS * B * DH + 2 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matDeltaN_tplus1 = tl.load(matDeltaNtrans_last_ptr).to(tl.float32)\n matR_i_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 0 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_i = tl.load(matR_i_ptr)\n matR_f_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 1 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_f = tl.load(matR_f_ptr)\n matR_z_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 2 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_z = tl.load(matR_z_ptr)\n matR_o_ptr = tl.make_block_ptr(base=R + idx_b_NH * str_matR_NH + 3 *\n str_matR_NGR, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matR_o = tl.load(matR_o_ptr)\n matDeltaR_i = tl.zeros((DH, DH), dtype=tl.float32)\n matDeltaR_f = tl.zeros((DH, DH), dtype=tl.float32)\n matDeltaR_z = tl.zeros((DH, DH), dtype=tl.float32)\n matDeltaR_o = tl.zeros((DH, DH), dtype=tl.float32)\n vecDeltaB_i = tl.zeros((DH,), dtype=tl.float32)\n vecDeltaB_f = tl.zeros((DH,), dtype=tl.float32)\n vecDeltaB_z = tl.zeros((DH,), dtype=tl.float32)\n vecDeltaB_o = tl.zeros((DH,), dtype=tl.float32)\n for idx_t in range(T - 1, -1, -1):\n matG_i_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_ibar = tl.load(matG_i_ptr).to(tl.float32)\n matG_f_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_fbar = tl.load(matG_f_ptr).to(tl.float32)\n matG_z_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 2 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_z = tl.load(matG_z_ptr)\n matG_o_ptr = tl.make_block_ptr(base=gates_all + idx_b_NH *\n str_matGatesAll_NH + idx_t * str_matGatesAll_T + 3 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matG_o = tl.load(matG_o_ptr)\n matC_t_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 1 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n matC_t = tl.load(matC_t_ptr)\n matN_t_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 2 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n matN_t = tl.load(matN_t_ptr)\n matM_t_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 3 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n matM_t = tl.load(matM_t_ptr).to(tl.float32)\n matH_tminus1_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + idx_t * str_matStatesAll_T + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matH_tminus1 = tl.load(matH_tminus1_ptr)\n matC_tminus1_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + idx_t * str_matStatesAll_T + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matC_tminus1 = tl.load(matC_tminus1_ptr)\n matN_tminus1_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + idx_t * str_matStatesAll_T + 2 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matN_tminus1 = tl.load(matN_tminus1_ptr)\n matM_tminus1_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + idx_t * str_matStatesAll_T + 3 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n matM_tminus1 = tl.load(matM_tminus1_ptr).to(tl.float32)\n matDeltaHtrans_out_t_ptr = tl.make_block_ptr(base=\n delta_states_all_outside + idx_b_NH *\n str_delta_states_all_outside_NH + idx_t *\n str_delta_states_all_outside_T + 0 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matDeltaHtrans_out_t = tl.load(matDeltaHtrans_out_t_ptr)\n matDeltaCtrans_out_t_ptr = tl.make_block_ptr(base=\n delta_states_all_outside + idx_b_NH *\n str_delta_states_all_outside_NH + idx_t *\n str_delta_states_all_outside_T + 1 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matDeltaCtrans_out_t = tl.load(matDeltaCtrans_out_t_ptr)\n matDeltaNtrans_out_t_ptr = tl.make_block_ptr(base=\n delta_states_all_outside + idx_b_NH *\n str_delta_states_all_outside_NH + idx_t *\n str_delta_states_all_outside_T + 1 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matDeltaNtrans_out_t = tl.load(matDeltaNtrans_out_t_ptr)\n matDeltaH_t = matDeltaHtrans_out_t + matDeltaH_tplus1\n matDeltaC_t = matDeltaCtrans_out_t + matDeltaC_tplus1\n matDeltaN_t = matDeltaNtrans_out_t + matDeltaN_tplus1\n matDeltaC_t = matDeltaC_t + matDeltaH_t * (matG_o / matN_t)\n matDeltaN_t = matDeltaN_t - matDeltaH_t * (matG_o * matC_t / (\n matN_t * matN_t))\n matG_i = tl.exp(matG_ibar - matM_t)\n matG_logfplusm = matM_tminus1 + tl.log(tl.sigmoid(matG_fbar))\n matG_f = tl.exp(matG_logfplusm - matM_t)\n matDeltaGI = (matDeltaC_t * matG_z + matDeltaN_t) * matG_i\n matDeltaGF = (matDeltaC_t * matC_tminus1 + matDeltaN_t * matN_tminus1\n ) * matG_f * tl.sigmoid(-matG_fbar)\n matDeltaGZ = matDeltaC_t * matG_i * (1 - matG_z * matG_z)\n matDeltaGO = matDeltaH_t * (matC_t / matN_t) * (1 - matG_o) * matG_o\n matDeltaC_tminus1 = matDeltaC_t * matG_f\n matDeltaN_tminus1 = matDeltaN_t * matG_f\n matDeltaH_tminus1 = tl.dot(matDeltaGI.to(DTYPE), matR_i)\n matDeltaH_tminus1 += tl.dot(matDeltaGF.to(DTYPE), matR_f)\n matDeltaH_tminus1 += tl.dot(matDeltaGZ.to(DTYPE), matR_z)\n matDeltaH_tminus1 += tl.dot(matDeltaGO.to(DTYPE), matR_o)\n matDeltaR_i += tl.dot(tl.trans(matDeltaGI.to(DTYPE)), matH_tminus1)\n matDeltaR_f += tl.dot(tl.trans(matDeltaGF.to(DTYPE)), matH_tminus1)\n matDeltaR_z += tl.dot(tl.trans(matDeltaGZ.to(DTYPE)), matH_tminus1)\n matDeltaR_o += tl.dot(tl.trans(matDeltaGO.to(DTYPE)), matH_tminus1)\n vecDeltaB_i += tl.sum(matDeltaGI, axis=0)\n vecDeltaB_f += tl.sum(matDeltaGF, axis=0)\n vecDeltaB_z += tl.sum(matDeltaGZ, axis=0)\n vecDeltaB_o += tl.sum(matDeltaGO, axis=0)\n matDeltaGI_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 0 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGI_ptr, matDeltaGI.to(DTYPE))\n matDeltaGF_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 1 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGF_ptr, matDeltaGF.to(DTYPE))\n matDeltaGZ_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 2 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGZ_ptr, matDeltaGZ.to(DTYPE))\n matDeltaGO_ptr = tl.make_block_ptr(base=delta_Wx + idx_b_NH *\n str_matDeltaWx_NH + idx_t * str_matDeltaWx_T + 3 * B * DH,\n shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matDeltaGO_ptr, matDeltaGO.to(DTYPE))\n matDeltaH_tplus1 = matDeltaH_tminus1\n matDeltaC_tplus1 = matDeltaC_tminus1\n matDeltaN_tplus1 = matDeltaN_tminus1\n matDeltaHtrans_initial_ptr = tl.make_block_ptr(base=\n delta_states_initial + idx_b_NH * NS * B * DH + 0 * B * DH, shape=(\n B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=\n (siz_B, DH), order=(0, 1))\n tl.store(matDeltaHtrans_initial_ptr, matDeltaH_tplus1.to(DTYPE))\n matDeltaCtrans_initial_ptr = tl.make_block_ptr(base=\n delta_states_initial + idx_b_NH * NS * B * DH + 1 * B * DH, shape=(\n B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=\n (siz_B, DH), order=(0, 1))\n tl.store(matDeltaCtrans_initial_ptr, matDeltaC_tplus1.to(DTYPE))\n matDeltaNtrans_initial_ptr = tl.make_block_ptr(base=\n delta_states_initial + idx_b_NH * NS * B * DH + 2 * B * DH, shape=(\n B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=\n (siz_B, DH), order=(0, 1))\n tl.store(matDeltaNtrans_initial_ptr, matDeltaN_tplus1.to(DTYPE))\n matDeltaMtrans_initial_ptr = tl.make_block_ptr(base=\n delta_states_initial + idx_b_NH * NS * B * DH + 3 * B * DH, shape=(\n B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=\n (siz_B, DH), order=(0, 1))\n tl.store(matDeltaMtrans_initial_ptr, tl.zeros((siz_B, DH), dtype=DTYPE))\n matDeltaR_i_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 0 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_i_ptr, matDeltaR_i.to(DTYPE))\n matDeltaR_f_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 1 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_f_ptr, matDeltaR_f.to(DTYPE))\n matDeltaR_z_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 2 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_z_ptr, matDeltaR_z.to(DTYPE))\n matDeltaR_o_ptr = tl.make_block_ptr(base=delta_R + idx_b_B * str_matR_B +\n idx_b_NH * str_matR_NH + 3 * str_matR_NGR, shape=(DH, DH), strides=\n (DH, 1), offsets=(0, 0), block_shape=(DH, DH), order=(0, 1))\n tl.store(matDeltaR_o_ptr, matDeltaR_o.to(DTYPE))\n vecDeltaB_i_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 0 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_i_ptr, vecDeltaB_i.to(DTYPE))\n vecDeltaB_f_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 1 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_f_ptr, vecDeltaB_f.to(DTYPE))\n vecDeltaB_z_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 2 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_z_ptr, vecDeltaB_z.to(DTYPE))\n vecDeltaB_o_ptr = (delta_b + idx_b_B * NH * NGI * DH + idx_b_NH * NGI *\n DH + 3 * DH + tl.arange(0, DH))\n tl.store(vecDeltaB_o_ptr, vecDeltaB_o.to(DTYPE))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT", "BSD" ], "github_url": "https://github.com/NX-AI/flashrnn/blob/3fca666a81c8740af4878d7bc5e2a51900e4fe14/flashrnn/flashrnn/triton_fused/slstm_bw.py" }, { "uuid": "ca9df654-133c-4ad7-bf52-bab6ba0855c7", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _bwd_preprocess_do_o_dot(o_ptr, do_ptr, delta_ptr, T, stride_ob,\n stride_ot, stride_od, stride_do_b, stride_do_t, stride_do_d, BLOCK_T:\n tl.constexpr, BLOCK_D: tl.constexpr):\n start_t = tl.program_id(0)\n offs_t = start_t * BLOCK_T + tl.arange(0, BLOCK_T)\n pid_b = tl.program_id(1)\n offs_d = tl.arange(0, BLOCK_D)\n o_ptrs = o_ptr + pid_b * stride_ob + offs_t[:, None] * stride_ot + offs_d[\n None, :] * stride_od\n do_ptrs = do_ptr + pid_b * stride_do_b + offs_t[:, None\n ] * stride_do_t + offs_d[None, :] * stride_do_d\n o = tl.load(o_ptrs, mask=offs_t[:, None] < T, other=0.0)\n do = tl.load(do_ptrs, mask=offs_t[:, None] < T, other=0.0)\n delta = tl.sum(o * do, axis=1)\n delta_ptrs = delta_ptr + pid_b * T + offs_t\n tl.store(delta_ptrs, delta, mask=offs_t < T)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "89cd787f-1e2c-4865-a904-bc0d36218c36", "file_name": "flash_attention_nopad.py", "repo_name": "tascj/kaggle-lmsys-chatbot-arena", "file_path": "human_pref/inference/ops/flash_attention_nopad.py", "commit_hash": "83cd93d50b9283c18711e8c63e4e1c6399c7b9ce", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel(Q, K, V, sm_scale, B_Start_Loc, B_Seqlen, Out, stride_qbs,\n stride_qh, stride_qd, stride_kbs, stride_kh, stride_kd, stride_vbs,\n stride_vh, stride_vd, stride_obs, stride_oh, stride_od, kv_group_num,\n logit_softcapping: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_DMODEL:\n tl.constexpr, BLOCK_N: tl.constexpr):\n \"\"\"flash attention forward triton kernel.\"\"\"\n cur_batch = tl.program_id(0)\n cur_head = tl.program_id(1)\n start_m = tl.program_id(2)\n cur_kv_head = cur_head // kv_group_num\n cur_batch_seq_len = tl.load(B_Seqlen + cur_batch)\n cur_batch_in_all_start_index = tl.load(B_Start_Loc + cur_batch)\n block_start_loc = BLOCK_M * start_m\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n off_q = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_qbs + cur_head * stride_qh + offs_d[None, :] * stride_qd\n off_k = offs_n[None, :] * stride_kbs + cur_kv_head * stride_kh + offs_d[\n :, None] * stride_kd\n off_v = offs_n[:, None] * stride_vbs + cur_kv_head * stride_vh + offs_d[\n None, :] * stride_vd\n q = tl.load(Q + off_q, mask=offs_m[:, None] < cur_batch_seq_len, other=0.0)\n k_ptrs = K + off_k\n v_ptrs = V + off_v\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n block_mask = tl.where(block_start_loc < cur_batch_seq_len, 1, 0)\n end_n = tl.minimum((start_m + 1) * BLOCK_M, cur_batch_seq_len)\n for start_n in range(0, block_mask * end_n, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(k_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_kbs, mask=start_n + offs_n[None, :] < cur_batch_seq_len,\n other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk = tl.dot(q, k, qk)\n qk *= sm_scale\n if logit_softcapping > 0.0:\n qk = qk / logit_softcapping\n qk = tl.math.tanh(qk)\n qk = qk * logit_softcapping\n qk_mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk = tl.where(qk_mask, qk, float('-inf'))\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n p = tl.exp(qk - m_i_new[:, None])\n alpha = tl.exp(m_i - m_i_new)\n l_i_new = alpha * l_i + tl.sum(p, 1)\n acc = acc * alpha[:, None]\n v = tl.load(v_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_vbs, mask=start_n + offs_n[:, None] < cur_batch_seq_len,\n other=0.0)\n p = p.to(v.dtype)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n acc = acc / l_i[:, None]\n off_o = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_obs + cur_head * stride_oh + offs_d[None, :] * stride_od\n out_ptrs = Out + off_o\n tl.store(out_ptrs, acc.to(Out.type.element_ty), mask=offs_m[:, None] <\n cur_batch_seq_len)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/tascj/kaggle-lmsys-chatbot-arena/blob/83cd93d50b9283c18711e8c63e4e1c6399c7b9ce/human_pref/inference/ops/flash_attention_nopad.py" }, { "uuid": "3b340b98-2a14-4946-85d4-8529289fd141", "file_name": "mhmoe_bwd.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe_bwd.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_B': 32, 'BLOCK_SIZE_E':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_B': 64,\n 'BLOCK_SIZE_E': 32}, num_stages=2, num_warps=4), triton.Config({\n 'BLOCK_SIZE_B': 32, 'BLOCK_SIZE_E': 64}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_B': 64, 'BLOCK_SIZE_E': 64}, num_stages=2,\n num_warps=4)], key=['H', 'B', 'D', 'E'])\n@triton.jit\ndef mlp_wide_kernel_bwd2(x_ptr, w1_ptr, w2_ptr, o_ptr, dx_ptr, dw1_ptr,\n dw2_ptr, do_ptr, H, B, D: tl.constexpr, E, stride_xb, stride_xd,\n stride_w1d, stride_w1e, stride_w2e, stride_w2d, stride_ob, stride_od,\n stride_dxb, stride_dxd, stride_dw1d, stride_dw1e, stride_dw2e,\n stride_dw2d, stride_dob, stride_dod, BLOCK_SIZE_B: tl.constexpr,\n BLOCK_SIZE_E: tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp\n Z = X @ W1, H = f(Z), O = H @ W2\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n - dX has shape (B, D)\n - dW1 has shape (D, E)\n - dW2 has shape (E, D)\n - dO has shape (B, D)\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_x_w = 0\n batch_groups_e = tl.cdiv(E, BLOCK_SIZE_E)\n batch_groups_b = tl.cdiv(B, BLOCK_SIZE_B)\n idx = pid % (batch_groups_e + batch_groups_b)\n pid_h = pid // (batch_groups_e + batch_groups_b)\n TARGET_TYPE = x_ptr.type.element_ty\n offs_b = tl.arange(0, BLOCK_SIZE_B)\n offs_d = tl.arange(0, D)\n offs_e = tl.arange(0, BLOCK_SIZE_E)\n if idx >= batch_groups_e:\n pid_b = idx - batch_groups_e\n dx_ptrs = dx_ptr + ((pid_h * B + pid_b * BLOCK_SIZE_B + offs_b[:,\n None]) * stride_dxb + offs_d[None, :] * stride_dxd)\n dx_mask = (offs_b[:, None] < B - pid_b * BLOCK_SIZE_B) & (offs_d[\n None, :] < D)\n dx = tl.zeros((BLOCK_SIZE_B, D), dtype=tl.float32)\n dx = _mlp_wide_kernel_bwd_dx(pid_h, pid_b, x_ptr, w1_ptr, w2_ptr,\n o_ptr, dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D, E, stride_xb,\n stride_xd, stride_w1d, stride_w1e, stride_w2e, stride_w2d,\n stride_ob, stride_od, stride_dxb, stride_dxd, stride_dw1d,\n stride_dw1e, stride_dw2e, stride_dw2d, stride_dob, stride_dod,\n BLOCK_SIZE_B, BLOCK_SIZE_E, ACTIVATION)\n tl.store(dx_ptrs, dx.to(TARGET_TYPE), mask=dx_mask)\n else:\n pid_e = idx\n dw1_ptrs = dw1_ptr + ((pid_h * D + offs_d[:, None]) * stride_dw1d +\n (pid_e * BLOCK_SIZE_E + offs_e[None, :]) * stride_dw1e)\n dw1_mask = (offs_d[:, None] < D) & (offs_e[None, :] < E - pid_e *\n BLOCK_SIZE_E)\n dw2_ptrs = dw2_ptr + ((pid_h * E + pid_e * BLOCK_SIZE_E + offs_e[:,\n None]) * stride_dw2e + offs_d[None, :] * stride_dw2d)\n dw2_mask = (offs_e[:, None] < E - pid_e * BLOCK_SIZE_E) & (offs_d[\n None, :] < D)\n dw1, dw2 = _mlp_wide_kernel_bwd_dw1w2(pid_h, pid_e, x_ptr, w1_ptr,\n w2_ptr, o_ptr, dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D, E,\n stride_xb, stride_xd, stride_w1d, stride_w1e, stride_w2e,\n stride_w2d, stride_ob, stride_od, stride_dxb, stride_dxd,\n stride_dw1d, stride_dw1e, stride_dw2e, stride_dw2d, stride_dob,\n stride_dod, BLOCK_SIZE_B, BLOCK_SIZE_E, ACTIVATION)\n tl.store(dw1_ptrs, dw1.to(TARGET_TYPE), mask=dw1_mask)\n tl.store(dw2_ptrs, dw2.to(TARGET_TYPE), mask=dw2_mask)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe_bwd.py" }, { "uuid": "1d20f406-94e0-403c-a1e0-92ea5edee22d", "file_name": "rwkv_vanilla.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/rwkv_vanilla.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef wkv_triton_vanilla_forward_kernel(w_ptr, w_s_c, u_ptr, u_s_c, k_ptr,\n k_s_b, k_s_t, k_s_c, v_ptr, v_s_b, v_s_t, v_s_c, state_ptr, state_s_b,\n state_s_ab, state_s_c, wkv_ptr, wkv_s_b, wkv_s_t, wkv_s_c,\n state_out_ptr, state_out_s_b, state_out_s_ab, state_out_s_t,\n state_out_s_c, chans, tsz, BLOCK_SIZE_C: tl.constexpr):\n b_idx = tl.program_id(0)\n c_idx = tl.program_id(1)\n cs = c_idx * BLOCK_SIZE_C + tl.arange(0, BLOCK_SIZE_C)\n cmask = cs < chans\n k_ptr = k_ptr + b_idx * k_s_b\n v_ptr = v_ptr + b_idx * v_s_b\n alpha_ptr = state_ptr + b_idx * state_s_b\n beta_ptr = state_ptr + b_idx * state_s_b + state_s_ab\n wkv_ptr = wkv_ptr + b_idx * wkv_s_b\n alpha_out_ptr = state_out_ptr + b_idx * state_out_s_b\n beta_out_ptr = state_out_ptr + b_idx * state_out_s_b + state_out_s_ab\n alpha = tl.load(alpha_ptr + cs * state_s_c, mask=cmask).to(tl.float32)\n beta = tl.load(beta_ptr + cs * state_s_c, mask=cmask).to(tl.float32)\n w = tl.load(w_ptr + cs * w_s_c, mask=cmask).to(tl.float32)\n u = tl.load(u_ptr + cs * u_s_c, mask=cmask).to(tl.float32)\n ew = tl.exp(w)\n for t in range(tsz):\n kt = tl.load(k_ptr + t * k_s_t + cs * k_s_c, mask=cmask).to(tl.float32)\n vt = tl.load(v_ptr + t * v_s_t + cs * v_s_c, mask=cmask).to(tl.float32)\n euk = tl.exp(u + kt)\n wkv = (alpha + euk * vt) / (beta + euk)\n tl.store(wkv_ptr + t * wkv_s_t + cs * wkv_s_c, wkv, mask=cmask)\n ek = tl.exp(kt)\n alpha = ew * alpha + ek * vt\n beta = ew * beta + ek\n tl.store(alpha_out_ptr + t * state_out_s_t + cs * state_out_s_c,\n alpha, mask=cmask)\n tl.store(beta_out_ptr + t * state_out_s_t + cs * state_out_s_c,\n beta, mask=cmask)\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/rwkv_vanilla.py" }, { "uuid": "ebfa7825-dfff-4555-b37d-85b4f1aa9d91", "file_name": "seqlen_utils.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/seqlen_utils.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef clamp(x, amin, amax):\n x = tl.where(x < amin, amin, x)\n x = tl.where(x >= amax, amax, x)\n return x\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/seqlen_utils.py" }, { "uuid": "5655fee2-cd43-4aa1-9458-4f9a099947b6", "file_name": "y_2.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_2.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef second_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor,\n block_size: tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.\n constexpr, col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST_00 = 3.87298334620742\n CONST_01 = 2.23606797749979\n CONST_02 = -1.11803398874989\n CONST_03 = 1.93649167310371\n Y20 = CONST_00 * x * z\n Y21 = CONST_00 * x * y\n Y23 = CONST_00 * y * z\n Y22 = CONST_02 * x * x + CONST_01 * y * y + CONST_02 * z * z\n Y24 = -CONST_03 * x * x + CONST_03 * z * z\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y20, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y21, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y22, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y23, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y24, mask=\n output_row_offset + 4 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_2.py" }, { "uuid": "83df5d43-d1a9-47bb-98c2-6ef4b7de675b", "file_name": "blocksparse_sum.py", "repo_name": "kimiasa/Experiments", "file_path": "src/models/attention/blocksparse_sum.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.heuristics({'num_warps': lambda *args, **meta: num_warps(args[3] *\n meta['BLOCK'])})\n@triton.heuristics({'TN': lambda *args, **meta: next_power_of_2(args[3]) *\n meta['BLOCK']})\n@triton.jit\ndef _backward(DX, DOUT, LUT, sizemax, stride_zdx, stride_zdout,\n stride_hdout, **meta):\n pidhm = tl.program_id(0)\n pidz = tl.program_id(1)\n TN = meta['TN']\n BLOCK = meta['BLOCK']\n rxm = pidhm % BLOCK\n rbm = pidhm // BLOCK\n rxn = tl.arange(0, TN) % BLOCK\n rbn = tl.arange(0, TN) // BLOCK\n header = LUT + rbm * 2\n size = tl.load(header + 0)\n offset = tl.load(header + 1)\n check = rbn < size\n rbmn = tl.where(check, rbn, size - 1)\n blockid = tl.load(LUT + offset + rbmn * 4)\n rowid = tl.load(LUT + offset + rbmn * 4 + 2)\n headid = tl.load(LUT + offset + rbmn * 4 + 3)\n pdx = DX + pidz * stride_zdx + blockid * BLOCK * BLOCK + rxm * BLOCK + rxn\n pdout = (DOUT + pidz * stride_zdout + headid * stride_hdout + rowid *\n BLOCK + rxm)\n dx_zeros = tl.load(pdx, mask=check, other=0)\n dout = tl.load(pdout)\n dx = dout - dx_zeros\n tl.store(pdx, dx, mask=check)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/models/attention/blocksparse_sum.py" }, { "uuid": "f22d7c5d-4b22-44c8-bd17-71abf32be596", "file_name": "softmax_split.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_split.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef combine_logsumexp_kernel(out_ptr, inp_ptr, M, N, TILE_N: tl.constexpr):\n pid_m = tl.program_id(0)\n n_offsets = tl.arange(0, TILE_N)\n mask = n_offsets < N\n logzs = tl.load(inp_ptr + pid_m * N + n_offsets, other=-float('inf'),\n mask=mask).to(out_ptr.dtype.element_ty)\n m = tl.max(logzs, 0)\n e = tl.exp(logzs - m)\n z = tl.sum(e, 0)\n logz = m + tl.log(z)\n tl.store(out_ptr + pid_m, logz)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_split.py" }, { "uuid": "3f75f29d-097d-46b4-a75c-c46d48ca63f5", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_linear_attn_fwd_kernel_o(q, k, v, h, o, s_k_h, s_k_t, s_k_d,\n s_v_h, s_v_t, s_v_d, s_h_h, s_h_t, scale, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_s = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n b_s += tl.dot(b_q, b_k, allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_o = (b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)) * scale\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/chunk.py" }, { "uuid": "feb07ab0-66fa-4032-b855-37ff437994a7", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_dense_elementwise_mul_jagged_out_kernel(a_ptr, b_ptr, c_ptr,\n a_seq_lengths_ptr, a_offsets_ptr, stride_a, stride_bm, stride_bn,\n max_seq_len, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n pid_batch = tl.program_id(0)\n pid_row_block = tl.program_id(1)\n batch_offset = tl.load(a_offsets_ptr + pid_batch)\n batch_seq_len = tl.load(a_seq_lengths_ptr + pid_batch)\n truncated_seq_len = tl.minimum(batch_seq_len, max_seq_len)\n offs_row = tl.arange(0, BLOCK_M)\n offs_col = tl.arange(0, BLOCK_N)\n rows = pid_row_block * BLOCK_M + offs_row\n a_ptrs = a_ptr + batch_offset * stride_a + rows[:, None\n ] * truncated_seq_len + offs_col[None, :]\n b_ptrs = b_ptr + rows[:, None] * stride_bm + offs_col[None, :] * stride_bn\n c_ptrs = c_ptr + batch_offset + rows[:, None\n ] * truncated_seq_len + offs_col[None, :]\n for block_start in range(0, truncated_seq_len, BLOCK_N):\n cols = block_start + offs_col\n mask = (rows[:, None] < truncated_seq_len) & (cols[None, :] <\n truncated_seq_len)\n a = tl.load(a_ptrs, mask=mask)\n a_ptrs += BLOCK_N\n b = tl.load(b_ptrs, mask=mask)\n b_ptrs += BLOCK_N\n c = a * b\n tl.store(c_ptrs, c, mask=mask)\n c_ptrs += BLOCK_N\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "3b3299a2-36e9-47f7-8c4e-3fab53ca5277", "file_name": "rotary.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/rotary.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8, 16, 32]], key=['BLOCK_K', 'BLOCK_M', 'INTERLEAVED'])\n@triton.jit\ndef rotary_embedding_kernel(X, COS, SIN, OUT, CU_SEQLENS, SEQLEN_OFFSETS,\n seqlen, rotary_dim, seqlen_ro, stride_out_batch, stride_out_seqlen,\n stride_out_nheads, stride_out_headdim, stride_x_batch, stride_x_seqlen,\n stride_x_nheads, stride_x_headdim, BLOCK_K: tl.constexpr, BLOCK_M: tl.\n constexpr, IS_SEQLEN_OFFSETS_TENSOR: tl.constexpr, IS_VARLEN: tl.\n constexpr, INTERLEAVED: tl.constexpr, CONJUGATE: tl.constexpr):\n pid_m = tl.program_id(axis=0)\n pid_batch = tl.program_id(axis=1)\n pid_head = tl.program_id(axis=2)\n rotary_dim_half = rotary_dim // 2\n if not IS_VARLEN:\n X = X + pid_batch * stride_x_batch + pid_head * stride_x_nheads\n OUT = OUT + pid_batch * stride_out_batch + pid_head * stride_out_nheads\n else:\n start_idx = tl.load(CU_SEQLENS + pid_batch)\n seqlen = tl.load(CU_SEQLENS + pid_batch + 1) - start_idx\n X = X + start_idx * stride_x_seqlen + pid_head * stride_x_nheads\n OUT = (OUT + start_idx * stride_out_seqlen + pid_head *\n stride_out_nheads)\n if pid_m * BLOCK_M >= seqlen:\n return\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n if not IS_SEQLEN_OFFSETS_TENSOR:\n rm_cs = rm + SEQLEN_OFFSETS\n else:\n rm_cs = rm + tl.load(SEQLEN_OFFSETS + pid_batch)\n rk = tl.arange(0, BLOCK_K)\n rk_half = tl.arange(0, BLOCK_K // 2)\n if not INTERLEAVED:\n X = X + (rm[:, None] * stride_x_seqlen + rk_half[None, :] *\n stride_x_headdim)\n COS = COS + (rm_cs[:, None] * rotary_dim_half + rk_half[None, :])\n SIN = SIN + (rm_cs[:, None] * rotary_dim_half + rk_half[None, :])\n cos = tl.load(COS, mask=(rm_cs[:, None] < seqlen_ro) & (rk_half[\n None, :] < rotary_dim_half), other=1.0).to(tl.float32)\n sin = tl.load(SIN, mask=(rm_cs[:, None] < seqlen_ro) & (rk_half[\n None, :] < rotary_dim_half), other=0.0).to(tl.float32)\n x0 = tl.load(X, mask=(rm[:, None] < seqlen) & (rk_half[None, :] <\n rotary_dim_half), other=0.0).to(tl.float32)\n x1 = tl.load(X + rotary_dim_half * stride_x_headdim, mask=(rm[:,\n None] < seqlen) & (rk_half[None, :] < rotary_dim_half), other=0.0\n ).to(tl.float32)\n if CONJUGATE:\n sin = -sin\n o0 = x0 * cos - x1 * sin\n o1 = x0 * sin + x1 * cos\n OUT = OUT + (rm[:, None] * stride_out_seqlen + rk_half[None, :] *\n stride_out_headdim)\n tl.store(OUT, o0, mask=(rm[:, None] < seqlen) & (rk_half[None, :] <\n rotary_dim_half))\n tl.store(OUT + rotary_dim_half * stride_out_headdim, o1, mask=(rm[:,\n None] < seqlen) & (rk_half[None, :] < rotary_dim_half))\n else:\n rk_swap = rk + (rk + 1) % 2 * 2 - 1\n rk_repeat = tl.arange(0, BLOCK_K) // 2\n X0 = X + (rm[:, None] * stride_x_seqlen + rk[None, :] *\n stride_x_headdim)\n X1 = X + (rm[:, None] * stride_x_seqlen + rk_swap[None, :] *\n stride_x_headdim)\n COS = COS + (rm_cs[:, None] * rotary_dim_half + rk_repeat[None, :])\n SIN = SIN + (rm_cs[:, None] * rotary_dim_half + rk_repeat[None, :])\n cos = tl.load(COS, mask=(rm_cs[:, None] < seqlen_ro) & (rk_repeat[\n None, :] < rotary_dim_half), other=1.0).to(tl.float32)\n sin = tl.load(SIN, mask=(rm_cs[:, None] < seqlen_ro) & (rk_repeat[\n None, :] < rotary_dim_half), other=0.0).to(tl.float32)\n x0 = tl.load(X0, mask=(rm[:, None] < seqlen) & (rk[None, :] <\n rotary_dim), other=0.0).to(tl.float32)\n x1 = tl.load(X1, mask=(rm[:, None] < seqlen) & (rk_swap[None, :] <\n rotary_dim), other=0.0).to(tl.float32)\n if CONJUGATE:\n sin = -sin\n x0_cos = x0 * cos\n x1_sin = x1 * sin\n out = tl.where(rk[None, :] % 2 == 0, x0_cos - x1_sin, x0_cos + x1_sin)\n OUT = OUT + (rm[:, None] * stride_out_seqlen + rk[None, :] *\n stride_out_headdim)\n tl.store(OUT, out, mask=(rm[:, None] < seqlen) & (rk[None, :] <\n rotary_dim))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/rotary.py" }, { "uuid": "53d194b5-4f30-42c5-bcdc-aa0d961e4d3f", "file_name": "k_dropout.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_dropout.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.autotune(configs=_k_configs, key=['N'])\n@triton.jit\ndef k_dropout_bw(GRAD_IN, GRAD_OUT, INPUTS, BIAS, SEEDS, stride_grad,\n stride_inputs, N, p, **META):\n \"\"\"\n Apply dropout on an input tensor\n GRAD_OUT (M, N)\n GRAD_IN (M, N)\n BIAS (N,)\n SEEDS (M,)\n p : dropout probability\n \"\"\"\n BLOCK_SIZE = META['BLOCK_SIZE']\n row = tl.program_id(axis=0)\n col = tl.program_id(axis=1)\n grad_offsets = row * stride_grad + col * BLOCK_SIZE + tl.arange(0,\n BLOCK_SIZE)\n mask = col * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE) < N\n grad_out_ptrs = GRAD_OUT + grad_offsets\n grad_out = tl.load(grad_out_ptrs, mask=mask)\n if META['ACTIVATION_GRAD']:\n input_ptrs = (INPUTS + row * stride_inputs + col * BLOCK_SIZE + tl.\n arange(0, BLOCK_SIZE))\n inputs = tl.load(input_ptrs, mask=mask)\n if META['USE_BIAS']:\n b_ptrs = BIAS + col * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n b = tl.load(b_ptrs, mask=mask)\n inputs += b\n act_grad = META['ACTIVATION_GRAD'](inputs)\n grad_out *= act_grad\n if p > 0.0:\n output = _drop_and_scale(SEEDS, row, p, grad_offsets, grad_out)\n else:\n output = grad_out\n y_ptrs = GRAD_IN + grad_offsets\n tl.store(y_ptrs, output, mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_dropout.py" }, { "uuid": "212d49aa-c7b6-41bc-b921-3cda1e94187e", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/launch_latency/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.jit\ndef nop_with_args_kernel(t1, t2, t3, t4, t5, i1, i2, i3, i4, i5, i6, i7, i8,\n i9, c1: tl.constexpr, c2: tl.constexpr, c3: tl.constexpr, c4: tl.\n constexpr, c5: tl.constexpr):\n pass\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/launch_latency/kernels.py" }, { "uuid": "1dacd6b7-d7ac-4c8b-9b58-afc4b5e496bd", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=MATMUL_CONFIGS, key=['m_key', 'n_key', 'k_key'])\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.jit\ndef _kernel_matmul_fp8_row_imprecise_acc(A, B, C, M, N, K, m_key, n_key,\n k_key, A_scale, B_scale, Bias, stride_am, stride_ak, stride_bn,\n stride_bk, stride_cm, stride_cn, dot_out_dtype: tl.constexpr,\n allow_tf32: tl.constexpr, fp8_fast_accum: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.\n constexpr, SPLIT_K: tl.constexpr, EVEN_K: tl.constexpr, USE_BIAS: tl.\n constexpr, AB_DTYPE: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with row-wise scales\n\n performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles.\n\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n m_key (int): Autotuning key for M dimension of input tensor.\n n_key (int): Autotuning key for N dimension of input tensor.\n k_key (int): Autotuning key for K dimension of input tensor.\n A_scale (TensorWrapper): [M] reciprocal scale tensor per row. A * A_scale = original A\n B_scale (TensorWrapper): [N] reciprocal scale tensor per row. B * B_scale = original B\n Bias (TensorWrapper): [N] Optional bias tensor.\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n USE_BIAS (bool): Whether to use bias.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n _0 = tl.zeros((1, 1), dtype=C.dtype.element_ty)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_0)\n b = tl.load(B, mask=rk[:, None] < k_remaining, other=_0)\n if AB_DTYPE:\n a = a.to(C.dtype.element_ty)\n b = b.to(C.dtype.element_ty)\n if fp8_fast_accum:\n acc = tl.dot(a, b, acc, max_num_imprecise_acc=32, out_dtype=\n dot_out_dtype, allow_tf32=allow_tf32)\n else:\n acc += tl.dot(a, b, out_dtype=dot_out_dtype, allow_tf32=allow_tf32)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n a_scale = tl.load(A_scale + rm, mask=rm < M)\n b_scale = tl.load(B_scale + rn, mask=rn < N)\n scale = a_scale[:, None] * b_scale[None, :]\n acc *= scale\n if USE_BIAS:\n bias = tl.load(Bias + rn, mask=rn < N)\n acc += bias[None, :]\n acc = acc.to(C.dtype.element_ty)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if SPLIT_K == 1:\n tl.store(C, acc, mask=mask)\n else:\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "f3407da0-33a9-4a5e-bade-84ebd8b023fd", "file_name": "fwd_kernel.py", "repo_name": "ROCm/aotriton", "file_path": "test/fwd_kernel.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef attn_fwd(Q, K, V, sm_scale, M, Out, stride_qz, stride_qh, stride_qm,\n stride_qk, stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vk, stride_vn, stride_oz, stride_oh, stride_om,\n stride_on, seqlen_q, seqlen_k, dropout_p, philox_seed,\n philox_offset_base, encoded_softmax, STAGE: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr,\n pre_load_v: tl.constexpr, ENABLE_DROPOUT: tl.constexpr,\n RETURN_ENCODED_SOFTMAX: tl.constexpr):\n start_m = tl.program_id(0)\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n num_h = tl.num_programs(1)\n num_z = tl.num_programs(2)\n q_offset = off_h * stride_qh + off_z * stride_qz\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n k_offset = off_h * stride_kh + off_z * stride_kz\n K_block_ptr = tl.make_block_ptr(base=K + k_offset, shape=(BLOCK_DMODEL,\n seqlen_k), strides=(stride_kk, stride_kn), offsets=(0, 0),\n block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n v_offset = off_h * stride_vh + off_z * stride_vz\n V_block_ptr = tl.make_block_ptr(base=V + v_offset, shape=(seqlen_k,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504\n q = tl.load(Q_block_ptr)\n q = (q * qk_scale).to(Q_block_ptr.type.element_ty)\n off_zh = off_z * num_h + off_h * 1\n if ENABLE_DROPOUT:\n batch_philox_offset = philox_offset_base + off_zh * seqlen_q * seqlen_k\n else:\n batch_philox_offset = 0\n if RETURN_ENCODED_SOFTMAX:\n encoded_softmax_block_ptr = tl.make_block_ptr(base=encoded_softmax +\n off_zh * seqlen_q * seqlen_k, shape=(seqlen_q, seqlen_k),\n strides=(seqlen_k, 1), offsets=(start_m * BLOCK_M, 0),\n block_shape=(BLOCK_M, BLOCK_N), order=(1, 0))\n else:\n encoded_softmax_block_ptr = 0\n if STAGE & 1:\n acc, l_i, m_i = attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, seqlen_q, seqlen_k, dropout_p,\n philox_seed, batch_philox_offset, encoded_softmax_block_ptr,\n BLOCK_M, BLOCK_DMODEL, BLOCK_N, 4 - STAGE, offs_m, offs_n,\n pre_load_v, ENABLE_DROPOUT, RETURN_ENCODED_SOFTMAX)\n if STAGE & 2:\n tl.debug_barrier()\n acc, l_i, m_i = attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, seqlen_q, seqlen_k, dropout_p,\n philox_seed, batch_philox_offset, encoded_softmax_block_ptr,\n BLOCK_M, BLOCK_DMODEL, BLOCK_N, 2, offs_m, offs_n, pre_load_v,\n ENABLE_DROPOUT, RETURN_ENCODED_SOFTMAX)\n acc = acc / l_i[:, None]\n if ENABLE_DROPOUT:\n acc = acc / (1 - dropout_p)\n m_ptrs = M + off_zh * seqlen_q + offs_m\n tl.store(m_ptrs, m_i + tl.math.log2(l_i))\n o_offset = off_h * stride_oh + off_z * stride_oz\n O_block_ptr = tl.make_block_ptr(base=Out + o_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n tl.store(O_block_ptr, acc.to(Out.type.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/fwd_kernel.py" }, { "uuid": "23435036-debc-4e75-8236-37b373cdcf8f", "file_name": "_semi_structured_conversions.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/_semi_structured_conversions.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.autotune(configs=get_configs(), key=['m', 'k'])\n@triton.jit\ndef _sparse_semi_structured_from_dense_triton_16(dense_ptr, sparse_ptr,\n meta_reordered_ptr, mask_ptr, dense_row_stride, sparse_row_stride,\n mask_row_stride, dense_col_stride, sparse_col_stride, mask_col_stride,\n m, k, seed, BLOCK_SIZE: tl.constexpr, PRUNE: tl.constexpr, ARRAY_LAYOUT:\n tl.constexpr):\n if ARRAY_LAYOUT == 'row':\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1) * 16 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 16\n mask = col_idx < k\n elif ARRAY_LAYOUT == 'col':\n row_idx = tl.arange(0, BLOCK_SIZE) + tl.program_id(0) * BLOCK_SIZE\n col_idx = tl.program_id(1) * 16\n mask = row_idx < m\n dense_40 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 0) * dense_col_stride, mask=mask)\n dense_41 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 1) * dense_col_stride, mask=mask)\n dense_42 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 2) * dense_col_stride, mask=mask)\n dense_43 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 3) * dense_col_stride, mask=mask)\n dense_44 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 4) * dense_col_stride, mask=mask)\n dense_45 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 5) * dense_col_stride, mask=mask)\n dense_46 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 6) * dense_col_stride, mask=mask)\n dense_47 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 7) * dense_col_stride, mask=mask)\n dense_48 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 8) * dense_col_stride, mask=mask)\n dense_49 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 9) * dense_col_stride, mask=mask)\n dense_4A = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 10) * dense_col_stride, mask=mask)\n dense_4B = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 11) * dense_col_stride, mask=mask)\n dense_4C = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 12) * dense_col_stride, mask=mask)\n dense_4D = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 13) * dense_col_stride, mask=mask)\n dense_4E = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 14) * dense_col_stride, mask=mask)\n dense_4F = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 15) * dense_col_stride, mask=mask)\n if PRUNE == 'mse':\n if dense_ptr.type.element_ty == tl.bfloat16:\n (_dense_40, _dense_41, _dense_42, _dense_43, _dense_44,\n _dense_45, _dense_46, _dense_47, _dense_48, _dense_49,\n _dense_4A, _dense_4B, _dense_4C, _dense_4D, _dense_4E,\n _dense_4F) = (dense_40.to(tl.float32), dense_41.to(tl.\n float32), dense_42.to(tl.float32), dense_43.to(tl.float32),\n dense_44.to(tl.float32), dense_45.to(tl.float32), dense_46.\n to(tl.float32), dense_47.to(tl.float32), dense_48.to(tl.\n float32), dense_49.to(tl.float32), dense_4A.to(tl.float32),\n dense_4B.to(tl.float32), dense_4C.to(tl.float32), dense_4D.\n to(tl.float32), dense_4E.to(tl.float32), dense_4F.to(tl.\n float32))\n else:\n (_dense_40, _dense_41, _dense_42, _dense_43, _dense_44,\n _dense_45, _dense_46, _dense_47, _dense_48, _dense_49,\n _dense_4A, _dense_4B, _dense_4C, _dense_4D, _dense_4E,\n _dense_4F) = (dense_40, dense_41, dense_42, dense_43,\n dense_44, dense_45, dense_46, dense_47, dense_48, dense_49,\n dense_4A, dense_4B, dense_4C, dense_4D, dense_4E, dense_4F)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_40) > tl.abs(_dense_41), tl.abs(\n _dense_40) > tl.abs(_dense_42), tl.abs(_dense_40) > tl.abs(\n _dense_43), tl.abs(_dense_41) > tl.abs(_dense_42), tl.abs(_dense_41\n ) > tl.abs(_dense_43), tl.abs(_dense_42) > tl.abs(_dense_43)\n m0, m1, m2, m3 = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_44) > tl.abs(_dense_45), tl.abs(\n _dense_44) > tl.abs(_dense_46), tl.abs(_dense_44) > tl.abs(\n _dense_47), tl.abs(_dense_45) > tl.abs(_dense_46), tl.abs(_dense_45\n ) > tl.abs(_dense_47), tl.abs(_dense_46) > tl.abs(_dense_47)\n m4, m5, m6, m7 = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_48) > tl.abs(_dense_49), tl.abs(\n _dense_48) > tl.abs(_dense_4A), tl.abs(_dense_48) > tl.abs(\n _dense_4B), tl.abs(_dense_49) > tl.abs(_dense_4A), tl.abs(_dense_49\n ) > tl.abs(_dense_4B), tl.abs(_dense_4A) > tl.abs(_dense_4B)\n m8, m9, mA, mB = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_4C) > tl.abs(_dense_4D), tl.abs(\n _dense_4C) > tl.abs(_dense_4E), tl.abs(_dense_4C) > tl.abs(\n _dense_4F), tl.abs(_dense_4D) > tl.abs(_dense_4E), tl.abs(_dense_4D\n ) > tl.abs(_dense_4F), tl.abs(_dense_4E) > tl.abs(_dense_4F)\n mC, mD, mE, mF = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n elif PRUNE == 'mask':\n m0 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 0) *\n mask_col_stride, mask=mask).to(tl.int1)\n m1 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 1) *\n mask_col_stride, mask=mask).to(tl.int1)\n m2 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 2) *\n mask_col_stride, mask=mask).to(tl.int1)\n m3 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 3) *\n mask_col_stride, mask=mask).to(tl.int1)\n m4 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 4) *\n mask_col_stride, mask=mask).to(tl.int1)\n m5 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 5) *\n mask_col_stride, mask=mask).to(tl.int1)\n m6 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 6) *\n mask_col_stride, mask=mask).to(tl.int1)\n m7 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 7) *\n mask_col_stride, mask=mask).to(tl.int1)\n m8 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 8) *\n mask_col_stride, mask=mask).to(tl.int1)\n m9 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 9) *\n mask_col_stride, mask=mask).to(tl.int1)\n mA = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 10) *\n mask_col_stride, mask=mask).to(tl.int1)\n mB = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 11) *\n mask_col_stride, mask=mask).to(tl.int1)\n mC = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 12) *\n mask_col_stride, mask=mask).to(tl.int1)\n mD = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 13) *\n mask_col_stride, mask=mask).to(tl.int1)\n mE = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 14) *\n mask_col_stride, mask=mask).to(tl.int1)\n mF = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 15) *\n mask_col_stride, mask=mask).to(tl.int1)\n elif PRUNE == 'mvue':\n if ARRAY_LAYOUT == 'row':\n seed0 = seed + (tl.program_id(0) + tl.program_id(1) * m) * 2\n seed1 = seed + (tl.program_id(0) + tl.program_id(1) * m) * 2 + 1\n else:\n seed0 = seed + (tl.program_id(0) * k // 16 + tl.program_id(1)) * 2\n seed1 = seed + (tl.program_id(0) * k // 16 + tl.program_id(1)\n ) * 2 + 1\n random0, random1, random2, random3 = tl.rand4x(seed0, tl.arange(0,\n BLOCK_SIZE), n_rounds=5)\n random4, random5, random6, random7 = tl.rand4x(seed1, tl.arange(0,\n BLOCK_SIZE), n_rounds=5)\n dense_40, dense_41, dense_42, dense_43, m0, m1, m2, m3 = (\n _MVUE24_approx(dense_40, dense_41, dense_42, dense_43, random0,\n random1))\n dense_44, dense_45, dense_46, dense_47, m4, m5, m6, m7 = (\n _MVUE24_approx(dense_44, dense_45, dense_46, dense_47, random2,\n random3))\n dense_48, dense_49, dense_4A, dense_4B, m8, m9, mA, mB = (\n _MVUE24_approx(dense_48, dense_49, dense_4A, dense_4B, random4,\n random5))\n dense_4C, dense_4D, dense_4E, dense_4F, mC, mD, mE, mF = (\n _MVUE24_approx(dense_4C, dense_4D, dense_4E, dense_4F, random6,\n random7))\n else:\n m0 = dense_40 != 0\n m1 = dense_41 != 0\n m2 = dense_42 != 0\n m3 = dense_43 != 0\n m4 = dense_44 != 0\n m5 = dense_45 != 0\n m6 = dense_46 != 0\n m7 = dense_47 != 0\n m8 = dense_48 != 0\n m9 = dense_49 != 0\n mA = dense_4A != 0\n mB = dense_4B != 0\n mC = dense_4C != 0\n mD = dense_4D != 0\n mE = dense_4E != 0\n mF = dense_4F != 0\n bit0 = ~m0 & m1\n bit1 = ~m0 & ~m1\n bit2 = bit1 | ~m2\n bit3 = bit0 | ~m1 | m2\n idxs0 = bit0 | bit1.to(tl.int64) << 1\n idxs1 = bit2 | bit3.to(tl.int64) << 1\n sparse0 = tl.where(bit1, tl.where(bit0, dense_43, dense_42), tl.where(\n bit0, dense_41, dense_40))\n sparse1 = tl.where(bit3, tl.where(bit2, dense_43, dense_42), tl.where(\n bit2, dense_41, dense_40))\n bit4 = ~m4 & m5\n bit5 = ~m4 & ~m5\n bit6 = bit5 | ~m6\n bit7 = bit4 | ~m5 | m6\n idxs2 = bit4 | bit5.to(tl.int64) << 1\n idxs3 = bit6 | bit7.to(tl.int64) << 1\n sparse2 = tl.where(bit5, tl.where(bit4, dense_47, dense_46), tl.where(\n bit4, dense_45, dense_44))\n sparse3 = tl.where(bit7, tl.where(bit6, dense_47, dense_46), tl.where(\n bit6, dense_45, dense_44))\n bit8 = ~m8 & m9\n bit9 = ~m8 & ~m9\n bitA = bit9 | ~mA\n bitB = bit8 | ~m9 | mA\n idxs4 = bit8 | bit9.to(tl.int64) << 1\n idxs5 = bitA | bitB.to(tl.int64) << 1\n sparse4 = tl.where(bit9, tl.where(bit8, dense_4B, dense_4A), tl.where(\n bit8, dense_49, dense_48))\n sparse5 = tl.where(bitB, tl.where(bitA, dense_4B, dense_4A), tl.where(\n bitA, dense_49, dense_48))\n bitC = ~mC & mD\n bitD = ~mC & ~mD\n bitE = bitD | ~mE\n bitF = bitC | ~mD | mE\n idxs6 = bitC | bitD.to(tl.int64) << 1\n idxs7 = bitE | bitF.to(tl.int64) << 1\n sparse6 = tl.where(bitD, tl.where(bitC, dense_4F, dense_4E), tl.where(\n bitC, dense_4D, dense_4C))\n sparse7 = tl.where(bitF, tl.where(bitE, dense_4F, dense_4E), tl.where(\n bitE, dense_4D, dense_4C))\n col_idx = tl.program_id(1) * 8\n if ARRAY_LAYOUT == 'row':\n col_idx = tl.program_id(1) * 8 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 8\n mask = col_idx < k // 2\n else:\n col_idx = tl.program_id(1) * 8\n mask = row_idx < m\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 0) *\n sparse_col_stride, sparse0, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 1) *\n sparse_col_stride, sparse1, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 2) *\n sparse_col_stride, sparse2, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 3) *\n sparse_col_stride, sparse3, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 4) *\n sparse_col_stride, sparse4, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 5) *\n sparse_col_stride, sparse5, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 6) *\n sparse_col_stride, sparse6, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 7) *\n sparse_col_stride, sparse7, mask=mask)\n meta_40 = idxs0 | idxs1 << 2\n meta_41 = idxs2 | idxs3 << 2\n meta_42 = idxs4 | idxs5 << 2\n meta_43 = idxs6 | idxs7 << 2\n meta = meta_40 | meta_41 << 4 | meta_42 << 8 | meta_43 << 12\n if ARRAY_LAYOUT == 'row':\n col_idx = tl.program_id(1) * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n elif ARRAY_LAYOUT == 'col':\n col_idx = tl.program_id(1)\n group, interweave = 32, 4\n dest_row = row_idx // 32 * 32 + row_idx % 8 * 4 + row_idx % group // 8\n dest_col = col_idx\n topright = ((dest_row % 2 == 0) & (dest_col % 2 == 1)).to(tl.int8)\n bottomleft = ((dest_row % 2 == 1) & (dest_col % 2 == 0)).to(tl.int8)\n dest_row = dest_row + topright - bottomleft\n dest_col = dest_col - topright + bottomleft\n interleave = 2\n cols_maj = dest_col // interleave\n cols_min = dest_col % interleave\n meta_reordered_offsets = (cols_maj * m * interleave + dest_row *\n interleave + cols_min)\n if ARRAY_LAYOUT == 'row':\n mask = col_idx < k // 16\n elif ARRAY_LAYOUT == 'col':\n mask = row_idx < m\n tl.store(meta_reordered_ptr + meta_reordered_offsets, meta, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/_semi_structured_conversions.py" }, { "uuid": "5539577c-6764-48b6-859f-2234d6a9e634", "file_name": "normalization.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/normalization.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_normalization_forward_kernel(input_ptr, output_ptr, weight_ptr,\n bias_ptr, inv_var_ptr, n_cols, eps, has_bias: tl.constexpr,\n zero_centered: tl.constexpr, block_size: tl.constexpr):\n row = tl.program_id(0).to(tl.int64)\n cols = tl.arange(0, block_size)\n mask = cols < n_cols\n offsets = row * n_cols + cols\n input_ = tl.load(input_ptr + offsets, mask=mask, other=0.0).to(tl.float32)\n if has_bias:\n mean = tl.sum(input_, axis=0) / n_cols\n input_ = tl.where(mask, input_ - mean, 0.0)\n inv_var = 1 / tl.sqrt(tl.sum(input_ * input_, axis=0) / n_cols + eps)\n tl.store(inv_var_ptr + row, inv_var)\n weight = tl.load(weight_ptr + cols, mask=mask)\n if zero_centered:\n weight += 1\n output = input_ * inv_var * weight\n if has_bias:\n bias = tl.load(bias_ptr + cols, mask=mask)\n output = output + bias\n tl.store(output_ptr + offsets, output, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/normalization.py" }, { "uuid": "69b84f1a-f834-4d8d-8fa9-a4d114df2847", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef sign(x):\n return (x > 0).to(tl.float32) - (x < 0).to(tl.float32)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "fa8e1c2a-4c55-4f07-97c6-e7f805a3a487", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _jagged_dense_flash_attention_bwd_dv_db_dq_kernel(q_ptr, k_ptr, v_ptr,\n ab_ptr, jagged_offsets_ptr, out_ptr, do_ptr, lse_ptr, delta_ptr, dq_ptr,\n dk_ptr, dv_ptr, dbias_ptr, max_seq_len, stride_ql, stride_qd, stride_kb,\n stride_kd, stride_kt, stride_vl, stride_vd, stride_ab_b, stride_ab_l,\n stride_ab_t, stride_ob, stride_ot, stride_od, stride_dq_l, stride_dq_d,\n stride_dv_l, stride_dv_d, stride_db_b, stride_db_l, stride_db_t,\n stride_do_b, stride_do_t, stride_do_d, T: tl.constexpr, BLOCK_T: tl.\n constexpr, BLOCK_L: tl.constexpr, BLOCK_D: tl.constexpr, allow_tf32: tl\n .constexpr):\n pid_l = tl.program_id(0)\n pid_b = tl.program_id(1)\n begin = tl.load(jagged_offsets_ptr + pid_b)\n end = tl.load(jagged_offsets_ptr + pid_b + 1)\n seqlen = end - begin\n seqlen = tl.minimum(seqlen, max_seq_len)\n if seqlen == 0:\n return\n q_start_ptr = q_ptr + begin * stride_ql\n k_start_ptr = k_ptr + pid_b * stride_kb\n ab_start_ptr = ab_ptr + pid_b * stride_ab_b\n v_start_ptr = v_ptr + begin * stride_vl\n do_start_ptr = do_ptr + pid_b * stride_do_b\n dq_start_ptr = dq_ptr + begin * stride_dq_l\n dv_start_ptr = dv_ptr + begin * stride_dv_l\n dbias_start_ptr = dbias_ptr + pid_b * stride_db_b\n delta_ptrs = delta_ptr + pid_b * T\n lse_ptrs = lse_ptr + pid_b * T\n start_l = pid_l * BLOCK_L\n offs_l_curr = start_l + tl.arange(0, BLOCK_L)\n offs_d = tl.arange(0, BLOCK_D)\n offs_t = tl.arange(0, BLOCK_T)\n q_ptrs = q_start_ptr + offs_l_curr[:, None] * stride_ql + offs_d[None, :\n ] * stride_qd\n k_ptrs = k_start_ptr + offs_d[:, None] * stride_kd + offs_t[None, :\n ] * stride_kt\n v_ptrs = v_start_ptr + offs_l_curr[:, None] * stride_vl + offs_d[None, :\n ] * stride_vd\n do_ptrs = do_start_ptr + offs_t[:, None] * stride_do_t + offs_d[None, :\n ] * stride_do_d\n dq = tl.zeros([BLOCK_L, BLOCK_D], dtype=tl.float32)\n dv = tl.zeros([BLOCK_L, BLOCK_D], dtype=tl.float32)\n q = tl.load(q_ptrs, mask=(offs_l_curr[:, None] < seqlen) & (offs_d[None,\n :] < BLOCK_D), other=0.0)\n v = tl.load(v_ptrs, mask=offs_l_curr[:, None] < seqlen, other=0.0)\n start_t = 0\n while start_t < T:\n offs_t_curr = start_t + tl.arange(0, BLOCK_T)\n k = tl.load(k_ptrs, mask=(offs_t_curr[None, :] < T) & (offs_d[:,\n None] < BLOCK_D), other=0.0)\n qk = tl.zeros([BLOCK_L, BLOCK_T], dtype=tl.float32)\n qk += tl.dot(q, k, allow_tf32=allow_tf32)\n ab_ptrs = ab_start_ptr + offs_l_curr[:, None\n ] * stride_ab_l + offs_t_curr[None, :] * stride_ab_t\n ab = tl.load(ab_ptrs, mask=(offs_l_curr[:, None] < seqlen) & (\n offs_t_curr[None, :] < T), other=0.0)\n qk = qk + ab\n qk_mask = (offs_l_curr[:, None] < seqlen) & (offs_t_curr[None, :] < T)\n qk = tl.where(qk_mask, qk, float('-inf'))\n lse_t = tl.load(lse_ptrs + offs_t_curr, mask=offs_t_curr < T, other\n =float('inf'))\n p = tl.exp(qk - lse_t[None, :])\n p = tl.where(qk_mask, p, 0.0)\n do = tl.load(do_ptrs, mask=offs_t_curr[:, None] < T, other=0.0)\n dv += tl.dot(p, do, allow_tf32=allow_tf32)\n delta = tl.load(delta_ptrs + offs_t_curr, mask=offs_t_curr < T)\n dp = tl.zeros([BLOCK_L, BLOCK_T], dtype=tl.float32)\n dp += tl.trans(tl.dot(do, tl.trans(v), allow_tf32=allow_tf32))\n ds = p * (dp - delta[None, :])\n dbias_ptrs = dbias_start_ptr + offs_l_curr[:, None\n ] * stride_db_l + offs_t_curr[None, :] * stride_db_t\n tl.store(dbias_ptrs, ds, mask=(offs_l_curr[:, None] < seqlen) & (\n offs_t_curr[None, :] < T))\n dq += tl.dot(ds, tl.trans(k), allow_tf32=allow_tf32)\n k_ptrs += BLOCK_T * stride_kt\n do_ptrs += BLOCK_T * stride_do_t\n start_t += BLOCK_T\n dq_ptrs = dq_start_ptr + offs_l_curr[:, None] * stride_dq_l + offs_d[\n None, :] * stride_dq_d\n dv_ptrs = dv_start_ptr + offs_l_curr[:, None] * stride_dv_l + offs_d[\n None, :] * stride_dv_d\n tl.store(dq_ptrs, dq, mask=offs_l_curr[:, None] < seqlen)\n tl.store(dv_ptrs, dv, mask=offs_l_curr[:, None] < seqlen)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "ade66aeb-e4c3-493d-8ecf-bf05180889aa", "file_name": "dropout.py", "repo_name": "daemyung/practice-triton", "file_path": "dropout.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@staticmethod\n@triton.jit\ndef forward(output_ptr, input_ptr, size, p, seed, block_size: tl.constexpr):\n pid = tl.program_id(0)\n offset = pid * block_size\n input_block_ptr = tl.make_block_ptr(input_ptr, shape=(size,), strides=(\n 1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n output_block_ptr = tl.make_block_ptr(output_ptr, shape=(size,), strides\n =(1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n offsets = tl.arange(0, block_size) + offset\n random_values = tl.rand(seed, offsets)\n condition = random_values > p\n input = tl.load(input_block_ptr, boundary_check=(0,))\n output = tl.where(condition, input * (1 / (1 - p)), 0.0)\n tl.store(output_block_ptr, output, boundary_check=(0,))\n", "category": { "Functionality": [ "Elementwise Operations", "Activation Functions" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/dropout.py" }, { "uuid": "b04ed8dc-c834-4c02-bbc5-5fe077ac9864", "file_name": "gemm_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=s, num_warps=32) for s in [2, 3]] + [triton.Config\n ({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=s, num_warps=32) for\n s in [2]] + [triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 1024,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages\n =s, num_warps=32) for s in [2, 3]] + [triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=s, num_warps=32) for s in [2]] + [triton.Config({\n 'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512, 'BLOCK_SIZE_K': 64,\n 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages=s, num_warps=32) for\n s in [2]] + [triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =s, num_warps=4) for s in [2]], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers_batched(a_ptr, b_ptr, c_ptr, B: tl.\n constexpr, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr, stride_az:\n tl.constexpr, stride_am: tl.constexpr, stride_ak: tl.constexpr,\n stride_bz: tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.\n constexpr, stride_cz: tl.constexpr, stride_cm: tl.constexpr, stride_cn:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n bid = tl.program_id(axis=1)\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offset_a = bid.to(tl.int64) * stride_az\n offset_b = bid.to(tl.int64) * stride_bz\n a_block_ptr = tl.make_block_ptr(base=a_ptr + offset_a, shape=(M, K),\n strides=(stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr + offset_b, shape=(K, N),\n strides=(stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c = accumulator.to(tl.float32)\n offset_c = bid.to(tl.int64) * stride_cz\n c_block_ptr = tl.make_block_ptr(base=c_ptr + offset_c, shape=(M, N),\n strides=(stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, \n pid_n * BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N),\n order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_benchmark.py" }, { "uuid": "76abb677-7e00-4012-bc67-1b2087e786e1", "file_name": "ops.py", "repo_name": "srush/triton-autodiff", "file_path": "triton_autodiff/ops.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef triton_unbroadcast(array, other):\n l: tl.constexpr = tl.constexpr(shape_l(array.shape))\n ol: tl.constexpr = tl.constexpr(shape_l(other.value))\n for i in tl.static_range(0, l):\n if i >= ol:\n array = tl.sum(array, l - (1 + i))\n array = tl.expand_dims(array, l - (1 + i))\n elif array.shape[l - (1 + i)] > other.value[ol - (1 + i)]:\n array = tl.sum(array, l - (1 + i))\n array = tl.expand_dims(array, l - (1 + i))\n tl.static_assert(tl.constexpr(shape_l(array.shape)) == l)\n return tl.view(array, other.value)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/triton_autodiff/ops.py" }, { "uuid": "8294d9f6-80bb-4440-80cc-6db0df32303a", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK}, num_warps=num_warps,\n num_stages=num_stages) for BK in [32, 64] for num_warps in [1, 2, 4, 8] for\n num_stages in [2, 3, 4]], key=['BC'])\n@triton.jit\ndef chunk_gla_fwd_A_kernel_intra_sub_inter(q, k, g, A, offsets, indices,\n scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.\n constexpr, BC: tl.constexpr, BK: tl.constexpr, NC: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_i, i_j = i_c // NC, i_c % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if i_t * BT + i_i * BC >= T:\n return\n if i_i <= i_j:\n return\n b_A = tl.zeros([BC, BC], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gk = tl.make_block_ptr(g + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (i_bh * T + i_t *\n BT + i_i * BC) * K + o_k, BK), BK)\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gk = tl.make_block_ptr(g + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + \n i_i * BC) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_qg = b_q * tl.exp(b_g - b_gn[None, :]) * scale\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_kg = b_k * tl.exp(b_gn[:, None] - b_gk)\n b_A += tl.dot(b_qg, b_kg)\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n tl.store(p_A, b_A.to(A.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "fe206ade-10f1-48be-9faf-065054bbea19", "file_name": "softmax_split.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_split.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel(out_ptr, in_ptr, logz_ptr, M, N, TILE_N: tl.constexpr):\n pid_n = tl.program_id(0)\n pid_m = tl.program_id(1)\n n_offsets = pid_n * TILE_N + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n mask = n_offsets < N\n inp = tl.load(in_ptr + offset, mask=mask, other=-float('inf')).to(out_ptr\n .dtype.element_ty)\n logz = tl.load(logz_ptr + pid_m).to(out_ptr.dtype.element_ty)\n out = tl.exp(inp - logz)\n tl.store(out_ptr + offset, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_split.py" }, { "uuid": "a47ca1c7-56ce-48bc-b2f1-eb0c70e769d9", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_mean/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES_RAGGED, BLOCK_SIZES_M, NUM_WARPS,\n NUM_STAGES)], key=['M'])\n@triton.jit\ndef triton_jagged_mean_kernel_simple_fused_buffer_then_sum(input_ptr_values,\n input_ptr_offsets, output_ptr, M, MAX_SEQLEN, BLOCK_SIZE_RAGGED: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_b = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_b), tl.load(\n input_ptr_offsets + (pid_b + 1))\n ragged_len = ragged_end - ragged_start\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n buffer += tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer_sum = tl.sum(buffer, axis=0)\n buffer_view = buffer_sum.reshape((BLOCK_SIZE_M,))\n buffer_view_mean = buffer_view * (1 / ragged_len)\n output_offsets = offsets_m + pid_b * M\n output_mask = output_offsets < M * (pid_b + 1)\n tl.store(output_ptr + output_offsets, buffer_view_mean, mask=output_mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_mean/kernels.py" }, { "uuid": "a1761742-5783-4551-93c3-9a127846b9fc", "file_name": "01-vector-add.py", "repo_name": "kiwik/os-version-checker", "file_path": "ai/Triton/scripts/01-vector-add.py", "commit_hash": "65ebf607e0b4bb26c64a025d13e087200517b78c", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'TILE_SIZE': 16, 'BLOCK_SIZE': \n 4096}, num_threads=1), triton.Config({'TILE_SIZE': 16, 'BLOCK_SIZE': \n 4096}, num_threads=0), triton.Config({'TILE_SIZE': 16, 'BLOCK_SIZE': \n 8192}, num_threads=0), triton.Config({'TILE_SIZE': 16, 'BLOCK_SIZE': \n 16384}, num_threads=0), triton.Config({'TILE_SIZE': 16, 'BLOCK_SIZE': \n 32768}, num_threads=0), triton.Config({'TILE_SIZE': 16, 'BLOCK_SIZE': \n 65536}, num_threads=0)], key=['n_elements'])\n@triton.jit\ndef add_kernel_tiled_autotuned(x_ptr, y_ptr, output_ptr, n_elements,\n BLOCK_SIZE: tl.constexpr, TILE_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n for i in range(0, tl.cdiv(BLOCK_SIZE, TILE_SIZE)):\n offsets = block_start + i * TILE_SIZE + tl.arange(0, TILE_SIZE)\n mask = offsets < n_elements\n x = tl.load(x_ptr + offsets, mask=mask)\n y = tl.load(y_ptr + offsets, mask=mask)\n output = x + y\n tl.store(output_ptr + offsets, output, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kiwik/os-version-checker/blob/65ebf607e0b4bb26c64a025d13e087200517b78c/ai/Triton/scripts/01-vector-add.py" }, { "uuid": "bbab54f5-e0f5-45d1-a33b-6925fcd3c225", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'] is not\n None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BK', 'BV', 'USE_GK', 'USE_GV', 'USE_G'])\n@triton.jit\ndef fused_recurrent_bwd_kernel(q, k, v, g, gk, gv, h0, do, dq, dk, dv, dht,\n dh0, offsets, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n REVERSE: tl.constexpr, USE_G: tl.constexpr, USE_GK: tl.constexpr,\n USE_GV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n STORE_INITIAL_STATE_GRADIENT: tl.constexpr, USE_FINAL_STATE_GRADIENT:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.\n int64), tl.program_id(2).to(tl.int64)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n if HEAD_FIRST:\n p_k = k + i_nh * T * K + ((T - 1) * K if REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_do = do + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if REVERSE else\n 0) + i_k * BK + tl.arange(0, BK)\n if USE_G:\n p_g = g + i_nh * T + (T - 1 if REVERSE else 0)\n if USE_GK:\n p_gk = gk + i_nh * T * K + ((T - 1) * K if REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n if USE_GV:\n p_gv = gv + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n else:\n p_k = k + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_do = do + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_v * all + bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n if USE_G:\n p_g = g + (bos + (T - 1 if REVERSE else 0)) * H + i_h\n if USE_GK:\n p_gk = gk + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n if USE_GV:\n p_gv = gv + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n mask_h = mask_k[:, None] & mask_v[None, :]\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n if USE_G:\n b_g = tl.load(p_g).to(tl.float32)\n b_h = b_h * tl.exp(b_g)\n if USE_GK:\n b_gk = tl.load(p_gk, mask=mask_k, other=0).to(tl.float32)\n b_h = b_h * tl.exp(b_gk[:, None])\n if USE_GV:\n b_gv = tl.load(p_gv, mask=mask_v, other=0).to(tl.float32)\n b_h = b_h * tl.exp(b_gv[None, :])\n b_h += b_k[:, None] * b_v[None, :]\n b_dq = b_h * b_do[None, :]\n b_dq = tl.sum(b_dq, axis=1) * scale\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), mask=mask_k)\n p_k += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_do += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_dq += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n if USE_G:\n p_g += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H)\n if USE_GK:\n p_gk += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n if USE_GV:\n p_gv += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n tl.debug_barrier()\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + ((T - 1) * K if not REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + ((T - 1) * K if not REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + ((T - 1) * V if not REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_do = do + i_nh * T * V + ((T - 1) * V if not REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_dk = dk + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if not\n REVERSE else 0) + i_k * BK + tl.arange(0, BK)\n p_dv = dv + (i_k * B * H + i_nh) * T * V + ((T - 1) * V if not\n REVERSE else 0) + i_v * BV + tl.arange(0, BV)\n if USE_G:\n p_g = g + i_nh * T + (T - 1 if not REVERSE else 0)\n if USE_GK:\n p_gk = gk + i_nh * T * K + ((T - 1) * K if not REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n if USE_GV:\n p_gv = gv + i_nh * T * V + ((T - 1) * V if not REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_do = do + (bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_dk = dk + (i_v * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_dv = dv + (i_k * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n if USE_G:\n p_g = g + (bos + (T - 1 if not REVERSE else 0)) * H + i_h\n if USE_GK:\n p_gk = gk + (bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n if USE_GV:\n p_gv = gv + (bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = dht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_dh += tl.load(p_dht, mask=mask_h, other=0).to(tl.float32)\n for _ in range(T):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n b_dh += b_q[:, None] * b_do[None, :]\n b_dk = tl.sum(b_dh * b_v[None, :], axis=1)\n b_dv = tl.sum(b_dh * b_k[:, None], axis=0)\n if USE_G:\n b_g = tl.load(p_g).to(tl.float32)\n b_dh *= tl.exp(b_g)\n if USE_GK:\n b_gk = tl.load(p_gk, mask=mask_k, other=0).to(tl.float32)\n b_dh *= tl.exp(b_gk)[:, None]\n if USE_GV:\n b_gv = tl.load(p_gv, mask=mask_v, other=0).to(tl.float32)\n b_dh *= tl.exp(b_gv)[None, :]\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), mask=mask_k)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), mask=mask_v)\n p_q += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n p_k += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n p_v += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n p_do += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n p_dk += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n p_dv += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n if USE_G:\n p_g += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H)\n if USE_GK:\n p_gk += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * K\n if USE_GV:\n p_gv += (1 if REVERSE else -1) * (1 if HEAD_FIRST else H) * V\n if STORE_INITIAL_STATE_GRADIENT:\n p_dh0 = dh0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/fused_recurrent.py" }, { "uuid": "a8445512-cbd6-47e9-9aaf-77d03f212f4e", "file_name": "complex_rnn.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/complex_rnn.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef fwd_sequential_scan_complex(v_real, v_imag, decay_real, decay_imag,\n hidden_real, hidden_imag, B, L, C, BLOCK_M: tl.constexpr):\n offset_b = tl.program_id(0)\n if offset_b >= B:\n return\n offset_n = tl.program_id(1)\n ptr = tl.arange(0, BLOCK_M) + offset_b * L * C + offset_n * BLOCK_M\n h_real = tl.zeros([BLOCK_M], dtype=tl.float32)\n h_imag = tl.zeros([BLOCK_M], dtype=tl.float32)\n for _ in range(L):\n x_real = tl.load(v_real + ptr).to(tl.float32)\n x_imag = tl.load(v_imag + ptr).to(tl.float32)\n f_real = tl.load(decay_real + ptr).to(tl.float32)\n f_imag = tl.load(decay_imag + ptr).to(tl.float32)\n h_real_new = h_real * f_real - h_imag * f_imag + x_real\n h_imag_new = h_real * f_imag + h_imag * f_real + x_imag\n tl.store(hidden_real + ptr, h_real_new.to(hidden_real.dtype.element_ty)\n )\n tl.store(hidden_imag + ptr, h_imag_new.to(hidden_imag.dtype.element_ty)\n )\n h_real = h_real_new\n h_imag = h_imag_new\n ptr += C\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/complex_rnn.py" }, { "uuid": "7518b7e9-9f9a-4687-8c6c-2c18f6325875", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_delta_rule_fwd_kernel_h(k, v, d, v_new, h, h0, ht, offsets,\n chunk_offsets, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl\n .constexpr, BT: tl.constexpr, BC: tl.constexpr, BK: tl.constexpr, BV:\n tl.constexpr, NT: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT):\n if HEAD_FIRST:\n p_h = tl.make_block_ptr(h + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_h = tl.make_block_ptr(h + ((boh + i_t) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_hc = tl.zeros([BK, BV], dtype=tl.float32)\n for i_c in range(tl.cdiv(min(BT, T - i_t * BT), BC)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_nh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_d = tl.make_block_ptr(d + i_nh * T * K, (T, K), (K, 1), (\n i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_nh * T * V, (T, V), (V, 1), (\n i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_v_new = tl.make_block_ptr(v_new + i_nh * T * V, (T, V), (\n V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1,\n H * K), (i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_d = tl.make_block_ptr(d + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_v_new = tl.make_block_ptr(v_new + (bos * H + i_h) * V, (T,\n V), (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC,\n BV), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_d = tl.load(p_d, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_v -= tl.dot(b_d, b_h.to(b_k.dtype))\n tl.store(p_v_new, b_v.to(p_v_new.dtype.element_ty),\n boundary_check=(0, 1))\n b_hc += tl.dot(b_k, b_v.to(b_k.dtype), allow_tf32=False)\n b_h += b_hc\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/chunk.py" }, { "uuid": "09a0bee9-c6e5-453a-99e4-ba49fd05641a", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'USE_INITIAL_STATE': lambda args: args['dh0'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_gated_delta_rule_bwd_kernel_dhu(q, k, d, g, dht, dh0, do, dh, dv,\n dv2, offsets, c_offsets, scale, T: tl.constexpr, H: tl.constexpr, K: tl\n .constexpr, V: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BK: tl\n .constexpr, BV: tl.constexpr, USE_FINAL_STATE_GRADIENT: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(c_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1))\n for i_t in range(NT - 1, -1, -1):\n if HEAD_FIRST:\n p_dh = tl.make_block_ptr(dh + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_dh = tl.make_block_ptr(dh + ((boh + i_t) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n b_dh_tmp = tl.zeros([BK, BV], dtype=tl.float32)\n last_idx = min((i_t + 1) * BT, T) - 1\n if HEAD_FIRST:\n bg_last = tl.load(g + i_nh * T + last_idx)\n else:\n bg_last = tl.load(g + (bos + last_idx) * H + i_h)\n for i_c in range(tl.cdiv(BT, BC) - 1, -1, -1):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_k = tl.make_block_ptr(k + i_nh * T * K, (T, K), (K, 1), (\n i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_d = tl.make_block_ptr(d + i_nh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_dv = tl.make_block_ptr(dv + i_nh * T * V, (T, V), (V, 1),\n (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_nh * T * V, (T, V), (V, 1),\n (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_g = tl.make_block_ptr(g + i_nh * T, (T,), (1,), (i_t * BT +\n i_c * BC,), (BC,), (0,))\n p_dv2 = tl.make_block_ptr(dv2 + i_nh * T * V, (T, V), (V, 1\n ), (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1,\n H * K), (i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_d = tl.make_block_ptr(d + (bos * H + i_h) * K, (K, T), (1,\n H * K), (i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV),\n (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV),\n (1, 0))\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t *\n BT + i_c * BC,), (BC,), (0,))\n p_dv2 = tl.make_block_ptr(dv2 + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV),\n (1, 0))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale * tl.exp(b_g)[None, :]).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_d = tl.load(p_d, boundary_check=(0, 1))\n b_k = (b_k * tl.exp(bg_last - b_g)[:, None]).to(b_k.dtype)\n b_d = (b_d * tl.exp(b_g)[None, :]).to(b_d.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dv = tl.load(p_dv, boundary_check=(0, 1))\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False)\n tl.store(p_dv2, b_dv.to(p_dv.dtype.element_ty), boundary_check=\n (0, 1))\n b_dh_tmp += tl.dot(b_q, b_do.to(b_q.dtype), allow_tf32=False)\n b_dh_tmp -= tl.dot(b_d, b_dv.to(b_q.dtype), allow_tf32=False)\n b_dh *= tl.exp(bg_last)\n b_dh += b_dh_tmp\n if USE_INITIAL_STATE:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/chunk.py" }, { "uuid": "2b6f63b8-ff56-4ab9-8423-39194f903638", "file_name": "dynamic_quant.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/dynamic_quant.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.autotune(configs=_get_autotune_configs(), key=['M', 'N'])\n@triton.jit\ndef _triton_dynamic_quantize_kernel(output_ptr, input_ptr, scale_ptr,\n stride_outputm, stride_outputn, stride_inputm, stride_inputn,\n n_elements, M: tl.constexpr, N: tl.constexpr):\n pid = tl.program_id(axis=0)\n offsets = tl.arange(0, N)\n mask = offsets < n_elements\n input_ptrs = input_ptr + pid * stride_inputm + offsets\n input_vals = tl.load(input_ptrs, mask=mask, other=1e-06)\n abs_max_f = tl.reduce(input_vals, 0, _abs_max)\n dynamic_per_token_scale = 127.0 / abs_max_f\n precison_mask = tl.where(input_vals > 0, 0.5, -0.5)\n output_vals = (input_vals * dynamic_per_token_scale + precison_mask).to(tl\n .int8)\n output_ptrs = output_ptr + pid * stride_outputm + offsets\n tl.store(output_ptrs, output_vals, mask=mask)\n tl.store(scale_ptr + pid, abs_max_f / 127.0)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/dynamic_quant.py" }, { "uuid": "cfb5d0c5-f872-468f-8407-d69c5eed5e51", "file_name": "05-layer-norm.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/05-layer-norm.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_fwd_fused(X, Y, W, B, Mean, Rstd, stride, N, eps,\n BLOCK_SIZE: tl.constexpr):\n row = tl.program_id(0)\n Y += row * stride\n X += row * stride\n mean = 0\n _mean = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n a = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n _mean += a\n mean = tl.sum(_mean, axis=0) / N\n _var = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n x = tl.where(cols < N, x - mean, 0.0)\n _var += x * x\n var = tl.sum(_var, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n tl.store(Mean + row, mean)\n tl.store(Rstd + row, rstd)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n w = tl.load(W + cols, mask=mask)\n b = tl.load(B + cols, mask=mask)\n x = tl.load(X + cols, mask=mask, other=0.0).to(tl.float32)\n x_hat = (x - mean) * rstd\n y = x_hat * w + b\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/05-layer-norm.py" }, { "uuid": "790d51bc-f5f5-494f-b80a-9596d37fd44f", "file_name": "lao.py", "repo_name": "MayDomine/Burst-Attention", "file_path": "burst_attn/lao.py", "commit_hash": "b088c554072935074ea9c643de5ee363be5ab1f6", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0, 'EVEN_HEADDIM': lambda args: args['headdim'] == args[\n 'BLOCK_HEADDIM']})\n@triton.jit\ndef _fwd_kernel(Q, K, V, Bias, Out, M_in, Lse_in, O_in, Lse, M_out, TMP,\n softmax_scale, stride_qb, stride_qh, stride_qm, stride_kb, stride_kh,\n stride_kn, stride_vb, stride_vh, stride_vn, stride_bb, stride_bh,\n stride_bm, stride_ob, stride_oh, stride_om, nheads, seqlen_q, seqlen_k,\n seqlen_q_rounded, headdim, CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K,\n BIAS_TYPE: tl.constexpr, IS_CAUSAL: tl.constexpr, BLOCK_HEADDIM: tl.\n constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr, EVEN_HEADDIM: tl\n .constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n q_ptrs = Q + off_b * stride_qb + off_h * stride_qh + (offs_m[:, None] *\n stride_qm + offs_d[None, :])\n k_ptrs = K + off_b * stride_kb + off_h * stride_kh + (offs_n[:, None] *\n stride_kn + offs_d[None, :])\n v_ptrs = V + off_b * stride_vb + off_h * stride_vh + (offs_n[:, None] *\n stride_vn + offs_d[None, :])\n if BIAS_TYPE == 'vector':\n b_ptrs = Bias + off_b * stride_bb + off_h * stride_bh + offs_n\n elif BIAS_TYPE == 'matrix':\n b_ptrs = Bias + off_b * stride_bb + off_h * stride_bh + (offs_m[:,\n None] * stride_bm + offs_n[None, :])\n t_ptrs = TMP + off_hb * seqlen_q_rounded + offs_m\n lin_ptrs = Lse_in + off_hb * seqlen_q_rounded + offs_m\n acc_o_ptrs = O_in + off_b * stride_qb + off_h * stride_qh + (offs_m[:,\n None] * stride_qm + offs_d[None, :])\n lse_i = tl.load(lin_ptrs)\n m_ptrs = M_in + off_hb * seqlen_q_rounded + offs_m\n m_i = tl.load(m_ptrs)\n acc_o = tl.load(acc_o_ptrs)\n if EVEN_M & EVEN_N:\n if EVEN_HEADDIM:\n q = tl.load(q_ptrs)\n else:\n q = tl.load(q_ptrs, mask=offs_d[None, :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n q = tl.load(q_ptrs, mask=offs_m[:, None] < seqlen_q, other=0.0)\n else:\n q = tl.load(q_ptrs, mask=(offs_m[:, None] < seqlen_q) & (offs_d[\n None, :] < headdim), other=0.0)\n end_n = seqlen_k if not IS_CAUSAL else tl.minimum((start_m + 1) *\n BLOCK_M, seqlen_k)\n for start_n in range(0, end_n, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_N & EVEN_M:\n if EVEN_HEADDIM:\n k = tl.load(k_ptrs + start_n * stride_kn)\n else:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=offs_d[None,\n :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=(start_n +\n offs_n)[:, None] < seqlen_k, other=0.0)\n else:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=((start_n +\n offs_n)[:, None] < seqlen_k) & (offs_d[None, :] < headdim),\n other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k, trans_b=True)\n if not EVEN_N:\n qk += tl.where((start_n + offs_n)[None, :] < seqlen_k, 0, float\n ('-inf'))\n if IS_CAUSAL:\n qk += tl.where(offs_m[:, None] >= (start_n + offs_n)[None, :], \n 0, float('-inf'))\n if BIAS_TYPE != 'none':\n if BIAS_TYPE == 'vector':\n if EVEN_N:\n bias = tl.load(b_ptrs + start_n).to(tl.float32)\n else:\n bias = tl.load(b_ptrs + start_n, mask=start_n + offs_n <\n seqlen_k, other=0.0).to(tl.float32)\n bias = bias[None, :]\n elif BIAS_TYPE == 'matrix':\n if EVEN_M & EVEN_N:\n bias = tl.load(b_ptrs + start_n).to(tl.float32)\n else:\n bias = tl.load(b_ptrs + start_n, mask=(offs_m[:, None] <\n seqlen_q) & ((start_n + offs_n)[None, :] < seqlen_k\n ), other=0.0).to(tl.float32)\n qk = qk * softmax_scale + bias\n m_ij = tl.maximum(tl.max(qk, 1), lse_i)\n p = tl.exp(qk - m_ij[:, None])\n else:\n m_ij = tl.maximum(tl.max(qk, 1) * softmax_scale, lse_i)\n p = tl.exp(qk * softmax_scale - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n acc_o_scale = tl.exp(m_i - m_ij)\n tl.store(t_ptrs, acc_o_scale)\n acc_o_scale = tl.load(t_ptrs)\n acc_o = acc_o * acc_o_scale[:, None]\n if EVEN_N & EVEN_M:\n if EVEN_HEADDIM:\n v = tl.load(v_ptrs + start_n * stride_vn)\n else:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=offs_d[None,\n :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=(start_n +\n offs_n)[:, None] < seqlen_k, other=0.0)\n else:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=((start_n +\n offs_n)[:, None] < seqlen_k) & (offs_d[None, :] < headdim),\n other=0.0)\n p = p.to(v.dtype)\n acc_o += tl.dot(p, v)\n m_i = m_ij\n l_i_new = tl.exp(lse_i - m_ij) + l_ij\n lse_i = m_ij + tl.log(l_i_new)\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n lse_ptrs = Lse + off_hb * seqlen_q_rounded + offs_m\n m_ptrs = M_out + off_hb * seqlen_q_rounded + offs_m\n tl.store(m_ptrs, m_i)\n tl.store(lse_ptrs, lse_i)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n if EVEN_HEADDIM:\n tl.store(out_ptrs, acc_o)\n else:\n tl.store(out_ptrs, acc_o, mask=offs_d[None, :] < headdim)\n elif EVEN_HEADDIM:\n tl.store(out_ptrs, acc_o, mask=offs_m[:, None] < seqlen_q)\n else:\n tl.store(out_ptrs, acc_o, mask=(offs_m[:, None] < seqlen_q) & (\n offs_d[None, :] < headdim))\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MayDomine/Burst-Attention/blob/b088c554072935074ea9c643de5ee363be5ab1f6/burst_attn/lao.py" }, { "uuid": "5a8dca50-9d6e-4735-be6c-03ed94a672f6", "file_name": "positional_embedding.py", "repo_name": "sjjeong94/ai_compiler_study", "file_path": "aicom/positional_embedding.py", "commit_hash": "e87284aab74acab704e2d192190be446e328e1c6", "starcount": 0, "input": "@triton.jit\ndef rope_fw(t_ptr, f_ptr, o_ptr, t_s_stride, f_s_stride, o_s_stride, d, d2,\n BLOCK_SIZE: tl.constexpr):\n s_idx = tl.program_id(0)\n bh_idx = tl.program_id(1)\n t_start_ptr = t_ptr + s_idx * t_s_stride\n f_start_ptr = f_ptr + s_idx * f_s_stride\n o_start_ptr = o_ptr + s_idx * o_s_stride\n d2_half = d2 // 2\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < d2_half\n f0_ptrs = f_start_ptr + col_offsets\n f1_ptrs = f_start_ptr + col_offsets + d2_half\n f0 = tl.load(f0_ptrs, mask=mask, other=0.0)\n cos0 = tl.cos(f0)\n sin0 = tl.sin(f0)\n f1 = tl.load(f1_ptrs, mask=mask, other=0.0)\n cos1 = tl.cos(f1)\n sin1 = tl.sin(f1)\n t0_ptrs = t_start_ptr + bh_idx * d + col_offsets\n t1_ptrs = t_start_ptr + bh_idx * d + col_offsets + d2_half\n t0 = tl.load(t0_ptrs, mask=mask, other=0.0)\n t1 = tl.load(t1_ptrs, mask=mask, other=0.0)\n o0 = t0 * cos0 - t1 * sin0\n o1 = t1 * cos1 + t0 * sin1\n o0_ptrs = o_start_ptr + bh_idx * d + col_offsets\n o1_ptrs = o_start_ptr + bh_idx * d + col_offsets + d2_half\n tl.store(o0_ptrs, o0, mask=mask)\n tl.store(o1_ptrs, o1, mask=mask)\n if d2 < d:\n remainder = d - d2\n q, r = remainder // BLOCK_SIZE, remainder % BLOCK_SIZE\n for i in range(q):\n t2_ptrs = (t_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * i)\n o2_ptrs = (o_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * i)\n t2 = tl.load(t2_ptrs)\n tl.store(o2_ptrs, t2)\n if r > 0:\n t2_ptrs = (t_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * q)\n o2_ptrs = (o_start_ptr + bh_idx * d + col_offsets + d2 + \n BLOCK_SIZE * q)\n mask = col_offsets < r\n t2 = tl.load(t2_ptrs, mask=mask, other=0.0)\n tl.store(o2_ptrs, t2, mask=mask)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sjjeong94/ai_compiler_study/blob/e87284aab74acab704e2d192190be446e328e1c6/aicom/positional_embedding.py" }, { "uuid": "fca61cfe-da61-4c1c-bf97-ac5bad29149b", "file_name": "test_addptr.py", "repo_name": "microsoft/triton-shared", "file_path": "python/examples/test_addptr.py", "commit_hash": "d5b7bee73b5b12f09906e88f300c0d83b0022753", "starcount": 0, "input": "@triton.jit\ndef addptr(in0, out0):\n for i in range(0, 10, 2):\n in1 = in0 + 1 + i\n in2 = in1 + 1\n out1 = out0 + 1 + i\n out2 = out1 + 1\n a1 = tl.load(in1)\n a2 = tl.load(in2)\n tl.store(out1, a1)\n tl.store(out2, a2)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/microsoft/triton-shared/blob/d5b7bee73b5b12f09906e88f300c0d83b0022753/python/examples/test_addptr.py" }, { "uuid": "5b77e44e-f459-4f02-bbc2-d49523a36ffa", "file_name": "gemm_a16w4.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/gemm_a16w4.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _triton_gemm_a16w4_sub_channel_kernel(A, B, C, scale_b, bias,\n zero_points, M, N, K, rescale_m, rescale_n, rescale_k, stride_am,\n stride_ak, stride_bn, stride_bk, stride_cm, stride_cn, stride_zpk,\n stride_zpn, stride_scalek, stride_scalen, add_bias: tl.constexpr,\n add_zero_points: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl.\n constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rbn[:, None] * stride_bn + rk[None, :] * stride_bk)\n acc_l = tl.zeros((BLOCK_N, BLOCK_M), dtype=tl.float32)\n acc_h = tl.zeros((BLOCK_N, BLOCK_M), dtype=tl.float32)\n _A0 = tl.zeros((1, 1), dtype=A.dtype.element_ty)\n _B0 = tl.zeros((1, 1), dtype=B.dtype.element_ty)\n if add_zero_points:\n zero_points_offs = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n _ZERO_POINT0 = tl.zeros([1], dtype=zero_points.dtype.element_ty)\n scale_offs = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n _SCALE0 = tl.zeros([1], dtype=scale_b.dtype.element_ty)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n b_int4_two = tl.load(B, mask=rk[None, :] < k_remaining, other=_B0)\n b_int4_l = b_int4_two.__lshift__(4).to(tl.int8).__rshift__(4)\n b_int4_h = b_int4_two.__rshift__(4)\n if add_zero_points:\n zero_points_ptrs = (zero_points + k * SPLIT_K * stride_zpk + \n pid_z * stride_zpk + zero_points_offs)\n zero_points_vals = tl.load(zero_points_ptrs, mask=\n zero_points_offs < 2 * N, other=_ZERO_POINT0)\n zero_points_vals = tl.reshape(zero_points_vals, (BLOCK_N, 2))\n zp_l, zp_h = tl.split(zero_points_vals)\n b_int4_l -= zp_l[:, None]\n b_int4_h -= zp_h[:, None]\n scales_val = tl.load(scale_b + k * SPLIT_K * stride_scalek + pid_z *\n stride_scalek + scale_offs, mask=scale_offs < 2 * N, other=_SCALE0)\n scales_val = tl.reshape(scales_val, (BLOCK_N, 2))\n scale_l, scale_h = tl.split(scales_val)\n b_int4_l = b_int4_l * scale_l[:, None]\n b_int4_h = b_int4_h * scale_h[:, None]\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_A0)\n a = tl.trans(a)\n acc_l += tl.dot(b_int4_l, a, out_dtype=tl.float32, allow_tf32=True)\n acc_h += tl.dot(b_int4_h, a, out_dtype=tl.float32, allow_tf32=True)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n acc_l = tl.trans(acc_l)\n acc_h = tl.trans(acc_h)\n acc = tl.interleave(acc_l, acc_h)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n mask = (rm < M)[:, None] & (rn < 2 * N)[None, :]\n if add_bias:\n offs_bias = pid_n * BLOCK_N * 2 + tl.arange(0, 2 * BLOCK_N)\n bias_ptrs = bias + offs_bias\n _BIAS0 = tl.zeros([1], dtype=bias.dtype.element_ty)\n bias_vals = tl.load(bias_ptrs, mask=offs_bias < 2 * N, other=_BIAS0)\n if pid_z == 0:\n acc += bias_vals[None, :]\n if SPLIT_K == 1:\n tl.store(C + rm[:, None] * stride_cm + rn[None, :], acc, mask=mask)\n else:\n tl.atomic_add(C + rm[:, None] * stride_cm + rn[None, :], acc, mask=mask\n )\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/gemm_a16w4.py" }, { "uuid": "e9b25d3b-8143-4146-a7a0-9427ecb0c33d", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_jagged_bmm_kernel(a_ptr, a_offset_ptr, b_ptr, c_ptr, M, N,\n stride_am, stride_ak, stride_bk, stride_bn, stride_cl, stride_cm,\n stride_cn, max_seq_len, allow_tf32: tl.constexpr, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr):\n \"\"\"\n Kernel for computing the matmul C = A x B.\n A has shape (M, sum_B(Ki)), B has shape (sum_B(Ki), N) and C has shape (B, M, N)\n \"\"\"\n pid_batch = tl.program_id(0)\n pid = tl.program_id(1)\n begin = tl.load(a_offset_ptr + pid_batch)\n end = tl.load(a_offset_ptr + pid_batch + 1)\n K = end - begin\n K = tl.minimum(K, max_seq_len)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_m = pid // num_pid_n\n pid_n = pid % num_pid_n\n offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak) + begin * stride_ak\n b_ptrs = b_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] *\n stride_bn) + begin * stride_bk\n c = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, K, BLOCK_SIZE_K):\n updated_offset = k + offs_k\n a = tl.load(a_ptrs, mask=(updated_offset[None, :] < K) & (offs_am[:,\n None] < M), other=0.0)\n b = tl.load(b_ptrs, mask=(updated_offset[:, None] < K) & (offs_bn[\n None, :] < N), other=0.0)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n offs_m = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_n = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n mask = (offs_m[:, None] < M) & (offs_n[None, :] < N)\n c_ptrs = c_ptr + stride_cm * offs_m[:, None] + stride_cn * offs_n[None, :\n ] + stride_cl * pid_batch\n tl.store(c_ptrs, c, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "a5c53b73-1cef-4764-bfc4-9437dd79e4c5", "file_name": "bwd_split_kernel.py", "repo_name": "ROCm/aotriton", "file_path": "test/bwd_split_kernel.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_kernel_dk_dv(Q, K, V, sm_scale, Out, DO, DK, DV, L, D, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vk, stride_vn, seqlen_q,\n seqlen_k, dropout_p, philox_seed, philox_offset_base, BLOCK_M: tl.\n constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL:\n tl.constexpr, ENABLE_DROPOUT: tl.constexpr):\n start_m = tl.program_id(0) * BLOCK_N\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n num_h = tl.num_programs(1)\n num_z = tl.num_programs(2)\n offs_m = start_m + tl.arange(0, BLOCK_N)\n offs_n = tl.arange(0, BLOCK_M)\n q_offset = off_h * stride_qh + off_z * stride_qz\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n k_offset = off_h * stride_kh + off_z * stride_kz\n K_block_ptr = tl.make_block_ptr(base=K + k_offset, shape=(BLOCK_DMODEL,\n seqlen_k), strides=(stride_kk, stride_kn), offsets=(0, start_m),\n block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n v_offset = off_h * stride_vh + off_z * stride_vz\n VT_block_ptr = tl.make_block_ptr(base=V + v_offset, shape=(BLOCK_DMODEL,\n seqlen_k), strides=(stride_vn, stride_vk), offsets=(0, start_m),\n block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n do_offset = q_offset\n DO_block_ptr = tl.make_block_ptr(base=DO + do_offset, shape=(seqlen_q,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n off_zh = off_z * num_h + off_h * 1\n D_ptrs = D + off_zh * seqlen_q\n l_ptrs = L + off_zh * seqlen_q\n qk_scale = sm_scale * 1.44269504\n k = tl.load(K_block_ptr)\n k = (k * qk_scale).to(K_block_ptr.type.element_ty)\n vt = tl.load(VT_block_ptr)\n dv = tl.zeros([BLOCK_N, BLOCK_DMODEL], dtype=tl.float32)\n dk = tl.zeros([BLOCK_N, BLOCK_DMODEL], dtype=tl.float32)\n lo = start_m // BLOCK_M * BLOCK_M if CAUSAL else 0\n hi = seqlen_q\n Q_block_ptr = tl.advance(Q_block_ptr, (lo, 0))\n DO_block_ptr = tl.advance(DO_block_ptr, (lo, 0))\n batch_philox_offset = philox_offset_base + off_zh * seqlen_q * seqlen_k\n \"\"\"\n K1 K2 (d)V dO\n Q1 qk11 qk12 (d)v1 dO1\n Q2 qk21 qk22 (d)v2 dO2\n\n QK: (seqlen_q, seqlen_k)\n dO: (seqlen_q, hdim)\n dV: (seqlen_k, hdim)\n\n dV = (QK)^T dO\n\n dV1 = qk11 dO1 + qk21 dO2 = q1 k1 dO1 + q2 k1 dO2\n dV2 = qk12 dO1 + qk22 dO2 = q1 k2 dO1 + q2 k2 dO2\n ~~~~~ = 0\n start_m: select k and dV\n start_n: select q and dO\n \"\"\"\n for start_n in range(lo, hi, BLOCK_M):\n offs_m_curr = offs_n[:, None] + start_n\n q = tl.load(Q_block_ptr)\n do = tl.load(DO_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += dot(BLOCK_M, BLOCK_DMODEL, BLOCK_DMODEL, q, k)\n if CAUSAL:\n qk = tl.where(offs_m_curr >= offs_m[None, :], qk, float('-inf'))\n l_i = tl.load(l_ptrs + offs_m_curr)\n p = tl.math.exp2(qk - l_i)\n if ENABLE_DROPOUT:\n philox_offset = batch_philox_offset + start_n * seqlen_k + start_m\n keep = dropout_mask(philox_seed, philox_offset, dropout_p,\n BLOCK_M, BLOCK_N, seqlen_k)\n if BLOCK_M == 1:\n dv += tl.where(keep, p / (1 - dropout_p), 0.0).to(Q.dtype.\n element_ty) * do\n else:\n dv += tl.dot(tl.where(tl.trans(keep), tl.trans(p) / (1 -\n dropout_p), 0.0).to(Q.dtype.element_ty), do)\n elif BLOCK_M == 1:\n dv += p.to(Q.dtype.element_ty) * do\n else:\n dv += tl.dot(tl.trans(p).to(do.dtype), do)\n Di = tl.load(D_ptrs + offs_m_curr)\n dp = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n dp += tl.dot(do, vt)\n if ENABLE_DROPOUT:\n dp = tl.where(keep, dp / (1 - dropout_p), 0)\n ds = p * (dp - Di)\n if BLOCK_M == 1:\n dk += ds.to(Q.dtype.element_ty) * q\n else:\n dk += tl.dot(tl.trans(ds.to(Q.dtype.element_ty)), q)\n Q_block_ptr = tl.advance(Q_block_ptr, (BLOCK_M, 0))\n DO_block_ptr = tl.advance(DO_block_ptr, (BLOCK_M, 0))\n DK_block_ptr = tl.make_block_ptr(base=DK + k_offset, shape=(seqlen_k,\n BLOCK_DMODEL), strides=(stride_kn, stride_kk), offsets=(start_m, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n DV_block_ptr = tl.make_block_ptr(base=DV + v_offset, shape=(seqlen_k,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(start_m, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n tl.store(DK_block_ptr, (dk * sm_scale).to(DK.type.element_ty))\n tl.store(DV_block_ptr, dv.to(DV.type.element_ty))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/bwd_split_kernel.py" }, { "uuid": "5e173f19-b632-4e9b-8079-ecbf1eeba1e1", "file_name": "k_softmax.py", "repo_name": "kimiasa/Experiments", "file_path": "src/ops/triton/k_softmax.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['K'])\n@triton.heuristics({'DEPTH': lambda nargs: get_depth(nargs['K'])})\n@triton.heuristics({'IS_FP16': lambda nargs: nargs['GradIn'].dtype == torch\n .float16})\n@triton.jit\ndef _softmax_backward(GradIn, GradOut, Out, stride_bm, stride_bn, stride_gm,\n stride_gn, stride_om, stride_on, K, LOG: tl.constexpr, CAUSAL: tl.\n constexpr, DEPTH: tl.constexpr, IS_FP16: tl.constexpr):\n \"\"\"\n Compute the softmax gradients.\n ..Note: Not autotuning for now because this would lead to broken accumulated gradients\n \"\"\"\n m = tl.program_id(0)\n n = tl.program_id(1)\n k = tl.arange(0, DEPTH)\n grad_out_ptrs = GradOut + m * stride_gm + n * stride_gn + k\n out_ptrs = Out + m * stride_om + n * stride_on + k\n io_mask = k < K\n if CAUSAL:\n io_mask = io_mask & (k <= n)\n g = tl.load(grad_out_ptrs, mask=io_mask, other=float(0))\n o = tl.load(out_ptrs, mask=io_mask, other=float(0))\n if CAUSAL:\n zero = float(0)\n zero = zero.to(g.dtype)\n g = tl.where(k > n, zero, g)\n o = tl.where(k > n, zero, o)\n if LOG:\n s = tl.sum(g, 0)\n if IS_FP16:\n o = o.to(tl.float32)\n grad_in = g - tl.exp(o) * s\n else:\n s = tl.sum(g * o, 0)\n grad_in = o * (g - s)\n grad_in_ptrs = GradIn + m * stride_bm + n * stride_bn + k\n tl.store(grad_in_ptrs, grad_in, mask=k < K)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/ops/triton/k_softmax.py" }, { "uuid": "ab5cdfd9-a6c2-4c41-ada3-c603bb44fb3a", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=warps) for warps in [\n 4, 8, 16]], key=['HEAD_SIZE', 'PADDED_NUM_SPLITS', 'PARTITION_SIZE'])\n@triton.jit\ndef _paged_attn_wo_mma_v2_reduce_kernel(out, exp_sums, max_logits, tmp_out,\n context_lens, stride_exp_m, stride_exp_n, stride_out_m, stride_out_n,\n stride_tmp_m, stride_tmp_n, stride_tmp_k, HEAD_SIZE: tl.constexpr,\n PADDED_NUM_SPLITS: tl.constexpr, PARTITION_SIZE: tl.constexpr):\n seq_idx = tl.program_id(axis=1)\n head_idx = tl.program_id(axis=0)\n context_len = tl.load(context_lens + seq_idx)\n num_partitions = tl.cdiv(context_len, PARTITION_SIZE)\n max_logit = float('-inf')\n offs_logit = seq_idx * stride_exp_m + head_idx * stride_exp_n\n head_size_offs = tl.arange(0, HEAD_SIZE)\n tmp_out_ptr = seq_idx * stride_tmp_m + head_idx * stride_tmp_n\n out_ptr = seq_idx * stride_out_m + head_idx * stride_out_n + head_size_offs\n acc = tl.zeros([HEAD_SIZE], dtype=tl.float32)\n global_exp_sum = tl.zeros([1], dtype=tl.float32)\n logits = tl.load(max_logits + offs_logit + tl.arange(0,\n PADDED_NUM_SPLITS), mask=tl.arange(0, PADDED_NUM_SPLITS) <\n num_partitions, other=float('-inf'))\n max_logit = tl.max(logits, axis=0)\n exp_sum = tl.load(exp_sums + offs_logit + tl.arange(0,\n PADDED_NUM_SPLITS), mask=tl.arange(0, PADDED_NUM_SPLITS) <\n num_partitions, other=0.0)\n rescaled_exp_sum = exp_sum * tl.exp(logits - max_logit)\n global_exp_sum += tl.sum(rescaled_exp_sum, axis=0)\n tmp = tl.load(tmp_out + tmp_out_ptr + tl.arange(0, PADDED_NUM_SPLITS)[:,\n None] * stride_tmp_k + head_size_offs)\n acc += tl.sum(tmp * rescaled_exp_sum[:, None], axis=0)\n inv_sum = 1.0 / (global_exp_sum + 1e-06)\n tl.store(out + out_ptr, acc * inv_sum)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "0c45df3d-8dd1-4102-b17a-cee67e7c7218", "file_name": "sparse_linear.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_linear.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.autotune(configs=autotune_configs, key=['row_dim', 'col_dim',\n 'inner_dim'])\n@triton.jit\ndef dense_matmul_kernel(lhs_ptr, rhs_ptr, out_ptr, row_dim: tl.constexpr,\n col_dim: tl.constexpr, inner_dim: tl.constexpr, lhs_stride_row: tl.\n constexpr, lhs_stride_inner: tl.constexpr, rhs_stride_inner: tl.\n constexpr, rhs_stride_col: tl.constexpr, out_stride_row: tl.constexpr,\n out_stride_col: tl.constexpr, accumulate: tl.constexpr, masked: tl.\n constexpr, block_size_row: tl.constexpr, block_size_col: tl.constexpr,\n block_size_inner: tl.constexpr, group_size_row: tl.constexpr):\n if not masked:\n tl.static_assert(row_dim % block_size_row == 0)\n tl.static_assert(col_dim % block_size_col == 0)\n tl.static_assert(inner_dim % block_size_inner == 0)\n pid_row, pid_col = tl.swizzle2d(tl.program_id(axis=0), tl.program_id(\n axis=1), tl.cdiv(row_dim, block_size_row), tl.cdiv(col_dim,\n block_size_col), group_size_row)\n row_offset = pid_row * block_size_row\n col_offset = pid_col * block_size_col\n row_range = tl.arange(0, block_size_row)[:, None] + row_offset\n col_range = tl.arange(0, block_size_col)[None, :] + col_offset\n inner_range = tl.arange(0, block_size_inner)\n lhs_ptr += row_range * lhs_stride_row + inner_range[None, :\n ] * lhs_stride_inner\n rhs_ptr += inner_range[:, None\n ] * rhs_stride_inner + col_range * rhs_stride_col\n out_ptr += row_range * out_stride_row + col_range * out_stride_col\n if masked:\n row_mask = row_range < row_dim\n col_mask = col_range < col_dim\n inner_mask = inner_range < inner_dim\n out = tl.dot(tl.load(lhs_ptr, mask=row_mask * inner_mask[None, :],\n other=0), tl.load(rhs_ptr, mask=inner_mask[:, None] * col_mask,\n other=0), out_dtype=tl.float32)\n else:\n out = tl.dot(tl.load(lhs_ptr), tl.load(rhs_ptr), out_dtype=tl.float32)\n for k in range(1, inner_dim // block_size_inner):\n lhs_ptr += block_size_inner * lhs_stride_inner\n rhs_ptr += block_size_inner * rhs_stride_inner\n if masked:\n inner_range += block_size_inner\n inner_mask = inner_range < inner_dim\n out += tl.dot(tl.load(lhs_ptr, mask=row_mask & inner_mask[None,\n :], other=0), tl.load(rhs_ptr, mask=inner_mask[:, None] &\n col_mask, other=0), out_dtype=tl.float32)\n else:\n out += tl.dot(tl.load(lhs_ptr), tl.load(rhs_ptr))\n if masked:\n out_mask = row_mask & col_mask\n if accumulate:\n out += tl.load(out_ptr, mask=out_mask)\n tl.store(out_ptr, out, mask=out_mask)\n else:\n if accumulate:\n out += tl.load(out_ptr)\n tl.store(out_ptr, out)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_linear.py" }, { "uuid": "a20761f1-48a0-41de-8397-039ab5f0ba71", "file_name": "bgmv_expand_slice.py", "repo_name": "IBM/vllm", "file_path": "vllm/lora/ops/bgmv_expand_slice.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _bgmv_expand_slice_kernel(input_ptr, lora_ptr, out_ptr, N, K,\n lora_indices, xm_stride, xk_stride, l0_stride, lora_k_stride,\n lora_n_stride, cm_stride, cn_stride, slice_offset, BLOCK_N: tl.\n constexpr, BLOCK_K: tl.constexpr, SPLIT_N: tl.constexpr, EVEN_K: tl.\n constexpr, ADD_INPUTS: tl.constexpr, CAST_TYPE: tl.constexpr):\n \"\"\"\n GroupGEMV, additionally, introducing SPLIT_N can improve large hidden_size's\n performance\n \"\"\"\n pid_sn = tl.program_id(axis=0)\n cur_batch = tl.program_id(axis=1)\n lora_index = tl.load(lora_indices + cur_batch)\n if lora_index == -1:\n return\n offset_k = tl.arange(0, BLOCK_K)\n offset_n = tl.arange(0, BLOCK_N)\n if EVEN_K:\n tiled_a = tl.load(input_ptr + cur_batch * xm_stride + offset_k *\n xk_stride)\n else:\n tiled_a = tl.load(input_ptr + cur_batch * xm_stride + offset_k *\n xk_stride, mask=offset_k < K, other=0)\n split_n_length = tl.cdiv(N, SPLIT_N)\n if CAST_TYPE:\n tiled_a = tiled_a.to(lora_ptr.dtype.element_ty)\n b_ptr = (lora_ptr + l0_stride * lora_index + pid_sn * split_n_length *\n lora_k_stride)\n c_ptr = (out_ptr + cur_batch * cm_stride + pid_sn * split_n_length + \n slice_offset * cn_stride)\n for n in range(0, split_n_length, BLOCK_N):\n current_n = n + offset_n\n b_ptr_mask = (current_n[:, None] < split_n_length) & (offset_k[None,\n :] < K)\n c_mask = current_n < split_n_length\n tiled_b = tl.load(b_ptr + current_n[:, None] * lora_k_stride + \n offset_k[None, :] * lora_n_stride, mask=b_ptr_mask, other=0.0)\n if ADD_INPUTS:\n tiled_out = tl.load(c_ptr + current_n * cn_stride, mask=c_mask,\n other=None)\n accumulator = tl.sum(tiled_a * tiled_b, 1) + tiled_out\n else:\n accumulator = tl.sum(tiled_a * tiled_b, 1)\n tl.store(c_ptr + current_n * cn_stride, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/lora/ops/bgmv_expand_slice.py" }, { "uuid": "1d21c4d6-1ec8-482a-8d2e-484bbc9cdf08", "file_name": "y_9.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_9.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef ninth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_9 = tl.load(sph_grad_ptr + output_row_offset + 9, mask=\n output_row_offset + 9 < output_numel)\n g_10 = tl.load(sph_grad_ptr + output_row_offset + 10, mask=\n output_row_offset + 10 < output_numel)\n g_11 = tl.load(sph_grad_ptr + output_row_offset + 11, mask=\n output_row_offset + 11 < output_numel)\n g_12 = tl.load(sph_grad_ptr + output_row_offset + 12, mask=\n output_row_offset + 12 < output_numel)\n g_13 = tl.load(sph_grad_ptr + output_row_offset + 13, mask=\n output_row_offset + 13 < output_numel)\n g_14 = tl.load(sph_grad_ptr + output_row_offset + 14, mask=\n output_row_offset + 14 < output_numel)\n g_15 = tl.load(sph_grad_ptr + output_row_offset + 15, mask=\n output_row_offset + 15 < output_numel)\n g_16 = tl.load(sph_grad_ptr + output_row_offset + 16, mask=\n output_row_offset + 16 < output_numel)\n g_17 = tl.load(sph_grad_ptr + output_row_offset + 17, mask=\n output_row_offset + 17 < output_numel)\n g_18 = tl.load(sph_grad_ptr + output_row_offset + 18, mask=\n output_row_offset + 18 < output_numel)\n CONST000 = 1.59908344719522\n CONST001 = 2.0\n CONST002 = 3.0\n CONST003 = 4.0\n CONST004 = 5.0\n CONST005 = 6.39633378878088\n CONST006 = 7.0\n CONST007 = 8.63855507530412\n CONST008 = 9.59450068317133\n CONST009 = 6.39633378878088\n CONST011 = 12.7926675775618\n CONST012 = 12.7926675775618\n CONST014 = 15.5493991355474\n CONST015 = 14.391751024757\n CONST017 = 15.0007324039945\n CONST018 = 14.45506743704\n CONST019 = 14.45506743704\n CONST020 = 13.3827919767794\n CONST021 = 23.8930627690618\n CONST022 = 23.8930627690618\n CONST023 = 27.0429549260581\n CONST024 = 29.2403830344269\n CONST025 = 30.001464807989\n CONST027 = 29.2403830344269\n CONST028 = 38.3780027326853\n CONST031 = 39.2300904918661\n CONST032 = 42.9079114754785\n CONST033 = 10.7269778688696\n CONST034 = 54.0859098521163\n CONST036 = 58.9217071894985\n CONST037 = 57.8202697481601\n CONST038 = 60.0029296159779\n CONST039 = 62.4530292249704\n CONST040 = 64.3618672132178\n CONST042 = 69.1084406024329\n CONST044 = 78.5622762526647\n CONST045 = 85.815822950957\n CONST046 = 85.815822950957\n CONST050 = 107.062335814235\n CONST052 = 108.171819704233\n CONST053 = -1935.03633686812\n CONST055 = 115.64053949632\n CONST056 = 117.843414378997\n CONST057 = 117.843414378997\n CONST059 = 120.005859231956\n CONST060 = 2176.91587897664\n CONST061 = 2176.91587897664\n CONST064 = 150.007324039945\n CONST065 = -1892.23403121978\n CONST066 = -1885.49463006395\n CONST067 = 173.46080924448\n CONST068 = -1873.59087674911\n CONST070 = 10.7269778688696\n CONST071 = 180.008788847934\n CONST074 = 13.5214774630291\n CONST076 = 205.957975082297\n CONST078 = 216.343639408465\n CONST079 = 4326.8727881693\n CONST080 = 233.923064275415\n CONST081 = 233.923064275415\n CONST082 = 240.011718463912\n CONST083 = 241.879542108515\n CONST085 = 255.853351551235\n CONST086 = 255.853351551235\n CONST087 = 257.447468852871\n CONST088 = 257.447468852871\n CONST090 = 270.429549260581\n CONST091 = 289.101348740801\n CONST093 = 300.01464807989\n CONST097 = 13.0937127087774\n CONST099 = -3747.18175349822\n CONST100 = 6.39633378878088\n CONST103 = 374.718175349822\n CONST105 = 404.741888237121\n CONST106 = 411.915950164594\n CONST107 = 412.45195032649\n CONST108 = 432.68727881693\n CONST109 = 435.383175795328\n CONST110 = 435.383175795327\n CONST112 = 462.562157985281\n CONST113 = -1571.24552505329\n CONST114 = 483.759084217031\n CONST115 = 511.706703102471\n CONST116 = 562.077263024733\n CONST117 = 578.202697481601\n CONST119 = -1451.27725265109\n CONST121 = -1451.27725265109\n CONST123 = 600.029296159779\n CONST124 = -1440.07031078347\n CONST129 = -1387.68647395584\n CONST130 = -1387.68647395584\n CONST131 = -1373.05316721531\n CONST132 = -1338.01151506746\n CONST133 = 725.638626325546\n CONST134 = -1298.06183645079\n CONST137 = 788.430846341574\n CONST138 = -1249.06058449941\n CONST139 = -1228.09608744593\n CONST140 = -1228.09608744593\n CONST141 = 823.831900329187\n CONST142 = -3245.15459112698\n CONST143 = -1178.43414378997\n CONST144 = 870.766351590655\n CONST145 = 870.766351590655\n CONST147 = -1124.15452604947\n CONST149 = -3153.7233853663\n CONST150 = 960.046873855647\n CONST151 = 960.046873855647\n CONST152 = 967.518168434061\n CONST153 = -1081.71819704233\n CONST154 = 967.518168434061\n CONST155 = -1060.59072941097\n CONST156 = 1023.41340620494\n CONST157 = 1023.41340620494\n CONST159 = -967.518168434061\n CONST160 = 1081.71819704233\n CONST161 = -960.046873855647\n CONST163 = -936.795438374555\n CONST165 = -900.043944239669\n CONST166 = 1156.4053949632\n CONST168 = -2902.55450530218\n CONST170 = 11.2632978048796\n CONST171 = -785.622762526647\n CONST172 = -785.622762526647\n CONST173 = -767.560054653706\n CONST175 = 1338.01151506746\n CONST176 = -693.843236977922\n CONST177 = -693.843236977921\n CONST178 = -686.526583607656\n CONST179 = -669.005757533731\n CONST180 = -669.005757533731\n CONST182 = -649.030918225395\n CONST183 = -630.744677073259\n CONST184 = -628.498210021318\n CONST185 = -628.498210021317\n CONST186 = -600.029296159779\n CONST187 = -589.217071894985\n CONST188 = -578.202697481601\n CONST189 = 15.5493991355474\n CONST190 = -562.077263024733\n CONST191 = 1500.07324039945\n CONST192 = -480.023436927823\n CONST193 = -480.023436927823\n CONST195 = -462.562157985281\n CONST196 = -450.021972119834\n CONST197 = -412.45195032649\n CONST198 = -409.365362481977\n CONST199 = -409.365362481976\n CONST200 = -404.741888237121\n CONST201 = -392.811381263323\n CONST202 = -383.780027326853\n CONST203 = -383.780027326853\n CONST204 = 1672.51439383433\n CONST205 = -374.718175349822\n CONST206 = -353.530243136991\n CONST207 = -2400.11718463912\n CONST209 = -346.921618488961\n CONST210 = -346.921618488961\n CONST211 = -343.263291803828\n CONST212 = -338.631358951921\n CONST213 = -338.631358951921\n CONST214 = -324.515459112698\n CONST215 = -315.37233853663\n CONST216 = -314.249105010659\n CONST217 = -2356.86828757994\n CONST218 = -300.01464807989\n CONST219 = -294.608535947493\n CONST220 = -289.101348740801\n CONST221 = -270.013183271901\n CONST222 = -2312.81078992641\n CONST223 = 1800.08788847934\n CONST224 = -241.879542108515\n CONST225 = -240.011718463912\n CONST226 = -241.879542108515\n CONST227 = -4326.8727881693\n CONST228 = -216.343639408465\n CONST229 = -210.010253655923\n CONST230 = -204.682681240988\n CONST231 = -204.682681240988\n CONST232 = -204.682681240988\n CONST233 = -196.405690631662\n CONST234 = -191.144502152495\n CONST235 = -191.890013663426\n CONST236 = -191.890013663427\n CONST237 = -187.359087674911\n CONST238 = -180.008788847934\n CONST239 = -176.765121568496\n CONST241 = 1873.59087674911\n CONST242 = -173.46080924448\n CONST244 = -162.257729556349\n CONST245 = -156.920361967464\n CONST246 = -156.920361967464\n CONST248 = -150.007324039945\n CONST249 = -144.5506743704\n CONST250 = -137.14955340795\n CONST251 = -135.214774630291\n CONST252 = -127.926675775618\n CONST253 = -127.926675775618\n CONST254 = -120.939771054258\n CONST255 = -120.005859231956\n CONST256 = -120.939771054258\n CONST257 = -117.843414378997\n CONST258 = -117.843414378997\n CONST259 = -115.64053949632\n CONST260 = -115.64053949632\n CONST261 = 1935.03633686812\n CONST262 = -2163.43639408465\n CONST263 = -114.421097267943\n CONST264 = -108.171819704233\n CONST265 = -107.062335814235\n CONST266 = -108.171819704233\n CONST267 = -104.74970167022\n CONST268 = -96.7518168434061\n CONST269 = -96.7518168434061\n CONST270 = -90.0043944239669\n CONST271 = -90.106382439037\n CONST272 = -80.2967518606762\n CONST273 = -78.4601809837321\n CONST274 = -78.4601809837321\n CONST275 = -77.2655855030233\n CONST276 = -78.5622762526647\n CONST277 = -68.5747767039748\n CONST278 = -63.9633378878088\n CONST279 = -62.4530292249704\n CONST280 = -61.8124684024186\n CONST281 = -60.0029296159779\n CONST282 = -63.9633378878088\n CONST283 = -58.9217071894985\n CONST284 = -57.8202697481601\n CONST285 = -57.8202697481601\n CONST286 = -48.375908421703\n CONST287 = -48.3759084217031\n CONST288 = -39.2811381263323\n CONST289 = -38.6327927515116\n CONST290 = -39.2811381263323\n CONST291 = -30.9062342012093\n CONST292 = -30.001464807989\n CONST293 = -30.001464807989\n CONST294 = -27.6433762409732\n CONST295 = -17.3847567381802\n CONST296 = -15.0007324039945\n CONST297 = -14.7304267973746\n CONST298 = -13.5214774630291\n CONST299 = -13.0937127087774\n CONST300 = -13.3827919767794\n CONST301 = -9.82028453158308\n CONST302 = -4.91014226579154\n CONST303 = 2046.82681240988\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR02 = VAR06 * VAR06\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR11 = VAR15 * VAR15\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR20 = VAR24 * VAR24\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += g_0 * (CONST021 * VAR20 + CONST022 * VAR02 + CONST179 * VAR04 *\n VAR26 + CONST180 * VAR08 * VAR22 + CONST204 * VAR06 * VAR24\n ) + g_1 * y * (CONST065 * VAR08 * VAR23 - CONST149 * VAR06 * VAR25 +\n CONST183 * VAR04 * z - CONST271 * VAR21) + g_10 * (CONST012 * VAR21 *\n x + VAR23 * (CONST028 * VAR07 + CONST203 * VAR17 * x) + VAR25 * (\n CONST028 * VAR05 + CONST157 * VAR15 * x + CONST173 * VAR07 * VAR17) +\n z * (CONST011 * VAR03 + CONST157 * VAR07 * VAR15 + CONST198 * VAR13 *\n x + CONST202 * VAR05 * VAR17)) + g_11 * (CONST150 * VAR07 * VAR14 +\n CONST250 * VAR12 * x + VAR16 * (CONST093 * VAR24 * x + CONST165 *\n VAR05 + CONST186 * VAR07 * VAR26) + y * (CONST059 * VAR03 + \n CONST071 * VAR05 * VAR26 + CONST281 * VAR22 * x)) + g_12 * (VAR23 *\n (CONST257 * VAR17 * x - CONST290 * VAR07) + VAR25 * (CONST044 *\n VAR05 + CONST143 * VAR07 * VAR17 - CONST172 * VAR15 * x) + z * (\n CONST155 * VAR05 * VAR17 + CONST184 * VAR13 * x - CONST217 * VAR07 *\n VAR15 - CONST288 * VAR03)) + g_13 * (VAR14 * (CONST129 * VAR26 * x -\n CONST195 * VAR07) + VAR16 * (CONST166 * VAR24 * x + CONST176 *\n VAR05 - CONST222 * VAR07 * VAR26) + y * (CONST188 * VAR07 * VAR24 +\n CONST209 * VAR05 * VAR26 - CONST259 * VAR03 + CONST259 * VAR22 * x)\n ) + g_14 * (CONST042 * VAR03 * z + CONST268 * VAR07 * VAR23 + \n CONST294 * VAR21 * x + VAR15 * (CONST053 * VAR25 * x + CONST261 *\n VAR07 * z) + VAR17 * (CONST119 * VAR05 * z + CONST144 * VAR23 * x +\n CONST152 * VAR07 * VAR25)) + g_15 * (VAR16 * (CONST068 * VAR24 * x -\n CONST099 * VAR07 * VAR26 + CONST205 * VAR05) + y * (CONST050 *\n VAR03 + CONST147 * VAR05 * VAR26 - CONST205 * VAR22 * x)) + g_16 * (\n CONST214 * VAR05 * VAR25 - CONST264 * VAR03 * z + CONST264 * VAR07 *\n VAR23 - CONST275 * VAR21 * x + VAR17 * (CONST079 * VAR07 * VAR25 + \n CONST134 * VAR05 * z + CONST134 * VAR23 * x)) + g_17 * y * (\n CONST065 * VAR05 * VAR26 - CONST149 * VAR07 * VAR24 + CONST183 *\n VAR22 * x - CONST271 * VAR03) + g_18 * (CONST132 * VAR05 * VAR25 + \n CONST175 * VAR07 * VAR23 - CONST234 * VAR03 * z + CONST234 * VAR21 * x\n ) + g_2 * (CONST002 * VAR08 * (CONST034 * VAR22 + CONST153 * VAR17 *\n VAR24) + CONST004 * VAR06 * (CONST023 * VAR24 - CONST182 * VAR17 *\n VAR26) + CONST006 * VAR04 * (CONST289 * VAR26 + CONST291 * VAR17) -\n CONST228 * VAR17 * VAR22 - CONST295 * VAR02 + CONST298 * VAR20\n ) + g_3 * (VAR16 * (-CONST068 * VAR06 * z + CONST099 * VAR08 *\n VAR25 + CONST103 * VAR23) + y * (CONST116 * VAR08 * VAR23 - \n CONST163 * VAR06 * VAR25 + CONST190 * VAR04 * z + CONST272 * VAR21)\n ) + g_4 * (CONST007 * VAR20 + CONST014 * VAR02 + CONST254 * VAR06 *\n VAR24 + CONST269 * VAR04 * VAR26 + VAR15 * (CONST114 * VAR06 + \n CONST114 * VAR24 + CONST168 * VAR08 * VAR26) + VAR17 * (CONST060 *\n VAR06 * VAR26 + CONST133 * VAR08 * VAR24 + CONST212 * VAR04 + \n CONST224 * VAR22)) + g_5 * (VAR14 * (CONST130 * VAR08 * z - \n CONST195 * VAR25) + VAR16 * (CONST195 * VAR23 - CONST222 * VAR06 *\n z) + y * (CONST067 * VAR08 * VAR23 + CONST200 * VAR04 * z + \n CONST220 * VAR06 * VAR25 - CONST284 * VAR21)) + g_6 * (CONST002 *\n VAR08 * (CONST201 * VAR15 * VAR26 - CONST219 * VAR17 * VAR24 + \n CONST267 * VAR13 + CONST299 * VAR22) + CONST004 * VAR06 * (CONST036 *\n VAR17 * VAR26 - CONST233 * VAR15 + CONST301 * VAR24) + CONST187 *\n VAR15 * VAR24 + CONST197 * VAR04 * VAR17 - CONST216 * VAR13 * VAR26 -\n CONST239 * VAR17 * VAR22 - CONST297 * VAR02 + CONST302 * VAR20\n ) + g_7 * (CONST002 * VAR08 * (-CONST186 * VAR16 * VAR25 + CONST192 *\n VAR14 * z + CONST270 * VAR23 * y) + CONST004 * VAR06 * (-CONST218 *\n VAR16 * z + CONST270 * VAR25 * y) + CONST193 * VAR14 * VAR25 - \n CONST218 * VAR16 * VAR23 + CONST229 * VAR04 * y * z - CONST250 *\n VAR12 * z + CONST292 * VAR21 * y) + g_8 * (CONST000 * VAR20 + \n CONST002 * VAR08 * (CONST005 * VAR22 + CONST115 * VAR15 * VAR26 + \n CONST230 * VAR13 + CONST235 * VAR17 * VAR24) + CONST004 * VAR06 * (\n CONST008 * VAR24 + CONST085 * VAR15 + CONST235 * VAR17 * VAR26) + \n CONST006 * VAR04 * (CONST009 * VAR26 + CONST278 * VAR17) + CONST015 *\n VAR02 + CONST024 * VAR11 + CONST085 * VAR15 * VAR24 + CONST231 *\n VAR13 * VAR26 + CONST278 * VAR17 * VAR22) + g_9 * (CONST245 * VAR12 *\n x + VAR14 * (CONST141 * VAR07 + CONST141 * VAR26 * x) + VAR16 * (\n CONST131 * VAR07 * VAR26 + CONST178 * VAR05 + CONST178 * VAR24 * x) +\n y * (CONST045 * VAR03 + CONST046 * VAR22 * x + CONST087 * VAR05 *\n VAR26 + CONST088 * VAR07 * VAR24))\n g_y += CONST001 * g_16 * y * (CONST160 * VAR06 * VAR25 + CONST182 *\n VAR08 * VAR23 + CONST228 * VAR04 * z - CONST291 * VAR21) + g_1 * (-\n CONST183 * VAR05 * VAR25 + CONST183 * VAR07 * VAR23 + CONST271 *\n VAR03 * z - CONST271 * VAR21 * x) + g_10 * (CONST252 * VAR21 * y + \n VAR23 * (CONST157 * VAR16 + CONST203 * VAR08 * y) + VAR25 * (\n CONST140 * VAR14 + CONST202 * VAR06 * y + CONST303 * VAR08 * VAR16) +\n z * (CONST080 * VAR12 + CONST139 * VAR08 * VAR14 + CONST157 * VAR06 *\n VAR16 + CONST252 * VAR04 * y)) + g_11 * (CONST002 * VAR17 * (\n CONST064 * VAR08 * VAR24 + CONST248 * VAR04 + CONST248 * VAR06 *\n VAR26 - CONST248 * VAR22) + CONST004 * VAR15 * (CONST082 * VAR06 + \n CONST225 * VAR24) + CONST006 * VAR13 * (CONST277 * VAR08 - CONST277 *\n VAR26) + CONST017 * VAR02 + CONST025 * VAR04 * VAR26 + CONST293 *\n VAR08 * VAR22 + CONST296 * VAR20) + g_12 * (CONST056 * VAR21 * y + \n VAR23 * (CONST171 * VAR16 + CONST257 * VAR08 * y) + VAR25 * (-\n CONST113 * VAR08 * VAR16 - CONST185 * VAR14 + CONST187 * VAR06 * y) +\n z * (CONST066 * VAR08 * VAR14 + CONST206 * VAR04 * y - CONST217 *\n VAR06 * VAR16)) + g_13 * (CONST002 * VAR17 * (CONST117 * VAR06 *\n VAR26 + CONST117 * VAR08 * VAR24 + CONST259 * VAR04 + CONST260 *\n VAR22) + CONST004 * VAR15 * (CONST055 * VAR06 + CONST055 * VAR24 + \n CONST176 * VAR08 * VAR26) + CONST018 * VAR20 + CONST019 * VAR02 + \n CONST249 * VAR06 * VAR24 + CONST284 * VAR04 * VAR26 + CONST285 *\n VAR08 * VAR22) + g_14 * (CONST001 * y * (CONST083 * VAR06 * VAR25 +\n CONST109 * VAR08 * VAR23 + CONST226 * VAR04 * z + CONST286 * VAR21) +\n CONST003 * VAR16 * (CONST114 * VAR06 * z + CONST159 * VAR08 * VAR25 -\n CONST269 * VAR23)) + g_15 * (CONST002 * VAR17 * (CONST039 * VAR22 -\n CONST163 * VAR06 * VAR26 + CONST163 * VAR08 * VAR24 + CONST279 *\n VAR04) + CONST020 * VAR02 + CONST237 * VAR04 * VAR26 - CONST237 *\n VAR08 * VAR22 + CONST300 * VAR20) + g_17 * (CONST137 * VAR06 *\n VAR24 + CONST170 * VAR02 + CONST170 * VAR20 + CONST215 * VAR04 *\n VAR26 + CONST215 * VAR08 * VAR22) + g_2 * (CONST108 * VAR22 * x * y -\n CONST134 * VAR05 * VAR26 * y + CONST262 * VAR07 * VAR24 * y + \n CONST280 * VAR03 * y) + g_3 * (CONST002 * VAR17 * (CONST103 * VAR23 *\n x + CONST138 * VAR07 * VAR25 - CONST205 * VAR05 * z) - CONST237 *\n VAR05 * VAR25 - CONST237 * VAR07 * VAR23 + CONST272 * VAR03 * z + \n CONST272 * VAR21 * x) + g_4 * (CONST001 * y * (CONST110 * VAR05 *\n VAR26 - CONST224 * VAR07 * VAR24 + CONST224 * VAR22 * x + CONST287 *\n VAR03) + CONST003 * VAR16 * (CONST114 * VAR24 * x + CONST159 *\n VAR07 * VAR26 - CONST269 * VAR05)) + g_5 * (CONST002 * VAR17 * (\n CONST112 * VAR05 * z + CONST195 * VAR23 * x) + CONST004 * VAR15 * (\n CONST195 * VAR07 * z - CONST195 * VAR25 * x) + CONST037 * VAR07 *\n VAR23 + CONST284 * VAR05 * VAR25 - CONST284 * VAR21 * x + CONST285 *\n VAR03 * z) + g_6 * (CONST258 * VAR03 * y + VAR05 * (CONST057 *\n VAR26 * y - CONST171 * VAR16) + VAR07 * (CONST113 * VAR16 * VAR26 +\n CONST185 * VAR14 - CONST187 * VAR24 * y) + x * (-CONST066 * VAR14 *\n VAR26 - CONST206 * VAR22 * y + CONST217 * VAR16 * VAR24)) + g_7 * (\n CONST292 * VAR03 * z + VAR05 * (-CONST165 * VAR17 * z + CONST270 *\n VAR25) + VAR07 * (CONST207 * VAR15 * z + CONST223 * VAR17 * VAR25 +\n CONST270 * VAR23) + x * (CONST151 * VAR13 * z - CONST165 * VAR17 *\n VAR23 + CONST207 * VAR15 * VAR25 + CONST292 * VAR21)) + g_8 * (\n CONST253 * VAR03 * y + VAR05 * (CONST156 * VAR16 + CONST202 * VAR26 *\n y) + VAR07 * (CONST139 * VAR14 + CONST202 * VAR24 * y + CONST303 *\n VAR16 * VAR26) + x * (CONST081 * VAR12 + CONST140 * VAR14 * VAR26 +\n CONST156 * VAR16 * VAR24 + CONST253 * VAR22 * y)) + g_9 * (CONST002 *\n VAR17 * (CONST211 * VAR06 * VAR26 + CONST211 * VAR08 * VAR24 + \n CONST263 * VAR04 + CONST263 * VAR22) + CONST004 * VAR15 * (CONST076 *\n VAR06 + CONST076 * VAR24 + CONST106 * VAR08 * VAR26) + CONST006 *\n VAR13 * (CONST273 * VAR26 + CONST274 * VAR08) + CONST031 * VAR11 + \n CONST032 * VAR04 * VAR26 + CONST032 * VAR08 * VAR22 + CONST033 *\n VAR20 + CONST040 * VAR06 * VAR24 + CONST070 * VAR02)\n g_z += g_0 * (CONST132 * VAR07 * VAR23 + CONST175 * VAR05 * VAR25 + \n CONST234 * VAR03 * z - CONST234 * VAR21 * x) + g_1 * y * (-CONST065 *\n VAR05 * VAR26 + CONST149 * VAR07 * VAR24 - CONST183 * VAR22 * x + \n CONST271 * VAR03) + g_10 * (CONST000 * VAR02 + CONST002 * VAR26 * (\n CONST100 * VAR04 + CONST115 * VAR08 * VAR15 + CONST231 * VAR13 + \n CONST235 * VAR06 * VAR17) + CONST004 * VAR24 * (CONST008 * VAR06 + \n CONST086 * VAR15 + CONST236 * VAR08 * VAR17) + CONST006 * VAR22 * (\n CONST005 * VAR08 + CONST282 * VAR17) + CONST015 * VAR20 + CONST027 *\n VAR11 + CONST086 * VAR06 * VAR15 + CONST232 * VAR08 * VAR13 + \n CONST282 * VAR04 * VAR17) + g_11 * (CONST161 * VAR14 * VAR25 - \n CONST250 * VAR12 * z + VAR16 * (CONST123 * VAR08 * VAR25 - CONST165 *\n VAR23 + CONST218 * VAR06 * z) + y * (CONST038 * VAR04 * z + \n CONST238 * VAR08 * VAR23 + CONST255 * VAR21)) + g_12 * (CONST002 *\n VAR26 * (CONST097 * VAR04 - CONST201 * VAR08 * VAR15 + CONST219 *\n VAR06 * VAR17 - CONST267 * VAR13) + CONST004 * VAR24 * (CONST233 *\n VAR15 + CONST283 * VAR08 * VAR17 - CONST301 * VAR06) + CONST107 *\n VAR17 * VAR22 - CONST187 * VAR06 * VAR15 + CONST216 * VAR08 * VAR13 +\n CONST239 * VAR04 * VAR17 + CONST297 * VAR20 - CONST302 * VAR02\n ) + g_13 * (VAR14 * (CONST129 * VAR08 * z - CONST195 * VAR25) + \n VAR16 * (CONST166 * VAR06 * z + CONST177 * VAR23 - CONST222 * VAR08 *\n VAR25) + y * (CONST188 * VAR06 * VAR25 + CONST210 * VAR08 * VAR23 +\n CONST260 * VAR04 * z - CONST260 * VAR21)) + g_14 * (CONST007 *\n VAR02 + CONST189 * VAR20 + CONST256 * VAR06 * VAR24 + CONST269 *\n VAR08 * VAR22 + VAR15 * (CONST114 * VAR06 + CONST114 * VAR24 + \n CONST168 * VAR08 * VAR26) + VAR17 * (CONST061 * VAR08 * VAR24 + \n CONST133 * VAR06 * VAR26 + CONST213 * VAR22 + CONST226 * VAR04)\n ) + g_15 * (VAR16 * (-CONST068 * VAR06 * z + CONST099 * VAR08 *\n VAR25 + CONST103 * VAR23) + y * (-CONST147 * VAR08 * VAR23 + \n CONST205 * VAR04 * z + CONST265 * VAR21)) + g_16 * (CONST074 *\n VAR02 + CONST090 * VAR08 * VAR22 + CONST244 * VAR04 * VAR26 + \n CONST251 * VAR06 * VAR24 + CONST295 * VAR20 + VAR17 * (CONST078 *\n VAR22 - CONST142 * VAR06 * VAR26 + CONST142 * VAR08 * VAR24 + \n CONST228 * VAR04)) + g_17 * y * (CONST065 * VAR08 * VAR23 - \n CONST149 * VAR06 * VAR25 + CONST183 * VAR04 * z - CONST271 * VAR21\n ) + g_18 * (CONST021 * VAR02 + CONST022 * VAR20 + CONST179 * VAR08 *\n VAR22 + CONST180 * VAR04 * VAR26 + CONST204 * VAR06 * VAR24) + g_2 * (\n CONST275 * VAR03 * z + VAR05 * (CONST052 * VAR25 - CONST134 * VAR17 *\n z) + VAR07 * (-CONST214 * VAR23 + CONST227 * VAR17 * VAR25) + x * (\n -CONST134 * VAR17 * VAR23 + CONST266 * VAR21)) + g_3 * (VAR16 * (\n CONST099 * VAR07 * VAR26 - CONST205 * VAR05 + CONST241 * VAR24 * x) +\n y * (CONST116 * VAR05 * VAR26 - CONST163 * VAR07 * VAR24 + CONST190 *\n VAR22 * x + CONST272 * VAR03)) + g_4 * (CONST042 * VAR21 * x + \n CONST269 * VAR05 * VAR25 + CONST294 * VAR03 * z + VAR15 * (CONST053 *\n VAR07 * z + CONST261 * VAR25 * x) + VAR17 * (CONST121 * VAR23 * x +\n CONST145 * VAR05 * z + CONST154 * VAR07 * VAR25)) + g_5 * (VAR14 *\n (-CONST130 * VAR26 * x + CONST195 * VAR07) + VAR16 * (CONST112 *\n VAR05 + CONST222 * VAR24 * x) + y * (CONST091 * VAR07 * VAR24 + \n CONST105 * VAR22 * x + CONST242 * VAR05 * VAR26 + CONST285 * VAR03)\n ) + g_6 * (VAR05 * (CONST057 * VAR17 * z + CONST290 * VAR25) + \n VAR07 * (-CONST143 * VAR17 * VAR25 + CONST172 * VAR15 * z + \n CONST276 * VAR23) + x * (-CONST155 * VAR17 * VAR23 - CONST184 *\n VAR13 * z + CONST217 * VAR15 * VAR25 + CONST288 * VAR21)) + g_7 * (\n CONST292 * VAR03 * y + VAR05 * (-CONST218 * VAR16 + CONST221 *\n VAR26 * y) + VAR07 * (CONST192 * VAR14 + CONST196 * VAR24 * y + \n CONST223 * VAR16 * VAR26) + x * (CONST124 * VAR14 * VAR26 + \n CONST191 * VAR16 * VAR24 + CONST229 * VAR22 * y - CONST250 * VAR12)\n ) + g_8 * (CONST011 * VAR03 * z + VAR05 * (CONST028 * VAR25 + \n CONST202 * VAR17 * z) + VAR07 * (CONST028 * VAR23 + CONST157 *\n VAR15 * z + CONST173 * VAR17 * VAR25) + x * (CONST011 * VAR21 + \n CONST156 * VAR15 * VAR25 + CONST199 * VAR13 * z + CONST202 * VAR17 *\n VAR23)) + g_9 * (CONST246 * VAR12 * z + VAR14 * (CONST141 * VAR08 *\n z + CONST141 * VAR25) + VAR16 * (CONST131 * VAR08 * VAR25 + \n CONST178 * VAR06 * z + CONST178 * VAR23) + y * (CONST046 * VAR04 *\n z + CONST046 * VAR21 + CONST087 * VAR08 * VAR23 + CONST088 * VAR06 *\n VAR25))\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_9.py" }, { "uuid": "16125124-4587-4526-acdf-7107ff2c9612", "file_name": "FleetAttention_triton.py", "repo_name": "Computational-Machine-Intelligence/LeetDecoding", "file_path": "leetDecoding/methods/FleetAttention_triton.py", "commit_hash": "1b545c2f5bacc155255250d1f70ac9484744559a", "starcount": 0, "input": "@triton.jit\ndef FleetAttention_with_decay_kernel(B_ptr, C_ptr, V_ptr, gamma_ptr,\n ans_ptr, heads: tl.constexpr, seqlen: tl.constexpr, dim: tl.constexpr,\n rank: tl.constexpr, stride_vbh: tl.constexpr, stride_bbh: tl.constexpr,\n dim_BLOCK: tl.constexpr):\n rank_idx = tl.program_id(axis=0)\n bz = tl.program_id(axis=1)\n dim_block_idx = tl.program_id(axis=2)\n off_b = tl.arange(0, 1)\n off_dim = tl.arange(0, dim_BLOCK)\n off_gamma = tl.full((1,), bz % heads, dtype=tl.int32)\n cv = tl.zeros([1, dim_BLOCK], dtype=tl.float32)\n o = tl.zeros([1, dim_BLOCK], dtype=tl.float32)\n gamma = tl.load(gamma_ptr + off_gamma, mask=off_gamma < heads, other=0)\n for seq_idx in range(seqlen):\n offs_bc = bz * stride_bbh + seq_idx * rank + rank_idx + off_b[None, :]\n offs_v = (bz * stride_vbh + seq_idx * dim + dim_block_idx *\n dim_BLOCK + off_dim[None, :])\n ans_ptrs = (ans_ptr + bz * stride_vbh + seq_idx * dim + \n dim_block_idx * dim_BLOCK + off_dim[None, :])\n v_ptrs = V_ptr + offs_v\n b_ptr = B_ptr + offs_bc\n c_ptr = C_ptr + offs_bc\n b = tl.load(b_ptr, mask=off_b[None, :] < 1, other=0)\n c = tl.load(c_ptr, mask=off_b[None, :] < 1, other=0)\n v = tl.load(v_ptrs, mask=off_dim[None, :] < dim, other=0)\n cv = c * v + cv * gamma\n o = b * cv\n ans = tl.load(ans_ptrs, mask=off_dim[None, :] < dim, other=0)\n tl.store(ans_ptrs, ans + o, mask=off_dim[None, :] < dim)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Computational-Machine-Intelligence/LeetDecoding/blob/1b545c2f5bacc155255250d1f70ac9484744559a/leetDecoding/methods/FleetAttention_triton.py" }, { "uuid": "9b808ef9-4ee5-48d1-af63-3b5d5a3d4067", "file_name": "attn_qk_int8_per_block_h64.py", "repo_name": "rodjjo/editorium", "file_path": "editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_h64.py", "commit_hash": "7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd(Q, K, V, Q_scale, K_scale, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, Z, H, N_CTX, HEAD_DIM: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, STAGE: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n off_z = off_hz // H\n off_h = off_hz % H\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n vk_offset = qvk_offset // stride_qm\n q_scale_offset = off_hz * tl.cdiv(N_CTX, BLOCK_M)\n k_scale_offset = off_hz * tl.cdiv(N_CTX, BLOCK_N)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_k = tl.arange(0, HEAD_DIM)\n Q_ptrs = Q + qvk_offset + offs_m[:, None] * stride_qm + offs_k[None, :\n ] * stride_qk\n Q_scale_ptr = Q_scale + q_scale_offset + start_m\n K_ptrs = K + qvk_offset + offs_k[:, None] + offs_n[None, :] * stride_kn\n K_scale_ptr = K_scale + k_scale_offset\n V_ptrs = V + qvk_offset + offs_n[:, None] * stride_qm + offs_k[None, :\n ] * stride_qk\n O_block_ptr = Out + qvk_offset + offs_m[:, None] * stride_qm + offs_k[\n None, :] * stride_qk\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, HEAD_DIM], dtype=tl.float32)\n q = tl.load(Q_ptrs, mask=offs_m[:, None] < N_CTX)\n q_scale = tl.load(Q_scale_ptr)\n acc, l_i = _attn_fwd_inner(acc, l_i, m_i, q, q_scale, K_ptrs,\n K_scale_ptr, V_ptrs, start_m, BLOCK_M, HEAD_DIM, BLOCK_N, 4 - STAGE,\n offs_m, offs_n, N_CTX)\n acc = acc / l_i[:, None]\n tl.store(O_block_ptr, acc.to(Out.type.element_ty), mask=offs_m[:, None] <\n N_CTX)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/rodjjo/editorium/blob/7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694/editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_h64.py" }, { "uuid": "2a6747c9-0f4a-4d02-8dbd-aa17a83f609c", "file_name": "layernorm.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/layernorm.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef layernorm_backward(dY, dY_row_stride, X, X_row_stride, W, b, r, mu,\n n_cols, eps, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n dY += row_idx * dY_row_stride\n X += row_idx * X_row_stride\n r += row_idx\n mu += row_idx\n dY_row = tl.load(dY + col_offsets, mask=mask, other=0).to(tl.float32)\n X_row = tl.load(X + col_offsets, mask=mask, other=0).to(tl.float32)\n W_row = tl.load(W + col_offsets, mask=mask, other=0).to(tl.float32)\n b_row = tl.load(b + col_offsets, mask=mask, other=0).to(tl.float32)\n inv_var = tl.load(r).to(tl.float32)\n mean = tl.load(mu).to(tl.float32)\n normed = (X_row - mean) * inv_var\n dY_W = dY_row * W_row\n dX_row = dY_W - tl.sum(dY_W, axis=0) / n_cols - normed * tl.sum(dY_W *\n normed, axis=0) / n_cols\n dX_row = dX_row * inv_var\n tl.store(dY + col_offsets, dX_row, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/layernorm.py" }, { "uuid": "c2355f8d-2629-4b64-9d2f-7bb6c69f238d", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef store_full_1d(vals, ptr, sz: tl.constexpr, stride=1):\n \"\"\"Store 1d block into vector (defined by ptr)\"\"\"\n offs = get_1d_offest(sz)\n mask = get_1d_mask(offs, sz)\n tl.store(ptr + offs, vals, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "ef1a3b80-243d-4b09-9484-b0a123fda695", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_NON_REDUCE_DIM': b_nr,\n 'BLOCK_SIZE_REDUCE_DIM': b_r}, num_warps=w) for b_nr, b_r, w in\n itertools.product([2, 4, 8, 16], [2, 4, 8, 16], [2, 4, 8])], key=['M', 'N']\n )\n@triton.jit\ndef triton_sum_kernel_1D_result_sum_then_buffer(input_ptr, output_ptr, M, N,\n BLOCK_SIZE_NON_REDUCE_DIM: tl.constexpr, BLOCK_SIZE_REDUCE_DIM: tl.\n constexpr, dim: tl.constexpr):\n \"\"\"\n Sum blocks of input using Triton and store in buffer\n \"\"\"\n pid = tl.program_id(axis=0)\n reduce_dim_len = M if dim == 0 else N\n non_reduce_dim_len = N if dim == 0 else M\n buffer = tl.zeros((1, BLOCK_SIZE_NON_REDUCE_DIM), dtype=tl.float32)\n block_start_non_reduce_dim = pid * BLOCK_SIZE_NON_REDUCE_DIM\n offsets_non_reduce_dim = block_start_non_reduce_dim + tl.arange(0,\n BLOCK_SIZE_NON_REDUCE_DIM)\n mask_non_reduce_dim = offsets_non_reduce_dim < non_reduce_dim_len\n for block_start_reduce_dim in range(0, reduce_dim_len,\n BLOCK_SIZE_REDUCE_DIM):\n offsets_reduce_dim = block_start_reduce_dim + tl.arange(0,\n BLOCK_SIZE_REDUCE_DIM)\n mask_reduce_dim = offsets_reduce_dim < reduce_dim_len\n idxs, mask = None, None\n if dim == 0:\n idxs = offsets_reduce_dim[:, None\n ] * non_reduce_dim_len + offsets_non_reduce_dim\n mask = mask_reduce_dim[:, None] & mask_non_reduce_dim\n elif dim == 1:\n idxs = offsets_non_reduce_dim[:, None\n ] * reduce_dim_len + offsets_reduce_dim\n mask = mask_non_reduce_dim[:, None] & mask_reduce_dim\n input = tl.load(input_ptr + idxs, mask=mask, other=mask)\n buffer += tl.sum(input, axis=dim)\n buffer_view = buffer.reshape((BLOCK_SIZE_NON_REDUCE_DIM,))\n tl.store(output_ptr + offsets_non_reduce_dim, buffer_view, mask=\n mask_non_reduce_dim)\n", "category": { "Functionality": [ "Elementwise Operations", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/sum/kernels.py" }, { "uuid": "377b8e8a-7e71-4aa1-89e1-79323130a64c", "file_name": "test_autodiff.py", "repo_name": "srush/triton-autodiff", "file_path": "tests/test_autodiff.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef ub2(X, Y):\n r = tl.arange(0, 16)\n r2 = tl.arange(0, 32)\n x = tl.load(X + 16 * r2[:, None] + r)\n y = triton_unbroadcast(x, tl.arange(0, 32)[:, None].shape)\n tl.store(Y + r2[:, None], y)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/tests/test_autodiff.py" }, { "uuid": "bc5f4d34-0861-44b0-9b72-4824516d105b", "file_name": "causal_product.py", "repo_name": "calclavia/Triton-Transformer", "file_path": "ttx/attention/causal_product.py", "commit_hash": "d1d1e5b5651cf7959866b0198d90a665e1f45354", "starcount": 0, "input": "@triton.jit\ndef causal_product_kernel(q_ptr, k_ptr, v_ptr, output_ptr, batch, length,\n dim, vdim, **meta):\n BLOCK_SIZE = meta['BLOCK_SIZE']\n pid = tl.program_id(axis=0)\n state = tl.zeros((BLOCK_SIZE, BLOCK_SIZE), dtype=tl.float32)\n cur_qk_pos = pid * length * dim\n cur_v_pos = pid * length * vdim\n dim_ptrs = tl.arange(0, BLOCK_SIZE)\n qk_mask = dim_ptrs < dim\n v_mask = dim_ptrs < vdim\n for _ in range(0, length, 1):\n qk_row_offsets = cur_qk_pos + dim_ptrs\n v_row_offsets = cur_v_pos + dim_ptrs\n k = tl.load(k_ptr + qk_row_offsets, mask=qk_mask, other=0)\n v = tl.load(v_ptr + v_row_offsets, mask=v_mask, other=0)\n context = tl.dot(k[:, None], v[None, :])\n state += context\n q = tl.load(q_ptr + qk_row_offsets, mask=qk_mask, other=0)\n output = tl.dot(q[None, :], state)\n tl.store(output_ptr + v_row_offsets[None, :], output, mask=v_mask[\n None, :])\n cur_qk_pos += dim\n cur_v_pos += vdim\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/calclavia/Triton-Transformer/blob/d1d1e5b5651cf7959866b0198d90a665e1f45354/ttx/attention/causal_product.py" }, { "uuid": "2cccc53e-fdd8-4955-b9a0-e935a64f8577", "file_name": "bucketed_argmax.py", "repo_name": "graphcore-research/pytorch-approx-topk", "file_path": "approx_topk/experimental/bucketed_argmax.py", "commit_hash": "339eea971f17bf810e2eec746a06b9c93dc4cce0", "starcount": 0, "input": "@triton.jit\ndef _topk_triton_kernel__parallel_bkn(xs_ptr, values_out_ptr,\n indices_out_ptr, xs_stride: int, n_stride: int, b: int, k: int, n: int,\n BLOCK_BK: tl.constexpr, BLOCK_N: tl.constexpr, PAD_VALUE: tl.constexpr,\n INTERLEAVED: tl.constexpr):\n idx = tl.program_id(axis=0) * BLOCK_BK + tl.arange(0, BLOCK_BK)\n b_idx, k_idx = idx // k, idx % k\n if INTERLEAVED:\n k_stride, i_stride = 1, k\n else:\n k_stride, i_stride = n_stride, 1\n ni = tl.arange(0, BLOCK_N)\n n_idx = k_idx[:, None] * k_stride + ni[None, :] * i_stride\n data = tl.load(xs_ptr + b_idx[:, None] * xs_stride + n_idx, mask=(b_idx\n [:, None] < b) & (n_idx < n) & (ni < n_stride), other=PAD_VALUE)\n max_value, max_i = tl.max(data, axis=1, return_indices=True)\n max_index = k_idx * k_stride + max_i * i_stride\n tl.store(values_out_ptr + b_idx * k + k_idx, max_value, mask=b_idx < b)\n tl.store(indices_out_ptr + b_idx * k + k_idx, max_index, mask=b_idx < b)\n", "category": { "Functionality": [ "Top-K Selection" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Batch-Oriented" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/graphcore-research/pytorch-approx-topk/blob/339eea971f17bf810e2eec746a06b9c93dc4cce0/approx_topk/experimental/bucketed_argmax.py" }, { "uuid": "7924e701-dd48-4f1d-bf9f-b59ffeb4ff7a", "file_name": "ln_linear_triton.py", "repo_name": "ethansmith2000/fused-layer-norm", "file_path": "ln_linear_triton.py", "commit_hash": "84fe243a829364acdcfd7cd70b699db04838af0f", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_bwd_dx_fused(DX, DY, DSc, DSh, Y, Sc, Sh, Mean, Rstd, Lock,\n stride, N, GROUP_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr):\n row = tl.program_id(0)\n cols = tl.arange(0, BLOCK_SIZE_N)\n mask = cols < N\n Y += row * stride\n DY += row * stride\n DX += row * stride\n lock_id = row % GROUP_SIZE_M\n Lock += lock_id\n Count = Lock + GROUP_SIZE_M\n DSc = DSc + lock_id * N + cols\n DSh = DSh + lock_id * N + cols\n y = tl.load(Y + cols, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + cols, mask=mask, other=0).to(tl.float32)\n sc = tl.load(Sc + cols, mask=mask).to(tl.float32)\n sh = tl.load(Sh + cols, mask=mask).to(tl.float32)\n rstd = tl.load(Rstd + row)\n xhat = (y - sh) / sc\n scdy = sc * dy\n xhat = tl.where(mask, xhat, 0.0)\n scdy = tl.where(mask, scdy, 0.0)\n c1 = tl.sum(xhat * scdy, axis=0) / N\n c2 = tl.sum(scdy, axis=0) / N\n dx = (scdy - (xhat * c1 + c2)) * rstd\n tl.store(DX + cols, dx, mask=mask)\n partial_dsc = (dy * xhat).to(sc.dtype)\n partial_dsh = dy.to(sc.dtype)\n while tl.atomic_cas(Lock, 0, 1) == 1:\n pass\n count = tl.load(Count)\n if count == 0:\n tl.atomic_xchg(Count, 1)\n else:\n partial_dsc += tl.load(DSc, mask=mask)\n partial_dsh += tl.load(DSh, mask=mask)\n tl.store(DSc, partial_dsc, mask=mask)\n tl.store(DSh, partial_dsh, mask=mask)\n tl.atomic_xchg(Lock, 0)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ethansmith2000/fused-layer-norm/blob/84fe243a829364acdcfd7cd70b699db04838af0f/ln_linear_triton.py" }, { "uuid": "62aa8411-9a66-4488-be2f-bd3fdaec1510", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BV', 'BT'])\n@triton.jit\ndef chunk_gla_bwd_kernel_dA(v, do, dA, offsets, indices, scale, T: tl.\n constexpr, H: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BV: tl.\n constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n b_dA = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (V, T), (1, V), (i_v *\n BV, i_t * BT), (BV, BT), (0, 1))\n else:\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (V, T), (1, H *\n V), (i_v * BV, i_t * BT), (BV, BT), (0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dA += tl.dot(b_do, b_v)\n if HEAD_FIRST:\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_dA = tl.make_block_ptr(dA + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n m_s = tl.arange(0, BT)[:, None] >= tl.arange(0, BT)[None, :]\n b_dA = tl.where(m_s, b_dA * scale, 0.0)\n tl.store(p_dA, b_dA.to(p_dA.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "7f214f7f-42e1-4445-be83-9e13d10d6055", "file_name": "fused_kl_div.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_kl_div.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef kl_div_kernel(logits, target_logits, loss, s_logits, s_loss, reduction:\n tl.constexpr, N: tl.constexpr, V: tl.constexpr, BV: tl.constexpr):\n i_n = tl.program_id(0).to(tl.int64)\n logits += i_n * s_logits\n target_logits += i_n * s_logits\n sm, tm = float('-inf'), float('-inf')\n sd, td = 0.0, 0.0\n NV = tl.cdiv(V, BV)\n for iv in range(0, NV):\n o_x = iv * BV + tl.arange(0, BV)\n b_sl = tl.load(logits + o_x, mask=o_x < V, other=float('-inf'))\n b_sm = tl.max(b_sl)\n m_new = tl.maximum(sm, b_sm)\n sd = sd * tl.exp(sm - m_new) + tl.sum(tl.exp(b_sl - m_new))\n sm = m_new\n b_tl = tl.load(target_logits + o_x, mask=o_x < V, other=float('-inf'))\n b_tm = tl.max(b_tl)\n m_new = tl.maximum(tm, b_tm)\n td = td * tl.exp(tm - m_new) + tl.sum(tl.exp(b_tl - m_new))\n tm = m_new\n b_loss = 0.0\n for iv in range(0, NV):\n o_x = iv * BV + tl.arange(0, BV)\n b_sl = tl.load(logits + o_x, mask=o_x < V, other=float('-inf'))\n b_tl = tl.load(target_logits + o_x, mask=o_x < V, other=float('-inf'))\n b_sp_log = b_sl - sm - tl.log(sd)\n b_tp_log = b_tl - tm - tl.log(td)\n b_sp = tl.exp(b_sp_log)\n b_tp = tl.exp(b_tp_log)\n b_kl = tl.where(o_x < V, b_tp * (b_tp_log - b_sp_log), 0)\n b_dl = -b_tp + b_sp\n b_loss += tl.sum(b_kl)\n if reduction == 'batchmean':\n b_dl = b_dl / N\n tl.store(logits + o_x, b_dl, mask=o_x < V)\n if reduction == 'batchmean':\n b_loss = b_loss / N\n tl.store(loss + i_n * s_loss, b_loss)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_kl_div.py" }, { "uuid": "b8cbf987-fa5e-4eb6-a8ce-1e45c7cfcc13", "file_name": "layer_norm.py", "repo_name": "jiweibo/MMA", "file_path": "bench/layer_norm.py", "commit_hash": "f8df6f8e3e9095110b651c31b081e39b2713a7c9", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_fwd_fused(Out, A, Weight, Bias, Mean, Rstd, stride, N, eps,\n BLOCK_SIZE: tl.constexpr):\n row = tl.program_id(0)\n Out += row * stride\n A += row * stride\n mean = 0\n _mean = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n a = tl.load(A + cols, mask=cols < N, other=0.0, eviction_policy=\n 'evict_last').to(tl.float32)\n _mean += a\n mean = tl.sum(_mean, axis=0) / N\n _var = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n a = tl.load(A + cols, mask=cols < N, other=0.0, eviction_policy=\n 'evict_last').to(tl.float32)\n a = tl.where(cols < N, a - mean, 0.0)\n _var += a * a\n var = tl.sum(_var, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n tl.store(Mean + row, mean)\n tl.store(Rstd + row, rstd)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n weight = tl.load(Weight + cols, mask=mask)\n bias = tl.load(Bias + cols, mask=mask)\n a = tl.load(A + cols, mask=mask, other=0.0, eviction_policy=\n 'evict_first').to(tl.float32)\n a_hat = (a - mean) * rstd\n out = a_hat * weight + bias\n tl.store(Out + cols, out, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/jiweibo/MMA/blob/f8df6f8e3e9095110b651c31b081e39b2713a7c9/bench/layer_norm.py" }, { "uuid": "ecdab7b6-1233-4dcc-807a-beba3c0d7bbb", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_simple_gla_bwd_kernel_dq(i_bh, i_t, i_k, i_v, i_kv, q, k, v, g,\n do, dq, dg, s_k_h, s_k_t, s_v_h, s_v_t, scale, B: tl.constexpr, H: tl.\n constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.\n constexpr, BS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n for i_s in range(0, i_t * BT, BS):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_s,\n i_k * BK), (BS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (1, s_v_t), (i_v *\n BV, i_s), (BV, BS), (0, 1))\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_s,), (BS,), (0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_gn = tl.load(g + i_bh * T + min(i_s + BS, T) - 1)\n b_gp = tl.load(g + i_bh * T + i_s - 1) if i_s % BT > 0 else 0.0\n b_ds = tl.dot(b_do, b_v, allow_tf32=False) * tl.exp(b_gn - b_g)[None, :\n ]\n if i_s > 0:\n b_dq *= tl.exp(b_gn - b_gp)\n b_dq += tl.dot(b_ds.to(b_v.dtype), b_k, allow_tf32=False)\n p_gq = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,), (0,)\n )\n b_gq = tl.load(p_gq, boundary_check=(0,))\n b_dq *= tl.exp(b_gq)[:, None] * scale\n o_q = i_t * BT + tl.arange(0, BT)\n o_k = i_t * BT + tl.arange(0, BS)\n for i_s in range(i_t * BT, min((i_t + 1) * BT, T), BS):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_s,\n i_k * BK), (BS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (1, s_v_t), (i_v *\n BV, i_s), (BV, BS), (0, 1))\n p_gk = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_s,), (BS,), (0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0,))\n m_s = o_q[:, None] >= o_k[None, :]\n b_ds = tl.where(m_s, tl.dot(b_do, b_v, allow_tf32=False) * tl.exp(\n b_gq[:, None] - b_gk[None, :]), 0) * scale\n b_dq += tl.dot(b_ds.to(b_k.dtype), b_k, allow_tf32=False)\n o_k += BS\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + (i_v * B * H + i_bh) * s_k_h, (T, K), (\n s_k_t, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + (i_kv * B * H + i_bh) * T, (T,), (1,), (\n i_t * BT,), (BT,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_dg = tl.sum(b_dq * b_q, 1)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/parallel.py" }, { "uuid": "d1e0e5b8-b819-414f-9789-a449f97c5c56", "file_name": "kernels.py", "repo_name": "ShenzheZhu/sparse_autoencoder", "file_path": "sparse_autoencoder/kernels.py", "commit_hash": "afef049c905fda5b0f69729127ce0d3a42399152", "starcount": 0, "input": "@triton.jit\ndef triton_add_mul_kernel(x_ptr, a_ptr, b_ptr, c, stride_x0, stride_x1,\n stride_a0, stride_a1, stride_b0, stride_b1, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, M: tl.constexpr, N: tl.constexpr):\n pid_m = tl.program_id(0)\n pid_n = tl.program_id(1)\n offsets_m = tl.arange(0, BLOCK_SIZE_M) + pid_m * BLOCK_SIZE_M\n offsets_n = tl.arange(0, BLOCK_SIZE_N) + pid_n * BLOCK_SIZE_N\n x = tl.load(x_ptr + offsets_m[:, None] * stride_x0 + offsets_n[None, :] *\n stride_x1, mask=(offsets_m[:, None] < M) & (offsets_n[None, :] < N))\n a = tl.load(a_ptr + offsets_m[:, None] * stride_a0 + offsets_n[None, :] *\n stride_a1, mask=(offsets_m[:, None] < M) & (offsets_n[None, :] < N))\n b = tl.load(b_ptr + offsets_m[:, None] * stride_b0 + offsets_n[None, :] *\n stride_b1, mask=(offsets_m[:, None] < M) & (offsets_n[None, :] < N))\n x_dtype = x.dtype\n x = (x.to(tl.float32) + a.to(tl.float32) * b.to(tl.float32) * c).to(x_dtype\n )\n tl.store(x_ptr + offsets_m[:, None] * stride_x0 + offsets_n[None, :] *\n stride_x1, x, mask=(offsets_m[:, None] < M) & (offsets_n[None, :] < N))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ShenzheZhu/sparse_autoencoder/blob/afef049c905fda5b0f69729127ce0d3a42399152/sparse_autoencoder/kernels.py" }, { "uuid": "f8a04198-8560-4bd6-84b9-8bb4719d3310", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef dense_jagged_cat_jagged_out_kernel(a_ptr, b_ptr, c_ptr, b_offsets_ptr,\n c_offsets_ptr, max_seq_len, BLOCK_SIZE: tl.constexpr):\n pid_batch = tl.program_id(0)\n b_start = tl.load(b_offsets_ptr + pid_batch)\n b_end = tl.load(b_offsets_ptr + pid_batch + 1)\n c_start = b_start + pid_batch\n N = b_end - b_start\n N = tl.minimum(N, max_seq_len)\n a = tl.load(a_ptr + pid_batch)\n tl.store(c_ptr + c_start, a)\n offs_k = tl.arange(0, BLOCK_SIZE)\n for k in range(0, N, BLOCK_SIZE):\n b_offset = k + offs_k\n b_ptrs = b_ptr + b_start + b_offset\n b = tl.load(b_ptrs, mask=b_offset < N, other=0.0)\n tl.store(c_ptr + c_start + 1 + b_offset, b, mask=b_offset < N)\n tl.store(c_offsets_ptr + pid_batch, b_start + pid_batch)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "9c3d59d9-a8a8-42ff-a0c4-03f9a9c1683a", "file_name": "test_autodiff.py", "repo_name": "srush/triton-autodiff", "file_path": "tests/test_autodiff.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef tr1(X, Y):\n r = tl.arange(0, 16)\n x = tl.load(X + r)\n y = comp2tt(x)\n tl.store(Y + 16 * r[:, None] + r, y)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/tests/test_autodiff.py" }, { "uuid": "bf9fed28-eaf5-46e1-8969-eec1c9a5c2f7", "file_name": "06-fused-attention.py", "repo_name": "2lambda123/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "09e27725b89043a07f49c440db6a9aedcfba8432", "starcount": 0, "input": "@triton.jit\ndef max_fn(x, y):\n return tl.math.max(x, y)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/2lambda123/triton/blob/09e27725b89043a07f49c440db6a9aedcfba8432/python/tutorials/06-fused-attention.py" }, { "uuid": "313cbd67-cc75-4672-a355-e8c80754facc", "file_name": "ops.py", "repo_name": "shawntan/scattermoe", "file_path": "scattermoe/kernels/ops.py", "commit_hash": "63b76a2f5f28c052fb4cd7c34479a54158354052", "starcount": 0, "input": "@triton.autotune(configs=_config_grouping(), key=['K'])\n@triton.heuristics({'NO_K_MASK': lambda args: args['K'] % args['BLOCK_K'] == 0}\n )\n@triton.jit\ndef _group(src_ptr, stride_sn, stride_sk, has_coeff: tl.constexpr,\n coeff_ptr, FAN_OUT: tl.constexpr, tgt_ptr, stride_tn, stride_ti,\n grouped_idx_ptr, N, K: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl\n .constexpr, NO_K_MASK: tl.constexpr):\n pid = tl.program_id(axis=0)\n N_block_id = pid\n N_blk = N_block_id * BLOCK_N + tl.arange(0, BLOCK_N)\n N_mask = N_blk < N\n N_blk = tl.max_contiguous(tl.multiple_of(N_blk % N, BLOCK_N), BLOCK_N)\n N_idx = tl.load(grouped_idx_ptr + N_blk, mask=N_mask, other=0)\n K_blk = tl.arange(0, BLOCK_K)\n src_blk_ptrs = src_ptr + (N_idx // FAN_OUT)[:, None] * stride_sn + K_blk[\n None, :] * stride_sk\n tgt_blk_ptrs = tgt_ptr + N_blk[:, None] * stride_tn + K_blk[None, :\n ] * stride_ti\n if has_coeff:\n c = tl.load(coeff_ptr + N_idx, mask=N_mask)[:, None]\n iters = tl.cdiv(K, BLOCK_K)\n for i in range(0, iters):\n if NO_K_MASK or i < iters - 1:\n block = tl.load(src_blk_ptrs, mask=N_mask[:, None])\n if has_coeff:\n block *= c\n tl.store(tgt_blk_ptrs, block, mask=N_mask[:, None])\n else:\n K_mask = i * BLOCK_K + K_blk < K\n mask = N_mask[:, None] & K_mask[None, :]\n block = tl.load(src_blk_ptrs, mask=mask)\n if has_coeff:\n block *= c\n tl.store(tgt_blk_ptrs, block, mask=mask)\n src_blk_ptrs += BLOCK_K * stride_sk\n tgt_blk_ptrs += BLOCK_K * stride_ti\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/scattermoe/blob/63b76a2f5f28c052fb4cd7c34479a54158354052/scattermoe/kernels/ops.py" }, { "uuid": "e9ec4ca4-67b0-4b4c-ae46-1b511c456193", "file_name": "_semi_structured_conversions.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/_semi_structured_conversions.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.autotune(configs=get_configs(), key=['m', 'k'])\n@triton.jit\ndef _sparse_semi_structured_from_dense_triton_8(dense_ptr, sparse_ptr,\n meta_reordered_ptr, mask_ptr, dense_row_stride, sparse_row_stride,\n mask_row_stride, dense_col_stride, sparse_col_stride, mask_col_stride,\n m, k, seed, BLOCK_SIZE: tl.constexpr, PRUNE: tl.constexpr, ARRAY_LAYOUT:\n tl.constexpr):\n if ARRAY_LAYOUT == 'row':\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1) * 32 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 32\n mask = col_idx < k\n elif ARRAY_LAYOUT == 'col':\n row_idx = tl.arange(0, BLOCK_SIZE) + tl.program_id(0) * BLOCK_SIZE\n col_idx = tl.program_id(1) * 32\n mask = row_idx < m\n dense_40 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 0) * dense_col_stride, mask=mask)\n dense_41 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 1) * dense_col_stride, mask=mask)\n dense_42 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 2) * dense_col_stride, mask=mask)\n dense_43 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 3) * dense_col_stride, mask=mask)\n dense_44 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 4) * dense_col_stride, mask=mask)\n dense_45 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 5) * dense_col_stride, mask=mask)\n dense_46 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 6) * dense_col_stride, mask=mask)\n dense_47 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 7) * dense_col_stride, mask=mask)\n dense_48 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 8) * dense_col_stride, mask=mask)\n dense_49 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 9) * dense_col_stride, mask=mask)\n dense_4A = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 10) * dense_col_stride, mask=mask)\n dense_4B = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 11) * dense_col_stride, mask=mask)\n dense_4C = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 12) * dense_col_stride, mask=mask)\n dense_4D = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 13) * dense_col_stride, mask=mask)\n dense_4E = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 14) * dense_col_stride, mask=mask)\n dense_4F = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 15) * dense_col_stride, mask=mask)\n dense_4G = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 16) * dense_col_stride, mask=mask)\n dense_4H = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 17) * dense_col_stride, mask=mask)\n dense_4I = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 18) * dense_col_stride, mask=mask)\n dense_4J = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 19) * dense_col_stride, mask=mask)\n dense_4K = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 20) * dense_col_stride, mask=mask)\n dense_4L = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 21) * dense_col_stride, mask=mask)\n dense_4M = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 22) * dense_col_stride, mask=mask)\n dense_4N = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 23) * dense_col_stride, mask=mask)\n dense_4O = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 24) * dense_col_stride, mask=mask)\n dense_4P = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 25) * dense_col_stride, mask=mask)\n dense_4Q = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 26) * dense_col_stride, mask=mask)\n dense_4R = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 27) * dense_col_stride, mask=mask)\n dense_4S = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 28) * dense_col_stride, mask=mask)\n dense_4T = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 29) * dense_col_stride, mask=mask)\n dense_4U = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 30) * dense_col_stride, mask=mask)\n dense_4V = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 31) * dense_col_stride, mask=mask)\n if PRUNE == 'mse':\n (_dense_40, _dense_41, _dense_42, _dense_43, _dense_44, _dense_45,\n _dense_46, _dense_47, _dense_48, _dense_49, _dense_4A,\n _dense_4B, _dense_4C, _dense_4D, _dense_4E, _dense_4F) = (\n dense_40, dense_41, dense_42, dense_43, dense_44, dense_45,\n dense_46, dense_47, dense_48, dense_49, dense_4A, dense_4B,\n dense_4C, dense_4D, dense_4E, dense_4F)\n (_dense_4G, _dense_4H, _dense_4I, _dense_4J, _dense_4K, _dense_4L,\n _dense_4M, _dense_4N, _dense_4O, _dense_4P, _dense_4Q,\n _dense_4R, _dense_4S, _dense_4T, _dense_4U, _dense_4V) = (\n dense_4G, dense_4H, dense_4I, dense_4J, dense_4K, dense_4L,\n dense_4M, dense_4N, dense_4O, dense_4P, dense_4Q, dense_4R,\n dense_4S, dense_4T, dense_4U, dense_4V)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_40) > tl.abs(_dense_41), tl.abs(\n _dense_40) > tl.abs(_dense_42), tl.abs(_dense_40) > tl.abs(\n _dense_43), tl.abs(_dense_41) > tl.abs(_dense_42), tl.abs(_dense_41\n ) > tl.abs(_dense_43), tl.abs(_dense_42) > tl.abs(_dense_43)\n m0, m1, m2, m3 = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_44) > tl.abs(_dense_45), tl.abs(\n _dense_44) > tl.abs(_dense_46), tl.abs(_dense_44) > tl.abs(\n _dense_47), tl.abs(_dense_45) > tl.abs(_dense_46), tl.abs(_dense_45\n ) > tl.abs(_dense_47), tl.abs(_dense_46) > tl.abs(_dense_47)\n m4, m5, m6, m7 = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_48) > tl.abs(_dense_49), tl.abs(\n _dense_48) > tl.abs(_dense_4A), tl.abs(_dense_48) > tl.abs(\n _dense_4B), tl.abs(_dense_49) > tl.abs(_dense_4A), tl.abs(_dense_49\n ) > tl.abs(_dense_4B), tl.abs(_dense_4A) > tl.abs(_dense_4B)\n m8, m9, mA, mB = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_4C) > tl.abs(_dense_4D), tl.abs(\n _dense_4C) > tl.abs(_dense_4E), tl.abs(_dense_4C) > tl.abs(\n _dense_4F), tl.abs(_dense_4D) > tl.abs(_dense_4E), tl.abs(_dense_4D\n ) > tl.abs(_dense_4F), tl.abs(_dense_4E) > tl.abs(_dense_4F)\n mC, mD, mE, mF = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_4G) > tl.abs(_dense_4H), tl.abs(\n _dense_4G) > tl.abs(_dense_4I), tl.abs(_dense_4G) > tl.abs(\n _dense_4J), tl.abs(_dense_4H) > tl.abs(_dense_4I), tl.abs(_dense_4H\n ) > tl.abs(_dense_4J), tl.abs(_dense_4I) > tl.abs(_dense_4J)\n mG, mH, mI, mJ = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_4K) > tl.abs(_dense_4L), tl.abs(\n _dense_4K) > tl.abs(_dense_4M), tl.abs(_dense_4K) > tl.abs(\n _dense_4N), tl.abs(_dense_4L) > tl.abs(_dense_4M), tl.abs(_dense_4L\n ) > tl.abs(_dense_4N), tl.abs(_dense_4M) > tl.abs(_dense_4N)\n mK, mL, mM, mN = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_4O) > tl.abs(_dense_4P), tl.abs(\n _dense_4O) > tl.abs(_dense_4Q), tl.abs(_dense_4O) > tl.abs(\n _dense_4R), tl.abs(_dense_4P) > tl.abs(_dense_4Q), tl.abs(_dense_4P\n ) > tl.abs(_dense_4R), tl.abs(_dense_4Q) > tl.abs(_dense_4R)\n mO, mP, mQ, mR = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n x1, x2, x3, x4, x5, x6 = tl.abs(_dense_4S) > tl.abs(_dense_4T), tl.abs(\n _dense_4S) > tl.abs(_dense_4U), tl.abs(_dense_4S) > tl.abs(\n _dense_4V), tl.abs(_dense_4T) > tl.abs(_dense_4U), tl.abs(_dense_4T\n ) > tl.abs(_dense_4V), tl.abs(_dense_4U) > tl.abs(_dense_4V)\n mS, mT, mU, mV = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 |\n ~x1 & x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~\n x6 | ~x5 & ~x6)\n elif PRUNE == 'mask':\n m0 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 0) *\n mask_col_stride, mask=mask).to(tl.int1)\n m1 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 1) *\n mask_col_stride, mask=mask).to(tl.int1)\n m2 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 2) *\n mask_col_stride, mask=mask).to(tl.int1)\n m3 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 3) *\n mask_col_stride, mask=mask).to(tl.int1)\n m4 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 4) *\n mask_col_stride, mask=mask).to(tl.int1)\n m5 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 5) *\n mask_col_stride, mask=mask).to(tl.int1)\n m6 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 6) *\n mask_col_stride, mask=mask).to(tl.int1)\n m7 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 7) *\n mask_col_stride, mask=mask).to(tl.int1)\n m8 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 8) *\n mask_col_stride, mask=mask).to(tl.int1)\n m9 = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 9) *\n mask_col_stride, mask=mask).to(tl.int1)\n mA = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 10) *\n mask_col_stride, mask=mask).to(tl.int1)\n mB = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 11) *\n mask_col_stride, mask=mask).to(tl.int1)\n mC = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 12) *\n mask_col_stride, mask=mask).to(tl.int1)\n mD = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 13) *\n mask_col_stride, mask=mask).to(tl.int1)\n mE = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 14) *\n mask_col_stride, mask=mask).to(tl.int1)\n mF = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 15) *\n mask_col_stride, mask=mask).to(tl.int1)\n mG = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 16) *\n mask_col_stride, mask=mask).to(tl.int1)\n mH = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 17) *\n mask_col_stride, mask=mask).to(tl.int1)\n mI = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 18) *\n mask_col_stride, mask=mask).to(tl.int1)\n mJ = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 19) *\n mask_col_stride, mask=mask).to(tl.int1)\n mK = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 20) *\n mask_col_stride, mask=mask).to(tl.int1)\n mL = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 21) *\n mask_col_stride, mask=mask).to(tl.int1)\n mM = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 22) *\n mask_col_stride, mask=mask).to(tl.int1)\n mN = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 23) *\n mask_col_stride, mask=mask).to(tl.int1)\n mO = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 24) *\n mask_col_stride, mask=mask).to(tl.int1)\n mP = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 25) *\n mask_col_stride, mask=mask).to(tl.int1)\n mQ = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 26) *\n mask_col_stride, mask=mask).to(tl.int1)\n mR = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 27) *\n mask_col_stride, mask=mask).to(tl.int1)\n mS = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 28) *\n mask_col_stride, mask=mask).to(tl.int1)\n mT = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 29) *\n mask_col_stride, mask=mask).to(tl.int1)\n mU = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 30) *\n mask_col_stride, mask=mask).to(tl.int1)\n mV = tl.load(mask_ptr + row_idx * mask_row_stride + (col_idx + 31) *\n mask_col_stride, mask=mask).to(tl.int1)\n elif PRUNE == 'mvue':\n if ARRAY_LAYOUT == 'row':\n seed0 = seed + (tl.program_id(0) + tl.program_id(1) * m) * 2\n seed1 = seed + (tl.program_id(0) + tl.program_id(1) * m) * 2 + 1\n else:\n seed0 = seed + (tl.program_id(0) * k // 32 + tl.program_id(1)) * 2\n seed1 = seed + (tl.program_id(0) * k // 32 + tl.program_id(1)\n ) * 2 + 1\n random0, random1, random2, random3 = tl.rand4x(seed0, tl.arange(0,\n BLOCK_SIZE), n_rounds=5)\n random4, random5, random6, random7 = tl.rand4x(seed1, tl.arange(0,\n BLOCK_SIZE), n_rounds=5)\n dense_40, dense_41, dense_42, dense_43, m0, m1, m2, m3 = (\n _MVUE24_approx(dense_40, dense_41, dense_42, dense_43, random0,\n random1))\n dense_44, dense_45, dense_46, dense_47, m4, m5, m6, m7 = (\n _MVUE24_approx(dense_44, dense_45, dense_46, dense_47, random2,\n random3))\n dense_48, dense_49, dense_4A, dense_4B, m8, m9, mA, mB = (\n _MVUE24_approx(dense_48, dense_49, dense_4A, dense_4B, random4,\n random5))\n dense_4C, dense_4D, dense_4E, dense_4F, mC, mD, mE, mF = (\n _MVUE24_approx(dense_4C, dense_4D, dense_4E, dense_4F, random6,\n random7))\n else:\n m0 = dense_40 != 0\n m1 = dense_41 != 0\n m2 = dense_42 != 0\n m3 = dense_43 != 0\n m4 = dense_44 != 0\n m5 = dense_45 != 0\n m6 = dense_46 != 0\n m7 = dense_47 != 0\n m8 = dense_48 != 0\n m9 = dense_49 != 0\n mA = dense_4A != 0\n mB = dense_4B != 0\n mC = dense_4C != 0\n mD = dense_4D != 0\n mE = dense_4E != 0\n mF = dense_4F != 0\n mG = dense_4G != 0\n mH = dense_4H != 0\n mI = dense_4I != 0\n mJ = dense_4J != 0\n mK = dense_4K != 0\n mL = dense_4L != 0\n mM = dense_4M != 0\n mN = dense_4N != 0\n mO = dense_4O != 0\n mP = dense_4P != 0\n mQ = dense_4Q != 0\n mR = dense_4R != 0\n mS = dense_4S != 0\n mT = dense_4T != 0\n mU = dense_4U != 0\n mV = dense_4V != 0\n bit0 = ~m0 & m1\n bit1 = ~m0 & ~m1\n bit2 = bit1 | ~m2\n bit3 = bit0 | ~m1 | m2\n idxs0 = bit0 | bit1.to(tl.int64) << 1\n idxs1 = bit2 | bit3.to(tl.int64) << 1\n sparse0 = tl.where(bit1, tl.where(bit0, dense_43, dense_42), tl.where(\n bit0, dense_41, dense_40))\n sparse1 = tl.where(bit3, tl.where(bit2, dense_43, dense_42), tl.where(\n bit2, dense_41, dense_40))\n bit4 = ~m4 & m5\n bit5 = ~m4 & ~m5\n bit6 = bit5 | ~m6\n bit7 = bit4 | ~m5 | m6\n idxs2 = bit4 | bit5.to(tl.int64) << 1\n idxs3 = bit6 | bit7.to(tl.int64) << 1\n sparse2 = tl.where(bit5, tl.where(bit4, dense_47, dense_46), tl.where(\n bit4, dense_45, dense_44))\n sparse3 = tl.where(bit7, tl.where(bit6, dense_47, dense_46), tl.where(\n bit6, dense_45, dense_44))\n bit8 = ~m8 & m9\n bit9 = ~m8 & ~m9\n bitA = bit9 | ~mA\n bitB = bit8 | ~m9 | mA\n idxs4 = bit8 | bit9.to(tl.int64) << 1\n idxs5 = bitA | bitB.to(tl.int64) << 1\n sparse4 = tl.where(bit9, tl.where(bit8, dense_4B, dense_4A), tl.where(\n bit8, dense_49, dense_48))\n sparse5 = tl.where(bitB, tl.where(bitA, dense_4B, dense_4A), tl.where(\n bitA, dense_49, dense_48))\n bitC = ~mC & mD\n bitD = ~mC & ~mD\n bitE = bitD | ~mE\n bitF = bitC | ~mD | mE\n idxs6 = bitC | bitD.to(tl.int64) << 1\n idxs7 = bitE | bitF.to(tl.int64) << 1\n sparse6 = tl.where(bitD, tl.where(bitC, dense_4F, dense_4E), tl.where(\n bitC, dense_4D, dense_4C))\n sparse7 = tl.where(bitF, tl.where(bitE, dense_4F, dense_4E), tl.where(\n bitE, dense_4D, dense_4C))\n bitG = ~mG & mH\n bitH = ~mG & ~mH\n bitI = bitH | ~mI\n bitJ = bitG | ~mH | mI\n idxs8 = bitG | bitH.to(tl.int64) << 1\n idxs9 = bitI | bitJ.to(tl.int64) << 1\n sparse8 = tl.where(bitH, tl.where(bitG, dense_4J, dense_4I), tl.where(\n bitG, dense_4H, dense_4G))\n sparse9 = tl.where(bitJ, tl.where(bitI, dense_4J, dense_4I), tl.where(\n bitI, dense_4H, dense_4G))\n bitK = ~mK & mL\n bitL = ~mK & ~mL\n bitM = bitL | ~mM\n bitN = bitK | ~mL | mM\n idxsA = bitK | bitL.to(tl.int64) << 1\n idxsB = bitM | bitN.to(tl.int64) << 1\n sparseA = tl.where(bitL, tl.where(bitK, dense_4N, dense_4M), tl.where(\n bitK, dense_4L, dense_4K))\n sparseB = tl.where(bitN, tl.where(bitM, dense_4N, dense_4M), tl.where(\n bitM, dense_4L, dense_4K))\n bitO = ~mO & mP\n bitP = ~mO & ~mP\n bitQ = bitP | ~mQ\n bitR = bitO | ~mP | mQ\n idxsC = bitO | bitP.to(tl.int64) << 1\n idxsD = bitQ | bitR.to(tl.int64) << 1\n sparseC = tl.where(bitP, tl.where(bitO, dense_4R, dense_4Q), tl.where(\n bitO, dense_4P, dense_4O))\n sparseD = tl.where(bitR, tl.where(bitQ, dense_4R, dense_4Q), tl.where(\n bitQ, dense_4P, dense_4O))\n bitS = ~mS & mT\n bitT = ~mS & ~mT\n bitU = bitT | ~mU\n bitV = bitS | ~mT | mU\n idxsE = bitS | bitT.to(tl.int64) << 1\n idxsF = bitU | bitV.to(tl.int64) << 1\n sparseE = tl.where(bitT, tl.where(bitS, dense_4V, dense_4U), tl.where(\n bitS, dense_4T, dense_4S))\n sparseF = tl.where(bitV, tl.where(bitU, dense_4V, dense_4U), tl.where(\n bitU, dense_4T, dense_4S))\n col_idx = tl.program_id(1) * 16\n if ARRAY_LAYOUT == 'row':\n col_idx = tl.program_id(1) * 16 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 16\n mask = col_idx < k // 2\n else:\n col_idx = tl.program_id(1) * 16\n mask = row_idx < m\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 0) *\n sparse_col_stride, sparse0, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 1) *\n sparse_col_stride, sparse1, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 2) *\n sparse_col_stride, sparse2, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 3) *\n sparse_col_stride, sparse3, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 4) *\n sparse_col_stride, sparse4, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 5) *\n sparse_col_stride, sparse5, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 6) *\n sparse_col_stride, sparse6, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 7) *\n sparse_col_stride, sparse7, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 8) *\n sparse_col_stride, sparse8, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 9) *\n sparse_col_stride, sparse9, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 10) *\n sparse_col_stride, sparseA, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 11) *\n sparse_col_stride, sparseB, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 12) *\n sparse_col_stride, sparseC, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 13) *\n sparse_col_stride, sparseD, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 14) *\n sparse_col_stride, sparseE, mask=mask)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 15) *\n sparse_col_stride, sparseF, mask=mask)\n meta_40 = idxs0 | idxs1 << 2\n meta_41 = idxs2 | idxs3 << 2\n meta_42 = idxs4 | idxs5 << 2\n meta_43 = idxs6 | idxs7 << 2\n meta_44 = idxs8 | idxs9 << 2\n meta_45 = idxsA | idxsB << 2\n meta_46 = idxsC | idxsD << 2\n meta_47 = idxsE | idxsF << 2\n meta = (meta_40 | meta_41 << 4 | meta_42 << 8 | meta_43 << 12 | meta_44 <<\n 16 | meta_45 << 20 | meta_46 << 24 | meta_47 << 28)\n if ARRAY_LAYOUT == 'row':\n col_idx = tl.program_id(1) * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n elif ARRAY_LAYOUT == 'col':\n col_idx = tl.program_id(1)\n group, interweave = 16, 2\n dest_row = (row_idx // group * group + row_idx % 8 * interweave + \n row_idx % group // 8)\n dest_col = col_idx\n topright = ((dest_row % 2 == 0) & (dest_col % 2 == 1)).to(tl.int8)\n bottomleft = ((dest_row % 2 == 1) & (dest_col % 2 == 0)).to(tl.int8)\n dest_row = dest_row + topright - bottomleft\n dest_col = dest_col - topright + bottomleft\n interleave = 2\n cols_maj = dest_col // interleave\n cols_min = dest_col % interleave\n meta_reordered_offsets = (cols_maj * m * interleave + dest_row *\n interleave + cols_min)\n if ARRAY_LAYOUT == 'row':\n mask = col_idx < k // 32\n elif ARRAY_LAYOUT == 'col':\n mask = row_idx < m\n tl.store(meta_reordered_ptr + meta_reordered_offsets, meta, mask=mask)\n", "category": { "Functionality": [ "Quantization", "Top-K Selection" ], "Data Type": [ "int8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/_semi_structured_conversions.py" }, { "uuid": "0f3aabee-e682-46a8-89dc-314404372b6b", "file_name": "scaled_quant.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/fp8/scaled_quant.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef scaled_cast(inpt_ptr: torch.Tensor, output_ptr: torch.Tensor, scale_ptr:\n torch.Tensor, abs_max_ptr: torch.Tensor, numel: int, XBLOCK: tl.\n constexpr, float8_dtype: tl.constexpr, max_val: tl.constexpr):\n \"\"\"Quantize tensor to fp8 using a delayed scaled and calculate abs_max\"\"\"\n offset = tl.program_id(0) * XBLOCK\n index = offset + tl.arange(0, XBLOCK)[:]\n index = tl.max_contiguous(tl.multiple_of(index, XBLOCK), XBLOCK)\n mask = index < numel\n inpt = tl.load(inpt_ptr + index, mask=mask)\n block_max = tl.max(tl.abs(inpt))\n tl.atomic_max(abs_max_ptr, block_max)\n scale = tl.load(scale_ptr)\n scaled_inpt = inpt * scale\n if max_val != 0.0:\n tl.where(scaled_inpt > max_val, max_val, scaled_inpt)\n tl.where(scaled_inpt < -1 * max_val, -1 * max_val, scaled_inpt)\n tl.store(output_ptr + index, scaled_inpt.to(float8_dtype), mask=mask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/fp8/scaled_quant.py" }, { "uuid": "85beb12c-9aca-4963-98a0-73a6a62a12a3", "file_name": "rms_norm.py", "repo_name": "tascj/kaggle-lmsys-chatbot-arena", "file_path": "human_pref/inference/ops/rms_norm.py", "commit_hash": "83cd93d50b9283c18711e8c63e4e1c6399c7b9ce", "starcount": 0, "input": "@wrap_jit_func(type_hint=dict(input=Tensor, weight=Tensor, output=Tensor,\n input_row_stride=int, eps=float, N_COLS=torch.int32, BLOCK_N=torch.int32))\n@triton.jit\ndef rms_norm_kernel(input, weight, output, input_row_stride: tl.constexpr,\n eps: tl.constexpr, N_COLS: tl.constexpr, BLOCK_N: tl.constexpr):\n \"\"\"rms norm kernel.\"\"\"\n prog_id = tl.program_id(0)\n offsets = tl.arange(0, BLOCK_N)\n w = tl.load(weight + offsets, mask=offsets < N_COLS)\n x_ptr = input + prog_id * input_row_stride\n x = tl.load(x_ptr + offsets, mask=offsets < N_COLS)\n xf = x.to(tl.float32)\n var = tl.sum(xf * xf, 0) * float(1.0 / N_COLS)\n out = xf / tl.sqrt(var + eps)\n out = (w * out).to(x.dtype)\n out_ptr = output + prog_id * input_row_stride\n tl.store(out_ptr + offsets, out, mask=offsets < N_COLS)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/tascj/kaggle-lmsys-chatbot-arena/blob/83cd93d50b9283c18711e8c63e4e1c6399c7b9ce/human_pref/inference/ops/rms_norm.py" }, { "uuid": "db2799a9-b71d-4ed2-84ba-ff3e85441eca", "file_name": "multi_head_attention_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/multi_head_attention_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef _bwd_kernel(Q, K, V, sm_scale, Out, DO, DQ, DK, DV, L, D, stride_dqa,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vn, stride_vk, Z, H,\n N_CTX, Z_H_N_CTX, SQ_Z_H_N_CTX, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl\n .constexpr, BLOCK_N: tl.constexpr, SEQUENCE_PARALLEL: tl.constexpr,\n CAUSAL: tl.constexpr, MMA_V3: tl.constexpr):\n qk_scale = sm_scale * 1.44269504\n off_hz = tl.program_id(0)\n off_z = off_hz // H\n off_h = off_hz % H\n Q_block_ptr = tl.make_block_ptr(base=Q, shape=(Z_H_N_CTX, BLOCK_DMODEL),\n strides=(stride_qm, stride_qk), offsets=(0, 0), block_shape=(\n BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K, shape=(Z_H_N_CTX, BLOCK_DMODEL),\n strides=(stride_kn, stride_kk), offsets=(0, 0), block_shape=(\n BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n V_block_ptr = tl.make_block_ptr(base=V, shape=(Z_H_N_CTX, BLOCK_DMODEL),\n strides=(stride_vn, stride_vk), offsets=(0, 0), block_shape=(\n BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n DO_block_ptr = tl.make_block_ptr(base=DO, shape=(Z_H_N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n if SEQUENCE_PARALLEL:\n DQ_block_ptr = tl.make_block_ptr(base=DQ, shape=(SQ_Z_H_N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n else:\n DQ_block_ptr = tl.make_block_ptr(base=DQ, shape=(Z_H_N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n DK_block_ptr = tl.make_block_ptr(base=DK, shape=(Z_H_N_CTX,\n BLOCK_DMODEL), strides=(stride_kn, stride_kk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n DV_block_ptr = tl.make_block_ptr(base=DV, shape=(Z_H_N_CTX,\n BLOCK_DMODEL), strides=(stride_vn, stride_vk), offsets=(0, 0),\n block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n num_block_n = tl.cdiv(N_CTX, BLOCK_N)\n if not SEQUENCE_PARALLEL:\n for start_n in range(0, num_block_n):\n _bwd_kernel_one_col_block(Q, K, V, sm_scale, qk_scale, Out, DO,\n DQ, DK, DV, L, D, Q_block_ptr, K_block_ptr, V_block_ptr,\n DO_block_ptr, DQ_block_ptr, DK_block_ptr, DV_block_ptr,\n stride_dqa, stride_qz, stride_qh, stride_qm, stride_qk,\n stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vn, stride_vk, Z, H, N_CTX, off_h, off_z,\n off_hz, start_n, num_block_n, BLOCK_M=BLOCK_M, BLOCK_DMODEL\n =BLOCK_DMODEL, BLOCK_N=BLOCK_N, SEQUENCE_PARALLEL=\n SEQUENCE_PARALLEL, CAUSAL=CAUSAL, MMA_V3=MMA_V3)\n else:\n start_n = tl.program_id(1)\n _bwd_kernel_one_col_block(Q, K, V, sm_scale, qk_scale, Out, DO, DQ,\n DK, DV, L, D, Q_block_ptr, K_block_ptr, V_block_ptr,\n DO_block_ptr, DQ_block_ptr, DK_block_ptr, DV_block_ptr,\n stride_dqa, stride_qz, stride_qh, stride_qm, stride_qk,\n stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vn, stride_vk, Z, H, N_CTX, off_h, off_z,\n off_hz, start_n, num_block_n, BLOCK_M=BLOCK_M, BLOCK_DMODEL=\n BLOCK_DMODEL, BLOCK_N=BLOCK_N, SEQUENCE_PARALLEL=\n SEQUENCE_PARALLEL, CAUSAL=CAUSAL, MMA_V3=MMA_V3)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32", "fp16", "bf16" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/multi_head_attention_kernels.py" }, { "uuid": "db218ad8-20e0-48b5-b390-052c8b786f91", "file_name": "softmax_online_v2.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v2.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n final_m = tl.max(m, 0)\n z = tl.sum(tl.exp(m - final_m) * z)\n m = final_m\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v2.py" }, { "uuid": "73a1b7d4-10ae-42d1-829c-fc9da1265666", "file_name": "quant_per_block.py", "repo_name": "rodjjo/editorium", "file_path": "editorium/app/server/pipelines/cogvideo/sageattention/quant_per_block.py", "commit_hash": "7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694", "starcount": 0, "input": "@triton.jit\ndef k_kernel_per_block_int8(X, X_int8, BLK: tl.constexpr, Scale, L, C: tl.\n constexpr, scale_stride):\n off_b = tl.program_id(1)\n off_blk = tl.program_id(0)\n x_offset = off_b * L * C\n offs_m = off_blk * BLK + tl.arange(0, BLK)\n offs_k = tl.arange(0, C)\n x_ptrs = X + x_offset + offs_m[:, None] * C + offs_k[None, :]\n x_int8_ptrs = X_int8 + x_offset + offs_m[:, None] * C + offs_k[None, :]\n scale_ptrs = Scale + off_b * scale_stride + off_blk\n x = tl.load(x_ptrs, mask=offs_m[:, None] < L)\n scale = tl.max(tl.abs(x)) / 127.0\n x_int8 = x / scale\n x_int8 += 0.5 * tl.where(x_int8 >= 0, 1, -1)\n x_int8 = x_int8.to(tl.int8)\n tl.store(x_int8_ptrs, x_int8, mask=offs_m[:, None] < L)\n tl.store(scale_ptrs, scale)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/rodjjo/editorium/blob/7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694/editorium/app/server/pipelines/cogvideo/sageattention/quant_per_block.py" }, { "uuid": "e208a539-0dcc-4c48-b62a-23278be7b325", "file_name": "test_triton_varargs.py", "repo_name": "facebookresearch/xformers", "file_path": "tests/test_triton_varargs.py", "commit_hash": "a2f37f8c5f4e3ae0d3459a92e42cd1aeb45b03bc", "starcount": 0, "input": "@triton.jit\ndef weighted_sumN(output_ptr, a_ptr: 'VAR_ARGS_ARRAY', b: 'VAR_ARGS_ARRAY',\n BLOCK_SIZE: tl.constexpr):\n offset = tl.arange(0, BLOCK_SIZE)\n output = tl.zeros([BLOCK_SIZE], tl.float32)\n for i in range(len(a_ptr)):\n output = output + tl.load(a_ptr[i] + offset) * b[i]\n tl.store(output_ptr + offset, output)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/facebookresearch/xformers/blob/a2f37f8c5f4e3ae0d3459a92e42cd1aeb45b03bc/tests/test_triton_varargs.py" }, { "uuid": "940875b4-4e20-421f-a86c-5e25ff28a855", "file_name": "02-fused-softmax.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/02-fused-softmax.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel(output_ptr, input_ptr, input_row_stride,\n output_row_stride, n_rows, n_cols, BLOCK_SIZE: tl.constexpr, num_stages:\n tl.constexpr):\n row_start = tl.program_id(0)\n row_step = tl.num_programs(0)\n for row_idx in tl.range(row_start, n_rows, row_step, num_stages=num_stages\n ):\n row_start_ptr = input_ptr + row_idx * input_row_stride\n col_offsets = tl.arange(0, BLOCK_SIZE)\n input_ptrs = row_start_ptr + col_offsets\n mask = col_offsets < n_cols\n row = tl.load(input_ptrs, mask=mask, other=-float('inf'))\n row_minus_max = row - tl.max(row, axis=0)\n numerator = tl.exp(row_minus_max)\n denominator = tl.sum(numerator, axis=0)\n softmax_output = numerator / denominator\n output_row_start_ptr = output_ptr + row_idx * output_row_stride\n output_ptrs = output_row_start_ptr + col_offsets\n tl.store(output_ptrs, softmax_output, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/02-fused-softmax.py" }, { "uuid": "bd846196-d65e-4894-a342-0d208017c704", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_local_reversed_cumsum_scalar_kernel(s, o, offsets, indices, T: tl\n .constexpr, H: tl.constexpr, BT: tl.constexpr, HEAD_FIRST: tl.constexpr,\n USE_OFFSETS: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n p_o = tl.make_block_ptr(o + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n else:\n p_s = tl.make_block_ptr(s + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n p_o = tl.make_block_ptr(o + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n b_s = tl.load(p_s, boundary_check=(0,)).to(tl.float32)\n b_z = tl.sum(b_s, axis=0)\n b_o = b_z[None] - tl.cumsum(b_s, axis=0) + b_s\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "d8ccdd9a-8a45-418c-8e08-65a619303b4e", "file_name": "triton_attn_torch_function.py", "repo_name": "ROCm/aotriton", "file_path": "test/triton_attn_torch_function.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64,\n 'waves_per_eu': 0, 'pre_load_v': True}, num_stages=1, num_warps=4),\n triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 1,\n 'pre_load_v': True}, num_stages=1, num_warps=4), triton.Config({\n 'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 2, 'pre_load_v': True},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 64, 'waves_per_eu': 3, 'pre_load_v': True}, num_stages=1, num_warps=4),\n triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 4,\n 'pre_load_v': True}, num_stages=1, num_warps=4), triton.Config({\n 'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 0, 'pre_load_v': False},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 64, 'waves_per_eu': 1, 'pre_load_v': False}, num_stages=1, num_warps=4),\n triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 2,\n 'pre_load_v': False}, num_stages=1, num_warps=4), triton.Config({\n 'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 3, 'pre_load_v': False},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 64, 'waves_per_eu': 4, 'pre_load_v': False}, num_stages=1, num_warps=4)\n ], key=['seqlen_q', 'seqlen_k', 'STAGE'])\n@triton.jit\ndef tuned_attn_fwd(Q, K, V, sm_scale, M, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, seqlen_q, seqlen_k, dropout_p, philox_seed,\n philox_offset_base, encoded_softmax, STAGE: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr,\n pre_load_v: tl.constexpr, ENABLE_DROPOUT: tl.constexpr,\n RETURN_ENCODED_SOFTMAX: tl.constexpr):\n bare_attn_fwd(Q, K, V, sm_scale, M, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, seqlen_q, seqlen_k, dropout_p, philox_seed,\n philox_offset_base, encoded_softmax, STAGE, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, pre_load_v, ENABLE_DROPOUT, RETURN_ENCODED_SOFTMAX)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency", "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/triton_attn_torch_function.py" }, { "uuid": "feca8afb-e281-4618-b17b-e142d9d07e8c", "file_name": "softmax_online_v2_rev.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v2_rev.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n final_m = tl.max(m, 0)\n z = tl.sum(tl.exp(m - final_m) * z)\n m = final_m\n previous_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, N, TILE_N):\n n_offsets = previous_multiple - start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v2_rev.py" }, { "uuid": "dbe1ee83-8582-4032-942f-933e819075c9", "file_name": "1_linear_trident_debug.py", "repo_name": "gmgu/study-triton", "file_path": "toy_example/1_linear_trident_debug.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@staticmethod\n@triton.jit\ndef forward(input_ptr: tl.tensor, weight_ptr: tl.tensor, bias_ptr: tl.\n tensor, m_size: tl.int32, n_size: tl.int32, k_size: tl.int32,\n input_m_stride: tl.int32, input_k_stride: tl.int32, weight_n_stride: tl\n .int32, weight_k_stride: tl.int32, m_offset: tl.int32, n_offset: tl.\n int32, use_accelerator: tl.constexpr, m_block_size: tl.constexpr,\n n_block_size: tl.constexpr, k_block_size: tl.constexpr, dtype: tl.constexpr\n ):\n input_block_ptr = tl.make_block_ptr(input_ptr, shape=(m_size, k_size),\n strides=(input_m_stride, input_k_stride), offsets=(m_offset, 0),\n block_shape=(m_block_size, k_block_size), order=(1, 0))\n weight_block_ptr = tl.make_block_ptr(weight_ptr, shape=(k_size, n_size),\n strides=(weight_k_stride, weight_n_stride), offsets=(0, n_offset),\n block_shape=(k_block_size, n_block_size), order=(0, 1))\n output = tl.zeros((m_block_size, n_block_size), dtype)\n for k_offset in range(0, k_size, k_block_size):\n input = tl.load(input_block_ptr, boundary_check=(0, 1),\n padding_option='zero')\n weight = tl.load(weight_block_ptr, boundary_check=(0, 1),\n padding_option='zero')\n output += tl.dot(input, weight, use_accelerator).to(dtype)\n input_block_ptr = tl.advance(input_block_ptr, (0, k_block_size))\n weight_block_ptr = tl.advance(weight_block_ptr, (k_block_size, 0))\n if bias_ptr is not None:\n bias_block_ptr = tl.make_block_ptr(bias_ptr, shape=(n_size,),\n strides=(1,), offsets=(n_offset,), block_shape=(n_block_size,),\n order=(0,))\n bias = tl.load(bias_block_ptr, boundary_check=(0,), padding_option=\n 'zero')\n output += bias\n return output\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/toy_example/1_linear_trident_debug.py" }, { "uuid": "54490e5d-07a7-43ff-af70-75332c3c39e7", "file_name": "kernels.py", "repo_name": "ShenzheZhu/sparse_autoencoder", "file_path": "sparse_autoencoder/kernels.py", "commit_hash": "afef049c905fda5b0f69729127ce0d3a42399152", "starcount": 0, "input": "@triton.jit\ndef triton_sum_dim0_in_fp32_kernel(xs_ptr, out_ptr, stride_a, a, b,\n BLOCK_SIZE_A: tl.constexpr, BLOCK_SIZE_B: tl.constexpr):\n pid = tl.program_id(0)\n offsets_b = tl.arange(0, BLOCK_SIZE_B) + pid * BLOCK_SIZE_B\n all_out = tl.zeros((BLOCK_SIZE_B,), dtype=tl.float32)\n for i in range(0, a, BLOCK_SIZE_A):\n offsets_a = tl.arange(0, BLOCK_SIZE_A) + i\n xs = tl.load(xs_ptr + offsets_a[:, None] * stride_a + offsets_b[\n None, :], mask=(offsets_a < a)[:, None] & (offsets_b < b)[None,\n :], other=0)\n xs = xs.to(tl.float32)\n out = tl.sum(xs, axis=0)\n all_out += out\n tl.store(out_ptr + offsets_b, all_out, mask=offsets_b < b)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ShenzheZhu/sparse_autoencoder/blob/afef049c905fda5b0f69729127ce0d3a42399152/sparse_autoencoder/kernels.py" }, { "uuid": "a4954557-c50d-4f29-8e9a-cc269e7c427f", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_gated_delta_rule_fwd_kernel_h(k, v, d, v_new, g, h, h0, ht,\n offsets, c_offsets, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr,\n V: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BK: tl.constexpr,\n BV: tl.constexpr, NT: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(c_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT):\n if HEAD_FIRST:\n p_h = tl.make_block_ptr(h + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_h = tl.make_block_ptr(h + ((boh + i_t) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_hc = tl.zeros([BK, BV], dtype=tl.float32)\n last_idx = min((i_t + 1) * BT, T) - 1\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_nh * T + last_idx)\n else:\n b_g_last = tl.load(g + bos * H + last_idx * H + i_h)\n for i_c in range(tl.cdiv(min(BT, T - i_t * BT), BC)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_nh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_d = tl.make_block_ptr(d + i_nh * T * K, (T, K), (K, 1), (\n i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_nh * T * V, (T, V), (V, 1), (\n i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_v_new = tl.make_block_ptr(v_new + i_nh * T * V, (T, V), (\n V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_g = tl.make_block_ptr(g + i_nh * T, (T,), (1,), (i_t * BT +\n i_c * BC,), (BC,), (0,))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1,\n H * K), (i_k * BK, i_t * BT + i_c * BC), (BK, BC), (0, 1))\n p_d = tl.make_block_ptr(d + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_c * BC, i_k * BK), (BC, BK), (1, 0))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC, BV), (1, 0))\n p_v_new = tl.make_block_ptr(v_new + (bos * H + i_h) * V, (T,\n V), (H * V, 1), (i_t * BT + i_c * BC, i_v * BV), (BC,\n BV), (1, 0))\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t *\n BT + i_c * BC,), (BC,), (0,))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_k = (b_k * tl.exp(b_g_last - b_g)[None, :]).to(b_k.dtype)\n b_d = tl.load(p_d, boundary_check=(0, 1))\n b_d = (b_d * tl.exp(b_g)[:, None]).to(b_d.dtype)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_v -= tl.dot(b_d, b_h.to(b_k.dtype))\n tl.store(p_v_new, b_v.to(p_v_new.dtype.element_ty),\n boundary_check=(0, 1))\n b_hc += tl.dot(b_k, b_v.to(b_k.dtype), allow_tf32=False)\n b_h *= tl.exp(b_g_last)\n b_h += b_hc\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/chunk.py" }, { "uuid": "9158e059-6a68-45a0-bb6e-187574d65a8e", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N':\n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': \n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_K': 32, 'BLOCK_SIZE_N': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': \n 16}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 32, 'BLOCK_SIZE_N': 16}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 16}, num_stages=2, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef rz_linear_backward_input_grad_kernel_fp32(a_ptr, b_ptr, c_ptr,\n init_factor, M, N, K, H, stride_am, stride_an, stride_cm, stride_ck, R7:\n int, R6: int, R5: int, R4: int, R3: int, R2: int, R1: int, R0: int,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_backward_input_grad_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=\n c_ptr, init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=\n stride_am, stride_an=stride_an, stride_cm=stride_cm, stride_ck=\n stride_ck, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1, R0=R0,\n allow_tf32=False, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=\n BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "9e9e1c3a-4a92-4686-a3c3-09f634021f06", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_cum(s, r, c, p, s_sk_h, s_sk_t, s_sk_m, T, BT: tl.\n constexpr, BM: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_m, i_bh = tl.program_id(0), tl.program_id(1)\n p_s = tl.make_block_ptr(s + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n 0, i_m * BM), (BT, BM), (1, 0))\n p_r = tl.make_block_ptr(r + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_c = tl.make_block_ptr(c + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n 0, i_m * BM), (BT, BM), (1, 0))\n p_p = tl.make_block_ptr(p + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n 0, i_m * BM), (BT, BM), (1, 0))\n b_mp = tl.zeros([BM], dtype=tl.float32)\n b_zp = tl.zeros([BM], dtype=tl.float32)\n for i in range(NT):\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_m = tl.max(b_s, 0)\n if i == 0:\n b_r = tl.exp(-b_m)\n else:\n b_m = tl.maximum(b_mp, b_m)\n b_r = tl.exp(b_mp - b_m)\n b_c = tl.exp(b_s - b_m[None, :])\n b_z = tl.cumsum(b_c, 0) + (b_zp * b_r)[None, :]\n b_p = tl.exp(-tl.log(b_z))\n b_mp = b_m\n b_zp = tl.max(b_z, 0)\n tl.store(p_r, b_r.to(p_r.dtype.element_ty), boundary_check=(0,))\n tl.store(p_c, b_c.to(p_c.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_p, b_p.to(p_p.dtype.element_ty), boundary_check=(0, 1))\n p_s = tl.advance(p_s, (BT, 0))\n p_r = tl.advance(p_r, (DM,))\n p_c = tl.advance(p_c, (BT, 0))\n p_p = tl.advance(p_p, (BT, 0))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "7671d636-5551-4193-b0be-489e180535f4", "file_name": "lightning_attn2_no_decay.py", "repo_name": "OpenNLPLab/lightning-attention", "file_path": "lightning_attn/ops/triton/lightning_attn2_no_decay.py", "commit_hash": "d7439519541e966084eeaaf3ffd63eecc216f414", "starcount": 0, "input": "@triton.jit\ndef _bwd_intra_kernel(Q, K, V, DO, DQ, DK, DV, b: tl.constexpr, h: tl.\n constexpr, n: tl.constexpr, d: tl.constexpr, e: tl.constexpr, BLOCK: tl\n .constexpr, NUM_BLOCK: tl.constexpr, CBLOCK: tl.constexpr, NUM_CBLOCK:\n tl.constexpr):\n off_bh = tl.program_id(0)\n off_block = tl.program_id(1)\n off_bh % h\n qk_offset = off_bh * n * d\n v_offset = off_bh * n * e\n o_offset = off_bh * n * e\n block_offset = off_block * BLOCK + tl.arange(0, BLOCK)\n Q_trans_block_ptr = Q + qk_offset + block_offset[None, :] * d + tl.arange(\n 0, d)[:, None]\n K_block_ptr = K + qk_offset + block_offset[:, None] * d + tl.arange(0, d)[\n None, :]\n V_trans_block_ptr = V + v_offset + block_offset[None, :] * e + tl.arange(\n 0, e)[:, None]\n DQ_block_ptr = DQ + qk_offset + block_offset[:, None] * d + tl.arange(0, d\n )[None, :]\n DK_trans_block_ptr = DK + qk_offset + block_offset[None, :\n ] * d + tl.arange(0, d)[:, None]\n DV_block_ptr = DV + v_offset + block_offset[:, None] * e + tl.arange(0, e)[\n None, :]\n DO_block_ptr = DO + o_offset + block_offset[:, None] * e + tl.arange(0, e)[\n None, :]\n array = tl.arange(0, BLOCK).to(tl.float32)\n index = array[:, None] - array[None, :]\n k = tl.load(K_block_ptr, mask=block_offset[:, None] < n, other=0.0).to(tl\n .float32)\n v_trans = tl.load(V_trans_block_ptr, mask=block_offset[None, :] < n,\n other=0.0).to(tl.float32)\n do = tl.load(DO_block_ptr, mask=block_offset[:, None] < n, other=0.0).to(tl\n .float32)\n q_trans = tl.load(Q_trans_block_ptr, mask=block_offset[None, :] < n,\n other=0.0).to(tl.float32)\n dqk = tl.dot(do, v_trans)\n dqk = tl.where(index >= 0, dqk, 0)\n dq_intra = tl.dot(dqk, k)\n dk_intra_trans = tl.dot(q_trans, dqk)\n qk_trans = tl.dot(k, q_trans)\n qk_trans = tl.where(index <= 0, qk_trans, 0)\n dv_intra = tl.dot(qk_trans, do)\n dq = dq_intra\n dk_trans = dk_intra_trans\n dv = dv_intra\n tl.store(DQ_block_ptr, dq.to(DQ_block_ptr.dtype.element_ty), mask=\n block_offset[:, None] < n)\n tl.store(DK_trans_block_ptr, dk_trans.to(DK_trans_block_ptr.dtype.\n element_ty), mask=block_offset[None, :] < n)\n tl.store(DV_block_ptr, dv.to(DV_block_ptr.dtype.element_ty), mask=\n block_offset[:, None] < n)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/OpenNLPLab/lightning-attention/blob/d7439519541e966084eeaaf3ffd63eecc216f414/lightning_attn/ops/triton/lightning_attn2_no_decay.py" }, { "uuid": "46ac2c79-450e-48fc-8437-4e363de32217", "file_name": "grid.py", "repo_name": "daemyung/practice-triton", "file_path": "grid.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@triton.jit\ndef print_grid():\n pid = tl.program_id(0)\n tl.device_print('pid: ', pid)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/grid.py" }, { "uuid": "0d1dcbf9-4918-4161-b36a-9394e15bb253", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef precompute_mlstm_triton_scan(K, V, F, I, F_REDUCED, C, N, NH: tl.\n constexpr, S: tl.constexpr, D: tl.constexpr, SB: tl.constexpr, VB: tl.\n constexpr):\n bh_id = tl.program_id(0)\n sb_id = tl.program_id(1)\n vb_id = tl.program_id(2)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n num_sequence_blocks = tl.num_programs(1)\n v_range = tl.arange(0, VB) + vb_id * VB\n v_range_2d = v_range[None, :]\n v_range_3d = v_range[None, :, None]\n k_range = tl.arange(0, VB)\n sb_range_2d = tl.arange(0, SB)[:, None]\n sb_range_3d = tl.arange(0, SB)[:, None, None]\n sb_range_offset = tl.arange(0, SB) + sb_id * SB\n sb_range_offset_2d = sb_range_offset[:, None]\n batch_offset_fi = batch_id * NH * S + head_id * S\n batch_offset_qkv = batch_id * NH * S * D + head_id * S * D\n batch_offset_n = (batch_id * NH * num_sequence_blocks * D + head_id *\n num_sequence_blocks * D)\n batch_offset_c = (batch_id * NH * num_sequence_blocks * D * D + head_id *\n num_sequence_blocks * D * D)\n f = tl.load(F + sb_range_offset + batch_offset_fi, sb_range_offset < S)\n i = tl.load(I + sb_range_offset + batch_offset_fi, sb_range_offset < S)\n v_range_ = batch_offset_qkv + sb_range_offset_2d * D + v_range_2d\n v_mask = (sb_range_offset_2d < S) & (v_range_2d < D)\n v = tl.load(V + v_range_, v_mask)\n k_scale_factor = tl.sqrt(tl.full((1,), D, dtype=tl.float32))\n for j in tl.range(tl.cdiv(D, VB)):\n k_range_ = batch_offset_qkv + sb_range_offset_2d * D + k_range[None, :]\n k_mask = (sb_range_offset_2d < S) & (k_range[None, :] < D)\n k = tl.load(K + k_range_, k_mask) / k_scale_factor\n vk = v[:, :, None] * k[:, None, :] * i[:, None, None]\n _, c = tl.associative_scan((tl.broadcast_to(f[:, None, None], (SB,\n VB, VB)), vk), 0, scan_op)\n c_range = (batch_offset_c + sb_range_3d * 0 + sb_id * D * D + \n v_range_3d * D + k_range[None, None, :])\n c_mask = (sb_range_3d == SB - 1) & (v_range_3d < D) & (k_range[None,\n None, :] < D)\n tl.store(C + c_range, c, c_mask)\n f_reduced, n = tl.associative_scan((tl.broadcast_to(f[:, None], (SB,\n VB)), i[:, None] * k), 0, scan_op)\n n_range = batch_offset_n + sb_range_2d * 0 + sb_id * D + k_range[\n None, :]\n n_mask = (sb_range_2d == SB - 1) & (k_range[None, :] < D)\n tl.store(N + n_range, n, n_mask)\n if j == 0:\n f_range = batch_offset_fi + sb_range_2d * 0 + sb_id + tl.arange(\n 0, VB)[None, :]\n f_mask = (sb_range_2d == SB - 1) & (tl.arange(0, VB)[None, :] == 0)\n tl.store(F_REDUCED + f_range, f_reduced, f_mask)\n k_range += VB\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "2396ab23-b768-4d96-8878-5a6ea4683b65", "file_name": "triton_fused_local_attn_rerope.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_local_attn_rerope.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q1, q2, sm_scale, K1_block_ptr,\n K2_block_ptr, V_block_ptr, start_m, offs_m, offs_n, SEQLEN_K: tl.\n constexpr, WINDOW_SIZE: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N:\n tl.constexpr, EVEN_MN: tl.constexpr, STAGE: tl.constexpr):\n if STAGE == 1:\n hi = start_m * BLOCK_M - WINDOW_SIZE + BLOCK_M\n lo = start_m * BLOCK_M - WINDOW_SIZE\n if hi < 0:\n hi = 0\n if lo < 0:\n lo = 0\n elif STAGE == 2:\n hi = start_m * BLOCK_M\n lo = start_m * BLOCK_M - WINDOW_SIZE + BLOCK_M\n if lo < 0:\n lo = 0\n else:\n lo, hi = start_m * BLOCK_M, (start_m + 1) * BLOCK_M\n lo = tl.multiple_of(lo, BLOCK_M)\n hi = min(hi, SEQLEN_K)\n EVEN_MASK_FREE = EVEN_MN & ((STAGE == 1) | (STAGE == 2))\n K1_block_ptr = tl.advance(K1_block_ptr, (0, lo))\n K2_block_ptr = tl.advance(K2_block_ptr, (0, lo))\n V_block_ptr = tl.advance(V_block_ptr, (lo, 0))\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_MASK_FREE:\n k1 = tl.load(K1_block_ptr)\n else:\n k1 = tl.load(K1_block_ptr, boundary_check=(1,), padding_option=\n 'zero')\n qk = tl.dot(q1, k1) * (sm_scale * RCP_LN2)\n if STAGE == 1:\n if EVEN_MN:\n k2 = tl.load(K2_block_ptr)\n else:\n k2 = tl.load(K2_block_ptr, boundary_check=(1,),\n padding_option='zero')\n qk2 = tl.dot(q2, k2) * (sm_scale * RCP_LN2)\n mask = offs_m[:, None] <= start_n + WINDOW_SIZE + offs_n[None, :]\n qk = tl.where(mask, qk, qk2)\n elif STAGE == 3:\n mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk += tl.where(mask, 0, NEGINF)\n if not EVEN_MASK_FREE:\n qk += tl.where((start_n + offs_n)[None, :] < SEQLEN_K, 0, NEGINF)\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc *= alpha[:, None]\n if EVEN_MASK_FREE:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(1,), padding_option='zero'\n )\n acc += tl.dot(p.to(V_block_ptr.dtype.element_ty), v)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K1_block_ptr = tl.advance(K1_block_ptr, (0, BLOCK_N))\n K2_block_ptr = tl.advance(K2_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_local_attn_rerope.py" }, { "uuid": "0fa50a32-0fe2-47d6-882e-e43af53f8157", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv4/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_rwkv4_forward_kernel(w_ptr, w_s_c, u_ptr, u_s_c, k_ptr,\n k_s_b, k_s_t, k_s_c, v_ptr, v_s_b, v_s_t, v_s_c, state_ptr, state_s_b,\n state_s_abe, state_s_c, wkv_ptr, wkv_s_b, wkv_s_t, wkv_s_c,\n state_out_ptr, state_out_s_b, state_out_s_abe, state_out_s_t,\n state_out_s_c, chans, tsz, BLOCK_SIZE_C: tl.constexpr):\n b_idx = tl.program_id(0)\n c_idx = tl.program_id(1)\n cs = c_idx * BLOCK_SIZE_C + tl.arange(0, BLOCK_SIZE_C)\n cmask = cs < chans\n k_ptr = k_ptr + b_idx * k_s_b\n v_ptr = v_ptr + b_idx * v_s_b\n alpha_ptr = state_ptr + b_idx * state_s_b\n beta_ptr = state_ptr + b_idx * state_s_b + state_s_abe\n eps_ptr = state_ptr + b_idx * state_s_b + 2 * state_s_abe\n wkv_ptr = wkv_ptr + b_idx * wkv_s_b\n alpha_out_ptr = state_out_ptr + b_idx * state_out_s_b\n beta_out_ptr = state_out_ptr + b_idx * state_out_s_b + state_out_s_abe\n eps_out_ptr = state_out_ptr + b_idx * state_out_s_b + 2 * state_out_s_abe\n alpha = tl.load(alpha_ptr + cs * state_s_c, mask=cmask).to(tl.float32)\n beta = tl.load(beta_ptr + cs * state_s_c, mask=cmask).to(tl.float32)\n eps = tl.load(eps_ptr + cs * state_s_c, mask=cmask).to(tl.float32)\n w = tl.load(w_ptr + cs * w_s_c, mask=cmask).to(tl.float32)\n u = tl.load(u_ptr + cs * u_s_c, mask=cmask).to(tl.float32)\n for t in range(tsz):\n kt = tl.load(k_ptr + t * k_s_t + cs * k_s_c, mask=cmask).to(tl.float32)\n vt = tl.load(v_ptr + t * v_s_t + cs * v_s_c, mask=cmask).to(tl.float32)\n ukt = u + kt\n tau = tl.maximum(ukt, eps)\n e1a = tl.exp(eps - tau)\n e2a = tl.exp(ukt - tau)\n wkv = (e1a * alpha + e2a * vt) / (e1a * beta + e2a)\n tl.store(wkv_ptr + t * wkv_s_t + cs * wkv_s_c, wkv, mask=cmask)\n w_eps = w + eps\n eps = tl.maximum(w_eps, kt)\n e1b = tl.exp(w_eps - eps)\n e2b = tl.exp(kt - eps)\n alpha = e1b * alpha + e2b * vt\n beta = e1b * beta + e2b\n tl.store(alpha_out_ptr + t * state_out_s_t + cs * state_out_s_c,\n alpha, mask=cmask)\n tl.store(beta_out_ptr + t * state_out_s_t + cs * state_out_s_c,\n beta, mask=cmask)\n tl.store(eps_out_ptr + t * state_out_s_t + cs * state_out_s_c, eps,\n mask=cmask)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Register Intensive", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv4/fused_recurrent.py" }, { "uuid": "eac3fea0-6ec0-4a47-aee5-7bbb6b64ef29", "file_name": "addition.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/addition.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _AddStats_cl3d_impl(X_ptr, Y_ptr, Out_ptr, Mean_ptr, Sqmean_ptr, numel,\n numel_no_channels, BLOCK_SIZE: tl.constexpr, num_channels: tl.constexpr,\n block_other: tl.constexpr):\n pid = tl.program_id(0)\n X_ptr += pid * BLOCK_SIZE\n Y_ptr += pid * BLOCK_SIZE\n Out_ptr += pid * BLOCK_SIZE\n channels_offset = tl.arange(0, num_channels)\n other_offset = tl.arange(0, block_other)\n offset = channels_offset[None, :] + other_offset[:, None] * num_channels\n mask = (other_offset < numel_no_channels - pid * block_other)[:, None]\n x = tl.load(X_ptr + offset, mask=mask, other=0)\n y = tl.load(Y_ptr + offset, mask=mask, other=0)\n output = (x + y).to(tl.float32)\n tl.store(Out_ptr + offset, output, mask=mask)\n mean = tl.sum(output, axis=0) / numel_no_channels\n sqmean = tl.sum(output * output, axis=0) / numel_no_channels\n tl.atomic_add(Mean_ptr + channels_offset, mean)\n tl.atomic_add(Sqmean_ptr + channels_offset, sqmean)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/addition.py" }, { "uuid": "221c6145-dd84-45c7-9c0e-18b5a05dcdca", "file_name": "complex_rnn.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/complex_rnn.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef bwd_sequential_scan_complex(grad_output_real, grad_output_imag, v_real,\n v_imag, f_real, f_imag, hidden_real, hidden_imag, B, L, C, BLOCK_M: tl.\n constexpr):\n offset_b = tl.program_id(0)\n if offset_b >= B:\n return\n offset_n = tl.program_id(1)\n ptr = tl.arange(0, BLOCK_M) + offset_b * L * C + (L - 1\n ) * C + offset_n * BLOCK_M\n grad_h_real = tl.zeros([BLOCK_M], dtype=tl.float32)\n grad_h_imag = tl.zeros([BLOCK_M], dtype=tl.float32)\n for time_step in range(L - 1, -1, -1):\n grad_real = tl.load(grad_output_real + ptr).to(tl.float32)\n grad_imag = tl.load(grad_output_imag + ptr).to(tl.float32)\n grad_h_real += grad_real\n grad_h_imag += grad_imag\n decay_real = tl.load(f_real + ptr).to(tl.float32)\n decay_imag = tl.load(f_imag + ptr).to(tl.float32)\n h_real = tl.load(hidden_real + ptr - C, mask=ptr >= offset_b * L *\n C + C, other=0.0).to(tl.float32)\n h_imag = tl.load(hidden_imag + ptr - C, mask=ptr >= offset_b * L *\n C + C, other=0.0).to(tl.float32)\n grad_f_real = grad_h_real * h_real + grad_h_imag * h_imag\n grad_f_imag = grad_h_imag * h_real - grad_h_real * h_imag\n tl.store(f_real + ptr, grad_f_real.to(f_real.dtype.element_ty))\n tl.store(f_imag + ptr, grad_f_imag.to(f_real.dtype.element_ty))\n tl.store(v_real + ptr, grad_h_real.to(v_real.dtype.element_ty))\n tl.store(v_imag + ptr, grad_h_imag.to(v_real.dtype.element_ty))\n grad_h_real_new = grad_h_real * decay_real + grad_h_imag * decay_imag\n grad_h_imag_new = grad_h_imag * decay_real - grad_h_real * decay_imag\n grad_h_real = grad_h_real_new\n grad_h_imag = grad_h_imag_new\n ptr -= C\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/complex_rnn.py" }, { "uuid": "8974a9b5-f6d2-496c-b6b2-4fdfa904b752", "file_name": "dw_conv.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/dw_conv.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _DWConv_cl3d_impl(input_ptr, weight_ptr, output_ptr, H, W, D, H_stride,\n W_stride, ACCTYPE: tl.constexpr, channels: tl.constexpr, D_block: tl.\n constexpr):\n H_cell = tl.program_id(0)\n W_cell = tl.program_id(1)\n D_cell = tl.program_id(2)\n output_ptr += D_cell * D_block * channels\n input_ptr += D_cell * D_block * channels\n channels_offset = tl.arange(0, channels)\n channels_offset = tl.max_contiguous(tl.multiple_of(channels_offset,\n channels), channels)\n d_offset = tl.arange(0, D_block)\n near_offset = tl.arange(0, 4) - 1\n offset = d_offset[:, None, None] * channels + channels_offset[None, :, None\n ] + near_offset[None, None, :] * channels\n mask = d_offset[:, None, None] + near_offset[None, None, :\n ] < D - D_block * D_cell\n mask = mask and d_offset[:, None, None] + near_offset[None, None, :\n ] >= 0 - D_block * D_cell\n mask = mask and near_offset[None, None, :] != 2\n weight_offset = channels_offset[None, :, None] + tl.arange(0, 4)[None,\n None, :] * channels\n weight_mask = tl.arange(0, 4)[None, None, :] != 3\n weight_h0_w0 = tl.load(weight_ptr + weight_offset, mask=weight_mask,\n other=0.0)\n weight_h0_w1 = tl.load(weight_ptr + 3 * channels + weight_offset, mask=\n weight_mask, other=0.0)\n weight_h0_w2 = tl.load(weight_ptr + 6 * channels + weight_offset, mask=\n weight_mask, other=0.0)\n weight_h1_w0 = tl.load(weight_ptr + 9 * channels + weight_offset, mask=\n weight_mask, other=0.0)\n weight_h1_w1 = tl.load(weight_ptr + 12 * channels + weight_offset, mask\n =weight_mask, other=0.0)\n weight_h1_w2 = tl.load(weight_ptr + 15 * channels + weight_offset, mask\n =weight_mask, other=0.0)\n weight_h2_w0 = tl.load(weight_ptr + 18 * channels + weight_offset, mask\n =weight_mask, other=0.0)\n weight_h2_w1 = tl.load(weight_ptr + 21 * channels + weight_offset, mask\n =weight_mask, other=0.0)\n weight_h2_w2 = tl.load(weight_ptr + 24 * channels + weight_offset, mask\n =weight_mask, other=0.0)\n h0_w0 = tl.zeros([D_block, channels], dtype=ACCTYPE)\n h0_w1 = tl.zeros([D_block, channels], dtype=ACCTYPE)\n h1_w0 = tl.zeros([D_block, channels], dtype=ACCTYPE)\n h1_w1 = tl.zeros([D_block, channels], dtype=ACCTYPE)\n out_mask = d_offset[:, None] < D - D_block * D_cell\n out_offset = d_offset[:, None] * channels + channels_offset[None, :]\n H1_store = 2 * H_cell + 1 < H\n W1_store = 2 * W_cell + 1 < W\n load_all = (H_cell > 0 and H_cell < tl.cdiv(H, 2) - 1) and (W_cell > 0 and\n W_cell < tl.cdiv(W, 2) - 1)\n i = -1\n j = -1\n load_next = (2 * H_cell + i < H and 2 * H_cell + i >= 0) and (2 *\n W_cell + j < W and 2 * W_cell + j >= 0)\n tmp_input_ptr = input_ptr + (2 * H_cell + i) * H_stride + (2 * W_cell + j\n ) * W_stride\n x = tl.load(tmp_input_ptr + offset, mask=(load_all or load_next) and mask)\n for k in tl.static_range(0, 16):\n if k == 0:\n h0_w0 += tl.sum(x * weight_h0_w0, axis=2)\n elif k == 1:\n h0_w0 += tl.sum(x * weight_h1_w0, axis=2)\n h1_w0 += tl.sum(x * weight_h0_w0, axis=2)\n elif k == 2:\n h0_w0 += tl.sum(x * weight_h2_w0, axis=2)\n h1_w0 += tl.sum(x * weight_h1_w0, axis=2)\n elif k == 3:\n h1_w0 += tl.sum(x * weight_h2_w0, axis=2)\n elif k == 4:\n h0_w0 += tl.sum(x * weight_h0_w1, axis=2)\n h0_w1 += tl.sum(x * weight_h0_w0, axis=2)\n elif k == 5:\n h0_w0 += tl.sum(x * weight_h1_w1, axis=2)\n h0_w1 += tl.sum(x * weight_h1_w0, axis=2)\n h1_w0 += tl.sum(x * weight_h0_w1, axis=2)\n h1_w1 += tl.sum(x * weight_h0_w0, axis=2)\n elif k == 6:\n h0_w0 += tl.sum(x * weight_h2_w1, axis=2)\n h0_w1 += tl.sum(x * weight_h2_w0, axis=2)\n h1_w0 += tl.sum(x * weight_h1_w1, axis=2)\n h1_w1 += tl.sum(x * weight_h1_w0, axis=2)\n elif k == 7:\n h1_w0 += tl.sum(x * weight_h2_w1, axis=2)\n h1_w1 += tl.sum(x * weight_h2_w0, axis=2)\n elif k == 8:\n h0_w0 += tl.sum(x * weight_h0_w2, axis=2)\n h0_w1 += tl.sum(x * weight_h0_w1, axis=2)\n elif k == 9:\n h0_w0 += tl.sum(x * weight_h1_w2, axis=2)\n h0_w1 += tl.sum(x * weight_h1_w1, axis=2)\n h1_w0 += tl.sum(x * weight_h0_w2, axis=2)\n h1_w1 += tl.sum(x * weight_h0_w1, axis=2)\n elif k == 10:\n h0_w0 += tl.sum(x * weight_h2_w2, axis=2)\n h0_w1 += tl.sum(x * weight_h2_w1, axis=2)\n h1_w0 += tl.sum(x * weight_h1_w2, axis=2)\n h1_w1 += tl.sum(x * weight_h1_w1, axis=2)\n elif k == 11:\n h1_w0 += tl.sum(x * weight_h2_w2, axis=2)\n h1_w1 += tl.sum(x * weight_h2_w1, axis=2)\n elif k == 12:\n h0_w1 += tl.sum(x * weight_h0_w2, axis=2)\n elif k == 13:\n h0_w1 += tl.sum(x * weight_h1_w2, axis=2)\n h1_w1 += tl.sum(x * weight_h0_w2, axis=2)\n elif k == 14:\n h0_w1 += tl.sum(x * weight_h2_w2, axis=2)\n h1_w1 += tl.sum(x * weight_h1_w2, axis=2)\n else:\n h1_w1 += tl.sum(x * weight_h2_w2, axis=2)\n k_ = k + 1\n i = k_ % 4 - 1\n j = k_ // 4 - 1\n load_next = (2 * H_cell + i < H and 2 * H_cell + i >= 0) and (2 *\n W_cell + j < W and 2 * W_cell + j >= 0)\n tmp_input_ptr = input_ptr + (2 * H_cell + i) * H_stride + (2 *\n W_cell + j) * W_stride\n x = tl.load(tmp_input_ptr + offset, mask=(load_all or load_next) and\n mask)\n tmp_output_ptr = output_ptr + 2 * H_cell * H_stride + 2 * W_cell * W_stride\n tl.store(tmp_output_ptr + out_offset, h0_w0, mask=out_mask)\n tmp_output_ptr = output_ptr + 2 * H_cell * H_stride + (2 * W_cell + 1\n ) * W_stride\n tl.store(tmp_output_ptr + out_offset, h0_w1, mask=out_mask and W1_store)\n tmp_output_ptr = output_ptr + (2 * H_cell + 1\n ) * H_stride + 2 * W_cell * W_stride\n tl.store(tmp_output_ptr + out_offset, h1_w0, mask=out_mask and H1_store)\n tmp_output_ptr = output_ptr + (2 * H_cell + 1) * H_stride + (2 * W_cell + 1\n ) * W_stride\n tl.store(tmp_output_ptr + out_offset, h1_w1, mask=out_mask and (\n H1_store and W1_store))\n", "category": { "Functionality": [ "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/dw_conv.py" }, { "uuid": "570a1e21-423e-48b9-9625-0e664ec62aae", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BK', 'BV', 'USE_GK', 'USE_GV', 'USE_G'])\n@triton.jit\ndef fused_recurrent_fwd_kernel(q, k, v, g, gk, gv, o, h0, ht, offsets,\n scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, REVERSE:\n tl.constexpr, USE_G: tl.constexpr, USE_GK: tl.constexpr, USE_GV: tl.\n constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.\n constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.\n int64), tl.program_id(2).to(tl.int64)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + ((T - 1) * K if REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + ((T - 1) * K if REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n p_o = o + (i_k * B * H + i_nh) * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n if USE_G:\n p_g = g + i_nh * T + (T - 1 if REVERSE else 0)\n if USE_GK:\n p_gk = gk + i_nh * T * K + ((T - 1) * K if REVERSE else 0\n ) + i_k * BK + tl.arange(0, BK)\n if USE_GV:\n p_gv = gv + i_nh * T * V + ((T - 1) * V if REVERSE else 0\n ) + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_o = o + (i_k * all + bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n if USE_G:\n p_g = g + (bos + (T - 1 if REVERSE else 0)) * H + i_h\n if USE_GK:\n p_gk = gk + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n if USE_GV:\n p_gv = gv + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n mask_h = mask_k[None, :] & mask_v[:, None]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n if USE_GK:\n b_gk = tl.load(p_gk, mask=mask_k, other=0).to(tl.float32)\n b_h = b_h * tl.exp(b_gk[None, :])\n if USE_GV:\n b_gv = tl.load(p_gv, mask=mask_v, other=0).to(tl.float32)\n b_h = b_h * tl.exp(b_gv[:, None])\n if USE_G:\n b_g = tl.load(p_g).to(tl.float32)\n b_h = b_h * tl.exp(b_g)\n b_h += b_k[None, :] * b_v[:, None]\n b_o = b_h * b_q[None, :]\n b_o = tl.sum(b_o, axis=1)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), mask=mask_v)\n p_q += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_k += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_o += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n if USE_GK:\n p_gk += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n if USE_GV:\n p_gv += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n if USE_G:\n p_g += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H)\n if STORE_FINAL_STATE:\n p_ht = ht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/fused_recurrent.py" }, { "uuid": "a44d6bb9-9a39-4506-bfa3-b7ebd9fa2abb", "file_name": "test_matmul.py", "repo_name": "triton-lang/kernels", "file_path": "test/test_matmul.py", "commit_hash": "eeeebdd8be7d13629de22d600621e6234057eed3", "starcount": 0, "input": "@triton.jit\ndef kernel(Y, X, N, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(0)\n offs = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offs < N\n x = tl.load(X + offs, mask=mask)\n tl.store(Y + offs, x, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/kernels/blob/eeeebdd8be7d13629de22d600621e6234057eed3/test/test_matmul.py" }, { "uuid": "ddf1f588-9692-47ab-b525-919d573b3c8a", "file_name": "softmax.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/softmax.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_forward(out_ptr, inp_ptr, inp_stride, out_stride,\n seq_len, is_causal, BLOCK_SIZE: tl.constexpr, num_warps: tl.constexpr):\n batch_idx = tl.program_id(0)\n batch_start_ptr = inp_ptr + batch_idx * inp_stride\n pos_offsets = tl.arange(0, BLOCK_SIZE)\n batch_ptrs = batch_start_ptr + pos_offsets\n valid_mask = pos_offsets < seq_len\n logits = tl.load(batch_ptrs, mask=valid_mask, other=-float('inf'))\n if is_causal:\n attn_mask = pos_offsets > batch_idx % seq_len\n logits = logits + tl.where(attn_mask, -float('inf'), 0.0)\n shifted_logits = logits - tl.max(logits, axis=0)\n exp_logits = tl.exp(shifted_logits)\n sum_exp = tl.sum(exp_logits, axis=0)\n probs = exp_logits / sum_exp\n out_batch_ptr = out_ptr + batch_idx * out_stride\n out_ptrs = out_batch_ptr + pos_offsets\n tl.store(out_ptrs, probs, mask=valid_mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Latency Sensitive" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/softmax.py" }, { "uuid": "54ba9a77-a828-4180-a238-3b81400afbb1", "file_name": "1_linear_trident_debug.py", "repo_name": "gmgu/study-triton", "file_path": "toy_example/1_linear_trident_debug.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@staticmethod\n@util.autotune(configs=linear_configs(), key=['m_size', 'n_size', 'k_size'])\n@triton.jit\ndef forward(output_ptr: tl.tensor, input_ptr: tl.tensor, weight_ptr: tl.\n tensor, bias_ptr: tl.tensor, m_size: tl.int32, n_size: tl.int32, k_size:\n tl.int32, input_batch_stride: tl.int32, input_m_stride: tl.int32,\n input_k_stride: tl.int32, weight_n_stride: tl.int32, weight_k_stride:\n tl.int32, use_accelerator: tl.constexpr, dtype: tl.constexpr,\n m_block_size: tl.constexpr, n_block_size: tl.constexpr, k_block_size:\n tl.constexpr):\n pid = tl.program_id(0)\n num_m_blocks = tl.cdiv(m_size, m_block_size)\n num_n_blocks = tl.cdiv(n_size, n_block_size)\n num_blocks = num_m_blocks * num_n_blocks\n batch = pid // num_blocks\n block = pid % num_blocks\n m_block = block // num_n_blocks\n n_block = block % num_n_blocks\n m_offset = m_block * m_block_size\n n_offset = n_block * n_block_size\n output = language.Linear.forward(input_ptr + batch * input_batch_stride,\n weight_ptr, bias_ptr, m_size, n_size, k_size, input_m_stride,\n input_k_stride, weight_n_stride, weight_k_stride, m_offset,\n n_offset, use_accelerator, m_block_size, n_block_size, k_block_size,\n dtype)\n output_block_ptr = tl.make_block_ptr(output_ptr + batch * m_size *\n n_size, shape=(m_size, n_size), strides=(n_size, 1), offsets=(\n m_offset, n_offset), block_shape=(m_block_size, n_block_size),\n order=(1, 0))\n tl.store(output_block_ptr, output, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/toy_example/1_linear_trident_debug.py" }, { "uuid": "171aad36-63cb-44be-831f-54745f85e0d3", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/hgrn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_hgrn_fwd_kernel_o(gc, o, s_b, s_t, s_d, T: tl.constexpr, D: tl.\n constexpr, BT: tl.constexpr, BD: tl.constexpr):\n i_d, i_b = tl.program_id(0), tl.program_id(1)\n o_d = i_d * BD + tl.arange(0, BD)\n mask = o_d < D\n for i_t in range(1, tl.cdiv(T, BT)):\n p_gc = tl.make_block_ptr(gc + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT, i_d * BD), (BT, BD), (1, 0))\n p_o = tl.make_block_ptr(o + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT, i_d * BD), (BT, BD), (1, 0))\n b_h0 = tl.load(o + i_b * T * D + i_t * BT * D - D + o_d, mask=mask,\n other=0).to(tl.float32)\n b_gc = tl.load(p_gc, boundary_check=(0, 1)).to(tl.float32)\n b_o = tl.load(p_o, boundary_check=(0, 1)).to(tl.float32)\n b_o = b_o + tl.exp(b_gc) * b_h0[None, :]\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/hgrn/chunk.py" }, { "uuid": "bff66182-3082-44d8-ab45-db96e371884d", "file_name": "activation.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/activation.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@triton.jit\ndef relu(x):\n return tl.max(x, 0.0)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/activation.py" }, { "uuid": "18871690-73de-4fa7-8cc1-99b5248781fc", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef d_leacky_relu(x):\n return tl.where(x >= 0, 1.0, 100.0)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "be4722dd-52dd-4663-8146-0f41c82e92f7", "file_name": "y_8.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_8.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef eighth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor,\n block_size: tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.\n constexpr, col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST000 = 1.12741169450483\n CONST003 = 4.12310562561766\n CONST004 = 4.50964677801932\n CONST006 = 6.76447016702898\n CONST007 = 1.69594242329302\n CONST008 = 1.88707052233084\n CONST010 = 2.58397773170915\n CONST011 = 13.136713523081\n CONST012 = 13.136713523081\n CONST014 = -489.184589393411\n CONST015 = 24.738633753706\n CONST017 = 24.738633753706\n CONST019 = 48.9184589393411\n CONST020 = 48.5105296237322\n CONST021 = 51.744564931981\n CONST024 = 65.6835676154051\n CONST025 = 67.8376969317208\n CONST029 = 97.0210592474644\n CONST030 = -6.78376969317208\n CONST031 = 103.489129863962\n CONST032 = -407.026181590325\n CONST033 = 108.231522672464\n CONST035 = 110.066532613517\n CONST036 = 110.066532613517\n CONST037 = -396.284809689477\n CONST040 = -361.756882439281\n CONST041 = -1.88707052233084\n CONST042 = 158.513923875791\n CONST045 = 180.87844121964\n CONST046 = 194.042118494929\n CONST047 = -12.2296147348353\n CONST048 = 203.513090795162\n CONST050 = 216.463045344927\n CONST051 = 217.054129463568\n CONST052 = 216.463045344927\n CONST053 = -6.78376969317208\n CONST054 = -271.350787726883\n CONST055 = 244.592294696706\n CONST056 = 244.592294696706\n CONST057 = -262.734270461621\n CONST058 = -258.722824659905\n CONST061 = -217.054129463568\n CONST062 = -210.187416369296\n CONST063 = -175.156180307747\n CONST064 = -162.81047263613\n CONST066 = -144.702752975712\n CONST067 = -129.877827206956\n CONST068 = -129.361412329953\n CONST070 = -108.231522672464\n CONST071 = -108.231522672464\n CONST072 = -87.5780901538735\n CONST073 = -3.23403530824881\n CONST074 = -72.3513764878561\n CONST075 = -70.0624721230988\n CONST076 = -65.6835676154052\n CONST077 = -61.1480736741764\n CONST078 = -61.1480736741764\n CONST079 = -57.7234787586472\n CONST080 = -57.7234787586472\n CONST081 = -51.744564931981\n CONST082 = -48.5105296237322\n CONST083 = -40.5868210021738\n CONST084 = -39.4101405692431\n CONST085 = -40.7026181590325\n CONST086 = -36.0771742241545\n CONST087 = -36.0771742241545\n CONST088 = -26.4189873126318\n CONST089 = -20.6718218536732\n CONST090 = -528.379746252636\n CONST091 = -16.9594242329302\n CONST092 = -13.136713523081\n CONST093 = -12.2296147348353\n CONST094 = -11.3224231339851\n CONST095 = -10.3359109268366\n CONST096 = -9.70210592474644\n CONST097 = -11.3224231339851\n CONST098 = -13.5289403340579\n CONST099 = -6.78376969317208\n CONST100 = -13.5289403340579\n CONST101 = -13.136713523081\n CONST102 = -3.23403530824881\n CONST103 = -1.61701765412441\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR02 = VAR06 * VAR06\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR11 = VAR15 * VAR16\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR20 = VAR24 * VAR24\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n Y00 = (-CONST066 * VAR05 * VAR25 + CONST066 * VAR07 * VAR23 + CONST089 *\n VAR03 * z - CONST089 * VAR21 * x)\n Y01 = y * (CONST040 * VAR07 * VAR24 + CONST051 * VAR05 * VAR26 - \n CONST074 * VAR22 * x + CONST095 * VAR03)\n Y02 = CONST097 * VAR03 * z + VAR05 * (CONST042 * VAR17 * z - CONST088 *\n VAR25) + VAR07 * (-CONST088 * VAR23 + CONST090 * VAR17 * VAR25) + x * (\n CONST042 * VAR17 * VAR23 + CONST094 * VAR21)\n Y03 = VAR16 * (CONST014 * VAR07 * VAR26 + CONST019 * VAR05 + CONST055 *\n VAR24 * x) + y * (CONST035 * VAR05 * VAR26 + CONST077 * VAR22 * x -\n CONST078 * VAR07 * VAR24 + CONST093 * VAR03)\n Y04 = CONST099 * VAR03 * z + VAR05 * (-CONST064 * VAR17 * z + CONST099 *\n VAR25) + VAR07 * (-CONST053 * VAR23 + CONST054 * VAR15 * z) + x * (\n -CONST053 * VAR21 - CONST054 * VAR15 * VAR25 + CONST064 * VAR17 * VAR23\n )\n Y05 = VAR14 * (-CONST062 * VAR26 * x + CONST075 * VAR07) + VAR16 * (\n CONST057 * VAR24 * x + CONST063 * VAR07 * VAR26 - CONST072 * VAR05\n ) + y * (CONST011 * VAR05 * VAR26 + CONST024 * VAR07 * VAR24 - \n CONST084 * VAR22 * x + CONST092 * VAR03)\n Y06 = CONST102 * VAR03 * z + VAR05 * (CONST029 * VAR17 * z + CONST096 *\n VAR25) + VAR07 * (CONST046 * VAR17 * VAR25 + CONST058 * VAR15 * z +\n CONST096 * VAR23) + x * (CONST029 * VAR17 * VAR23 + CONST031 *\n VAR13 * z + CONST058 * VAR15 * VAR25 + CONST102 * VAR21)\n Y07 = CONST098 * VAR03 * y + VAR05 * (CONST033 * VAR16 + CONST083 *\n VAR26 * y) + VAR07 * (CONST050 * VAR16 * VAR26 + CONST067 * VAR14 +\n CONST083 * VAR24 * y) + x * (CONST015 * VAR12 + CONST067 * VAR14 *\n VAR26 - CONST070 * VAR16 * VAR24 + CONST098 * VAR22 * y)\n Y08 = (CONST000 * VAR02 + CONST000 * VAR20 + CONST003 * VAR11 - \n CONST070 * VAR15 * VAR24 + CONST080 * VAR13 * VAR26 + CONST087 *\n VAR17 * VAR22 + VAR04 * (CONST004 * VAR26 + CONST086 * VAR17) + \n VAR06 * (CONST006 * VAR24 - CONST070 * VAR15 + CONST071 * VAR17 *\n VAR26) + VAR08 * (CONST004 * VAR22 + CONST050 * VAR15 * VAR26 + \n CONST070 * VAR17 * VAR24 + CONST079 * VAR13))\n Y09 = CONST098 * VAR21 * y + VAR23 * (CONST033 * VAR16 + CONST083 *\n VAR08 * y) + VAR25 * (CONST052 * VAR08 * VAR16 + CONST067 * VAR14 +\n CONST083 * VAR06 * y) + z * (CONST017 * VAR12 + CONST033 * VAR06 *\n VAR16 + CONST067 * VAR08 * VAR14 + CONST100 * VAR04 * y)\n Y10 = (CONST073 * VAR08 * VAR22 - CONST102 * VAR04 * VAR26 - CONST103 *\n VAR02 + CONST103 * VAR20 + VAR13 * (CONST021 * VAR26 + CONST081 *\n VAR08) + VAR15 * (-CONST068 * VAR06 + CONST068 * VAR24) + VAR17 * (\n CONST020 * VAR08 * VAR24 + CONST020 * VAR22 + CONST082 * VAR04 + \n CONST082 * VAR06 * VAR26))\n Y11 = VAR14 * (CONST062 * VAR08 * z - CONST075 * VAR25) + VAR16 * (-\n CONST057 * VAR06 * z - CONST063 * VAR08 * VAR25 + CONST072 * VAR23\n ) + y * (CONST012 * VAR21 + CONST076 * VAR06 * VAR25 + CONST084 *\n VAR04 * z + CONST101 * VAR08 * VAR23)\n Y12 = (CONST007 * VAR02 + CONST007 * VAR20 + CONST030 * VAR04 * VAR26 +\n CONST053 * VAR08 * VAR22 + CONST091 * VAR06 * VAR24 + VAR15 * (\n CONST025 * VAR06 + CONST025 * VAR24 + CONST032 * VAR08 * VAR26) + \n VAR17 * (CONST048 * VAR06 * VAR26 + CONST048 * VAR08 * VAR24 + \n CONST085 * VAR04 + CONST085 * VAR22))\n Y13 = VAR16 * (CONST014 * VAR08 * VAR25 + CONST019 * VAR23 + CONST056 *\n VAR06 * z) + y * (CONST036 * VAR08 * VAR23 + CONST047 * VAR21 - \n CONST077 * VAR06 * VAR25 + CONST078 * VAR04 * z)\n Y14 = (CONST008 * VAR02 + CONST041 * VAR20 + CONST088 * VAR04 * VAR26 -\n CONST088 * VAR08 * VAR22 + VAR17 * (-CONST037 * VAR06 * VAR26 + \n CONST037 * VAR08 * VAR24 + CONST088 * VAR04 - CONST088 * VAR22))\n Y15 = y * (-CONST040 * VAR06 * VAR25 + CONST061 * VAR08 * VAR23 + \n CONST074 * VAR04 * z - CONST095 * VAR21)\n Y16 = (CONST010 * VAR02 + CONST010 * VAR20 + CONST045 * VAR06 * VAR24 +\n CONST074 * VAR04 * VAR26 + CONST074 * VAR08 * VAR22)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n tl.store(output_ptr + output_row_offset + 9, Y09, mask=\n output_row_offset + 9 < output_numel)\n tl.store(output_ptr + output_row_offset + 10, Y10, mask=\n output_row_offset + 10 < output_numel)\n tl.store(output_ptr + output_row_offset + 11, Y11, mask=\n output_row_offset + 11 < output_numel)\n tl.store(output_ptr + output_row_offset + 12, Y12, mask=\n output_row_offset + 12 < output_numel)\n tl.store(output_ptr + output_row_offset + 13, Y13, mask=\n output_row_offset + 13 < output_numel)\n tl.store(output_ptr + output_row_offset + 14, Y14, mask=\n output_row_offset + 14 < output_numel)\n tl.store(output_ptr + output_row_offset + 15, Y15, mask=\n output_row_offset + 15 < output_numel)\n tl.store(output_ptr + output_row_offset + 16, Y16, mask=\n output_row_offset + 16 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_8.py" }, { "uuid": "1af50369-d016-482c-9e4e-234c967c3ae6", "file_name": "dropout.py", "repo_name": "daemyung/practice-triton", "file_path": "dropout.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@staticmethod\n@triton.jit\ndef backward(grad_input_ptr, grad_output_ptr, output_ptr, size, p,\n block_size: tl.constexpr):\n pid = tl.program_id(0)\n offset = pid * block_size\n grad_input_block_ptr = tl.make_block_ptr(grad_input_ptr, shape=(size,),\n strides=(1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n grad_output_block_ptr = tl.make_block_ptr(grad_output_ptr, shape=(size,\n ), strides=(1,), offsets=(offset,), block_shape=(block_size,),\n order=(0,))\n output_block_ptr = tl.make_block_ptr(output_ptr, shape=(size,), strides\n =(1,), offsets=(offset,), block_shape=(block_size,), order=(0,))\n grad_output = tl.load(grad_output_block_ptr, boundary_check=(0,))\n output = tl.load(output_block_ptr, boundary_check=(0,))\n condition = output > 0.0\n grad_input = tl.where(condition, grad_output * (1 / (1 - p)), 0.0)\n tl.store(grad_input_block_ptr, grad_input, boundary_check=(0,))\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/dropout.py" }, { "uuid": "b2c5e42d-4d18-4d41-be89-0859575d1a55", "file_name": "lightningAttention2.py", "repo_name": "Computational-Machine-Intelligence/LeetDecoding", "file_path": "leetDecoding/methods/lightningAttention2.py", "commit_hash": "1b545c2f5bacc155255250d1f70ac9484744559a", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel_without_s(Q, K, V, Out, b: tl.constexpr, h: tl.constexpr, n:\n tl.constexpr, d: tl.constexpr, e: tl.constexpr, BLOCK: tl.constexpr,\n NUM_BLOCK: tl.constexpr, BLOCK_MODEL: tl.constexpr):\n off_bh = tl.program_id(0)\n off_h = off_bh % h\n off_e = tl.program_id(1)\n qk_offset = off_bh * n * d\n v_offset = off_bh * n * e\n o_offset = off_bh * n * e\n e_offset = off_e * BLOCK_MODEL\n Q_block_ptr = Q + qk_offset + tl.arange(0, d)[None, :]\n K_trans_block_ptr = K + qk_offset + tl.arange(0, d)[:, None]\n V_block_ptr = V + v_offset + e_offset + tl.arange(0, BLOCK_MODEL)[None, :]\n O_block_ptr = Out + o_offset + e_offset + tl.arange(0, BLOCK_MODEL)[None, :\n ]\n off_block = tl.arange(0, BLOCK)\n index = off_block[:, None] - off_block[None, :]\n diag_decay = tl.where(index >= 0, 1, 0)\n kv = tl.zeros([d, BLOCK_MODEL], dtype=tl.float32)\n for i in range(NUM_BLOCK):\n q = tl.load(Q_block_ptr + off_block[:, None] * d, mask=off_block[:,\n None] < n, other=0.0).to(tl.float32)\n k_trans = tl.load(K_trans_block_ptr + off_block[None, :] * d, mask=\n off_block[None, :] < n, other=0.0).to(tl.float32)\n v = tl.load(V_block_ptr + off_block[:, None] * e, mask=off_block[:,\n None] < n, other=0.0).to(tl.float32)\n qk = tl.dot(q, k_trans) * diag_decay\n o_intra = tl.dot(qk, v)\n o_inter = tl.dot(q, kv)\n o = o_intra + o_inter\n tl.store(O_block_ptr + off_block[:, None] * e, o.to(O_block_ptr.\n dtype.element_ty), mask=off_block[:, None] < n)\n kv = kv + tl.dot(k_trans, v)\n off_block += BLOCK\n", "category": { "Functionality": [ "Attention Mechanisms", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Computational-Machine-Intelligence/LeetDecoding/blob/1b545c2f5bacc155255250d1f70ac9484744559a/leetDecoding/methods/lightningAttention2.py" }, { "uuid": "832c1247-97a6-4951-b770-b50148fc3427", "file_name": "test_inductor.py", "repo_name": "triton-lang/kernels", "file_path": "test/test_inductor.py", "commit_hash": "eeeebdd8be7d13629de22d600621e6234057eed3", "starcount": 0, "input": "@triton.jit\ndef triton_(in_out_ptr0, in_out_ptr1, in_ptr0, in_ptr1, in_ptr2, in_ptr3,\n xnumel, rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):\n xnumel = 512\n rnumel = 4096\n xoffset = tl.program_id(0) * XBLOCK\n xindex = xoffset + tl.arange(0, XBLOCK)[:, None]\n xmask = xindex < xnumel\n rbase = tl.arange(0, RBLOCK)[None, :]\n x3 = xindex\n x0 = xindex % 64\n tmp1 = tl.load(in_ptr0 + x0, xmask)\n tmp3 = tl.load(in_ptr1 + x0, xmask)\n tmp11 = tl.load(in_ptr2 + x0, xmask)\n tmp13 = tl.load(in_ptr3 + x0, xmask)\n _tmp17 = tl.zeros([XBLOCK, RBLOCK], tl.float32) + 0\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r2 = rindex\n tmp0 = tl.load(in_out_ptr0 + (r2 + 4096 * x3), rmask & xmask,\n eviction_policy='evict_last', other=0)\n tmp2 = tmp0 - tmp1\n tmp4 = 1e-05\n tmp5 = tmp3 + tmp4\n tmp6 = tl.sqrt(tmp5)\n tmp7 = 1 / tmp6\n tmp8 = 1.0\n tmp9 = tmp7 * tmp8\n tmp10 = tmp2 * tmp9\n tmp12 = tmp10 * tmp11\n tmp14 = tmp12 + tmp13\n _tmp17 = tl.where(rmask & xmask, _tmp17 + tmp14, _tmp17)\n tl.store(in_out_ptr0 + (r2 + 4096 * x3 + tl.zeros([XBLOCK, RBLOCK],\n tl.int32)), tmp14, rmask & xmask)\n tmp17 = tl.sum(_tmp17, 1)[:, None]\n tmp18 = 4096.0\n tmp19 = tmp17 / tmp18\n tl.store(in_out_ptr1 + (x3 + tl.zeros([XBLOCK, 1], tl.int32)), tmp19, xmask\n )\n", "category": { "Functionality": [ "Elementwise Operations", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/kernels/blob/eeeebdd8be7d13629de22d600621e6234057eed3/test/test_inductor.py" }, { "uuid": "a2322d06-016c-4be9-920f-2be617b54e4c", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_local_cumsum_scalar_kernel(s, o, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, BT: tl.constexpr, HEAD_FIRST: tl.constexpr,\n USE_OFFSETS: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n p_o = tl.make_block_ptr(o + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n else:\n p_s = tl.make_block_ptr(s + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n p_o = tl.make_block_ptr(o + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n b_s = tl.load(p_s, boundary_check=(0,)).to(tl.float32)\n b_o = tl.cumsum(b_s, axis=0)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency", "Single Instance", "Latency Sensitive" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "84f5d3ce-86d9-4bd2-8886-537018fb3ecc", "file_name": "linear.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/linear.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _ReLULinearAdd(input_ptr, weight_ptr, add_ptr, output_ptr,\n numel_no_channels, in_channels: tl.constexpr, out_channels: tl.\n constexpr, D_block: tl.constexpr, _ILP: tl.constexpr):\n pid = tl.program_id(0)\n input_ptr += pid * _ILP * in_channels * D_block\n add_ptr += pid * _ILP * out_channels * D_block\n output_ptr += pid * _ILP * out_channels * D_block\n in_channels_offset = tl.arange(0, in_channels)\n out_channels_offset = tl.arange(0, out_channels)\n d_offset = tl.arange(0, D_block)\n in_offset = d_offset[:, None] * in_channels + in_channels_offset[None, :]\n out_offset = d_offset[:, None] * out_channels + out_channels_offset[None, :\n ]\n weight_offset = in_channels_offset[:, None\n ] * out_channels + out_channels_offset[None, :]\n weight = tl.load(weight_ptr + weight_offset)\n for i in tl.static_range(0, _ILP):\n mask = d_offset[:, None] < numel_no_channels - (pid * _ILP + i\n ) * D_block\n x = tl.load(input_ptr + in_offset, mask=mask, other=0)\n add = tl.load(add_ptr + out_offset, mask=mask, other=0)\n x = tl.maximum(x, 0.0).to(tl.float16)\n output = tl.dot(x, weight, out_dtype=tl.float32, allow_tf32=True).to(tl\n .float16) + add\n tl.store(output_ptr + out_offset, output, mask=mask)\n input_ptr += in_channels * D_block\n output_ptr += out_channels * D_block\n add_ptr += out_channels * D_block\n", "category": { "Functionality": [ "Activation Functions", "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/linear.py" }, { "uuid": "84cd1cd2-9462-473a-bb44-5b276d47af20", "file_name": "bgmv_shrink.py", "repo_name": "IBM/vllm", "file_path": "vllm/lora/ops/bgmv_shrink.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _bgmv_shrink_kernel(input_ptr, lora_ptr, out_ptr, N, K, lora_indices,\n scaling, xm_stride, xk_stride, l0_stride, lora_k_stride, lora_n_stride,\n cm_stride, cn_stride, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,\n SPLIT_K: tl.constexpr):\n \"\"\"\n GroupGEMV, additionally, introducing SPLIT-K can improve large hidden_size's\n performance\n \"\"\"\n pid_sk = tl.program_id(axis=0)\n cur_batch = tl.program_id(axis=1)\n lora_index = tl.load(lora_indices + cur_batch)\n if lora_index == -1:\n return\n offset_n = tl.arange(0, BLOCK_N)\n offset_k = tl.arange(0, BLOCK_K) + pid_sk * BLOCK_K\n a_ptr = input_ptr + cur_batch * xm_stride\n b_ptr = lora_ptr + l0_stride * lora_index\n accumulator = tl.zeros((BLOCK_N,), dtype=tl.float32)\n for k in range(0, K, BLOCK_K * SPLIT_K):\n current_k = k + offset_k\n current_k_c = tl.max_contiguous(current_k, BLOCK_K)\n tiled_a = tl.load(a_ptr + current_k_c, mask=current_k < K, other=0.0)\n b_ptr_mask = (offset_n[:, None] < N) & (current_k[None, :] < K)\n tiled_b = tl.load(b_ptr + offset_n[:, None] * lora_k_stride + \n current_k[None, :] * lora_n_stride, mask=b_ptr_mask, other=0.0)\n accumulator += tl.sum(tiled_a * tiled_b, 1)\n accumulator *= scaling\n offset_cn = tl.arange(0, BLOCK_N)\n c_ptr = out_ptr + cur_batch * cm_stride + offset_cn * cn_stride\n c_mask = offset_cn < N\n if SPLIT_K == 1:\n tl.store(c_ptr, accumulator, mask=c_mask)\n else:\n tl.atomic_add(c_ptr, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/lora/ops/bgmv_shrink.py" }, { "uuid": "7aa394e6-e22f-4bc1-adb7-e9d132c66ff6", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_gated_delta_rule_fwd_kernel_prepare_dv(q, k, g, do, dv, offsets,\n indices, scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_A += tl.dot(b_k, b_q, allow_tf32=False)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n else:\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_A = b_A * tl.exp(b_g[None, :] - b_g[:, None]) * scale\n b_A = tl.where(tl.arange(0, BT)[:, None] <= tl.arange(0, BT)[None, :],\n b_A, 0).to(do.dtype.element_ty)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dv = tl.dot(b_A, b_do, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/chunk.py" }, { "uuid": "9945be86-5f3d-4188-944a-1ea2180faf6f", "file_name": "RzLinearForward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearForward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 32}, num_stages=5, num_warps=2),\n triton.Config({'BLOCK_SIZE_M': 16, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 16,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 16, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 16, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 16, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 16, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4)],\n key=['M', 'N', 'K'])\n@triton.jit\ndef rz_linear_forward_kernel_tf32(a_ptr, b_ptr, c_ptr, init_factor, M, N, K,\n H, stride_am, stride_ak, stride_cm, stride_cn, R7: int, R6: int, R5:\n int, R4: int, R3: int, R2: int, R1: int, R0: int, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE: tl.constexpr):\n rz_linear_forward_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=c_ptr,\n init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=stride_am,\n stride_ak=stride_ak, stride_cm=stride_cm, stride_cn=stride_cn,\n allow_tf32=True, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1,\n R0=R0, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=BLOCK_SIZE_N,\n BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearForward.py" }, { "uuid": "7c4f95a3-8744-4afb-a957-f1b3a27eedcc", "file_name": "gemm_streamk_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32)], key=['M', 'N', 'K'])\n@triton.jit\ndef full_tiles(a_ptr, b_ptr, c_ptr, M: tl.constexpr, N: tl.constexpr, K: tl\n .constexpr, stride_am: tl.constexpr, stride_ak: tl.constexpr, stride_bk:\n tl.constexpr, stride_bn: tl.constexpr, stride_cm: tl.constexpr,\n stride_cn: tl.constexpr, streamk_tiles, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr):\n tile_id = tl.program_id(axis=0) + streamk_tiles\n if GROUP_SIZE_M > 0:\n pid_m, pid_n = swizzle_tile(tile_id, M, N, K, BLOCK_SIZE_M,\n BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M)\n else:\n pid_m, pid_n = linear_tile(tile_id, M, N, K, BLOCK_SIZE_M,\n BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M)\n a_block_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n acc = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n acc += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n tl.store(c_block_ptr, acc, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py" }, { "uuid": "f6db9b7b-2ee0-44bc-9725-7ba9d1cba3c0", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BK', 'BT'])\n@triton.jit\ndef chunk_gla_fwd_A_kernel_intra_sub_intra(q, k, g, A, offsets, indices,\n scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.\n constexpr, BC: tl.constexpr, BK: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_i, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_j = i_i\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if i_t * BT + i_i * BC >= T:\n return\n o_i = tl.arange(0, BC)\n o_k = tl.arange(0, BK)\n m_k = o_k < K\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n if HEAD_FIRST:\n o_A = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_j * BC\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, 0), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, 0), (BC, BK), (1, 0))\n p_k = tl.max_contiguous(tl.multiple_of(k + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(g + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n else:\n o_A = (bos + i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * H * BT + i_h * BT + i_j * BC\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, 0), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, 0), (BC, BK), (1, 0))\n p_k = tl.max_contiguous(tl.multiple_of(k + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_k = tl.load(p_k, mask=m_k, other=0).to(tl.float32)\n b_gk = tl.load(p_gk, mask=m_k, other=0).to(tl.float32)\n b_A = tl.sum(b_q * b_k[None, :] * tl.exp(b_g - b_gk[None, :]), 1)\n b_A = tl.where(o_i >= j, b_A * scale, 0.0)\n tl.store(A + o_A + j, b_A, mask=m_A)\n p_k += K if HEAD_FIRST else H * K\n p_gk += K if HEAD_FIRST else H * K\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "3db707e0-ddf4-4545-8ffd-260cfb5291c6", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N': 32}, num_stages=2, num_warps=8),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=2, num_warps=8), triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_N':\n 32}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N': 32}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_N':\n 32}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': 32}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_N': \n 32}, num_stages=2, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef rz_linear_backward_input_grad_kernel_tf32(a_ptr, b_ptr, c_ptr,\n init_factor, M, N, K, H, stride_am, stride_an, stride_cm, stride_ck, R7:\n int, R6: int, R5: int, R4: int, R3: int, R2: int, R1: int, R0: int,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_backward_input_grad_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=\n c_ptr, init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=\n stride_am, stride_an=stride_an, stride_cm=stride_cm, stride_ck=\n stride_ck, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1, R0=R0,\n allow_tf32=True, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=\n BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Matrix Multiplication", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "c3518964-a1ec-4489-8219-cf05cf366207", "file_name": "fused_softmax.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/fused_softmax.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'threads_per_warp': 32}, num_warps\n =32), triton.Config({'threads_per_warp': 32}, num_warps=16), triton.\n Config({'threads_per_warp': 32}, num_warps=8), triton.Config({\n 'threads_per_warp': 32}, num_warps=4), triton.Config({\n 'threads_per_warp': 16}, num_warps=64), triton.Config({\n 'threads_per_warp': 16}, num_warps=32), triton.Config({\n 'threads_per_warp': 16}, num_warps=16), triton.Config({\n 'threads_per_warp': 16}, num_warps=8), triton.Config({\n 'threads_per_warp': 16}, num_warps=4)], key=['BLOCK_SIZE_X',\n 'BLOCK_SIZE_Y'])\n@triton.jit\ndef softmax_kernel(output_ptr, input_ptr, input_row_stride,\n output_row_stride, n_cols, BLOCK_SIZE_X: tl.constexpr, BLOCK_SIZE_Y: tl\n .constexpr):\n row_idx = tl.program_id(0) * BLOCK_SIZE_Y\n row_start_ptr = input_ptr + row_idx * input_row_stride\n col_offsets = tl.arange(0, BLOCK_SIZE_X)\n row_offsets = tl.arange(0, BLOCK_SIZE_Y)\n offsets = col_offsets[None, :] + row_offsets[:, None] * input_row_stride\n input_ptrs = row_start_ptr + offsets\n mask = col_offsets[None, :] < n_cols\n row = tl.load(input_ptrs, mask=mask, other=-float('inf'))\n row_minus_max = row - tl.max(row, axis=1)[:, None]\n numerator = tl.exp(row_minus_max)\n denominator = tl.sum(numerator, axis=1)[:, None]\n softmax_output = numerator / denominator\n output_row_start_ptr = output_ptr + row_idx * output_row_stride\n output_ptrs = output_row_start_ptr + offsets\n tl.store(output_ptrs, softmax_output, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/fused_softmax.py" }, { "uuid": "faeab38a-3414-4adf-b42a-0d11426d5131", "file_name": "test_triton.py", "repo_name": "apd10/RzLinear", "file_path": "python/tests/test_triton.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef triton_tn_kernel(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,\n stride_bm, stride_bn, stride_ck, stride_cn, allow_tf32: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A^T x B.\n A has shape (M, K), B has shape (M, N) and C has shape (K, N)\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_k = tl.cdiv(K, BLOCK_SIZE_K)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_k = pid // num_pid_n\n pid_n = pid % num_pid_n\n offs_ak = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n offs_am = tl.arange(0, BLOCK_SIZE_M)\n a_ptrs = a_ptr + offs_ak[:, None] * stride_am + offs_am[None, :\n ] * stride_ak\n offs_bm = tl.arange(0, BLOCK_SIZE_M)\n offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n b_ptrs = b_ptr + offs_bm[:, None] * stride_bm + offs_bn[None, :\n ] * stride_bn\n c = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, M // BLOCK_SIZE_M):\n a = tl.load(a_ptrs)\n b = tl.load(b_ptrs)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_M * stride_ak\n b_ptrs += BLOCK_SIZE_M * stride_bm\n offs_ck = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + stride_ck * offs_ck[:, None] + stride_cn * offs_cn[None, :\n ]\n c_mask = (offs_ck[:, None] < K) & (offs_cn[None, :] < N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/tests/test_triton.py" }, { "uuid": "d0b8c6a2-7f55-44e6-9e98-4a7950d8a027", "file_name": "k_layer_norm.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_layer_norm.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _store(y, Y, stride, N, META):\n row = tl.program_id(0)\n cols = tl.arange(0, META['BLOCK_SIZE_N'])\n y_ptrs = Y + row * stride + cols\n tl.store(y_ptrs, y, mask=cols < N)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_layer_norm.py" }, { "uuid": "3a7b1bd1-f3ca-43bf-a7b4-0c9a9351f847", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_self_substraction_jagged_out_kernel(a_ptr, b_ptr, a_offsets_ptr,\n b_offsets_ptr, max_seq_len, BLOCK_SIZE: tl.constexpr):\n pid_batch = tl.program_id(0)\n pid_index = tl.program_id(1)\n a_offset = tl.load(a_offsets_ptr + pid_batch)\n a_length = tl.load(a_offsets_ptr + pid_batch + 1) - a_offset\n a_length = tl.minimum(a_length, max_seq_len + 1)\n if a_length <= 1:\n return\n N = a_length - 1\n if pid_index >= N:\n return\n a_cur = tl.load(a_ptr + a_offset + pid_index)\n offs = tl.arange(0, BLOCK_SIZE)\n mask = offs < N\n a_row = tl.load(a_ptr + a_offset + offs + 1, mask=mask)\n b = a_cur - a_row\n b_offset = tl.load(b_offsets_ptr + pid_batch)\n tl.store(b_ptr + b_offset + pid_index * N + offs, b, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "1785486b-2352-41b5-af96-46f69ff6c60e", "file_name": "mamba_ssm.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/model_executor/layers/mamba/ops/mamba_ssm.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.jit\ndef softplus(dt):\n dt = tl.where(dt <= 20.0, tl.math.log(tl.math.exp(dt) + 1), dt)\n return dt\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/model_executor/layers/mamba/ops/mamba_ssm.py" }, { "uuid": "dcc18d2e-fcbe-411e-948a-c0bd4f7e40c3", "file_name": "softmax_online_v2_spec.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v2_spec.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n prev_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, prev_multiple, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs).to(output_ptr.dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n for start_n in range(prev_multiple, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n final_m = tl.max(m, 0)\n z = tl.sum(tl.exp(m - final_m) * z)\n m = final_m\n prev_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, prev_multiple, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs).to(output_ptr.dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out)\n for start_n in range(prev_multiple, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v2_spec.py" }, { "uuid": "4d7c81d2-85d8-4a4f-9e51-fda6146986f7", "file_name": "lightning_attn2.py", "repo_name": "OpenNLPLab/lightning-attention", "file_path": "lightning_attn/ops/triton/lightning_attn2.py", "commit_hash": "d7439519541e966084eeaaf3ffd63eecc216f414", "starcount": 0, "input": "@triton.jit\ndef _bwd_inter_kernel(Q, K, V, S, DO, DQ, DK, DV, b: tl.constexpr, h: tl.\n constexpr, n: tl.constexpr, d: tl.constexpr, e: tl.constexpr, BLOCK: tl\n .constexpr, NUM_BLOCK: tl.constexpr, CBLOCK: tl.constexpr, NUM_CBLOCK:\n tl.constexpr):\n off_bh = tl.program_id(0)\n off_h = off_bh % h\n qk_offset = off_bh * n * d\n v_offset = off_bh * n * e\n o_offset = off_bh * n * e\n S_block_ptr = S + off_h\n DQ_block_ptr = DQ + qk_offset + tl.arange(0, CBLOCK)[:, None\n ] * d + tl.arange(0, d)[None, :]\n K_block_ptr = K + qk_offset + tl.arange(0, CBLOCK)[:, None\n ] * d + tl.arange(0, d)[None, :]\n V_trans_block_ptr = V + v_offset + tl.arange(0, CBLOCK)[None, :\n ] * e + tl.arange(0, e)[:, None]\n DO_block_ptr = DO + o_offset + tl.arange(0, CBLOCK)[:, None\n ] * e + tl.arange(0, e)[None, :]\n off_block1 = tl.arange(0, CBLOCK)\n off_block2 = tl.arange(0, CBLOCK)\n c_array = tl.arange(0, CBLOCK)\n s = tl.load(S_block_ptr)\n block_decay = tl.exp(-s.to(tl.float32) * BLOCK)\n kv_trans = tl.zeros([e, d], dtype=tl.float32)\n for i in range(NUM_BLOCK):\n for j in range(NUM_CBLOCK):\n if i > 0:\n q_decay = tl.exp(-s.to(tl.float32) * (j * CBLOCK + c_array[\n :, None]))\n do = tl.load(DO_block_ptr, mask=off_block1[:, None] < n,\n other=0.0).to(tl.float32)\n dq_inter = tl.dot(do, kv_trans) * q_decay\n dq = dq_inter + tl.load(DQ_block_ptr, mask=off_block1[:,\n None] < n, other=0.0)\n tl.store(DQ_block_ptr, dq.to(DQ_block_ptr.dtype.element_ty),\n mask=off_block1[:, None] < n)\n DQ_block_ptr += CBLOCK * d\n DO_block_ptr += CBLOCK * e\n off_block1 += CBLOCK\n kv_trans_current = tl.zeros([e, d], dtype=tl.float32)\n for j in range(NUM_CBLOCK):\n v_trans = tl.load(V_trans_block_ptr, mask=off_block2[None, :] <\n n, other=0.0).to(tl.float32)\n k = tl.load(K_block_ptr, mask=off_block2[:, None] < n, other=0.0\n ).to(tl.float32)\n k_decay = tl.exp(-s.to(tl.float32) * (BLOCK - (j * CBLOCK +\n c_array[:, None])))\n kv_trans_current += tl.dot(v_trans, k * k_decay)\n K_block_ptr += CBLOCK * d\n V_trans_block_ptr += CBLOCK * e\n off_block2 += CBLOCK\n kv_trans = block_decay * kv_trans + kv_trans_current\n m = NUM_BLOCK * BLOCK\n off_block1 = m + tl.arange(0, CBLOCK)\n off_block2 = m + tl.arange(0, CBLOCK)\n Q_trans_block_ptr = Q + qk_offset + m * d + tl.arange(0, CBLOCK)[None, :\n ] * d + tl.arange(0, d)[:, None]\n K_block_ptr = K + qk_offset + m * d + tl.arange(0, CBLOCK)[:, None\n ] * d + tl.arange(0, d)[None, :]\n V_trans_block_ptr = V + v_offset + m * e + tl.arange(0, CBLOCK)[None, :\n ] * e + tl.arange(0, e)[:, None]\n DK_trans_block_ptr = DK + qk_offset + m * d + tl.arange(0, CBLOCK)[None, :\n ] * d + tl.arange(0, d)[:, None]\n DV_block_ptr = DV + v_offset + m * e + tl.arange(0, CBLOCK)[:, None\n ] * e + tl.arange(0, e)[None, :]\n DO_block_ptr = DO + o_offset + m * e + tl.arange(0, CBLOCK)[:, None\n ] * e + tl.arange(0, e)[None, :]\n dkv = tl.zeros([d, e], dtype=tl.float32)\n for i in range(NUM_BLOCK - 1, -1, -1):\n for j in range(NUM_CBLOCK - 1, -1, -1):\n K_block_ptr -= CBLOCK * d\n V_trans_block_ptr -= CBLOCK * e\n DK_trans_block_ptr -= CBLOCK * d\n DV_block_ptr -= CBLOCK * e\n off_block1 -= CBLOCK\n if i < NUM_BLOCK - 1:\n k = tl.load(K_block_ptr, mask=off_block1[:, None] < n,\n other=0.0).to(tl.float32)\n v_trans = tl.load(V_trans_block_ptr, mask=off_block1[None,\n :] < n, other=0.0).to(tl.float32)\n k_decay_trans = tl.exp(-s.to(tl.float32) * (BLOCK - (j *\n CBLOCK + c_array[None, :])))\n k_decay = tl.exp(-s.to(tl.float32) * (BLOCK - (j * CBLOCK +\n c_array[:, None])))\n dk_inter_trans = tl.dot(dkv, v_trans) * k_decay_trans\n dv_inter = tl.dot(k, dkv) * k_decay\n dk_trans = dk_inter_trans + tl.load(DK_trans_block_ptr,\n mask=off_block1[None, :] < n, other=0.0)\n dv = dv_inter + tl.load(DV_block_ptr, mask=off_block1[:,\n None] < n, other=0.0)\n tl.store(DK_trans_block_ptr, dk_trans.to(DK_trans_block_ptr\n .dtype.element_ty), mask=off_block1[None, :] < n)\n tl.store(DV_block_ptr, dv.to(DV_block_ptr.dtype.element_ty),\n mask=off_block1[:, None] < n)\n dkv_current = tl.zeros([d, e], dtype=tl.float32)\n for j in range(NUM_CBLOCK - 1, -1, -1):\n DO_block_ptr -= CBLOCK * e\n Q_trans_block_ptr -= CBLOCK * d\n off_block2 -= CBLOCK\n do = tl.load(DO_block_ptr, mask=off_block2[:, None] < n, other=0.0\n ).to(tl.float32)\n q_trans = tl.load(Q_trans_block_ptr, mask=off_block2[None, :] <\n n, other=0.0).to(tl.float32)\n q_decay_trans = tl.exp(-s.to(tl.float32) * (j * CBLOCK +\n c_array[None, :]))\n dkv_current += tl.dot(q_trans * q_decay_trans, do)\n dkv = block_decay * dkv + dkv_current\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/OpenNLPLab/lightning-attention/blob/d7439519541e966084eeaaf3ffd63eecc216f414/lightning_attn/ops/triton/lightning_attn2.py" }, { "uuid": "a120d48c-11cf-4fd5-a8e7-b007acd4cd2e", "file_name": "softmax_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/softmax_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef softmax_forward_kernel(input_pointer, output_pointer, batch_dim,\n feat_dim, input_batch_stride, input_feat_stride, output_batch_stride,\n output_feat_stride, log: tl.constexpr, BLOCK_SIZE_BATCH: tl.constexpr,\n BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Normalizes the input using softmax.\n\n Args:\n input_pointer: Pointer to the input to normalize.\n The input must be of shape [batch_dim, feat_dim].\n output_pointer: Pointer to a container the result is written to.\n The container must be of shape [batch_dim, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output container's batch dimension.\n output_feat_stride: Stride necessary to jump one element along the\n output container's feature dimension.\n log: Flag for indicating if the log of softmax should be taken.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n output_pointer += output_batch_stride * batch_offset[:, None\n ] + output_feat_stride * feat_offset[None, :]\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :], other=-float('inf')).to(tl.float32)\n input -= tl.max(input, axis=1)[:, None]\n numerator = tl.exp(input)\n denominator = tl.sum(numerator, axis=1)[:, None]\n if log:\n output = input - tl.log(denominator)\n else:\n output = numerator / denominator\n tl.store(output_pointer, output, mask=batch_mask[:, None] & feat_mask[\n None, :])\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/softmax_kernels.py" }, { "uuid": "5d6d3565-d6b7-4e2c-9a44-573d03809ba0", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gsa/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_gsa_bwd_k_kernel_dA(v, g, do, dA, indices, offsets, scale, B: tl.\n constexpr, T: tl.constexpr, HQ: tl.constexpr, H: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BC: tl.constexpr, BV: tl.constexpr, NC: tl\n .constexpr, NG: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl\n .constexpr):\n i_v, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_bh // NG\n i_b, i_hq = i_bh // HQ, i_bh % HQ\n i_h = i_hq // NG\n i_t, i_i, i_j = i_c // (NC * NC), i_c % (NC * NC) // NC, i_c % (NC * NC\n ) % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n o_v = i_v * BV + tl.arange(0, BV)\n m_v = o_v < V\n if i_t * BT + i_i * BC > T:\n return\n if HEAD_FIRST:\n p_dA = tl.make_block_ptr(dA + (i_v * B * H + i_bh) * T * BT, (T, BT\n ), (BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n else:\n p_dA = tl.make_block_ptr(dA + ((i_v * all + bos) * HQ + i_hq) * BT,\n (T, BT), (HQ * BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC\n ), (1, 0))\n b_dA = tl.zeros([BC, BC], dtype=tl.float32)\n if i_i > i_j:\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bg * T * V, (V, T), (1, V), (i_v *\n BV, i_t * BT + i_j * BC), (BV, BC), (0, 1))\n p_gv = tl.make_block_ptr(g + i_bg * T * V, (V, T), (1, V), (i_v *\n BV, i_t * BT + i_j * BC), (BV, BC), (0, 1))\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + (i_t *\n BT + i_i * BC) * V + o_v, BV), BV)\n p_g = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (V, T), (1, H *\n V), (i_v * BV, i_t * BT + i_j * BC), (BV, BC), (0, 1))\n p_gv = tl.make_block_ptr(g + (bos * H + i_h) * V, (V, T), (1, H *\n V), (i_v * BV, i_t * BT + i_j * BC), (BV, BC), (0, 1))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + \n i_i * BC) * H * V + i_h * V + o_v, BV), BV)\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n b_gn = tl.load(p_gn, mask=m_v, other=0.0)\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_g - b_gn[None, :]) * scale).to(b_do.dtype)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_vg = (b_v * tl.exp(b_gn[:, None] - b_gv)).to(b_v.dtype)\n b_dA = tl.dot(b_do, b_vg)\n elif i_i == i_j:\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_v = tl.max_contiguous(tl.multiple_of(v + i_bg * T * V + (i_t *\n BT + i_j * BC) * V + o_v, BV), BV)\n p_gv = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + (i_t *\n BT + i_j * BC) * V + o_v, BV), BV)\n else:\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_v = tl.max_contiguous(tl.multiple_of(v + (bos + i_t * BT + \n i_j * BC) * H * V + i_h * V + o_v, BV), BV)\n p_gv = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + \n i_j * BC) * H * V + i_h * V + o_v, BV), BV)\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)) * scale\n m_v = o_v < V\n o_i = tl.arange(0, BC)\n m_dA = o_i[:, None] >= o_i[None, :]\n for j in range(0, min(BC, T - i_t * BT - i_j * BC)):\n b_v = tl.load(p_v, mask=m_v, other=0).to(tl.float32)\n b_gv = tl.load(p_gv, mask=m_v, other=0).to(tl.float32)\n b_dAj = tl.sum(b_do * b_v[None, :] * tl.exp(b_g - b_gv[None, :]), 1\n )\n b_dA = tl.where((o_i == j)[None, :], b_dAj[:, None], b_dA)\n p_v += (1 if HEAD_FIRST else H) * V\n p_gv += (1 if HEAD_FIRST else H) * V\n b_dA = tl.where(m_dA, b_dA, 0.0)\n tl.store(p_dA, b_dA.to(dA.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gsa/chunk.py" }, { "uuid": "735b3e92-e000-4d97-b785-9e46514b0726", "file_name": "dropout_rng.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/dropout_rng.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef debug_fill_dropout_rng_tensor(R, stride_rz, stride_rh, stride_rm,\n stride_rn, seqlen_q, seqlen_k, philox_seed_ptr, philox_offset_base_ptr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n philox_seed = tl.load(philox_seed_ptr)\n philox_offset_base = tl.load(philox_offset_base_ptr)\n debug_fill_dropout_rng(R, stride_rz, stride_rh, stride_rm, stride_rn,\n seqlen_q, seqlen_k, philox_seed, philox_offset_base, BLOCK_M, BLOCK_N)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/dropout_rng.py" }, { "uuid": "0f4487e2-762b-4302-8603-dbcd1043dab6", "file_name": "dequant_kernel.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/quant/dequant_kernel.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef dequantize_scalers(quantized_scalers_ptr, quantization_factor_ptr,\n scaler_mean_ptr, block_size, scaler_block_size):\n \"\"\"Dequantizes the quantized scalers to bfloat16\n Args:\n quantized_scalers_ptr: Pointer to the quantized scalers\n quantization_factor_ptr: Pointer to the quantization factor\n scaler_mean_ptr: Pointer to the scaler mean\n block_size: Size of the block\n scaler_block_size: Size of the scaler block\n \"\"\"\n block_idx = tl.program_id(0)\n quantization_factor_idx = block_idx // scaler_block_size\n scaler_quantization_factor = tl.load(quantization_factor_ptr +\n quantization_factor_idx)\n block_scaler = tl.load(quantized_scalers_ptr + block_idx)\n scaler_mean = tl.load(scaler_mean_ptr)\n dequantized_block_scaler = (block_scaler / scaler_quantization_factor).to(\n tl.bfloat16)\n dequantized_block_scaler = dequantized_block_scaler + scaler_mean\n return dequantized_block_scaler\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "bf16", "int8" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/quant/dequant_kernel.py" }, { "uuid": "f6685121-0e40-477c-b66b-4993da0134fc", "file_name": "chunk_h_parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'\n ] is not None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4, 8, 16] for num_stages in [2, 3]], key=\n ['BT', 'USE_G', 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_bwd_kernel_dh_reduction(g, gk, gv, dh, doq0, dh0, offsets,\n chunk_offsets, T: tl.constexpr, HQ: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV:\n tl.constexpr, NG: tl.constexpr, USE_G: tl.constexpr, USE_GK: tl.\n constexpr, USE_GV: tl.constexpr, STORE_INITIAL_STATE_GRADIENT: tl.\n constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_nh // NG\n i_n, i_hq = i_nh // HQ, i_nh % HQ\n i_h = i_hq // NG\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n for i_t in range(NT - 1, -1, -1):\n if HEAD_FIRST:\n p_dh = tl.make_block_ptr(dh + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_dh = tl.make_block_ptr(dh + ((boh + i_t) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dh, boundary_check=(0, 1)).to(tl.float32)\n if i_t < NT - 1:\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(\n 0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_bg * T + last_idx)\n else:\n b_g_last = tl.load(g + (bos + last_idx) * H + i_h)\n b_dh *= tl.exp(b_g_last)\n if USE_GK:\n if HEAD_FIRST:\n p_gk_last = gk + (i_bg * T + last_idx\n ) * K + i_k * BK + tl.arange(0, BK)\n else:\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) <\n K, other=0.0)\n b_dh *= tl.exp(b_gk_last)[:, None]\n if USE_GV:\n if HEAD_FIRST:\n p_gv_last = gv + (i_bg * T + last_idx\n ) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) <\n V, other=0.0)\n b_dh *= tl.exp(b_gv_last)[None, :]\n if STORE_INITIAL_STATE_GRADIENT:\n p_doq0 = tl.make_block_ptr(doq0 + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_doq0, boundary_check=(0, 1)).to(tl.float32)\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_parallel.py" }, { "uuid": "06154394-82a9-4d57-b6ed-f27fc9bbaca5", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef _bwd_preprocess(Out, DO, NDO, L, Delta, M_Q, stride_oz, stride_oh,\n stride_om, stride_od, stride_doz, stride_doh, stride_dom, stride_dod,\n stride_ndoz, stride_ndoh, stride_ndom, stride_ndod, stride_lz,\n stride_lh, stride_lm, stride_dz, stride_dh, stride_dm, BLOCK_DMODEL: tl\n .constexpr, BLOCK_M: tl.constexpr, EVEN_M: tl.constexpr):\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n offs_m = tl.program_id(0) * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n Out = Out + off_z * stride_oz + off_h * stride_oh + offs_m[:, None\n ] * stride_om + offs_d[None, :] * stride_od\n DO = DO + off_z * stride_doz + off_h * stride_doh + offs_m[:, None\n ] * stride_dom + offs_d[None, :] * stride_dod\n NDO = NDO + off_z * stride_ndoz + off_h * stride_ndoh + offs_m[:, None\n ] * stride_ndom + offs_d[None, :] * stride_ndod\n L = L + off_z * stride_lz + off_h * stride_lh + offs_m * stride_lm\n Delta = Delta + off_z * stride_dz + off_h * stride_dh + offs_m * stride_dm\n if EVEN_M:\n o = tl.load(Out).to(tl.float32)\n do = tl.load(DO).to(tl.float32)\n denom = tl.load(L).to(tl.float32)\n else:\n o = tl.load(Out, mask=offs_m[:, None] < M_Q).to(tl.float32)\n do = tl.load(DO, mask=offs_m[:, None] < M_Q).to(tl.float32)\n denom = tl.load(L, mask=offs_m < M_Q).to(tl.float32)\n do = do / denom[:, None]\n delta = tl.sum(o * do, axis=1)\n if EVEN_M:\n tl.store(NDO, do)\n tl.store(Delta, delta)\n else:\n tl.store(NDO, do, mask=offs_m[:, None] < M_Q)\n tl.store(Delta, delta, mask=offs_m < M_Q)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "e5746bd4-5ff0-429c-abaa-ebb35c0d4af0", "file_name": "fused_norm_gate.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_norm_gate.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N', 'HAS_RESIDUAL', 'STORE_RESIDUAL_OUT',\n 'IS_RMS_NORM', 'HAS_BIAS'])\n@triton.jit\ndef layer_norm_fwd_kernel(X, O, Y, W, B, RESIDUAL, RESIDUAL_OUT, Mean, Rstd,\n stride_x_row, stride_y_row, stride_res_row, stride_res_out_row, N, eps,\n IS_RMS_NORM: tl.constexpr, BLOCK_N: tl.constexpr, HAS_RESIDUAL: tl.\n constexpr, STORE_RESIDUAL_OUT: tl.constexpr, HAS_WEIGHT: tl.constexpr,\n HAS_BIAS: tl.constexpr):\n row = tl.program_id(0)\n X += row * stride_x_row\n Y += row * stride_y_row\n O += row * stride_x_row\n if HAS_RESIDUAL:\n RESIDUAL += row * stride_res_row\n if STORE_RESIDUAL_OUT:\n RESIDUAL_OUT += row * stride_res_out_row\n cols = tl.arange(0, BLOCK_N)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n if HAS_RESIDUAL:\n residual = tl.load(RESIDUAL + cols, mask=cols < N, other=0.0).to(tl\n .float32)\n x += residual\n if STORE_RESIDUAL_OUT:\n tl.store(RESIDUAL_OUT + cols, x, mask=cols < N)\n if not IS_RMS_NORM:\n mean = tl.sum(x, axis=0) / N\n tl.store(Mean + row, mean)\n xbar = tl.where(cols < N, x - mean, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n else:\n xbar = tl.where(cols < N, x, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n tl.store(Rstd + row, rstd)\n mask = cols < N\n if HAS_WEIGHT:\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n if HAS_BIAS:\n b = tl.load(B + cols, mask=mask).to(tl.float32)\n x_hat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n y = x_hat * w if HAS_WEIGHT else x_hat\n if HAS_BIAS:\n y = y + b\n o = tl.load(O + cols, mask=cols < N, other=0.0).to(tl.float32)\n y = y * o * tl.sigmoid(o)\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_norm_gate.py" }, { "uuid": "1867f9a5-2505-4dea-85b4-7eec68d369de", "file_name": "nll_loss_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/nll_loss_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim',\n 'spatial_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_SPATIAL': lambda args: next_power_of_2(args['spatial_dim'])})\n@triton.jit\ndef nll_loss_backward_kernel(output_grad_pointer, target_pointer,\n weight_pointer, sum_weights_pointer, input_grad_pointer, batch_dim,\n spatial_dim, output_grad_batch_stride, output_grad_feat_stride,\n target_batch_stride, target_spatial_stride, input_grad_batch_stride,\n input_grad_feat_stride, input_grad_spatial_stride, reduction: tl.\n constexpr, weighted: tl.constexpr, BLOCK_SIZE_BATCH: tl.constexpr,\n BLOCK_SIZE_SPATIAL: tl.constexpr):\n \"\"\"\n Calculates the input gradient of negative log likelihood loss.\n\n Args:\n output_grad_pointer: Pointer to the loss's output gradients.\n The output gradients must be of shape [batch_dim, spatial_dim]\n if reduction is 'none', and otherwise [batch_dim/BLOCK_SIZE_BATCH].\n target_pointer: Pointer to the target.\n The target must be of shape [batch_dim, spatial_dim].\n weight_pointer: Pointer to an optional class weight vector.\n The class weight vector, if provided, must be of shape [feat_dim].\n sum_weights_pointer: Pointer to the sum of the class weights if the classes were weighed.\n The sum of weights must be a scalar.\n input_grad_pointer: Pointer to a container the input's gradients are written to.\n The container must be of shape [batch_dim, feat_dim, spatial_dim] and zeroed.\n batch_dim: Batch dimension.\n spatial_dim: Spatial dimension.\n output_grad_batch_stride: Stride necessary to jump one element along the\n output gradients' batch dimension.\n output_grad_feat_stride: Stride necessary to jump one element along the\n output gradients' feature dimension.\n input_spatial_stride: Stride necessary to jump one element along the\n input's spatial dimension.\n target_batch_stride: Stride necessary to jump one element along the\n target's batch dimension.\n target_spatial_stride: Stride necessary to jump one element along the\n target's spatial dimension.\n input_grad_batch_stride: Stride necessary to jump one element along the\n input gradient container's batch dimension.\n input_grad_feat_stride: Stride necessary to jump one element along the\n input gradient container's feature dimension.\n input_grad_spatial_stride: Stride necessary to jump one element along the\n input gradient container's spatial dimension.\n reduction: Reduction strategy for the output whose gradient is calculated.\n Options are 'none' for no reduction, 'mean' for averaging the loss\n across all entries, and 'sum' for summing the loss across all entries.\n weighted: Flag for weighing each class.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_SPATIAL: Block size across the spatial dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n spatial_offset = tl.arange(0, BLOCK_SIZE_SPATIAL)\n batch_mask = batch_offset < batch_dim\n spatial_mask = spatial_offset < spatial_dim\n output_grad_mask = None\n if reduction == 'none':\n output_grad_pointer += output_grad_batch_stride * batch_offset[:, None\n ] + output_grad_feat_stride * spatial_offset[None, :]\n output_grad_mask = batch_mask[:, None] & spatial_mask[None, :]\n output_grad = tl.load(output_grad_pointer, mask=output_grad_mask).to(tl\n .float32)\n input_grad = -output_grad\n target_pointer += target_batch_stride * batch_offset[:, None\n ] + target_spatial_stride * spatial_offset[None, :]\n target = tl.load(target_pointer, mask=batch_mask[:, None] &\n spatial_mask[None, :])\n if weighted:\n weight = tl.load(weight_pointer + target, mask=batch_mask[:, None] &\n spatial_mask[None, :]).to(tl.float32)\n input_grad *= weight\n if reduction == 'mean':\n input_grad /= tl.load(sum_weights_pointer)\n elif reduction == 'mean':\n input_grad /= batch_dim * spatial_dim\n input_grad_pointer += (input_grad_feat_stride * target + \n input_grad_batch_stride * batch_offset[:, None] + \n input_grad_spatial_stride * spatial_offset[None, :])\n tl.store(input_grad_pointer, input_grad, mask=batch_mask[:, None] &\n spatial_mask[None, :])\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/nll_loss_kernels.py" }, { "uuid": "13add3b4-2ac9-4b8e-9860-79b4012d9a64", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_backward_weight_grad_core(a_ptr, b_ptr, c_ptr, init_factor, M,\n N, K, H, stride_am, stride_ak, stride_bm, stride_bn, R7: int, R6: int,\n R5: int, R4: int, R3: int, R2: int, R1: int, R0: int, allow_tf32: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A^T x B.\n A has shape (M, K), B has shape (M, N) and C has shape (K, N)\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_k = tl.cdiv(K, BLOCK_SIZE_K)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_k = group_id * GROUP_SIZE\n group_size_k = min(num_pid_k - first_pid_k, GROUP_SIZE)\n pid_k = first_pid_k + pid % group_size_k\n pid_n = pid % num_pid_in_group // group_size_k\n offs_ak = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n offs_am = tl.arange(0, BLOCK_SIZE_M)\n a_ptrs = a_ptr + offs_ak[:, None] * stride_am + offs_am[None, :\n ] * stride_ak\n offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_bm = tl.arange(0, BLOCK_SIZE_M)\n b_ptrs = b_ptr + offs_bm[:, None] * stride_bm + offs_bn[None, :\n ] * stride_bn\n offs_ck = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n a_zero = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_M), dtype=tl.float32)\n b_zero = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n c = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_N), dtype=tl.float32)\n for m in range(0, tl.cdiv(M, BLOCK_SIZE_M)):\n offs_m = m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n a_mask = (offs_ck[:, None] < K) & (offs_m[None, :] < M)\n b_mask = (offs_m[:, None] < M) & (offs_cn[None, :] < N)\n a = tl.load(a_ptrs, mask=a_mask, other=a_zero)\n b = tl.load(b_ptrs, mask=b_mask, other=b_zero)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_M * stride_ak\n b_ptrs += BLOCK_SIZE_M * stride_bm\n c_offset = c_ptr + tl.arange(0, BLOCK_SIZE_K)[:, None\n ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]\n c_ptrs = c_offset + ((pid_k * R3 + pid_n * R2 + R1) % R0 * R0 + (pid_k *\n R7 + pid_n * R5 + R4) % R0) % (H - BLOCK_SIZE_K * BLOCK_SIZE_N)\n tl.atomic_add(c_ptrs, c * init_factor)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "74718d3f-c518-4407-8ec5-e202d737b762", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_s(q, k, s, rk, ck, pk, s_qk_h, s_qk_t, s_qk_d,\n s_sk_h, s_sk_t, s_sk_m, T, scale, BT: tl.constexpr, BK: tl.constexpr,\n BM: tl.constexpr, DK: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_m, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n p_q = tl.make_block_ptr(q + i_bh * s_qk_h, (T, DK), (s_qk_t, s_qk_d), (\n 0, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_qk_h, (DK, T), (s_qk_d, s_qk_t), (\n i_k * BK, 0), (BK, BT), (0, 1))\n p_s = tl.make_block_ptr(s + (i_k * n_bh + i_bh) * s_sk_h, (T, DM), (\n s_sk_t, s_sk_m), (0, i_m * BM), (BT, BM), (1, 0))\n p_rk = tl.make_block_ptr(rk + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_ck = tl.make_block_ptr(ck + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n (0, i_m * BM), (BT, BM), (1, 0))\n p_pk = tl.make_block_ptr(pk + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n (0, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_hk = tl.zeros([BK, BM], dtype=tl.float32)\n for _ in range(NT):\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_rk = tl.load(p_rk, boundary_check=(0,))\n b_ck = tl.load(p_ck, boundary_check=(0, 1))\n b_pk = tl.load(p_pk, boundary_check=(0, 1))\n b_inter = tl.dot(b_q, b_hk.to(b_q.dtype), allow_tf32=False) * b_rk[\n None, :]\n b_intra = tl.dot(tl.where(m_s, tl.dot(b_q, b_k, allow_tf32=False), \n 0).to(b_q.dtype), b_ck, allow_tf32=False)\n b_s = (b_inter + b_intra) * b_pk\n b_hk = b_hk * b_rk[None, :] + tl.dot(b_k, b_ck, allow_tf32=False)\n tl.store(p_s, b_s.to(p_s.dtype.element_ty), boundary_check=(0, 1))\n p_q = tl.advance(p_q, (BT, 0))\n p_k = tl.advance(p_k, (0, BT))\n p_s = tl.advance(p_s, (BT, 0))\n p_rk = tl.advance(p_rk, (DM,))\n p_ck = tl.advance(p_ck, (BT, 0))\n p_pk = tl.advance(p_pk, (BT, 0))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "0d55d92f-0a9b-4b89-9f91-5898bd40e024", "file_name": "geglu.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/geglu.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef geglu_forward_kernel(x_ptr, y_ptr, N, C, C2, BLK_C: tl.constexpr, BLK_N:\n tl.constexpr):\n pid_n = tl.program_id(0)\n pid_c = tl.program_id(1)\n offs_n = pid_n * BLK_N + tl.arange(0, BLK_N)\n offs_c = pid_c * BLK_C + tl.arange(0, BLK_C)\n mask_n = offs_n < N\n mask_c = offs_c < C2\n mask = mask_n[:, None] & mask_c[None, :]\n x_ptrs = x_ptr + offs_n[:, None] * C + offs_c[None, :]\n x1 = tl.load(x_ptrs, mask=mask)\n x2 = tl.load(x_ptrs + C2, mask=mask)\n y = x1 * gelu_forward(x2)\n y_ptrs = y_ptr + offs_n[:, None] * C2 + offs_c[None, :]\n tl.store(y_ptrs, y, mask=mask)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/geglu.py" }, { "uuid": "eca0e629-398b-4f13-a441-1f45f6e88d23", "file_name": "stats.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/stats.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _Stats_cl3d_backward_impl(X_ptr, Meangrad_ptr, Sqmeangrad_ptr,\n Outputgrad_ptr, numel_no_channels, num_channels: tl.constexpr,\n block_other: tl.constexpr):\n pid = tl.program_id(0)\n X_ptr += pid * num_channels * block_other\n Outputgrad_ptr += pid * num_channels * block_other\n channels_offset = tl.arange(0, num_channels)\n other_offset = tl.arange(0, block_other)\n offset = other_offset[:, None] * num_channels + channels_offset[None, :]\n mask = other_offset[:, None] < numel_no_channels - pid * block_other\n x = tl.load(X_ptr + offset, mask=mask, other=0.0).to(tl.float32)\n mean_grad = tl.load(Meangrad_ptr + channels_offset)\n sqmean_grad = tl.load(Sqmeangrad_ptr + channels_offset)\n grad = (2 * x * sqmean_grad / numel_no_channels + mean_grad /\n numel_no_channels)\n tl.store(Outputgrad_ptr + offset, grad, mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/stats.py" }, { "uuid": "10275dc6-1d3c-4562-9324-771303bd1166", "file_name": "sb_varlen_bwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_bwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.autotune(configs=get_configs(), key=['token_size', 'head_size'],\n reset_to_zero=['DK_ptr', 'DV_ptr'])\n@triton.jit\ndef _backward(DO_ptr, stride_doh: tl.constexpr, stride_dom, stride_dod: tl.\n constexpr, DR_ptr, stride_drh, stride_drm, A_ptr, stride_ah, stride_am,\n Q_ptr, stride_qh: tl.constexpr, stride_qm, stride_qd: tl.constexpr,\n K_ptr, stride_kh: tl.constexpr, stride_kn, stride_kd: tl.constexpr,\n V_ptr, stride_vh: tl.constexpr, stride_vn, stride_vd: tl.constexpr,\n DQ_ptr, stride_dqh: tl.constexpr, stride_dqm, stride_dqd: tl.constexpr,\n DK_ptr, stride_dkh: tl.constexpr, stride_dkn, stride_dkd: tl.constexpr,\n DV_ptr, stride_dvh: tl.constexpr, stride_dvn, stride_dvd: tl.constexpr,\n KV_Lock_ptr, KV_Count_ptr, stride_kvs, stride_kvh, CSL_ptr, logit_scale,\n batch_size, token_size, head_size: tl.constexpr, num_heads: tl.\n constexpr, BLOCK_D: tl.constexpr, BLOCK_CSL: tl.constexpr, NO_D_MASK:\n tl.constexpr, NO_M_MASK: tl.constexpr, NO_N_MASK: tl.constexpr,\n ALLOW_TF32: tl.constexpr, inv_log2: tl.constexpr, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr, acc_dtype: tl.constexpr=tl.float32,\n attend_current: tl.constexpr=False):\n tl.static_assert(BLOCK_M % BLOCK_N == 0)\n seq_id = tl.program_id(0)\n fhead_id = tl.program_id(1)\n seq_alloc_prog_id = tl.program_id(2)\n num_seq_alloc_progs = tl.num_programs(2)\n if seq_id == 0:\n seq_start_offset = 0\n else:\n seq_start_offset = tl.load(CSL_ptr + seq_id - 1).to(tl.int32)\n seq_end_offset = tl.load(CSL_ptr + seq_id).to(tl.int32)\n seq_length = seq_end_offset - seq_start_offset\n num_seq_blocks = tl.cdiv(seq_length, BLOCK_M)\n seq_a_block_id = num_seq_blocks - seq_alloc_prog_id - 1\n seq_b_block_id = seq_alloc_prog_id - (num_seq_alloc_progs - num_seq_blocks)\n if seq_a_block_id >= 0 or seq_b_block_id >= 0:\n qk_scale = inv_log2 * logit_scale\n M_range = tl.arange(0, BLOCK_M)\n N_range = tl.arange(0, BLOCK_N)\n D_range = tl.arange(0, BLOCK_D)\n D_mask = D_range < head_size\n cm = tl.where(N_range[:, None] >= N_range[None, :], 1.0, 0.0).to(Q_ptr\n .type.element_ty)\n if seq_a_block_id >= 0:\n head_id = fhead_id * 2\n DO_head_seq_ptr = (DO_ptr + stride_doh * head_id + stride_dom *\n seq_start_offset)\n DR_head_seq_ptr = (DR_ptr + stride_drh * head_id + stride_drm *\n seq_start_offset)\n A_head_seq_ptr = (A_ptr + stride_ah * head_id + stride_am *\n seq_start_offset)\n Q_head_seq_ptr = (Q_ptr + stride_qh * head_id + stride_qm *\n seq_start_offset)\n K_head_seq_ptr = (K_ptr + stride_kh * head_id + stride_kn *\n seq_start_offset)\n V_head_seq_ptr = (V_ptr + stride_vh * head_id + stride_vn *\n seq_start_offset)\n DQ_head_seq_ptr = (DQ_ptr + stride_dqh * head_id + stride_dqm *\n seq_start_offset)\n DK_head_seq_ptr = (DK_ptr + stride_dkh * head_id + stride_dkn *\n seq_start_offset)\n DV_head_seq_ptr = (DV_ptr + stride_dvh * head_id + stride_dvn *\n seq_start_offset)\n KV_Lock_head_seq_ptr = (KV_Lock_ptr + stride_kvs * seq_id + \n stride_kvh * head_id)\n KV_Count_head_seq_ptr = (KV_Count_ptr + stride_kvs * seq_id + \n stride_kvh * head_id)\n _backward_one_row(seq_a_block_id, seq_length, qk_scale, M_range,\n N_range, D_range, D_mask, cm, DO_head_seq_ptr, stride_dom,\n stride_dod, DR_head_seq_ptr, stride_drm, A_head_seq_ptr,\n stride_am, Q_head_seq_ptr, stride_qm, stride_qd,\n K_head_seq_ptr, stride_kn, stride_kd, V_head_seq_ptr,\n stride_vn, stride_vd, DQ_head_seq_ptr, stride_dqm,\n stride_dqd, DK_head_seq_ptr, stride_dkn, stride_dkd,\n DV_head_seq_ptr, stride_dvn, stride_dvd,\n KV_Lock_head_seq_ptr, KV_Count_head_seq_ptr, logit_scale,\n BLOCK_D, NO_D_MASK, NO_M_MASK, ALLOW_TF32, BLOCK_M, BLOCK_N,\n acc_dtype, attend_current=attend_current)\n if seq_b_block_id >= 0 and fhead_id * 2 + 1 < num_heads:\n head_id = fhead_id * 2 + 1\n DO_head_seq_ptr = (DO_ptr + stride_doh * head_id + stride_dom *\n seq_start_offset)\n DR_head_seq_ptr = (DR_ptr + stride_drh * head_id + stride_drm *\n seq_start_offset)\n A_head_seq_ptr = (A_ptr + stride_ah * head_id + stride_am *\n seq_start_offset)\n Q_head_seq_ptr = (Q_ptr + stride_qh * head_id + stride_qm *\n seq_start_offset)\n K_head_seq_ptr = (K_ptr + stride_kh * head_id + stride_kn *\n seq_start_offset)\n V_head_seq_ptr = (V_ptr + stride_vh * head_id + stride_vn *\n seq_start_offset)\n DQ_head_seq_ptr = (DQ_ptr + stride_dqh * head_id + stride_dqm *\n seq_start_offset)\n DK_head_seq_ptr = (DK_ptr + stride_dkh * head_id + stride_dkn *\n seq_start_offset)\n DV_head_seq_ptr = (DV_ptr + stride_dvh * head_id + stride_dvn *\n seq_start_offset)\n KV_Lock_head_seq_ptr = (KV_Lock_ptr + stride_kvs * seq_id + \n stride_kvh * head_id)\n KV_Count_head_seq_ptr = (KV_Count_ptr + stride_kvs * seq_id + \n stride_kvh * head_id)\n _backward_one_row(seq_b_block_id, seq_length, qk_scale, M_range,\n N_range, D_range, D_mask, cm, DO_head_seq_ptr, stride_dom,\n stride_dod, DR_head_seq_ptr, stride_drm, A_head_seq_ptr,\n stride_am, Q_head_seq_ptr, stride_qm, stride_qd,\n K_head_seq_ptr, stride_kn, stride_kd, V_head_seq_ptr,\n stride_vn, stride_vd, DQ_head_seq_ptr, stride_dqm,\n stride_dqd, DK_head_seq_ptr, stride_dkn, stride_dkd,\n DV_head_seq_ptr, stride_dvn, stride_dvd,\n KV_Lock_head_seq_ptr, KV_Count_head_seq_ptr, logit_scale,\n BLOCK_D, NO_D_MASK, NO_M_MASK, ALLOW_TF32, BLOCK_M, BLOCK_N,\n acc_dtype, attend_current=attend_current)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_bwd.py" }, { "uuid": "07efee37-5fc4-487f-907f-99cc5df92ca4", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_rcum(s, r, c, o, s_sk_h, s_sk_t, s_sk_m, T, BT: tl\n .constexpr, BM: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_m, i_bh = tl.program_id(0), tl.program_id(1)\n p_s = tl.make_block_ptr(s + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n (NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n p_c = tl.make_block_ptr(c + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n (NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n (NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_t = tl.where(o_i[:, None] <= o_i[None, :], 1.0, 0.0)\n b_z = tl.zeros([BM], dtype=tl.float32)\n for i in range(NT):\n p_r = tl.make_block_ptr(r + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m\n ,), ((NT - i) % NT * DM + i_m * BM,), (BM,), (0,))\n b_s = tl.load(p_s, boundary_check=(0, 1))\n b_r = tl.load(p_r, boundary_check=(0,))\n b_c = tl.load(p_c, boundary_check=(0, 1))\n b_o = tl.load(p_o, boundary_check=(0, 1))\n b_z = b_z * b_r\n b_o -= b_c * (b_z[None, :] + tl.dot(m_t.to(b_s.dtype), b_s,\n allow_tf32=False))\n b_z += tl.sum(b_s, 0)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_s = tl.advance(p_s, (-BT, 0))\n p_c = tl.advance(p_c, (-BT, 0))\n p_o = tl.advance(p_o, (-BT, 0))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "67e4c93c-b727-4fc8-a953-27e3c96d1539", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4)], key=['BT', 'K', 'V'])\n@triton.jit\ndef chunk_transform_qk_fwd_kernel(q, k, v, beta, o, A, q_new, k_new,\n A_local, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, scale, T: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr, BT: tl.constexpr, OUTPUT_ATTENTIONS: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, 0), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, 0), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, 0), (BT, BV), (1, 0))\n b_q = (tl.load(p_q, boundary_check=(0, 1)) * scale).to(p_q.dtype.element_ty\n )\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n p_T = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t * BT,\n 0), (BT, BT), (1, 0))\n b_T = tl.load(p_T, boundary_check=(0, 1))\n o_i = tl.arange(0, BT)\n m_t = o_i[:, None] >= o_i[None, :]\n b_qk = tl.where(m_t, tl.dot(b_q, tl.trans(b_k), allow_tf32=False), 0).to(\n b_q.dtype)\n m_t = o_i[:, None] > o_i[None, :]\n b_kk = tl.where(m_t, tl.dot(b_k, tl.trans(b_k), allow_tf32=False), 0).to(\n b_k.dtype)\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,), (\n BT,), (0,))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_k_beta = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_qkT = tl.dot(b_qk, b_T, allow_tf32=False).to(b_k.dtype)\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(A_local + i_bh * T * BT, (T, BT), (BT, 1),\n (i_t * BT, 0), (BT, BT), (1, 0))\n tl.store(p_a, b_qkT.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n b_kkT = tl.dot(b_kk, b_T, allow_tf32=False).to(b_k.dtype)\n p_o = tl.make_block_ptr(o + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, 0), (BT, BV), (1, 0))\n tl.store(p_o, tl.dot(b_qkT, b_v).to(p_o.dtype.element_ty),\n boundary_check=(0, 1))\n p_q_new = tl.make_block_ptr(q_new + i_bh * s_k_h, (T, K), (s_k_t, s_k_d\n ), (i_t * BT, 0), (BT, BK), (1, 0))\n tl.store(p_q_new, (b_q - tl.dot(b_qkT, b_k_beta, allow_tf32=False)).to(\n p_q_new.dtype.element_ty), boundary_check=(0, 1))\n p_k_new = tl.make_block_ptr(k_new + i_bh * s_k_h, (T, K), (s_k_t, s_k_d\n ), (i_t * BT, 0), (BT, BK), (1, 0))\n tl.store(p_k_new, (b_k - tl.dot(tl.trans(b_kkT), b_k_beta, allow_tf32=\n False)).to(p_k_new.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/parallel.py" }, { "uuid": "f9c0d792-543f-40b9-b98d-def82c9bbbb9", "file_name": "sb_varlen_fwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_fwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.autotune(configs=get_configs(), key=['head_size'])\n@triton.jit\ndef _forward(Q_ptr, stride_qh: tl.constexpr, stride_qm, stride_qd: tl.\n constexpr, K_ptr, stride_kh: tl.constexpr, stride_kn, stride_kd: tl.\n constexpr, V_ptr, stride_vh: tl.constexpr, stride_vn, stride_vd: tl.\n constexpr, O_ptr, stride_oh: tl.constexpr, stride_om, stride_od: tl.\n constexpr, R_ptr, stride_rh, stride_rm: tl.constexpr, A_ptr, stride_ah,\n stride_am: tl.constexpr, W_ptr, stride_wh, stride_wm, stride_wn,\n CSL_ptr, logit_scale: tl.constexpr, batch_size, token_size, head_size:\n tl.constexpr, num_heads: tl.constexpr, BLOCK_D: tl.constexpr, NO_D_MASK:\n tl.constexpr, NO_M_MASK: tl.constexpr, NO_N_MASK: tl.constexpr,\n ALLOW_TF32: tl.constexpr, inv_log2: tl.constexpr, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr, no_grad: tl.constexpr=False, acc_dtype: tl.\n constexpr=tl.float32, return_attention: tl.constexpr=False, use_cumsum:\n tl.constexpr=False, attend_current: tl.constexpr=False):\n tl.static_assert(BLOCK_M % BLOCK_N == 0)\n seq_id = tl.program_id(0)\n fhead_id = tl.program_id(1)\n seq_alloc_prog_id = tl.program_id(2)\n num_seq_alloc_progs = tl.num_programs(2)\n if seq_id == 0:\n seq_start_offset = 0\n else:\n seq_start_offset = tl.load(CSL_ptr + seq_id - 1).to(tl.int32)\n seq_end_offset = tl.load(CSL_ptr + seq_id).to(tl.int32)\n seq_length = seq_end_offset - seq_start_offset\n num_seq_blocks = tl.cdiv(seq_length, BLOCK_M)\n seq_a_block_id = num_seq_blocks - seq_alloc_prog_id - 1\n seq_b_block_id = seq_alloc_prog_id - (num_seq_alloc_progs - num_seq_blocks)\n if seq_a_block_id >= 0 or seq_b_block_id >= 0:\n qk_scale = inv_log2 * logit_scale\n M_range = tl.arange(0, BLOCK_M)\n N_range = tl.arange(0, BLOCK_N)\n D_range = tl.arange(0, BLOCK_D)\n D_mask = D_range < head_size\n if not use_cumsum:\n cm = tl.where(N_range[:, None] >= N_range[None, :], 1.0, 0.0).to(\n Q_ptr.type.element_ty)\n else:\n cm = None\n if seq_a_block_id >= 0:\n head_id = fhead_id * 2\n Q_head_seq_ptr = (Q_ptr + stride_qh * head_id + stride_qm *\n seq_start_offset)\n K_head_seq_ptr = (K_ptr + stride_kh * head_id + stride_kn *\n seq_start_offset)\n V_head_seq_ptr = (V_ptr + stride_vh * head_id + stride_vn *\n seq_start_offset)\n O_head_seq_ptr = (O_ptr + stride_oh * head_id + stride_om *\n seq_start_offset)\n R_head_seq_ptr = (R_ptr + stride_rh * head_id + stride_rm *\n seq_start_offset)\n A_head_seq_ptr = (A_ptr + stride_ah * head_id + stride_am *\n seq_start_offset)\n W_head_seq_ptr = (W_ptr + stride_wh * head_id + stride_am *\n seq_start_offset)\n _forward_one_row(seq_a_block_id, seq_length, qk_scale, M_range,\n N_range, D_range, D_mask, cm, Q_head_seq_ptr, stride_qm,\n stride_qd, K_head_seq_ptr, stride_kn, stride_kd,\n V_head_seq_ptr, stride_vn, stride_vd, O_head_seq_ptr,\n stride_om, stride_od, R_head_seq_ptr, stride_rm,\n A_head_seq_ptr, stride_am, W_head_seq_ptr, stride_wm,\n stride_wn, BLOCK_D, NO_D_MASK, NO_M_MASK, NO_N_MASK,\n ALLOW_TF32, BLOCK_M, BLOCK_N, no_grad, acc_dtype,\n return_attention, use_cumsum=use_cumsum, attend_current=\n attend_current)\n if seq_b_block_id >= 0 and fhead_id * 2 + 1 < num_heads:\n head_id = fhead_id * 2 + 1\n Q_head_seq_ptr = (Q_ptr + stride_qh * head_id + stride_qm *\n seq_start_offset)\n K_head_seq_ptr = (K_ptr + stride_kh * head_id + stride_kn *\n seq_start_offset)\n V_head_seq_ptr = (V_ptr + stride_vh * head_id + stride_vn *\n seq_start_offset)\n O_head_seq_ptr = (O_ptr + stride_oh * head_id + stride_om *\n seq_start_offset)\n R_head_seq_ptr = (R_ptr + stride_rh * head_id + stride_rm *\n seq_start_offset)\n A_head_seq_ptr = (A_ptr + stride_ah * head_id + stride_am *\n seq_start_offset)\n W_head_seq_ptr = (W_ptr + stride_wh * head_id + stride_am *\n seq_start_offset)\n _forward_one_row(seq_b_block_id, seq_length, qk_scale, M_range,\n N_range, D_range, D_mask, cm, Q_head_seq_ptr, stride_qm,\n stride_qd, K_head_seq_ptr, stride_kn, stride_kd,\n V_head_seq_ptr, stride_vn, stride_vd, O_head_seq_ptr,\n stride_om, stride_od, R_head_seq_ptr, stride_rm,\n A_head_seq_ptr, stride_am, W_head_seq_ptr, stride_wm,\n stride_wn, BLOCK_D, NO_D_MASK, NO_M_MASK, NO_N_MASK,\n ALLOW_TF32, BLOCK_M, BLOCK_N, no_grad, acc_dtype,\n return_attention, use_cumsum=use_cumsum, attend_current=\n attend_current)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_fwd.py" }, { "uuid": "fdbc848d-92d3-499e-a813-fa9e22d5993a", "file_name": "l2norm.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/l2norm.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16, 32]], key=['N'])\n@triton.jit\ndef l2norm_bwd_kernel(X, DY, DX, stride_x_row, N, eps, BLOCK_N: tl.constexpr):\n row = tl.program_id(0)\n X += row * stride_x_row\n DX += row * stride_x_row\n DY += row * stride_x_row\n cols = tl.arange(0, BLOCK_N)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n x = tl.where(cols < N, x, 0.0)\n var = tl.sum(x * x)\n rstd = 1 / tl.sqrt(var + eps)\n mask = cols < N\n dy = tl.load(DY + cols, mask=cols < N, other=0.0).to(tl.float32)\n dy = tl.where(cols < N, dy, 0.0)\n dx = dy * rstd - tl.sum(dy * x) * (1 / (var + eps)) * rstd * x\n tl.store(DX + cols, dx, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/l2norm.py" }, { "uuid": "e3c53215-9ddd-4e38-942f-2dfc120fb36c", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef load_full_1d(ptr, sz: tl.constexpr, stride=1):\n \"\"\"Load 1d block [0,...,sz-1]\"\"\"\n offs = get_1d_offest(sz)\n mask = get_1d_mask(offs, sz)\n return tl.load(ptr + offs, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "78bedff7-31b2-401f-b494-a038e6470b98", "file_name": "glu_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/glu_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=element_wise_kernel_configs(), key=['size'])\n@triton.jit\ndef glu_forward_kernel(input1_pointer, input2_pointer, output_pointer, size,\n param, act_func: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n Applies the gated linear unit with an arbitrary activation function\n to the input.\n\n Args:\n input1_pointer: Pointer to the first half of the input to gate.\n The first half must be contiguous and contain size elements.\n input2_pointer: Pointer to the second half of the input to gate.\n The second half must be contiguous and contain size elements.\n output_pointer: Pointer to a container the result is written to.\n The container must be contiguous and contain size elements.\n size: Number of elements in each half of the input.\n param: Parameter in the case of parameterized activation functions.\n act_func: Name of activation function to apply.\n Options are 'sigmoid', 'tanh', 'relu', 'gelu', 'silu',\n 'relu6', 'hardsigmoid', 'hardswish', 'selu', 'mish', and 'leaky_relu'.\n BLOCK_SIZE: Block size.\n \"\"\"\n pid = tl.program_id(axis=0)\n offset = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offset < size\n input1 = tl.load(input1_pointer + offset, mask=mask)\n input2 = tl.load(input2_pointer + offset, mask=mask)\n output = input1 * apply_act_func(input2, None, None, None, param,\n act_func, False)\n tl.store(output_pointer + offset, output, mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/glu_kernels.py" }, { "uuid": "87d0765e-cecf-486a-95fb-7d23c0b6a3f0", "file_name": "bucketed_argmax.py", "repo_name": "graphcore-research/pytorch-approx-topk", "file_path": "approx_topk/experimental/bucketed_argmax.py", "commit_hash": "339eea971f17bf810e2eec746a06b9c93dc4cce0", "starcount": 0, "input": "@triton.jit\ndef _topk_triton_kernel__parallel_bk(xs_ptr, values_out_ptr,\n indices_out_ptr, b: int, k: int, n: int, n_chunk: int, xs_stride: int,\n BLOCK_SIZE: tl.constexpr, PAD_VALUE: tl.constexpr, INTERLEAVED: tl.\n constexpr):\n pidx = tl.program_id(axis=0).to(tl.int64)\n bk_idx = BLOCK_SIZE * pidx + tl.arange(0, BLOCK_SIZE)\n b_idx, k_idx = bk_idx // k, bk_idx % k\n xs_ptr += b_idx * xs_stride\n if INTERLEAVED:\n k_stride, i_stride = 1, k\n else:\n k_stride, i_stride = n_chunk, 1\n mask = (b_idx < b) & (k_idx * k_stride < n)\n max_value = tl.load(xs_ptr + k_idx * k_stride, mask=mask, other=PAD_VALUE)\n max_i = tl.zeros((BLOCK_SIZE,), tl.int64)\n for i in tl.range(1, n_chunk):\n mask = (b_idx < b) & (k_idx * k_stride + i * i_stride < n)\n block = tl.load(xs_ptr + k_idx * k_stride + i * i_stride, mask=mask,\n other=PAD_VALUE)\n mask &= max_value < block\n max_value = tl.where(mask, block, max_value)\n max_i = tl.where(mask, i, max_i)\n max_index = k_idx * k_stride + max_i * i_stride\n tl.store(values_out_ptr + b_idx * k + k_idx, max_value, mask=b_idx < b)\n tl.store(indices_out_ptr + b_idx * k + k_idx, max_index, mask=b_idx < b)\n", "category": { "Functionality": [ "Top-K Selection" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/graphcore-research/pytorch-approx-topk/blob/339eea971f17bf810e2eec746a06b9c93dc4cce0/approx_topk/experimental/bucketed_argmax.py" }, { "uuid": "c66dd256-37a5-4e14-9622-5ef0661c9e4c", "file_name": "decay.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/decay.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef masked_add_kernel(grad_ptr, p_ptr, p_mask_ptr, n_elements, alpha,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n p_mask = tl.load(p_mask_ptr + offsets, mask=mask).to(tl.int1)\n mask = mask & ~p_mask\n p = tl.load(p_ptr + offsets, mask=mask)\n grad = tl.load(grad_ptr + offsets, mask=mask)\n grad += p * alpha\n tl.store(grad_ptr + offsets, grad, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/decay.py" }, { "uuid": "64df009f-59cf-495e-b5c2-0456d955bdc3", "file_name": "linear.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/kernels/linear.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef gelu(x):\n c = 0.7978845608028654\n x_cubed = x * x * x\n tanh_arg = c * (x + 0.044715 * x_cubed)\n tanh_result = tanh(tanh_arg)\n return 0.5 * x * (1 + tanh_result)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/kernels/linear.py" }, { "uuid": "e786250d-5d3e-44b4-8ec6-304092edb0a2", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_linear_attn_bwd_kernel(q, k, v, do, dq, dk, dv, h0, s_k_h,\n s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, scale, B, H, T, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, CHECK: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(h0 + i_bh * K * V, (V, K), (1, V), (i_v *\n BV, i_k * BK), (BV, BK), (0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n for i in range(0, tl.cdiv(T, BT)):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i * BT, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (\n i_v * BV, i * BT), (BV, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dq = tl.make_block_ptr(dq + (i_bh + i_v * B * H) * s_k_h, (T, K),\n (s_k_t, s_k_d), (i * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_ds = tl.dot(b_do, b_v, allow_tf32=False)\n b_ds = tl.where(m_s, b_ds, 0)\n b_dq = tl.dot(b_ds.to(b_k.dtype), b_k, allow_tf32=False)\n if CHECK and i == 0:\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_v, b_k, allow_tf32=False)\n else:\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_v, b_k, allow_tf32=False)\n b_dq *= scale\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n b_h = None\n tl.debug_barrier()\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n m_s = o_i[:, None] <= o_i[None, :]\n for i in range(1, tl.cdiv(T, BT) + 1):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, T - i * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n T - i * BT, i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n T - i * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (T - i * BT, i_v * BV), (BT, BV), (1, 0))\n p_dk = tl.make_block_ptr(dk + (i_bh + i_v * B * H) * s_k_h, (T, K),\n (s_k_t, s_k_d), (T - i * BT, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + i_k * B * H) * s_v_h, (T, V),\n (s_v_t, s_v_d), (T - i * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_s = tl.dot(b_k, b_q, allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0).to(b_q.dtype)\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False)\n b_ds = tl.where(m_s, b_ds, 0).to(b_q.dtype)\n b_dk = tl.dot(b_ds, tl.trans(b_q), allow_tf32=False)\n b_dv = tl.dot(b_s, b_do, allow_tf32=False)\n if CHECK and i == 1:\n b_dk += tl.dot(b_v, tl.trans(b_dh).to(b_v.dtype), allow_tf32=False)\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False)\n b_dh += tl.dot(b_q, b_do, allow_tf32=False)\n else:\n b_dk += tl.dot(b_v, tl.trans(b_dh).to(b_v.dtype), allow_tf32=False)\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype), allow_tf32=False)\n b_dh += tl.dot(b_q, b_do, allow_tf32=False)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "bf16", "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/fused_chunk.py" }, { "uuid": "36a84d74-811a-47c3-b0f6-b6e9716f4768", "file_name": "partition_k.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/gemm/partition_k.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.jit\ndef _reduce(c_ptr, c_buf_ptr, M, N, stride_cm, stride_cn, stride_cb_m,\n stride_cb_n, stride_cb_k, PK: tl.constexpr, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr):\n pid = tl.program_id(0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_m = pid // num_pid_m\n pid_n = pid % num_pid_n\n offs_m = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_n = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, PK)\n c_buf_ptrs = c_buf_ptr + (offs_m[:, None, None] * stride_cb_m + offs_n[\n None, :, None] * stride_cb_n + offs_k[None, None, :] * stride_cb_k)\n c_buf = tl.load(c_buf_ptrs)\n reduced_k = tl.sum(c_buf, axis=2)\n c_ptrs = c_ptr + (offs_m[:, None] * stride_cm + offs_n[None, :] * stride_cn\n )\n tl.store(c_ptrs, reduced_k)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/gemm/partition_k.py" }, { "uuid": "d0677865-01e5-4cad-8f2a-27ff2419f1c7", "file_name": "_semi_structured_conversions.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/_semi_structured_conversions.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _MVUE24_approx(x0, x1, x2, x3, random0, random1):\n eps = 1.19209e-07\n a0 = tl.abs(x0) + eps\n a1 = tl.abs(x1) + eps\n a2 = tl.abs(x2) + eps\n a3 = tl.abs(x3) + eps\n sum = a0 + a1 + a2 + a3\n t0 = a0 / sum\n t1 = a1 / sum\n t2 = a2 / sum\n t3 = a3 / sum\n s0 = sum - a0\n s1 = sum - a1\n s2 = sum - a2\n s3 = sum - a3\n k0 = t0 / s0\n k1 = t1 / s1\n k2 = t2 / s2\n k3 = t3 / s3\n k = k0 + k1 + k2 + k3\n p0 = t0 + a0 * (k - k0)\n p1 = t1 + a1 * (k - k1)\n p2 = t2 + a2 * (k - k2)\n p3 = t3 + a3 * (k - k3)\n m0 = random0 <= t0\n m1 = (random0 <= t0 + t1) & ~m0\n m2 = (random0 <= t0 + t1 + t2) & ~m1 & ~m0\n m3 = ~m2 & ~m1 & ~m0\n d_a0 = ~m0 * a0\n d_a1 = ~m1 * a1\n d_a2 = ~m2 * a2\n d_a3 = ~m3 * a3\n d_sum = d_a0 + d_a1 + d_a2 + d_a3\n t = random1 * d_sum\n d_m0 = t <= d_a0\n d_m1 = (t <= d_a0 + d_a1) & ~d_m0\n d_m2 = (t <= d_a0 + d_a1 + d_a2) & ~d_m1 & ~d_m0\n d_m3 = ~d_m2 & ~d_m1 & ~d_m0\n m0, m1, m2, m3 = m0 | d_m0, m1 | d_m1, m2 | d_m2, m3 | d_m3\n a0 = x0 / p0\n a1 = x1 / p1\n a2 = x2 / p2\n a3 = x3 / p3\n return a0, a1, a2, a3, m0, m1, m2, m3\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/_semi_structured_conversions.py" }, { "uuid": "ccc604f8-18e9-45f5-b245-d3cc28061db6", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef fwd_recompute_w_u_kernel(k, v, beta, w, u, A, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.\n constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_u = tl.make_block_ptr(u + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_u = tl.make_block_ptr(u + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_vb = (b_v * b_beta[:, None]).to(b_v.dtype)\n b_u = tl.dot(b_A.to(b_vb.dtype), b_vb, allow_tf32=False)\n tl.store(p_u, b_u.to(p_u.dtype.element_ty), boundary_check=(0, 1))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_w = tl.make_block_ptr(w + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_w = tl.dot(b_A.to(b_kb.dtype), b_kb, allow_tf32=False)\n tl.store(p_w, b_w.to(p_w.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/wy_fast.py" }, { "uuid": "326e20e4-4217-4f1d-919d-85d0480d4692", "file_name": "test_triton.py", "repo_name": "pytorch/xla", "file_path": "test/test_triton.py", "commit_hash": "40efdb7b6571ce92797b5ba42619b79c1b147b3e", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr, V_block_ptr, start_m,\n qk_scale, BLOCK_M: tl.constexpr, HEAD_DIM: tl.constexpr, BLOCK_N: tl.\n constexpr, STAGE: tl.constexpr, offs_m: tl.constexpr, offs_n: tl.\n constexpr, N_CTX: tl.constexpr, fp8_v: tl.constexpr):\n if STAGE == 1:\n lo, hi = 0, start_m * BLOCK_M\n elif STAGE == 2:\n lo, hi = start_m * BLOCK_M, (start_m + 1) * BLOCK_M\n lo = tl.multiple_of(lo, BLOCK_M)\n else:\n lo, hi = 0, N_CTX\n K_block_ptr = tl.advance(K_block_ptr, (0, lo))\n V_block_ptr = tl.advance(V_block_ptr, (lo, 0))\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(K_block_ptr)\n qk = tl.dot(q, k)\n if STAGE == 2:\n mask = offs_m[:, None] >= start_n + offs_n[None, :]\n qk = qk * qk_scale + tl.where(mask, 0, -1000000.0)\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n qk -= m_ij[:, None]\n else:\n m_ij = tl.maximum(m_i, tl.max(qk, 1) * qk_scale)\n qk = qk * qk_scale - m_ij[:, None]\n p = tl.math.exp2(qk)\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp2(m_i - m_ij)\n l_i = l_i * alpha + l_ij\n acc = acc * alpha[:, None]\n v = tl.load(V_block_ptr)\n if fp8_v:\n p = p.to(tl.float8e5)\n else:\n p = p.to(tl.float16)\n acc = tl.dot(p, v, acc)\n m_i = m_ij\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch/xla/blob/40efdb7b6571ce92797b5ba42619b79c1b147b3e/test/test_triton.py" }, { "uuid": "49f3c6b9-1c5a-473c-9559-2dfc1c27c665", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_gla_fwd_kernel(q, k, v, g, o, h0, ht, s_k_h, s_k_t, s_k_d,\n s_v_h, s_v_t, s_v_d, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr,\n BV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE:\n tl.constexpr, CHECK: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (0, \n i_k * BK), (BT, BK), (1, 0))\n p_db = g + i_bh * s_k_h + (BT - 1) * s_k_t + i_k * BK + tl.arange(0, BK)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, 0), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (0, \n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (i_bh + i_k * B * H) * s_v_h, (T, V), (\n s_v_t, s_v_d), (0, i_v * BV), (BT, BV), (1, 0))\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(h0 + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n mask = i_k * BK + tl.arange(0, BK) < K\n for i in range(0, tl.cdiv(T, BT)):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n d_b = tl.load(p_db, mask=mask, other=0).to(tl.float32)\n if CHECK and i == 0:\n b_o = tl.dot(b_q.to(b_v.dtype), b_h.to(b_v.dtype), allow_tf32=False\n )\n b_h = b_h * tl.exp(d_b)[:, None] + tl.dot(b_k.to(b_v.dtype),\n b_v, allow_tf32=False)\n else:\n b_o = tl.dot(b_q.to(b_v.dtype), b_h.to(b_v.dtype), allow_tf32=False\n )\n b_h = b_h * tl.exp(d_b)[:, None] + tl.dot(b_k.to(b_v.dtype),\n b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_q = tl.advance(p_q, (BT, 0))\n p_k = tl.advance(p_k, (0, BT))\n p_v = tl.advance(p_v, (BT, 0))\n p_o = tl.advance(p_o, (BT, 0))\n p_db += BT * K\n if STORE_FINAL_STATE:\n p_final = tl.make_block_ptr(ht + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_final, b_h.to(p_final.dtype.element_ty), boundary_check=\n (0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/fused_chunk.py" }, { "uuid": "9e707ccc-8655-4571-8d88-7225cd973c4c", "file_name": "triton_kernel.py", "repo_name": "yann-Choho/projet_PPML", "file_path": "notebooks/triton_kernel.py", "commit_hash": "9274e0561443b01f029ee6e0737f922f71d2da39", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['M', 'N', 'K'])\n@triton.jit\ndef ff_llama_with_rmsnorm(a_ptr, w1_ptr, w3_ptr, out_ptr, rms_w_ptr, M, N,\n K, stride_am, stride_ak, stride_w1k, stride_w1n, stride_w3k, stride_w3n,\n stride_outm, stride_outn, stride_rms_w, USE_FP8: tl.constexpr, EPS: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr):\n \"\"\"\n A Triton kernel for performing feed-forward operations in a LLaMA model.\n \n This kernel computes the feed-forward transformation using the following operations:\n w1 and w3 are weights (linear layers)\n F.silu(w1(x)) * w3(x)\n \n Args:\n a_ptr: Pointer to the input tensor.\n w1_ptr: Pointer to the first weight tensor.\n w3_ptr: Pointer to the third weight tensor.\n out_ptr: Pointer to the output tensor.\n rms_w_ptr: Pointer to the RMS normalization weights.\n M: Number of rows in the input tensor.\n N: Number of columns in the weight tensors.\n K: Number of columns in the input tensor.\n stride_am: Stride of the input tensor in the first dimension.\n stride_ak: Stride of the input tensor in the second dimension.\n stride_w1k: Stride of the first weight tensor in the first dimension.\n stride_w1n: Stride of the first weight tensor in the second dimension.\n stride_w3k: Stride of the third weight tensor in the first dimension.\n stride_w3n: Stride of the third weight tensor in the second dimension.\n stride_outm: Stride of the output tensor in the first dimension.\n stride_outn: Stride of the output tensor in the second dimension.\n stride_rms_w: Stride of the RMS normalization weights.\n USE_FP8: Constant specifying whether to use FP8 precision.\n EPS: Constant epsilon value for numerical stability in RMS normalization.\n BLOCK_SIZE_M: Constant block size in the M dimension.\n BLOCK_SIZE_N: Constant block size in the N dimension.\n BLOCK_SIZE_K: Constant block size in the K dimension.\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_m = pid // tl.cdiv(N, BLOCK_SIZE_N)\n pid_n = pid % tl.cdiv(N, BLOCK_SIZE_N)\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n w1_ptrs = w1_ptr + (offs_k[:, None] * stride_w1k + offs_bn[None, :] *\n stride_w1n)\n w3_ptrs = w3_ptr + (offs_k[:, None] * stride_w3k + offs_bn[None, :] *\n stride_w3n)\n acc1 = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n acc2 = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n rms_w_ptrs = rms_w_ptr + tl.arange(0, BLOCK_SIZE_K)[None, :] * stride_rms_w\n a_sum = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_K), dtype=tl.float32)\n for _ in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs)\n a_sum += tl.math.pow(a.to(tl.float32), 2)\n rms_w = tl.load(rms_w_ptrs)\n if USE_FP8:\n rms_w = rms_w.to(tl.float8e5, bitcast=True)\n rms_w = rms_w.to(tl.float16)\n a = a * rms_w\n b = tl.load(w1_ptrs)\n if USE_FP8:\n b = b.to(tl.float8e5, bitcast=True)\n b = b.to(tl.float32)\n b = b.to(tl.float16)\n acc1 += tl.dot(a, b)\n c = tl.load(w3_ptrs)\n if USE_FP8:\n c = c.to(tl.float8e5, bitcast=True)\n c = c.to(tl.float32)\n c = c.to(tl.float16)\n acc2 += tl.dot(a, c)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n w1_ptrs += BLOCK_SIZE_K * stride_w1k\n w3_ptrs += BLOCK_SIZE_K * stride_w3k\n rms_w_ptrs += BLOCK_SIZE_K * stride_rms_w\n a_mean = tl.sum(a_sum, axis=1) / K + EPS\n a_norm = tl.math.rsqrt(a_mean)\n acc1 = acc1 * a_norm[:, None]\n acc2 = acc2 * a_norm[:, None]\n accumulator = acc1 * tl.sigmoid(acc1) * acc2\n offs_outm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_outn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n out_ptrs = out_ptr + (stride_outm * offs_outm[:, None] + stride_outn *\n offs_outn[None, :])\n out_mask = (offs_outm[:, None] < M) & (offs_outn[None, :] < N)\n tl.store(out_ptrs, accumulator, mask=out_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Normalization", "Activation Functions" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/yann-Choho/projet_PPML/blob/9274e0561443b01f029ee6e0737f922f71d2da39/notebooks/triton_kernel.py" }, { "uuid": "2f039813-0a4f-434e-8684-dfa2962e6c20", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rebased/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_rebased_bwd_kernel(q, k, v, do, dz, dq, dk, dv, s_k_h, s_k_t,\n s_k_d, s_v_h, s_v_t, s_v_d, scale, B: tl.constexpr, H: tl.constexpr, T:\n tl.constexpr, K: tl.constexpr, V: tl.constexpr, BTL: tl.constexpr, BTS:\n tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n i_kv, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n NV = tl.cdiv(V, BV)\n i_k = i_kv // NV\n i_v = i_kv % NV\n i_h = i_bh % H\n _parallel_rebased_bwd_dq(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dq,\n s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, scale, B=B, H=H, T=T, K=K,\n V=V, BTL=BTL, BTS=BTS, BK=BK, BV=BV)\n tl.debug_barrier()\n _parallel_rebased_bwd_dkv(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dk,\n dv, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, scale, B=B, H=H, T=T,\n K=K, V=V, BTL=BTL, BTS=BTS, BK=BK, BV=BV)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rebased/parallel.py" }, { "uuid": "fb256f38-277f-4402-8b55-cf02270b1533", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef matrix_mult(x, y, B):\n return tl.dot(x, y) if B >= 16 else tl.sum(x[:, :, None] * y, 1)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "c186aa78-7e7f-494d-bcc8-d002861dceb2", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BK', 'BT'])\n@triton.jit\ndef chunk_rwkv6_fwd_A_kernel_intra_sub_intra(q, k, gi, ge, u, A, offsets,\n indices, scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, BT:\n tl.constexpr, BC: tl.constexpr, BK: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_i, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_j = i_i\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if i_t * BT + i_i * BC >= T:\n return\n o_i = tl.arange(0, BC)\n o_k = tl.arange(0, BK)\n m_k = o_k < K\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n if HEAD_FIRST:\n o_A = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_j * BC\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, 0), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(ge + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, 0), (BC, BK), (1, 0))\n p_qj = tl.max_contiguous(tl.multiple_of(q + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n p_kj = tl.max_contiguous(tl.multiple_of(k + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(gi + (i_bh * T + i_t * BT +\n i_j * BC) * K + o_k, BK), BK)\n else:\n o_A = (bos + i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * H * BT + i_h * BT + i_j * BC\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, 0), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(ge + (bos * H + i_h) * K, (T, K), (H * K, 1\n ), (i_t * BT + i_i * BC, 0), (BC, BK), (1, 0))\n p_qj = tl.max_contiguous(tl.multiple_of(q + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_kj = tl.max_contiguous(tl.multiple_of(k + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(gi + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n p_u = tl.make_block_ptr(u + i_h * K, (K,), (1,), (0,), (BK,), (0,))\n b_u = tl.load(p_u, boundary_check=(0,))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_qj = tl.load(p_qj, mask=m_k, other=0).to(tl.float32)\n b_kj = tl.load(p_kj, mask=m_k, other=0).to(tl.float32)\n b_gk = tl.load(p_gk, mask=m_k, other=0).to(tl.float32)\n b_A = tl.sum(b_q * b_kj[None, :] * tl.exp(b_g - b_gk[None, :]), 1)\n b_A = tl.where(o_i > j, b_A * scale, 0.0)\n b_A = tl.where(o_i != j, b_A, tl.sum(b_qj * b_kj * b_u * scale))\n tl.store(A + o_A + j, b_A, mask=m_A)\n p_qj += K if HEAD_FIRST else H * K\n p_kj += K if HEAD_FIRST else H * K\n p_gk += K if HEAD_FIRST else H * K\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "48379ee8-f2ff-4497-a0e7-85d8537a7560", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_delta_rule_fwd_kernel_o(q, k, v, h, o, offsets, indices, scale, T:\n tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl\n .constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_s = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (\n V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n b_s += tl.dot(b_q, b_k, allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_o = b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/chunk.py" }, { "uuid": "beebe0e4-2407-465c-b381-0707292d593f", "file_name": "conv_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/conv_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=[conv2d_forward_config(128, 32, 128, n_warps=8,\n n_stages=2), conv2d_forward_config(256, 32, 64, n_warps=8, n_stages=2),\n conv2d_forward_config(256, 32, 32, n_warps=4, n_stages=4),\n conv2d_forward_config(256, 64, 32, n_warps=4, n_stages=4),\n conv2d_forward_config(256, 32, 16, n_warps=2, n_stages=4),\n conv2d_forward_config(64, 32, 128, n_warps=8, n_stages=4),\n conv2d_forward_config(128, 32, 64, n_warps=4, n_stages=4),\n conv2d_forward_config(64, 32, 64, n_warps=4, n_stages=4),\n conv2d_forward_config(128, 32, 16, n_warps=4, n_stages=4),\n conv2d_forward_config(128, 128, 128, n_warps=8, n_stages=3),\n conv2d_forward_config(256, 128, 64, n_warps=8, n_stages=3),\n conv2d_forward_config(256, 128, 32, n_warps=4, n_stages=4),\n conv2d_forward_config(64, 128, 128, n_warps=4, n_stages=4),\n conv2d_forward_config(128, 128, 64, n_warps=4, n_stages=4),\n conv2d_forward_config(128, 64, 32, n_warps=2, n_stages=4),\n conv2d_forward_config(64, 64, 64, n_warps=2, n_stages=4)], key=[\n 'batch_dim', 'in_feat_dim', 'in_height', 'in_width', 'out_feat_dim',\n 'out_height', 'out_width', 'kernel_height', 'kernel_width',\n 'stride_height', 'stride_width', 'padding_height', 'padding_width',\n 'groups', 'fp16'])\n@triton.heuristics({'tf32': lambda _: allow_tf32()})\n@triton.jit\ndef conv2d_forward_kernel(input_pointer, weight_pointer, output_pointer,\n batch_dim, in_feat_dim, in_height, in_width, out_feat_dim, out_height,\n out_width, input_batch_stride, input_in_feat_stride,\n input_height_stride, input_width_stride, weight_out_feat_stride,\n weight_in_feat_stride, weight_height_stride, weight_width_stride,\n output_batch_stride, output_out_feat_stride, output_height_stride,\n output_width_stride, kernel_height: tl.constexpr, kernel_width: tl.\n constexpr, stride_height: tl.constexpr, stride_width: tl.constexpr,\n padding_height: tl.constexpr, padding_width: tl.constexpr, groups: tl.\n constexpr, fp16: tl.constexpr, tf32: tl.constexpr,\n BLOCK_SIZE_BATCH_HEIGHT_WIDTH: tl.constexpr, BLOCK_SIZE_IN_FEAT: tl.\n constexpr, BLOCK_SIZE_OUT_FEAT: tl.constexpr):\n \"\"\"\n 2D-convolves over the input using weights.\n\n Args:\n input_pointer: Pointer to the input to convolve over.\n The input must be of shape [batch_dim, in_feat_dim, in_height, in_width].\n weight_pointer: Pointer to the weights input is convolved over by.\n The weights must be of shape [out_feat_dim, in_feat_dim, kernel_height, kernel_width].\n output_pointer: Pointer to a container the result is written to.\n The container must be of shape [batch_dim, out_feat_dim, out_height, out_width].\n batch_dim: Batch dimension of the input and output.\n in_feat_dim: Dimensionality of the input features.\n in_height: Input height.\n in_width: Input width.\n out_feat_dim: Dimensionality of the output features.\n out_height: Output height.\n out_width: Output width.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_in_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n input_height_stride: Stride necessary to jump one element along the\n input's height dimension.\n input_width_stride: Stride necessary to jump one element along the\n input's width dimension.\n weight_out_feat_stride: Stride necessary to jump one element along the\n weights' output feature dimension.\n weight_in_feat_stride: Stride necessary to jump one element along the\n weights' input feature dimension.\n weight_height_stride: Stride necessary to jump one element along the\n weights' height dimension.\n weight_width_stride: Stride necessary to jump one element along the\n weights' width dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output's batch dimension.\n output_out_feat_stride: Stride necessary to jump one element along the\n output's feature dimension.\n output_height_stride: Stride necessary to jump one element along the\n output's height dimension.\n output_width_stride: Stride necessary to jump one element along the\n output's width dimension.\n kernel_height: Kernel height.\n kernel_width: Kernel width.\n stride_height: Stride of kernel across the height dimension.\n stride_width: Stride of kernel across the width dimension.\n padding_height: Padding applied to the input across the height dimension.\n padding_width: Padding applied to the input across the width dimension.\n groups: Number of groups for the convolution.\n fp16: Flag for loading the input and weights in FP16.\n tf32: Flag for performing matrix products in TF32.\n BLOCK_SIZE_BATCH_HEIGHT_WIDTH: Block size across the batch, height, and\n width dimensions.\n BLOCK_SIZE_IN_FEAT: Block size across the input feature dimension.\n BLOCK_SIZE_OUT_FEAT: Block size across the output feature dimension.\n \"\"\"\n batch_height_width_pid = tl.program_id(0)\n out_feat_pid = tl.program_id(1)\n group_pid = tl.program_id(2)\n in_group_dim = in_feat_dim // groups\n out_group_dim = out_feat_dim // groups\n batch_height_width_offset = (batch_height_width_pid *\n BLOCK_SIZE_BATCH_HEIGHT_WIDTH + tl.arange(0,\n BLOCK_SIZE_BATCH_HEIGHT_WIDTH))\n batch_height_offset = batch_height_width_offset // out_width\n batch_offset = batch_height_offset // out_height\n output_feat_offset = out_feat_pid * BLOCK_SIZE_OUT_FEAT + tl.arange(0,\n BLOCK_SIZE_OUT_FEAT)\n output_height_offset = batch_height_offset % out_height\n output_width_offset = batch_height_width_offset % out_width\n input_pointer += (input_batch_stride * batch_offset + \n input_in_feat_stride * group_pid * in_group_dim)[:, None]\n weight_pointer += (weight_out_feat_stride * output_feat_offset + \n weight_out_feat_stride * group_pid * out_group_dim)[None, :]\n accum = tl.zeros((BLOCK_SIZE_BATCH_HEIGHT_WIDTH, BLOCK_SIZE_OUT_FEAT),\n dtype=tl.float32)\n for h in range(kernel_height):\n for w in range(kernel_width):\n for c in range(0, in_group_dim, BLOCK_SIZE_IN_FEAT):\n input_feat_offset = c + tl.arange(0, BLOCK_SIZE_IN_FEAT)\n input_height_offset = (h - padding_height + stride_height *\n output_height_offset)\n input_width_offset = (w - padding_width + stride_width *\n output_width_offset)\n curr_input_pointer = input_pointer + (input_in_feat_stride *\n input_feat_offset)[None, :] + (input_height_stride *\n input_height_offset)[:, None] + (input_width_stride *\n input_width_offset)[:, None]\n curr_weight_pointer = weight_pointer + (weight_in_feat_stride *\n input_feat_offset)[:, None\n ] + weight_height_stride * h + weight_width_stride * w\n input_mask = (batch_offset < batch_dim)[:, None] & (\n input_feat_offset < in_group_dim)[None, :] & (0 <=\n input_height_offset)[:, None] & (input_height_offset <\n in_height)[:, None] & (0 <= input_width_offset)[:, None\n ] & (input_width_offset < in_width)[:, None]\n weight_mask = (input_feat_offset < in_group_dim)[:, None] & (\n output_feat_offset < out_group_dim)[None, :]\n input_block = tl.load(curr_input_pointer, mask=input_mask)\n weight_block = tl.load(curr_weight_pointer, mask=weight_mask)\n if fp16:\n input_block = input_block.to(tl.float16)\n weight_block = weight_block.to(tl.float16)\n accum += tl.dot(input_block, weight_block, allow_tf32=tf32)\n output_pointer += (output_batch_stride * batch_offset)[:, None] + (\n output_out_feat_stride * (group_pid * out_group_dim +\n output_feat_offset))[None, :] + (output_height_stride *\n output_height_offset)[:, None] + (output_width_stride *\n output_width_offset)[:, None]\n output_mask = (batch_offset < batch_dim)[:, None] & (output_feat_offset <\n out_group_dim)[None, :] & (output_height_offset < out_height)[:, None\n ] & (output_width_offset < out_width)[:, None]\n tl.store(output_pointer, accum, mask=output_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/conv_kernels.py" }, { "uuid": "54b68535-dd6a-428b-ba2c-aacf68f8e026", "file_name": "triton_rms_norm.py", "repo_name": "vladmandic/dcae", "file_path": "dcae/nn/triton_rms_norm.py", "commit_hash": "5223970c7e6c6acfe282e18be7e3821b61511673", "starcount": 0, "input": "@triton.jit\ndef _rms_norm_2d_fwd_fused(X, Y, W, B, Rrms, M, C, N, num_blocks, eps,\n BLOCK_SIZE: tl.constexpr):\n m_n = tl.program_id(0)\n m, n = m_n // num_blocks, m_n % num_blocks\n Y += m * C * N\n X += m * C * N\n cols = n * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n x_sum_square = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, C):\n x = tl.load(X + off * N + cols, mask=mask, other=0.0).to(tl.float32)\n x_sum_square += x * x\n mean_square = x_sum_square / C\n rrms = 1 / tl.sqrt(mean_square + eps)\n tl.store(Rrms + m * N + cols, rrms, mask=mask)\n for off in range(0, C):\n pos = off * N + cols\n w = tl.load(W + off)\n b = tl.load(B + off)\n x = tl.load(X + pos, mask=mask, other=0.0).to(tl.float32)\n x_hat = x * rrms\n y = x_hat * w + b\n tl.store(Y + pos, y, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/vladmandic/dcae/blob/5223970c7e6c6acfe282e18be7e3821b61511673/dcae/nn/triton_rms_norm.py" }, { "uuid": "01a67365-f163-429d-bbd8-8c27946656e2", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/generalized_delta_rule/iplr/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_bwd_kernel(q, k, v, alpha, beta, ha, dht, dh0, do, dq,\n dk, dv, dalpha, dbeta, dha, h0, s_k_h, s_v_h, NK, scale, B, H, T, K: tl\n .constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, USE_DH0: tl.constexpr, USE_DHT: tl.\n constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n mask_bk = i_k * BK + tl.arange(0, BK) < K\n mask_bv = i_v * BV + tl.arange(0, BV) < V\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_do = do + i_bh * s_v_h + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_v = v + i_bh * s_v_h + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_ha = ha + i_bh * s_v_h + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_alpha = alpha + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_beta = beta + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_dk = dk + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(0, BK) + (T\n - 1) * K\n p_dbeta = dbeta + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(0, BK\n ) + (T - 1) * K\n p_dv = dv + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV) + (T\n - 1) * V\n p_dha = dha + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV\n ) + (T - 1) * V\n d_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_DHT:\n p_ht = dht + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n d_h += tl.load(p_ht, mask=mask_bk[:, None] & mask_bv[None, :], other=0\n ).to(tl.float32)\n for _ in range(T):\n b_q = tl.load(p_q, mask=mask_bk, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_bk, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_bv, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_bv, other=0).to(tl.float32)\n b_beta = tl.load(p_beta, mask=mask_bk, other=0).to(tl.float32)\n b_alpha = tl.load(p_alpha, mask=mask_bk, other=0).to(tl.float32)\n b_ha = tl.load(p_ha, mask=mask_bv, other=0).to(tl.float32)\n d_h += b_q[:, None] * b_do[None, :]\n d_k = tl.sum(d_h * b_v[None, :], axis=1)\n d_v = tl.sum(d_h * b_k[:, None], axis=0)\n tl.store(p_dk, d_k.to(p_dk.dtype.element_ty), mask=mask_bk)\n tl.store(p_dv, d_v.to(p_dv.dtype.element_ty), mask=mask_bv)\n b_dha = tl.sum(d_h * b_beta[:, None], axis=0)\n tl.store(p_dha, b_dha.to(p_dha.dtype.element_ty), mask=mask_bv)\n b_dbeta = tl.sum(d_h * b_ha[None, :], axis=1)\n tl.store(p_dbeta, b_dbeta.to(p_dbeta.dtype.element_ty), mask=mask_bk)\n d_h += b_dha[None, :] * b_alpha[:, None]\n p_do -= V\n p_q -= K\n p_k -= K\n p_v -= V\n p_dk -= K\n p_dv -= V\n p_beta -= K\n p_dbeta -= K\n p_alpha -= K\n p_dha -= V\n p_ha -= V\n if USE_DH0:\n p_dh0 = dh0 + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n tl.store(p_dh0, d_h.to(p_dh0.dtype.element_ty), mask=mask_bk[:,\n None] & mask_bv[None, :])\n tl.debug_barrier()\n h = tl.zeros([BK, BV], dtype=tl.float32)\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_beta = beta + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_v = v + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_ha = ha + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_do = do + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(0, BK)\n p_dv = dv + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV)\n p_dha = dha + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV)\n p_alpha = alpha + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(0, BK\n )\n p_dalpha = dalpha + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(\n 0, BK)\n if USE_INITIAL_STATE:\n mask_kv = mask_bk[:, None] & mask_bv[None, :]\n p_h0 = h0 + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n h += tl.load(p_h0, mask=mask_kv, other=0).to(tl.float32)\n for i in range(0, T):\n d_ha = tl.load(p_dha, mask=mask_bv, other=0).to(tl.float32)\n d_alpha = tl.sum(d_ha[None, :] * h, axis=1)\n tl.store(p_dalpha, d_alpha.to(p_dalpha.dtype.element_ty), mask=mask_bk)\n b_k = tl.load(p_k, mask=mask_bk, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_bv, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_bv, other=0).to(tl.float32)\n b_beta = tl.load(p_beta, mask=mask_bk, other=0).to(tl.float32)\n b_ha = tl.load(p_ha, mask=mask_bv, other=0).to(tl.float32)\n h += b_k[:, None] * b_v[None, :] + b_beta[:, None] * b_ha[None, :]\n _d_q = h * b_do[None, :]\n d_q = tl.sum(_d_q, axis=1) * scale\n tl.store(p_dq, d_q.to(p_dq.dtype.element_ty), mask=mask_bk)\n p_k += K\n p_do += V\n p_v += V\n p_dk += K\n p_dalpha += K\n p_dha += V\n p_ha += V\n p_dq += K\n p_beta += K\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/generalized_delta_rule/iplr/fused_recurrent.py" }, { "uuid": "7e5bd5a2-7393-4fdc-8835-64d5a5604ecc", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_second_order_fwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, sh_1_0_ptr: tl.tensor, sh_1_1_ptr: tl.tensor, sh_1_2_ptr: tl.\n tensor, sh_2_0_ptr: tl.tensor, sh_2_1_ptr: tl.tensor, sh_2_2_ptr: tl.\n tensor, sh_2_3_ptr: tl.tensor, sh_2_4_ptr: tl.tensor, BLOCK_SIZE: tl.\n constexpr, vector_length: tl.constexpr):\n sqrt_3 = 3 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n sh_1_0 = x * sqrt_3\n sh_1_1 = y * sqrt_3\n sh_1_2 = z * sqrt_3\n sqrt_15 = 15 ** 0.5\n sqrt_5 = 5 ** 0.5\n sq_x = x * x\n sq_y = y * y\n sq_z = z * z\n sh_2_0 = sqrt_15 * x * z\n sh_2_1 = sqrt_15 * x * y\n sh_2_2 = sqrt_5 * (sq_y - 0.5 * (sq_x + sq_z))\n sh_2_3 = sqrt_15 * y * z\n sh_2_4 = 0.5 * sqrt_15 * (sq_z - sq_x)\n sh_1_0_start = sh_1_0_ptr + offset\n sh_1_1_start = sh_1_1_ptr + offset\n sh_1_2_start = sh_1_2_ptr + offset\n sh_2_0_start = sh_2_0_ptr + offset\n sh_2_1_start = sh_2_1_ptr + offset\n sh_2_2_start = sh_2_2_ptr + offset\n sh_2_3_start = sh_2_3_ptr + offset\n sh_2_4_start = sh_2_4_ptr + offset\n tl.store(sh_1_0_start, sh_1_0, mask=offset < vector_length)\n tl.store(sh_1_1_start, sh_1_1, mask=offset < vector_length)\n tl.store(sh_1_2_start, sh_1_2, mask=offset < vector_length)\n tl.store(sh_2_0_start, sh_2_0, mask=offset < vector_length)\n tl.store(sh_2_1_start, sh_2_1, mask=offset < vector_length)\n tl.store(sh_2_2_start, sh_2_2, mask=offset < vector_length)\n tl.store(sh_2_3_start, sh_2_3, mask=offset < vector_length)\n tl.store(sh_2_4_start, sh_2_4, mask=offset < vector_length)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "2692045b-1381-44b0-bcd7-ec5e84568124", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'\n ] is not None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [1, 2, 4, 8] for num_stages in [2, 3, 4]], key=['BT'])\n@triton.jit\ndef chunk_rwkv6_bwd_kernel_dh(q, gi, ge, do, dh, dht, dh0, offsets,\n chunk_offsets, scale, T: tl.constexpr, HQ: tl.constexpr, H: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, NG: tl.constexpr,\n STORE_INITIAL_STATE_GRADIENT: tl.constexpr, USE_FINAL_STATE_GRADIENT:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_nh // NG\n i_n, i_hq = i_nh // HQ, i_nh % HQ\n i_h = i_hq // NG\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT - 1, -1, -1):\n if HEAD_FIRST:\n p_dh = tl.make_block_ptr(dh + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_dh = tl.make_block_ptr(dh + ((boh + i_t) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_nh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * HQ + i_hq) * K, (K, T), (1, \n HQ * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(ge + i_bg * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gi + (i_bg * T + last_idx) * K + i_k * BK + tl.arange(\n 0, BK)\n else:\n p_gk = tl.make_block_ptr(ge + (bos * H + i_h) * K, (K, T), (1, \n H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gi + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_q = (b_q * tl.exp(b_gk) * scale).to(b_q.dtype)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) < K,\n other=0.0)\n b_dh *= tl.exp(b_gk_last)[:, None]\n b_dh += tl.dot(b_q, b_do)\n if STORE_INITIAL_STATE_GRADIENT:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "2845735e-85d3-4315-9d21-ce129b242704", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/based/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef _parallel_based_bwd_dkv(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dk,\n dv, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, B, H, T, scale, BTL: tl.\n constexpr, BTS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, K: tl\n .constexpr, V: tl.constexpr):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTL, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_c *\n BTL, i_v * BV), (BTL, BV), (1, 0))\n b_k, b_v = tl.load(p_k, boundary_check=(0, 1)), tl.load(p_v,\n boundary_check=(0, 1))\n b_dk, b_dv = tl.zeros([BTL, BK], dtype=tl.float32), tl.zeros([BTL, BV],\n dtype=tl.float32)\n for i in range(tl.cdiv(T, BTS) * BTS - BTS, (i_c + 1) * BTL - BTS, -BTS):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i), (BK, BTS), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (V, T), (s_v_d, s_v_t),\n (i_v * BV, i), (BV, BTS), (0, 1))\n p_dz = dz + i_bh * T + i + tl.arange(0, BTS)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_dz = tl.load(p_dz, mask=i + tl.arange(0, BTS) < T)\n b_s = tl.dot(b_k.to(b_q.dtype), b_q, allow_tf32=False) * scale\n b_s2 = 1 + b_s + 0.5 * b_s * b_s\n b_dv += tl.dot(b_s2.to(b_q.dtype), tl.trans(b_do), allow_tf32=False)\n b_ds = tl.dot(b_v, b_do, allow_tf32=False) * scale\n if i_v == 0:\n b_ds += b_dz[None, :] * scale\n else:\n b_ds = b_ds\n b_dk += tl.dot((b_ds + b_ds * b_s).to(b_q.dtype), tl.trans(b_q),\n allow_tf32=False)\n tl.debug_barrier()\n o_q, o_k = tl.arange(0, BTS), tl.arange(0, BTL)\n for i in range(i_c * BTL, (i_c + 1) * BTL, BTS):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i), (BK, BTS), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (V, T), (s_v_d, s_v_t),\n (i_v * BV, i), (BV, BTS), (0, 1))\n p_dz = dz + i_bh * T + i + tl.arange(0, BTS)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_dz = tl.load(p_dz, mask=i + tl.arange(0, BTS) < T)\n m_s = o_k[:, None] <= o_q[None, :]\n b_s = tl.dot(b_k, b_q, allow_tf32=False) * scale\n b_s2 = 1 + b_s + 0.5 * b_s * b_s\n b_s = tl.where(m_s, b_s, 0)\n b_s2 = tl.where(m_s, b_s2, 0)\n b_ds = tl.dot(b_v, b_do, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[None, :]\n else:\n b_ds = b_ds\n b_ds = tl.where(m_s, b_ds, 0) * scale\n b_dv += tl.dot(b_s2.to(b_q.dtype), tl.trans(b_do), allow_tf32=False)\n b_dk += tl.dot((b_ds + b_ds * b_s).to(b_q.dtype), tl.trans(b_q),\n allow_tf32=False)\n o_q += BTS\n p_dk = tl.make_block_ptr(dk + (i_bh + B * H * i_v) * s_k_h, (T, K), (\n s_k_t, s_k_d), (i_c * BTL, i_k * BK), (BTL, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + B * H * i_k) * s_v_h, (T, V), (\n s_v_t, s_v_d), (i_c * BTL, i_v * BV), (BTL, BV), (1, 0))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n return\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/based/parallel.py" }, { "uuid": "86340ed0-7aa9-45cf-8b18-cb8988e9b602", "file_name": "masks.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/flash/masks.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef inverse_causal_mask_triton(score, batch, head, seq_len_q, seq_len_kv):\n score = tl.where(seq_len_q > seq_len_kv, float('-inf'), score)\n return score\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/flash/masks.py" }, { "uuid": "aed79a3c-9b2f-4cb8-809d-b5eb89f04608", "file_name": "associative_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/associative_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _associative_rnn_scan_fwd_kernel(x_ptr, a_ptr, cum_a_ptr, out_ptr,\n stride_x_batch, stride_x_len, stride_x_dim, stride_a_batch,\n stride_a_len, stride_a_dim, stride_out_batch, stride_out_len,\n stride_out_dim, stride_cum_a_batch, stride_cum_a_len, stride_cum_a_dim,\n BLOCK_SIZE_LEN: tl.constexpr, BLOCK_SIZE_DIM: tl.constexpr):\n pid_batch = tl.program_id(0)\n pid_len = tl.program_id(1)\n pid_dim = tl.program_id(2)\n x_ptr += pid_batch * stride_x_batch\n a_ptr += pid_batch * stride_a_batch\n if cum_a_ptr is not None:\n cum_a_ptr += pid_batch * stride_cum_a_batch\n out_ptr += pid_batch * stride_out_batch\n offsets_dim = pid_dim * BLOCK_SIZE_DIM + tl.arange(0, BLOCK_SIZE_DIM)\n offsets_len = pid_len * BLOCK_SIZE_LEN + tl.arange(0, BLOCK_SIZE_LEN)\n x_ptrs = x_ptr + offsets_dim[None, :] * stride_x_dim + offsets_len[:, None\n ] * stride_x_len\n a_ptrs = a_ptr + offsets_dim[None, :] * stride_a_dim + offsets_len[:, None\n ] * stride_a_len\n out_ptrs = out_ptr + offsets_dim[None, :] * stride_out_dim + offsets_len[\n :, None] * stride_out_len\n if cum_a_ptr is not None:\n cum_a_ptrs = cum_a_ptr + offsets_dim[None, :\n ] * stride_cum_a_dim + offsets_len[:, None] * stride_cum_a_len\n x = tl.load(x_ptrs).to(tl.float32)\n a = tl.load(a_ptrs).to(tl.float32)\n cum_a, all_hiddens = tl.associative_scan(input=(a, x), axis=0,\n combine_fn=_associative_scan_op)\n mask = (offsets_len == (pid_len + 1) * BLOCK_SIZE_LEN - 1)[:, None]\n if cum_a_ptr is not None:\n tl.store(cum_a_ptrs, cum_a.to(cum_a_ptr.dtype.element_ty), mask=mask)\n tl.store(out_ptrs, all_hiddens.to(out_ptr.dtype.element_ty), mask=mask)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/associative_rnn_scan.py" }, { "uuid": "4df492d6-8632-47e9-80d8-2308db2c2a20", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef standardize(input, mean, inv_std, weight, bias):\n \"\"\"\n Standardizes the input given its mean and inverse standard deviation,\n multiplies the result by weights, and adds a bias vector.\n\n Args:\n input: Input to standardize.\n mean: Mean of input.\n inv_std: Inverse standard deviation of input.\n weight: Weight multiplied by the standardized input.\n bias: Bias added to the result of the weight multiplication.\n\n Returns:\n Standardized input.\n \"\"\"\n return weight * inv_std * (input - mean) + bias\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "2e8a3dc0-e0ec-484c-ad3a-59cdc79b11ae", "file_name": "sgmv_shrink.py", "repo_name": "IBM/vllm", "file_path": "vllm/lora/ops/sgmv_shrink.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _sgmv_shrink_kernel(input_ptr, lora_ptr, out_ptr, N, K, b_seq_start_loc,\n seq_lens, lora_indices, scaling, xm_stride, xk_stride, l0_stride,\n lora_k_stride, lora_n_stride, cm_stride, cn_stride, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, EVEN_K: tl.\n constexpr, SPLIT_K: tl.constexpr):\n \"\"\"\n The sgmv's shrink triton kernel is based on GroupGEMM+SPLIT-K.\n The GEMM of Multi-LoRA can be considered as GroupGEMM. Additionally,\n introducing SPLIT-K can improve performance\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_sk = tl.program_id(axis=1)\n cur_batch = tl.program_id(axis=2)\n cta_n_num = tl.cdiv(N, BLOCK_N)\n pid_m = pid // cta_n_num\n pid_n = pid % cta_n_num\n M = tl.load(seq_lens + cur_batch)\n if pid_m * BLOCK_M > M:\n return\n lora_index = tl.load(lora_indices + cur_batch)\n if lora_index == -1:\n return\n cur_seq_start = tl.load(b_seq_start_loc + cur_batch)\n offset_m = tl.arange(0, BLOCK_M) + pid_m * BLOCK_M\n offset_n = tl.arange(0, BLOCK_N) + pid_n * BLOCK_N\n offset_k = pid_sk * BLOCK_K + tl.arange(0, BLOCK_K)\n ram = tl.max_contiguous(tl.multiple_of(offset_m % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(offset_n % N, BLOCK_N), BLOCK_N)\n a_ptr = input_ptr + cur_seq_start * xm_stride + ram[:, None\n ] * xm_stride + offset_k[None, :] * xk_stride\n b_ptr = lora_ptr + l0_stride * lora_index + rbn[None, :\n ] * lora_k_stride + offset_k[:, None] * lora_n_stride\n accumulator = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n if EVEN_K:\n tiled_a = tl.load(a_ptr)\n tiled_b = tl.load(b_ptr)\n else:\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n tiled_a = tl.load(a_ptr, mask=offset_k[None, :] < k_remaining,\n other=0.0)\n tiled_b = tl.load(b_ptr, mask=offset_k[:, None] < k_remaining,\n other=0.0)\n accumulator += tl.dot(tiled_a, tiled_b)\n a_ptr += BLOCK_K * SPLIT_K * xk_stride\n b_ptr += BLOCK_K * SPLIT_K * lora_n_stride\n offset_cm = cur_seq_start + tl.arange(0, BLOCK_M) + pid_m * BLOCK_M\n offset_cn = tl.arange(0, BLOCK_N) + pid_n * BLOCK_N\n c_ptr = out_ptr + offset_cm[:, None] * cm_stride + offset_cn[None, :\n ] * cn_stride\n c_mask = (offset_cm[:, None] < cur_seq_start + M) & (offset_cn[None, :] < N\n )\n accumulator *= scaling\n if SPLIT_K == 1:\n tl.store(c_ptr, accumulator, mask=c_mask)\n else:\n tl.atomic_add(c_ptr, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/lora/ops/sgmv_shrink.py" }, { "uuid": "b6a99fcb-ac7f-4a0f-ab1a-1f9af95e6c52", "file_name": "sparse_linear.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_linear.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.autotune(configs=autotune_configs, key=['col_dim',\n 'inner_sparse_dim', 'sparse_dim'])\n@triton.jit\ndef input_inner_sparse_matmul_kernel(lhs_ptr, rhs_ptr, out_ptr,\n expert_ends_ptr, row_dim: tl.constexpr, col_dim: tl.constexpr,\n inner_sparse_dim: tl.constexpr, sparse_dim: tl.constexpr,\n padded_sparse_dim: tl.constexpr, lhs_stride_row: tl.constexpr,\n lhs_stride_inner: tl.constexpr, rhs_stride_inner: tl.constexpr,\n rhs_stride_col: tl.constexpr, out_stride_row: tl.constexpr,\n out_stride_col: tl.constexpr, accumulate: tl.constexpr, block_size_row:\n tl.constexpr, block_size_col: tl.constexpr, block_size_inner: tl.\n constexpr, group_size_row: tl.constexpr):\n tl.static_assert(row_dim % block_size_row == 0)\n tl.static_assert(col_dim % block_size_col == 0)\n tl.static_assert(inner_sparse_dim % block_size_inner == 0)\n pid_row, pid_col = tl.swizzle2d(tl.program_id(axis=0), tl.program_id(\n axis=1), row_dim // block_size_row, col_dim // block_size_col,\n group_size_row)\n row_offset = pid_row * block_size_row\n sparse_range = tl.arange(0, padded_sparse_dim)\n expert_ends = tl.load(expert_ends_ptr + sparse_range, mask=sparse_range <\n sparse_dim, other=row_dim)\n sparse_index = tl.sum((expert_ends <= row_offset).to(tl.int64))\n if sparse_index == sparse_dim:\n return\n inner_dense_offset = sparse_index * inner_sparse_dim\n col_offset = pid_col * block_size_col\n row_range = tl.arange(0, block_size_row)[:, None]\n col_range = tl.arange(0, block_size_col)[None, :]\n inner_range = tl.arange(0, block_size_inner)\n lhs_ptr += (row_offset + row_range) * lhs_stride_row + inner_range[None, :\n ] * lhs_stride_inner\n rhs_ptr += (inner_dense_offset + inner_range[:, None]\n ) * rhs_stride_inner + (col_offset + col_range) * rhs_stride_col\n out_ptr += (row_offset + row_range) * out_stride_row + (col_offset +\n col_range) * out_stride_col\n out = tl.dot(tl.load(lhs_ptr), tl.load(rhs_ptr), out_dtype=tl.float32)\n for k in range(1, inner_sparse_dim // block_size_inner):\n lhs_ptr += block_size_inner * lhs_stride_inner\n rhs_ptr += block_size_inner * rhs_stride_inner\n out += tl.dot(tl.load(lhs_ptr), tl.load(rhs_ptr))\n if accumulate:\n out += tl.load(out_ptr)\n tl.store(out_ptr, out)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced", "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_linear.py" }, { "uuid": "7118da2e-e1df-45f5-99f0-a46403452599", "file_name": "gemm2.py", "repo_name": "vedantroy/awq", "file_path": "examples/gemm2.py", "commit_hash": "a0e638f269862a78da4ea6a7f4c08bc54486018e", "starcount": 0, "input": "@triton.jit\ndef matmul_kernel_simple(a_ptr, qw_ptr, c_ptr, scales_ptr, zeros_ptr,\n dbg_qwpacked_ptr, dbg_qwunpacked_ptr, dbg_dequant_ptr, dbg_scales_ptr,\n dbg_unpacked_zeros_ptr, dbg_to_add_ptr, M, N, K, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE_M: tl.constexpr, QUANT_GROUP_SIZE: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x qw (qweights). \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n qw_shifter = offs_k % 8 * 4\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, 1):\n a_offs = k * BLOCK_SIZE_K + (offs_am[:, None] * K + offs_k[None, :])\n a = tl.load(a_ptr + a_offs, mask=offs_k[None, :] < K - k *\n BLOCK_SIZE_K, other=0.0)\n qw_offs = (k * BLOCK_SIZE_K + offs_k[:, None]) // 8 * N + offs_bn[\n None, :]\n qw_packed = tl.load(qw_ptr + qw_offs)\n if pid == 0 and k == 0:\n k_x_n = tl.arange(0, BLOCK_SIZE_K)[:, None\n ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]\n tl.store(dbg_qwpacked_ptr + k_x_n, qw_packed)\n qw_unpacked = qw_packed >> qw_shifter[:, None] & 15\n if pid == 0 and k == 0:\n k_x_n = tl.arange(0, BLOCK_SIZE_K)[:, None\n ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]\n tl.store(dbg_qwunpacked_ptr + k_x_n, qw_unpacked)\n k_iters_per_quant_group = QUANT_GROUP_SIZE // BLOCK_SIZE_K\n grp_idx = k // k_iters_per_quant_group\n grp_row_off = N * grp_idx\n col_offs = offs_bn\n scales = tl.load(scales_ptr + grp_row_off + col_offs)\n if pid == 0 and k == 0:\n tl.store(dbg_scales_ptr + tl.arange(0, BLOCK_SIZE_N), scales)\n zeros_row_off = grp_row_off // 8\n idx_within_packed = grp_idx % 8\n packed_zeros = tl.load(zeros_ptr + zeros_row_off + col_offs)\n unpacked_zeros = packed_zeros >> idx_within_packed * 4 & 15\n if pid == 0 and k == 0:\n tl.store(dbg_unpacked_zeros_ptr + tl.arange(0, BLOCK_SIZE_N),\n unpacked_zeros)\n dequantized = scales[None, :].to(tl.float32) * (qw_unpacked.to(tl.\n float32) - unpacked_zeros[None, :].to(tl.float32))\n if pid == 0 and k == 0:\n k_x_n = tl.arange(0, BLOCK_SIZE_K)[:, None\n ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]\n tl.store(dbg_dequant_ptr + k_x_n, dequantized)\n to_add = tl.dot(a, dequantized.to(tl.float16))\n if pid == 0 and k == 0:\n m_x_n = tl.arange(0, BLOCK_SIZE_M)[:, None\n ] * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)[None, :]\n tl.store(dbg_to_add_ptr + m_x_n, to_add)\n accumulator += to_add\n c = accumulator.to(tl.float16)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n stride_cm = N\n c_ptrs = c_ptr + stride_cm * offs_cm[:, None] + offs_cn[None, :]\n c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/vedantroy/awq/blob/a0e638f269862a78da4ea6a7f4c08bc54486018e/examples/gemm2.py" }, { "uuid": "cce543b6-f8b2-4791-8e56-9a8d72b6369f", "file_name": "dequant_kernel.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/quant/dequant_kernel.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef dequant_nf4_tensor_kernel(inpt_ptr, output_ptr, quantized_scalers_ptr,\n quantization_factor_ptr, scaler_mean_ptr, nf4_lut_ptr,\n scaler_block_size: tl.constexpr, XBLOCK: tl.constexpr):\n \"\"\"Dequantizes a tensor from nf4 to bfloat16\"\"\"\n offset = tl.program_id(0) * XBLOCK\n index = offset + tl.arange(0, XBLOCK)[:]\n index = tl.max_contiguous(tl.multiple_of(index, XBLOCK), XBLOCK)\n inpt = tl.load(inpt_ptr + index)\n first_elements = inpt >> 4\n second_elements = inpt & 15\n dequantized_first = dequantize(first_elements, nf4_lut_ptr)\n dequantized_second = dequantize(second_elements, nf4_lut_ptr)\n block_scaler = dequantize_scalers(quantized_scalers_ptr,\n quantization_factor_ptr, scaler_mean_ptr, XBLOCK, scaler_block_size)\n scaled_first = dequantized_first * block_scaler\n scaled_second = dequantized_second * block_scaler\n store_indices = offset * 2 + tl.arange(0, XBLOCK * 2)[:]\n interleaved = tl.interleave(scaled_first, scaled_second)\n tl.store(output_ptr + store_indices, interleaved)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8", "bf16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/quant/dequant_kernel.py" }, { "uuid": "75190c07-be32-4efd-b8f2-d8a6bee1648a", "file_name": "quantize.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/quantize.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _kernel_quantize_mx4(A, out, rand_bits, M, K, GROUPS_PER_ROW,\n GROUPS_PER_THREAD, ROW_PADDING, GROUP_SIZE: tl.constexpr, EBITS: tl.\n constexpr, MBITS: tl.constexpr, ROUNDING_MODE: tl.constexpr,\n STOCHASTIC_CASTING: tl.constexpr, FP4_EXP_BIAS: tl.constexpr,\n GROUP_LOAD: tl.constexpr, USE_INT64: tl.constexpr) ->None:\n \"\"\"Quantize a 1D float tensor into a packed MX4 tensor.\n\n Args:\n A (Tensor): [M] float tensor to be quantized.\n out (Tensor): [M / 2 + M / GROUP_SIZE] output containing packed mx4 values.\n rand_bits (Optional Tensor): [M, K / 2] random integers used for stochastic rounding.\n M (int): Number of input rows.\n K (int): Number of input columns.\n GROUPS_PER_ROW (int): Number of groups in each row of the input.\n GROUPS_PER_THREAD (int): Number of groups to process per thread.\n ROW_PADDING (int): Number of elements of padding to insert into each row.\n GROUP_SIZE (int): Size of chunks that use the same shared exponent.\n EBITS (int): Number of exponent bits in target mx4 format.\n MBITS (int): Number of mantissa bits in target mx4 format.\n ROUNDING_MODE (int): Which rounding method to use when calculating shared exponent.\n STOCHASTIC_CASTING (bool): Whether to use stochastic rounding when downcasting.\n FP4_EXP_BIAS (int): Exponent bias of target mx4 format.\n GROUP_LOAD (int): Number of groups to process simultaneously.\n USE_INT64 (bool): Whether to use int64 for indexing. This is needed for large tensors.\n \"\"\"\n FP32_EXP_MASK: tl.constexpr = 2139095040\n FP32_EXP_OFFSET: tl.constexpr = 23\n FP32_EXP_BIAS: tl.constexpr = 127\n FP32_SIGN_OFFSET: tl.constexpr = 31\n SIGN_MASK: tl.constexpr = 1\n FP32_MANTISSA_MASK: tl.constexpr = 8388607\n MBITS_IMPLICIT: tl.constexpr = MBITS + 1\n MAX_FP32_MANTISSA_BITS: tl.constexpr = 24\n IMPLIED_1_BIT: tl.constexpr = 1 << 23\n FP32_MIN_NORMAL: tl.constexpr = 2 ** -126\n MANTISSA_OVERFLOW_THRESHOLD: tl.constexpr = (1 << MBITS_IMPLICIT) - 1\n EXPONENT_OVERFLOW_THRESHOLD: tl.constexpr = (1 << EBITS) - 1\n IMPLICIT_1_MASK = (1 << MBITS_IMPLICIT - 1) - 1\n RAND_MASK: tl.constexpr = (1 << FP32_EXP_OFFSET - MBITS) - 1\n pid = tl.program_id(0)\n if USE_INT64:\n pid = pid.to(tl.int64)\n M = tl.cast(M, tl.int64)\n K = tl.cast(K, tl.int64)\n GROUPS_PER_THREAD = tl.cast(GROUPS_PER_THREAD, tl.int64)\n PACKED_GROUP_SIZE: tl.constexpr = GROUP_SIZE // 2 + 1\n NUM_GROUPS = M * GROUPS_PER_ROW\n OUTPUT_CHUNK_SIZE = GROUPS_PER_THREAD * GROUP_SIZE // 2 + GROUPS_PER_THREAD\n OUTPUT_SIZE = GROUP_SIZE * NUM_GROUPS // 2 + NUM_GROUPS\n input_start = pid * (GROUPS_PER_THREAD * GROUP_SIZE)\n output_start = pid * OUTPUT_CHUNK_SIZE\n exp_start = output_start + GROUP_SIZE // 2\n input_offset = tl.arange(0, GROUP_LOAD * GROUP_SIZE) + input_start\n output_offset = tl.arange(0, GROUP_LOAD * (GROUP_SIZE // 2))\n if ROUNDING_MODE == 3:\n rand_bits_offset = tl.arange(0, GROUP_LOAD) + pid * GROUPS_PER_THREAD\n else:\n rand_bits_offset = pid * GROUPS_PER_THREAD\n output_offset += output_offset // (GROUP_SIZE // 2) + output_start\n exp_offset = tl.arange(0, GROUP_LOAD) * PACKED_GROUP_SIZE + exp_start\n for _k in range(0, tl.cdiv(GROUPS_PER_THREAD, GROUP_LOAD)):\n pad_mask = input_offset % (GROUPS_PER_ROW * GROUP_SIZE) < K\n if ROW_PADDING != 0:\n padded_input_offset = input_offset - input_offset // (\n GROUPS_PER_ROW * GROUP_SIZE) * ROW_PADDING\n else:\n padded_input_offset = input_offset\n a = tl.load(A + padded_input_offset, mask=(padded_input_offset < M *\n K) & (padded_input_offset < (pid + 1) * GROUPS_PER_THREAD *\n GROUP_SIZE) & pad_mask, other=0)\n a_groups = tl.reshape(a, [GROUP_LOAD, GROUP_SIZE])\n group_max = tl.max(tl.abs(a_groups), axis=1)\n group_max = tl.where(group_max == 0, FP32_MIN_NORMAL, group_max)\n group_rand_bits = None\n if ROUNDING_MODE == 3 or STOCHASTIC_CASTING:\n group_rand_bits = tl.load(rand_bits + rand_bits_offset, mask=\n rand_bits_offset < K // GROUP_SIZE, other=0)\n rand_bits_offset += GROUP_LOAD\n group_exp = _compute_exp(group_max, ROUNDING_MODE, group_rand_bits,\n MBITS)\n group_exp = group_exp - EBITS\n group_exp = tl.clamp(group_exp, -127, 125)\n scale = tl.exp2(group_exp.to(tl.float64)).to(tl.float32)\n scaled_a = tl.reshape(a, [GROUP_LOAD, GROUP_SIZE]) / tl.reshape(scale,\n [GROUP_LOAD, 1])\n scaled_a = tl.reshape(scaled_a, [GROUP_LOAD * GROUP_SIZE])\n tl.store(out + exp_offset, (group_exp + FP32_EXP_BIAS).to(tl.int8),\n mask=(exp_offset < OUTPUT_SIZE) & (exp_offset < \n OUTPUT_CHUNK_SIZE * (pid + 1)))\n scaled_a = scaled_a.to(tl.int32, bitcast=True)\n if STOCHASTIC_CASTING:\n philox_4x_offset = tl.split(tl.reshape(input_offset, [\n GROUP_LOAD * GROUP_SIZE // 2, 2], can_reorder=True))\n philox_4x_offset = tl.split(tl.reshape(philox_4x_offset, [\n GROUP_LOAD * GROUP_SIZE // 4, 2], can_reorder=True))\n a_4x, b_4x, c_4x, d_4x = tl.randint4x(group_rand_bits,\n philox_4x_offset, n_rounds=7)\n stochastic_round_bits = tl.join(tl.join(a_4x, b_4x), tl.join(\n c_4x, d_4x))\n stochastic_round_bits = tl.reshape(stochastic_round_bits, [\n GROUP_LOAD * GROUP_SIZE]).to(tl.int32, bitcast=True)\n scaled_a = scaled_a + (stochastic_round_bits & RAND_MASK)\n sign_bit = scaled_a >> FP32_SIGN_OFFSET & SIGN_MASK\n biased_exp = (scaled_a & FP32_EXP_MASK) >> FP32_EXP_OFFSET\n trailing_mantissa = scaled_a & FP32_MANTISSA_MASK\n new_biased_exp = biased_exp - FP32_EXP_BIAS + FP4_EXP_BIAS\n exp_diff = tl.where(new_biased_exp <= 0, 1 - new_biased_exp, 0)\n exp_diff = tl.minimum(exp_diff, MAX_FP32_MANTISSA_BITS)\n is_subnorm = biased_exp == 0\n mantissa = tl.where(is_subnorm, trailing_mantissa, \n trailing_mantissa + IMPLIED_1_BIT)\n fp32_sig_bits = tl.where(is_subnorm, 23, 24).to(tl.int32)\n mantissa = mantissa >> fp32_sig_bits + exp_diff - MBITS_IMPLICIT - 1\n mantissa = mantissa + 1 >> 1\n overflow = mantissa > MANTISSA_OVERFLOW_THRESHOLD\n mantissa = tl.where(overflow and not is_subnorm, mantissa >> 1,\n mantissa)\n new_biased_exp = tl.where(new_biased_exp <= 0 and mantissa == 2, 1,\n new_biased_exp)\n mantissa = mantissa & IMPLICIT_1_MASK\n new_biased_exp = tl.where(overflow, new_biased_exp + 1, new_biased_exp)\n mantissa = tl.where(new_biased_exp > EXPONENT_OVERFLOW_THRESHOLD, 1,\n mantissa)\n new_biased_exp = tl.maximum(tl.minimum(new_biased_exp,\n EXPONENT_OVERFLOW_THRESHOLD), 0)\n mx4_value = new_biased_exp << MBITS_IMPLICIT - 1 | mantissa\n mx4_value = sign_bit << EBITS + MBITS | mx4_value\n low_mx4, high_mx4 = tl.split(tl.reshape(mx4_value, [GROUP_LOAD *\n GROUP_SIZE // 2, 2]))\n packed_mx4 = (high_mx4 << 4 | low_mx4).to(tl.int8)\n tl.store(out + output_offset, packed_mx4, mask=(output_offset <\n OUTPUT_SIZE) & (output_offset < OUTPUT_CHUNK_SIZE * (pid + 1)))\n input_offset += GROUP_LOAD * GROUP_SIZE\n exp_offset += GROUP_LOAD * PACKED_GROUP_SIZE\n output_offset += GROUP_LOAD * PACKED_GROUP_SIZE\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/quantize.py" }, { "uuid": "e433ab40-e94b-424b-8781-6a02f5a372a2", "file_name": "dx.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/dropconnect/dx.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.jit\ndef dropconnect_dx_kernel(dy_ptr, w_ptr, dx_ptr, seed, M, K, N, stride_dym,\n stride_dyn, stride_wk, stride_wn, stride_dm, stride_dk, stride_dn,\n stride_xm, stride_xk, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr, ALLOWTF32: tl.constexpr):\n \"\"\" \n dY_m = Y.grad\n dO_m = dY_m.view(M,1,N).broadcast_to(M,K,N)\n dx_m_cast = dO_m * WD_m\n dx_m = dx_m_cast.sum(dim=2) \"\"\"\n pid_m = tl.program_id(0)\n pid_k = tl.program_id(1)\n offset_m = pid_m * BLOCK_SIZE_M\n offset_n = 0\n offset_k = pid_k * BLOCK_SIZE_K\n dy_offsets = block_offsets_2d(M, N, stride_dym, stride_dyn, offset_m,\n offset_n, BLOCK_SIZE_M, BLOCK_SIZE_N)\n w_offsets = block_offsets_2d(K, N, stride_wk, stride_wn, offset_k,\n offset_n, BLOCK_SIZE_K, BLOCK_SIZE_N)\n d_offsets = block_offsets_3d(M, K, N, stride_dm, stride_dk, stride_dn,\n offset_m, offset_k, offset_n, BLOCK_SIZE_M, BLOCK_SIZE_K, BLOCK_SIZE_N)\n dy_offsets = dy_offsets.reshape(BLOCK_SIZE_M, 1, BLOCK_SIZE_N)\n w_offsets = w_offsets.reshape(1, BLOCK_SIZE_K, BLOCK_SIZE_N)\n offs_n = tl.arange(0, BLOCK_SIZE_N)\n dy_tile = dy_ptr + dy_offsets\n w_tile = w_ptr + w_offsets\n ASM: tl.constexpr = 'cvt.rna.tf32.f32 $0, $1;'\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_K), dtype=tl.float32)\n for n in range(0, tl.cdiv(N, BLOCK_SIZE_N)):\n random_masks = tl.random.rand(seed, d_offsets) > 0.5\n n_mask = offs_n[None, None, :] < N - n * BLOCK_SIZE_N\n dy_load = tl.load(dy_tile, mask=n_mask, other=0.0)\n w_load = tl.load(w_tile, mask=n_mask, other=0.0)\n dy = tl.where(random_masks, dy_load, 0.0)\n wd = tl.where(random_masks, w_load, 0.0)\n mul = dy * wd\n accumulator += tl.sum(mul, axis=2)\n dy_tile += BLOCK_SIZE_N * stride_dyn\n w_tile += BLOCK_SIZE_N * stride_wn\n d_offsets += BLOCK_SIZE_N * stride_dn\n dx_offset, dx_mask = block_offsets_2d(M, K, stride_xm, stride_xk,\n offset_m, offset_k, BLOCK_SIZE_M, BLOCK_SIZE_K, True)\n dx_tile = dx_ptr + dx_offset\n dx = accumulator.to(dx_tile.dtype.element_ty)\n tl.store(dx_tile, dx, mask=dx_mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/dropconnect/dx.py" }, { "uuid": "65eed763-e3c9-4f09-8b89-130070dd79d3", "file_name": "sized_tuned_bwd.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/sized_tuned_bwd.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=TRITON_CONFIG_LIST_BWD_SIZED, key=['BLOCK_DMODEL',\n 'max_seqlen_q', 'max_seqlen_k'])\n@triton.jit\ndef sized_tuned_bwd_kernel_dq(Q, K, V, B, sm_scale, Out, DO, DQ, DB, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dqz, stride_dqh, stride_dqm, stride_dqk,\n stride_dbz, stride_dbh, stride_dbm, stride_dbn, cu_seqlens_q,\n cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k, head_dim,\n dropout_p, philox_seed, philox_offset_base, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.\n constexpr):\n bare_bwd_kernel_dq(Q, K, V, B, sm_scale, Out, DO, DQ, DB, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dqz, stride_dqh, stride_dqm,\n stride_dqk, stride_dbz, stride_dbh, stride_dbm, stride_dbn,\n cu_seqlens_q, cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k,\n head_dim, dropout_p, philox_seed, philox_offset_base, BLOCK_M,\n BLOCK_DMODEL, BLOCK_N, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD=\n PADDED_HEAD, BIAS_TYPE=BIAS_TYPE)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/sized_tuned_bwd.py" }, { "uuid": "29eb6850-1766-413b-8e3d-01a3060c34f7", "file_name": "chunk_h.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'\n ] is not None, 'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [1, 2, 4, 8] for num_stages in [2, 3, 4]], key=['BT',\n 'USE_G', 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_bwd_kernel_dh(q, g, gk, gv, do, dh, dht, dh0, offsets,\n chunk_offsets, scale, T: tl.constexpr, HQ: tl.constexpr, H: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, NG: tl.constexpr, USE_G: tl.constexpr,\n USE_GK: tl.constexpr, USE_GV: tl.constexpr,\n STORE_INITIAL_STATE_GRADIENT: tl.constexpr, USE_FINAL_STATE_GRADIENT:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_nh // NG\n i_n, i_hq = i_nh // HQ, i_nh % HQ\n i_h = i_hq // NG\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT - 1, -1, -1):\n if HEAD_FIRST:\n p_dh = tl.make_block_ptr(dh + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_dh = tl.make_block_ptr(dh + ((boh + i_t) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_nh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * HQ + i_hq) * K, (K, T), (1, \n HQ * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n if USE_G:\n if HEAD_FIRST:\n p_g = g + i_bg * T + i_t * BT + tl.arange(0, BT)\n p_g = tl.max_contiguous(tl.multiple_of(p_g, BT), BT)\n b_g_last = tl.load(g + i_bg * T + last_idx)\n else:\n p_g = g + (bos + i_t * BT + tl.arange(0, BT)) * H + i_h\n b_g_last = tl.load(g + (bos + last_idx) * H + i_h)\n b_g = tl.load(p_g, mask=i_t * BT + tl.arange(0, BT) < T, other=0.0)\n b_q = (b_q * tl.exp(b_g)[None, :]).to(b_q.dtype)\n b_dh *= tl.exp(b_g_last)\n if USE_GK:\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(gk + i_bg * T * K, (K, T), (1, K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (i_bg * T + last_idx\n ) * K + i_k * BK + tl.arange(0, BK)\n else:\n p_gk = tl.make_block_ptr(gk + (bos * H + i_h) * K, (K, T),\n (1, H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_q = (b_q * tl.exp(b_gk)).to(b_q.dtype)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) <\n K, other=0.0)\n b_dh *= tl.exp(b_gk_last)[:, None]\n if USE_GV:\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(gv + i_bg * T * V, (T, V), (V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (i_bg * T + last_idx\n ) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_gv = tl.make_block_ptr(gv + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_gv)).to(b_do.dtype)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) <\n V, other=0.0)\n b_dh *= tl.exp(b_gv_last)[None, :]\n b_dh += tl.dot(b_q, b_do)\n if STORE_INITIAL_STATE_GRADIENT:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h.py" }, { "uuid": "1e1944d8-6b04-41df-b0ee-4bdf17a83a50", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv4/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_rwkv4_backward_kernel(w_ptr, w_s_c, u_ptr, u_s_c, k_ptr,\n k_s_b, k_s_t, k_s_c, v_ptr, v_s_b, v_s_t, v_s_c, state_ptr, state_s_b,\n state_s_abe, state_s_t, state_s_c, gwkv_ptr, gwkv_s_b, gwkv_s_t,\n gwkv_s_c, gstate_out_ptr, gstate_out_s_b, gstate_out_s_abe,\n gstate_out_s_c, gw_ptr, gw_s_c, gu_ptr, gu_s_c, gk_ptr, gk_s_b, gk_s_t,\n gk_s_c, gv_ptr, gv_s_b, gv_s_t, gv_s_c, gstate_ptr, gstate_s_b,\n gstate_s_abe, gstate_s_c, tsz, chans, BLOCK_SIZE_C: tl.constexpr):\n b_idx = tl.program_id(0)\n c_idx = tl.program_id(1)\n cs = c_idx * BLOCK_SIZE_C + tl.arange(0, BLOCK_SIZE_C)\n cmask = cs < chans\n k_ptr = k_ptr + b_idx * k_s_b\n v_ptr = v_ptr + b_idx * v_s_b\n alpha_ptr = state_ptr + b_idx * state_s_b\n beta_ptr = state_ptr + b_idx * state_s_b + state_s_abe\n eps_ptr = state_ptr + b_idx * state_s_b + 2 * state_s_abe\n gk_ptr = gk_ptr + b_idx * gk_s_b\n gv_ptr = gv_ptr + b_idx * gv_s_b\n gwkv_ptr = gwkv_ptr + b_idx * gwkv_s_b\n galpha_out_ptr = gstate_out_ptr + b_idx * gstate_out_s_b\n gbeta_out_ptr = gstate_out_ptr + b_idx * gstate_out_s_b + gstate_out_s_abe\n geps_out_ptr = (gstate_out_ptr + b_idx * gstate_out_s_b + 2 *\n gstate_out_s_abe)\n galpha = tl.load(galpha_out_ptr + gstate_out_s_c * cs, mask=cmask).to(tl\n .float32)\n gbeta = tl.load(gbeta_out_ptr + gstate_out_s_c * cs, mask=cmask).to(tl.\n float32)\n geps = tl.load(geps_out_ptr + gstate_out_s_c * cs, mask=cmask).to(tl.\n float32)\n w = tl.load(w_ptr + w_s_c * cs, mask=cmask).to(tl.float32)\n u = tl.load(u_ptr + u_s_c * cs, mask=cmask).to(tl.float32)\n gw = tl.zeros_like(w)\n gu = tl.zeros_like(u)\n alpha_prev = tl.load(alpha_ptr + tsz * state_s_t + state_s_c * cs, mask\n =cmask).to(tl.float32)\n beta_prev = tl.load(beta_ptr + tsz * state_s_t + state_s_c * cs, mask=cmask\n ).to(tl.float32)\n eps_prev = tl.load(eps_ptr + tsz * state_s_t + state_s_c * cs, mask=cmask\n ).to(tl.float32)\n for t in range(tsz):\n tc = tsz - t - 1\n kt = tl.load(k_ptr + tc * k_s_t + k_s_c * cs, mask=cmask).to(tl.float32\n )\n vt = tl.load(v_ptr + tc * v_s_t + v_s_c * cs, mask=cmask).to(tl.float32\n )\n alpha_curr = alpha_prev\n beta_curr = beta_prev\n eps_curr = eps_prev\n alpha_prev = tl.load(alpha_ptr + tc * state_s_t + state_s_c * cs,\n mask=cmask).to(tl.float32)\n beta_prev = tl.load(beta_ptr + tc * state_s_t + state_s_c * cs,\n mask=cmask).to(tl.float32)\n eps_prev = tl.load(eps_ptr + tc * state_s_t + state_s_c * cs, mask=\n cmask).to(tl.float32)\n ukt = u + kt\n tau = tl.maximum(ukt, eps_prev)\n e1 = tl.exp(eps_prev - tau)\n e2 = tl.exp(ukt - tau)\n euke = tl.exp(ukt + eps_prev - 2 * tau)\n denom = e1 * beta_prev + e2\n denom_sq = denom * denom\n gwkvt = tl.load(gwkv_ptr + tc * gwkv_s_t + gwkv_s_c * cs, mask=cmask\n ).to(tl.float32)\n guk = gwkvt * e2 * (e1 * beta_prev * vt - e1 * alpha_prev) / denom_sq\n gu += guk\n gk = guk\n gv = gwkvt * e2 / denom\n galpha_wkv = gwkvt * e1 / denom\n gbeta_wkv = -gwkvt * e1 * (e2 * vt + e1 * alpha_prev) / denom_sq\n geps_wkv_denom = e1 * beta_prev + e2\n geps_wkv = gwkvt * euke * (alpha_prev - vt * beta_prev) / (\n geps_wkv_denom * geps_wkv_denom)\n e1 = tl.exp(w + eps_prev - eps_curr)\n e2 = tl.exp(kt - eps_curr)\n galpha_we = galpha * e1 * alpha_prev\n gw += galpha_we\n gk += galpha * e2 * vt\n gv += galpha * e2\n geps += galpha * -alpha_curr\n gbeta_we = gbeta * e1 * beta_prev\n gw += gbeta_we\n gk += gbeta * e2\n geps += gbeta * -beta_curr\n geps_mask = w + eps_prev > kt\n geps_we = tl.where(geps_mask, geps, tl.zeros_like(geps))\n gw += geps_we\n gk += tl.where(geps_mask, tl.zeros_like(geps), geps)\n tl.store(gk_ptr + tc * gk_s_t + gk_s_c * cs, gk, mask=cmask)\n tl.store(gv_ptr + tc * gv_s_t + gv_s_c * cs, gv, mask=cmask)\n galpha = galpha * e1 + galpha_wkv\n gbeta = gbeta * e1 + gbeta_wkv\n geps = galpha_we + gbeta_we + geps_we + geps_wkv\n galpha_ptr = gstate_ptr + b_idx * gstate_s_b\n gbeta_ptr = gstate_ptr + b_idx * gstate_s_b + gstate_s_abe\n geps_ptr = gstate_ptr + b_idx * gstate_s_b + 2 * gstate_s_abe\n tl.store(galpha_ptr + gstate_s_c * cs, galpha, mask=cmask)\n tl.store(gbeta_ptr + gstate_s_c * cs, gbeta, mask=cmask)\n tl.store(geps_ptr + gstate_s_c * cs, geps, mask=cmask)\n gw_temp = tl.load(gw_ptr + gw_s_c * cs, mask=cmask).to(tl.float32)\n gw_temp += gw\n tl.store(gw_ptr + gw_s_c * cs, gw_temp, mask=cmask)\n gu_temp = tl.load(gu_ptr + gu_s_c * cs, mask=cmask).to(tl.float32)\n gu_temp += gu\n tl.store(gu_ptr + gu_s_c * cs, gu_temp, mask=cmask)\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv4/fused_recurrent.py" }, { "uuid": "4a398122-1442-4248-8842-7e8a278b8424", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/hgrn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BD': 32}, num_warps=1), triton.\n Config({'BD': 32}, num_warps=2), triton.Config({'BD': 32}, num_warps=4),\n triton.Config({'BD': 32}, num_warps=8), triton.Config({'BD': 64},\n num_warps=1), triton.Config({'BD': 64}, num_warps=2), triton.Config({\n 'BD': 64}, num_warps=4), triton.Config({'BD': 64}, num_warps=8), triton\n .Config({'BD': 128}, num_warps=1), triton.Config({'BD': 128}, num_warps\n =2), triton.Config({'BD': 128}, num_warps=4), triton.Config({'BD': 128},\n num_warps=8)], key=['D'])\n@triton.jit\ndef chunk_hgrn_fwd_kernel_h(x, g, gc, o, h0, T: tl.constexpr, D: tl.\n constexpr, BT: tl.constexpr, BD: tl.constexpr, USE_INITIAL_STATE: tl.\n constexpr):\n i_d, i_t, i_b = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_d = i_d * BD + tl.arange(0, BD)\n mask = o_d < D\n p_x = x + i_b * T * D + i_t * BT * D + o_d\n p_g = g + i_b * T * D + i_t * BT * D + o_d\n p_gc = gc + i_b * T * D + i_t * BT * D + o_d\n p_o = o + i_b * T * D + i_t * BT * D + o_d\n b_h = tl.zeros([BD], dtype=tl.float32)\n b_gc = tl.zeros([BD], dtype=tl.float32)\n if USE_INITIAL_STATE:\n if i_t == 0:\n b_h += tl.load(h0 + i_b * D + o_d, mask=mask, other=0).to(tl.\n float32)\n for i in range(0, BT):\n mask_t = mask & (i_t * BT + i < T)\n b_x = tl.load(p_x, mask=mask_t, other=0).to(tl.float32)\n b_g = tl.load(p_g, mask=mask_t, other=0).to(tl.float32)\n b_h = tl.exp(b_g) * b_h + b_x\n b_gc = b_gc + b_g\n tl.store(p_gc, b_gc.to(p_o.dtype.element_ty), mask=mask_t)\n tl.store(p_o, b_h.to(p_o.dtype.element_ty), mask=mask_t)\n p_x += D\n p_g += D\n p_gc += D\n p_o += D\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/hgrn/chunk.py" }, { "uuid": "67bfb3db-8a20-4dc2-925e-39148ea3e6d9", "file_name": "rms_norm.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/rms_norm.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE': 128, 'NUM_WARPS': 4}\n ), triton.Config({'BLOCK_SIZE': 256, 'NUM_WARPS': 8}), triton.Config({\n 'BLOCK_SIZE': 512, 'NUM_WARPS': 16}), triton.Config({'BLOCK_SIZE': 1024,\n 'NUM_WARPS': 16}), triton.Config({'BLOCK_SIZE': 2048, 'NUM_WARPS': 32}),\n triton.Config({'BLOCK_SIZE': 4096, 'NUM_WARPS': 32}), triton.Config({\n 'BLOCK_SIZE': 8192, 'NUM_WARPS': 48})], key=['n_cols'])\n@triton.jit\ndef _rms_layernorm_backward(dY, dY_row_stride, X, X_row_stride, W,\n W_row_stride, r, r_row_stride, dX, dX_row_stride, dW, n_cols, eps,\n BLOCK_SIZE: tl.constexpr, NUM_WARPS: tl.constexpr):\n pid = tl.program_id(0)\n num_pids = tl.num_programs(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n dY_ptr = dY + pid * dY_row_stride + col_offsets\n X_ptr = X + pid * X_row_stride + col_offsets\n dX_ptr = dX + pid * dX_row_stride + col_offsets\n dY_row = tl.load(dY_ptr, mask=mask, other=0).to(tl.float32)\n X_row = tl.load(X_ptr, mask=mask, other=0).to(tl.float32)\n W_row = tl.load(W + col_offsets, mask=mask, other=0).to(tl.float32)\n rms = tl.load(r + pid).to(tl.float32)\n X_norm = X_row * rms\n dY_W = dY_row * W_row\n sum_dY_X = tl.sum(dY_W * X_norm, axis=0)\n dX = rms * (dY_W - X_norm * (sum_dY_X / n_cols))\n dW_row = dY_row * X_norm\n tl.atomic_add(dW + col_offsets, dW_row, mask=mask)\n tl.store(dX_ptr, dX, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/rms_norm.py" }, { "uuid": "7596edff-211e-475d-872d-74ad640ee13a", "file_name": "inout_tensor.py", "repo_name": "gmgu/study-triton", "file_path": "2_inout_tensor/inout_tensor.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@triton.jit\ndef copy_kernel(in_ptr, out_ptr, n: tl.constexpr):\n offsets = tl.arange(0, n)\n x = tl.load(in_ptr + offsets)\n y = tl.store(out_ptr + offsets, x)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/2_inout_tensor/inout_tensor.py" }, { "uuid": "9c7ea44a-b658-498e-bf16-7647e1ef2be1", "file_name": "cross_entropy.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/cross_entropy.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_cross_entropy_backward(input_grad_ptr, input_stride,\n grad_output_ptr, num_classes, BLOCK_SIZE: tl.constexpr):\n row_id = tl.program_id(0).to(tl.int64)\n input_grad_ptr += row_id * input_stride\n grad_output = tl.load(grad_output_ptr)\n for i in range(0, num_classes, BLOCK_SIZE):\n input_offsets = i + tl.arange(0, BLOCK_SIZE)\n input_grad_block = tl.load(input_grad_ptr + input_offsets, mask=\n input_offsets < num_classes)\n tl.store(input_grad_ptr + input_offsets, input_grad_block *\n grad_output, mask=input_offsets < num_classes)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/cross_entropy.py" }, { "uuid": "90672e0c-650f-4d76-8b2b-6f1033c4bc1c", "file_name": "y_9.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_9.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef ninth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor, block_size:\n tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.constexpr,\n col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST000 = 1.93163963757558\n CONST001 = 2.65478475211798\n CONST002 = 1.72771101506082\n CONST004 = 1.59908344719522\n CONST005 = 6.39633378878088\n CONST006 = 6.39633378878088\n CONST007 = 8.63855507530412\n CONST008 = 9.59450068317133\n CONST009 = 4.35889894354067\n CONST010 = 10.7269778688696\n CONST011 = 10.7269778688696\n CONST012 = 6.39633378878088\n CONST013 = 15.0007324039945\n CONST014 = 13.0937127087774\n CONST016 = 14.45506743704\n CONST017 = 14.45506743704\n CONST018 = 13.3827919767794\n CONST019 = 13.5214774630291\n CONST020 = 23.8930627690618\n CONST021 = 27.0429549260581\n CONST022 = 29.2403830344269\n CONST023 = 29.2403830344269\n CONST024 = 30.001464807989\n CONST025 = -480.023436927823\n CONST026 = -480.023436927823\n CONST029 = 42.9079114754785\n CONST030 = -462.562157985281\n CONST032 = -967.518168434061\n CONST034 = 57.8202697481601\n CONST035 = 58.9217071894985\n CONST036 = 58.9217071894985\n CONST037 = 62.4530292249704\n CONST038 = 1081.71819704233\n CONST039 = 64.3618672132178\n CONST040 = 578.202697481601\n CONST044 = 600.029296159779\n CONST045 = -936.795438374555\n CONST047 = 96.7518168434061\n CONST049 = 115.64053949632\n CONST051 = -392.811381263323\n CONST053 = 137.14955340795\n CONST055 = 150.007324039945\n CONST056 = -343.263291803828\n CONST058 = 11.2632978048796\n CONST061 = -315.37233853663\n CONST062 = -314.249105010659\n CONST063 = 205.957975082297\n CONST065 = -294.608535947493\n CONST066 = 240.011718463912\n CONST068 = 241.879542108515\n CONST069 = 255.853351551235\n CONST070 = 255.853351551235\n CONST071 = -241.879542108515\n CONST072 = -240.011718463912\n CONST073 = -241.879542108515\n CONST074 = 788.430846341574\n CONST075 = 1.72771101506082\n CONST076 = -1.93163963757558\n CONST077 = -1249.06058449941\n CONST078 = -223.00191917791\n CONST080 = -216.343639408465\n CONST081 = 300.01464807989\n CONST082 = -204.682681240988\n CONST083 = -204.682681240988\n CONST084 = -204.682681240988\n CONST086 = -196.405690631662\n CONST087 = -191.890013663426\n CONST088 = -191.890013663427\n CONST089 = -187.359087674911\n CONST090 = -693.843236977922\n CONST091 = 334.502878766866\n CONST092 = -176.765121568496\n CONST093 = -150.007324039945\n CONST094 = -144.5506743704\n CONST095 = 374.718175349822\n CONST096 = 374.718175349822\n CONST097 = -649.030918225395\n CONST099 = -630.744677073259\n CONST100 = -115.64053949632\n CONST101 = -114.421097267943\n CONST102 = -115.64053949632\n CONST103 = -104.74970167022\n CONST104 = 411.915950164594\n CONST105 = -95.5722510762473\n CONST106 = -90.106382439037\n CONST107 = -90.0043944239669\n CONST109 = -80.2967518606762\n CONST110 = -78.4601809837321\n CONST111 = 435.383175795327\n CONST112 = -589.217071894985\n CONST113 = -78.4601809837321\n CONST114 = 435.383175795328\n CONST115 = -68.5747767039748\n CONST116 = -63.9633378878088\n CONST117 = -63.9633378878088\n CONST118 = -62.4530292249704\n CONST119 = -58.9217071894985\n CONST120 = -1081.71819704233\n CONST121 = -57.8202697481601\n CONST122 = -57.8202697481601\n CONST123 = -58.9217071894985\n CONST124 = -54.0859098521163\n CONST125 = 462.562157985281\n CONST127 = -48.3759084217031\n CONST128 = -48.375908421703\n CONST129 = -38.6327927515116\n CONST130 = -30.9062342012093\n CONST131 = 483.759084217031\n CONST132 = -30.001464807989\n CONST133 = -30.001464807989\n CONST134 = -27.0429549260581\n CONST135 = -24.1879542108515\n CONST136 = -24.1879542108515\n CONST137 = -1.63671408859718\n CONST138 = -15.0007324039945\n CONST139 = -13.5214774630291\n CONST140 = -13.8216881204866\n CONST141 = -13.0937127087774\n CONST142 = -13.3827919767794\n CONST143 = -9.82028453158308\n CONST144 = -4.91014226579154\n CONST145 = 511.706703102471\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR01 = VAR07 * VAR07 * VAR07\n VAR02 = VAR06 * VAR06\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR10 = VAR16 * VAR16 * VAR16\n VAR11 = VAR15 * VAR15\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR19 = VAR25 * VAR25 * VAR25\n VAR20 = VAR24 * VAR24\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n Y00 = (CONST001 * VAR01 + CONST020 * VAR20 * x + CONST078 * VAR07 *\n VAR22 + CONST091 * VAR05 * VAR24 + CONST105 * VAR03 * VAR26)\n Y01 = y * (-CONST099 * VAR05 * VAR25 + CONST099 * VAR07 * VAR23 + \n CONST106 * VAR03 * z - CONST106 * VAR21 * x)\n Y02 = CONST000 * VAR01 + VAR03 * (CONST129 * VAR26 + CONST130 * VAR17\n ) + VAR05 * (CONST021 * VAR24 - CONST097 * VAR17 * VAR26) + VAR07 * (\n CONST120 * VAR17 * VAR24 - CONST124 * VAR22) + x * (-CONST080 *\n VAR17 * VAR22 + CONST139 * VAR20)\n Y03 = VAR16 * (CONST077 * VAR07 * VAR25 + CONST095 * VAR05 * z + \n CONST096 * VAR23 * x) + y * (-CONST089 * VAR05 * VAR25 - CONST089 *\n VAR07 * VAR23 + CONST109 * VAR03 * z + CONST109 * VAR21 * x)\n Y04 = (CONST002 * VAR01 + CONST007 * VAR20 * x + CONST135 * VAR05 *\n VAR24 + CONST140 * VAR03 * VAR26 + VAR15 * (CONST032 * VAR07 *\n VAR26 + CONST047 * VAR05 + CONST131 * VAR24 * x) + VAR17 * (-\n CONST071 * VAR07 * VAR24 + CONST071 * VAR22 * x + CONST111 * VAR05 *\n VAR26 + CONST127 * VAR03))\n Y05 = VAR14 * (CONST030 * VAR07 * z - CONST030 * VAR25 * x) + VAR16 * (\n CONST030 * VAR23 * x + CONST125 * VAR05 * z) + y * (CONST034 *\n VAR07 * VAR23 + CONST121 * VAR05 * VAR25 - CONST121 * VAR21 * x + \n CONST122 * VAR03 * z)\n Y06 = CONST119 * VAR03 * VAR17 - CONST137 * VAR01 + VAR05 * (CONST035 *\n VAR17 * VAR26 - CONST086 * VAR15 + CONST143 * VAR24) + VAR07 * (\n CONST051 * VAR15 * VAR26 - CONST065 * VAR17 * VAR24 + CONST103 *\n VAR13 + CONST141 * VAR22) + x * (-CONST062 * VAR13 * VAR26 - \n CONST092 * VAR17 * VAR22 + CONST112 * VAR15 * VAR24 + CONST144 * VAR20)\n Y07 = CONST132 * VAR03 * y * z + VAR05 * (CONST081 * VAR16 * z + \n CONST107 * VAR25 * y) + VAR07 * (CONST026 * VAR14 * z + CONST044 *\n VAR16 * VAR25 + CONST107 * VAR23 * y) + x * (CONST025 * VAR14 *\n VAR25 + CONST053 * VAR12 * z + CONST081 * VAR16 * VAR23 + CONST132 *\n VAR21 * y)\n Y08 = CONST004 * VAR01 + VAR03 * (CONST006 * VAR26 + CONST116 * VAR17\n ) + VAR05 * (CONST008 * VAR24 + CONST069 * VAR15 + CONST087 * VAR17 *\n VAR26) + VAR07 * (CONST005 * VAR22 + CONST083 * VAR13 + CONST087 *\n VAR17 * VAR24 + CONST145 * VAR15 * VAR26) + x * (CONST004 * VAR20 +\n CONST022 * VAR11 + CONST069 * VAR15 * VAR24 + CONST082 * VAR13 *\n VAR26 + CONST116 * VAR17 * VAR22)\n Y09 = CONST009 * VAR10 + VAR12 * (CONST110 * VAR26 + CONST113 * VAR08\n ) + VAR14 * (CONST063 * VAR06 + CONST063 * VAR24 + CONST104 * VAR08 *\n VAR26) + VAR16 * (CONST056 * VAR06 * VAR26 + CONST056 * VAR08 *\n VAR24 + CONST101 * VAR04 + CONST101 * VAR22) + y * (CONST010 *\n VAR20 + CONST011 * VAR02 + CONST029 * VAR04 * VAR26 + CONST029 *\n VAR08 * VAR22 + CONST039 * VAR06 * VAR24)\n Y10 = CONST004 * VAR19 + VAR21 * (CONST005 * VAR08 + CONST117 * VAR17\n ) + VAR23 * (CONST008 * VAR06 + CONST070 * VAR15 + CONST088 * VAR08 *\n VAR17) + VAR25 * (CONST012 * VAR04 + CONST082 * VAR13 + CONST087 *\n VAR06 * VAR17 + CONST145 * VAR08 * VAR15) + z * (CONST004 * VAR02 +\n CONST023 * VAR11 + CONST070 * VAR06 * VAR15 + CONST084 * VAR08 *\n VAR13 + CONST117 * VAR04 * VAR17)\n Y11 = VAR12 * (CONST115 * VAR08 - CONST115 * VAR26) + VAR14 * (CONST066 *\n VAR06 + CONST072 * VAR24) + VAR16 * (CONST055 * VAR08 * VAR24 + \n CONST093 * VAR04 + CONST093 * VAR06 * VAR26 - CONST093 * VAR22) + y * (\n CONST013 * VAR02 + CONST024 * VAR04 * VAR26 + CONST133 * VAR08 *\n VAR22 + CONST138 * VAR20)\n Y12 = CONST036 * VAR17 * VAR21 + CONST137 * VAR19 + VAR23 * (CONST086 *\n VAR15 + CONST123 * VAR08 * VAR17 - CONST143 * VAR06) + VAR25 * (\n CONST014 * VAR04 - CONST051 * VAR08 * VAR15 + CONST065 * VAR06 *\n VAR17 - CONST103 * VAR13) + z * (CONST062 * VAR08 * VAR13 + \n CONST092 * VAR04 * VAR17 - CONST112 * VAR06 * VAR15 - CONST144 * VAR02)\n Y13 = VAR14 * (CONST049 * VAR06 + CONST049 * VAR24 + CONST090 * VAR08 *\n VAR26) + VAR16 * (CONST040 * VAR06 * VAR26 + CONST040 * VAR08 *\n VAR24 + CONST100 * VAR22 + CONST102 * VAR04) + y * (CONST016 *\n VAR20 + CONST017 * VAR02 + CONST094 * VAR06 * VAR24 + CONST121 *\n VAR04 * VAR26 + CONST122 * VAR08 * VAR22)\n Y14 = (CONST007 * VAR02 * z + CONST075 * VAR19 + CONST136 * VAR06 *\n VAR23 + CONST140 * VAR08 * VAR21 + VAR15 * (CONST032 * VAR08 *\n VAR25 + CONST047 * VAR23 + CONST131 * VAR06 * z) + VAR17 * (\n CONST068 * VAR06 * VAR25 + CONST073 * VAR04 * z + CONST114 * VAR08 *\n VAR23 + CONST128 * VAR21))\n Y15 = VAR16 * (CONST037 * VAR22 - CONST045 * VAR06 * VAR26 + CONST045 *\n VAR08 * VAR24 + CONST118 * VAR04) + y * (CONST018 * VAR02 + \n CONST089 * VAR04 * VAR26 - CONST089 * VAR08 * VAR22 + CONST142 * VAR20)\n Y16 = (CONST019 * VAR02 * z + CONST076 * VAR19 + CONST124 * VAR04 *\n VAR25 - CONST129 * VAR08 * VAR21 + CONST134 * VAR06 * VAR23 + VAR17 *\n (CONST038 * VAR06 * VAR25 + CONST080 * VAR04 * z + CONST097 * VAR08 *\n VAR23 - CONST130 * VAR21))\n Y17 = y * (CONST058 * VAR02 + CONST058 * VAR20 + CONST061 * VAR04 *\n VAR26 + CONST061 * VAR08 * VAR22 + CONST074 * VAR06 * VAR24)\n Y18 = (CONST001 * VAR19 + CONST020 * VAR02 * z + CONST078 * VAR04 *\n VAR25 + CONST091 * VAR06 * VAR23 + CONST105 * VAR08 * VAR21)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n tl.store(output_ptr + output_row_offset + 9, Y09, mask=\n output_row_offset + 9 < output_numel)\n tl.store(output_ptr + output_row_offset + 10, Y10, mask=\n output_row_offset + 10 < output_numel)\n tl.store(output_ptr + output_row_offset + 11, Y11, mask=\n output_row_offset + 11 < output_numel)\n tl.store(output_ptr + output_row_offset + 12, Y12, mask=\n output_row_offset + 12 < output_numel)\n tl.store(output_ptr + output_row_offset + 13, Y13, mask=\n output_row_offset + 13 < output_numel)\n tl.store(output_ptr + output_row_offset + 14, Y14, mask=\n output_row_offset + 14 < output_numel)\n tl.store(output_ptr + output_row_offset + 15, Y15, mask=\n output_row_offset + 15 < output_numel)\n tl.store(output_ptr + output_row_offset + 16, Y16, mask=\n output_row_offset + 16 < output_numel)\n tl.store(output_ptr + output_row_offset + 17, Y17, mask=\n output_row_offset + 17 < output_numel)\n tl.store(output_ptr + output_row_offset + 18, Y18, mask=\n output_row_offset + 18 < output_numel)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_9.py" }, { "uuid": "e243a29b-b114-4f2d-a187-afd303c61af0", "file_name": "special.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/special.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef joint_second_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_stride = 9\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = output_striding + block_size * output_stride * block_id\n CONST_00 = 3.87298334620742\n CONST_01 = 2.23606797749979\n CONST_02 = 4.47213595499958\n CONST_03 = tl.sqrt(3.0)\n g_Y10 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_Y11 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_Y12 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_Y20 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_Y21 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_Y22 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_Y23 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_Y24 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_x = (CONST_00 * g_Y20 * z + CONST_00 * g_Y21 * y - CONST_01 * g_Y22 *\n x - CONST_00 * g_Y24 * x + CONST_03 * g_Y10)\n g_y = (CONST_00 * g_Y21 * x + CONST_02 * g_Y22 * y + CONST_00 * g_Y23 *\n z + CONST_03 * g_Y11)\n g_z = (CONST_00 * g_Y20 * x - CONST_01 * g_Y22 * z + CONST_00 * g_Y23 *\n y + CONST_00 * g_Y24 * z + CONST_03 * g_Y12)\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/special.py" }, { "uuid": "12f42420-1a7f-46d4-adc4-5b7cb9b2a72f", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_fourth_order_fwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, sh_1_0_ptr: tl.tensor, sh_1_1_ptr: tl.tensor, sh_1_2_ptr: tl.\n tensor, sh_2_0_ptr: tl.tensor, sh_2_1_ptr: tl.tensor, sh_2_2_ptr: tl.\n tensor, sh_2_3_ptr: tl.tensor, sh_2_4_ptr: tl.tensor, sh_3_0_ptr: tl.\n tensor, sh_3_1_ptr: tl.tensor, sh_3_2_ptr: tl.tensor, sh_3_3_ptr: tl.\n tensor, sh_3_4_ptr: tl.tensor, sh_3_5_ptr: tl.tensor, sh_3_6_ptr: tl.\n tensor, sh_4_0_ptr: tl.tensor, sh_4_1_ptr: tl.tensor, sh_4_2_ptr: tl.\n tensor, sh_4_3_ptr: tl.tensor, sh_4_4_ptr: tl.tensor, sh_4_5_ptr: tl.\n tensor, sh_4_6_ptr: tl.tensor, sh_4_7_ptr: tl.tensor, sh_4_8_ptr: tl.\n tensor, BLOCK_SIZE: tl.constexpr, vector_length: tl.constexpr):\n sqrt_3 = 3 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n sh_1_0 = x * sqrt_3\n sh_1_1 = y * sqrt_3\n sh_1_2 = z * sqrt_3\n sqrt_15 = 15 ** 0.5\n sqrt_5 = 5 ** 0.5\n sq_x = x * x\n sq_y = y * y\n sq_z = z * z\n sh_2_0 = sqrt_15 * x * z\n sh_2_1 = sqrt_15 * x * y\n sh_2_2 = sqrt_5 * (sq_y - 0.5 * (sq_x + sq_z))\n sh_2_3 = sqrt_15 * y * z\n sh_2_4 = 0.5 * sqrt_15 * (sq_z - sq_x)\n sqrt_42 = 42 ** 0.5\n sqrt_168 = 168 ** 0.5\n sqrt_7 = 7 ** 0.5\n sh_3_0 = 1 / 6 * sqrt_42 * (sh_2_0 * z + sh_2_4 * x)\n sh_3_1 = sqrt_7 * sh_2_0 * y\n sh_3_2 = 1 / 8 * sqrt_168 * (4 * sq_y - (sq_x + sq_z)) * x\n sh_3_3 = 0.5 * sqrt_7 * y * (2 * sq_y - 3 * (sq_x + sq_z))\n sh_3_4 = 1 / 8 * sqrt_168 * z * (4 * sq_y - (sq_x + sq_z))\n sh_3_5 = sqrt_7 * (sh_2_4 * y)\n sh_3_6 = 1 / 6 * sqrt_42 * (sh_2_4 * z - sh_2_0 * x)\n sqrt_2 = 2 ** 0.5\n sqrt_210 = 210 ** 0.5\n sqrt_14 = 14 ** 0.5\n sqrt_21 = 21 ** 0.5\n sqrt_70 = 70 ** 0.5\n sqrt_105 = 105 ** 0.5\n sqrt_6 = 6 ** 0.5\n sh_4_0 = 3 / 4 * sqrt_2 * (sh_3_0 * z + sh_3_6 * x)\n sh_4_1 = (3 / 4 * sh_3_0 * y + 3 / 8 * sqrt_6 * sh_3_1 * z + 3 / 8 *\n sqrt_6 * sh_3_5 * x)\n sh_4_2 = (-3 / 56 * sqrt_14 * sh_3_0 * z + 3 / 14 * sqrt_21 * sh_3_1 *\n y + 3 / 56 * sqrt_210 * sh_3_2 * z + 3 / 56 * sqrt_210 * sh_3_4 * x +\n 3 / 56 * sqrt_14 * sh_3_6 * x)\n sh_4_3 = (-3 / 56 * sqrt_42 * sh_3_1 * z + 3 / 28 * sqrt_105 * sh_3_2 *\n y + 3 / 28 * sqrt_70 * sh_3_3 * x + 3 / 56 * sqrt_42 * sh_3_5 * x)\n sh_4_4 = (-3 / 28 * sqrt_42 * sh_3_2 * x + 3 / 7 * sqrt_7 * sh_3_3 * y -\n 3 / 28 * sqrt_42 * sh_3_4 * z)\n sh_4_5 = (-3 / 56 * sqrt_42 * sh_3_1 * x + 3 / 28 * sqrt_70 * sh_3_3 *\n z + 3 / 28 * sqrt_105 * sh_3_4 * y - 3 / 56 * sqrt_42 * sh_3_5 * z)\n sh_4_6 = (-3 / 56 * sqrt_14 * sh_3_0 * x - 3 / 56 * sqrt_210 * sh_3_2 *\n x + 3 / 56 * sqrt_210 * sh_3_4 * z + 3 / 14 * sqrt_21 * sh_3_5 * y -\n 3 / 56 * sqrt_14 * sh_3_6 * z)\n sh_4_7 = (-3 / 8 * sqrt_6 * sh_3_1 * x + 3 / 8 * sqrt_6 * sh_3_5 * z + \n 3 / 4 * sh_3_6 * y)\n sh_4_8 = 3 / 4 * sqrt_2 * (-sh_3_0 * x + sh_3_6 * z)\n sh_1_0_start = sh_1_0_ptr + offset\n sh_1_1_start = sh_1_1_ptr + offset\n sh_1_2_start = sh_1_2_ptr + offset\n sh_2_0_start = sh_2_0_ptr + offset\n sh_2_1_start = sh_2_1_ptr + offset\n sh_2_2_start = sh_2_2_ptr + offset\n sh_2_3_start = sh_2_3_ptr + offset\n sh_2_4_start = sh_2_4_ptr + offset\n sh_3_0_start = sh_3_0_ptr + offset\n sh_3_1_start = sh_3_1_ptr + offset\n sh_3_2_start = sh_3_2_ptr + offset\n sh_3_3_start = sh_3_3_ptr + offset\n sh_3_4_start = sh_3_4_ptr + offset\n sh_3_5_start = sh_3_5_ptr + offset\n sh_3_6_start = sh_3_6_ptr + offset\n sh_4_0_start = sh_4_0_ptr + offset\n sh_4_1_start = sh_4_1_ptr + offset\n sh_4_2_start = sh_4_2_ptr + offset\n sh_4_3_start = sh_4_3_ptr + offset\n sh_4_4_start = sh_4_4_ptr + offset\n sh_4_5_start = sh_4_5_ptr + offset\n sh_4_6_start = sh_4_6_ptr + offset\n sh_4_7_start = sh_4_7_ptr + offset\n sh_4_8_start = sh_4_8_ptr + offset\n tl.store(sh_1_0_start, sh_1_0, mask=offset < vector_length)\n tl.store(sh_1_1_start, sh_1_1, mask=offset < vector_length)\n tl.store(sh_1_2_start, sh_1_2, mask=offset < vector_length)\n tl.store(sh_2_0_start, sh_2_0, mask=offset < vector_length)\n tl.store(sh_2_1_start, sh_2_1, mask=offset < vector_length)\n tl.store(sh_2_2_start, sh_2_2, mask=offset < vector_length)\n tl.store(sh_2_3_start, sh_2_3, mask=offset < vector_length)\n tl.store(sh_2_4_start, sh_2_4, mask=offset < vector_length)\n tl.store(sh_3_0_start, sh_3_0, mask=offset < vector_length)\n tl.store(sh_3_1_start, sh_3_1, mask=offset < vector_length)\n tl.store(sh_3_2_start, sh_3_2, mask=offset < vector_length)\n tl.store(sh_3_3_start, sh_3_3, mask=offset < vector_length)\n tl.store(sh_3_4_start, sh_3_4, mask=offset < vector_length)\n tl.store(sh_3_5_start, sh_3_5, mask=offset < vector_length)\n tl.store(sh_3_6_start, sh_3_6, mask=offset < vector_length)\n tl.store(sh_4_0_start, sh_4_0, mask=offset < vector_length)\n tl.store(sh_4_1_start, sh_4_1, mask=offset < vector_length)\n tl.store(sh_4_2_start, sh_4_2, mask=offset < vector_length)\n tl.store(sh_4_3_start, sh_4_3, mask=offset < vector_length)\n tl.store(sh_4_4_start, sh_4_4, mask=offset < vector_length)\n tl.store(sh_4_5_start, sh_4_5, mask=offset < vector_length)\n tl.store(sh_4_6_start, sh_4_6, mask=offset < vector_length)\n tl.store(sh_4_7_start, sh_4_7, mask=offset < vector_length)\n tl.store(sh_4_8_start, sh_4_8, mask=offset < vector_length)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "2330b2e5-9c58-4b9b-8328-2f4b391bd8bf", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_softmax/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES_RAGGED, BLOCK_SIZES_M, NUM_WARPS,\n NUM_STAGES)], key=['M'])\n@triton.jit\ndef triton_jagged_softmax_kernel_variable_length_loop_buffer_then_sum(\n input_ptr_values, input_ptr_offsets, output_ptr, M, BLOCK_SIZE_RAGGED:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_b = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_b), tl.load(\n input_ptr_offsets + (pid_b + 1))\n buffer_max_all = tl.full((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), value=float\n ('-inf'), dtype=tl.float32)\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=float('-inf')\n )\n buffer_max_all = tl.maximum(buffer_max_all, input)\n buffer_max = tl.max(buffer_max_all, axis=0, keep_dims=True)\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=float('-inf')\n )\n buffer += tl.exp(input - buffer_max)\n buffer_exp_sum = tl.sum(buffer, axis=0)\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=float('-inf')\n )\n output = tl.fdiv(tl.exp(input - buffer_max), buffer_exp_sum)\n tl.store(output_ptr + idxs, output, mask=mask)\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_softmax/kernels.py" }, { "uuid": "a85dfd4f-2d51-4198-9b23-08c7173a6ea2", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BC', 'BK'])\n@triton.jit\ndef chunk_gla_fwd_A_kernel_intra_sub_intra_split(q, k, g, A, offsets,\n indices, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BK: tl.constexpr, NC:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_tc, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_t, i_i = i_tc // NC, i_tc % NC\n i_j = i_i\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n if i_t * BT + i_i * BC >= T:\n return\n o_i = tl.arange(0, BC)\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n if HEAD_FIRST:\n o_A = (i_k * B * H + i_bh) * T * BC + (i_t * BT + i_i * BC + tl.\n arange(0, BC)) * BC\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.max_contiguous(tl.multiple_of(k + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(g + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n else:\n o_A = (i_k * all + bos + i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * H * BC + i_h * BC\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.max_contiguous(tl.multiple_of(k + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_A = tl.zeros([BC], dtype=tl.float32)\n b_k = tl.load(p_k, mask=m_k, other=0).to(tl.float32)\n b_gk = tl.load(p_gk, mask=m_k, other=0).to(tl.float32)\n b_A += tl.sum(b_q * b_k[None, :] * tl.exp(b_g - b_gk[None, :]), 1)\n b_A = tl.where(o_i >= j, b_A * scale, 0.0)\n tl.store(A + o_A + j, b_A, mask=m_A)\n p_k += K if HEAD_FIRST else H * K\n p_gk += K if HEAD_FIRST else H * K\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "37d65854-b0fd-4bc2-a248-cd43fe18bd16", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_jagged_bmm_jagged_out_kernel(a_ptr, a_offset_ptr, b_ptr,\n b_offset_ptr, c_ptr, offsets_mn_ptr, max_seq_len, num_blocks_n, K,\n stride_am, stride_ak, stride_bk, stride_bn, allow_tf32: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr):\n \"\"\"\n Kernel for computing C = A x B.\n A has shape (sum_B(Mi), K), B has shape (K, sum_B(Ni))\n and C has shape (sum_B(Mi * Ni))\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_batch = tl.program_id(axis=1)\n begin_a = tl.load(a_offset_ptr + pid_batch)\n end_a = tl.load(a_offset_ptr + pid_batch + 1)\n begin_b = tl.load(b_offset_ptr + pid_batch)\n end_b = tl.load(b_offset_ptr + pid_batch + 1)\n offset_mn = tl.load(offsets_mn_ptr + pid_batch)\n M = end_a - begin_a\n M = tl.minimum(M, max_seq_len)\n N = end_b - begin_b\n N = tl.minimum(N, max_seq_len)\n pid_m = pid // num_blocks_n\n pid_n = pid % num_blocks_n\n if pid_m * BLOCK_SIZE_M >= M or pid_n * BLOCK_SIZE_N >= N:\n return\n offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak) + begin_a * stride_am\n b_ptrs = b_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] *\n stride_bn) + begin_b * stride_bn\n c = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, K, BLOCK_SIZE_K):\n updated_offset = k + offs_k\n a = tl.load(a_ptrs, mask=(updated_offset[None, :] < K) & (offs_am[:,\n None] < M), other=0.0)\n b = tl.load(b_ptrs, mask=(updated_offset[:, None] < K) & (offs_bn[\n None, :] < N), other=0.0)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + offset_mn + N * offs_cm[:, None] + offs_cn[None, :]\n c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "9c9a0484-f69a-4208-aa24-d3d5c62c9050", "file_name": "sb_varlen_bwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_bwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.jit\ndef _backward_one_row(seq_prog_id, seq_length, qk_scale, M_range, N_range,\n D_range, D_mask, cm, DO_head_seq_ptr, stride_dom, stride_dod: tl.\n constexpr, DR_head_seq_ptr, stride_drm, A_head_seq_ptr, stride_am: tl.\n constexpr, Q_head_seq_ptr, stride_qm, stride_qd: tl.constexpr,\n K_head_seq_ptr, stride_kn, stride_kd: tl.constexpr, V_head_seq_ptr,\n stride_vn, stride_vd: tl.constexpr, DQ_head_seq_ptr, stride_dqm,\n stride_dqd: tl.constexpr, DK_head_seq_ptr, stride_dkn, stride_dkd: tl.\n constexpr, DV_head_seq_ptr, stride_dvn, stride_dvd: tl.constexpr,\n KV_Lock_ptr, KV_Count_ptr, logit_scale, BLOCK_D: tl.constexpr,\n NO_D_MASK: tl.constexpr, NO_M_MASK: tl.constexpr, ALLOW_TF32: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, acc_dtype: tl.\n constexpr=tl.float32, is_compiling: tl.constexpr=False, attend_current:\n tl.constexpr=False):\n block_start_offset = BLOCK_M * seq_prog_id\n M_blk_idxs = block_start_offset + M_range\n M_mask = M_blk_idxs < seq_length\n NO_M_MASK = block_start_offset + BLOCK_M - 1 < seq_length\n N_blk_idxs_start = 0\n N_blk_idxs = N_blk_idxs_start + N_range\n DO_blk_ptrs = DO_head_seq_ptr + (stride_dom * M_blk_idxs[:, None] + \n stride_dod * D_range[None, :])\n K_blk_ptrs = K_head_seq_ptr + (stride_kn * N_blk_idxs[:, None] + \n stride_kd * D_range[None, :])\n Q_blk_ptrs = Q_head_seq_ptr + (stride_qm * M_blk_idxs[:, None] + \n stride_qd * D_range[None, :])\n V_blk_ptrs = V_head_seq_ptr + (stride_vn * N_blk_idxs[:, None] + \n stride_vd * D_range[None, :])\n A_blk_ptrs = A_head_seq_ptr + stride_am * M_blk_idxs\n DQ_blk_ptrs = DQ_head_seq_ptr + (stride_dqm * M_blk_idxs[:, None] + \n stride_dqd * D_range[None, :])\n DK_blk_ptrs = DK_head_seq_ptr + (stride_dkn * N_blk_idxs[:, None] + \n stride_dkd * D_range[None, :])\n DV_blk_ptrs = DV_head_seq_ptr + (stride_dvn * N_blk_idxs[:, None] + \n stride_dvd * D_range[None, :])\n DR_blk_ptrs = DR_head_seq_ptr + stride_drm * M_blk_idxs\n if NO_D_MASK:\n if NO_M_MASK:\n q = tl.load(Q_blk_ptrs)\n do = tl.load(DO_blk_ptrs)\n dr = tl.load(DR_blk_ptrs)\n neg_log_acc = tl.load(A_blk_ptrs, mask=M_mask)\n else:\n q = tl.load(Q_blk_ptrs, mask=M_mask[:, None])\n do = tl.load(DO_blk_ptrs, mask=M_mask[:, None])\n dr = tl.load(DR_blk_ptrs, mask=M_mask)\n neg_log_acc = tl.load(A_blk_ptrs, mask=M_mask)\n else:\n MD_mask = M_mask[:, None] & D_mask[None, :]\n q = tl.load(Q_blk_ptrs, mask=MD_mask)\n do = tl.load(DO_blk_ptrs, mask=MD_mask)\n dr = tl.load(DR_blk_ptrs, mask=M_mask)\n neg_log_acc = tl.load(A_blk_ptrs, mask=M_mask)\n neg_log_acc = neg_log_acc.to(dtype=acc_dtype)\n grad_prev_acc = tl.zeros((BLOCK_M,), dtype=acc_dtype)\n dq = tl.zeros((BLOCK_M, BLOCK_D), dtype=acc_dtype)\n fwd_cm = tl.trans(cm)\n iters = (block_start_offset + BLOCK_M) // BLOCK_N\n for i in range(iters):\n on_band = iters - i - 1 < BLOCK_M // BLOCK_N\n N_mask = N_blk_idxs < seq_length\n NO_N_MASK = N_blk_idxs_start + BLOCK_N - 1 < seq_length\n k, v = load_kv(K_blk_ptrs, V_blk_ptrs, N_mask=N_mask, NO_N_MASK=\n N_blk_idxs_start + BLOCK_N - 1 < seq_length, D_mask=D_mask,\n NO_D_MASK=NO_D_MASK)\n p, log_om_beta, neg_log_acc = compute_block(q, k, qk_scale,\n neg_log_acc, M_blk_idxs, N_blk_idxs, cm, on_band, ALLOW_TF32,\n attend_current=attend_current, backward=True, is_compiling=\n is_compiling)\n if not NO_M_MASK:\n neg_log_acc = tl.where(M_mask, neg_log_acc, 0.0)\n att_dA = p * (tl.dot(do, tl.trans(v), allow_tf32=ALLOW_TF32) - dr[:,\n None])\n cumul_att_dA = tl.dot(att_dA.to(cm.dtype), fwd_cm, allow_tf32=\n ALLOW_TF32) + grad_prev_acc[:, None]\n grad_prev_acc += tl.sum(att_dA, axis=1)\n beta = 1 - tl.exp2(log_om_beta)\n dqk = att_dA - beta * cumul_att_dA\n dq = tl.dot(dqk.to(k.dtype), k, acc=dq, allow_tf32=ALLOW_TF32)\n block_dk = tl.dot(tl.trans(dqk).to(q.dtype), q, allow_tf32=ALLOW_TF32\n ) * logit_scale\n block_dv = tl.dot(tl.trans(p), do.to(p.dtype), allow_tf32=ALLOW_TF32)\n locked_add(KV_Lock_ptr + i, KV_Count_ptr + i, DK_blk_ptrs, block_dk,\n DV_blk_ptrs, block_dv, N_mask, NO_N_MASK, D_mask, NO_D_MASK)\n N_blk_idxs += BLOCK_N\n N_blk_idxs_start += BLOCK_N\n K_blk_ptrs += BLOCK_N * stride_kn\n V_blk_ptrs += BLOCK_N * stride_vn\n DK_blk_ptrs += BLOCK_N * stride_dkn\n DV_blk_ptrs += BLOCK_N * stride_dvn\n dq = (logit_scale * dq).to(DQ_head_seq_ptr.type.element_ty)\n if NO_D_MASK:\n tl.store(DQ_blk_ptrs, dq, mask=M_mask[:, None])\n else:\n tl.store(DQ_blk_ptrs, dq, mask=M_mask[:, None] & D_mask[None, :])\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Transposed Access", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_bwd.py" }, { "uuid": "0fa9d38c-c513-408f-a16f-741c7127f438", "file_name": "flash_triton.py", "repo_name": "MayDomine/Burst-Attention", "file_path": "burst_attn/flash_triton.py", "commit_hash": "b088c554072935074ea9c643de5ee363be5ab1f6", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0, 'EVEN_HEADDIM': lambda args: args['headdim'] == args[\n 'BLOCK_HEADDIM']})\n@triton.jit\ndef _fwd_kernel(Q, K, V, Bias, Out, Lse, TMP, softmax_scale, stride_qb,\n stride_qh, stride_qm, stride_kb, stride_kh, stride_kn, stride_vb,\n stride_vh, stride_vn, stride_bb, stride_bh, stride_bm, stride_ob,\n stride_oh, stride_om, nheads, seqlen_q, seqlen_k, seqlen_q_rounded,\n headdim, CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, BIAS_TYPE: tl.\n constexpr, IS_CAUSAL: tl.constexpr, BLOCK_HEADDIM: tl.constexpr, EVEN_M:\n tl.constexpr, EVEN_N: tl.constexpr, EVEN_HEADDIM: tl.constexpr, BLOCK_M:\n tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n q_ptrs = Q + off_b * stride_qb + off_h * stride_qh + (offs_m[:, None] *\n stride_qm + offs_d[None, :])\n k_ptrs = K + off_b * stride_kb + off_h * stride_kh + (offs_n[:, None] *\n stride_kn + offs_d[None, :])\n v_ptrs = V + off_b * stride_vb + off_h * stride_vh + (offs_n[:, None] *\n stride_vn + offs_d[None, :])\n if BIAS_TYPE == 'vector':\n b_ptrs = Bias + off_b * stride_bb + off_h * stride_bh + offs_n\n elif BIAS_TYPE == 'matrix':\n b_ptrs = Bias + off_b * stride_bb + off_h * stride_bh + (offs_m[:,\n None] * stride_bm + offs_n[None, :])\n t_ptrs = TMP + off_hb * seqlen_q_rounded + offs_m\n lse_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n acc_o = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M & EVEN_N:\n if EVEN_HEADDIM:\n q = tl.load(q_ptrs)\n else:\n q = tl.load(q_ptrs, mask=offs_d[None, :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n q = tl.load(q_ptrs, mask=offs_m[:, None] < seqlen_q, other=0.0)\n else:\n q = tl.load(q_ptrs, mask=(offs_m[:, None] < seqlen_q) & (offs_d[\n None, :] < headdim), other=0.0)\n end_n = seqlen_k if not IS_CAUSAL else tl.minimum((start_m + 1) *\n BLOCK_M, seqlen_k)\n for start_n in range(0, end_n, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_N & EVEN_M:\n if EVEN_HEADDIM:\n k = tl.load(k_ptrs + start_n * stride_kn)\n else:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=offs_d[None,\n :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=(start_n +\n offs_n)[:, None] < seqlen_k, other=0.0)\n else:\n k = tl.load(k_ptrs + start_n * stride_kn, mask=((start_n +\n offs_n)[:, None] < seqlen_k) & (offs_d[None, :] < headdim),\n other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k, trans_b=True)\n if not EVEN_N:\n qk += tl.where((start_n + offs_n)[None, :] < seqlen_k, 0, float\n ('-inf'))\n if IS_CAUSAL:\n qk += tl.where(offs_m[:, None] >= (start_n + offs_n)[None, :], \n 0, float('-inf'))\n if BIAS_TYPE != 'none':\n if BIAS_TYPE == 'vector':\n if EVEN_N:\n bias = tl.load(b_ptrs + start_n).to(tl.float32)\n else:\n bias = tl.load(b_ptrs + start_n, mask=start_n + offs_n <\n seqlen_k, other=0.0).to(tl.float32)\n bias = bias[None, :]\n elif BIAS_TYPE == 'matrix':\n if EVEN_M & EVEN_N:\n bias = tl.load(b_ptrs + start_n).to(tl.float32)\n else:\n bias = tl.load(b_ptrs + start_n, mask=(offs_m[:, None] <\n seqlen_q) & ((start_n + offs_n)[None, :] < seqlen_k\n ), other=0.0).to(tl.float32)\n qk = qk * softmax_scale + bias\n m_ij = tl.maximum(tl.max(qk, 1), lse_i)\n p = tl.exp(qk - m_ij[:, None])\n else:\n m_ij = tl.maximum(tl.max(qk, 1) * softmax_scale, lse_i)\n p = tl.exp(qk * softmax_scale - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n acc_o_scale = tl.exp(m_i - m_ij)\n tl.store(t_ptrs, acc_o_scale)\n acc_o_scale = tl.load(t_ptrs)\n acc_o = acc_o * acc_o_scale[:, None]\n if EVEN_N & EVEN_M:\n if EVEN_HEADDIM:\n v = tl.load(v_ptrs + start_n * stride_vn)\n else:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=offs_d[None,\n :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=(start_n +\n offs_n)[:, None] < seqlen_k, other=0.0)\n else:\n v = tl.load(v_ptrs + start_n * stride_vn, mask=((start_n +\n offs_n)[:, None] < seqlen_k) & (offs_d[None, :] < headdim),\n other=0.0)\n p = p.to(v.dtype)\n acc_o += tl.dot(p, v)\n m_i = m_ij\n l_i_new = tl.exp(lse_i - m_ij) + l_ij\n lse_i = m_ij + tl.log(l_i_new)\n o_scale = tl.exp(m_i - lse_i)\n tl.store(t_ptrs, o_scale)\n o_scale = tl.load(t_ptrs)\n acc_o = acc_o * o_scale[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n lse_ptrs = Lse + off_hb * seqlen_q_rounded + offs_m\n tl.store(lse_ptrs, lse_i)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n if EVEN_HEADDIM:\n tl.store(out_ptrs, acc_o)\n else:\n tl.store(out_ptrs, acc_o, mask=offs_d[None, :] < headdim)\n elif EVEN_HEADDIM:\n tl.store(out_ptrs, acc_o, mask=offs_m[:, None] < seqlen_q)\n else:\n tl.store(out_ptrs, acc_o, mask=(offs_m[:, None] < seqlen_q) & (\n offs_d[None, :] < headdim))\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MayDomine/Burst-Attention/blob/b088c554072935074ea9c643de5ee363be5ab1f6/burst_attn/flash_triton.py" }, { "uuid": "8a6f7534-fbb7-4a16-8b55-555cc439bcf0", "file_name": "paged_attn_v2.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn_v2.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _paged_attention_v2_reduce(out, exp_sums, max_logits, tmp_out,\n context_lens, stride_exp_m, stride_exp_n, stride_out_m, stride_out_n,\n stride_tmp_m, stride_tmp_n, stride_tmp_k, HEAD_SIZE: tl.constexpr,\n NUM_PARTITIONS: tl.constexpr):\n seq_idx = tl.program_id(axis=1)\n head_idx = tl.program_id(axis=0)\n context_len = tl.load(context_lens + seq_idx)\n num_partitions = tl.cdiv(context_len, PARTITION_SIZE)\n exp_sum = 0.0\n max_logit = float('-inf')\n offs_logit = seq_idx * stride_exp_m + head_idx * stride_exp_n\n head_size_offs = tl.arange(0, HEAD_SIZE)\n tmp_out_ptr = seq_idx * stride_tmp_m + head_idx * stride_tmp_n\n out_ptr = seq_idx * stride_out_m + head_idx * stride_out_n + head_size_offs\n acc = tl.zeros([HEAD_SIZE], dtype=tl.float32)\n global_exp_sum = tl.zeros([1], dtype=tl.float32)\n logits = tl.load(max_logits + offs_logit + tl.arange(0, NUM_PARTITIONS),\n mask=tl.arange(0, NUM_PARTITIONS) < num_partitions, other=float('-inf')\n )\n max_logit = tl.max(logits, axis=0)\n exp_sum = tl.load(exp_sums + offs_logit + tl.arange(0, NUM_PARTITIONS),\n mask=tl.arange(0, NUM_PARTITIONS) < num_partitions, other=0.0)\n rescaled_exp_sum = exp_sum * tl.exp(logits - max_logit)\n global_exp_sum += tl.sum(rescaled_exp_sum, axis=0)\n tmp = tl.load(tmp_out + tmp_out_ptr + tl.arange(0, NUM_PARTITIONS)[:,\n None] * stride_tmp_k + head_size_offs)\n acc += tl.sum(tmp * rescaled_exp_sum[:, None], axis=0)\n inv_sum = 1.0 / (global_exp_sum + 1e-06)\n tl.store(out + out_ptr, acc * inv_sum)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn_v2.py" }, { "uuid": "8114d12c-96e5-4779-a4c3-39663c02465d", "file_name": "conv.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/conv.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@conv_heuristics()\n@triton.jit\ndef _kernel_delta_x(x, w, bias, y, stride_xn, stride_xc, stride_xh,\n stride_xw, stride_wn, stride_wc, stride_wh, stride_ww, stride_yn,\n stride_yc, stride_yh, stride_yw, delta_x_ptr, BATCH, IN_C, IN_H, IN_W,\n KERNEL_N, KERNEL_H, KERNEL_W, OUT_H, OUT_W, stride_h, stride_w,\n padding_h, padding_w, dilation_h, dilation_w, output_padding_h,\n output_padding_w, groups, ACC_TYPE: tl.constexpr, CONV1X1_NHWC: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.\n constexpr, GROUP_H: tl.constexpr, WITH_BIAS: tl.constexpr):\n \"\"\"\n each program instance computes a [BLOCK_BATCH, BLOCK_N, BLOCK_H, BLOCK_W] block of y\n \"\"\"\n pid_nhw = tl.program_id(0)\n pid_k = tl.program_id(1)\n off_y_k = pid_k * BLOCK_N + tl.arange(0, BLOCK_N)\n off_y_nhw = pid_nhw * BLOCK_M + tl.arange(0, BLOCK_M)\n off_y_n = off_y_nhw // (OUT_H * OUT_W)\n off_y_hw = off_y_nhw % (OUT_H * OUT_W)\n off_y_h = off_y_hw // OUT_W + output_padding_h\n off_y_w = off_y_hw % OUT_W + output_padding_w\n off_x_n = off_y_n\n off_x_h = off_y_h * stride_h - padding_h\n off_x_w = off_y_w * stride_w - padding_w\n off_x_nhw = off_x_n * stride_xn + off_x_h * stride_xh + off_x_w * stride_xw\n off_x_crs = tl.arange(0, BLOCK_K)\n CRS = IN_C * KERNEL_H * KERNEL_W\n if not CONV1X1_NHWC:\n delta_x_ptrs = delta_x_ptr + off_x_crs\n off_x_crs_unpacked = tl.load(delta_x_ptrs, mask=off_x_crs < CRS)\n x_ptrs = x + off_x_nhw[:, None] + off_x_crs_unpacked[None, :]\n else:\n x_ptrs = x + off_x_nhw[:, None] + off_x_crs[None, :]\n mask_x = ((off_x_n < BATCH) & (off_x_h >= 0) & (off_x_h < IN_H) & (\n off_x_w >= 0) & (off_x_w < IN_W))[:, None] & (off_x_crs < CRS)[None, :]\n off_w_crs = tl.arange(0, BLOCK_K)\n off_w_k = off_y_k\n w_ptrs = w + off_w_crs[:, None] + off_w_k[None, :] * stride_wn\n mask_w = (off_x_crs < CRS)[:, None] & (off_w_k < KERNEL_N)[None, :]\n matrix_x = tl.load(x_ptrs, mask=mask_x, other=0.0)\n matrix_w = tl.load(w_ptrs, mask=mask_w, other=0.0)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=ACC_TYPE)\n for crs in range(0, CRS, BLOCK_K):\n acc += tl.dot(matrix_x, matrix_w, out_dtype=ACC_TYPE)\n w_ptrs += BLOCK_K\n if not CONV1X1_NHWC:\n delta_x_ptrs += BLOCK_K\n off_x_crs = crs + BLOCK_K + tl.arange(0, BLOCK_K)\n off_x_crs_unpacked = tl.load(delta_x_ptrs, mask=off_x_crs < CRS,\n other=0)\n x_ptrs = x + off_x_nhw[:, None] + off_x_crs_unpacked[None, :]\n else:\n off_x_crs = crs + BLOCK_K + tl.arange(0, BLOCK_K)\n x_ptrs += BLOCK_K\n mask_x = ((off_x_n < BATCH) & (off_x_h >= 0) & (off_x_h < IN_H) & (\n off_x_w >= 0) & (off_x_w < IN_W))[:, None] & (off_x_crs < CRS)[\n None, :]\n mask_w = (off_x_crs < CRS)[:, None] & (off_w_k < KERNEL_N)[None, :]\n matrix_x = tl.load(x_ptrs, mask=mask_x, other=0.0)\n matrix_w = tl.load(w_ptrs, mask=mask_w, other=0.0)\n if WITH_BIAS:\n acc += tl.load(bias + off_y_k)[None, :]\n acc = acc.to(y.dtype.element_ty)\n off_y_k = pid_k * BLOCK_N + tl.arange(0, BLOCK_N)\n off_y_nhw = pid_nhw * BLOCK_M + tl.arange(0, BLOCK_M)\n off_y_n = off_y_nhw // (OUT_H * OUT_W)\n off_y_hw = off_y_nhw % (OUT_H * OUT_W)\n off_y_h = off_y_hw // OUT_W + output_padding_h\n off_y_w = off_y_hw % OUT_W + output_padding_w\n y_ptrs = y + off_y_n[:, None] * stride_yn + off_y_h[:, None\n ] * stride_yh + off_y_w[:, None] * stride_yw + off_y_k[None, :\n ] * stride_yc\n mask_y = (off_y_n < BATCH)[:, None] & (off_y_h < OUT_H + output_padding_h)[\n :, None] & (off_y_w < OUT_W + output_padding_w)[:, None] & (off_y_k <\n KERNEL_N)[None, :]\n tl.store(y_ptrs, acc, mask=mask_y)\n return\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/conv.py" }, { "uuid": "bd8d9b19-0eb1-4606-abf9-07bc9b74d955", "file_name": "logsumexp.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/logsumexp.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'HAS_SCALE': lambda args: args['scale'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16, 32]], key=['D'])\n@triton.jit\ndef logsumexp_fwd_kernel(x, z, scale, D: tl.constexpr, B: tl.constexpr,\n HAS_SCALE: tl.constexpr):\n i_n, i_d = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.int64)\n o_d = i_d * B + tl.arange(0, B)\n m_d = o_d < D\n b_x = tl.load(x + i_n * D + o_d, mask=m_d, other=-float('inf'))\n if HAS_SCALE:\n b_x = b_x * scale\n b_m = tl.max(b_x, 0)\n b_z = tl.log(tl.sum(tl.exp(b_x - b_m), 0)) + b_m\n tl.store(z + i_n * tl.cdiv(D, B) + i_d, b_z)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/logsumexp.py" }, { "uuid": "6a35f449-cfba-4f15-a4d9-9faf8f90396e", "file_name": "gemm_postop_addmatrix_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_postop_addmatrix_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32), triton.Config({'BLOCK_SIZE_M': \n 256, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4,\n 'grf_mode': 'large'}, num_stages=3, num_warps=32), triton.Config({\n 'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32\n ), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =2, num_warps=32)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers(a_ptr, b_ptr, c_ptr, d_ptr, M: tl.\n constexpr, N: tl.constexpr, K: tl.constexpr, stride_am: tl.constexpr,\n stride_ak: tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.\n constexpr, stride_cm: tl.constexpr, stride_cn: tl.constexpr, stride_dm:\n tl.constexpr, stride_dn: tl.constexpr, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n a_block_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n d_block_ptr = tl.make_block_ptr(base=d_ptr, shape=(M, N), strides=(\n stride_dm, stride_dn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n d = tl.load(d_block_ptr, boundary_check=(0, 1))\n c = accumulator + d\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_postop_addmatrix_benchmark.py" }, { "uuid": "10debe65-3ac2-4a2b-b2a0-78f9bbae7964", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef tensor_elementwise_add(x, y):\n return x + y\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "965c0840-cbb1-4409-bcfe-384d35052963", "file_name": "softmax.py", "repo_name": "l1351868270/implicit_gemm.triton", "file_path": "triton_kernel/softmax.py", "commit_hash": "64eb8548ccf4576883c928f6315be8b24680a455", "starcount": 0, "input": "@triton.jit\ndef _ld_softmax_bwd_kernel(ds_ptr, p_ptr, dp_ptr, ds_row_stride,\n p_row_stride, dp_row_stride, n_rows, n_cols, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n p_start_ptr = p_ptr + row_idx * p_row_stride\n dp_start_ptr = dp_ptr + row_idx * dp_row_stride\n col_offsets = tl.arange(0, BLOCK_SIZE)\n p_ptrs = p_start_ptr + col_offsets\n dp_ptrs = dp_start_ptr + col_offsets\n mask = col_offsets < n_cols\n p_row = tl.load(p_ptrs, mask=mask, other=0)\n dp_row = tl.load(dp_ptrs, mask=mask, other=0)\n ds_row = p_row * (dp_row - tl.sum(p_row * dp_row, axis=0))\n ds_start_ptr = ds_ptr + row_idx * ds_row_stride\n ds_ptrs = ds_start_ptr + col_offsets\n tl.store(ds_ptrs, ds_row, mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/l1351868270/implicit_gemm.triton/blob/64eb8548ccf4576883c928f6315be8b24680a455/triton_kernel/softmax.py" }, { "uuid": "23ae7635-b08c-4919-a8c0-55f2f7104fe2", "file_name": "group_norm.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/group_norm.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@eval(\n \"\"\"triton.heuristics({\n 'ROW_SIZE':\n lambda kwargs: triton.next_power_of_2(kwargs['C'] // kwargs['groups']),\n 'BLOCK_SIZE':\n lambda kwargs: max(\n 1, min(triton.next_power_of_2(kwargs['HxW']),\n 4096 // (triton.next_power_of_2(kwargs['C'] // kwargs['groups']))\n )),\n})\"\"\"\n )\n@eval(\n \"\"\"triton.heuristics({\n 'num_warps':\n lambda kwargs: max(1, min(16, kwargs['ROW_SIZE'] * kwargs['BLOCK_SIZE'] // 128)),\n 'C_G': lambda kwargs: kwargs['C'] // kwargs['groups'],\n})\"\"\"\n )\n@triton.jit\ndef group_norm_4d_channels_last_forward_collect_stats_kernel(input_ptr, N,\n C, HxW, groups, eps, mean_ptr, rstd_ptr, C_G, ROW_SIZE: tl.constexpr,\n BLOCK_SIZE: tl.constexpr):\n group = tl.program_id(0)\n pid_batch = tl.program_id(1)\n offset = pid_batch * C * HxW + group * C_G\n X = input_ptr + offset\n _mean = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n _m2 = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n _weight = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n row = tl.arange(0, ROW_SIZE)\n for off in range(0, HxW, BLOCK_SIZE):\n r = off + tl.arange(0, BLOCK_SIZE)\n m2_ = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n mask = (r < HxW)[:, None] & (row[None, :] < C_G)\n weight_ = mask.to(tl.float32)\n x = tl.load(X + (r * C)[:, None] + row[None, :], mask=mask).to(tl.\n float32)\n _mean, _m2, _weight = welford_combine(_mean, _m2, _weight, x, m2_,\n weight_)\n _mean = tl.view(_mean, (BLOCK_SIZE * ROW_SIZE,))\n _m2 = tl.view(_m2, (BLOCK_SIZE * ROW_SIZE,))\n _weight = tl.view(_weight, (BLOCK_SIZE * ROW_SIZE,))\n mean, m2, weight = tl.reduce((_mean, _m2, _weight), 0, welford_combine)\n var = m2 / weight\n rstd = 1.0 / tl.sqrt(var + eps)\n offset = pid_batch * groups + group\n tl.store(mean_ptr + offset, mean)\n tl.store(rstd_ptr + offset, rstd)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/group_norm.py" }, { "uuid": "770ec2b3-7745-432e-bbae-8d2c438cc02f", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_softmax_kernel(input_ptr, output_ptr, input_offsets_ptr,\n input_row_stride, input_head_stride, output_row_stride,\n output_head_stride, max_seq_len: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n input shpae is [SUM_B, H]\n output shape is [SUM_B, H]\n \"\"\"\n pid_batch = tl.program_id(0)\n pid_head = tl.program_id(1)\n row_begin = tl.load(input_offsets_ptr + pid_batch)\n row_end = tl.load(input_offsets_ptr + pid_batch + 1)\n N = tl.minimum(max_seq_len, row_end - row_begin)\n if N == 0:\n return\n row_start_ptr = input_ptr + row_begin * input_row_stride\n col_offsets = tl.arange(0, BLOCK_SIZE)\n input_ptrs = (row_start_ptr + col_offsets * input_row_stride + pid_head *\n input_head_stride)\n row = tl.load(input_ptrs, mask=col_offsets < N, other=-float('inf'))\n row_mins_max = row - tl.max(row, axis=0)\n numerator = tl.exp(row_mins_max)\n denominator = tl.sum(numerator, axis=0)\n softmax_output = numerator / denominator\n output_row_start_ptr = output_ptr + row_begin * output_row_stride\n output_ptrs = (output_row_start_ptr + col_offsets * output_row_stride +\n pid_head * output_head_stride)\n tl.store(output_ptrs, softmax_output, mask=col_offsets < N)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "5c760d10-cb85-49c6-9d13-141637fb65e6", "file_name": "matrix-vector-multiplication-bf16.py", "repo_name": "northstreet12/triton-cpu", "file_path": "python/tutorials/matrix-vector-multiplication-bf16.py", "commit_hash": "bfb302ffc5fde3b9efe040cb452ddac0454dbb98", "starcount": 0, "input": "@triton.jit\ndef gemv_kernel(Y, A, X, M, N, stride_am, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr):\n start_m = tl.program_id(0)\n rm = start_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n rn = tl.arange(0, BLOCK_SIZE_N)\n A = A + (rm[:, None] * stride_am + rn[None, :])\n X = X + rn\n acc = tl.zeros((BLOCK_SIZE_M,), dtype=tl.float32)\n for n in range(N, 0, -BLOCK_SIZE_N):\n a = tl.load(A)\n x = tl.load(X)\n acc += tl.sum(a * x[None, :], axis=1)\n A += BLOCK_SIZE_N\n X += BLOCK_SIZE_N\n y = acc.to(tl.bfloat16)\n Y = Y + rm\n tl.store(Y, y)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "bf16", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/northstreet12/triton-cpu/blob/bfb302ffc5fde3b9efe040cb452ddac0454dbb98/python/tutorials/matrix-vector-multiplication-bf16.py" }, { "uuid": "1e8d4b3f-525d-4e92-a1e7-b8c95e9d1b8e", "file_name": "bwd_kernel_dk_dv.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/bwd_kernel_dk_dv.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef bwd_kernel_dk_dv(Q, K, V, B, sm_scale, Out, DO, DK, DV, L, D, stride_qz,\n stride_qh, stride_qm, stride_qk, stride_kz, stride_kh, stride_kn,\n stride_kk, stride_vz, stride_vh, stride_vk, stride_vn, stride_bz,\n stride_bh, stride_bm, stride_bn, stride_oz, stride_oh, stride_om,\n stride_ok, stride_dkz, stride_dkh, stride_dkn, stride_dkk, stride_dvz,\n stride_dvh, stride_dvk, stride_dvn, num_head_q: 'i32', num_head_k:\n 'i32', cu_seqlens_q, cu_seqlens_k, num_seqlens: 'i32', max_seqlen_q:\n 'i32', max_seqlen_k: 'i32', head_dim: 'i32', dropout_p, philox_seed_ptr,\n philox_offset1: '*u32', philox_offset2: 'u32', BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.\n constexpr):\n philox_seed = 0\n philox_offset_base = philox_offset2\n if ENABLE_DROPOUT:\n philox_seed = tl.load(philox_seed_ptr)\n philox_offset_base += tl.load(philox_offset1)\n start_k = tl.program_id(0) * BLOCK_N\n off_h_k = tl.program_id(1)\n off_z = tl.program_id(2)\n num_z = tl.num_programs(2)\n offs_m = tl.arange(0, BLOCK_M)\n offs_n = start_k + tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n ld_offs_d = None if not PADDED_HEAD else tl.arange(0, BLOCK_DMODEL)\n cu_seqlens_q_start = 0\n cu_seqlens_k_start = 0\n seqlen_q = max_seqlen_q\n seqlen_k = max_seqlen_k\n batch_index = off_z\n if num_seqlens > 0:\n cu_seqlens_k_start = tl.load(cu_seqlens_k + off_z)\n cu_seqlens_k_end = tl.load(cu_seqlens_k + off_z + 1)\n seqlen_k = cu_seqlens_k_end - cu_seqlens_k_start\n if start_k >= seqlen_k:\n return\n cu_seqlens_q_start = tl.load(cu_seqlens_q + off_z)\n cu_seqlens_q_end = tl.load(cu_seqlens_q + off_z + 1)\n seqlen_q = cu_seqlens_q_end - cu_seqlens_q_start\n batch_index = 0\n if num_seqlens < 0:\n cu_seqlens_k_start = tl.load(cu_seqlens_k + off_z)\n cu_seqlens_k_end = tl.load(cu_seqlens_k + off_z + 1)\n seqlen_k = cu_seqlens_k_end - cu_seqlens_k_start\n if start_k >= seqlen_k:\n return\n cu_seqlens_q_start = tl.load(cu_seqlens_q + off_z)\n cu_seqlens_q_end = tl.load(cu_seqlens_q + off_z + 1)\n seqlen_q = cu_seqlens_q_end - cu_seqlens_q_start\n cu_seqlens_q_start = 0\n cu_seqlens_k_start = 0\n batch_index = off_z\n k_offset = (off_h_k * stride_kh + batch_index * stride_kz + \n cu_seqlens_k_start * stride_kn)\n K += k_offset\n kt_ptrs = K + offs_d[:, None] * stride_kk + offs_n[None, :] * stride_kn\n if start_k + BLOCK_N <= seqlen_k:\n kt = load_fn(kt_ptrs, ld_offs_d, None, head_dim, seqlen_k)\n else:\n kt = load_fn(kt_ptrs, ld_offs_d, offs_n, head_dim, seqlen_k)\n v_offset = (off_h_k * stride_vh + batch_index * stride_vz + \n cu_seqlens_k_start * stride_vk)\n V += v_offset\n vt_ptrs = V + offs_d[:, None] * stride_vn + offs_n[None, :] * stride_vk\n if start_k + BLOCK_N <= seqlen_k:\n vt = load_fn(vt_ptrs, ld_offs_d, None, head_dim, seqlen_k)\n else:\n vt = load_fn(vt_ptrs, ld_offs_d, offs_n, head_dim, seqlen_k)\n if BIAS_TYPE == 0:\n B_block_ptr = 0\n elif BIAS_TYPE == 1:\n B_block_ptr = tl.make_block_ptr(base=B + off_h_k * stride_bh + \n batch_index * stride_bz, shape=(seqlen_q, seqlen_k), strides=(\n stride_bm, stride_bn), offsets=(0, start_k), block_shape=(\n BLOCK_M, BLOCK_N), order=(1, 0))\n else:\n tl.static_assert(False, f'Unsupported BIAS_TYPE {BIAS_TYPE}')\n dk_offset = (off_h_k * stride_dkh + batch_index * stride_dkz + \n cu_seqlens_k_start * stride_dkn)\n DK += dk_offset\n dv_offset = (off_h_k * stride_dvh + batch_index * stride_dvz + \n cu_seqlens_k_start * stride_dvk)\n DV += dv_offset\n dv = tl.zeros([BLOCK_N, BLOCK_DMODEL], dtype=tl.float32)\n dk = tl.zeros([BLOCK_N, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504089\n bias_scale = 1.0 / sm_scale\n group_size = num_head_q // num_head_k\n q_lo = start_k if CAUSAL else 0\n q_hi = seqlen_q\n real_seqlen_q = q_hi - q_lo\n n_blocks = tl.cdiv(q_hi - q_lo, BLOCK_M)\n n_extra_tokens = 0\n if real_seqlen_q < BLOCK_M:\n n_extra_tokens = BLOCK_M - real_seqlen_q\n elif real_seqlen_q % BLOCK_M:\n n_extra_tokens = real_seqlen_q % BLOCK_M\n is_irregular_q = n_extra_tokens != 0\n leading_masked_blocks = 0\n trailing_masked_blocks = 0\n if CAUSAL:\n leading_masked_blocks = tl.cdiv(BLOCK_N, BLOCK_M)\n trailing_masked_blocks = 1 if is_irregular_q else 0\n else:\n leading_masked_blocks = 0\n trailing_masked_blocks = 1 if is_irregular_q else 0\n n_full_blocks = n_blocks - leading_masked_blocks - trailing_masked_blocks\n dropout_scale = 1.0 / (1.0 - dropout_p) if ENABLE_DROPOUT else 1.0\n for off_h_q in range(off_h_k * group_size, off_h_k * group_size +\n group_size):\n off_zh = off_z * num_head_q + off_h_q * 1\n if ENABLE_DROPOUT:\n batch_philox_offset = (philox_offset_base + off_zh *\n max_seqlen_q * max_seqlen_k)\n else:\n batch_philox_offset = 0\n D_ptrs = D + off_zh * max_seqlen_q\n l_ptrs = L + off_zh * max_seqlen_q\n q_offset = (off_h_q * stride_qh + batch_index * stride_qz + \n cu_seqlens_q_start * stride_qm)\n q_ptrs = Q + q_offset + offs_m[:, None] * stride_qm + offs_d[None, :\n ] * stride_qk\n do_offset = (off_h_q * stride_oh + batch_index * stride_oz + \n cu_seqlens_q_start * stride_om)\n do_ptrs = DO + do_offset + offs_m[:, None] * stride_om + offs_d[None, :\n ] * stride_ok\n lo = 0\n hi = 0\n if leading_masked_blocks > 0:\n lo = q_lo\n hi = lo + leading_masked_blocks * BLOCK_M\n overflow_size = 0 if hi < q_hi else hi - q_hi\n dk, dv = bwd_inner_dk_dv(dk, dv, qk_scale, bias_scale, q_ptrs,\n stride_qm, kt, vt, B_block_ptr, do_ptrs, stride_om, l_ptrs,\n D_ptrs, seqlen_q, seqlen_k, head_dim, start_k, lo, hi,\n overflow_size, dropout_p, dropout_scale, philox_seed,\n batch_philox_offset, max_seqlen_k, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, False, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD, BIAS_TYPE)\n tl.debug_barrier()\n if n_full_blocks > 0:\n lo = q_lo + leading_masked_blocks * BLOCK_M\n hi = lo + n_full_blocks * BLOCK_M\n dk, dv = bwd_inner_dk_dv(dk, dv, qk_scale, bias_scale, q_ptrs,\n stride_qm, kt, vt, B_block_ptr, do_ptrs, stride_om, l_ptrs,\n D_ptrs, seqlen_q, seqlen_k, head_dim, start_k, lo, hi, 0,\n dropout_p, dropout_scale, philox_seed, batch_philox_offset,\n max_seqlen_k, BLOCK_M, BLOCK_DMODEL, BLOCK_N, True, False,\n ENABLE_DROPOUT, PADDED_HEAD, BIAS_TYPE)\n if n_full_blocks >= 0 and trailing_masked_blocks > 0:\n tl.debug_barrier()\n lo = (q_lo + leading_masked_blocks * BLOCK_M + n_full_blocks *\n BLOCK_M)\n hi = q_hi\n overflow_size = lo + trailing_masked_blocks * BLOCK_M - q_hi\n dk, dv = bwd_inner_dk_dv(dk, dv, qk_scale, bias_scale, q_ptrs,\n stride_qm, kt, vt, B_block_ptr, do_ptrs, stride_om, l_ptrs,\n D_ptrs, seqlen_q, seqlen_k, head_dim, start_k, lo, hi,\n overflow_size, dropout_p, dropout_scale, philox_seed,\n batch_philox_offset, max_seqlen_k, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, False, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD, BIAS_TYPE)\n dk = (dk * sm_scale).to(kt.type.element_ty)\n dv = dv.to(vt.type.element_ty)\n mstore2d(dk, BLOCK_N, BLOCK_DMODEL, o_base=DK, o_start_row=start_k,\n o_start_col=0, o_rows=seqlen_k, o_cols=head_dim, stride_row=\n stride_dkn, stride_col=stride_dkk)\n mstore2d(dv, BLOCK_N, BLOCK_DMODEL, o_base=DV, o_start_row=start_k,\n o_start_col=0, o_rows=seqlen_k, o_cols=head_dim, stride_row=\n stride_dvk, stride_col=stride_dvn)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/bwd_kernel_dk_dv.py" }, { "uuid": "ee05de93-5deb-4808-b6ef-0af8f24d4eda", "file_name": "triton_fused_vq_attn.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_vq_attn.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0})\n@triton.jit\ndef _vq_fwd_kernel(Q, K_VQ, K_VQ_CNT, V_VQ, V_VQ_INDEX, Out, L,\n softmax_scale, stride_q_b, stride_q_h, stride_q_m, stride_kvq_h,\n stride_kvq_c, stride_kvqc_b, stride_kvqc_h, stride_kvqc_n, stride_vvq_b,\n stride_vvq_h, stride_vvq_n, stride_vvqi_b, stride_vvqi_h, stride_vvqi_n,\n stride_o_b, stride_o_h, stride_o_m, nheads, seqlen_q, codebook_size,\n CACHE_KEY_SEQLEN_Q, WINDOW_SIZE: tl.constexpr, BLOCK_HEADDIM: tl.\n constexpr, EVEN_M: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr, WRITE_LSE: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + WINDOW_SIZE + BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n Q_block_ptr = tl.make_block_ptr(base=Q + (off_b * stride_q_b + off_h *\n stride_q_h), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_q_m, \n 1), offsets=(start_m * BLOCK_M + WINDOW_SIZE + BLOCK_M, 0),\n block_shape=(BLOCK_M, BLOCK_HEADDIM), order=(1, 0))\n K_VQ_block_ptr = tl.make_block_ptr(base=K_VQ + off_h * stride_kvq_h,\n shape=(BLOCK_HEADDIM, codebook_size), strides=(1, stride_kvq_c),\n offsets=(0, 0), block_shape=(BLOCK_HEADDIM, BLOCK_N), order=(0, 1))\n K_VQC_block_ptr = tl.make_block_ptr(base=K_VQ_CNT + (off_b *\n stride_kvqc_b + off_h * stride_kvqc_h + start_m * stride_kvqc_n),\n shape=(codebook_size,), strides=(1,), offsets=(0,), block_shape=(\n BLOCK_N,), order=(0,))\n VVQI_block_ptr = tl.make_block_ptr(base=V_VQ_INDEX + (off_b *\n stride_vvqi_b + off_h * stride_vvqi_h + start_m * stride_vvqi_n),\n shape=(codebook_size,), strides=(1,), offsets=(0,), block_shape=(\n BLOCK_N,), order=(0,))\n V_VQ += off_b * stride_vvq_b + off_h * stride_vvq_h\n if EVEN_M:\n q = tl.load(Q_block_ptr)\n else:\n q = tl.load(Q_block_ptr, boundary_check=(0,), padding_option='zero')\n acc, l_i, m_i = _vq_attn_fwd_inner(acc, l_i, m_i, q, softmax_scale,\n K_VQ_block_ptr, K_VQC_block_ptr, VVQI_block_ptr, V_VQ, stride_vvq_n,\n codebook_size, BLOCK_HEADDIM, BLOCK_N)\n acc = acc / l_i[:, None]\n if WRITE_LSE:\n l_ptrs = L + off_hb * seqlen_q + offs_m\n if EVEN_M:\n tl.store(l_ptrs, m_i + tl.math.log2(l_i))\n else:\n tl.store(l_ptrs, m_i + tl.math.log2(l_i), mask=offs_m < seqlen_q)\n out_ptrs = Out + off_b * stride_o_b + off_h * stride_o_h + (offs_m[:,\n None] * stride_o_m + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc)\n else:\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Quantization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_vq_attn.py" }, { "uuid": "a1c210f1-dae7-43a1-b05d-d236f1f87998", "file_name": "real_rnn_tie_input_gate.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef fwd_sequential_scan_fused(v, f1, hidden, B, L, C, BLOCK_M: tl.constexpr):\n offset_b = tl.program_id(0)\n if offset_b >= B:\n return\n offset_n = tl.program_id(1)\n ptr = tl.arange(0, BLOCK_M) + offset_b * L * C + offset_n * BLOCK_M\n h1 = tl.zeros([BLOCK_M], dtype=tl.float32)\n for _ in range(L):\n x0 = tl.load(v + ptr).to(tl.float32)\n decay1 = tl.load(f1 + ptr).to(tl.float32)\n decay1 = tl.sigmoid(decay1)\n h1 = (h1 - x0) * decay1 + x0\n tl.store(hidden + ptr, h1.to(hidden.dtype.element_ty))\n ptr += C\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py" }, { "uuid": "4e1ef67f-1573-4d17-8121-3a7f8e148d1b", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef load_full_2d(ptr, sz0: tl.constexpr, sz1: tl.constexpr, stride0=None,\n stride1=1):\n \"\"\"Load 2d block [0,...,sz0-1] x [0,...,sz1-1]\"\"\"\n stride0 = stride0 or sz1\n offs = get_2d_offset(tl.arange(0, sz0), tl.arange(0, sz1), stride0, stride1\n )\n mask = get_2d_mask(tl.arange(0, sz0), tl.arange(0, sz1), sz0, sz1)\n return tl.load(ptr + offs, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "399b5bd6-779f-481e-b641-a97817c65b63", "file_name": "k_softmax.py", "repo_name": "kimiasa/Experiments", "file_path": "src/ops/triton/k_softmax.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['K'])\n@triton.heuristics({'DEPTH': lambda nargs: get_depth(nargs['K'])})\n@triton.heuristics({'IS_FP16': lambda nargs: nargs['Y'].dtype == torch.float16}\n )\n@triton.jit\ndef _softmax(Y, X, M, stride_ym, stride_yn, stride_xm, stride_xn, stride_m,\n K, LOG: tl.constexpr, MASK_TYPE: tl.constexpr, CAUSAL: tl.constexpr,\n DEPTH: tl.constexpr, IS_FP16: tl.constexpr):\n \"\"\"\n Fused softmax kernel over a 3d tensor.\n The softmax is applied over the last dimension, meaning that this is equivalent to torch.softmax(tensor, dim=-1)\n\n Note, if the last dimension is large, say 128K elements, the kernel compile time can shot up to many minutes when\n the kernel is run for the first time.\n \"\"\"\n m = tl.program_id(0)\n n = tl.program_id(1)\n k = tl.arange(0, DEPTH)\n x_ptrs = X + m * stride_xm + n * stride_xn + k\n io_mask = k < K\n if CAUSAL:\n io_mask = io_mask & (k <= n)\n x = tl.load(x_ptrs, mask=io_mask, other=float('-inf'))\n if CAUSAL:\n off = float('-inf')\n off = off.to(x.dtype)\n x = tl.where(k > n, off, x)\n if MASK_TYPE is not None:\n if MASK_TYPE == 'qk':\n mask_ptrs = M + n * stride_m + k\n elif MASK_TYPE == 'bk':\n mask_ptrs = M + m * stride_m + k\n add_mask = tl.load(mask_ptrs, io_mask, other=float('-inf'))\n x += add_mask\n z = x - tl.max(x, axis=0)\n if IS_FP16:\n z = z.to(tl.float32)\n num = tl.exp(z)\n denom = tl.sum(num, axis=0)\n if LOG:\n y = z - tl.log(denom)\n else:\n y = num / denom\n y_ptrs = Y + m * stride_ym + n * stride_yn + k\n tl.store(y_ptrs, y, mask=k < K)\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/ops/triton/k_softmax.py" }, { "uuid": "a5f58e11-541c-49c1-aad8-632c55cafadf", "file_name": "mamba_ssm.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/model_executor/layers/mamba/ops/mamba_ssm.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.heuristics({'HAS_DT_BIAS': lambda args: args['dt_bias_ptr'] is not\n None})\n@triton.heuristics({'HAS_D': lambda args: args['D_ptr'] is not None})\n@triton.heuristics({'HAS_Z': lambda args: args['z_ptr'] is not None})\n@triton.heuristics({'HAS_STATE_BATCH_INDICES': lambda args: args[\n 'state_batch_indices_ptr'] is not None})\n@triton.heuristics({'BLOCK_SIZE_DSTATE': lambda args: triton.\n next_power_of_2(args['dstate'])})\n@triton.jit\ndef _selective_scan_update_kernel(state_ptr, x_ptr, dt_ptr, dt_bias_ptr,\n A_ptr, B_ptr, C_ptr, D_ptr, z_ptr, out_ptr, state_batch_indices_ptr,\n batch, nheads, dim, dstate, nheads_ngroups_ratio, stride_state_batch,\n stride_state_head, stride_state_dim, stride_state_dstate,\n stride_x_batch, stride_x_head, stride_x_dim, stride_dt_batch,\n stride_dt_head, stride_dt_dim, stride_dt_bias_head, stride_dt_bias_dim,\n stride_A_head, stride_A_dim, stride_A_dstate, stride_B_batch,\n stride_B_group, stride_B_dstate, stride_C_batch, stride_C_group,\n stride_C_dstate, stride_D_head, stride_D_dim, stride_z_batch,\n stride_z_head, stride_z_dim, stride_out_batch, stride_out_head,\n stride_out_dim, DT_SOFTPLUS: tl.constexpr, TIE_HDIM: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, HAS_DT_BIAS: tl.constexpr, HAS_D: tl.\n constexpr, HAS_Z: tl.constexpr, HAS_STATE_BATCH_INDICES: tl.constexpr,\n BLOCK_SIZE_DSTATE: tl.constexpr):\n pid_m = tl.program_id(axis=0)\n pid_b = tl.program_id(axis=1)\n pid_h = tl.program_id(axis=2)\n if HAS_STATE_BATCH_INDICES:\n state_batch_indices_ptr += pid_b\n state_batch_idx = tl.load(state_batch_indices_ptr)\n state_ptr += (state_batch_idx * stride_state_batch + pid_h *\n stride_state_head)\n else:\n state_ptr += pid_b * stride_state_batch + pid_h * stride_state_head\n x_ptr += pid_b * stride_x_batch + pid_h * stride_x_head\n dt_ptr += pid_b * stride_dt_batch + pid_h * stride_dt_head\n if HAS_DT_BIAS:\n dt_bias_ptr += pid_h * stride_dt_bias_head\n A_ptr += pid_h * stride_A_head\n B_ptr += (pid_b * stride_B_batch + pid_h // nheads_ngroups_ratio *\n stride_B_group)\n C_ptr += (pid_b * stride_C_batch + pid_h // nheads_ngroups_ratio *\n stride_C_group)\n if HAS_Z:\n z_ptr += pid_b * stride_z_batch + pid_h * stride_z_head\n out_ptr += pid_b * stride_out_batch + pid_h * stride_out_head\n offs_m = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_n = tl.arange(0, BLOCK_SIZE_DSTATE)\n state_ptrs = state_ptr + (offs_m[:, None] * stride_state_dim + offs_n[\n None, :] * stride_state_dstate)\n x_ptrs = x_ptr + offs_m * stride_x_dim\n dt_ptrs = dt_ptr + offs_m * stride_dt_dim\n if HAS_DT_BIAS:\n dt_bias_ptrs = dt_bias_ptr + offs_m * stride_dt_bias_dim\n if HAS_D:\n D_ptr += pid_h * stride_D_head\n A_ptrs = A_ptr + (offs_m[:, None] * stride_A_dim + offs_n[None, :] *\n stride_A_dstate)\n B_ptrs = B_ptr + offs_n * stride_B_dstate\n C_ptrs = C_ptr + offs_n * stride_C_dstate\n if HAS_D:\n D_ptrs = D_ptr + offs_m * stride_D_dim\n if HAS_Z:\n z_ptrs = z_ptr + offs_m * stride_z_dim\n out_ptrs = out_ptr + offs_m * stride_out_dim\n state = tl.load(state_ptrs, mask=(offs_m[:, None] < dim) & (offs_n[None,\n :] < dstate), other=0.0)\n x = tl.load(x_ptrs, mask=offs_m < dim, other=0.0).to(tl.float32)\n if not TIE_HDIM:\n dt = tl.load(dt_ptrs, mask=offs_m < dim, other=0.0).to(tl.float32)\n if HAS_DT_BIAS:\n dt += tl.load(dt_bias_ptrs, mask=offs_m < dim, other=0.0).to(tl\n .float32)\n if DT_SOFTPLUS:\n dt = softplus(dt)\n A = tl.load(A_ptrs, mask=(offs_m[:, None] < dim) & (offs_n[None, :] <\n dstate), other=0.0).to(tl.float32)\n dA = tl.exp(A * dt[:, None])\n else:\n dt = tl.load(dt_ptr).to(tl.float32)\n if HAS_DT_BIAS:\n dt += tl.load(dt_bias_ptr).to(tl.float32)\n if DT_SOFTPLUS:\n dt = softplus(dt)\n A = tl.load(A_ptr).to(tl.float32)\n dA = tl.exp(A * dt)\n B = tl.load(B_ptrs, mask=offs_n < dstate, other=0.0).to(tl.float32)\n C = tl.load(C_ptrs, mask=offs_n < dstate, other=0.0).to(tl.float32)\n if HAS_D:\n D = tl.load(D_ptrs, mask=offs_m < dim, other=0.0).to(tl.float32)\n if HAS_Z:\n z = tl.load(z_ptrs, mask=offs_m < dim, other=0.0).to(tl.float32)\n dB = B[None, :] * dt[:, None] if not TIE_HDIM else B * dt\n state = state * dA + dB * x[:, None]\n tl.store(state_ptrs, state, mask=(offs_m[:, None] < dim) & (offs_n[None,\n :] < dstate))\n out = tl.sum(state * C[None, :], axis=1)\n if HAS_D:\n out += x * D\n if HAS_Z:\n out *= z * tl.sigmoid(z)\n tl.store(out_ptrs, out, mask=offs_m < dim)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/model_executor/layers/mamba/ops/mamba_ssm.py" }, { "uuid": "bfa71336-4d07-4f50-b917-10440a567a7d", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8]], key=['BK'])\n@triton.jit\ndef fwd_prepare_wy_repr_kernel_chunk64(k, g, beta, Aw, Au, offsets, indices,\n T: tl.constexpr, K: tl.constexpr, H: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr, BC: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n b_Aw = tl.zeros([BC, BC], dtype=tl.float32)\n b_Aw2 = tl.zeros([BC, BC], dtype=tl.float32)\n b_Aw3 = tl.zeros([BC, BC], dtype=tl.float32)\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BC,), (0,))\n p_beta2 = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT +\n BC,), (BC,), (0,))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BC,), (0,))\n p_beta2 = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT + BC,), (BC,), (0,))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_beta2 = tl.load(p_beta2, boundary_check=(0,))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BC, BK), (1, 0))\n p_k2 = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + BC, i_k * BK), (BC, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BC, BK), (1, 0))\n p_k2 = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + BC, i_k * BK), (BC, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_k2 = tl.load(p_k2, boundary_check=(0, 1))\n b_kb2 = (b_k2 * b_beta2[:, None]).to(b_k2.dtype)\n b_Aw += tl.dot(b_kb, tl.trans(b_k))\n b_Aw2 += tl.dot(b_kb2, tl.trans(b_k2))\n b_Aw3 += tl.dot(b_kb2, tl.trans(b_k))\n b_Aw = -tl.where(tl.arange(0, BC)[:, None] > tl.arange(0, BC)[None, :],\n b_Aw, 0)\n b_Aw2 = -tl.where(tl.arange(0, BC)[:, None] > tl.arange(0, BC)[None, :],\n b_Aw2, 0)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BC,\n ), (0,))\n p_g2 = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT + BC,),\n (BC,), (0,))\n else:\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BC,), (0,))\n p_g2 = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT +\n BC,), (BC,), (0,))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_g2 = tl.load(p_g2, boundary_check=(0,))\n b_Au = b_Aw * tl.exp(b_g[:, None] - b_g[None, :])\n b_Au2 = b_Aw2 * tl.exp(b_g2[:, None] - b_g2[None, :])\n b_Au3 = b_Aw3 * tl.exp(b_g2[:, None] - b_g[None, :])\n for i in range(1, BC):\n mask = tl.arange(0, BC) == i\n b_aw = tl.sum(tl.where(mask[:, None], b_Aw, 0), 0)\n b_aw2 = tl.sum(tl.where(mask[:, None], b_Aw2, 0), 0)\n b_au = tl.sum(tl.where(mask[:, None], b_Au, 0), 0)\n b_au2 = tl.sum(tl.where(mask[:, None], b_Au2, 0), 0)\n b_aw = b_aw + tl.sum(b_aw[:, None] * b_Aw, 0) * (tl.arange(0, BC) < i)\n b_aw2 = b_aw2 + tl.sum(b_aw2[:, None] * b_Aw2, 0) * (tl.arange(0,\n BC) < i)\n b_au = b_au + tl.sum(b_au[:, None] * b_Au, 0) * (tl.arange(0, BC) < i)\n b_au2 = b_au2 + tl.sum(b_au2[:, None] * b_Au2, 0) * (tl.arange(0,\n BC) < i)\n b_Aw = tl.where(mask[:, None], b_aw, b_Aw)\n b_Aw2 = tl.where(mask[:, None], b_aw2, b_Aw2)\n b_Au = tl.where(mask[:, None], b_au, b_Au)\n b_Au2 = tl.where(mask[:, None], b_au2, b_Au2)\n b_Aw += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_Aw2 += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_Aw3 = -tl.dot(tl.dot(b_Aw2, b_Aw3, allow_tf32=False), b_Aw,\n allow_tf32=False)\n b_Au += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_Au2 += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_Au3 = -tl.dot(tl.dot(b_Au2, b_Au3, allow_tf32=False), b_Au,\n allow_tf32=False)\n if HEAD_FIRST:\n p_Aw1 = tl.make_block_ptr(Aw + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT, 0), (BC, BC), (1, 0))\n p_Aw2 = tl.make_block_ptr(Aw + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT + BC, BC), (BC, BC), (1, 0))\n p_Aw3 = tl.make_block_ptr(Aw + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT + BC, 0), (BC, BC), (1, 0))\n p_Aw4 = tl.make_block_ptr(Aw + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT, BC), (BC, BC), (1, 0))\n p_Au1 = tl.make_block_ptr(Au + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT, 0), (BC, BC), (1, 0))\n p_Au2 = tl.make_block_ptr(Au + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT + BC, BC), (BC, BC), (1, 0))\n p_Au3 = tl.make_block_ptr(Au + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT + BC, 0), (BC, BC), (1, 0))\n p_Au4 = tl.make_block_ptr(Au + i_bh * T * BT, (T, BT), (BT, 1), (\n i_t * BT, BC), (BC, BC), (1, 0))\n else:\n p_Aw1 = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BC, BC), (1, 0))\n p_Aw2 = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT + BC, BC), (BC, BC), (1, 0))\n p_Aw3 = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT + BC, 0), (BC, BC), (1, 0))\n p_Aw4 = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, BC), (BC, BC), (1, 0))\n p_Au1 = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BC, BC), (1, 0))\n p_Au2 = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT + BC, BC), (BC, BC), (1, 0))\n p_Au3 = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT + BC, 0), (BC, BC), (1, 0))\n p_Au4 = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, BC), (BC, BC), (1, 0))\n tl.store(p_Aw1, b_Aw.to(p_Aw1.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Aw2, b_Aw2.to(p_Aw2.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Aw3, b_Aw3.to(p_Aw3.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Aw4, tl.zeros([BC, BC], dtype=tl.float32).to(p_Aw4.dtype.\n element_ty), boundary_check=(0, 1))\n tl.store(p_Au1, b_Au.to(p_Au1.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Au2, b_Au2.to(p_Au2.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Au3, b_Au3.to(p_Au3.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Au4, tl.zeros([BC, BC], dtype=tl.float32).to(p_Au4.dtype.\n element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Quantization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/wy_fast.py" }, { "uuid": "382c7df7-c231-4082-9738-316b2060d437", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef fused_recurrent_retention_fwd_kernel(q, k, v, o, h0, ht, offsets, scale,\n B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, REVERSE: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n b_b = 1 - tl.math.exp2(-5 - i_h * 1.0)\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n p_o = o + (i_k * B * H + i_nh) * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_o = o + (i_k * all + bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n mask_h = mask_k[None, :] & mask_v[:, None]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_h = b_b * b_h + b_k[None, :] * b_v[:, None]\n b_o = b_h * b_q[None, :]\n b_o = tl.sum(b_o, axis=1)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), mask=mask_v)\n p_q += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_k += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_o += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n if STORE_FINAL_STATE:\n p_ht = ht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/fused_recurrent.py" }, { "uuid": "cdef9924-80d7-4787-9792-40f7c0314224", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_third_order_fwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, sh_1_0_ptr: tl.tensor, sh_1_1_ptr: tl.tensor, sh_1_2_ptr: tl.\n tensor, sh_2_0_ptr: tl.tensor, sh_2_1_ptr: tl.tensor, sh_2_2_ptr: tl.\n tensor, sh_2_3_ptr: tl.tensor, sh_2_4_ptr: tl.tensor, sh_3_0_ptr: tl.\n tensor, sh_3_1_ptr: tl.tensor, sh_3_2_ptr: tl.tensor, sh_3_3_ptr: tl.\n tensor, sh_3_4_ptr: tl.tensor, sh_3_5_ptr: tl.tensor, sh_3_6_ptr: tl.\n tensor, BLOCK_SIZE: tl.constexpr, vector_length: tl.constexpr):\n sqrt_3 = 3 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n sh_1_0 = x * sqrt_3\n sh_1_1 = y * sqrt_3\n sh_1_2 = z * sqrt_3\n sqrt_15 = 15 ** 0.5\n sqrt_5 = 5 ** 0.5\n sq_x = x * x\n sq_y = y * y\n sq_z = z * z\n sh_2_0 = sqrt_15 * x * z\n sh_2_1 = sqrt_15 * x * y\n sh_2_2 = sqrt_5 * (sq_y - 0.5 * (sq_x + sq_z))\n sh_2_3 = sqrt_15 * y * z\n sh_2_4 = 0.5 * sqrt_15 * (sq_z - sq_x)\n sqrt_42 = 42 ** 0.5\n sqrt_168 = 168 ** 0.5\n sqrt_7 = 7 ** 0.5\n sh_3_0 = 1 / 6 * sqrt_42 * (sh_2_0 * z + sh_2_4 * x)\n sh_3_1 = sqrt_7 * sh_2_0 * y\n sh_3_2 = 1 / 8 * sqrt_168 * (4 * sq_y - (sq_x + sq_z)) * x\n sh_3_3 = 0.5 * sqrt_7 * y * (2 * sq_y - 3 * (sq_x + sq_z))\n sh_3_4 = 1 / 8 * sqrt_168 * z * (4 * sq_y - (sq_x + sq_z))\n sh_3_5 = sqrt_7 * (sh_2_4 * y)\n sh_3_6 = 1 / 6 * sqrt_42 * (sh_2_4 * z - sh_2_0 * x)\n sh_1_0_start = sh_1_0_ptr + offset\n sh_1_1_start = sh_1_1_ptr + offset\n sh_1_2_start = sh_1_2_ptr + offset\n sh_2_0_start = sh_2_0_ptr + offset\n sh_2_1_start = sh_2_1_ptr + offset\n sh_2_2_start = sh_2_2_ptr + offset\n sh_2_3_start = sh_2_3_ptr + offset\n sh_2_4_start = sh_2_4_ptr + offset\n sh_3_0_start = sh_3_0_ptr + offset\n sh_3_1_start = sh_3_1_ptr + offset\n sh_3_2_start = sh_3_2_ptr + offset\n sh_3_3_start = sh_3_3_ptr + offset\n sh_3_4_start = sh_3_4_ptr + offset\n sh_3_5_start = sh_3_5_ptr + offset\n sh_3_6_start = sh_3_6_ptr + offset\n tl.store(sh_1_0_start, sh_1_0, mask=offset < vector_length)\n tl.store(sh_1_1_start, sh_1_1, mask=offset < vector_length)\n tl.store(sh_1_2_start, sh_1_2, mask=offset < vector_length)\n tl.store(sh_2_0_start, sh_2_0, mask=offset < vector_length)\n tl.store(sh_2_1_start, sh_2_1, mask=offset < vector_length)\n tl.store(sh_2_2_start, sh_2_2, mask=offset < vector_length)\n tl.store(sh_2_3_start, sh_2_3, mask=offset < vector_length)\n tl.store(sh_2_4_start, sh_2_4, mask=offset < vector_length)\n tl.store(sh_3_0_start, sh_3_0, mask=offset < vector_length)\n tl.store(sh_3_1_start, sh_3_1, mask=offset < vector_length)\n tl.store(sh_3_2_start, sh_3_2, mask=offset < vector_length)\n tl.store(sh_3_3_start, sh_3_3, mask=offset < vector_length)\n tl.store(sh_3_4_start, sh_3_4, mask=offset < vector_length)\n tl.store(sh_3_5_start, sh_3_5, mask=offset < vector_length)\n tl.store(sh_3_6_start, sh_3_6, mask=offset < vector_length)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "8a07eb48-f388-411a-8bea-4db66f7e583a", "file_name": "test_triton.py", "repo_name": "pytorch/xla", "file_path": "test/test_triton.py", "commit_hash": "40efdb7b6571ce92797b5ba42619b79c1b147b3e", "starcount": 0, "input": "@triton.jit\ndef add_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n x = tl.load(x_ptr + offsets, mask=mask)\n y = tl.load(y_ptr + offsets, mask=mask)\n output = x + y\n tl.store(output_ptr + offsets, output, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch/xla/blob/40efdb7b6571ce92797b5ba42619b79c1b147b3e/test/test_triton.py" }, { "uuid": "73d4eb91-5118-44b5-a7cc-d60243dd1659", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gsa/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_gsa_inference_kernel(q, k, v, s, g, o, hk0, hv0, hkt,\n hvt, scale, K: tl.constexpr, V: tl.constexpr, M: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, NG: tl.constexpr):\n i_bh = tl.program_id(0)\n i_bg = i_bh // NG\n b_s = tl.load(s + i_bg * M + tl.arange(0, M)).to(tl.float32)\n b_g = tl.load(g + i_bg * M + tl.arange(0, M)).to(tl.float32)\n b_g = tl.exp(b_g)\n b_ok = tl.zeros([M], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n o_k = i_k * BK + tl.arange(0, BK)\n p_hk0 = hk0 + i_bg * K * M + o_k[None, :] * M + tl.arange(0, M)[:, None\n ]\n mask_k = o_k < K\n mask_hk = (tl.arange(0, M) < M)[:, None] & mask_k[None, :]\n b_hk = tl.load(p_hk0, mask=mask_hk, other=0.0).to(tl.float32)\n b_q = tl.load(q + i_bh * K + o_k, mask=mask_k, other=0.0).to(tl.float32\n ) * scale\n b_k = tl.load(k + i_bg * K + o_k, mask=mask_k, other=0.0).to(tl.float32\n )\n b_hk = b_hk * b_g[:, None] + b_k[None, :] * b_s[:, None]\n b_ok += tl.sum(b_hk * b_q[None, :], axis=1)\n if i_bh % NG == 0:\n p_hkt = hkt + i_bg * K * M + o_k[None, :] * M + tl.arange(0, M)[\n :, None]\n tl.store(p_hkt, b_hk.to(p_hkt.dtype.element_ty), mask=mask_hk)\n b_qv = tl.softmax(b_ok)\n for i_v in range(tl.cdiv(V, BV)):\n o_v = i_v * BV + tl.arange(0, BV)\n p_hv0 = hv0 + i_bg * M * V + tl.arange(0, M)[None, :] * V + o_v[:, None\n ]\n mask_v = o_v < V\n mask_hv = mask_v[:, None] & (tl.arange(0, M) < M)[None, :]\n b_hv = tl.load(p_hv0, mask=mask_hv, other=0).to(tl.float32)\n b_v = tl.load(v + i_bg * V + o_v, mask=mask_v, other=0).to(tl.float32)\n b_hv = b_hv * b_g[None, :] + b_s[None, :] * b_v[:, None]\n b_ov = tl.sum(b_hv * b_qv[None, :], axis=1)\n tl.store(o + i_bh * V + o_v, b_ov.to(o.dtype.element_ty), mask=mask_v)\n if i_bh % NG == 0:\n p_hvt = hvt + i_bg * M * V + tl.arange(0, M)[None, :] * V + o_v[\n :, None]\n tl.store(p_hvt, b_hv.to(p_hvt.dtype.element_ty), mask=mask_hv)\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gsa/fused_recurrent.py" }, { "uuid": "d007ef85-87e3-4ce0-8e46-7b94cff34ce5", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(list(filter(keep, configsOpt)), key=['N_CTX'])\n@triton.jit\ndef _attn_fwd_opt(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v, desc_o,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.constexpr, STAGE: tl.\n constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE: tl.constexpr,\n ENABLE_WS: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n pid = tl.program_id(0)\n off_hz = tl.program_id(1)\n _attn_fwd_compute(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid,\n Z, H, N_CTX, BLOCK_M, BLOCK_N, HEAD_DIM, STAGE, ENABLE_TMA,\n LOOP_SCHEDULE)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "858e4bb7-3ed2-490f-84f5-a9677c3f962b", "file_name": "lstm_fw.py", "repo_name": "NX-AI/flashrnn", "file_path": "flashrnn/flashrnn/triton_fused/lstm_fw.py", "commit_hash": "3fca666a81c8740af4878d7bc5e2a51900e4fe14", "starcount": 0, "input": "@triton.autotune(configs, key=['siz_B', 'T', 'B', 'NH', 'DH'])\n@triton.jit\ndef _forward_sequence_kernel(states_initial, Wx, R, b, states_all,\n gates_all, T: tl.constexpr, NS: tl.constexpr, B: tl.constexpr, NH: tl.\n constexpr, DH: tl.constexpr, NGI: tl.constexpr, NGR: tl.constexpr,\n siz_B: tl.constexpr, OUTPUT_GATES: tl.constexpr, DTYPE: tl.constexpr=tl\n .float32):\n idx_b_NH, idx_b_B = tl.program_id(0), tl.program_id(1)\n str_matWx_NH = T * NGI * B * DH\n str_matWx_T = NGI * B * DH\n str_matStatesAll_NH = (T + 1) * NS * B * DH\n str_matStatesAll_T = NS * B * DH\n str_matGatesAll_NH = T * NGI * B * DH\n str_matGatesAll_T = NGI * B * DH\n matHtrans_initial_ptr = tl.make_block_ptr(base=states_initial + \n idx_b_NH * NS * B * DH + 0 * B * DH, shape=(B, DH), strides=(DH, 1),\n offsets=(idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n matHtrans = tl.load(matHtrans_initial_ptr).to(tl.float32)\n matCtrans_initial_ptr = tl.make_block_ptr(base=states_initial + \n idx_b_NH * NS * B * DH + 1 * B * DH, shape=(B, DH), strides=(DH, 1),\n offsets=(idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n matCtrans = tl.load(matCtrans_initial_ptr).to(tl.float32)\n matHtrans_initial_store_ptr = tl.make_block_ptr(base=states_all + \n idx_b_NH * str_matStatesAll_NH + 0 * str_matStatesAll_T + 0 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matHtrans_initial_store_ptr, matHtrans.to(DTYPE))\n matCtrans_initial_store_ptr = tl.make_block_ptr(base=states_all + \n idx_b_NH * str_matStatesAll_NH + 0 * str_matStatesAll_T + 1 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0),\n block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matCtrans_initial_store_ptr, matCtrans.to(DTYPE))\n matRtrans_i_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 0 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_i = tl.load(matRtrans_i_ptr)\n matRtrans_f_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 1 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_f = tl.load(matRtrans_f_ptr)\n matRtrans_z_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 2 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_z = tl.load(matRtrans_z_ptr)\n matRtrans_o_ptr = tl.make_block_ptr(base=R + idx_b_NH * DH * NGR * DH +\n 3 * DH * DH, shape=(DH, DH), strides=(DH, 1), offsets=(0, 0),\n block_shape=(DH, DH), order=(0, 1))\n matRtrans_o = tl.load(matRtrans_o_ptr)\n vecB_i_ptr = b + idx_b_NH * NGI * DH + 0 * DH + tl.arange(0, DH)\n vecB_i = tl.load(vecB_i_ptr)\n vecB_f_ptr = b + idx_b_NH * NGI * DH + 1 * DH + tl.arange(0, DH)\n vecB_f = tl.load(vecB_f_ptr)\n vecB_z_ptr = b + idx_b_NH * NGI * DH + 2 * DH + tl.arange(0, DH)\n vecB_z = tl.load(vecB_z_ptr)\n vecB_o_ptr = b + idx_b_NH * NGI * DH + 3 * DH + tl.arange(0, DH)\n vecB_o = tl.load(vecB_o_ptr)\n for idx_t in range(T):\n matIxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 0 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matIxtrans = tl.load(matIxtrans_ptr)\n matFxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 1 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matFxtrans = tl.load(matFxtrans_ptr)\n matZxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 2 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matZxtrans = tl.load(matZxtrans_ptr)\n matOxtrans_ptr = tl.make_block_ptr(base=Wx + idx_b_NH *\n str_matWx_NH + idx_t * str_matWx_T + 3 * B * DH, shape=(B, DH),\n strides=(DH, 1), offsets=(idx_b_B * siz_B, 0), block_shape=(\n siz_B, DH), order=(0, 1))\n matOxtrans = tl.load(matOxtrans_ptr)\n matRhtrans_i = tl.dot(matHtrans.to(DTYPE), matRtrans_i)\n matRhtrans_f = tl.dot(matHtrans.to(DTYPE), matRtrans_f)\n matRhtrans_z = tl.dot(matHtrans.to(DTYPE), matRtrans_z)\n matRhtrans_o = tl.dot(matHtrans.to(DTYPE), matRtrans_o)\n matIbar = matIxtrans + matRhtrans_i + vecB_i[None, :]\n matFbar = matFxtrans + matRhtrans_f + vecB_f[None, :]\n matZbar = matZxtrans + matRhtrans_z + vecB_z[None, :]\n matObar = matOxtrans + matRhtrans_o + vecB_o[None, :]\n matI = tl.sigmoid(matIbar)\n matF = tl.sigmoid(matFbar)\n matZ = triton_tanh(matZbar)\n matO = tl.sigmoid(matObar)\n matCtrans_next = matF * matCtrans + matI * matZ\n matHtrans_next = matO * triton_tanh(matCtrans_next)\n matHtrans_next_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 0 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matHtrans_next_ptr, matHtrans_next.to(DTYPE))\n matCtrans_next_ptr = tl.make_block_ptr(base=states_all + idx_b_NH *\n str_matStatesAll_NH + (idx_t + 1) * str_matStatesAll_T + 1 * B *\n DH, shape=(B, DH), strides=(DH, 1), offsets=(idx_b_B * siz_B, 0\n ), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matCtrans_next_ptr, matCtrans_next.to(DTYPE))\n if OUTPUT_GATES:\n matGatesItrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 0 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesItrans_ptr, matI.to(DTYPE))\n matGatesFtrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 1 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesFtrans_ptr, matF.to(DTYPE))\n matGatesZtrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 2 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesZtrans_ptr, matZ.to(DTYPE))\n matGatesOtrans_ptr = tl.make_block_ptr(base=gates_all + \n idx_b_NH * str_matGatesAll_NH + idx_t * str_matGatesAll_T +\n 3 * B * DH, shape=(B, DH), strides=(DH, 1), offsets=(\n idx_b_B * siz_B, 0), block_shape=(siz_B, DH), order=(0, 1))\n tl.store(matGatesOtrans_ptr, matO.to(DTYPE))\n matCtrans = matCtrans_next\n matHtrans = matHtrans_next\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Batch-Oriented" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT", "BSD" ], "github_url": "https://github.com/NX-AI/flashrnn/blob/3fca666a81c8740af4878d7bc5e2a51900e4fe14/flashrnn/flashrnn/triton_fused/lstm_fw.py" }, { "uuid": "87908dfa-3000-45a4-bd58-e284ba835528", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=[Config({'BLOCK_SIZE': 512}), Config({'BLOCK_SIZE':\n 1024}), Config({'BLOCK_SIZE': 2048}), Config({'BLOCK_SIZE': 4096}),\n Config({'BLOCK_SIZE': 8192})], key=['K'])\n@triton.jit\ndef _kernel_quantize_fp8_row(A, A_scale, A_fp8, scale_ub, B, M, N, K,\n stride_ab, stride_am, stride_an, stride_ak, stride_ob, stride_om,\n stride_on, stride_ok, TL_FP8_DTYPE: tl.constexpr, MAX_FP8: tl.constexpr,\n EPS: tl.constexpr, CLAMP_MAX: tl.constexpr, BLOCK_SIZE: tl.constexpr,\n USE_INT64: tl.constexpr) ->None:\n \"\"\"Quantize and scale each row.\n\n Scale per row i is computed as MAX_FP8 / max(abs(A[i, :]))\n\n Kernel naively iterates through matrix with [1, BLOCK_SIZE] tiles\n in a max pass then scale/quantize pass.\n\n Todo:\n * Better tiling schemes.\n\n Args:\n A (Tensor): higher precision input tensor of 4 dimension.\n A_scale (Tensor): [B * M * N] reciprocal scale tensor per row.\n A_fp8 (Tensor): fp8 scaled tensor. A_fp8 = A / a_scale\n scale_ub (Tensor): [1] Maximum value allowed for scale.\n B (int): Size of dimenion 0\n M (int): Size of dimenion 1\n N (int): Size of dimenion 2\n K (int): Size of dimenion 3\n stride_ab (int): Stride of b dimension of A.\n stride_am (int): Stride of m dimension of A.\n stride_an (int): Stride of n dimension of A.\n stride_ak (int): Stride of k dimension of A.\n stride_ob (int): Stride of b dimension of output.\n stride_om (int): Stride of m dimension of output.\n stride_on (int): Stride of n dimension of output.\n stride_ok (int): Stride of k dimension of output.\n TL_FP8_DTYPE (tl.dtype): Target fp8 datatype.\n MAX_FP8 (float): Maxmimum expressible value for FP8.\n EPS (float): Epsilon value for numerical stability.\n CLAMP_MAX (bool): Whethar to apply scale_ub.\n BLOCK_SIZE (int): Block size for reduction.\n USE_INT64 (bool): Whether to use int64 indexing for large inputs.\n \"\"\"\n pid = tl.program_id(0)\n if USE_INT64:\n pid = pid.to(tl.int64)\n n_offset = tl.arange(0, BLOCK_SIZE)\n a_offset_base = pid // (M * N) * stride_ab + pid % (M * N\n ) // N * stride_am + pid % (M * N) % N * stride_an\n a_fp8_offset_base = pid // (M * N) * stride_ob + pid % (M * N\n ) // N * stride_om + pid % (M * N) % N * stride_on\n cur_max = 0.0\n for _k in range(0, tl.cdiv(K, BLOCK_SIZE)):\n a = tl.load(A + a_offset_base + n_offset * stride_ak, mask=n_offset <\n K, other=0.0)\n tile_max = tl.max(tl.abs(a))\n cur_max = tl.maximum(tile_max, cur_max)\n n_offset += BLOCK_SIZE\n if CLAMP_MAX:\n ub = tl.load(scale_ub)\n cur_max = tl.clamp(cur_max, EPS, ub)\n else:\n cur_max = tl.maximum(cur_max, EPS)\n a_scale = MAX_FP8 / cur_max\n tl.store(A_scale + pid, 1.0 / a_scale)\n n_offset = tl.arange(0, BLOCK_SIZE)\n for _k in range(0, tl.cdiv(K, BLOCK_SIZE)):\n a = tl.load(A + a_offset_base + n_offset * stride_ak, mask=n_offset <\n K, other=0.0)\n a_fp8 = a * a_scale\n a_fp8 = tl.clamp(a_fp8, -MAX_FP8, MAX_FP8)\n a_fp8.to(TL_FP8_DTYPE)\n tl.store(A_fp8 + a_fp8_offset_base + n_offset * stride_ok, a_fp8,\n mask=n_offset < K)\n n_offset += BLOCK_SIZE\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "f4315a08-a5f0-461d-8704-8c3177daca71", "file_name": "attn_qk_int8_per_block_hd128_causal.py", "repo_name": "rodjjo/editorium", "file_path": "editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_hd128_causal.py", "commit_hash": "7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd(Q, K, V, Q_scale, K_scale, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, Z, H, N_CTX, HEAD_DIM: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, STAGE: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n off_z = off_hz // H\n off_h = off_hz % H\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n vk_offset = qvk_offset // stride_qm\n q_scale_offset = off_hz * tl.cdiv(N_CTX, BLOCK_M)\n k_scale_offset = off_hz * tl.cdiv(N_CTX, BLOCK_N)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_k = tl.arange(0, HEAD_DIM)\n Q_ptrs = Q + qvk_offset + offs_m[:, None] * stride_qm + offs_k[None, :\n ] * stride_qk\n Q_scale_ptr = Q_scale + q_scale_offset + start_m\n K_ptrs = K + qvk_offset + offs_k[:, None] + offs_n[None, :] * stride_kn\n K_scale_ptr = K_scale + k_scale_offset\n V_ptrs = V + qvk_offset + offs_n[:, None] * stride_qm + offs_k[None, :\n ] * stride_qk\n O_block_ptr = Out + qvk_offset + offs_m[:, None] * stride_qm + offs_k[\n None, :] * stride_qk\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, HEAD_DIM], dtype=tl.float32)\n q = tl.load(Q_ptrs, mask=offs_m[:, None] < N_CTX)\n q_scale = tl.load(Q_scale_ptr)\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, q_scale, K_ptrs,\n K_scale_ptr, V_ptrs, start_m, BLOCK_M, HEAD_DIM, BLOCK_N, 4 - STAGE,\n offs_m, offs_n, N_CTX)\n acc, l_i, _ = _attn_fwd_inner(acc, l_i, m_i, q, q_scale, K_ptrs,\n K_scale_ptr, V_ptrs, start_m, BLOCK_M, HEAD_DIM, BLOCK_N, 2, offs_m,\n offs_n, N_CTX)\n acc = acc / l_i[:, None]\n tl.store(O_block_ptr, acc.to(Out.type.element_ty), mask=offs_m[:, None] <\n N_CTX)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/rodjjo/editorium/blob/7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694/editorium/app/server/pipelines/cogvideo/sageattention/attn_qk_int8_per_block_hd128_causal.py" }, { "uuid": "c29a2e86-f522-4cb9-9e23-8953c5a58d34", "file_name": "GELUglu.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/GELUglu.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _gelu_glu_bwd_kernel_(grad_output_ptr, grad_input_ptr, input_ptr,\n grad_output_row_stride, grad_input_row_stride, input_row_stride,\n grad_output_col_stride, grad_input_col_stride, input_col_stride, n_rows,\n n_cols, BLOCK_SIZE: tl.constexpr):\n col_idx = tl.program_id(0)\n row_idx = tl.arange(0, BLOCK_SIZE)\n grad_output = tl.load(grad_output_ptr + row_idx *\n grad_output_row_stride + col_idx * grad_output_col_stride, mask=tl.\n arange(0, BLOCK_SIZE) < n_rows, other=-float('inf'))\n x = tl.load(input_ptr + row_idx * input_row_stride + col_idx *\n input_col_stride, mask=tl.arange(0, BLOCK_SIZE) < n_rows, other=-\n float('inf'))\n gate = tl.load(input_ptr + row_idx * input_row_stride + (col_idx + \n n_cols // 2) * input_col_stride, mask=tl.arange(0, BLOCK_SIZE) <\n n_rows, other=-float('inf'))\n gate_cube = gate * gate * gate\n beta = 0.7978845608028654\n kappa = 0.044715\n inner = beta * (gate + kappa * gate_cube)\n inner_tanh = tanh(inner)\n gate_gelu = 0.5 * gate * (inner_tanh + 1)\n grad_x = grad_output * gate_gelu\n grad_gelu = grad_output * x\n grad_gate = grad_gelu * (0.5 * (1 + inner_tanh) + 0.5 * gate * (1 - \n inner_tanh * inner_tanh) * beta * (1 + kappa * 3 * gate * gate))\n tl.store(grad_input_ptr + row_idx * grad_input_row_stride + col_idx *\n grad_input_col_stride, grad_x, mask=tl.arange(0, BLOCK_SIZE) < n_rows)\n tl.store(grad_input_ptr + row_idx * grad_input_row_stride + (col_idx + \n n_cols // 2) * grad_input_col_stride, grad_gate, mask=tl.arange(0,\n BLOCK_SIZE) < n_rows)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/GELUglu.py" }, { "uuid": "aed16229-3b7a-4b1c-8e82-17e1c95bb947", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef triton_dense_to_jagged(jagged_value_ptr, jagged_offsets_ptr,\n jagged_value_row_stride: int, output_dense_ptr, dense_indices_ptr,\n dense_col_stride, dense_row_stride: int, dense_matrix_stride,\n JAGGED_DIM: tl.constexpr, thread_block_row_size: tl.constexpr,\n thread_block_col_size: tl.constexpr, operation_function: tl.constexpr,\n operation_jagged_value_ptr) ->None:\n pid = tl.program_id(0)\n begin = tl.load(jagged_offsets_ptr + pid)\n end = tl.load(jagged_offsets_ptr + (pid + 1))\n N = jagged_value_row_stride\n M = end - begin\n dense_boundary_col = dense_row_stride\n if N < dense_row_stride:\n dense_boundary_col = N\n dense_boundary_row = tl.minimum(dense_matrix_stride // dense_row_stride, M)\n jagged_value_ptr += begin * jagged_value_row_stride\n if JAGGED_DIM > 2:\n dense_indice = tl.load(dense_indices_ptr + pid)\n if dense_indice == -1:\n dense_boundary_col = -1\n else:\n output_dense_ptr += dense_indice\n else:\n output_dense_ptr += pid * dense_matrix_stride\n if operation_function is not None:\n operation_jagged_value_ptr += begin * jagged_value_row_stride\n offset_row = tl.arange(0, thread_block_row_size)\n for _i in range(begin, end, thread_block_row_size):\n offset_col = tl.arange(0, thread_block_col_size)\n block_offset = offset_row[:, None] * dense_row_stride + offset_col[\n None, :] * dense_col_stride\n for _j in range(0, N, thread_block_col_size):\n dense_mask = (offset_row[:, None] < dense_boundary_row) & (\n offset_col[None, :] < dense_boundary_col)\n jagged_mask = (offset_row[:, None] < M) & (offset_col[None, :] < N)\n dense_values = tl.load(output_dense_ptr + block_offset, mask=\n dense_mask, other=0)\n if operation_function is not None:\n operation_jagged_value = tl.load(operation_jagged_value_ptr +\n block_offset, mask=jagged_mask, other=0)\n if operation_function == 'add':\n dense_values = tensor_elementwise_add(dense_values,\n operation_jagged_value)\n else:\n dense_values = tensor_elementwise_mul(dense_values,\n operation_jagged_value)\n tl.store(jagged_value_ptr + block_offset, dense_values, mask=\n jagged_mask)\n offset_col += thread_block_col_size\n block_offset += thread_block_col_size\n offset_row += thread_block_row_size\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "935a82ae-0233-49d1-bc2a-756762601b08", "file_name": "triton_implicit_gemm.py", "repo_name": "l1351868270/implicit_gemm.triton", "file_path": "triton_implicit_gemm.py", "commit_hash": "64eb8548ccf4576883c928f6315be8b24680a455", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['N', 'C', 'H', 'W',\n 'K', 'P', 'Q', 'R', 'S', 'U', 'V', 'pad_h', 'pad_w', 'dila_h', 'dila_w'])\n@triton.jit\ndef conv2d_kernel(x_ptr, w_ptr, y_ptr, N, C, H, W, K, P, Q, R, S, U, V,\n pad_h, pad_w, dila_h, dila_w, GEMM_M, GEMM_N, GEMM_K, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(GEMM_M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(GEMM_N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n gemm_i = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % GEMM_M\n gemm_j = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % GEMM_N\n n = gemm_i // (P * Q)\n npq_residual = gemm_i % (P * Q)\n p = npq_residual // Q\n q = npq_residual % Q\n k = gemm_j\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for idx_k in range(0, tl.cdiv(GEMM_K, BLOCK_SIZE_K)):\n gemm_k = idx_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n r = gemm_k // (S * C)\n rsc_residual = gemm_k % (S * C)\n s = rsc_residual // C\n c = rsc_residual % C\n h = p[:, None] * U + r[None, :] * dila_h - pad_h\n w = q[:, None] * V + s[None, :] * dila_w - pad_w\n mask_x = (h >= 0) & (h < H) & (w >= 0) & (w < W)\n mask_w = (r < R) & (s < S) & (c < C)\n offs_x = n[:, None] * H * W * C + h * W * C + w * C + c\n offs_w = k[None, :] * R * S * C + r[:, None] * S * C + s[:, None\n ] * C + c[:, None]\n x_ptrs = x_ptr + offs_x\n w_ptrs = w_ptr + offs_w\n x_data = tl.load(x_ptrs, mask=mask_x, other=0.0)\n w_data = tl.load(w_ptrs, mask=mask_w[:, None], other=0.0)\n accumulator = tl.dot(x_data, w_data, accumulator)\n c_data = accumulator.to(tl.float16)\n offs_y = gemm_i[:, None] * GEMM_N + gemm_j[None, :]\n mask_y = (gemm_i[:, None] < GEMM_M) & (gemm_j[None, :] < GEMM_N)\n y_ptrs = y_ptr + offs_y\n tl.store(y_ptrs, c_data, mask=mask_y)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/l1351868270/implicit_gemm.triton/blob/64eb8548ccf4576883c928f6315be8b24680a455/triton_implicit_gemm.py" }, { "uuid": "cd190af4-66fc-4636-9bc4-2a8357d80887", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef causal_alibi_mask(slope, offs_m, offs_n, M, N, EVEN_M: tl.constexpr,\n EVEN_N: tl.constexpr):\n shift = N - M\n alibi = (offs_n[None, :] - offs_m[:, None] - shift) * slope\n mask = alibi <= 0\n if not EVEN_M & EVEN_N:\n mask = mask & make_bounds(offs_m, offs_n, M, N, EVEN_M, EVEN_N)\n return tl.where(mask, alibi, float('-inf'))\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "0a360c43-f9f2-46b3-bcbc-051ade3b0924", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_compute(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid, Z,\n H, N_CTX, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.\n constexpr, STAGE: tl.constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE:\n tl.constexpr):\n start_m = pid\n off_z = off_hz // H\n off_h = off_hz % H\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n K_block_ptr = None\n V_block_ptr = None\n Q_block_ptr = None\n O_block_ptr = None\n if not ENABLE_TMA:\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, HEAD_DIM), order=(1, 0))\n v_order: tl.constexpr = (0, 1\n ) if V.dtype.element_ty == tl.float8e5 else (1, 0)\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, HEAD_DIM), order=v_order)\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(\n HEAD_DIM, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(HEAD_DIM, BLOCK_N), order=(0, 1))\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, HEAD_DIM), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, HEAD_DIM], dtype=tl.float32)\n qk_scale = sm_scale\n qk_scale *= 1.44269504\n if ENABLE_TMA:\n q = tl._experimental_descriptor_load(desc_q, [(qvk_offset //\n stride_qm + start_m * BLOCK_M).to(tl.int32), 0], [BLOCK_M,\n HEAD_DIM], Q.dtype.element_ty)\n else:\n q = tl.load(Q_block_ptr)\n if STAGE & 1:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, desc_k, desc_v, Q, qvk_offset, stride_kn,\n stride_vn, stride_vk, start_m, qk_scale, BLOCK_M, HEAD_DIM,\n BLOCK_N, 4 - STAGE, offs_m, offs_n, N_CTX, V.dtype.element_ty ==\n tl.float8e5, ENABLE_TMA, LOOP_SCHEDULE)\n if STAGE & 2:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, desc_k, desc_v, Q, qvk_offset, stride_kn,\n stride_vn, stride_vk, start_m, qk_scale, BLOCK_M, HEAD_DIM,\n BLOCK_N, 2, offs_m, offs_n, N_CTX, V.dtype.element_ty == tl.\n float8e5, ENABLE_TMA, LOOP_SCHEDULE)\n m_i += tl.math.log2(l_i)\n acc = acc / l_i[:, None]\n m_ptrs = M + off_hz * N_CTX + offs_m\n tl.store(m_ptrs, m_i)\n if ENABLE_TMA:\n tl._experimental_descriptor_store(desc_o, acc.to(Out.type.\n element_ty), [(qvk_offset // stride_om + start_m * BLOCK_M).to(\n tl.int32), 0])\n else:\n tl.store(O_block_ptr, acc.to(Out.type.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "9ea4a729-2b49-4f30-a3b7-315143733125", "file_name": "quant_triton.py", "repo_name": "CompendiumLabs/ziggy", "file_path": "ziggy/backends/quant_triton.py", "commit_hash": "bd12fe50ca3475743f62ae26d4c184108e441e03", "starcount": 0, "input": "@triton.jit\ndef dequantize_kernel(X, Y, N, K, K1, scale, zero_point, BITS: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, BLOCK_SIZE_K1:\n tl.constexpr):\n dtype = Y.dtype.element_ty\n scale_ty = tl.full((), scale, dtype=dtype)\n zero_point_ty = tl.full((), zero_point, dtype=dtype)\n QFACT = 8 // BITS\n QMASK = (1 << BITS) - 1\n QMASK_INT = tl.full((), QMASK, dtype=tl.uint8)\n pid_n = tl.program_id(0)\n pid_k = tl.program_id(1)\n bk = tl.arange(0, BLOCK_SIZE_K)\n bk1, bq1 = bk // QFACT, bk % QFACT\n x_shift = BITS * bq1\n rn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n rk = pid_k * BLOCK_SIZE_K + bk\n rk1 = pid_k * BLOCK_SIZE_K1 + bk1\n mask_x = rn[:, None] < N\n mask_y = rn[:, None] < N\n X1 = X + (rn[:, None] * K1 + rk1[None, :])\n Y1 = Y + (rn[:, None] * K + rk[None, :])\n x = tl.load(X1, mask=mask_x)\n xi = x >> x_shift & QMASK_INT\n xf = scale_ty * (xi.to(dtype) - zero_point_ty)\n tl.store(Y1, xf, mask=mask_y)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "uint8" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/CompendiumLabs/ziggy/blob/bd12fe50ca3475743f62ae26d4c184108e441e03/ziggy/backends/quant_triton.py" }, { "uuid": "767c7fac-160a-4bf1-a459-648f00cc19be", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_h(k, v, z, h, h0, ht, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, s_h_h, s_h_t, s_h_d, T: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NT:\n tl.constexpr, NORMK: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n STORE_FINAL_STATE: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h = tl.make_block_ptr(h0 + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n if NORMK:\n p_z0 = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), (i_k *\n BK,), (BK,), (0,))\n else:\n p_z0 = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), (i_v *\n BV,), (BV,), (0,))\n b_zp = tl.load(p_z0).to(tl.float32)\n for i_t in range(NT):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, s_h_d), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n if NORMK:\n p_zc = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,),\n ((i_t * BT + BT - 1) * K + i_k * BK,), (BK,), (0,))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_r, b_zp = tl.exp(b_zp - b_zc), b_zc\n b_h = b_h * b_r[:, None]\n b_k = tl.exp(b_k - b_zc[:, None]).to(b_k.dtype)\n else:\n p_zc = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,),\n ((i_t * BT + BT - 1) * V + i_v * BV,), (BV,), (0,))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_r, b_zp = tl.exp(b_zp - b_zc), b_zc\n b_h = b_h * b_r[None, :]\n b_v = tl.exp(b_v - b_zc[None, :]).to(b_v.dtype)\n b_h += tl.dot(b_k, b_v, allow_tf32=False)\n if STORE_FINAL_STATE:\n p_h = tl.make_block_ptr(ht + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "b8c40fe7-a4c6-44cc-b7fe-36d33f96630e", "file_name": "ln_linear_triton_2.py", "repo_name": "ethansmith2000/fused-layer-norm", "file_path": "ln_linear_triton_2.py", "commit_hash": "84fe243a829364acdcfd7cd70b699db04838af0f", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_fwd_fused(X_ptr, W_ptr, B_ptr, Mean_ptr, RSTD_ptr, stride,\n n_cols, eps, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n X_ptr += row_idx * stride\n Mean_ptr += row_idx\n RSTD_ptr += row_idx\n X_row = tl.load(X_ptr + col_offsets, mask=mask, other=0)\n W_row = tl.load(W_ptr + col_offsets, mask=mask, other=0)\n B_row = tl.load(B_ptr + col_offsets, mask=mask, other=0)\n mean = tl.sum(X_row, axis=0) / n_cols\n demeaned = X_row - mean\n var = tl.sum(demeaned * demeaned, axis=0) / n_cols\n rstd = rsqrt(var + eps)\n tl.store(Mean_ptr, mean)\n tl.store(RSTD_ptr, rstd)\n Y_row = tl.fma(demeaned * rstd, W_row, B_row)\n tl.store(X_ptr + col_offsets, Y_row, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Batch-Oriented", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ethansmith2000/fused-layer-norm/blob/84fe243a829364acdcfd7cd70b699db04838af0f/ln_linear_triton_2.py" }, { "uuid": "fc3fd787-4ea0-4a55-9c09-59fdb3df32dd", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=MATMUL_CONFIGS_NON_PERSISTENT, key=['M', 'N', 'K'],\n prune_configs_by={'early_config_prune': prune_configs, 'perf_model':\n None, 'top_k': None}, use_cuda_graph=True)\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.jit\ndef _kernel_matmul_fp8_row_non_persistent(A, B, C, M, N, K, m_key, n_key,\n k_key, A_scale, B_scale, stride_am, stride_ak, stride_bn, stride_bk,\n stride_cm, stride_cn, dot_out_dtype: tl.constexpr, allow_tf32: tl.\n constexpr, fp8_fast_accum: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N:\n tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl\n .constexpr, EVEN_K: tl.constexpr, AB_DTYPE: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with row-wise scales\n\n performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles.\n\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n m_key (int): Autotuning key for M dimension of input tensor.\n n_key (int): Autotuning key for N dimension of input tensor.\n k_key (int): Autotuning key for K dimension of input tensor.\n A_scale (TensorWrapper): [M] reciprocal scale tensor per row. A * A_scale = original A\n B_scale (TensorWrapper): [N] reciprocal scale tensor per row. B * B_scale = original B\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n _0 = tl.zeros((1, 1), dtype=C.dtype.element_ty)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_0)\n b = tl.load(B, mask=rk[:, None] < k_remaining, other=_0)\n if AB_DTYPE:\n a = a.to(C.dtype.element_ty)\n b = b.to(C.dtype.element_ty)\n if fp8_fast_accum:\n acc = tl.dot(a, b, acc, out_dtype=dot_out_dtype, allow_tf32=\n allow_tf32)\n else:\n acc += tl.dot(a, b, out_dtype=dot_out_dtype, allow_tf32=allow_tf32)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n a_scale = tl.load(A_scale + rm, mask=rm < M)\n b_scale = tl.load(B_scale + rn, mask=rn < N)\n scale = a_scale[:, None] * b_scale[None, :]\n acc *= scale\n acc = acc.to(C.dtype.element_ty)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if SPLIT_K == 1:\n tl.store(C, acc, mask=mask)\n else:\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "1831f041-03a2-4e24-a2de-415a1666eb42", "file_name": "attention.py", "repo_name": "e-b-daniel/flash_attention_replication", "file_path": "attention.py", "commit_hash": "86ac6ecffcfb729201606840dc72da116751a43f", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel(Q, K, V, sm_scale, L, M, Out, stride_head, stride_seq,\n hidden_dim, seq_len, Br: tl.constexpr, Bt: tl.constexpr, hidden: tl.\n constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n offs_br = start_m * Br + tl.arange(0, Br)\n offs_bt = tl.arange(0, Bt)\n offs_d = tl.arange(0, hidden)\n off_q = off_hz * stride_head + offs_br[:, None] * stride_seq + offs_d[\n None, :] * hidden_dim\n off_kv = off_hz * stride_head + offs_bt[:, None] * stride_seq + offs_d[\n None, :] * hidden_dim\n q_ptrs = Q + off_q\n k_ptrs = K + off_kv\n v_ptrs = V + off_kv\n m_i = tl.zeros([Br], dtype=tl.float16) - float('inf')\n l_i = tl.zeros([Br], dtype=tl.float16)\n acc = tl.zeros([Br, hidden], dtype=tl.float16)\n q = tl.load(q_ptrs)\n for start_n in tl.range(0, (start_m + 1) * Br, Bt):\n k = tl.load(k_ptrs + start_n * stride_seq)\n v = tl.load(v_ptrs + start_n * stride_seq)\n qk = tl.dot(q, tl.trans(k)) * sm_scale\n qk += tl.where(offs_br[:, None] >= start_n + offs_bt[None, :], 0,\n float('-inf'))\n m_ij = tl.max(qk, 1)\n p = tl.exp(qk - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n alpha = tl.exp(m_i - m_i_new)\n beta = tl.exp(m_ij - m_i_new)\n l_i_new = alpha * l_i + beta * l_ij\n p = p * (beta / l_i_new)[:, None]\n p = p.to(v.dtype)\n acc_scale_factor = l_i / l_i_new * alpha\n acc = acc * acc_scale_factor[:, None] + tl.dot(p, v)\n acc = acc.to(v.dtype)\n l_i = l_i_new.to(l_i.dtype)\n m_i = m_i_new.to(m_i.dtype)\n l_ptrs = L + off_hz * seq_len + offs_br\n m_ptrs = M + off_hz * seq_len + offs_br\n out_ptrs = Out + off_q\n tl.store(l_ptrs, l_i)\n tl.store(m_ptrs, m_i)\n tl.store(out_ptrs, acc)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/e-b-daniel/flash_attention_replication/blob/86ac6ecffcfb729201606840dc72da116751a43f/attention.py" }, { "uuid": "51de4fd6-86e7-4186-a066-d17def98e550", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef _mlp_wide_kernel_bwd_dw1w2(dw1, dw2, pid_h, pid_e, x_ptr, w1_ptr,\n w2_ptr, o_ptr, dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D: tl.constexpr,\n E, stride_xb, stride_xd, stride_w1d, stride_w1e, stride_w2e, stride_w2d,\n stride_ob, stride_od, stride_dxb, stride_dxd, stride_dw1d, stride_dw1e,\n stride_dw2e, stride_dw2d, stride_dob, stride_dod, BLOCK_SIZE_B: tl.\n constexpr, BLOCK_SIZE_E: tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp_bwd_dw1w2\n Z = X @ W1, H = f(Z), O = H @ W2\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n - dX has shape (B, D)\n - dW1 has shape (D, E)\n - dW2 has shape (E, D)\n - dO has shape (B, D)\n \"\"\"\n TARGET_TYPE = x_ptr.type.element_ty\n offs_b = tl.arange(0, BLOCK_SIZE_B)\n offs_d = tl.arange(0, D)\n offs_e = tl.arange(0, BLOCK_SIZE_E)\n x_ptrs = x_ptr + ((pid_h * B + offs_b[:, None]) * stride_xb + offs_d[\n None, :] * stride_xd)\n do_ptrs = do_ptr + ((pid_h * B + offs_b[:, None]) * stride_dob + offs_d\n [None, :] * stride_dod)\n do_mask = (offs_b[:, None] < B) & (offs_d[None, :] < D)\n w1_ptrs = w1_ptr + ((pid_h * D + offs_d[:, None]) * stride_w1d + (pid_e *\n BLOCK_SIZE_E + offs_e[None, :]) * stride_w1e)\n w1_mask = (offs_d[:, None] < D) & (offs_e[None, :] < E - pid_e *\n BLOCK_SIZE_E)\n w2_ptrs = w2_ptr + ((pid_h * E + pid_e * BLOCK_SIZE_E + offs_e[:, None]\n ) * stride_w2e + offs_d[None, :] * stride_w2d)\n w2_mask = (offs_e[:, None] < E - pid_e * BLOCK_SIZE_E) & (offs_d[None,\n :] < D)\n w1 = tl.load(w1_ptrs, mask=w1_mask, other=0.0)\n w2 = tl.load(w2_ptrs, mask=w2_mask, other=0.0)\n do = tl.load(do_ptrs, mask=do_mask, other=0.0)\n for b in range(0, tl.cdiv(B, BLOCK_SIZE_B)):\n x_mask = (offs_b[:, None] < B - b * BLOCK_SIZE_B) & (offs_d[None, :\n ] < D)\n do_mask = (offs_b[:, None] < B - b * BLOCK_SIZE_B) & (offs_d[None,\n :] < D)\n x = tl.load(x_ptrs, mask=x_mask, other=0.0)\n do = tl.load(do_ptrs, mask=do_mask, other=0.0)\n z = tl.dot(x, w1, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n h = leaky_relu(z).to(TARGET_TYPE)\n elif ACTIVATION == 'silu':\n h = silu(z).to(TARGET_TYPE)\n elif ACTIVATION == 'sigmoid':\n h = tl.sigmoid(z).to(TARGET_TYPE)\n else:\n h = z.to(TARGET_TYPE)\n dh = tl.dot(do, tl.trans(w2), out_dtype=tl.float32)\n dw2 += tl.dot(tl.trans(h), do, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n dz = (dh * d_leacky_relu(z)).to(TARGET_TYPE)\n elif ACTIVATION == 'silu':\n dz = (dh * d_silu(z, h)).to(TARGET_TYPE)\n elif ACTIVATION == 'sigmoid':\n dz = (dh * d_sigmoid(h)).to(TARGET_TYPE)\n else:\n dz = dh.to(TARGET_TYPE)\n dw1 += tl.dot(tl.trans(x), dz, out_dtype=tl.float32)\n x_ptrs += BLOCK_SIZE_B * stride_xb\n do_ptrs += BLOCK_SIZE_B * stride_dob\n return dw1, dw2\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "92f2a427-dd63-44de-8442-1178d2139794", "file_name": "gemm.py", "repo_name": "TiledTensor/TiledBench", "file_path": "benchs/python/gemm/triton/gemm.py", "commit_hash": "1191aecde1b29e0b7bb9ef1a06d0e156c1fce136", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128,\n 'BLOCK_K': 64}, num_stages=3, num_warps=8), triton.Config({'BLOCK_M': \n 64, 'BLOCK_N': 256, 'BLOCK_K': 32}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 32}, num_stages=3,\n num_warps=8), triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'BLOCK_K': \n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 64,\n 'BLOCK_N': 128, 'BLOCK_K': 32}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 32, 'BLOCK_K': 32}, num_stages=3,\n num_warps=8), triton.Config({'BLOCK_M': 64, 'BLOCK_N': 32, 'BLOCK_K': \n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 32,\n 'BLOCK_N': 64, 'BLOCK_K': 32}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K': 128}, num_stages=3,\n num_warps=8), triton.Config({'BLOCK_M': 256, 'BLOCK_N': 128, 'BLOCK_K':\n 128}, num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 256,\n 'BLOCK_N': 64, 'BLOCK_K': 128}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_M': 64, 'BLOCK_N': 256, 'BLOCK_K': 128}, num_stages=3,\n num_warps=8), triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K':\n 128}, num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 128,\n 'BLOCK_N': 64, 'BLOCK_K': 64}, num_stages=3, num_warps=8), triton.\n Config({'BLOCK_M': 64, 'BLOCK_N': 128, 'BLOCK_K': 64}, num_stages=3,\n num_warps=8), triton.Config({'BLOCK_M': 64, 'BLOCK_N': 128, 'BLOCK_K': \n 64}, num_stages=3, num_warps=8), triton.Config({'BLOCK_M': 128,\n 'BLOCK_N': 32, 'BLOCK_K': 64}, num_stages=3, num_warps=8)], key=['M',\n 'N', 'K'])\n@triton.jit\ndef _gemm_kernel(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_cm, stride_cn, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr):\n pid_m = tl.program_id(0)\n pid_n = tl.program_id(1)\n offset_am = (pid_m * BLOCK_M + tl.arange(0, BLOCK_M)) % M\n offset_bn = (pid_n * BLOCK_N + tl.arange(0, BLOCK_N)) % N\n offset_k = tl.arange(0, BLOCK_K)\n a_ptrs = a_ptr + (offset_am[:, None] * stride_am + offset_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + (offset_k[:, None] * stride_bk + offset_bn[None, :] *\n stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BLOCK_K)):\n a = tl.load(a_ptrs, mask=offset_k[None, :] < K - k * BLOCK_K)\n b = tl.load(b_ptrs, mask=offset_k[:, None] < K - k * BLOCK_K)\n acc = tl.dot(a, b, acc)\n a_ptrs += BLOCK_K * stride_ak\n b_ptrs += BLOCK_K * stride_bk\n offset_cm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offset_cn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n c_ptrs = c_ptr + (offset_cm[:, None] * stride_cm + offset_cn[None, :] *\n stride_cn)\n c_mask = (offset_cm[:, None] < M) & (offset_cn[None, :] < N)\n tl.store(c_ptrs, acc, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Transposed Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/TiledTensor/TiledBench/blob/1191aecde1b29e0b7bb9ef1a06d0e156c1fce136/benchs/python/gemm/triton/gemm.py" }, { "uuid": "abd73d7c-d83a-4608-8687-11f67fd11608", "file_name": "gemm_streamk_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef swizzle_tile(tile_id, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n grid_m = tl.cdiv(M, BLOCK_SIZE_M)\n grid_n = tl.cdiv(N, BLOCK_SIZE_N)\n width = GROUP_SIZE_M * grid_n\n group_id = tile_id // width\n group_size = tl.minimum(GROUP_SIZE_M, grid_m - group_id * GROUP_SIZE_M)\n pid_m = group_id * GROUP_SIZE_M + tile_id % group_size\n pid_n = tile_id % width // group_size\n return pid_m, pid_n\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py" }, { "uuid": "b7ea7c6d-cb9a-4a55-bf9c-8f193083482e", "file_name": "softmax_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/softmax_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef softmax_backward_kernel(output_grad_pointer, output_pointer,\n input_grad_pointer, batch_dim, feat_dim, output_grad_batch_stride,\n output_grad_feat_stride, output_batch_stride, output_feat_stride,\n input_grad_batch_stride, input_grad_feat_stride, log: tl.constexpr,\n BLOCK_SIZE_BATCH: tl.constexpr, BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Calculates the input gradient of softmax.\n\n Args:\n output_grad_pointer: Pointer to softmax's output gradients.\n The output gradients must be of shape [batch_dim, feat_dim].\n output_pointer: Pointer to softmax's output.\n The output must be of shape [batch_dim, feat_dim].\n input_grad_pointer: Pointer to a container the input's gradients are written to.\n The container must be of shape [batch_dim, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n output_grad_batch_stride: Stride necessary to jump one element along the\n output gradients' batch dimension.\n output_grad_feat_stride: Stride necessary to jump one element along the\n output gradients' feature dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output's batch dimension.\n output_feat_stride: Stride necessary to jump one element along the\n output's feature dimension.\n input_grad_batch_stride: Stride necessary to jump one element along the\n input gradient container's batch dimension.\n input_grad_feat_stride: Stride necessary to jump one element along the\n input gradient container's feature dimension.\n log: Flag indicating if log of softmax was taken.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n output_grad_pointer += output_grad_batch_stride * batch_offset[:, None\n ] + output_grad_feat_stride * feat_offset[None, :]\n output_pointer += output_batch_stride * batch_offset[:, None\n ] + output_feat_stride * feat_offset[None, :]\n input_grad_pointer += input_grad_batch_stride * batch_offset[:, None\n ] + input_grad_feat_stride * feat_offset[None, :]\n output_grad = tl.load(output_grad_pointer, mask=batch_mask[:, None] &\n feat_mask[None, :]).to(tl.float32)\n output = tl.load(output_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :]).to(tl.float32)\n if log:\n input_grad = output_grad - tl.exp(output) * tl.sum(output_grad, axis=1\n )[:, None]\n else:\n input_grad = output * (output_grad - tl.sum(output_grad * output,\n axis=1)[:, None])\n tl.store(input_grad_pointer, input_grad, mask=batch_mask[:, None] &\n feat_mask[None, :])\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/softmax_kernels.py" }, { "uuid": "b2ad8a84-f1bc-4160-86c6-16c93aa73c9d", "file_name": "dynamic_quant.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/dynamic_quant.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _abs_max(val1, val2):\n val1_abs = tl.abs(val1)\n val2_abs = tl.abs(val2)\n if val1_abs >= val2_abs:\n return val1_abs\n else:\n return val2_abs\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/dynamic_quant.py" }, { "uuid": "7cc562e7-5cf7-4828-8797-4dacdc2c7611", "file_name": "sgmv_expand.py", "repo_name": "IBM/vllm", "file_path": "vllm/lora/ops/sgmv_expand.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _sgmv_expand_kernel(input_ptr, lora_ptr, out_ptr, N, K, b_seq_start_loc,\n seq_lens, lora_indices, xm_stride, xk_stride, l0_stride, lora_k_stride,\n lora_n_stride, cm_stride, cn_stride, BLOCK_M: tl.constexpr, BLOCK_N: tl\n .constexpr, BLOCK_K: tl.constexpr, EVEN_K: tl.constexpr, ADD_INPUTS: tl\n .constexpr, CAST_TYPE: tl.constexpr):\n \"\"\"\n The sgmv's expand triton kernel is based on GroupGEMM.\n \"\"\"\n pid = tl.program_id(axis=0)\n cur_batch = tl.program_id(axis=1)\n cta_n_num = tl.cdiv(N, BLOCK_N)\n pid_m = pid // cta_n_num\n pid_n = pid % cta_n_num\n M = tl.load(seq_lens + cur_batch)\n if pid_m * BLOCK_M > M:\n return\n lora_index = tl.load(lora_indices + cur_batch)\n if lora_index == -1:\n return\n cur_seq_start = tl.load(b_seq_start_loc + cur_batch)\n offset_m = tl.arange(0, BLOCK_M) + pid_m * BLOCK_M\n offset_n = tl.arange(0, BLOCK_N) + pid_n * BLOCK_N\n offset_k = tl.arange(0, BLOCK_K)\n ram = tl.max_contiguous(tl.multiple_of(offset_m % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(offset_n % N, BLOCK_N), BLOCK_N)\n a_ptr = input_ptr + cur_seq_start * xm_stride + ram[:, None\n ] * xm_stride + offset_k[None, :] * xk_stride,\n b_ptr = lora_ptr + l0_stride * lora_index + offset_k[:, None\n ] * lora_n_stride + rbn[None, :] * lora_k_stride\n accumulator = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n for k in range(tl.cdiv(K, BLOCK_K)):\n if EVEN_K:\n tiled_a = tl.load(a_ptr)\n tiled_b = tl.load(b_ptr)\n else:\n tiled_a = tl.load(a_ptr, mask=offset_k[None, :] < K - k *\n BLOCK_K, other=0)\n tiled_b = tl.load(b_ptr, mask=offset_k[:, None] < K - k *\n BLOCK_K, other=0)\n if CAST_TYPE:\n tiled_a = tiled_a.to(lora_ptr.dtype.element_ty)\n accumulator += tl.dot(tiled_a, tiled_b)\n a_ptr += BLOCK_K * xk_stride\n b_ptr += BLOCK_K * lora_n_stride\n tiled_c = accumulator.to(lora_ptr.dtype.element_ty)\n offset_cm = cur_seq_start + tl.arange(0, BLOCK_M) + pid_m * BLOCK_M\n offset_cn = tl.arange(0, BLOCK_N) + pid_n * BLOCK_N\n c_ptr = out_ptr + offset_cm[:, None] * cm_stride + offset_cn[None, :\n ] * cn_stride\n M = tl.load(seq_lens + cur_batch)\n c_mask = (offset_cm[:, None] < cur_seq_start + M) & (offset_cn[None, :] < N\n )\n if ADD_INPUTS:\n tiled_out = tl.load(c_ptr, mask=c_mask, other=None)\n tiled_c += tiled_out\n tl.store(c_ptr, tiled_c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/lora/ops/sgmv_expand.py" }, { "uuid": "ed539db4-d433-434f-8d65-9170cc127c3b", "file_name": "triton_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/template_attention/triton_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64,\n 'BLOCK_DMODEL': 64}, num_stages=3, num_warps=4)], key=['num_queries'])\n@triton.jit\ndef triton_tem_fused_with_exp2(arg_Q, arg_K, arg_V, out_ptr0, num_queries:\n tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr):\n SCORE_MOD_IS_LINEAR: tl.constexpr = False\n ROWS_GUARANTEED_SAFE: tl.constexpr = False\n Q = arg_Q\n K = arg_K\n V = arg_V\n stride_qz = 4194304\n stride_qh = 262144\n stride_qm = 64\n stride_qk = 1\n stride_kz = 4194304\n stride_kh = 262144\n stride_kn = 64\n stride_kk = 1\n stride_vz = 4194304\n stride_vh = 262144\n stride_vk = 64\n stride_vn = 1\n Z = 16\n H = 16\n N_CTX = 4096\n qk_scale = 1.0\n MATMUL_PRECISION = Q.dtype.element_ty\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n qkv_offset = off_hz * stride_qh\n Q_block_ptr = tl.make_block_ptr(base=Q + qkv_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qkv_offset, shape=(\n BLOCK_DMODEL, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + qkv_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n q = tl.load(Q_block_ptr)\n if SCORE_MOD_IS_LINEAR:\n qk_scale *= 1.44269504\n q = (q * qk_scale).to(MATMUL_PRECISION)\n lo = 0\n hi = N_CTX\n for start_n in range(lo, hi, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(K_block_ptr)\n v = tl.load(V_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk = tl.dot(q, k.to(MATMUL_PRECISION), acc=qk)\n tmp0 = tl.full([1], 1024, tl.int64)\n tmp1 = offs_m[:, None] <= tmp0\n tmp2 = start_n + offs_n[None, :] <= tmp0\n tmp3 = tmp1 & tmp2\n tmp4 = offs_m[:, None] >= start_n + offs_n[None, :]\n tmp5 = tmp3 | tmp4\n tmp6 = float('-inf')\n tmp7 = tmp6.to(tl.float32)\n tmp8 = tl.where(tmp5, qk, tmp7)\n qk = tmp8\n if not SCORE_MOD_IS_LINEAR:\n qk *= 1.44269504\n row_max = tl.max(qk, 1)\n m_i_new = tl.maximum(m_i, row_max)\n masked_out_rows = m_i_new == float('-inf')\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n if not ROWS_GUARANTEED_SAFE:\n alpha = tl.where(masked_out_rows, 0, alpha)\n p = tl.where(masked_out_rows[:, None], 0, p)\n acc_scale = l_i * 0 + alpha\n acc *= acc_scale[:, None]\n acc = tl.dot(p.to(MATMUL_PRECISION), v.to(MATMUL_PRECISION), acc)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n acc = acc / l_i[:, None]\n idx_z = tl.program_id(1) // H\n idx_h = tl.program_id(1) % H\n idx_m = offs_m[:, None]\n idx_d = tl.arange(0, BLOCK_DMODEL)[None, :]\n mask = (idx_m != -1) & (idx_d != -1)\n xindex = idx_d + 64 * idx_m + 262144 * idx_h + 4194304 * idx_z\n tl.store(out_ptr0 + xindex, acc, None)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Cooperative Groups" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/template_attention/triton_attention.py" }, { "uuid": "065a20ba-b651-4f54-89ce-6c8b91a0e483", "file_name": "y_6.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_6.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef sixth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor, block_size:\n tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.constexpr,\n col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST002 = 3.26558761940328\n CONST003 = 3.26558761940328\n CONST004 = 6.53117523880657\n CONST006 = 8.38944649544891\n CONST007 = 9.79676285820985\n CONST008 = 10.3266947761614\n CONST009 = 3.60555127546399\n CONST010 = -1.78863600265677\n CONST011 = 14.5309475774982\n CONST012 = 8.94318001328386\n CONST013 = 16.5227116418583\n CONST014 = 16.5227116418583\n CONST015 = 17.8863600265677\n CONST017 = 20.6533895523229\n CONST018 = 20.2812259244849\n CONST019 = -107.318160159406\n CONST020 = 17.8863600265677\n CONST022 = 29.3902885746295\n CONST024 = 40.5624518489699\n CONST025 = 41.9472324772445\n CONST026 = -1.63279380970164\n CONST027 = -83.8944649544891\n CONST028 = -78.3741028656788\n CONST030 = -71.5454401062709\n CONST032 = -52.2494019104525\n CONST033 = -52.2494019104525\n CONST035 = -48.4364919249939\n CONST036 = -41.3067791046458\n CONST037 = -36.3273689437454\n CONST038 = -29.3902885746295\n CONST039 = -27.0416345659799\n CONST040 = -26.1247009552263\n CONST041 = -26.1247009552263\n CONST042 = -19.5935257164197\n CONST043 = -2.4218245962497\n CONST044 = -9.79676285820985\n CONST045 = -7.15454401062709\n CONST046 = -3.38020432074749\n CONST047 = -1.1267347735825\n VAR07 = x * x * x\n VAR08 = x * x\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR06 = VAR08 * VAR08\n VAR16 = y * y * y\n VAR17 = y * y\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR15 = VAR17 * VAR17\n VAR25 = z * z * z\n VAR26 = z * z\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n VAR24 = VAR26 * VAR26\n Y00 = (CONST011 * VAR05 * z + CONST011 * VAR23 * x + CONST035 * VAR07 *\n VAR25)\n Y01 = y * (CONST006 * VAR05 + CONST025 * VAR24 * x + CONST027 * VAR07 *\n VAR26)\n Y02 = -CONST045 * VAR05 * z + CONST045 * VAR23 * x + VAR17 * (CONST030 *\n VAR07 * z - CONST030 * VAR25 * x)\n Y03 = VAR16 * (-CONST028 * VAR26 * x + CONST040 * VAR07) + y * (\n CONST007 * VAR05 + CONST038 * VAR24 * x + CONST042 * VAR07 * VAR26)\n Y04 = CONST003 * VAR05 * z + VAR07 * (CONST004 * VAR25 + CONST033 *\n VAR17 * z) + x * (CONST002 * VAR23 - CONST032 * VAR15 * z + \n CONST032 * VAR17 * VAR25)\n Y05 = CONST008 * VAR05 * y + VAR07 * (CONST017 * VAR26 * y + CONST036 *\n VAR16) + x * (CONST008 * VAR24 * y + CONST013 * VAR14 + CONST036 *\n VAR16 * VAR26)\n Y06 = (CONST009 * VAR13 + CONST018 * VAR17 * VAR24 + CONST039 * VAR15 *\n VAR26 + CONST047 * VAR04 + CONST047 * VAR22 + VAR06 * (CONST018 *\n VAR17 + CONST046 * VAR26) + VAR08 * (CONST024 * VAR17 * VAR26 + \n CONST039 * VAR15 + CONST046 * VAR24))\n Y07 = CONST008 * VAR23 * y + VAR25 * (CONST017 * VAR08 * y + CONST036 *\n VAR16) + z * (CONST008 * VAR06 * y + CONST014 * VAR14 + CONST036 *\n VAR08 * VAR16)\n Y08 = (CONST026 * VAR04 - CONST026 * VAR22 + CONST040 * VAR17 * VAR24 -\n CONST041 * VAR15 * VAR26 + VAR06 * (CONST026 * VAR26 - CONST041 *\n VAR17) + VAR08 * (-CONST026 * VAR24 + CONST041 * VAR15))\n Y09 = VAR16 * (CONST028 * VAR08 * z - CONST041 * VAR25) + y * (CONST022 *\n VAR06 * z - CONST042 * VAR08 * VAR25 + CONST044 * VAR23)\n Y10 = (CONST010 * VAR04 + CONST010 * VAR22 + CONST020 * VAR17 * VAR24 +\n VAR06 * (CONST012 * VAR26 + CONST015 * VAR17) + VAR08 * (CONST012 *\n VAR24 + CONST019 * VAR17 * VAR26))\n Y11 = y * (CONST006 * VAR23 + CONST025 * VAR06 * z + CONST027 * VAR08 *\n VAR25)\n Y12 = (-CONST037 * VAR06 * VAR26 + CONST037 * VAR08 * VAR24 + CONST043 *\n VAR04 - CONST043 * VAR22)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n tl.store(output_ptr + output_row_offset + 9, Y09, mask=\n output_row_offset + 9 < output_numel)\n tl.store(output_ptr + output_row_offset + 10, Y10, mask=\n output_row_offset + 10 < output_numel)\n tl.store(output_ptr + output_row_offset + 11, Y11, mask=\n output_row_offset + 11 < output_numel)\n tl.store(output_ptr + output_row_offset + 12, Y12, mask=\n output_row_offset + 12 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_6.py" }, { "uuid": "c57cca70-6e96-47ee-9f5c-ee9125d45b80", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_backward_input_grad_kernel_notune(a_ptr, b_ptr, c_ptr,\n init_factor, M, N, K, H, stride_am, stride_an, stride_cm, stride_ck, R7:\n int, R6: int, R5: int, R4: int, R3: int, R2: int, R1: int, R0: int,\n allow_tf32: tl.constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_backward_input_grad_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=\n c_ptr, init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=\n stride_am, stride_an=stride_an, stride_cm=stride_cm, stride_ck=\n stride_ck, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1, R0=R0,\n allow_tf32=allow_tf32, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=\n BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "61065322-dd42-4a37-af64-ca295705d2b2", "file_name": "rms_norm_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/rms_norm_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef rms_norm_forward_kernel(input_pointer, weight_pointer, inv_rms_pointer,\n output_pointer, batch_dim, feat_dim, input_batch_stride,\n input_feat_stride, output_batch_stride, output_feat_stride, eps,\n scale_by_weight: tl.constexpr, save_stats: tl.constexpr,\n BLOCK_SIZE_BATCH: tl.constexpr, BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Root-mean-square-normalizes the input.\n\n Args:\n input_pointer: Pointer to the input to root-mean-square-normalize.\n The input must be of shape [batch_dim, feat_dim].\n weight_pointer: Pointer to optional weights for linear transform.\n The weights, if provided, must be of shape [feat_dim].\n inv_rms_pointer: Pointer to an optional container the input's inverse\n root mean square is written to if save_stats is True.\n The container, if provided, must be of shape [batch_dim].\n output_pointer: Pointer to a container the result is written to.\n The container must be of shape [batch_dim, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output container's batch dimension.\n output_feat_stride: Stride necessary to jump one element along the\n output container's feature dimension.\n eps: Epsilon added in the square root in the denominator\n to avoid division by zero.\n scale_by_weight: Flag for scaling the normalized output by weights.\n save_stats: Flag for saving the root mean square.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n output_pointer += output_batch_stride * batch_offset[:, None\n ] + output_feat_stride * feat_offset[None, :]\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :]).to(tl.float32)\n inv_rms = tl.rsqrt(tl.sum(input * input, axis=1) / feat_dim + eps)\n output = input * inv_rms[:, None]\n if save_stats:\n tl.store(inv_rms_pointer + batch_offset, inv_rms, mask=batch_mask)\n if scale_by_weight:\n weight = tl.load(weight_pointer + feat_offset, mask=feat_mask)\n output *= weight\n tl.store(output_pointer, output, mask=batch_mask[:, None] & feat_mask[\n None, :])\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/rms_norm_kernels.py" }, { "uuid": "c9a38822-1126-4d55-bac7-f5990f7d18ec", "file_name": "mlp.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/mlp.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_mlp_activation_backward_kernel(grad_output_ptr, grad_input_ptr,\n input_ptr, output_ptr, gated: tl.constexpr, activation_type: tl.\n constexpr, recompute: tl.constexpr, n_cols: tl.constexpr, block_size:\n tl.constexpr):\n row_idx = tl.program_id(0).to(tl.int64)\n columns = tl.program_id(1) * block_size + tl.arange(0, block_size)\n output_offsets = n_cols * row_idx + columns\n input_offsets = 2 * n_cols * row_idx + columns if gated else output_offsets\n input_ptr = input_ptr + input_offsets\n grad_input_ptr = grad_input_ptr + input_offsets\n mask = columns < n_cols\n input_ = tl.load(input_ptr, mask=mask).to(tl.float32)\n output_grad = tl.load(grad_output_ptr + output_offsets, mask=mask).to(tl\n .float32)\n if activation_type == _TritonActivationType.gelu:\n tanh_input = 0.79788456 * input_ * (1 + 0.044715 * input_ * input_)\n tanh = 1 - 2 / (1 + tl.exp(2 * tanh_input))\n grad = 0.5 * input_ * ((1 - tanh * tanh) * (0.79788456 + \n 0.1070322243 * input_ * input_)) + 0.5 * (1 + tanh)\n if gated or recompute:\n out = input_ * 0.5 * (1.0 + tanh)\n elif activation_type == _TritonActivationType.silu:\n exp = tl.exp(-input_)\n sigma = 1 / (1 + exp)\n grad = sigma * sigma + (1 + input_) / (2 + exp + 1 / exp)\n if gated or recompute:\n out = input_ * sigma\n elif activation_type == _TritonActivationType.relu:\n grad = tl.where(input_ > 0, 1, 0)\n if gated or recompute:\n out = tl.where(input_ > 0, input_, 0)\n elif activation_type == _TritonActivationType.squared_relu:\n relu_out = tl.where(input_ > 0, input_, 0)\n grad = 2 * relu_out\n if gated or recompute:\n out = relu_out * relu_out\n else:\n raise NotImplementedError()\n if gated:\n other = tl.load(input_ptr + n_cols, mask=mask)\n tl.store(grad_input_ptr, grad * other * output_grad, mask=mask)\n tl.store(grad_input_ptr + n_cols, out * output_grad, mask=mask)\n out = out * other\n else:\n tl.store(grad_input_ptr, grad * output_grad, mask=mask)\n if recompute:\n tl.store(output_ptr + output_offsets, out, mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/mlp.py" }, { "uuid": "78c3a947-9a20-4a2d-b1c0-8cdcf8617d2f", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_stages=stages, num_warps=\n warps) for stages in [0, 1, 3, 4] for warps in [4, 8, 16]], key=[\n 'QUERY_GROUP_SIZE', 'HEAD_SIZE', 'KV_BLOCK_SIZE'])\n@triton.jit\ndef _paged_attn_w_mma_kernel(m_i_ptr, l_i_ptr, out_ptr, q_ptr, k_cache_ptr,\n v_cache_ptr, context_lens_ptr, block_tables_ptr, attn_scale, stride_bt0,\n stride_bt1, stride_q0, stride_q1, stride_q2, stride_kv0, stride_kv1,\n stride_kv2, stride_kv3, stride_o0, stride_o1, stride_o2, stride_o3,\n stride_o4, HEAD_SIZE: tl.constexpr, QUERY_GROUP_SIZE: tl.constexpr,\n PADDED_QUERY_GROUP_SIZE: tl.constexpr, NUM_KV_HEADS: tl.constexpr,\n KV_BLOCK_SIZE: tl.constexpr, PARTITION_SIZE: tl.constexpr):\n seq_idx = tl.program_id(0)\n kv_head_idx = tl.program_id(1)\n part_idx = tl.program_id(2)\n max_num_partitions = tl.num_programs(2)\n log2e: tl.constexpr = 1.4426950408889634\n USE_PARTITIONING = PARTITION_SIZE > 0\n context_len = tl.load(context_lens_ptr + seq_idx)\n if USE_PARTITIONING:\n context_start_idx = part_idx * PARTITION_SIZE\n if context_start_idx >= context_len:\n return\n context_end_idx = tl.minimum(context_start_idx + PARTITION_SIZE,\n context_len)\n num_blocks = tl.cdiv(context_end_idx - context_start_idx, KV_BLOCK_SIZE\n )\n else:\n num_blocks = tl.cdiv(context_len, KV_BLOCK_SIZE)\n block_offset = tl.arange(0, KV_BLOCK_SIZE)\n head_offset = tl.arange(0, HEAD_SIZE)\n padding_group_offset = tl.arange(0, PADDED_QUERY_GROUP_SIZE)\n kv_offset = kv_head_idx * stride_kv1 + block_offset[:, None\n ] * stride_kv2 + head_offset[None, :] * stride_kv3\n q_offset = seq_idx * stride_q0 + (kv_head_idx * QUERY_GROUP_SIZE +\n padding_group_offset[:, None]) * stride_q1 + head_offset[None, :\n ] * stride_q2\n group_mask = padding_group_offset[:, None] < QUERY_GROUP_SIZE\n q = tl.load(q_ptr + q_offset, mask=group_mask, other=0.0)\n q = (q * attn_scale).to(q_ptr.dtype.element_ty)\n m_i = tl.zeros([PADDED_QUERY_GROUP_SIZE], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([PADDED_QUERY_GROUP_SIZE], dtype=tl.float32)\n acc = tl.zeros([PADDED_QUERY_GROUP_SIZE, HEAD_SIZE], dtype=tl.float32)\n num_prev_blocks = part_idx * (PARTITION_SIZE // KV_BLOCK_SIZE)\n for i in range(num_blocks):\n block_idx = num_prev_blocks + i\n block_number = tl.load(block_tables_ptr + seq_idx * stride_bt0 + \n block_idx * stride_bt1)\n kv_block_offset = block_number * stride_kv0 + kv_offset\n mask_offset = block_idx * KV_BLOCK_SIZE + block_offset\n kv_mask = mask_offset[:, None] < context_len\n k = tl.load(k_cache_ptr + kv_block_offset, mask=kv_mask, other=0.0)\n if PADDED_QUERY_GROUP_SIZE == 1:\n qk = tl.sum(q[:, None, :] * k[None, :, :], axis=2)\n else:\n qk = tl.dot(q, k.T, out_dtype=tl.float32)\n qk = tl.where(mask_offset < context_len, qk, float('-inf'))\n m_i_new = tl.maximum(m_i, tl.max(qk, axis=1))\n p = tl.math.exp2((qk - m_i_new[:, None]) * log2e)\n alpha = tl.math.exp2((m_i - m_i_new) * log2e)\n acc *= alpha[:, None]\n v = tl.load(v_cache_ptr + kv_block_offset, mask=kv_mask, other=0.0)\n if PADDED_QUERY_GROUP_SIZE == 1:\n acc += tl.sum(p.T[:, :, None] * v[:, None, :], axis=0)\n else:\n p = p.to(v.dtype)\n acc += tl.dot(p, v, out_dtype=tl.float32)\n l_i = l_i * alpha + tl.sum(p, axis=1)\n m_i = m_i_new\n acc = acc / l_i[:, None]\n if USE_PARTITIONING:\n part_offset = ((seq_idx * NUM_KV_HEADS + kv_head_idx) *\n max_num_partitions * QUERY_GROUP_SIZE + part_idx *\n QUERY_GROUP_SIZE + padding_group_offset)\n mask = padding_group_offset < QUERY_GROUP_SIZE\n tl.store(m_i_ptr + part_offset, m_i, mask=mask)\n tl.store(l_i_ptr + part_offset, l_i, mask=mask)\n out_offset = seq_idx * stride_o0\n if USE_PARTITIONING:\n out_offset += kv_head_idx * stride_o1\n else:\n out_offset += kv_head_idx * QUERY_GROUP_SIZE * stride_o1\n out_offset += part_idx * stride_o2 + padding_group_offset[:, None\n ] * stride_o3 + head_offset[None, :] * stride_o4\n group_mask = padding_group_offset[:, None] < QUERY_GROUP_SIZE\n tl.store(out_ptr + out_offset, acc, mask=group_mask)\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Transposed Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "97731521-c61c-4321-aa31-93651e9adc55", "file_name": "_matmul.py", "repo_name": "IBM/qattn", "file_path": "qattn/nn/functional/_matmul.py", "commit_hash": "07ceda0aceb9afd299d622325944c0c0471827fe", "starcount": 0, "input": "@triton.autotune(configs=int8_configs(), key=['M', 'N', 'K'],\n prune_configs_by={'early_config_prune': early_config_prune,\n 'perf_model': _estimate_matmul_time, 'top_k': 10})\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % args['BLOCK_K'] == 0})\n@triton.jit\ndef _kernel(A, B, C, bias, M, N, K, stride_am, stride_ak, stride_bk,\n stride_bn, stride_cm, stride_cn, a_scale_ptr, b_scale_ptr,\n out_scale_ptr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K:\n tl.constexpr, GROUP_M: tl.constexpr, EVEN_K: tl.constexpr, BIAS_ADD: tl\n .constexpr, A_PER_CHANNEL: tl.constexpr, B_PER_CHANNEL: tl.constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.int32)\n for k in range(0, tl.cdiv(K, BLOCK_K)):\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n k_remaining = K - k * BLOCK_K\n _0 = tl.zeros((1, 1), dtype=tl.int8)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_0)\n b = tl.load(B, mask=rk[:, None] < k_remaining, other=_0)\n acc += tl.dot(a, b, allow_tf32=True, out_dtype=tl.int32)\n A += BLOCK_K * stride_ak\n B += BLOCK_K * stride_bk\n if A_PER_CHANNEL:\n _0 = tl.zeros((1,), dtype=a_scale_ptr.dtype.element_ty)\n mask = ram < M\n a_scale = tl.load(a_scale_ptr + ram, mask=mask, other=_0)\n else:\n a_scale = tl.load(a_scale_ptr)\n if B_PER_CHANNEL:\n _0 = tl.zeros((1,), dtype=b_scale_ptr.dtype.element_ty)\n mask = rbn < N\n b_scale = tl.load(b_scale_ptr + rbn, mask=mask, other=_0)\n else:\n b_scale = tl.load(b_scale_ptr)\n if BIAS_ADD:\n bias = tl.load(bias + rn)\n if A_PER_CHANNEL and B_PER_CHANNEL:\n bias = tl.math.llrint(bias / (a_scale[:, None] * b_scale[None, :])\n ).to(tl.int32)\n acc = acc + bias\n else:\n bias = tl.math.llrint(bias / (a_scale * b_scale)).to(tl.int32)\n acc = acc + bias[None, :]\n if A_PER_CHANNEL and B_PER_CHANNEL:\n mask = ram < M\n _0 = tl.zeros((1,), dtype=out_scale_ptr.dtype.element_ty)\n out_scale = tl.load(out_scale_ptr + ram, mask=mask, other=_0)\n acc = tl.math.llrint(acc.to(tl.float32) * a_scale[:, None] *\n b_scale[None, :] * out_scale[:, None]).to(tl.int8)\n else:\n out_scale = tl.load(out_scale_ptr)\n acc = tl.math.llrint(acc.to(tl.float32) * (a_scale * b_scale *\n out_scale)).to(tl.int8)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n tl.store(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/IBM/qattn/blob/07ceda0aceb9afd299d622325944c0c0471827fe/qattn/nn/functional/_matmul.py" }, { "uuid": "b7fb0c98-69f2-48d3-a107-c7746602da7f", "file_name": "triton_fused_local_attn2.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_local_attn2.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0})\n@triton.jit\ndef _fwd_kernel(Q, K, V, Out, L, softmax_scale, stride_qb, stride_qh,\n stride_qm, stride_kb, stride_kh, stride_kn, stride_vb, stride_vh,\n stride_vn, stride_ob, stride_oh, stride_om, nheads, seqlen_q, seqlen_k,\n CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, WINDOW_SIZE: tl.constexpr,\n BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, WRITE_LSE: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n Q_block_ptr = tl.make_block_ptr(base=Q + (off_b * stride_qb + off_h *\n stride_qh), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_qm, 1),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_HEADDIM\n ), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + (off_b * stride_kb + off_h *\n stride_kh), shape=(BLOCK_HEADDIM, seqlen_k), strides=(1, stride_kn),\n offsets=(0, 0), block_shape=(BLOCK_HEADDIM, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + (off_b * stride_vb + off_h *\n stride_vh), shape=(seqlen_k, BLOCK_HEADDIM), strides=(stride_vn, 1),\n offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M:\n q = tl.load(Q_block_ptr)\n else:\n q = tl.load(Q_block_ptr, boundary_check=(0,), padding_option='zero')\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, softmax_scale,\n K_block_ptr, V_block_ptr, start_m, offs_m, offs_n, seqlen_k,\n WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 1)\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, softmax_scale,\n K_block_ptr, V_block_ptr, start_m, offs_m, offs_n, seqlen_k,\n WINDOW_SIZE, BLOCK_M, BLOCK_N, EVEN_M & EVEN_N, 3)\n if WRITE_LSE:\n l_ptrs = L + off_hb * seqlen_q + offs_m\n tl.store(l_ptrs, m_i + tl.math.log2(l_i))\n acc = acc / l_i[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc)\n else:\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_local_attn2.py" }, { "uuid": "fa4480e1-677b-4342-962a-c8f709e3fe8b", "file_name": "triton_call_test.py", "repo_name": "jax-ml/jax-triton", "file_path": "tests/triton_call_test.py", "commit_hash": "859cc392bec876d132bd0790ea6c00b6c246dd2b", "starcount": 0, "input": "@triton.jit\ndef add_scalar_kernel(x_ptr, y, output_ptr):\n tl.store(output_ptr, tl.load(x_ptr) + y)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Low Latency", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/jax-ml/jax-triton/blob/859cc392bec876d132bd0790ea6c00b6c246dd2b/tests/triton_call_test.py" }, { "uuid": "63cb7c43-5317-4ccc-88d2-92d74f1aa420", "file_name": "masked_load_store.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/masked_load_store.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef mstore2d(registers, REG_ROWS: tl.constexpr, REG_COLS: tl.constexpr,\n o_base, o_start_row, o_start_col, o_rows, o_cols, stride_row, stride_col):\n off_rows = tl.arange(0, REG_ROWS) + o_start_row\n off_cols = tl.arange(0, REG_COLS) + o_start_col\n o_ptrs = o_base + off_rows[:, None] * stride_row + off_cols[None, :\n ] * stride_col\n o_ptrs_mask = tl.full([REG_ROWS, REG_COLS], 1, dtype=tl.int1)\n row_overflow = o_start_row + REG_ROWS - o_rows\n if row_overflow > 0:\n o_ptrs_mask = o_ptrs_mask & (off_rows[:, None] < o_rows)\n col_overflow = o_start_col + REG_COLS - o_cols\n if col_overflow > 0:\n o_ptrs_mask = o_ptrs_mask & (off_cols[None, :] < o_cols)\n tl.store(o_ptrs, registers, mask=o_ptrs_mask)\n return o_ptrs, o_ptrs_mask\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/masked_load_store.py" }, { "uuid": "5af2a241-3541-414f-90b4-b233dbb92a70", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps) for BK in [32, 64] for BV in [64, 128] for num_warps in [2, \n 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_rwkv6_bwd_kernel_inter(q, k, v, h, gi, ge, u, do, dh, dA, dq, dk,\n dq2, dk2, dg, du, offsets, indices, scale, T: tl.constexpr, H: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.\n constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(ge + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_gi = tl.make_block_ptr(gi + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(gi + i_bh * T * K + (min(T,\n i_t * BT + BT) - 1) * K + o_k, BK), BK)\n else:\n p_gk = tl.make_block_ptr(ge + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_gi = tl.make_block_ptr(gi + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(gi + (bos + min(T, i_t * BT +\n BT) - 1) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_dgk = tl.zeros([BK], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * NT * K * V + i_t * K * V, (V,\n K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bh * NT * K * V + i_t * K * V,\n (V, K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dgk += tl.sum(b_h * b_dh, axis=0)\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype))\n b_dk += tl.dot(b_v, b_dh.to(b_v.dtype))\n b_dgk *= tl.exp(b_gn)\n b_dq *= scale\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_gi = tl.load(p_gi, boundary_check=(0, 1))\n b_dq = b_dq * tl.exp(b_gk)\n b_dk = b_dk * tl.exp(b_gn[None, :] - b_gi)\n o_i = tl.arange(0, BT)\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dA_dig = dA + (i_bh * T + i_t * BT + o_i) * BT + o_i\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dA_dig = dA + ((bos + i_t * BT + o_i) * H + i_h) * BT + o_i\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dgk += tl.sum(b_dk * b_k, axis=0)\n b_dq += tl.load(p_dq, boundary_check=(0, 1))\n b_dk += tl.load(p_dk, boundary_check=(0, 1))\n b_dg = b_q * b_dq - b_k * b_dk\n b_dg = b_dg - tl.cumsum(b_dg, axis=0) + tl.sum(b_dg, axis=0)[None, :\n ] + b_dgk[None, :] - b_q * b_dq\n b_dA_dig = tl.load(p_dA_dig, mask=i_t * BT + o_i < T, other=0)\n p_u = tl.make_block_ptr(u + i_h * K, (K,), (1,), (i_k * BK,), (BK,), (0,))\n b_u = tl.load(p_u, boundary_check=(0,))\n b_dq += b_dA_dig[:, None] * b_u[None, :] * b_k\n b_dk += b_dA_dig[:, None] * b_u[None, :] * b_q\n b_du = tl.sum(b_dA_dig[:, None] * b_q * b_k, axis=0)\n p_du = tl.make_block_ptr(du + (i_tg * H + i_h) * K, (K,), (1,), (i_k *\n BK,), (BK,), (0,))\n tl.store(p_du, b_du, boundary_check=(0,))\n if HEAD_FIRST:\n p_dq = tl.make_block_ptr(dq2 + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk2 + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_dq = tl.make_block_ptr(dq2 + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk2 + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "5850800a-a6b5-4982-b610-acbd6bb5f405", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _inner_paged_attn_unroll_8_kernel(q, k_cache, v_cache, stride_km,\n block_base_ptrs, base_offs_kv, alibi_slope, block_offs, seq_len, qkv,\n qk_max, exp_sum, BLOCK_SIZE: tl.constexpr, LO: tl.constexpr, HI: tl.\n constexpr):\n for block_idx in range(LO, HI, 8):\n offs_kv_0 = tl.load(block_base_ptrs + block_idx + 0\n ) * stride_km + base_offs_kv\n offs_kv_1 = tl.load(block_base_ptrs + block_idx + 1\n ) * stride_km + base_offs_kv\n offs_kv_2 = tl.load(block_base_ptrs + block_idx + 2\n ) * stride_km + base_offs_kv\n offs_kv_3 = tl.load(block_base_ptrs + block_idx + 3\n ) * stride_km + base_offs_kv\n offs_kv_4 = tl.load(block_base_ptrs + block_idx + 4\n ) * stride_km + base_offs_kv\n offs_kv_5 = tl.load(block_base_ptrs + block_idx + 5\n ) * stride_km + base_offs_kv\n offs_kv_6 = tl.load(block_base_ptrs + block_idx + 6\n ) * stride_km + base_offs_kv\n offs_kv_7 = tl.load(block_base_ptrs + block_idx + 7\n ) * stride_km + base_offs_kv\n k_0 = tl.load(k_cache + offs_kv_0)\n k_1 = tl.load(k_cache + offs_kv_1)\n k_2 = tl.load(k_cache + offs_kv_2)\n k_3 = tl.load(k_cache + offs_kv_3)\n k_4 = tl.load(k_cache + offs_kv_4)\n k_5 = tl.load(k_cache + offs_kv_5)\n k_6 = tl.load(k_cache + offs_kv_6)\n k_7 = tl.load(k_cache + offs_kv_7)\n v_0 = tl.load(v_cache + offs_kv_0)\n v_1 = tl.load(v_cache + offs_kv_1)\n v_2 = tl.load(v_cache + offs_kv_2)\n v_3 = tl.load(v_cache + offs_kv_3)\n v_4 = tl.load(v_cache + offs_kv_4)\n v_5 = tl.load(v_cache + offs_kv_5)\n v_6 = tl.load(v_cache + offs_kv_6)\n v_7 = tl.load(v_cache + offs_kv_7)\n _qk_0 = tl.sum((q[None, :] * k_0).to(tl.float32), axis=1)\n _qk_1 = tl.sum((q[None, :] * k_1).to(tl.float32), axis=1)\n _qk_2 = tl.sum((q[None, :] * k_2).to(tl.float32), axis=1)\n _qk_3 = tl.sum((q[None, :] * k_3).to(tl.float32), axis=1)\n _qk_4 = tl.sum((q[None, :] * k_4).to(tl.float32), axis=1)\n _qk_5 = tl.sum((q[None, :] * k_5).to(tl.float32), axis=1)\n _qk_6 = tl.sum((q[None, :] * k_6).to(tl.float32), axis=1)\n _qk_7 = tl.sum((q[None, :] * k_7).to(tl.float32), axis=1)\n if alibi_slope is not None:\n _qk_0 += alibi_slope * ((block_idx + 0) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_1 += alibi_slope * ((block_idx + 1) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_2 += alibi_slope * ((block_idx + 2) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_3 += alibi_slope * ((block_idx + 3) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_4 += alibi_slope * ((block_idx + 4) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_5 += alibi_slope * ((block_idx + 5) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_6 += alibi_slope * ((block_idx + 6) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_7 += alibi_slope * ((block_idx + 7) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_max = tl.maximum(tl.max(_qk_0, axis=0), qk_max)\n _qk_max = tl.maximum(tl.max(_qk_1, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_2, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_3, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_4, axis=0), qk_max)\n _qk_max = tl.maximum(tl.max(_qk_5, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_6, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_7, axis=0), _qk_max)\n exp_tmp = tl.exp(_qk_0 - _qk_max) + tl.exp(_qk_1 - _qk_max) + tl.exp(\n _qk_2 - _qk_max) + tl.exp(_qk_3 - _qk_max) + tl.exp(_qk_4 - _qk_max\n ) + tl.exp(_qk_5 - _qk_max) + tl.exp(_qk_6 - _qk_max) + tl.exp(\n _qk_7 - _qk_max)\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(exp_tmp, axis=0)\n qkv_sum_tmp = tl.exp(_qk_0[:, None] - _qk_max).to(v_cache.dtype.\n element_ty) * v_0 + tl.exp(_qk_1[:, None] - _qk_max).to(v_cache\n .dtype.element_ty) * v_1 + tl.exp(_qk_2[:, None] - _qk_max).to(\n v_cache.dtype.element_ty) * v_2 + tl.exp(_qk_3[:, None] - _qk_max\n ).to(v_cache.dtype.element_ty) * v_3 + tl.exp(_qk_4[:, None] -\n _qk_max).to(v_cache.dtype.element_ty) * v_4 + tl.exp(_qk_5[:,\n None] - _qk_max).to(v_cache.dtype.element_ty) * v_5 + tl.exp(\n _qk_6[:, None] - _qk_max).to(v_cache.dtype.element_ty\n ) * v_6 + tl.exp(_qk_7[:, None] - _qk_max).to(v_cache.dtype.\n element_ty) * v_7\n qkv = (qkv * (exp_sum * tl.exp(qk_max - _qk_max)) + qkv_sum_tmp\n ) / _exp_sum\n qk_max = _qk_max\n exp_sum = _exp_sum\n return qkv, qk_max, exp_sum\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "b88cea39-85a6-4298-a841-7a49f83348ed", "file_name": "dequant.py", "repo_name": "AutoGPTQ/AutoGPTQ", "file_path": "auto_gptq/nn_modules/triton_utils/dequant.py", "commit_hash": "6689349625de973b9ee3016c28c11f32acf7f02c", "starcount": 0, "input": "@triton.autotune(DEFAULT_DEQUANT_CONFIGS, key=['numels'])\n@triton.jit\ndef dequant_kernel_248(g_idx_ptr, scales_ptr, qweight_ptr, qzeros_ptr,\n out_ptr, numels, maxq: tl.constexpr, bits: tl.constexpr, outfeatures:\n tl.constexpr, num_groups: tl.constexpr, X_BLOCK: tl.constexpr):\n xoffset = tl.program_id(0) * X_BLOCK\n x_index = xoffset + tl.arange(0, X_BLOCK)\n xmask = x_index < numels\n row_idx = x_index // outfeatures\n col_idx = x_index % outfeatures\n elements_per_feature: tl.constexpr = 32 // bits\n g_idx = tl.load(g_idx_ptr + row_idx, None, eviction_policy='evict_last')\n qweights = tl.load(qweight_ptr + (col_idx + outfeatures * (row_idx //\n elements_per_feature)), None)\n wf_weights = row_idx % elements_per_feature * bits\n wf_zeros = col_idx % elements_per_feature * bits\n tmp1 = g_idx + num_groups\n tmp2 = g_idx < 0\n tl.device_assert(g_idx >= 0, 'index out of bounds: 0 <= tmp0 < 0')\n groups = tl.where(tmp2, tmp1, g_idx)\n scales = tl.load(scales_ptr + (col_idx + outfeatures * groups), None).to(tl\n .float32)\n weights = qweights >> wf_weights\n weights = weights & maxq\n qzero_ncols: tl.constexpr = outfeatures // elements_per_feature\n qzeros = tl.load(qzeros_ptr + (qzero_ncols * groups + col_idx //\n elements_per_feature), None, eviction_policy='evict_last')\n zeros = qzeros >> wf_zeros\n zeros = zeros & maxq\n zeros = zeros + 1\n weights = weights - zeros\n weights = weights.to(tl.float32)\n weights = scales * weights\n tl.store(out_ptr + x_index, weights, mask=xmask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/AutoGPTQ/AutoGPTQ/blob/6689349625de973b9ee3016c28c11f32acf7f02c/auto_gptq/nn_modules/triton_utils/dequant.py" }, { "uuid": "49d86003-ce5d-4605-a9f2-3f4ce9c8722f", "file_name": "fused_attention.py", "repo_name": "bortkomencw/jax-triton", "file_path": "examples/fused_attention.py", "commit_hash": "abfc627619f36f289d72d61bb16e1c9a222d0609", "starcount": 0, "input": "@triton.jit\ndef fused_attention_kernel(q_ptr, k_ptr, v_ptr, tmp_ptr, l_ptr, m_ptr,\n out_ptr, stride_qz: tl.constexpr, stride_qh: tl.constexpr, stride_qm:\n tl.constexpr, stride_qk: tl.constexpr, stride_kz: tl.constexpr,\n stride_kh: tl.constexpr, stride_kk: tl.constexpr, stride_kn: tl.\n constexpr, stride_vz: tl.constexpr, stride_vh: tl.constexpr, stride_vk:\n tl.constexpr, stride_vn: tl.constexpr, stride_oz: tl.constexpr,\n stride_oh: tl.constexpr, stride_om: tl.constexpr, stride_on: tl.\n constexpr, z: tl.constexpr, h: tl.constexpr, n_ctx: tl.constexpr,\n block_m: tl.constexpr, block_dmodel: tl.constexpr, block_n: tl.constexpr):\n \"\"\"Flash attention kernel.\"\"\"\n start_qm = tl.program_id(0)\n off_hz = tl.program_id(1)\n offs_m = start_qm * block_m + tl.arange(0, block_m)\n offs_n = tl.arange(0, block_n)\n offs_d = tl.arange(0, block_dmodel)\n off_q = off_hz * stride_qh + offs_m[:, None] * stride_qm + offs_d[None, :\n ] * stride_qk\n off_k = off_hz * stride_qh + offs_n[None, :] * stride_kn + offs_d[:, None\n ] * stride_kk\n off_v = off_hz * stride_qh + offs_n[:, None] * stride_qm + offs_d[None, :\n ] * stride_qk\n q_ptrs = q_ptr + off_q\n k_ptrs = k_ptr + off_k\n v_ptrs = v_ptr + off_v\n t_ptrs = tmp_ptr + off_hz * n_ctx + offs_m\n acc = tl.zeros([block_m, block_dmodel], dtype=tl.float32)\n m_i = tl.zeros([block_m], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([block_m], dtype=tl.float32)\n q = tl.load(q_ptrs)\n for start_n in range(0, start_qm + 1):\n k = tl.load(k_ptrs)\n qk = tl.dot(q, k)\n qk += tl.where(offs_m[:, None] >= start_n * block_n + offs_n[None,\n :], 0, float('-inf'))\n m_ij = tl.max(qk, 1)\n p = tl.exp(qk - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n alpha = tl.exp(m_i - m_i_new)\n beta = tl.exp(m_ij - m_i_new)\n l_i_new = alpha * l_i + beta * l_ij\n p_scale = beta / l_i_new\n p = p * p_scale[:, None]\n p = p.to(tl.float16)\n acc_scale = l_i / l_i_new * alpha\n tl.store(t_ptrs, acc_scale)\n acc_scale = tl.load(t_ptrs)\n acc = acc * acc_scale[:, None]\n v = tl.load(v_ptrs)\n acc += tl.dot(p, v)\n k_ptrs += block_n * stride_kn\n v_ptrs += block_n * stride_vk\n l_i = l_i_new\n m_i = m_i_new\n start_qm = tl.program_id(0)\n offs_m = start_qm * block_m + tl.arange(0, block_m)\n l_ptrs = l_ptr + off_hz * n_ctx + offs_m\n m_ptrs = m_ptr + off_hz * n_ctx + offs_m\n tl.store(l_ptrs, l_i)\n tl.store(m_ptrs, m_i)\n offs_n = tl.arange(0, block_dmodel)\n off_out = off_hz * stride_oh + offs_m[:, None] * stride_om + offs_n[None, :\n ] * stride_on\n out_ptrs = out_ptr + off_out\n tl.store(out_ptrs, acc)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/bortkomencw/jax-triton/blob/abfc627619f36f289d72d61bb16e1c9a222d0609/examples/fused_attention.py" }, { "uuid": "f2dadc40-d715-428a-a34d-6968f5971b95", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_delta_rule_bwd_kernel_dqkw(q, k, v, h, do, dh, dq, dk, dv, dw,\n offsets, indices, scale, T: tl.constexpr, H: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr, NT: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.\n constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k * BK,\n i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H * K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_dw = tl.zeros([BT, BK], dtype=tl.float32)\n b_ds = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * NT * K * V + i_t * K * V, (V,\n K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bh * NT * K * V + i_t * K * V,\n (V, K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_ds += tl.dot(b_do, tl.trans(b_v), allow_tf32=False)\n b_dq += tl.dot(b_do, b_h, allow_tf32=False)\n b_dk += tl.dot(b_v, b_dh, allow_tf32=False)\n b_dv = tl.load(p_dv, boundary_check=(0, 1))\n b_dw += tl.dot(b_dv.to(b_v.dtype), b_h.to(b_v.dtype), allow_tf32=False)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_ds = tl.where(o_i[:, None] >= o_i[None, :], b_ds, 0).to(b_q.dtype)\n b_dq += tl.dot(b_ds, b_k, allow_tf32=False)\n b_dq *= scale\n b_dk += tl.trans(tl.dot(b_q, b_ds, allow_tf32=False))\n if HEAD_FIRST:\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dw, -b_dw.to(p_dw.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/chunk.py" }, { "uuid": "1541bbe9-40db-47b2-be52-64a94c59d7fe", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4)], key=['BK', 'BV'])\n@triton.jit\ndef fused_recurrent_rwkv6_bwd_kernel_dq(k, v, w, u, do, dq, dq1, h0,\n offsets, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n REVERSE: tl.constexpr, USE_INITIAL_STATE: tl.constexpr, USE_OFFSETS: tl\n .constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.\n int64), tl.program_id(2).to(tl.int64)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n o_k = i_k * BK + tl.arange(0, BK)\n o_v = i_v * BV + tl.arange(0, BV)\n if HEAD_FIRST:\n p_k = k + i_nh * T * K + ((T - 1) * K if REVERSE else 0) + o_k\n p_v = v + i_nh * T * V + ((T - 1) * V if REVERSE else 0) + o_v\n p_w = w + i_nh * T * K + ((T - 1) * K if REVERSE else 0) + o_k\n p_do = do + i_nh * T * V + ((T - 1) * V if REVERSE else 0) + o_v\n p_dq = dq + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if REVERSE else\n 0) + o_k\n p_dq1 = dq1 + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if\n REVERSE else 0) + o_k\n else:\n p_k = k + (bos + (T - 1 if REVERSE else 0)) * H * K + i_h * K + o_k\n p_v = v + (bos + (T - 1 if REVERSE else 0)) * H * V + i_h * V + o_v\n p_w = w + (bos + (T - 1 if REVERSE else 0)) * H * K + i_h * K + o_k\n p_do = do + (bos + (T - 1 if REVERSE else 0)) * H * V + i_h * V + o_v\n p_dq = dq + (i_v * all + bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + o_k\n p_dq1 = dq1 + (i_v * all + bos + (T - 1 if REVERSE else 0)\n ) * H * K + i_h * K + o_k\n p_u = u + i_h * K + o_k\n mask_k = o_k < K\n mask_v = o_v < V\n mask_h = mask_k[:, None] & mask_v[None, :]\n b_u = tl.load(p_u, mask=mask_k, other=0).to(tl.float32)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + o_k[:, None] * V + o_v[None, :]\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_w = tl.load(p_w, mask=mask_k, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n b_kv = b_k[:, None] * b_v[None, :]\n b_hq = b_h * b_do[None, :]\n b_dq = tl.sum(b_hq + b_kv * b_u[:, None] * b_do[None, :], 1) * scale\n b_dq1 = tl.sum(b_hq, 1)\n b_h = b_h * tl.exp(b_w)[:, None]\n b_h += b_kv\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), mask=mask_k)\n tl.store(p_dq1, b_dq1.to(p_dq1.dtype.element_ty), mask=mask_k)\n p_k += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_w += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_do += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_dq += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_dq1 += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/fused_recurrent.py" }, { "uuid": "081c52c9-4bb1-427c-bd83-d90875518644", "file_name": "rwkv_log.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/rwkv_log.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef wkv_triton_log_space_forward_kernel(w_ptr, w_s_c, u_ptr, u_s_c, k_ptr,\n k_s_b, k_s_t, k_s_c, v_ptr, v_s_b, v_s_t, v_s_c, state_ptr, state_s_b,\n state_s_abe, state_s_c, wkv_ptr, wkv_s_b, wkv_s_t, wkv_s_c,\n state_out_ptr, state_out_s_b, state_out_s_abe, state_out_s_t,\n state_out_s_c, chans, tsz, eps: tl.constexpr, log_eps: tl.constexpr,\n normalize: tl.constexpr, BLOCK_SIZE_C: tl.constexpr):\n b_idx = tl.program_id(0)\n c_idx = tl.program_id(1)\n cs = c_idx * BLOCK_SIZE_C + tl.arange(0, BLOCK_SIZE_C)\n cmask = cs < chans\n k_ptr = k_ptr + b_idx * k_s_b\n v_ptr = v_ptr + b_idx * v_s_b\n ln_alpha_p_ptr = state_ptr + b_idx * state_s_b\n ln_alpha_m_ptr = state_ptr + b_idx * state_s_b + state_s_abe\n ln_beta_ptr = state_ptr + b_idx * state_s_b + 2 * state_s_abe\n wkv_ptr = wkv_ptr + b_idx * wkv_s_b\n ln_alpha_p_out_ptr = state_out_ptr + b_idx * state_out_s_b\n ln_alpha_m_out_ptr = (state_out_ptr + b_idx * state_out_s_b +\n state_out_s_abe)\n ln_beta_out_ptr = (state_out_ptr + b_idx * state_out_s_b + 2 *\n state_out_s_abe)\n ln_alpha_p = tl.load(ln_alpha_p_ptr + cs * state_s_c, mask=cmask).to(tl\n .float32)\n ln_alpha_m = tl.load(ln_alpha_m_ptr + cs * state_s_c, mask=cmask).to(tl\n .float32)\n ln_beta = tl.load(ln_beta_ptr + cs * state_s_c, mask=cmask).to(tl.float32)\n w = tl.load(w_ptr + cs * w_s_c, mask=cmask).to(tl.float32)\n u = tl.load(u_ptr + cs * u_s_c, mask=cmask).to(tl.float32)\n for t in range(tsz):\n kt = tl.load(k_ptr + t * k_s_t + cs * k_s_c, mask=cmask).to(tl.float32)\n vt = tl.load(v_ptr + t * v_s_t + cs * v_s_c, mask=cmask).to(tl.float32)\n vt_p = tl.maximum(vt, 0) + eps\n vt_m = tl.maximum(-vt, 0) + eps\n ln_v_p = tl.log(vt_p)\n ln_v_m = tl.log(vt_m)\n if normalize:\n ln_alpha_pm = tl.minimum(ln_alpha_p, ln_alpha_m) - eps\n ln_alpha_p = logsubexp(ln_alpha_p, ln_alpha_pm, log_eps)\n ln_alpha_m = logsubexp(ln_alpha_m, ln_alpha_pm, log_eps)\n ln_wkv_p = logaddexp(u + kt + ln_v_p, ln_alpha_p) - logaddexp(u +\n kt, ln_beta)\n ln_wkv_m = logaddexp(u + kt + ln_v_m, ln_alpha_m) - logaddexp(u +\n kt, ln_beta)\n wkv = tl.exp(ln_wkv_p) - tl.exp(ln_wkv_m)\n tl.store(wkv_ptr + t * wkv_s_t + cs * wkv_s_c, wkv, mask=cmask)\n ln_alpha_p = logaddexp(w + ln_alpha_p, kt + ln_v_p)\n ln_alpha_m = logaddexp(w + ln_alpha_m, kt + ln_v_m)\n ln_beta = logaddexp(w + ln_beta, kt)\n tl.store(ln_alpha_p_out_ptr + t * state_out_s_t + cs *\n state_out_s_c, ln_alpha_p, mask=cmask)\n tl.store(ln_alpha_m_out_ptr + t * state_out_s_t + cs *\n state_out_s_c, ln_alpha_m, mask=cmask)\n tl.store(ln_beta_out_ptr + t * state_out_s_t + cs * state_out_s_c,\n ln_beta, mask=cmask)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/rwkv_log.py" }, { "uuid": "ad805737-e12a-4994-9da0-2020700b1dad", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=[Config({'BLOCK_SIZE': 512}), Config({'BLOCK_SIZE':\n 1024}), Config({'BLOCK_SIZE': 2048}), Config({'BLOCK_SIZE': 4096}),\n Config({'BLOCK_SIZE': 8192})], key=['N'])\n@triton.jit\ndef _kernel_scale_fp8_row(A, x_scale, w_scale, scaled_out, M, N, stride_am,\n stride_an, stride_om, stride_on, BLOCK_SIZE: tl.constexpr) ->None:\n \"\"\"\n Scale each row of A by x_scale and each column of A by w_scale.\n\n Args:\n A (Tensor): [m, n] Input tensor to scale.\n x_scale (Tensor): [m] Row-wise scale tensor.\n w_scale (Tensor): [n] Col-wise scale tensor.\n scaled_out (Tensor): [m, n] Output tensor.\n M (int): Number of rows.\n N (int): Number of columns.\n stride_am (int): Stride of m dimension of A.\n stride_an (int): Stride of n dimension of A.\n stride_om (int): Stride of m dimension of output.\n stride_on (int): Stride of n dimension of output.\n BLOCK_SIZE (int): Block size for data loads.\n \"\"\"\n pid = tl.program_id(0)\n n_offset = tl.arange(0, BLOCK_SIZE)\n row_scale = tl.load(x_scale + pid)\n for _k in range(0, tl.cdiv(N, BLOCK_SIZE)):\n a = tl.load(A + pid * stride_am + n_offset * stride_an)\n col_scale = tl.load(w_scale + n_offset)\n scaled_a = a * row_scale * col_scale\n tl.store(scaled_out + pid * stride_om + n_offset * stride_on,\n scaled_a, mask=n_offset < N)\n n_offset += BLOCK_SIZE\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "fed5f596-06e2-4fbb-aadc-c5659115de85", "file_name": "_quantize.py", "repo_name": "IBM/qattn", "file_path": "qattn/nn/functional/_quantize.py", "commit_hash": "07ceda0aceb9afd299d622325944c0c0471827fe", "starcount": 0, "input": "@triton.jit\ndef quantize(x, scale, qmin, qmax) ->tl.tensor:\n \"\"\"Quantize the tensor given quantization scale and data type.\n\n Args:\n x (tl.tensor): floating-point tensor\n scale (tl.tensor): quantization scale factor.\n qmin (Number): quantization minimum range.\n qmax (Number): quantization maximum range\n\n Returns:\n tl.tensor: rounded and clamped tensor.\n Note: this is still in floating point as we can't pass dtype to function\n\n Example:\n \n out = quantize(out, scale, -128, 127).to(tl.int8)\n \"\"\"\n return clamp(tl.math.round(x / scale), qmin, qmax)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/IBM/qattn/blob/07ceda0aceb9afd299d622325944c0c0471827fe/qattn/nn/functional/_quantize.py" }, { "uuid": "1e3f0da1-6b39-42d3-9727-50923dfa01bf", "file_name": "masked_load_store.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/masked_load_store.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef mload1d(REGS: tl.constexpr, i_base, i_start, i_nums):\n offs = tl.arange(0, REGS) + i_start\n i_ptrs = i_base + offs\n overflow = i_start + REGS - i_nums\n i_ptrs_mask = tl.full([REGS], 1, dtype=tl.int1)\n i_ptrs_mask = i_ptrs_mask & (offs < i_nums)\n return tl.load(i_ptrs, mask=i_ptrs_mask, other=0.0)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/masked_load_store.py" }, { "uuid": "c4a78501-d4c6-4271-9b23-2445016fa667", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef silu(x):\n return x * tl.sigmoid(x)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "7098cab5-9d5a-47f3-ba34-1521893d3e8b", "file_name": "outer_softmax_online.py", "repo_name": "iclementine/optimize_softmax", "file_path": "outer_softmax_online.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef prev_multiple_of(a, b):\n return tl.cdiv(a, b) * b - b\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/outer_softmax_online.py" }, { "uuid": "980683e0-409c-46c6-a72e-852bc66ab9ba", "file_name": "kl.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/kl.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_kl_backward(target_ptr, target_stride, grad_output_ptr,\n grad_output_stride, num_classes, BLOCK_SIZE: tl.constexpr, log_target:\n tl.constexpr=False):\n row_id = tl.program_id(0).to(tl.int64)\n target_ptr += row_id * target_stride\n grad_output_ptr += row_id * grad_output_stride\n base_offsets = tl.arange(0, BLOCK_SIZE)\n mask = base_offsets < num_classes\n for i in range(0, num_classes, BLOCK_SIZE):\n offsets = i + base_offsets\n mask = offsets < num_classes\n target_val = tl.load(target_ptr + offsets, mask=mask, other=0.0)\n if not log_target:\n grad = target_val * -1\n else:\n grad = -tl.exp(target_val)\n tl.store(grad_output_ptr + offsets, grad, mask=mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/kl.py" }, { "uuid": "16cfa389-a9f5-4b12-9d71-271ca2751f42", "file_name": "prefix_prefill.py", "repo_name": "IBM/vllm", "file_path": "vllm/attention/ops/prefix_prefill.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel_alibi(Q, K, V, K_cache, V_cache, B_Loc, sm_scale, k_scale,\n v_scale, B_Start_Loc, B_Seqlen, B_Ctxlen, Alibi_slopes, block_size, x,\n Out, stride_b_loc_b, stride_b_loc_s, stride_qbs, stride_qh, stride_qd,\n stride_kbs, stride_kh, stride_kd, stride_vbs, stride_vh, stride_vd,\n stride_obs, stride_oh, stride_od, stride_k_cache_bs, stride_k_cache_h,\n stride_k_cache_d, stride_k_cache_bl, stride_k_cache_x,\n stride_v_cache_bs, stride_v_cache_h, stride_v_cache_d,\n stride_v_cache_bl, num_queries_per_kv: int, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_DMODEL_PADDED: tl.constexpr, BLOCK_N:\n tl.constexpr):\n cur_batch = tl.program_id(0)\n cur_head = tl.program_id(1)\n start_m = tl.program_id(2)\n cur_kv_head = cur_head // num_queries_per_kv\n cur_batch_ctx_len = tl.load(B_Ctxlen + cur_batch)\n cur_batch_seq_len = tl.load(B_Seqlen + cur_batch)\n cur_batch_in_all_start_index = tl.load(B_Start_Loc + cur_batch)\n block_start_loc = BLOCK_M * start_m\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL_PADDED)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n off_q = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_qbs + cur_head * stride_qh + offs_d[None, :] * stride_qd\n dim_mask = tl.where(tl.arange(0, BLOCK_DMODEL_PADDED) < BLOCK_DMODEL, 1, 0\n ).to(tl.int1)\n q = tl.load(Q + off_q, mask=dim_mask[None, :] & (offs_m[:, None] < \n cur_batch_seq_len - cur_batch_ctx_len), other=0.0)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL_PADDED], dtype=tl.float32)\n alibi_slope = tl.load(Alibi_slopes + cur_head)\n alibi_start_q = tl.arange(0, BLOCK_M) + block_start_loc + cur_batch_ctx_len\n alibi_start_k = 0\n for start_n in range(0, cur_batch_ctx_len, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n bn = tl.load(B_Loc + cur_batch * stride_b_loc_b + (start_n + offs_n\n ) // block_size * stride_b_loc_s, mask=start_n + offs_n <\n cur_batch_ctx_len, other=0)\n off_k = bn[None, :\n ] * stride_k_cache_bs + cur_kv_head * stride_k_cache_h + offs_d[\n :, None] // x * stride_k_cache_d + (start_n + offs_n[None, :]\n ) % block_size * stride_k_cache_bl + offs_d[:, None\n ] % x * stride_k_cache_x\n off_v = bn[:, None\n ] * stride_v_cache_bs + cur_kv_head * stride_v_cache_h + offs_d[\n None, :] * stride_v_cache_d + (start_n + offs_n[:, None]\n ) % block_size * stride_v_cache_bl\n k_load = tl.load(K_cache + off_k, mask=dim_mask[:, None] & (start_n +\n offs_n[None, :] < cur_batch_ctx_len), other=0.0)\n if k_load.dtype.is_fp8():\n k = (k_load.to(tl.float32) * k_scale).to(q.dtype)\n else:\n k = k_load\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n qk = tl.where(start_n + offs_n[None, :] < cur_batch_ctx_len, qk,\n float('-inf'))\n qk *= sm_scale\n alibi = (tl.arange(0, BLOCK_N)[None, :] + alibi_start_k -\n alibi_start_q[:, None]) * alibi_slope\n alibi = tl.where((alibi <= 0) & (alibi_start_q[:, None] <\n cur_batch_seq_len), alibi, float('-inf'))\n qk += alibi\n alibi_start_k += BLOCK_N\n m_ij = tl.max(qk, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n p = tl.math.exp(qk - m_i_new[:, None])\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp(m_i - m_i_new)\n l_i_new = alpha * l_i + l_ij\n acc_scale = alpha\n acc = acc * acc_scale[:, None]\n v_load = tl.load(V_cache + off_v, mask=dim_mask[None, :] & (start_n +\n offs_n[:, None] < cur_batch_ctx_len), other=0.0)\n if v_load.dtype.is_fp8():\n v = (v_load.to(tl.float32) * v_scale).to(q.dtype)\n else:\n v = v_load\n p = p.to(v.dtype)\n acc += tl.dot(p, v, allow_tf32=False)\n l_i = l_i_new\n m_i = m_i_new\n off_k = offs_n[None, :] * stride_kbs + cur_kv_head * stride_kh + offs_d[\n :, None] * stride_kd\n off_v = offs_n[:, None] * stride_vbs + cur_kv_head * stride_vh + offs_d[\n None, :] * stride_vd\n k_ptrs = K + off_k\n v_ptrs = V + off_v\n block_mask = tl.where(block_start_loc < cur_batch_seq_len -\n cur_batch_ctx_len, 1, 0)\n alibi_slope = tl.load(Alibi_slopes + cur_head)\n alibi_start_q = tl.arange(0, BLOCK_M) + block_start_loc + cur_batch_ctx_len\n alibi_start_k = cur_batch_ctx_len\n for start_n in range(0, block_mask * (start_m + 1) * BLOCK_M, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(k_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_kbs, mask=dim_mask[:, None] & (start_n + offs_n[None, :] <\n cur_batch_seq_len - cur_batch_ctx_len), other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k, allow_tf32=False)\n qk *= sm_scale\n qk = tl.where(offs_m[:, None] >= start_n + offs_n[None, :], qk,\n float('-inf'))\n alibi = (tl.arange(0, BLOCK_N)[None, :] + alibi_start_k -\n alibi_start_q[:, None]) * alibi_slope\n alibi = tl.where((alibi <= 0) & (alibi_start_q[:, None] <\n cur_batch_seq_len), alibi, float('-inf'))\n qk += alibi\n alibi_start_k += BLOCK_N\n m_ij = tl.max(qk, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n p = tl.math.exp(qk - m_i_new[:, None])\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp(m_i - m_i_new)\n l_i_new = alpha * l_i + l_ij\n acc_scale = alpha\n acc = acc * acc_scale[:, None]\n v = tl.load(v_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_vbs, mask=dim_mask[None, :] & (start_n + offs_n[:, None] <\n cur_batch_seq_len - cur_batch_ctx_len), other=0.0)\n p = p.to(v.dtype)\n acc += tl.dot(p, v, allow_tf32=False)\n l_i = l_i_new\n m_i = m_i_new\n acc = acc / l_i[:, None]\n off_o = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_obs + cur_head * stride_oh + offs_d[None, :] * stride_od\n out_ptrs = Out + off_o\n tl.store(out_ptrs, acc, mask=dim_mask[None, :] & (offs_m[:, None] < \n cur_batch_seq_len - cur_batch_ctx_len))\n return\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/attention/ops/prefix_prefill.py" }, { "uuid": "87c6037c-67a3-485d-86e0-1ffabb737c08", "file_name": "test_autodiff.py", "repo_name": "srush/triton-autodiff", "file_path": "tests/test_autodiff.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef dcomp2dx(x, b_return):\n _return2 = tl.expand_dims(x, 1)\n bx = zeroslike(x)\n b_return2 = zeroslike(_return2)\n _b_return2 = triton_unbroadcast(b_return * x, _return2.shape)\n return bx\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/tests/test_autodiff.py" }, { "uuid": "1ddbd0b4-73df-450b-8257-024ca9bc7937", "file_name": "lion.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/optim/lion.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE': 128}, num_warps=4),\n triton.Config({'BLOCK_SIZE': 1024}, num_warps=8)], key=['n_elements'],\n restore_value=['p_ptr', 'exp_avg_ptr'])\n@triton.jit\ndef update_fn_kernel(p_ptr, grad_ptr, exp_avg_ptr, lr, wd, beta1, beta2,\n n_elements, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n offset_p_ptr = p_ptr + offsets\n offset_grad_ptr = grad_ptr + offsets\n offset_exp_avg_ptr = exp_avg_ptr + offsets\n p = tl.load(offset_p_ptr, mask=mask)\n grad = tl.load(offset_grad_ptr, mask=mask)\n exp_avg = tl.load(offset_exp_avg_ptr, mask=mask)\n p = p * (1 - lr * wd)\n diff = exp_avg - grad\n update = diff * beta1 + grad\n can_update = update != 0\n update_sign = tl.where(update > 0, -lr, lr)\n p = p + update_sign * can_update\n exp_avg = diff * beta2 + grad\n tl.store(offset_p_ptr, p, mask=mask)\n tl.store(offset_exp_avg_ptr, exp_avg, mask=mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/optim/lion.py" }, { "uuid": "06298522-b30b-4da3-8f8f-fcaa25129441", "file_name": "softmax_online_v2_evict.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v2_evict.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n final_m = tl.max(m, 0)\n z = tl.sum(tl.exp(m - final_m) * z)\n m = final_m\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf'),\n eviction_policy='evict_first').to(output_ptr.dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v2_evict.py" }, { "uuid": "c7a39ace-d71e-493b-bba3-fd7c6be6a34f", "file_name": "matrix_multiplication.py", "repo_name": "gmgu/study-triton", "file_path": "4_2d_grid_and_matmul/matrix_multiplication.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@triton.jit\ndef triton_mm(x_ptr, y_ptr, out_ptr, n: tl.constexpr, m: tl.constexpr, p:\n tl.constexpr, BLOCK_SIZE: tl.constexpr):\n pid0 = tl.program_id(axis=0)\n pid1 = tl.program_id(axis=1)\n x_row = pid0 * BLOCK_SIZE * m + tl.arange(0, m)\n x_col = tl.arange(0, BLOCK_SIZE) * m\n x_offset = x_row[None, :] + x_col[:, None]\n x_mask = tl.core.full((1, m), True, dtype=tl.int1) and (pid0 *\n BLOCK_SIZE + tl.arange(0, BLOCK_SIZE))[:, None] < n\n y_row = pid1 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n y_col = tl.arange(0, m) * p\n y_offset = y_row[None, :] + y_col[:, None]\n y_mask = (pid1 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE))[None, :\n ] < p and tl.core.full((m, 1), True, dtype=tl.int1)\n x = tl.load(x_ptr + x_offset, mask=x_mask, other=0.0)\n y = tl.load(y_ptr + y_offset, mask=y_mask, other=0.0)\n out = tl.dot(x, y, allow_tf32=False)\n out_row = pid0 * BLOCK_SIZE * p + pid1 * BLOCK_SIZE + tl.arange(0,\n BLOCK_SIZE)\n out_col = tl.arange(0, BLOCK_SIZE) * p\n out_offset = out_row[None, :] + out_col[:, None]\n out_mask = (pid1 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE))[None, :\n ] < p and (pid0 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE))[:, None] < n\n tl.store(out_ptr + out_offset, out, mask=out_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/4_2d_grid_and_matmul/matrix_multiplication.py" }, { "uuid": "5a578960-7583-4a26-9bb1-7f85522153a1", "file_name": "quantize.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/quantize.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _floor_log2(x):\n \"\"\"Helper function to efficiently compute floor(log2(x))\n\n Args:\n x (Tensor): FP32 Input tensor to operate on.\n\n Returns:\n Tensor: Floor of log2(x).\n \"\"\"\n FP32_EXP_MASK: tl.constexpr = 2139095040\n FP32_EXP_OFFSET: tl.constexpr = 23\n FP32_EXP_BIAS: tl.constexpr = 127\n x = x.to(tl.int32, bitcast=True) & FP32_EXP_MASK\n x = x >> FP32_EXP_OFFSET\n return (x - FP32_EXP_BIAS).to(tl.float32)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/quantize.py" }, { "uuid": "88abece4-2613-439d-ab06-1e7c8c46fe8d", "file_name": "y_10.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_10.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef tenth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor, block_size:\n tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.constexpr,\n col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST001 = 1.75869118663323\n CONST002 = -1021.9231747532\n CONST004 = 4.58257569495584\n CONST005 = 6.632439808434\n CONST006 = 4.82870805793735\n CONST007 = 4.9743298563255\n CONST008 = 1545.18657853995\n CONST009 = 10.5521471197994\n CONST010 = 12.1657520803952\n CONST011 = 13.264879616868\n CONST013 = 15.7883647328499\n CONST014 = 15.7302121789667\n CONST015 = 16.4144510752435\n CONST016 = 12.8765548211663\n CONST017 = 19.3148322317494\n CONST018 = 16.7271353825295\n CONST019 = 22.862985426232\n CONST020 = 535.268332240943\n CONST021 = 23.213539329519\n CONST022 = 24.6216766128653\n CONST023 = 27.2034486491732\n CONST024 = 541.428124558099\n CONST025 = -994.666978169547\n CONST026 = 33.9852909359329\n CONST027 = 33.9852909359329\n CONST028 = 35.5238206489124\n CONST029 = -984.86706451461\n CONST030 = -4.82870805793735\n CONST031 = 1070.53666448189\n CONST032 = -463.555973561985\n CONST034 = 53.2857309733686\n CONST035 = 53.2857309733686\n CONST036 = 56.3871618715269\n CONST037 = 56.3871618715269\n CONST039 = -1989.33395633909\n CONST041 = -450.224943778107\n CONST042 = 66.9085415301178\n CONST043 = 69.640617988557\n CONST044 = 69.640617988557\n CONST045 = -437.967074894228\n CONST046 = 77.2593289269976\n CONST047 = 78.6510608948335\n CONST049 = -1969.73412902922\n CONST050 = 77.3468749368712\n CONST051 = 1624.2843736743\n CONST054 = 94.7301883970997\n CONST056 = 100.362812295177\n CONST057 = -412.04975427732\n CONST058 = 101.517773354644\n CONST059 = -5.63871618715269\n CONST060 = -406.071093418574\n CONST061 = 109.491768723557\n CONST062 = -393.946825805844\n CONST063 = -902.194589944431\n CONST065 = -386.296644634988\n CONST066 = -386.296644634988\n CONST070 = 4.9743298563255\n CONST071 = 150.074981259369\n CONST074 = 685.526905959165\n CONST075 = -337.668707833581\n CONST076 = -337.668707833581\n CONST077 = 176.178376404427\n CONST078 = 176.592751833137\n CONST079 = 185.708314636152\n CONST080 = -326.441383790078\n CONST081 = -1.60956935264578\n CONST082 = -1.97354559160624\n CONST083 = 196.973412902922\n CONST085 = -824.099508554641\n CONST087 = -1.97354559160624\n CONST088 = -305.867618423396\n CONST089 = -305.867618423396\n CONST090 = 721.755671955545\n CONST091 = -305.867618423396\n CONST092 = -300.731529981477\n CONST093 = -300.731529981477\n CONST094 = -1.75869118663323\n CONST095 = -290.050781013267\n CONST097 = 225.548647486108\n CONST098 = 225.548647486108\n CONST099 = -284.190565191299\n CONST101 = -278.562471954228\n CONST102 = -278.562471954228\n CONST103 = -787.893651611688\n CONST104 = -787.893651611688\n CONST105 = 772.593289269975\n CONST106 = 787.893651611688\n CONST107 = 787.893651611688\n CONST108 = 278.562471954228\n CONST109 = -742.833258544608\n CONST110 = -1.6581099521085\n CONST112 = -1761.78376404427\n CONST113 = -223.028471767059\n CONST114 = -734.07656835178\n CONST116 = -220.222970505534\n CONST117 = 1321.3378230332\n CONST118 = 1321.3378230332\n CONST119 = -203.035546709287\n CONST120 = -1.6581099521085\n CONST121 = -196.973412902922\n CONST122 = -196.973412902922\n CONST123 = -696.40617988557\n CONST125 = 338.322971229162\n CONST126 = -1181.84047741753\n CONST127 = -669.085415301178\n CONST128 = -669.085415301178\n CONST129 = -154.518657853995\n CONST130 = -154.518657853995\n CONST131 = 360.877835977772\n CONST132 = -150.074981259369\n CONST133 = -2707.14062279049\n CONST134 = -146.815313670356\n CONST135 = 880.891882022136\n CONST136 = 1392.81235977114\n CONST137 = 1392.81235977114\n CONST138 = -131.315608601948\n CONST139 = -131.315608601948\n CONST141 = -125.841697431734\n CONST142 = -125.841697431734\n CONST143 = -122.415518921279\n CONST145 = 406.071093418574\n CONST146 = -103.107953136506\n CONST147 = -103.107953136506\n CONST148 = -101.517773354644\n CONST149 = -98.486706451461\n CONST150 = 412.04975427732\n CONST151 = -94.7301883970997\n CONST152 = -1114.24988781691\n CONST153 = -88.2963759165686\n CONST154 = -1624.2843736743\n CONST155 = -82.8889148474622\n CONST156 = -82.8889148474622\n CONST158 = -590.920238708766\n CONST159 = -77.3468749368713\n CONST160 = -77.2593289269975\n CONST161 = 2486.66744542387\n CONST162 = -2626.31217203896\n CONST165 = -571.272421632637\n CONST166 = -56.2781179722634\n CONST167 = -49.2433532257305\n CONST168 = -49.2433532257305\n CONST169 = 984.86706451461\n CONST170 = -541.428124558099\n CONST171 = -24.6216766128653\n CONST172 = -22.862985426232\n CONST173 = -16.4144510752435\n CONST174 = -15.7883647328499\n CONST175 = -14.0695294930659\n CONST176 = -13.264879616868\n CONST177 = -11.2774323743054\n CONST178 = -14.5025390506634\n CONST179 = -6.632439808434\n CONST180 = -5.63871618715269\n CONST181 = 1532.8847621298\n CONST182 = -3.21913870529156\n CONST183 = -2.72034486491732\n CONST184 = -1.12774323743054\n VAR05 = x * x * x * x * x\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR00 = VAR05 * VAR05\n VAR01 = VAR05 * VAR06\n VAR02 = VAR06 * VAR06\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR14 = y * y * y * y * y\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR09 = VAR14 * VAR14\n VAR10 = VAR14 * VAR15\n VAR11 = VAR15 * VAR15\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR23 = z * z * z * z * z\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR18 = VAR23 * VAR23\n VAR19 = VAR23 * VAR24\n VAR20 = VAR24 * VAR24\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n Y00 = (CONST023 * VAR01 * z + CONST023 * VAR19 * x + CONST074 * VAR05 *\n VAR23 + CONST080 * VAR03 * VAR25 + CONST080 * VAR07 * VAR21)\n Y01 = y * (CONST002 * VAR07 * VAR22 + CONST010 * VAR01 + CONST045 *\n VAR03 * VAR26 + CONST061 * VAR20 * x + CONST181 * VAR05 * VAR24)\n Y02 = (CONST013 * VAR01 * z + CONST054 * VAR07 * VAR21 + CONST151 *\n VAR03 * VAR25 + CONST174 * VAR19 * x + VAR17 * (-CONST039 * VAR05 *\n VAR25 + CONST039 * VAR07 * VAR23 + CONST099 * VAR03 * z - CONST099 *\n VAR21 * x))\n Y03 = VAR16 * (CONST024 * VAR22 * x + CONST051 * VAR05 * VAR26 + \n CONST133 * VAR07 * VAR24 + CONST159 * VAR03) + y * (CONST095 *\n VAR03 * VAR26 - CONST119 * VAR05 * VAR24 + CONST145 * VAR07 * VAR22 +\n CONST148 * VAR20 * x - CONST178 * VAR01)\n Y04 = CONST009 * VAR01 * z + VAR03 * (CONST076 * VAR17 * z + CONST175 *\n VAR25) + VAR05 * (CONST106 * VAR15 * z + CONST107 * VAR17 * VAR25 +\n CONST167 * VAR23) + VAR07 * (CONST106 * VAR17 * VAR23 + CONST162 *\n VAR15 * VAR25 + CONST175 * VAR21) + x * (CONST009 * VAR19 + \n CONST075 * VAR17 * VAR21 + CONST106 * VAR15 * VAR23)\n Y05 = VAR14 * (CONST077 * VAR05 + CONST112 * VAR07 * VAR26 + CONST135 *\n VAR24 * x) + VAR16 * (-CONST114 * VAR07 * VAR24 + CONST114 * VAR22 *\n x + CONST117 * VAR05 * VAR26 + CONST134 * VAR03) + y * (CONST014 *\n VAR01 + CONST047 * VAR20 * x + CONST116 * VAR05 * VAR24 + CONST141 *\n VAR03 * VAR26)\n Y06 = CONST005 * VAR01 * z + VAR03 * (CONST011 * VAR25 + CONST102 *\n VAR17 * z) + VAR05 * (CONST101 * VAR17 * VAR25 - CONST152 * VAR15 * z\n ) + VAR07 * (CONST108 * VAR17 * VAR23 + CONST109 * VAR13 * z + \n CONST176 * VAR21) + x * (CONST108 * VAR17 * VAR21 - CONST109 *\n VAR13 * VAR25 + CONST152 * VAR15 * VAR23 + CONST179 * VAR19)\n Y07 = VAR12 * (-CONST041 * VAR26 * x + CONST132 * VAR07) + VAR14 * (-\n CONST062 * VAR05 + CONST103 * VAR07 * VAR26 + CONST126 * VAR24 * x\n ) + VAR16 * (CONST083 * VAR05 * VAR26 + CONST121 * VAR03 - CONST158 *\n VAR22 * x + CONST169 * VAR07 * VAR24) + y * (CONST015 * VAR01 + \n CONST138 * VAR07 * VAR22 + CONST149 * VAR05 * VAR24 + CONST168 *\n VAR20 * x)\n Y08 = -CONST182 * VAR01 * z + VAR03 * (CONST016 * VAR25 + CONST129 *\n VAR17 * z) + VAR05 * (CONST017 * VAR23 + CONST032 * VAR17 * VAR25 +\n CONST105 * VAR15 * z) + VAR07 * (CONST008 * VAR15 * VAR25 + \n CONST016 * VAR21 + CONST032 * VAR17 * VAR23 + CONST085 * VAR13 * z\n ) + x * (CONST078 * VAR11 * z + CONST085 * VAR13 * VAR25 + CONST105 *\n VAR15 * VAR23 + CONST129 * VAR17 * VAR21 - CONST182 * VAR19)\n Y09 = CONST018 * VAR01 * y + VAR03 * (CONST042 * VAR26 * y + CONST113 *\n VAR16) + VAR05 * (CONST020 * VAR14 + CONST056 * VAR24 * y + \n CONST128 * VAR16 * VAR26) + VAR07 * (CONST031 * VAR14 * VAR26 + \n CONST042 * VAR22 * y + CONST088 * VAR12 + CONST127 * VAR16 * VAR24\n ) + x * (CONST018 * VAR20 * y + CONST020 * VAR14 * VAR24 + CONST026 *\n VAR10 + CONST088 * VAR12 * VAR26 + CONST113 * VAR16 * VAR22)\n Y10 = (CONST004 * VAR09 + CONST037 * VAR17 * VAR20 + CONST093 * VAR15 *\n VAR22 + CONST131 * VAR13 * VAR24 + CONST147 * VAR11 * VAR26 + \n CONST184 * VAR00 + CONST184 * VAR18 + VAR02 * (CONST036 * VAR17 + \n CONST059 * VAR26) + VAR04 * (CONST092 * VAR15 + CONST098 * VAR17 *\n VAR26 + CONST177 * VAR24) + VAR06 * (CONST063 * VAR15 * VAR26 + \n CONST125 * VAR17 * VAR24 + CONST131 * VAR13 + CONST177 * VAR22) + \n VAR08 * (CONST063 * VAR15 * VAR24 + CONST090 * VAR13 * VAR26 + \n CONST097 * VAR17 * VAR22 + CONST146 * VAR11 + CONST180 * VAR20))\n Y11 = CONST018 * VAR19 * y + VAR21 * (CONST042 * VAR08 * y + CONST113 *\n VAR16) + VAR23 * (CONST020 * VAR14 + CONST056 * VAR06 * y + \n CONST128 * VAR08 * VAR16) + VAR25 * (CONST031 * VAR08 * VAR14 + \n CONST042 * VAR04 * y + CONST091 * VAR12 + CONST127 * VAR06 * VAR16\n ) + z * (CONST018 * VAR02 * y + CONST020 * VAR06 * VAR14 + CONST027 *\n VAR10 + CONST089 * VAR08 * VAR12 + CONST113 * VAR04 * VAR16)\n Y12 = (CONST057 * VAR13 * VAR24 - CONST066 * VAR15 * VAR22 + CONST081 *\n VAR00 - CONST081 * VAR18 - CONST153 * VAR11 * VAR26 + CONST160 *\n VAR17 * VAR20 + VAR02 * (CONST030 * VAR26 + CONST046 * VAR17) + \n VAR04 * (CONST066 * VAR15 - CONST129 * VAR17 * VAR26 + CONST182 *\n VAR24) + VAR06 * (CONST065 * VAR15 * VAR26 + CONST150 * VAR13 - \n CONST182 * VAR22) + VAR08 * (CONST006 * VAR20 - CONST066 * VAR15 *\n VAR24 + CONST130 * VAR17 * VAR22 + CONST153 * VAR11))\n Y13 = VAR12 * (CONST041 * VAR08 * z + CONST071 * VAR25) + VAR14 * (\n CONST062 * VAR23 + CONST107 * VAR08 * VAR25 - CONST126 * VAR06 * z\n ) + VAR16 * (CONST029 * VAR06 * VAR25 - CONST121 * VAR21 + CONST122 *\n VAR08 * VAR23 + CONST158 * VAR04 * z) + y * (-CONST138 * VAR04 *\n VAR25 - CONST149 * VAR06 * VAR23 - CONST168 * VAR02 * z + CONST173 *\n VAR19)\n Y14 = (CONST044 * VAR17 * VAR20 + CONST079 * VAR13 * VAR24 + CONST101 *\n VAR15 * VAR22 + CONST110 * VAR00 + CONST120 * VAR18 + VAR02 * (\n CONST043 * VAR17 + CONST070 * VAR26) + VAR04 * (CONST021 * VAR24 + \n CONST101 * VAR15 + CONST101 * VAR17 * VAR26) + VAR06 * (CONST021 *\n VAR22 + CONST079 * VAR13 + CONST123 * VAR17 * VAR24 + CONST137 *\n VAR15 * VAR26) + VAR08 * (CONST007 * VAR20 + CONST101 * VAR17 *\n VAR22 + CONST136 * VAR15 * VAR24 + CONST152 * VAR13 * VAR26))\n Y15 = VAR14 * (CONST077 * VAR23 + CONST112 * VAR08 * VAR25 + CONST135 *\n VAR06 * z) + VAR16 * (CONST114 * VAR04 * z - CONST114 * VAR06 *\n VAR25 + CONST118 * VAR08 * VAR23 + CONST134 * VAR21) + y * (\n CONST014 * VAR19 + CONST047 * VAR02 * z + CONST116 * VAR06 * VAR23 +\n CONST142 * VAR08 * VAR21)\n Y16 = (CONST001 * VAR18 + CONST094 * VAR00 - CONST139 * VAR15 * VAR22 +\n CONST166 * VAR17 * VAR20 + VAR02 * (CONST019 * VAR26 - CONST166 *\n VAR17) + VAR04 * (CONST022 * VAR24 + CONST104 * VAR17 * VAR26 + \n CONST139 * VAR15) + VAR06 * (-CONST049 * VAR15 * VAR26 + CONST171 *\n VAR22) + VAR08 * (CONST049 * VAR15 * VAR24 + CONST106 * VAR17 *\n VAR22 + CONST172 * VAR20))\n Y17 = VAR16 * (CONST050 * VAR21 - CONST133 * VAR06 * VAR25 + CONST154 *\n VAR08 * VAR23 + CONST170 * VAR04 * z) + y * (CONST058 * VAR02 * z +\n CONST060 * VAR04 * VAR25 - CONST095 * VAR08 * VAR21 + CONST119 *\n VAR06 * VAR23 + CONST178 * VAR19)\n Y18 = (CONST034 * VAR02 * VAR26 + CONST035 * VAR08 * VAR20 + CONST082 *\n VAR00 + CONST087 * VAR18 + CONST155 * VAR04 * VAR24 + CONST156 *\n VAR06 * VAR22 + VAR17 * (CONST025 * VAR04 * VAR26 + CONST025 *\n VAR08 * VAR22 + CONST028 * VAR02 + CONST028 * VAR20 + CONST161 *\n VAR06 * VAR24))\n Y19 = y * (CONST002 * VAR04 * VAR25 + CONST010 * VAR19 + CONST045 *\n VAR08 * VAR21 + CONST061 * VAR02 * z + CONST181 * VAR06 * VAR23)\n Y20 = (-CONST143 * VAR02 * VAR26 + CONST143 * VAR08 * VAR20 + CONST165 *\n VAR04 * VAR24 - CONST165 * VAR06 * VAR22 + CONST183 * VAR00 - \n CONST183 * VAR18)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n tl.store(output_ptr + output_row_offset + 9, Y09, mask=\n output_row_offset + 9 < output_numel)\n tl.store(output_ptr + output_row_offset + 10, Y10, mask=\n output_row_offset + 10 < output_numel)\n tl.store(output_ptr + output_row_offset + 11, Y11, mask=\n output_row_offset + 11 < output_numel)\n tl.store(output_ptr + output_row_offset + 12, Y12, mask=\n output_row_offset + 12 < output_numel)\n tl.store(output_ptr + output_row_offset + 13, Y13, mask=\n output_row_offset + 13 < output_numel)\n tl.store(output_ptr + output_row_offset + 14, Y14, mask=\n output_row_offset + 14 < output_numel)\n tl.store(output_ptr + output_row_offset + 15, Y15, mask=\n output_row_offset + 15 < output_numel)\n tl.store(output_ptr + output_row_offset + 16, Y16, mask=\n output_row_offset + 16 < output_numel)\n tl.store(output_ptr + output_row_offset + 17, Y17, mask=\n output_row_offset + 17 < output_numel)\n tl.store(output_ptr + output_row_offset + 18, Y18, mask=\n output_row_offset + 18 < output_numel)\n tl.store(output_ptr + output_row_offset + 19, Y19, mask=\n output_row_offset + 19 < output_numel)\n tl.store(output_ptr + output_row_offset + 20, Y20, mask=\n output_row_offset + 20 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Transposed Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_10.py" }, { "uuid": "4a890ec8-5225-43c0-953c-6992a9aa4780", "file_name": "fused_bitlinear.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_bitlinear.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'RECOMPUTE_OUTPUT': lambda args: args['Y'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N', 'HAS_DRESIDUAL', 'STORE_DRESIDUAL',\n 'IS_RMS_NORM', 'HAS_BIAS'])\n@triton.jit\ndef layer_norm_bwd_kernel(X, W, B, Y, DY, DX, DW, DB, DRESIDUAL,\n DRESIDUAL_IN, Mean, Rstd, stride_x_row, stride_y_row, stride_dy_row,\n stride_dx_row, stride_dres_row, stride_dres_in_row, M, N, eps,\n rows_per_program, IS_RMS_NORM: tl.constexpr, BLOCK_N: tl.constexpr,\n HAS_DRESIDUAL: tl.constexpr, STORE_DRESIDUAL: tl.constexpr, HAS_WEIGHT:\n tl.constexpr, HAS_BIAS: tl.constexpr, RECOMPUTE_OUTPUT: tl.constexpr):\n row_block_id = tl.program_id(0)\n row_start = row_block_id * rows_per_program\n cols = tl.arange(0, BLOCK_N)\n mask = cols < N\n X += row_start * stride_x_row\n if HAS_DRESIDUAL:\n DRESIDUAL += row_start * stride_dres_row\n if STORE_DRESIDUAL:\n DRESIDUAL_IN += row_start * stride_dres_in_row\n DY += row_start * stride_dy_row\n DX += row_start * stride_dx_row\n if RECOMPUTE_OUTPUT:\n Y += row_start * stride_y_row\n if HAS_WEIGHT:\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n dw = tl.zeros((BLOCK_N,), dtype=tl.float32)\n if RECOMPUTE_OUTPUT and HAS_BIAS:\n b = tl.load(B + cols, mask=mask, other=0.0).to(tl.float32)\n if HAS_BIAS:\n db = tl.zeros((BLOCK_N,), dtype=tl.float32)\n row_end = min((row_block_id + 1) * rows_per_program, M)\n for row in range(row_start, row_end):\n x = tl.load(X + cols, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + cols, mask=mask, other=0).to(tl.float32)\n if not IS_RMS_NORM:\n mean = tl.load(Mean + row)\n rstd = tl.load(Rstd + row)\n xhat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n xhat = tl.where(mask, xhat, 0.0)\n if RECOMPUTE_OUTPUT:\n y = xhat * w if HAS_WEIGHT else xhat\n if HAS_BIAS:\n y = y + b\n scale = 127.0 / tl.maximum(tl.max(tl.abs(y), 0), 1e-05)\n y = tl.math.round(y * scale)\n y = tl.maximum(tl.minimum(y, 127), -128) / scale\n tl.store(Y + cols, y, mask=mask)\n wdy = dy\n if HAS_WEIGHT:\n wdy = dy * w\n dw += dy * xhat\n if HAS_BIAS:\n db += dy\n if not IS_RMS_NORM:\n c1 = tl.sum(xhat * wdy, axis=0) / N\n c2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * c1 + c2)) * rstd\n else:\n c1 = tl.sum(xhat * wdy, axis=0) / N\n dx = (wdy - xhat * c1) * rstd\n if HAS_DRESIDUAL:\n dres = tl.load(DRESIDUAL + cols, mask=mask, other=0).to(tl.float32)\n dx += dres\n if STORE_DRESIDUAL:\n tl.store(DRESIDUAL_IN + cols, dx, mask=mask)\n tl.store(DX + cols, dx, mask=mask)\n X += stride_x_row\n if HAS_DRESIDUAL:\n DRESIDUAL += stride_dres_row\n if STORE_DRESIDUAL:\n DRESIDUAL_IN += stride_dres_in_row\n if RECOMPUTE_OUTPUT:\n Y += stride_y_row\n DY += stride_dy_row\n DX += stride_dx_row\n if HAS_WEIGHT:\n tl.store(DW + row_block_id * N + cols, dw, mask=mask)\n if HAS_BIAS:\n tl.store(DB + row_block_id * N + cols, db, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_bitlinear.py" }, { "uuid": "292f0e36-f8a0-4131-a7e6-00d1bf2210e9", "file_name": "lightseq_async_attn_varlen.py", "repo_name": "EvolvingLMMs-Lab/LongVA", "file_path": "easy_context/dist_flash_attn/lightseq_async_attn_varlen.py", "commit_hash": "76b7c33946936361eeb5a18b2c9fcc5fe63e9434", "starcount": 0, "input": "@triton.jit\ndef _rescale_kernel(peer_m, m, peer_l, l, peer_o, o, L, stride_oz,\n stride_oh, stride_om, stride_on, Z, H, N_CTX, seqlen_q_rounded,\n seqlen_peer_q_rounded, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.\n constexpr, BLOCK_N: tl.constexpr, LAST_STEP: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n o_offset = off_hz * stride_oh\n peer_o_block_ptr = tl.make_block_ptr(base=peer_o + o_offset, shape=(\n N_CTX, BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(\n start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(\n 1, 0))\n o_block_ptr = tl.make_block_ptr(base=o + o_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n peer_m_ptrs = peer_m + off_hz * seqlen_peer_q_rounded + offs_m\n m_ptrs = m + off_hz * seqlen_q_rounded + offs_m\n peer_l_ptrs = peer_l + off_hz * seqlen_peer_q_rounded + offs_m\n l_ptrs = l + off_hz * seqlen_q_rounded + offs_m\n peer_m_i = tl.load(peer_m_ptrs)\n peer_m_i = peer_m_i.to(tl.float32)\n m_i = tl.load(m_ptrs)\n m_i = m_i.to(tl.float32)\n peer_l_i = tl.load(peer_l_ptrs)\n peer_l_i = peer_l_i.to(tl.float32)\n l_i = tl.load(l_ptrs)\n l_i = l_i.to(tl.float32)\n peer_acc = tl.load(peer_o_block_ptr)\n peer_acc = peer_acc.to(tl.float32)\n acc = tl.load(o_block_ptr)\n acc = acc.to(tl.float32)\n lo = 0\n hi = N_CTX\n m_i_sync = tl.maximum(m_i, peer_m_i)\n alpha = tl.math.exp2(m_i - m_i_sync)\n peer_alpha = tl.math.exp2(peer_m_i - m_i_sync)\n acc_scale = l_i * 0 + alpha\n peer_acc_scale = peer_l_i * 0 + peer_alpha\n acc *= acc_scale[:, None]\n peer_acc *= peer_acc_scale[:, None]\n acc += peer_acc\n l_i = l_i * acc_scale + peer_l_i * peer_acc_scale\n tl.store(m_ptrs, m_i_sync)\n tl.store(l_ptrs, l_i)\n if LAST_STEP:\n acc = acc / l_i[:, None]\n L_ptrs = L + off_hz * N_CTX + offs_m\n tl.store(L_ptrs, m_i_sync / 1.44269504 + tl.math.log(l_i))\n tl.store(o_block_ptr, acc.to(tl.bfloat16), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/EvolvingLMMs-Lab/LongVA/blob/76b7c33946936361eeb5a18b2c9fcc5fe63e9434/easy_context/dist_flash_attn/lightseq_async_attn_varlen.py" }, { "uuid": "36831d21-1e3f-457a-b793-a0041c4d3e90", "file_name": "parallel_scan.py", "repo_name": "chengkai-liu/RecBLR", "file_path": "parallel_scan.py", "commit_hash": "66e520c26e28c05a5425ba2e81c9169b7e0176e2", "starcount": 0, "input": "@triton.jit\ndef backward_scan(gates, tokens, outputs, SEQUENCE_LENGTH: tl.constexpr):\n sequence_id = tl.num_programs(axis=1) * tl.program_id(axis=0\n ) + tl.program_id(axis=1)\n forward_strides = tl.arange(0, SEQUENCE_LENGTH\n ) + sequence_id * SEQUENCE_LENGTH\n reverse_strides = tl.num_programs(axis=0) * tl.num_programs(axis=1\n ) * SEQUENCE_LENGTH - 1 - forward_strides\n tokens_ = tl.load(tokens + reverse_strides)\n gates_ = tl.load(gates + reverse_strides)\n tuples = pack64(tokens_, gates_)\n output_tuples_ = tl.associative_scan(tuples, axis=0, combine_fn=\n first_order_op)\n output_tokens_, output_gates_ = unpack64(output_tuples_)\n tl.store(outputs + reverse_strides, output_tokens_)\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengkai-liu/RecBLR/blob/66e520c26e28c05a5425ba2e81c9169b7e0176e2/parallel_scan.py" }, { "uuid": "d0a50eec-53be-4662-90a6-08833c06ea42", "file_name": "modulation.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/ops/modulation.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef triton_modulation_gate_proj(img_ptr, mod_ptr, proj_ptr, output_ptr,\n batch_size, head_size, modulation_size, XBLOCK: tl.constexpr):\n pid = tl.program_id(0)\n xoffset = pid * XBLOCK + tl.arange(0, XBLOCK)[:]\n batch_idx = xoffset // batch_size\n head_dim_idx = xoffset % head_size\n modulation_offset = head_dim_idx + modulation_size * batch_idx\n img = tl.load(img_ptr + xoffset, None).to(tl.float32)\n mod_gate = tl.load(mod_ptr + (modulation_offset + head_size * 2), None,\n eviction_policy='evict_last').to(tl.float32)\n proj = tl.load(proj_ptr + xoffset, None).to(tl.float32)\n output = img + mod_gate * proj\n tl.store(output_ptr + xoffset, output, None)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/ops/modulation.py" }, { "uuid": "377ec787-3a8e-4549-bb1d-3e1b59b3efe5", "file_name": "test_func.py", "repo_name": "makslevental/triton-pp", "file_path": "tests/test_func.py", "commit_hash": "e2b3e2a35d96007fa1ae129432cf8e99f44588a1", "starcount": 0, "input": "@triton.jit\ndef kernel_0123(arg0: (+T.float32), arg1: (+T.float32), arg2: (+T.float32),\n arg3: T.int32):\n v0 = tl.get_program_id(axis='x')\n c32 = arith.constant(64, T.int32)\n v1 = arith.muli(v0, c32)\n v2 = arange(0, 64)\n v3 = splat(v1, (64,))\n v4 = arith.addi(v3, v2)\n v5 = splat(arg3, (64,))\n v6 = arith.cmpi('slt', v4, v5)\n v7 = splat(arg0, (64,))\n v8 = addptr(v7, v4)\n v9 = load(v8, v6, cache='none', evict='normal', is_volatile=False)\n v10 = splat(arg1, (64,))\n v11 = addptr(v10, v4)\n v12 = load(v11, v6, cache='none', evict='normal', is_volatile=False)\n v13 = arith.addf(v9, v12)\n v14 = splat(arg2, (64,))\n v15 = addptr(v14, v4)\n store(v15, v13, v6)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/makslevental/triton-pp/blob/e2b3e2a35d96007fa1ae129432cf8e99f44588a1/tests/test_func.py" }, { "uuid": "41df42df-c59d-449e-99bd-b4e436d8152f", "file_name": "fused_bitlinear.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_bitlinear.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N', 'HAS_RESIDUAL', 'STORE_RESIDUAL_OUT',\n 'IS_RMS_NORM', 'HAS_BIAS'])\n@triton.jit\ndef layer_norm_fwd_kernel_quant(X, Y, W, B, RESIDUAL, RESIDUAL_OUT, Mean,\n Rstd, stride_x_row, stride_y_row, stride_res_row, stride_res_out_row, N,\n eps, IS_RMS_NORM: tl.constexpr, BLOCK_N: tl.constexpr, HAS_RESIDUAL: tl\n .constexpr, STORE_RESIDUAL_OUT: tl.constexpr, HAS_WEIGHT: tl.constexpr,\n HAS_BIAS: tl.constexpr):\n row = tl.program_id(0)\n X += row * stride_x_row\n Y += row * stride_y_row\n if HAS_RESIDUAL:\n RESIDUAL += row * stride_res_row\n if STORE_RESIDUAL_OUT:\n RESIDUAL_OUT += row * stride_res_out_row\n cols = tl.arange(0, BLOCK_N)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n if HAS_RESIDUAL:\n residual = tl.load(RESIDUAL + cols, mask=cols < N, other=0.0).to(tl\n .float32)\n x += residual\n if STORE_RESIDUAL_OUT:\n tl.store(RESIDUAL_OUT + cols, x, mask=cols < N)\n if not IS_RMS_NORM:\n mean = tl.sum(x, axis=0) / N\n tl.store(Mean + row, mean)\n xbar = tl.where(cols < N, x - mean, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n else:\n xbar = tl.where(cols < N, x, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n tl.store(Rstd + row, rstd)\n mask = cols < N\n if HAS_WEIGHT:\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n if HAS_BIAS:\n b = tl.load(B + cols, mask=mask).to(tl.float32)\n x_hat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n y = x_hat * w if HAS_WEIGHT else x_hat\n if HAS_BIAS:\n y = y + b\n scale = 127.0 / tl.maximum(tl.max(tl.abs(y), 0), 1e-05)\n y = tl.math.round(y * scale)\n y = tl.maximum(tl.minimum(y, 127), -128) / scale\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Quantization" ], "Data Type": [ "fp32", "bf16", "int8" ], "Performance Objective": [ "Compute Bound", "Batch-Oriented" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_bitlinear.py" }, { "uuid": "47e6ffc6-ded8-4623-a79b-56645cfcad62", "file_name": "GEMM.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/GEMM.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.autotune(configs=get_cuda_autotune_config(), key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_cm, stride_cn, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr, ALLOWTF32: tl.constexpr, PRECISIONMATCH: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (M, K), B has shape (K, N) and C has shape (M, N)\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n a_tile = tl.make_block_ptr(a_ptr, shape=(M, K), strides=(stride_am,\n stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0), block_shape=(\n BLOCK_SIZE_M, BLOCK_SIZE_K), order=(0, 1))\n b_tile = tl.make_block_ptr(b_ptr, shape=(K, N), strides=(stride_bk,\n stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N), block_shape=(\n BLOCK_SIZE_K, BLOCK_SIZE_N), order=(0, 1))\n ASM: tl.constexpr = 'cvt.rna.tf32.f32 $0, $1;'\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_tile, boundary_check=(1,), padding_option='zero')\n b = tl.load(b_tile, boundary_check=(0,), padding_option='zero')\n if ALLOWTF32 and PRECISIONMATCH:\n a = tl.inline_asm_elementwise(ASM, '=r, r', [a], dtype=tl.\n float32, is_pure=True, pack=1)\n b = tl.inline_asm_elementwise(ASM, '=r, r', [b], dtype=tl.\n float32, is_pure=True, pack=1)\n accumulator = tl.dot(a, b, accumulator, input_precision='tf32' if\n ALLOWTF32 else 'ieee')\n a_tile = tl.advance(a_tile, (0, BLOCK_SIZE_K))\n b_tile = tl.advance(b_tile, (BLOCK_SIZE_K, 0))\n c_tile = tl.make_block_ptr(c_ptr, shape=(M, N), strides=(stride_cm,\n stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n c = accumulator.to(c_tile.dtype.element_ty)\n tl.store(c_tile, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/GEMM.py" }, { "uuid": "94697f0e-3719-4056-9cc6-daae59cf6664", "file_name": "geglu.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/geglu.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef gelu_backward(x):\n x2 = x * x\n tanh_ = tanh(_kAlpha * x * (1 + 0.044715 * x2))\n dx = 0.5 * (x * (1 - tanh_ * tanh_) * (0.1070322244089 * x2 + \n 0.797884560802865) + tanh_ + 1)\n return dx\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/geglu.py" }, { "uuid": "86772575-6e51-43f3-939c-f76536b27ef0", "file_name": "linear_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/linear_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=[linear_forward_config(32, 32, 32, n_warps=2,\n n_stages=2), linear_forward_config(64, 32, 32, n_warps=2, n_stages=5),\n linear_forward_config(64, 32, 128, n_warps=4, n_stages=4),\n linear_forward_config(64, 32, 256, n_warps=4, n_stages=4),\n linear_forward_config(128, 32, 32, n_warps=4, n_stages=4),\n linear_forward_config(128, 32, 64, n_warps=4, n_stages=4),\n linear_forward_config(128, 32, 128, n_warps=4, n_stages=4),\n linear_forward_config(128, 64, 256, n_warps=8, n_stages=3)], key=[\n 'batch_dim', 'in_feat_dim', 'out_feat_dim', 'fp16'])\n@triton.heuristics({'tf32': lambda _: allow_tf32()})\n@triton.jit\ndef linear_forward_kernel(input_pointer, weight_pointer, bias_pointer,\n pre_act_pointer, output_pointer, batch_dim, in_feat_dim, out_feat_dim,\n input_batch_stride, input_in_feat_stride, weight_in_feat_stride,\n weight_out_feat_stride, pre_act_batch_stride, pre_act_out_feat_stride,\n output_batch_stride, output_out_feat_stride, param, add_bias: tl.\n constexpr, act_func: tl.constexpr, save_pre_act: tl.constexpr, fp16: tl\n .constexpr, tf32: tl.constexpr, BLOCK_SIZE_BATCH: tl.constexpr,\n BLOCK_SIZE_IN_FEAT: tl.constexpr, BLOCK_SIZE_OUT_FEAT: tl.constexpr,\n GROUP_SIZE_BATCH: tl.constexpr):\n \"\"\"\n Linearly transforms the input using weights, optionally adding bias\n and fusing an activation function.\n\n Args:\n input_pointer: Pointer to the input to transform.\n The input must be of shape [batch_dim, in_feat_dim].\n weight_pointer: Pointer to the weights input is transformed by.\n The weights must be of shape [in_feat_dim, out_feat_dim].\n bias_pointer: Pointer to an optional additive bias vector.\n The bias vector, if provided, must be of shape [out_feat_dim].\n pre_act_pointer: Pointer to an optional container the pre-activation input\n is written to if act_func is not None and save_pre_act is True.\n The container, if provided, must be of shape [batch_dim, out_feat_dim].\n output_pointer: Pointer to a container the result is written to.\n The container must be of shape [batch_dim, out_feat_dim].\n batch_dim: Batch dimension of the input and output.\n in_feat_dim: Dimensionality of the input features.\n out_feat_dim: Dimensionality of the output features.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_in_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n weight_in_feat_stride: Stride necessary to jump one element along the\n weights' input feature dimension.\n weight_out_feat_stride: Stride necessary to jump one element along the\n weights' output feature dimension.\n pre_act_batch_stride: Stride necessary to jump one element along the\n pre-activation input container's batch dimension.\n pre_act_out_feat_stride: Stride necessary to jump one element along the\n pre-activation input container's feature dimension.\n output_batch_stride: Stride necessary to jump one element along the\n output container's batch dimension.\n output_out_feat_stride: Stride necessary to jump one element along the\n output container's feature dimension.\n param: Parameter in the case of parameterized activation functions.\n add_bias: Flag for adding a bias vector.\n act_func: Name of activation function to apply, with None for identity.\n Options are 'sigmoid', 'tanh', 'relu', 'gelu', 'silu',\n 'relu6', 'hardsigmoid', 'hardswish', 'selu', 'mish', and 'leaky_relu'.\n save_pre_act: Flag for saving the pre-activation input.\n fp16: Flag for loading the input, weights, and bias in FP16.\n tf32: Flag for performing matrix products in TF32.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_IN_FEAT: Block size across the input feature dimension.\n BLOCK_SIZE_OUT_FEAT: Block size across the output feature dimension.\n GROUP_SIZE_BATCH: Group size across the batch dimension.\n \"\"\"\n pid = tl.program_id(axis=0)\n n_batch_pids = tl.cdiv(batch_dim, BLOCK_SIZE_BATCH)\n n_out_feat_pids = tl.cdiv(out_feat_dim, BLOCK_SIZE_OUT_FEAT)\n pids_per_group = GROUP_SIZE_BATCH * n_out_feat_pids\n group_id = pid // pids_per_group\n first_batch_pid = group_id * GROUP_SIZE_BATCH\n GROUP_SIZE_BATCH = min(n_batch_pids - first_batch_pid, GROUP_SIZE_BATCH)\n batch_pid = first_batch_pid + pid % GROUP_SIZE_BATCH\n out_feat_pid = pid % pids_per_group // GROUP_SIZE_BATCH\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n out_feat_offset = out_feat_pid * BLOCK_SIZE_OUT_FEAT + tl.arange(0,\n BLOCK_SIZE_OUT_FEAT)\n batch_mask = batch_offset < batch_dim\n out_feat_mask = out_feat_offset < out_feat_dim\n input_pointer += input_batch_stride * batch_offset[:, None]\n weight_pointer += weight_out_feat_stride * out_feat_offset[None, :]\n accum = tl.zeros((BLOCK_SIZE_BATCH, BLOCK_SIZE_OUT_FEAT), dtype=tl.float32)\n for block_ind in range(0, tl.cdiv(in_feat_dim, BLOCK_SIZE_IN_FEAT)):\n in_feat_offset = block_ind * BLOCK_SIZE_IN_FEAT + tl.arange(0,\n BLOCK_SIZE_IN_FEAT)\n in_feat_mask = in_feat_offset < in_feat_dim\n curr_input_pointer = (input_pointer + input_in_feat_stride *\n in_feat_offset[None, :])\n curr_weight_pointer = (weight_pointer + weight_in_feat_stride *\n in_feat_offset[:, None])\n input_block = tl.load(curr_input_pointer, mask=batch_mask[:, None] &\n in_feat_mask[None, :])\n weight_block = tl.load(curr_weight_pointer, mask=out_feat_mask[None,\n :] & in_feat_mask[:, None])\n if fp16:\n input_block = input_block.to(tl.float16)\n weight_block = weight_block.to(tl.float16)\n accum += tl.dot(input_block, weight_block, allow_tf32=tf32)\n if add_bias:\n bias = tl.load(bias_pointer + out_feat_offset, mask=out_feat_mask)\n if fp16:\n bias = bias.to(tl.float16)\n accum += bias[None, :]\n if act_func is not None:\n if save_pre_act:\n pre_act_pointer += pre_act_batch_stride * batch_offset[:, None\n ] + pre_act_out_feat_stride * out_feat_offset[None, :]\n tl.store(pre_act_pointer, accum, mask=batch_mask[:, None] &\n out_feat_mask[None, :])\n accum = apply_act_func(accum, None, None, None, param, act_func, False)\n output_pointer += output_batch_stride * batch_offset[:, None\n ] + output_out_feat_stride * out_feat_offset[None, :]\n tl.store(output_pointer, accum, mask=batch_mask[:, None] &\n out_feat_mask[None, :])\n", "category": { "Functionality": [ "Matrix Multiplication", "Activation Functions" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/linear_kernels.py" }, { "uuid": "4450f891-1917-44af-86d7-af541511fc5f", "file_name": "real_rnn_tie_input_gate.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef bwd_sequential_scan_fused(grad_output, v, f, h, B, L, C, BLOCK_M: tl.\n constexpr):\n offset_b = tl.program_id(0)\n if offset_b >= B:\n return\n offset_n = tl.program_id(1)\n ptr = tl.arange(0, BLOCK_M) + offset_b * L * C + (L - 1\n ) * C + offset_n * BLOCK_M\n grad_h = tl.zeros([BLOCK_M], dtype=tl.float32)\n for time_step in range(L - 1, -1, -1):\n grad = tl.load(grad_output + ptr).to(tl.float32)\n grad_h += grad\n decay = tl.load(f + ptr).to(tl.float32)\n decay = tl.sigmoid(decay)\n input = tl.load(v + ptr).to(tl.float32)\n grad_v = (1 - decay) * grad_h\n tl.store(v + ptr, grad_v.to(v.dtype.element_ty))\n hidden_state = tl.load(h + ptr - C, mask=ptr >= offset_b * L * C +\n C, other=0.0).to(tl.float32)\n grad_f = grad_h * (hidden_state - input) * decay * (1 - decay)\n tl.store(f + ptr, grad_f.to(f.dtype.element_ty))\n grad_h *= decay\n ptr -= C\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/real_rnn_tie_input_gate.py" }, { "uuid": "e799356f-0cb1-45e9-99e3-609fd4815e15", "file_name": "layernorm.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/layernorm.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef layernorm_forward(Y, Y_row_stride, X, X_row_stride, W, b, r, mu, n_cols,\n eps, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n Y += row_idx * Y_row_stride\n X += row_idx * X_row_stride\n r += row_idx\n mu += row_idx\n X_row = tl.load(X + col_offsets, mask=mask, other=0).to(tl.float32)\n W_row = tl.load(W + col_offsets, mask=mask, other=0).to(tl.float32)\n b_row = tl.load(b + col_offsets, mask=mask, other=0).to(tl.float32)\n mean_X = tl.sum(X_row, axis=0) / n_cols\n XX = X_row - mean_X\n row_var = tl.sum(XX * XX, axis=0) / n_cols\n inv_var = tl.math.rsqrt(row_var + eps)\n tl.store(r, inv_var)\n tl.store(mu, mean_X)\n output = XX * inv_var * W_row + b_row\n tl.store(Y + col_offsets, output, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/layernorm.py" }, { "uuid": "8c552f13-b676-4f8c-a790-9b00891ef3c0", "file_name": "logits_processor.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/logits_processor.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _triton_logits_processor_kernel(scores, penalty, input_ids_ptr,\n input_ids_length, num_tokens: tl.constexpr, vocab_size: tl.constexpr,\n max_ids_length: tl.constexpr, power_2_of_vocab_size: tl.constexpr,\n power_2_of_max_ids_length: tl.constexpr, penalty_ty: tl.constexpr):\n token_id = tl.program_id(0)\n penalty_val = tl.load(penalty + token_id)\n if tl.abs(penalty_val - 1.0) > 1e-09:\n input_ids_address = tl.load(input_ids_ptr + token_id).to(tl.\n pointer_type(tl.int64))\n current_input_ids_length = tl.load(input_ids_length + token_id)\n ids_offs = tl.arange(0, power_2_of_max_ids_length)\n ids = tl.load(input_ids_address + ids_offs, mask=ids_offs <\n current_input_ids_length, other=vocab_size)\n ori_scores = tl.load(scores + token_id * vocab_size + ids[None, :],\n mask=ids[None, :] < vocab_size, other=0.0)\n tl.debug_barrier()\n if penalty_ty == 'REPETITION':\n new_scores = tl.where(ori_scores <= 0, ori_scores * penalty_val,\n ori_scores / penalty_val)\n elif penalty_ty == 'PRESENCE':\n new_scores = ori_scores - penalty_val\n tl.store(scores + token_id * vocab_size + ids[None, :], new_scores,\n mask=ids[None, :] < vocab_size)\n", "category": { "Functionality": [ "Elementwise Operations", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/logits_processor.py" }, { "uuid": "fda58767-fffe-4d57-a19a-4e44a1f929aa", "file_name": "triton_call_test.py", "repo_name": "jax-ml/jax-triton", "file_path": "tests/triton_call_test.py", "commit_hash": "859cc392bec876d132bd0790ea6c00b6c246dd2b", "starcount": 0, "input": "@triton.jit\ndef silly_add_kernel(x_ptr, y_ptr, output_ptr):\n pid = tl.program_id(axis=0)\n tl.store(output_ptr + pid, tl.load(x_ptr + pid) + tl.load(y_ptr + pid))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/jax-ml/jax-triton/blob/859cc392bec876d132bd0790ea6c00b6c246dd2b/tests/triton_call_test.py" }, { "uuid": "2e6f1a97-55af-4d82-a3eb-14a20678e5e9", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.jit\ndef fused_recurrent_gated_delta_rule_fwd_kernel(q, k, v, g, beta, o, h0, ht,\n offsets, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K:\n tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.constexpr,\n IS_BETA_HEADWISE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_k = k + i_nh * T * K + i_k * BK + tl.arange(0, BK)\n p_v = v + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n if IS_BETA_HEADWISE:\n p_beta = beta + i_nh * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_beta = beta + i_nh * T\n p_g = g + i_nh * T\n p_o = o + (i_k * B * H + i_nh) * T * V + i_v * BV + tl.arange(0, BV)\n else:\n p_q = q + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK)\n p_k = k + (bos * H + i_h) * K + i_k * BK + tl.arange(0, BK)\n p_v = v + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n if IS_BETA_HEADWISE:\n p_beta = beta + (bos * H + i_h) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_beta = beta + bos * H + i_h\n p_g = g + bos * H + i_h\n p_o = o + ((i_k * all + bos) * H + i_h) * V + i_v * BV + tl.arange(\n 0, BV)\n mask_k = i_k * BK + tl.arange(0, BK) < K\n mask_v = i_v * BV + tl.arange(0, BV) < V\n mask_h = mask_k[None, :] & mask_v[:, None]\n b_h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_g = tl.load(p_g).to(tl.float32)\n b_h *= tl.exp(b_g)\n b_v_minus = tl.sum(b_h * b_k[None, :], axis=1)\n b_v -= b_v_minus\n if IS_BETA_HEADWISE:\n b_beta = tl.load(p_beta, mask=mask_v, other=0).to(tl.float32)\n else:\n b_beta = tl.load(p_beta).to(tl.float32)\n b_v *= b_beta\n b_h += b_k[None, :] * b_v[:, None]\n b_o = b_h * b_q[None, :]\n b_o = tl.sum(b_o, axis=1)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), mask=mask_v)\n p_q += K if HEAD_FIRST else H * K\n p_k += K if HEAD_FIRST else H * K\n p_o += V if HEAD_FIRST else H * V\n p_v += V if HEAD_FIRST else H * V\n p_g += 1 if HEAD_FIRST else H\n p_beta += (1 if HEAD_FIRST else H) * (V if IS_BETA_HEADWISE else 1)\n if STORE_FINAL_STATE:\n p_ht = ht + i_nh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/fused_recurrent.py" }, { "uuid": "a5ecc712-03f7-4e99-82f2-544ad1ac17f3", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef stabilization_scan_op(x1, y1, x2, y2):\n z1 = x2 + x1\n z2 = tl.maximum(x2 + y1, y2)\n return z1, z2\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "d786f710-c461-4bf9-9c41-578935182b95", "file_name": "rotary.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/rotary.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_rotary_kernel(input_ptr, frequencies_ptr, stride_0, stride_1,\n stride_2, rotary_dim: tl.constexpr, num_heads: tl.constexpr,\n rotary_block_size: tl.constexpr, head_block_size: tl.constexpr,\n backward: tl.constexpr):\n pid_0 = tl.program_id(axis=0)\n pid_1 = tl.program_id(axis=1)\n pid_2 = tl.program_id(axis=2)\n offsets = tl.arange(0, rotary_block_size)\n head_offsets = pid_2 * head_block_size + tl.arange(0, head_block_size)[\n :, None]\n input_offsets = (stride_0 * pid_0 + stride_1 * pid_1 + stride_2 *\n head_offsets + offsets[None, :])\n input_re_ptr = input_ptr + input_offsets\n input_im_ptr = input_re_ptr + rotary_dim\n if (rotary_block_size % rotary_dim == 0 and num_heads % head_block_size ==\n 0):\n input_re = tl.load(input_re_ptr).to(tl.float32)\n input_im = tl.load(input_im_ptr).to(tl.float32)\n else:\n mask = (offsets[None, :] < rotary_dim) & (head_offsets < num_heads)\n input_re = tl.load(input_re_ptr, mask=mask).to(tl.float32)\n input_im = tl.load(input_im_ptr, mask=mask).to(tl.float32)\n frequencies_offsets = 2 * rotary_dim * pid_1 + offsets\n frequencies_re_ptr = frequencies_ptr + frequencies_offsets\n frequencies_im_ptr = frequencies_re_ptr + rotary_dim\n frequencies_re = tl.load(frequencies_re_ptr)\n frequencies_im = tl.load(frequencies_im_ptr)\n if backward:\n out_re = input_re * frequencies_re + input_im * frequencies_im\n out_im = input_im * frequencies_re - input_re * frequencies_im\n else:\n out_re = input_re * frequencies_re - input_im * frequencies_im\n out_im = input_im * frequencies_re + input_re * frequencies_im\n if (rotary_block_size % rotary_dim == 0 and num_heads % head_block_size ==\n 0):\n tl.store(input_re_ptr, out_re)\n tl.store(input_im_ptr, out_im)\n else:\n tl.store(input_re_ptr, out_re, mask=mask)\n tl.store(input_im_ptr, out_im, mask=mask)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Transposed Access", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/rotary.py" }, { "uuid": "ae472976-786a-4e37-9671-dccc1c8d91d6", "file_name": "triton_ops.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/triton_ops.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _sparse24_triton(dense_ptr, sparse_ptr, mask_ptr, dense_row_stride,\n sparse_row_stride, mask_row_stride, dense_col_stride, sparse_col_stride,\n mask_col_stride, m, k, BLOCK_SIZE: tl.constexpr, ARRAY_LAYOUT: tl.constexpr\n ):\n if ARRAY_LAYOUT == 'row':\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1) * 4 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 4\n mask = col_idx < k\n elif ARRAY_LAYOUT == 'col':\n row_idx = tl.arange(0, BLOCK_SIZE) + tl.program_id(0) * BLOCK_SIZE\n col_idx = tl.program_id(1) * 4\n mask = row_idx < m\n dense_40 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 0) * dense_col_stride, mask=mask)\n dense_41 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 1) * dense_col_stride, mask=mask)\n dense_42 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 2) * dense_col_stride, mask=mask)\n dense_43 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 3) * dense_col_stride, mask=mask)\n dense_40, dense_41, dense_42, dense_43, m0, m1, m2, m3 = _sparse24(dense_40\n , dense_41, dense_42, dense_43)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 0) *\n sparse_col_stride, dense_40, mask=mask & m0)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 1) *\n sparse_col_stride, dense_41, mask=mask & m1)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 2) *\n sparse_col_stride, dense_42, mask=mask & m2)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 3) *\n sparse_col_stride, dense_43, mask=mask & m3)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 0) *\n mask_col_stride, m0, mask=mask & m0)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 1) *\n mask_col_stride, m1, mask=mask & m1)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 2) *\n mask_col_stride, m2, mask=mask & m2)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 3) *\n mask_col_stride, m3, mask=mask & m3)\n", "category": { "Functionality": [], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/triton_ops.py" }, { "uuid": "76f2a140-03c5-435a-ad18-589b322670ed", "file_name": "03-matrix-multiplication.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/03-matrix-multiplication.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_cm, stride_cn, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (M, K), B has shape (K, N) and C has shape (M, N)\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] *\n stride_bn)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=offs_k[None, :] < K - k * BLOCK_SIZE_K,\n other=0.0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < K - k * BLOCK_SIZE_K,\n other=0.0)\n accumulator = tl.dot(a, b, accumulator)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n if ACTIVATION == 'leaky_relu':\n accumulator = leaky_relu(accumulator)\n c = accumulator.to(tl.float16)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + stride_cm * offs_cm[:, None] + stride_cn * offs_cn[None, :\n ]\n c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/03-matrix-multiplication.py" }, { "uuid": "d0523132-1573-4bfc-ad1a-db75a75ce64e", "file_name": "triton_chunk.py", "repo_name": "NX-AI/xlstm-jax", "file_path": "xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py", "commit_hash": "6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7", "starcount": 0, "input": "@triton.jit\ndef chunk_mlstm_bwd_kernel_dC(q, f, m, m_total, norm, dh, dC, final_dC,\n final_m, initial_dC, initial_m, s_qk_h, s_qk_t, s_qk_d, s_vh_h, s_vh_t,\n s_vh_d, s_C_h, s_C_t, scale, H: tl.constexpr, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr, NT: tl.constexpr):\n i_k, i_v, i_bC = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_dC = tl.make_block_ptr(final_dC + i_bC * K * V, (K, V), (s_C_t, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dC = tl.load(p_dC, boundary_check=(0, 1))\n b_m = tl.load(final_m + i_bC)\n for i_t in range(NT - 1, -1, -1):\n p_q = tl.make_block_ptr(q + i_bC * s_qk_h, (K, T), (s_qk_d, s_qk_t),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bC * s_vh_h, (T, V), (s_vh_t,\n s_vh_d), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dC = tl.make_block_ptr(dC + i_bC * s_C_h + i_t * K * V, (K, V), (\n s_C_t, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dC, b_dC.to(p_dC.dtype.element_ty), boundary_check=(0, 1))\n b_f_last = tl.load(f + i_bC * T + i_t * BT + BT - 1)\n b_f = tl.load(f + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_m_p = tl.load(m + i_bC * (NT + 1) + i_t)\n b_m_total = tl.load(m_total + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_norm = tl.load(norm + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale * tl.math.exp2(b_f + b_m_p - b_m_total)[None, :]\n ).to(b_q.dtype)\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dh /= b_norm[:, None]\n b_dC *= tl.math.exp2(b_f_last + b_m_p - b_m)\n b_dC += tl.dot(b_q, b_dh.to(b_q.dtype), allow_tf32=False)\n b_m = b_m_p\n p_initial_dC = tl.make_block_ptr(initial_dC + i_bC * K * V, (K, V), (V,\n 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_initial_dC, b_dC.to(p_initial_dC.dtype.element_ty),\n boundary_check=(0, 1))\n tl.store(initial_m + i_bC, b_m)\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache", "BSD" ], "github_url": "https://github.com/NX-AI/xlstm-jax/blob/6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7/xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py" }, { "uuid": "42cd92f0-6236-4849-b769-b3694bde27ff", "file_name": "sequential_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/sequential_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _sequential_rnn_scan_bwd_kernel():\n pass\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/sequential_rnn_scan.py" }, { "uuid": "71e1d145-99ab-4637-a976-6d25d864e20e", "file_name": "silu_and_mul.py", "repo_name": "tascj/kaggle-lmsys-chatbot-arena", "file_path": "human_pref/inference/ops/silu_and_mul.py", "commit_hash": "83cd93d50b9283c18711e8c63e4e1c6399c7b9ce", "starcount": 0, "input": "@triton.jit\ndef _silu_and_mul_kernel(input_ptr, stride_input_m, stride_input_n,\n stride_output_m, stride_output_n, size_m, size_n, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr):\n stride_input_m = stride_input_m.to(tl.int64)\n stride_output_m = stride_output_m.to(tl.int64)\n tid = tl.program_id(0)\n input_m_offsets = tid * BLOCK_M + tl.arange(0, BLOCK_M)\n output_m_offsets = tid * BLOCK_M + tl.arange(0, BLOCK_M)\n pid = tl.program_id(1)\n input_n_offsets = pid * BLOCK_N + tl.arange(0, BLOCK_N)\n output_n_offsets = pid * BLOCK_N + tl.arange(0, BLOCK_N)\n up_offsets = input_m_offsets[:, None] * stride_input_m + (input_n_offsets\n [None, :] + size_n) * stride_input_n\n gate_offsets = input_m_offsets[:, None] * stride_input_m + input_n_offsets[\n None, :] * stride_input_n\n res_offsets = output_m_offsets[:, None\n ] * stride_output_m + output_n_offsets[None, :] * stride_output_n\n up = tl.load(input_ptr + up_offsets, mask=(input_n_offsets < size_n)[\n None, :] * (input_m_offsets < size_m)[:, None], other=0.0)\n gate = tl.load(input_ptr + gate_offsets, mask=(input_n_offsets < size_n\n )[None, :] * (input_m_offsets < size_m)[:, None], other=0.0).to(tl.\n float32)\n gate = gate / (1 + tl.exp(-gate))\n gate = gate.to(input_ptr.dtype.element_ty)\n tl.store(input_ptr + res_offsets, up * gate, mask=(output_n_offsets <\n size_n)[None, :] * (output_m_offsets < size_m)[:, None])\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/tascj/kaggle-lmsys-chatbot-arena/blob/83cd93d50b9283c18711e8c63e4e1c6399c7b9ce/human_pref/inference/ops/silu_and_mul.py" }, { "uuid": "6fc9c97a-cb15-4764-a89b-ef90b31aac37", "file_name": "geglu.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/geglu.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef geglu_backward_kernel(x_ptr, dx_ptr, dy_ptr, N, C, C2, BLK_C: tl.\n constexpr, BLK_N: tl.constexpr):\n pid_n = tl.program_id(0)\n pid_c = tl.program_id(1)\n offs_n = pid_n * BLK_N + tl.arange(0, BLK_N)\n offs_c = pid_c * BLK_C + tl.arange(0, BLK_C)\n mask_n = offs_n < N\n mask_c = offs_c < C2\n mask = mask_n[:, None] & mask_c[None, :]\n x_ptrs = x_ptr + offs_n[:, None] * C + offs_c[None, :]\n x1 = tl.load(x_ptrs, mask=mask)\n x2 = tl.load(x_ptrs + C2, mask=mask)\n dy_ptrs = dy_ptr + offs_n[:, None] * C2 + offs_c[None, :]\n dy = tl.load(dy_ptrs, mask=mask)\n dx1 = dy * gelu_forward(x2)\n dx2 = dy * x1\n dx2 *= gelu_backward(x2)\n dx_ptrs = dx_ptr + offs_n[:, None] * C + offs_c[None, :]\n tl.store(dx_ptrs, dx1, mask=mask)\n tl.store(dx_ptrs + C2, dx2, mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/geglu.py" }, { "uuid": "faf12dcc-3a71-462c-9bd7-a076ddd12c3f", "file_name": "naive_associative_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/naive_associative_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _naive_associative_rnn_scan_fwd_kernel(x_ptr, a_ptr, out_ptr,\n stride_x_batch, stride_x_len, stride_x_dim, stride_a_batch,\n stride_a_len, stride_a_dim, stride_out_batch, stride_out_len,\n stride_out_dim, seq_len: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n pid_batch = tl.program_id(0)\n pid_dim = tl.program_id(1)\n x_ptr += pid_batch * stride_x_batch\n a_ptr += pid_batch * stride_a_batch\n out_ptr += pid_batch * stride_out_batch\n offsets_dim = pid_dim * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n offsets_len = tl.arange(0, seq_len)\n x_ptrs = x_ptr + offsets_dim[None, :] * stride_x_dim + offsets_len[:, None\n ] * stride_x_len\n a_ptrs = a_ptr + offsets_dim[None, :] * stride_a_dim + offsets_len[:, None\n ] * stride_a_len\n out_ptrs = out_ptr + offsets_dim[None, :] * stride_out_dim + offsets_len[\n :, None] * stride_out_len\n x = tl.load(x_ptrs).to(tl.float32)\n a = tl.load(a_ptrs).to(tl.float32)\n _, all_hiddens = tl.associative_scan(input=(a, x), axis=0, combine_fn=\n _associative_scan_op)\n tl.store(out_ptrs, all_hiddens.to(out_ptr.dtype.element_ty), mask=(\n offsets_len == seq_len - 1)[:, None])\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/naive_associative_rnn_scan.py" }, { "uuid": "8b8d9b04-0656-4233-8540-349f8e875a04", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/hope-fla", "file_path": "fla/ops/hope/fused_recurrent.py", "commit_hash": "0750c9a9a360fb72236dfaaaf21496959c5ef48d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_fwd_kernel(q, k, k_l2, q_reflected, k_reflected,\n dk_l2_partial, T, D: tl.constexpr, BK: tl.constexpr):\n i_b, i_h = tl.program_id(0), tl.program_id(1)\n p_q = q + i_b * T * D + i_h * BK + tl.arange(0, BK)\n p_k = k + i_b * T * D + i_h * BK + tl.arange(0, BK)\n p_k_l2 = k_l2 + i_b * T * D + i_h * BK + tl.arange(0, BK)\n p_q_reflected = q_reflected + i_b * T * D + i_h * BK + tl.arange(0, BK)\n p_k_reflected = k_reflected + i_b * T * D + i_h * BK + tl.arange(0, BK)\n p_dk_l2_partial = dk_l2_partial + i_b * T * D + i_h * BK + tl.arange(0, BK)\n h = tl.zeros([BK, BK], dtype=tl.float32) + (tl.arange(0, BK)[:, None] ==\n tl.arange(0, BK)[None, :])\n for _ in range(0, T):\n b_k_l2 = tl.load(p_k_l2).to(tl.float32)\n b_q = tl.load(p_q).to(tl.float32)\n b_k = tl.load(p_k).to(tl.float32)\n tmp = tl.sum(h * b_k_l2[None, :], axis=1)\n h -= 2 * b_k_l2[None, :] * tmp[:, None]\n b_q = tl.sum(h * b_q[None, :], axis=1)\n b_k = tl.sum(h * b_k[None, :], axis=1)\n tl.store(p_q_reflected, b_q.to(p_q_reflected.dtype.element_ty))\n tl.store(p_k_reflected, b_k.to(p_k_reflected.dtype.element_ty))\n tl.store(p_dk_l2_partial, tmp.to(p_dk_l2_partial.dtype.element_ty))\n p_q += D\n p_k += D\n p_k_l2 += D\n p_q_reflected += D\n p_k_reflected += D\n p_dk_l2_partial += D\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/hope-fla/blob/0750c9a9a360fb72236dfaaaf21496959c5ef48d/fla/ops/hope/fused_recurrent.py" }, { "uuid": "5f0785c8-cf18-4fd2-8f09-4990e5a3ec0a", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/based/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_based_fwd_kernel(q, k, v, o, z, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr,\n BV: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_h_0o = tl.zeros([BV], dtype=tl.float32)\n b_h_1o = tl.zeros([BK, BV], dtype=tl.float32)\n b_h_2o = tl.zeros([BK * BK, BV], dtype=tl.float32)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (0, \n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, 0), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (0, \n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (i_bh + i_k * B * H) * s_v_h, (T, V), (\n s_v_t, s_v_d), (0, i_v * BV), (BT, BV), (1, 0))\n p_z = z + (i_bh + i_k * B * H) * T + tl.arange(0, BT)\n k_2o = tl.zeros([1, BK * BK], dtype=tl.float32)\n k_1o = tl.zeros([1, BK], dtype=tl.float32)\n k_0o = 0\n for i in range(0, tl.cdiv(T, BT)):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_k_2o = b_k[:, None, :] * b_k[None, :, :]\n b_k_2o = tl.reshape(b_k_2o, [BK * BK, BT]).to(b_k.dtype)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_q = (tl.load(p_q, boundary_check=(0, 1)) * scale).to(b_k.dtype)\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_z = tl.zeros([BT], dtype=tl.float32)\n b_o += b_h_0o\n b_z += k_0o\n b_o += tl.dot(b_q, b_h_1o.to(b_q.dtype), allow_tf32=False)\n b_z += tl.sum(b_q * k_1o, axis=1)\n b_q_2o = b_q[:, :, None] * b_q[:, None, :]\n b_q_2o = tl.reshape(b_q_2o, [BT, BK * BK]).to(b_k.dtype)\n b_o += tl.dot(b_q_2o, b_h_2o.to(b_q_2o.dtype), allow_tf32=False) * 0.5\n b_z += tl.sum(b_q_2o * k_2o, axis=1) * 0.5\n k_1o += tl.sum(b_k, axis=1)[None, :]\n k_2o += tl.sum(b_k_2o, axis=1)[None, :]\n k_0o += BT\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = 1 + b_s + 0.5 * b_s * b_s\n b_s = tl.where(m_s, b_s, 0)\n b_z += tl.sum(b_s, axis=1)\n b_o += tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_z, b_z.to(p_z.dtype.element_ty), mask=i * BT + tl.arange\n (0, BT) < T)\n b_h_2o = b_h_2o + tl.dot(b_k_2o.to(b_v.dtype), b_v, allow_tf32=False)\n b_h_1o = b_h_1o + tl.dot(b_k, b_v, allow_tf32=False)\n b_h_0o = b_h_0o + tl.sum(b_v, axis=0)\n p_q = tl.advance(p_q, (BT, 0))\n p_k = tl.advance(p_k, (0, BT))\n p_v = tl.advance(p_v, (BT, 0))\n p_o = tl.advance(p_o, (BT, 0))\n p_z += BT\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/based/fused_chunk.py" }, { "uuid": "54d08794-506f-46cb-8b84-ab8be03f6801", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _jagged_flash_attention_bwd_preprocess_basic_kernel(o_ptr, o_offset_ptr,\n do_ptr, delta_ptr, stride_om, stride_od, max_seq_len, D: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_D: tl.constexpr):\n pid_m = tl.program_id(axis=0)\n pid_batch = tl.program_id(axis=1)\n begin_o = tl.load(o_offset_ptr + pid_batch)\n end_o = tl.load(o_offset_ptr + pid_batch + 1)\n M = end_o - begin_o\n M = tl.minimum(M, max_seq_len)\n offs_om = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_od = tl.arange(0, BLOCK_SIZE_D)\n o_offsets = offs_om[:, None] * stride_om + offs_od[None, :\n ] * stride_od + begin_o * stride_om\n o_ptrs = o_ptr + o_offsets\n do_ptrs = do_ptr + o_offsets\n o_mask = (offs_om[:, None] < M) & (offs_od[None, :] < D)\n o = tl.load(o_ptrs, mask=o_mask)\n do = tl.load(do_ptrs, mask=o_mask)\n delta = tl.sum(o * do, axis=1)\n tl.store(delta_ptr + begin_o + offs_om, delta, mask=offs_om < M)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "51ef560d-cee3-4e4b-9480-414a21661527", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4] for num_stages in [2, 3, 4]], key=['BT'])\n@triton.jit\ndef chunk_retention_fwd_kernel_o(q, k, v, h, o, offsets, indices, scale, H:\n tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl\n .constexpr, BK: tl.constexpr, BV: tl.constexpr, NT: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n o_i = tl.arange(0, BT)\n d_i = tl.math.exp2((o_i + 1) * b_b)\n m_s = o_i[:, None] >= o_i[None, :]\n d_s = tl.where(m_s, tl.math.exp2((o_i[:, None] - o_i[None, :]) * b_b), 0)\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_s = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (\n V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n b_s += tl.dot(b_q, b_k, allow_tf32=False)\n b_o = b_o * d_i[:, None]\n b_s = b_s * d_s\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_o = (b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)) * scale\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/chunk.py" }, { "uuid": "4b7f7511-1f81-4dfd-b663-c2657b3195c5", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'NV': lambda args: triton.cdiv(args['V'], args['BV'])})\n@triton.jit\ndef parallel_retention_bwd_kernel(q, k, v, do, dq, dk, dv, scale, B: tl.\n constexpr, H: tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BS: tl.constexpr, BK: tl.constexpr, BV: tl\n .constexpr, NV: tl.constexpr):\n i_kv, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_k, i_v = i_kv // NV, i_kv % NV\n i_h = i_bh % H\n parallel_retention_bwd_kernel_dq(i_bh, i_t, i_k, i_v, i_h, k, v, do, dq,\n scale, B=B, H=H, T=T, K=K, V=V, BT=BT, BS=BS, BK=BK, BV=BV)\n tl.debug_barrier()\n parallel_retention_bwd_kernel_dkv(i_bh, i_t, i_k, i_v, i_h, q, k, v, do,\n dk, dv, scale, B, H, T, K, V, BT, BS, BK, BV)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/parallel.py" }, { "uuid": "686cb4de-466f-4a1f-845c-31d93017e89f", "file_name": "test.py", "repo_name": "LLMServe/DistServe", "file_path": "evaluation/0-test-single-forward-performance/test.py", "commit_hash": "3a5c5397a260c2a53c815688d0df1796dd54128e", "starcount": 0, "input": "@triton.jit\ndef f(a: tl.constexpr, b):\n pass\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LLMServe/DistServe/blob/3a5c5397a260c2a53c815688d0df1796dd54128e/evaluation/0-test-single-forward-performance/test.py" }, { "uuid": "2dcb744e-9b5f-4362-b8b5-054fa60ab3b3", "file_name": "layernorm_gated.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/layernorm_gated.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'HAS_BIAS': lambda args: args['B'] is not None, 'HAS_Z':\n lambda args: args['Z'] is not None, 'RECOMPUTE_OUTPUT': lambda args: \n args['Y'] is not None})\n@triton.jit\ndef layer_norm_bwd_kernel(X, W, B, Z, Y, DY, DX, DW, DB, DZ, Mean, Rstd,\n stride_x_row, stride_z_row, stride_y_row, stride_dy_row, stride_dx_row,\n stride_dz_row, stride_dw_row, stride_db_row, M, N, eps,\n rows_per_program, NORM_BEFORE_GATE: tl.constexpr, IS_RMS_NORM: tl.\n constexpr, HAS_BIAS: tl.constexpr, HAS_Z: tl.constexpr,\n RECOMPUTE_OUTPUT: tl.constexpr, BLOCK_N: tl.constexpr):\n row_block_id = tl.program_id(0)\n group = tl.program_id(1)\n row_start = row_block_id * rows_per_program\n cols = tl.arange(0, BLOCK_N)\n mask = cols < N\n X += row_start * stride_x_row + group * N\n if HAS_Z:\n Z += row_start * stride_z_row + group * N\n DZ += row_start * stride_dz_row + group * N\n DY += row_start * stride_dy_row + group * N\n DX += row_start * stride_dx_row + group * N\n if RECOMPUTE_OUTPUT:\n Y += row_start * stride_y_row + group * N\n if not IS_RMS_NORM:\n Mean += group * M\n Rstd += group * M\n W += group * N\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n if (RECOMPUTE_OUTPUT or HAS_Z) and HAS_BIAS:\n B += group * N\n b = tl.load(B + cols, mask=mask, other=0.0).to(tl.float32)\n dw = tl.zeros((BLOCK_N,), dtype=tl.float32)\n if HAS_BIAS:\n db = tl.zeros((BLOCK_N,), dtype=tl.float32)\n row_end = min((row_block_id + 1) * rows_per_program, M)\n for row in range(row_start, row_end):\n x = tl.load(X + cols, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + cols, mask=mask, other=0).to(tl.float32)\n if not IS_RMS_NORM:\n mean = tl.load(Mean + row)\n if HAS_Z and not NORM_BEFORE_GATE:\n z = tl.load(Z + cols, mask=mask, other=0.0).to(tl.float32)\n x_og = x\n x = x_og * z * tl.sigmoid(z)\n rstd = tl.load(Rstd + row)\n xhat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n xhat = tl.where(mask, xhat, 0.0)\n if HAS_Z and NORM_BEFORE_GATE:\n z = tl.load(Z + cols, mask=mask, other=0.0).to(tl.float32)\n z_sigmoid = tl.sigmoid(z)\n y = xhat * w + b if HAS_BIAS else xhat * w\n if RECOMPUTE_OUTPUT:\n tl.store(Y + cols, y * z * z_sigmoid, mask=mask)\n dz = dy * y * z_sigmoid * (1 + z * (1 - z_sigmoid))\n tl.store(DZ + cols, dz, mask=mask)\n dy *= z * z_sigmoid\n elif RECOMPUTE_OUTPUT:\n y = xhat * w + b if HAS_BIAS else xhat * w\n tl.store(Y + cols, y, mask=mask)\n wdy = w * dy\n c1 = tl.sum(xhat * wdy, axis=0) / N\n if not IS_RMS_NORM:\n c2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * c1 + c2)) * rstd\n else:\n dx = (wdy - xhat * c1) * rstd\n dw += dy * xhat\n if HAS_BIAS:\n db += dy\n if HAS_Z and not NORM_BEFORE_GATE:\n z_sigmoid = tl.sigmoid(z)\n dz = dx * x_og * z_sigmoid * (1 + z * (1 - z_sigmoid))\n tl.store(DZ + cols, dz, mask=mask)\n dx *= z * z_sigmoid\n tl.store(DX + cols, dx, mask=mask)\n X += stride_x_row\n if HAS_Z:\n Z += stride_z_row\n DZ += stride_dz_row\n if RECOMPUTE_OUTPUT:\n Y += stride_y_row\n DY += stride_dy_row\n DX += stride_dx_row\n tl.store(DW + row_block_id * stride_dw_row + group * N + cols, dw, mask\n =mask)\n if HAS_BIAS:\n tl.store(DB + row_block_id * stride_db_row + group * N + cols, db,\n mask=mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/layernorm_gated.py" }, { "uuid": "214f7ac4-a9b5-4d29-84a0-b7ba3504f01e", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gsa/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps, num_stages\n =num_stages) for num_warps in [2, 4] for num_stages in [2, 3, 4]], key=\n ['BT'])\n@triton.jit\ndef chunk_gsa_bwd_k_kernel_dqkvg(q, k, v, h, g, A, do, dh, dq, dk, dv, dg,\n dgv, dA, offsets, indices, scale, B: tl.constexpr, T: tl.constexpr, HQ:\n tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl\n .constexpr, BK: tl.constexpr, BV: tl.constexpr, NG: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_bh // NG\n i_b, i_hq = i_bh // HQ, i_bh % HQ\n i_h = i_hq // NG\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n o_i = tl.arange(0, BT)\n o_t = min(i_t * BT + BT, T)\n m_s = o_i[:, None] >= o_i[None, :]\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bg * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_A = tl.make_block_ptr(A + (i_k * B * H + i_bh) * T * BT, (T, BT),\n (BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * HQ + i_hq) * K, (T, K), (HQ * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_A = tl.make_block_ptr(A + ((i_k * all + bos) * HQ + i_hq) * BT, (\n T, BT), (HQ * BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_A = tl.dot((b_q * scale).to(b_q.dtype), tl.trans(b_k))\n b_A = tl.where(m_s, b_A, 0.0)\n tl.store(p_A, b_A.to(p_A.dtype.element_ty), boundary_check=(0, 1))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n o_v = i_v * BV + tl.arange(0, BV)\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_g = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bg * T * V + (o_t -\n 1) * V + o_v, BV), BV)\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * B * H + i_bh) * T * V, (T,\n V), (V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dg = tl.make_block_ptr(dg + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dgv = tl.make_block_ptr(dgv + (i_k * B * H + i_bh) * T * V, (\n T, V), (V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bg * NT * K * V + i_t * K * V, (V,\n K), (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bh * NT * K * V + i_t * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + o_t - 1) * H *\n V + i_h * V + o_v, BV), BV)\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + ((i_k * all + bos) * HQ + i_hq) *\n V, (T, V), (HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dg = tl.make_block_ptr(dg + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dgv = tl.make_block_ptr(dgv + ((i_k * all + bos) * HQ + i_hq) *\n V, (T, V), (HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * HQ + i_hq) * K * V, (K, V\n ), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n m_v = o_v < V\n b_gn = tl.load(p_gn, mask=m_v, other=0)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_gv = tl.exp(b_gn[None, :] - b_g)\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_g) * scale).to(b_do.dtype)\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dg = tl.sum(tl.trans(b_h) * b_dh, 0) * tl.exp(b_gn)\n b_dh = b_dh.to(b_k.dtype)\n b_dq += tl.dot(b_do, b_h.to(b_k.dtype))\n b_dk += tl.dot((b_v * b_gv).to(b_v.dtype), tl.trans(b_dh))\n b_dv = tl.dot(b_k, b_dh) * b_gv\n b_dg += tl.sum(b_dv * b_v, 0)\n if i_k == 0:\n b_dgv = tl.load(p_dg, boundary_check=(0, 1)) + b_dg[None, :]\n else:\n b_dgv = tl.zeros([BT, BV], dtype=tl.float32) + b_dg[None, :]\n tl.store(p_dgv, b_dgv.to(p_dgv.dtype.element_ty), boundary_check=(0, 1)\n )\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n if HEAD_FIRST:\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_dA = tl.make_block_ptr(dA + (bos * HQ + i_hq) * BT, (T, BT), (HQ *\n BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n p_dq = tl.make_block_ptr(dq + (bos * HQ + i_hq) * K, (T, K), (HQ *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * HQ + i_hq) * K, (T, K), (HQ *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dq += tl.dot(b_dA, b_k)\n b_dk += tl.dot(tl.trans(b_dA).to(b_k.dtype), b_q)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gsa/chunk.py" }, { "uuid": "2e0354ac-cb88-4e37-87aa-b3e8199840dd", "file_name": "rwkv_log.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/rwkv_log.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef wkv_triton_log_space_backward_kernel(w_ptr, w_s_c, u_ptr, u_s_c, k_ptr,\n k_s_b, k_s_t, k_s_c, v_ptr, v_s_b, v_s_t, v_s_c, state_ptr, state_s_b,\n state_s_abe, state_s_t, state_s_c, gwkv_ptr, gwkv_s_b, gwkv_s_t,\n gwkv_s_c, gstate_out_ptr, gstate_out_s_b, gstate_out_s_abe,\n gstate_out_s_c, gw_ptr, gw_s_c, gu_ptr, gu_s_c, gk_ptr, gk_s_b, gk_s_t,\n gk_s_c, gv_ptr, gv_s_b, gv_s_t, gv_s_c, gstate_ptr, gstate_s_b,\n gstate_s_abe, gstate_s_c, tsz, chans, eps: tl.constexpr, BLOCK_SIZE_C:\n tl.constexpr):\n b_idx = tl.program_id(0)\n c_idx = tl.program_id(1)\n cs = c_idx * BLOCK_SIZE_C + tl.arange(0, BLOCK_SIZE_C)\n cmask = cs < chans\n k_ptr = k_ptr + b_idx * k_s_b\n v_ptr = v_ptr + b_idx * v_s_b\n alpha_p_ptr = state_ptr + b_idx * state_s_b\n alpha_m_ptr = state_ptr + b_idx * state_s_b + state_s_abe\n beta_ptr = state_ptr + b_idx * state_s_b + 2 * state_s_abe\n gk_ptr = gk_ptr + b_idx * gk_s_b\n gv_ptr = gv_ptr + b_idx * gv_s_b\n gwkv_ptr = gwkv_ptr + b_idx * gwkv_s_b\n galpha_p_out_ptr = gstate_out_ptr + b_idx * gstate_out_s_b\n galpha_m_out_ptr = (gstate_out_ptr + b_idx * gstate_out_s_b +\n gstate_out_s_abe)\n gbeta_out_ptr = (gstate_out_ptr + b_idx * gstate_out_s_b + 2 *\n gstate_out_s_abe)\n gln_alpha_p = tl.load(galpha_p_out_ptr + gstate_out_s_c * cs, mask=cmask\n ).to(tl.float32)\n gln_alpha_m = tl.load(galpha_m_out_ptr + gstate_out_s_c * cs, mask=cmask\n ).to(tl.float32)\n gln_beta = tl.load(gbeta_out_ptr + gstate_out_s_c * cs, mask=cmask).to(tl\n .float32)\n w = tl.load(w_ptr + w_s_c * cs, mask=cmask).to(tl.float32)\n u = tl.load(u_ptr + u_s_c * cs, mask=cmask).to(tl.float32)\n gw = tl.zeros_like(w)\n gu = tl.zeros_like(u)\n for t in range(tsz):\n tc = tsz - t - 1\n kt = tl.load(k_ptr + tc * k_s_t + k_s_c * cs, mask=cmask).to(tl.float32\n )\n vt = tl.load(v_ptr + tc * v_s_t + v_s_c * cs, mask=cmask).to(tl.float32\n )\n vt_p = tl.maximum(vt, 0) + eps\n vt_m = tl.maximum(-vt, 0) + eps\n ln_v_p = tl.log(vt_p)\n ln_v_m = tl.log(vt_m)\n ln_alpha_p_prev = tl.load(alpha_p_ptr + tc * state_s_t + state_s_c *\n cs, mask=cmask).to(tl.float32)\n ln_alpha_m_prev = tl.load(alpha_m_ptr + tc * state_s_t + state_s_c *\n cs, mask=cmask).to(tl.float32)\n ln_beta_prev = tl.load(beta_ptr + tc * state_s_t + state_s_c * cs,\n mask=cmask).to(tl.float32)\n uk = u + kt\n ukv_p = uk + ln_v_p\n ukv_m = uk + ln_v_m\n ukb = logaddexp(uk, ln_beta_prev)\n wkv_p = tl.exp(logaddexp(ukv_p, ln_alpha_p_prev) - ukb)\n wkv_m = tl.exp(logaddexp(ukv_m, ln_alpha_m_prev) - ukb)\n gwkvt = tl.load(gwkv_ptr + tc * gwkv_s_t + gwkv_s_c * cs, mask=cmask\n ).to(tl.float32)\n gln_wkv_p = gwkvt * wkv_p\n gln_wkv_m = gwkvt * -wkv_m\n e_num_p = tl.exp(ln_alpha_p_prev - ukv_p)\n e_num_m = tl.exp(ln_alpha_m_prev - ukv_m)\n e_den = tl.exp(ln_beta_prev - uk)\n grad_wkv_den_p = gln_wkv_p / (1 + e_den)\n grad_wkv_den_m = gln_wkv_m / (1 + e_den)\n gkv_p = gln_wkv_p / (1 + e_num_p)\n gkv_m = gln_wkv_m / (1 + e_num_m)\n grad_uk = gkv_p + gkv_m - grad_wkv_den_p - grad_wkv_den_m\n gu += grad_uk\n gk = grad_uk\n gv = tl.where(vt > 0, gkv_p / vt_p, gkv_m / -vt_m)\n gln_alpha_wkv_p = gln_wkv_p / (1 + 1 / e_num_p)\n gln_alpha_wkv_m = gln_wkv_m / (1 + 1 / e_num_m)\n gln_beta_wkv = -gln_wkv_p / (1 + 1 / e_den) - gln_wkv_m / (1 + 1 /\n e_den)\n e_alpha_p = tl.exp(kt + ln_v_p - (w + ln_alpha_p_prev))\n e_alpha_m = tl.exp(kt + ln_v_m - (w + ln_alpha_m_prev))\n gwa_p = gln_alpha_p / (1 + e_alpha_p)\n gwa_m = gln_alpha_m / (1 + e_alpha_m)\n gkv_p = gln_alpha_p / (1 + 1 / e_alpha_p)\n gkv_m = gln_alpha_m / (1 + 1 / e_alpha_m)\n gw += gwa_p + gwa_m\n gk += gkv_p + gkv_m\n gv += tl.where(vt > 0, gkv_p / vt_p, -gkv_m / vt_m)\n e_beta = tl.exp(kt - (w + ln_beta_prev))\n gwb = gln_beta / (1 + e_beta)\n gw += gwb\n gk += gln_beta / (1 + 1 / e_beta)\n tl.store(gk_ptr + tc * gk_s_t + gk_s_c * cs, gk, mask=cmask)\n tl.store(gv_ptr + tc * gv_s_t + gv_s_c * cs, gv, mask=cmask)\n gln_alpha_p = gwa_p + gln_alpha_wkv_p\n gln_alpha_m = gwa_m + gln_alpha_wkv_m\n gln_beta = gwb + gln_beta_wkv\n gln_alpha_p_ptr = gstate_ptr + b_idx * gstate_s_b\n gln_alpha_m_ptr = gstate_ptr + b_idx * gstate_s_b + gstate_s_abe\n gln_beta_ptr = gstate_ptr + b_idx * gstate_s_b + 2 * gstate_s_abe\n tl.store(gln_alpha_p_ptr + gstate_s_c * cs, gln_alpha_p, mask=cmask)\n tl.store(gln_alpha_m_ptr + gstate_s_c * cs, gln_alpha_m, mask=cmask)\n tl.store(gln_beta_ptr + gstate_s_c * cs, gln_beta, mask=cmask)\n tl.atomic_add(gw_ptr + gw_s_c * cs, gw, mask=cmask)\n tl.atomic_add(gu_ptr + gu_s_c * cs, gu, mask=cmask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/rwkv_log.py" }, { "uuid": "04b616e3-c3c8-4ae9-b466-28632451aa62", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16]], key=['BK', 'BV'])\n@triton.jit\ndef fused_recurrent_rwkv6_fwd_kernel(q, k, v, w, u, o, h0, ht, offsets,\n scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, REVERSE:\n tl.constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.\n constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.\n int64), tl.program_id(2).to(tl.int64)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n o_k = i_k * BK + tl.arange(0, BK)\n o_v = i_v * BV + tl.arange(0, BV)\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + ((T - 1) * K if REVERSE else 0) + o_k\n p_k = k + i_nh * T * K + ((T - 1) * K if REVERSE else 0) + o_k\n p_v = v + i_nh * T * V + ((T - 1) * V if REVERSE else 0) + o_v\n p_w = w + i_nh * T * K + ((T - 1) * K if REVERSE else 0) + o_k\n p_o = o + (i_k * B * H + i_nh) * T * V + ((T - 1) * V if REVERSE else 0\n ) + o_v\n else:\n p_q = q + (bos + (T - 1 if REVERSE else 0)) * H * K + i_h * K + o_k\n p_k = k + (bos + (T - 1 if REVERSE else 0)) * H * K + i_h * K + o_k\n p_v = v + (bos + (T - 1 if REVERSE else 0)) * H * V + i_h * V + o_v\n p_w = w + (bos + (T - 1 if REVERSE else 0)) * H * K + i_h * K + o_k\n p_o = o + (i_k * all + bos + (T - 1 if REVERSE else 0)\n ) * H * V + i_h * V + o_v\n p_u = u + i_h * K + o_k\n mask_k = o_k < K\n mask_v = o_v < V\n mask_h = mask_k[:, None] & mask_v[None, :]\n b_u = tl.load(p_u, mask=mask_k, other=0).to(tl.float32)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_nh * K * V + o_k[:, None] * V + o_v[None, :]\n b_h += tl.load(p_h0, mask=mask_h, other=0).to(tl.float32)\n for _ in range(0, T):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_w = tl.load(p_w, mask=mask_k, other=0).to(tl.float32)\n b_kv = b_k[:, None] * b_v[None, :]\n b_o = tl.sum((b_h + b_kv * b_u[:, None]) * b_q[:, None], 0)\n b_h = b_h * tl.exp(b_w)[:, None] + b_kv\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), mask=mask_v)\n p_q += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_k += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_w += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_o += (-1 if REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n if STORE_FINAL_STATE:\n p_ht = ht + i_nh * K * V + o_k[:, None] * V + o_v[None, :]\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Batch-Oriented" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/fused_recurrent.py" }, { "uuid": "b2ccfd99-57ca-4f63-8421-06fc03c2fd71", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_simple_gla_bwd_kernel_dv(q, k, g, do, dv, dh, offsets, indices,\n scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n b_g = tl.load(g + i_bh * T + i_t * BT + tl.arange(0, BT))\n b_g_last = tl.load(g + i_bh * T + min(i_t * BT + BT, T) - 1)\n else:\n b_g = tl.load(g + (bos + i_t * BT + tl.arange(0, BT)) * H + i_h)\n b_g_last = tl.load(g + (bos + min(i_t * BT + BT, T) - 1) * H + i_h)\n b_dv = tl.zeros([BT, BV], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dh = tl.make_block_ptr(dh + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype)) * tl.exp(-b_g + b_g_last)[:,\n None]\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_A += tl.dot(b_k, b_q, allow_tf32=False)\n mask = (tl.arange(0, BT)[:, None] <= tl.arange(0, BT)[None, :]) & (i_t *\n BT + tl.arange(0, BT) < T)\n b_A = b_A * tl.exp(b_g[None, :] - b_g[:, None]) * scale\n b_A = tl.where(mask, b_A, 0).to(do.dtype.element_ty)\n if HEAD_FIRST:\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H * V, \n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H * V, \n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dv += tl.dot(b_A, b_do)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/chunk.py" }, { "uuid": "c37220b7-83c8-4237-ab3c-c6b1f83a1aa3", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef symmetric_alibi_mask(slope, offs_m, offs_n, M, N, EVEN_M: tl.constexpr,\n EVEN_N: tl.constexpr):\n alibi = -tl.abs(M - N + offs_n[None, :] - offs_m[:, None]) * slope\n if not EVEN_M & EVEN_N:\n mask = make_bounds(offs_m, offs_n, M, N, EVEN_M, EVEN_N)\n mask, alibi = tl.broadcast(mask, alibi)\n alibi = tl.where(mask, alibi, float('-inf'))\n return alibi\n", "category": { "Functionality": [ "Attention Mechanisms", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "e2a70484-75b6-4ce3-8fc4-87362e385bde", "file_name": "attn_torch_function.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/attn_torch_function.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=TRITON_CONFIG_LIST_BWD_FUSED, key=['max_seqlen_q',\n 'max_seqlen_k', 'head_dim'])\n@triton.jit\ndef tuned_attn_bwd(Q, K, V, B, sm_scale, Out, DO, DK, DV, DQ, DB, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dkz, stride_dkh, stride_dkn, stride_dkk,\n stride_dvz, stride_dvh, stride_dvk, stride_dvn, stride_dqz, stride_dqh,\n stride_dqm, stride_dqk, stride_dbz, stride_dbh, stride_dbm, stride_dbn,\n num_head_q, num_head_k, cu_seqlens_q, cu_seqlens_k, num_seqlens,\n max_seqlen_q, max_seqlen_k, head_dim, dropout_p, philox_seed_ptr,\n philox_offset1, philox_offset2, BLOCK_DMODEL: tl.constexpr, CAUSAL: tl.\n constexpr, ENABLE_DROPOUT: tl.constexpr, PADDED_HEAD: tl.constexpr,\n BIAS_TYPE: tl.constexpr, BLOCK_M1: tl.constexpr, BLOCK_N1: tl.constexpr,\n BLOCK_M2: tl.constexpr, BLOCK_N2: tl.constexpr, BLK_SLICE_FACTOR: tl.\n constexpr):\n bare_attn_bwd(Q, K, V, B, sm_scale, Out, DO, DK, DV, DQ, DB, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dkz, stride_dkh, stride_dkn,\n stride_dkk, stride_dvz, stride_dvh, stride_dvk, stride_dvn,\n stride_dqz, stride_dqh, stride_dqm, stride_dqk, stride_dbz,\n stride_dbh, stride_dbm, stride_dbn, num_head_q, num_head_k,\n cu_seqlens_q, cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k,\n head_dim, dropout_p, philox_seed_ptr, philox_offset_base,\n BLOCK_DMODEL, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD, BIAS_TYPE,\n BLOCK_M1, BLOCK_N1, BLOCK_M2, BLOCK_N2, BLK_SLICE_FACTOR)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/attn_torch_function.py" }, { "uuid": "1df982b2-ab6b-4be2-b12a-68ff05bd304d", "file_name": "seqlen_utils.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/seqlen_utils.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef code_downscale_kernel(code_ptr, out_ptr, n_steps, N, BLK: tl.constexpr):\n pid = tl.program_id(0)\n offs_n = BLK * pid + tl.arange(0, BLK)\n mask_n = offs_n < N\n code = tl.load(code_ptr + offs_n, mask=mask_n)\n top16bit = code & 32767 << 48\n low16bit = code & (1 << 48) - 1\n low16bit >>= n_steps * 3\n new_code = top16bit | low16bit\n tl.store(out_ptr + offs_n, new_code, mask=mask_n)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "int8", "uint8" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/seqlen_utils.py" }, { "uuid": "04b2666a-1d7d-4696-a991-b70862c000e7", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef stabilize_fi(F, I, M, F_STABILIZED, I_STABILIZED, NH: tl.constexpr, S:\n tl.constexpr):\n bh_id = tl.program_id(0)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n s_range = tl.arange(0, S)\n batch_offset_fi = batch_id * NH * S + head_id * S\n f = tl.load(F + batch_offset_fi + s_range, s_range < S)\n i = tl.load(I + batch_offset_fi + s_range, s_range < S)\n f = tl.log(tl.sigmoid(f))\n _, m = tl.associative_scan((f, i), 0, stabilization_scan_op)\n m_shifted = roll(m, 0)\n i = tl.exp(i - m)\n f = tl.exp(f - m + m_shifted)\n tl.store(F_STABILIZED + batch_offset_fi + s_range, f, s_range < S)\n tl.store(I_STABILIZED + batch_offset_fi + s_range, i, s_range < S)\n tl.store(M + batch_offset_fi + s_range, m, s_range < S)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "f5393048-97b0-492a-b70c-6819fc017e7e", "file_name": "awq_triton.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/model_executor/layers/quantization/awq_triton.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.jit\ndef awq_dequantize_kernel(qweight_ptr, scales_ptr, zeros_ptr, group_size,\n result_ptr, num_cols, num_rows, BLOCK_SIZE_X: tl.constexpr,\n BLOCK_SIZE_Y: tl.constexpr):\n pid_x = tl.program_id(axis=0)\n pid_y = tl.program_id(axis=1)\n offsets_y = pid_y * BLOCK_SIZE_Y + tl.arange(0, BLOCK_SIZE_Y)\n offsets_x = pid_x * BLOCK_SIZE_X + tl.arange(0, BLOCK_SIZE_X)\n offsets = num_cols * offsets_y[:, None] + offsets_x[None, :]\n masks_y = offsets_y < num_rows\n masks_x = offsets_x < num_cols\n masks = masks_y[:, None] & masks_x[None, :]\n result_offsets_y = pid_y * BLOCK_SIZE_Y + tl.arange(0, BLOCK_SIZE_Y)\n result_offsets_x = pid_x * BLOCK_SIZE_X * 8 + tl.arange(0, BLOCK_SIZE_X * 8\n )\n result_offsets = 8 * num_cols * result_offsets_y[:, None\n ] + result_offsets_x[None, :]\n result_masks_y = result_offsets_y < num_rows\n result_masks_x = result_offsets_x < num_cols * 8\n result_masks = result_masks_y[:, None] & result_masks_x[None, :]\n iweights = tl.load(qweight_ptr + offsets, masks)\n iweights = tl.interleave(iweights, iweights)\n iweights = tl.interleave(iweights, iweights)\n iweights = tl.interleave(iweights, iweights)\n reverse_awq_order_tensor = ((tl.arange(0, 2) * 4)[None, :] + tl.arange(\n 0, 4)[:, None]).reshape(8)\n shifts = reverse_awq_order_tensor * 4\n shifts = tl.broadcast_to(shifts[None, :], (BLOCK_SIZE_Y * BLOCK_SIZE_X, 8))\n shifts = tl.reshape(shifts, (BLOCK_SIZE_Y, BLOCK_SIZE_X * 8))\n iweights = iweights >> shifts & 15\n zero_offsets_y = pid_y * BLOCK_SIZE_Y // group_size + tl.arange(0, 1)\n zero_offsets_x = pid_x * BLOCK_SIZE_X + tl.arange(0, BLOCK_SIZE_X)\n zero_offsets = num_cols * zero_offsets_y[:, None] + zero_offsets_x[None, :]\n zero_masks_y = zero_offsets_y < num_rows // group_size\n zero_masks_x = zero_offsets_x < num_cols\n zero_masks = zero_masks_y[:, None] & zero_masks_x[None, :]\n zeros = tl.load(zeros_ptr + zero_offsets, zero_masks)\n zeros = tl.interleave(zeros, zeros)\n zeros = tl.interleave(zeros, zeros)\n zeros = tl.interleave(zeros, zeros)\n zeros = tl.broadcast_to(zeros, (BLOCK_SIZE_Y, BLOCK_SIZE_X * 8))\n zeros = zeros >> shifts & 15\n scale_offsets_y = pid_y * BLOCK_SIZE_Y // group_size + tl.arange(0, 1)\n scale_offsets_x = pid_x * BLOCK_SIZE_X * 8 + tl.arange(0, BLOCK_SIZE_X * 8)\n scale_offsets = num_cols * 8 * scale_offsets_y[:, None] + scale_offsets_x[\n None, :]\n scale_masks_y = scale_offsets_y < num_rows // group_size\n scale_masks_x = scale_offsets_x < num_cols * 8\n scale_masks = scale_masks_y[:, None] & scale_masks_x[None, :]\n scales = tl.load(scales_ptr + scale_offsets, scale_masks)\n scales = tl.broadcast_to(scales, (BLOCK_SIZE_Y, BLOCK_SIZE_X * 8))\n iweights = (iweights - zeros) * scales\n iweights = iweights.to(result_ptr.type.element_ty)\n tl.store(result_ptr + result_offsets, iweights, result_masks)\n", "category": { "Functionality": [ "Quantization", "Elementwise Operations" ], "Data Type": [ "uint8", "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/model_executor/layers/quantization/awq_triton.py" }, { "uuid": "6a16d484-c7ae-4445-9911-2a441ad2edc4", "file_name": "matrix_multiplication.py", "repo_name": "gmgu/study-triton", "file_path": "5_out_of_index/matrix_multiplication.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@triton.jit\ndef triton_mm(x_ptr, y_ptr, out_ptr, n: tl.constexpr, m: tl.constexpr, p:\n tl.constexpr, BLOCK_SIZE: tl.constexpr):\n pid0 = tl.program_id(axis=0)\n pid1 = tl.program_id(axis=1)\n x_row_start = tl.arange(0, BLOCK_SIZE)[:, None] * m\n x_col_start = tl.arange(0, BLOCK_SIZE)[None, :]\n x_col_unit = BLOCK_SIZE\n y_row_start = tl.arange(0, BLOCK_SIZE)[:, None] * p\n y_col_start = tl.arange(0, BLOCK_SIZE)[None, :]\n y_row_unit = BLOCK_SIZE * p\n o_row_start = pid0 * BLOCK_SIZE * p + tl.arange(0, BLOCK_SIZE)[:, None] * p\n o_col_start = pid1 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)[None, :]\n o_offset = o_row_start + o_col_start\n out = tl.zeros((BLOCK_SIZE, BLOCK_SIZE), dtype=tl.float32)\n for i in range(tl.cdiv(m, BLOCK_SIZE)):\n x_block = x_row_start + x_col_start\n y_block = y_row_start + y_col_start\n x_offset = pid0 * BLOCK_SIZE * m + x_block\n x_mask = x_row_start < n * m and x_col_start < m\n y_offset = pid1 * BLOCK_SIZE + y_block\n y_mask = y_row_start < m * p and y_col_start < p\n x = tl.load(x_ptr + x_offset, mask=x_mask, other=0.0)\n y = tl.load(y_ptr + y_offset, mask=y_mask, other=0.0)\n out += tl.dot(x, y, allow_tf32=False)\n x_col_start += x_col_unit\n y_row_start += y_row_unit\n o_mask = o_row_start < n * p and o_col_start < p\n tl.store(out_ptr + o_offset, out, mask=o_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/5_out_of_index/matrix_multiplication.py" }, { "uuid": "f80e0e6a-ad55-4272-aace-e1d940a24b8d", "file_name": "reduction.py", "repo_name": "daemyung/practice-triton", "file_path": "reduction.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@triton.jit\ndef sum_kernel(y_ptr, x_ptr, size, block_size: tl.constexpr):\n offsets = tl.arange(0, block_size)\n mask = offsets < size\n x = tl.load(x_ptr + offsets, mask)\n y = tl.reduce(x, 0, combine_add)\n tl.store(y_ptr, y)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/reduction.py" }, { "uuid": "c1001477-cd08-4169-b77e-125bba440902", "file_name": "triton_example.py", "repo_name": "lshmouse/ai-playground", "file_path": "experimental/triton_example/triton_example.py", "commit_hash": "3d91bd77464e2a7fb0ce49180fc6d20e98869a73", "starcount": 0, "input": "@triton.jit\ndef softmax(Y, stride_ym, stride_yn, X, stride_xm, stride_xn, M, N):\n m = tl.program_id(0)\n BLOCK_SIZE: tl.constexpr = 1024\n n = tl.arange(0, BLOCK_SIZE)\n X = X + m * stride_xm + n * stride_xn\n x = tl.load(X, mask=n < N, other=-float('inf'))\n z = x - tl.max(x, axis=0)\n num = tl.exp(z)\n denom = tl.sum(num, axis=0)\n y = num / denom\n Y = Y + m * stride_ym + n * stride_yn\n tl.store(Y, y, mask=n < N)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/lshmouse/ai-playground/blob/3d91bd77464e2a7fb0ce49180fc6d20e98869a73/experimental/triton_example/triton_example.py" }, { "uuid": "a78ad7b2-9ebf-4407-be34-12ed6daa1918", "file_name": "triton_call_test.py", "repo_name": "jax-ml/jax-triton", "file_path": "tests/triton_call_test.py", "commit_hash": "859cc392bec876d132bd0790ea6c00b6c246dd2b", "starcount": 0, "input": "@triton.jit\ndef copy_twice_kernel(a_ptr, x_ptr, y_ptr):\n a = tl.load(a_ptr)\n tl.store(x_ptr, a)\n tl.store(y_ptr, a)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/jax-ml/jax-triton/blob/859cc392bec876d132bd0790ea6c00b6c246dd2b/tests/triton_call_test.py" }, { "uuid": "22a19981-d2fc-4603-a185-6608ad153106", "file_name": "sgmv_expand_slice.py", "repo_name": "IBM/vllm", "file_path": "vllm/lora/ops/sgmv_expand_slice.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _sgmv_expand_slice_kernel(input_ptr, lora_ptr, out_ptr, N, K,\n b_seq_start_loc, seq_lens, lora_indices, xm_stride, xk_stride,\n l0_stride, lora_k_stride, lora_n_stride, cm_stride, cn_stride,\n slice_offset, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl\n .constexpr, EVEN_K: tl.constexpr, ADD_INPUTS: tl.constexpr, CAST_TYPE:\n tl.constexpr):\n \"\"\"\n\n Similar to the 'sgmv_expand' operator, but with an added parameter \n 'slice_offset'. The reason for not reusing the 'sgmv_expand' operator \n might be that in the future, we could implement a fusion operator to \n achieve the current functionality instead of having to call it multiple \n times.\n \"\"\"\n pid = tl.program_id(axis=0)\n cur_batch = tl.program_id(axis=1)\n cta_n_num = tl.cdiv(N, BLOCK_N)\n pid_m = pid // cta_n_num\n pid_n = pid % cta_n_num\n M = tl.load(seq_lens + cur_batch)\n if pid_m * BLOCK_M > M:\n return\n lora_index = tl.load(lora_indices + cur_batch)\n if lora_index == -1:\n return\n cur_seq_start = tl.load(b_seq_start_loc + cur_batch)\n offset_m = tl.arange(0, BLOCK_M) + pid_m * BLOCK_M\n offset_n = tl.arange(0, BLOCK_N) + pid_n * BLOCK_N\n offset_k = tl.arange(0, BLOCK_K)\n ram = tl.max_contiguous(tl.multiple_of(offset_m % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(offset_n % N, BLOCK_N), BLOCK_N)\n a_ptr = input_ptr + cur_seq_start * xm_stride + ram[:, None\n ] * xm_stride + offset_k[None, :] * xk_stride,\n b_ptr = lora_ptr + l0_stride * lora_index + offset_k[:, None\n ] * lora_n_stride + rbn[None, :] * lora_k_stride\n accumulator = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n for k in range(tl.cdiv(K, BLOCK_K)):\n if EVEN_K:\n tiled_a = tl.load(a_ptr)\n tiled_b = tl.load(b_ptr)\n else:\n tiled_a = tl.load(a_ptr, mask=offset_k[None, :] < K - k *\n BLOCK_K, other=0)\n tiled_b = tl.load(b_ptr, mask=offset_k[:, None] < K - k *\n BLOCK_K, other=0)\n if CAST_TYPE:\n tiled_a = tiled_a.to(lora_ptr.dtype.element_ty)\n accumulator += tl.dot(tiled_a, tiled_b)\n a_ptr += BLOCK_K * xk_stride\n b_ptr += BLOCK_K * lora_n_stride\n tiled_c = accumulator.to(lora_ptr.dtype.element_ty)\n offset_cm = cur_seq_start + tl.arange(0, BLOCK_M) + pid_m * BLOCK_M\n offset_cn = tl.arange(0, BLOCK_N) + pid_n * BLOCK_N + slice_offset\n c_ptr = out_ptr + offset_cm[:, None] * cm_stride + offset_cn[None, :\n ] * cn_stride\n M = tl.load(seq_lens + cur_batch)\n c_mask = (offset_cm[:, None] < cur_seq_start + M) & (offset_cn[None, :] <\n slice_offset + N)\n if ADD_INPUTS:\n tiled_out = tl.load(c_ptr, mask=c_mask, other=None)\n tiled_c += tiled_out\n tl.store(c_ptr, tiled_c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/lora/ops/sgmv_expand_slice.py" }, { "uuid": "404e3e4e-48df-4d01-9ca3-88d31910bc38", "file_name": "masked_load_store.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/masked_load_store.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef mload2d(REG_ROWS: tl.constexpr, REG_COLS: tl.constexpr, i_base,\n i_start_row, i_start_col, i_rows, i_cols, stride_row, stride_col):\n off_rows = tl.arange(0, REG_ROWS) + i_start_row\n off_cols = tl.arange(0, REG_COLS) + i_start_col\n i_ptrs = i_base + off_rows[:, None] * stride_row + off_cols[None, :\n ] * stride_col\n row_overflow = i_start_row + REG_ROWS - i_rows\n col_overflow = i_start_col + REG_COLS - i_cols\n i_ptrs_mask = tl.full([REG_ROWS, REG_COLS], 1, dtype=tl.int1)\n if row_overflow > 0:\n i_ptrs_mask = i_ptrs_mask & (off_rows[:, None] < i_rows)\n if col_overflow > 0:\n i_ptrs_mask = i_ptrs_mask & (off_cols[None, :] < i_cols)\n return tl.load(i_ptrs, mask=i_ptrs_mask, other=0.0)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/masked_load_store.py" }, { "uuid": "00c82ef8-66e1-47a7-8dd2-64f2b33c6b0b", "file_name": "matmul.py", "repo_name": "MichaelWei7/torch", "file_path": "_inductor/triton_ops/matmul.py", "commit_hash": "4bfe6988308edc9544ddae94bfdcf83a4326b04a", "starcount": 0, "input": "@mm_heuristics()\n@mm_autotune(get_io_bound_configs=True)\n@triton.jit\ndef _kernel(A, B, C, M, N, K, stride_am, stride_ak, stride_bk, stride_bn,\n stride_cm, stride_cn, allow_tf32: tl.constexpr, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr,\n SPLIT_K: tl.constexpr, EVEN_K: tl.constexpr, ACC_TYPE: tl.constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = (M + BLOCK_M - 1) // BLOCK_M\n grid_n = (N + BLOCK_N - 1) // BLOCK_N\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=ACC_TYPE)\n for k in range(K, 0, -BLOCK_K * SPLIT_K):\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n a = tl.load(A, mask=rk[None, :] < k, other=0.0)\n b = tl.load(B, mask=rk[:, None] < k, other=0.0)\n acc += tl.dot(a, b, allow_tf32=allow_tf32)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n acc = acc.to(C.dtype.element_ty)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if SPLIT_K == 1:\n tl.store(C, acc, mask=mask)\n else:\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/MichaelWei7/torch/blob/4bfe6988308edc9544ddae94bfdcf83a4326b04a/_inductor/triton_ops/matmul.py" }, { "uuid": "cc5bd1e2-ee94-444e-9383-a3e3b726ce7c", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/hgrn/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BD': BD}, num_warps=num_warps) for\n BD in [32, 64, 128] for num_warps in [1, 2, 4, 8]], key=['D'])\n@triton.jit\ndef fused_recurrent_hgrn_fwd_kernel(x, g, o, h0, ht, offsets, T: tl.\n constexpr, D: tl.constexpr, BD: tl.constexpr, USE_INITIAL_STATE: tl.\n constexpr, STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_d, i_n = tl.program_id(0), tl.program_id(1)\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n o_d = i_d * BD + tl.arange(0, BD)\n mask = o_d < D\n p_x = x + bos * D + o_d\n p_g = g + bos * D + o_d\n p_o = o + bos * D + o_d\n b_h = tl.zeros([BD], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_n * D + o_d\n b_h += tl.load(p_h0, mask=mask, other=0).to(tl.float32)\n for _ in range(0, T):\n b_x = tl.load(p_x, mask=mask, other=0).to(tl.float32)\n b_g = tl.load(p_g, mask=mask, other=0).to(tl.float32)\n b_h = tl.exp(b_g) * b_h + b_x\n tl.store(p_o, b_h.to(p_o.dtype.element_ty), mask=mask)\n p_x += D\n p_g += D\n p_o += D\n if STORE_FINAL_STATE:\n p_ht = ht + i_n * D + o_d\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), mask=mask)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/hgrn/fused_recurrent.py" }, { "uuid": "abce0537-6e40-4d23-9771-998b073c6648", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _jagged_flash_attention_bwd_basic_kernel(q_ptr, k_ptr, v_ptr, o_ptr,\n offset_ptr, dq_ptr, dk_ptr, dv_ptr, do_ptr, delta_ptr, lse_ptr,\n stride_qm, stride_qd, stride_kn, stride_kd, stride_vn, stride_vd,\n stride_om, stride_od, stride_dqm, stride_dqd, stride_dkn, stride_dkd,\n stride_dvn, stride_dvd, stride_dom, stride_dod, max_seq_len, D: tl.\n constexpr, use_mask: tl.constexpr, allow_tf32: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_D:\n tl.constexpr):\n pid_batch = tl.program_id(axis=1)\n begin = tl.load(offset_ptr + pid_batch)\n end = tl.load(offset_ptr + pid_batch + 1)\n M = tl.minimum(end - begin, max_seq_len)\n pid_n = tl.program_id(axis=0)\n offs_d = tl.arange(0, BLOCK_SIZE_D)\n offs_n = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offs_m = tl.arange(0, BLOCK_SIZE_M)\n q_ptrs = q_ptr + begin * stride_qm + (offs_m[:, None] * stride_qm + \n offs_d[None, :] * stride_qd)\n k_ptrs = k_ptr + begin * stride_kn + (offs_n[:, None] * stride_kn + \n offs_d[None, :] * stride_kd)\n v_ptrs = v_ptr + begin * stride_vn + (offs_n[:, None] * stride_vn + \n offs_d[None, :] * stride_vd)\n do_ptrs = do_ptr + begin * stride_dom + (offs_m[:, None] * stride_dom +\n offs_d[None, :] * stride_dod)\n k = tl.load(k_ptrs, mask=(offs_d[None, :] < D) & (offs_n[:, None] < M))\n v = tl.load(v_ptrs, mask=(offs_d[None, :] < D) & (offs_n[:, None] < M))\n dv = tl.zeros([BLOCK_SIZE_N, BLOCK_SIZE_D], dtype=tl.float32)\n dk = tl.zeros([BLOCK_SIZE_N, BLOCK_SIZE_D], dtype=tl.float32)\n for begin_m in range(0, M, BLOCK_SIZE_M):\n offs_m_temp = begin_m + offs_m\n q = tl.load(q_ptrs, mask=(offs_d[None, :] < D) & (offs_m_temp[:,\n None] < M))\n qk = tl.dot(q, tl.trans(k), allow_tf32=allow_tf32)\n mn_mask = (offs_m_temp[:, None] < M) & (offs_n[None, :] < M)\n lse_i = tl.load(lse_ptr + offs_m_temp + begin, mask=offs_m_temp < M)\n p = tl.exp(qk - lse_i[:, None])\n p = tl.where(mn_mask, p, 0.0)\n p /= max_seq_len\n p_masked = p\n attn_mask = None\n if use_mask:\n attn_mask = offs_m_temp[:, None] - offs_n[None, :]\n attn_mask = tl.where(mn_mask, attn_mask, 0.0)\n attn_mask = tl.where(attn_mask > 0, 0.0, 1.0)\n p_masked = tl.where(attn_mask > 0, p, 0.0)\n p_masked = p_masked.to(do_ptr.dtype.element_ty)\n do = tl.load(do_ptrs, mask=(offs_d[None, :] < D) & (offs_m_temp[:,\n None] < M))\n dv += tl.dot(tl.trans(p_masked), do, allow_tf32=allow_tf32)\n dp = tl.dot(do, tl.trans(v), allow_tf32=allow_tf32)\n Di = tl.load(delta_ptr + offs_m_temp + begin, mask=offs_m_temp < M)\n dp_masked = dp\n if use_mask:\n dp_masked = tl.where(attn_mask > 0, dp, 0.0)\n ds = p * (dp_masked - Di[:, None] * max_seq_len)\n ds = ds.to(q_ptr.dtype.element_ty)\n dk += tl.dot(tl.trans(ds), q, allow_tf32=allow_tf32)\n q_ptrs += BLOCK_SIZE_M * stride_qm\n do_ptrs += BLOCK_SIZE_M * stride_dom\n dk_ptrs = dk_ptr + begin * stride_dkn + (offs_n[:, None] * stride_dkn +\n offs_d[None, :] * stride_dkd)\n dv_ptrs = dv_ptr + begin * stride_dvn + (offs_n[:, None] * stride_dvn +\n offs_d[None, :] * stride_dvd)\n tl.store(dk_ptrs, dk, mask=(offs_d[None, :] < D) & (offs_n[:, None] < M))\n tl.store(dv_ptrs, dv, mask=(offs_d[None, :] < D) & (offs_n[:, None] < M))\n start_m = tl.program_id(axis=0) * BLOCK_SIZE_N\n offs_m_curr = start_m + tl.arange(0, BLOCK_SIZE_N)\n dq_ptrs_curr = dq_ptr + begin * stride_dqm + (offs_m_curr[:, None] *\n stride_dqm + offs_d[None, :] * stride_dqd)\n dq_curr = tl.zeros([BLOCK_SIZE_N, BLOCK_SIZE_D], dtype=tl.float32)\n q_ptrs_curr = q_ptr + begin * stride_qm + (offs_m_curr[:, None] *\n stride_qm + offs_d[None, :] * stride_qd)\n q_curr = tl.load(q_ptrs_curr, mask=(offs_d[None, :] < D) & (offs_m_curr\n [:, None] < M))\n lse_i_curr = tl.load(lse_ptr + offs_m_curr + begin, mask=offs_m_curr < M)\n do_ptrs_curr = do_ptr + begin * stride_dom + (offs_m_curr[:, None] *\n stride_dom + offs_d[None, :] * stride_dod)\n do_curr = tl.load(do_ptrs_curr, mask=(offs_d[None, :] < D) & (\n offs_m_curr[:, None] < M))\n Di_curr = tl.load(delta_ptr + offs_m_curr + begin, mask=offs_m_curr < M)\n block_start = 0\n while block_start < M:\n offs_n_curr = block_start + tl.arange(0, BLOCK_SIZE_M)\n k_ptrs_curr = k_ptr + begin * stride_kn + (offs_n_curr[:, None] *\n stride_kn + offs_d[None, :] * stride_kd)\n v_ptrs_curr = v_ptr + begin * stride_vn + (offs_n_curr[:, None] *\n stride_vn + offs_d[None, :] * stride_vd)\n k_curr = tl.load(k_ptrs_curr, mask=(offs_d[None, :] < D) & (\n offs_n_curr[:, None] < M))\n v_curr = tl.load(v_ptrs_curr, mask=(offs_d[None, :] < D) & (\n offs_n_curr[:, None] < M))\n qk_curr = tl.dot(q_curr, tl.trans(k_curr), allow_tf32=allow_tf32)\n mn_mask_curr = (offs_m_curr[:, None] < M) & (offs_n_curr[None, :] < M)\n p_curr = tl.exp(qk_curr - lse_i_curr[:, None])\n p_curr = tl.where(mn_mask_curr, p_curr, 0.0)\n p_curr /= max_seq_len\n dp_curr = tl.dot(do_curr, tl.trans(v_curr), allow_tf32=allow_tf32)\n dp_curr_masked = dp_curr\n if use_mask:\n attn_mask = offs_m_curr[:, None] - offs_n_curr[None, :]\n attn_mask = tl.where(mn_mask_curr, attn_mask, 0.0)\n attn_mask = tl.where(attn_mask > 0, 0.0, 1.0)\n dp_curr_masked = tl.where(attn_mask > 0, dp_curr, 0.0)\n ds_curr = p_curr * (dp_curr_masked - Di_curr[:, None] * max_seq_len)\n ds_curr = ds_curr.to(k_ptr.dtype.element_ty)\n dq_curr += tl.dot(ds_curr, k_curr, allow_tf32=allow_tf32)\n block_start += BLOCK_SIZE_M\n tl.store(dq_ptrs_curr, dq_curr, mask=(offs_d[None, :] < D) & (\n offs_m_curr[:, None] < M))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "617a9bbf-b4c6-4dab-8223-f52320eabcd6", "file_name": "kernels.py", "repo_name": "ShenzheZhu/sparse_autoencoder", "file_path": "sparse_autoencoder/kernels.py", "commit_hash": "afef049c905fda5b0f69729127ce0d3a42399152", "starcount": 0, "input": "@triton.jit\ndef triton_mse_loss_fp16_kernel(output_ptr, target_ptr, out_ptr,\n stride_a_output, stride_a_target, a, b, BLOCK_SIZE_B: tl.constexpr):\n pid = tl.program_id(0)\n offsets_b = tl.arange(0, BLOCK_SIZE_B)\n output = tl.load(output_ptr + pid * stride_a_output + offsets_b, mask=\n offsets_b < b)\n target = tl.load(target_ptr + pid * stride_a_target + offsets_b, mask=\n offsets_b < b)\n output = output.to(tl.float32)\n target = target.to(tl.float32)\n mse = tl.sum((output - target) * (output - target)) / b\n tl.store(out_ptr + pid, mse)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ShenzheZhu/sparse_autoencoder/blob/afef049c905fda5b0f69729127ce0d3a42399152/sparse_autoencoder/kernels.py" }, { "uuid": "00406477-a3a9-43aa-bcb6-92042cbffae0", "file_name": "04-low-memory-dropout.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/04-low-memory-dropout.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _dropout(x_ptr, x_keep_ptr, output_ptr, n_elements, p, BLOCK_SIZE: tl.\n constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n x = tl.load(x_ptr + offsets, mask=mask)\n x_keep = tl.load(x_keep_ptr + offsets, mask=mask)\n output = tl.where(x_keep, x / (1 - p), 0.0)\n tl.store(output_ptr + offsets, output, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/04-low-memory-dropout.py" }, { "uuid": "020e145a-16d9-4584-82d7-d36d740a0ca5", "file_name": "stats.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/stats.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _Stats_cl3d_impl(X_ptr, Mean_ptr, Sqmean_ptr, numel_no_channels,\n num_channels: tl.constexpr, block_other: tl.constexpr):\n pid = tl.program_id(0)\n X_ptr += pid * block_other * num_channels\n channels_offset = tl.arange(0, num_channels)\n other_offset = tl.arange(0, block_other)\n offset = other_offset[:, None] * num_channels + channels_offset[None, :]\n mask = other_offset[:, None] < numel_no_channels - pid * block_other\n x = tl.load(X_ptr + offset, mask=mask, other=0.0).to(tl.float32)\n mean = tl.sum(x, axis=0) / numel_no_channels\n sqmean = tl.sum(x * x, axis=0) / numel_no_channels\n tl.atomic_add(Mean_ptr + channels_offset, mean)\n tl.atomic_add(Sqmean_ptr + channels_offset, sqmean)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/stats.py" }, { "uuid": "60939418-875a-427c-b473-1f90ef624523", "file_name": "gemm_preop_exp_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_preop_exp_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32), triton.Config({'BLOCK_SIZE_M': \n 256, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4,\n 'grf_mode': 'large'}, num_stages=3, num_warps=32), triton.Config({\n 'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32\n ), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =2, num_warps=32), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': \n 128, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'},\n num_stages=2, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers_batched(a_ptr, b_ptr, c_ptr, B: tl.\n constexpr, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr, stride_az:\n tl.constexpr, stride_am: tl.constexpr, stride_ak: tl.constexpr,\n stride_bz: tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.\n constexpr, stride_cz: tl.constexpr, stride_cm: tl.constexpr, stride_cn:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n bid = tl.program_id(axis=0)\n pid = tl.program_id(axis=1)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offset_a = bid.to(tl.int64) * stride_az\n offset_b = bid.to(tl.int64) * stride_bz\n a_block_ptr = tl.make_block_ptr(base=a_ptr + offset_a, shape=(M, K),\n strides=(stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr + offset_b, shape=(K, N),\n strides=(stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n a = a.to(tl.float32)\n a = tl.math.exp(a)\n a = a.to(tl.bfloat16)\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c = accumulator.to(tl.float32)\n offset_c = bid.to(tl.int64) * stride_cz\n c_block_ptr = tl.make_block_ptr(base=c_ptr + offset_c, shape=(M, N),\n strides=(stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, \n pid_n * BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N),\n order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_preop_exp_benchmark.py" }, { "uuid": "b2ab2e7c-d4ec-466b-bffb-cb8427e67f7f", "file_name": "l2norm.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/l2norm.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16, 32]], key=['N'])\n@triton.jit\ndef l2norm_fwd_kernel(X, Y, stride_x_row, N, eps, BLOCK_N: tl.constexpr):\n row = tl.program_id(0)\n X += row * stride_x_row\n Y += row * stride_x_row\n cols = tl.arange(0, BLOCK_N)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n xbar = tl.where(cols < N, x, 0.0)\n var = tl.sum(xbar * xbar, axis=0)\n rstd = 1 / tl.sqrt(var + eps)\n mask = cols < N\n y = x * rstd\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/l2norm.py" }, { "uuid": "3fed2f1b-c00b-47df-86e8-85fac9efc3b4", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_flash_attention_basic_kernel(q_ptr, k_ptr, v_ptr, offset_ptr,\n o_ptr, lse_i_ptr, stride_qm, stride_qd, stride_kd, stride_kn, stride_vn,\n stride_vd, stride_om, stride_od, max_seq_len, D: tl.constexpr, NEXT_D:\n tl.constexpr, use_mask: tl.constexpr, allow_tf32: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_D:\n tl.constexpr):\n pid_m = tl.program_id(axis=0)\n pid_batch = tl.program_id(axis=1)\n begin = tl.load(offset_ptr + pid_batch)\n end = tl.load(offset_ptr + pid_batch + 1)\n seqlen = end - begin\n seqlen = tl.minimum(seqlen, max_seq_len)\n if pid_m * BLOCK_SIZE_M >= seqlen:\n return\n offs_m = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_d = tl.arange(0, BLOCK_SIZE_D)\n offs_nextd = tl.arange(0, NEXT_D)\n acc = tl.zeros([BLOCK_SIZE_M, NEXT_D], dtype=tl.float32)\n m_i = tl.zeros([BLOCK_SIZE_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_SIZE_M], dtype=tl.float32)\n for j in range(0, seqlen, BLOCK_SIZE_N):\n offs_n = tl.arange(0, BLOCK_SIZE_N) + j\n q_ptrs = q_ptr + (offs_m[:, None] * stride_qm + offs_d[None, :] *\n stride_qd) + begin * stride_qm\n k_ptrs = k_ptr + (offs_d[:, None] * stride_kd + offs_n[None, :] *\n stride_kn) + begin * stride_kn\n qk = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for d in range(0, D, BLOCK_SIZE_D):\n updated_offset = d + offs_d\n q = tl.load(q_ptrs, mask=(updated_offset[None, :] < D) & (\n offs_m[:, None] < seqlen), other=0.0)\n k = tl.load(k_ptrs, mask=(updated_offset[:, None] < D) & (\n offs_n[None, :] < seqlen), other=0.0)\n qk += tl.dot(q, k, allow_tf32=allow_tf32)\n q_ptrs += BLOCK_SIZE_D * stride_qd\n k_ptrs += BLOCK_SIZE_D * stride_kd\n m_ij = tl.maximum(tl.max(qk, axis=1), m_i)\n mn_mask = (offs_m[:, None] < seqlen) & (offs_n[None, :] < seqlen)\n p = tl.exp(qk - m_ij[:, None])\n p = tl.where(mn_mask, p, 0.0)\n l_ij = tl.sum(p, axis=1)\n alpha = tl.exp(m_i - m_ij)\n l_i = l_i * alpha + l_ij\n acc = acc * alpha[:, None]\n v_ptrs = v_ptr + (offs_nextd[None, :] * stride_vd + offs_n[:, None] *\n stride_vn) + begin * stride_vn\n v = tl.load(v_ptrs, mask=(offs_nextd[None, :] < D) & (offs_n[:,\n None] < seqlen), other=0.0)\n p /= max_seq_len\n if use_mask:\n attn_mask = offs_m[:, None] - offs_n[None, :]\n attn_mask = tl.where(mn_mask, attn_mask, 0.0)\n attn_mask = tl.where(attn_mask > 0, 0.0, 1.0)\n p = tl.where(attn_mask > 0, p, 0.0)\n p = p.to(v_ptr.dtype.element_ty)\n acc_j = tl.dot(p, v, allow_tf32=allow_tf32)\n acc += acc_j\n m_i = m_ij\n lse_i = m_i + tl.math.log(l_i)\n lse_i_offsets = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n lse_i_ptrs = lse_i_ptr + lse_i_offsets + begin\n tl.store(lse_i_ptrs, lse_i, mask=lse_i_offsets < seqlen)\n acc = acc / l_i[:, None]\n o_ptrs = o_ptr + (offs_m[:, None] * stride_om + offs_nextd[None, :] *\n stride_od + begin * stride_om)\n o_mask = (offs_m[:, None] < seqlen) & (offs_nextd[None, :] < D)\n tl.store(o_ptrs, acc, mask=o_mask)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "b69d2cf0-95a2-423a-a626-19d6cb20f407", "file_name": "bnrelu.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/bnrelu.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _ApplyBNReLU_cl3d_backward_impl(Input_ptr, Weight_ptr, Bias_ptr,\n Grad_ptr, Outgrad_ptr, Weight_outgrad_ptr, Bias_outgrad_ptr,\n numel_no_channels, BLOCK_SIZE: tl.constexpr, num_channels: tl.constexpr,\n block_other: tl.constexpr):\n pid = tl.program_id(0)\n Input_ptr += pid * BLOCK_SIZE\n Grad_ptr += pid * BLOCK_SIZE\n Outgrad_ptr += pid * BLOCK_SIZE\n channels_offset = tl.arange(0, num_channels)\n other_offset = tl.arange(0, block_other)\n offset = channels_offset[None, :] + other_offset[:, None] * num_channels\n mask = (other_offset < numel_no_channels - pid * block_other)[:, None]\n weight = tl.load(Weight_ptr + channels_offset[None, :])\n bias = tl.load(Bias_ptr + channels_offset[None, :])\n input = tl.load(Input_ptr + offset, mask=mask, other=0).to(tl.float32)\n grad = tl.load(Grad_ptr + offset, mask=mask, other=0).to(tl.float32)\n grad = grad * (input * weight > -bias)\n b_grad = tl.sum(grad, axis=0)\n w_grad = tl.sum(input * grad, axis=0)\n x_grad = weight * grad\n tl.store(Outgrad_ptr + offset, x_grad, mask=mask)\n tl.atomic_add(Bias_outgrad_ptr + channels_offset, b_grad)\n tl.atomic_add(Weight_outgrad_ptr + channels_offset, w_grad)\n", "category": { "Functionality": [ "Backpropagation", "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/bnrelu.py" }, { "uuid": "5322126e-9117-4fd6-bd2b-3de14befa10d", "file_name": "argmax.py", "repo_name": "daemyung/practice-triton", "file_path": "argmax.py", "commit_hash": "27f727726f1507c8380a1c11751d851c7c4a07ce", "starcount": 0, "input": "@triton.jit\ndef argmax_kernel(output_ptr, input_ptr, num_batches, size, block_size: tl.\n constexpr):\n batch = tl.program_id(0)\n output_block_ptr = tl.make_block_ptr(output_ptr, shape=(num_batches,),\n strides=(1,), offsets=(batch,), block_shape=(1,), order=(0,))\n input_block_ptr = tl.make_block_ptr(input_ptr, shape=(num_batches, size\n ), strides=(size, 1), offsets=(batch, 0), block_shape=(1,\n block_size), order=(1, 0))\n input = tl.load(input_block_ptr, boundary_check=(1,))\n condition = tl.arange(0, block_size) < size\n input = tl.where(condition, input, float('-inf'))\n output = tl.argmax(input, 1)\n tl.store(output_block_ptr, output.to(tl.int64))\n", "category": { "Functionality": [ "Top-K Selection" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/daemyung/practice-triton/blob/27f727726f1507c8380a1c11751d851c7c4a07ce/argmax.py" }, { "uuid": "fd103ed2-89cc-476f-a89e-f223e86b5d3b", "file_name": "GELUglu.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/GELUglu.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _gelu_glu_bwd_kernel(grad_output_ptr, grad_input_ptr, input_ptr,\n grad_output_row_stride, grad_input_row_stride, input_row_stride,\n grad_output_col_stride, grad_input_col_stride, input_col_stride,\n grad_output_page_stride, grad_input_page_stride, input_page_stride,\n n_pages, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1)\n grad_output = tl.load(grad_output_ptr + row_idx *\n grad_output_row_stride + col_idx * grad_output_col_stride + tl.\n arange(0, BLOCK_SIZE // 2) * grad_output_page_stride, mask=tl.\n arange(0, BLOCK_SIZE // 2) < n_pages // 2, other=-float('inf'))\n x = tl.load(input_ptr + row_idx * input_row_stride + col_idx *\n input_col_stride + tl.arange(0, BLOCK_SIZE // 2) *\n input_page_stride, mask=tl.arange(0, BLOCK_SIZE // 2) < n_pages // \n 2, other=-float('inf'))\n gate = tl.load(input_ptr + row_idx * input_row_stride + col_idx *\n input_col_stride + (tl.arange(0, BLOCK_SIZE // 2) + n_pages // 2) *\n input_page_stride, mask=tl.arange(0, BLOCK_SIZE // 2) < n_pages // \n 2, other=-float('inf'))\n gate_cube = gate * gate * gate\n beta = 0.7978845608028654\n kappa = 0.044715\n inner = beta * (gate + kappa * gate_cube)\n inner_tanh = tanh(inner)\n gate_gelu = 0.5 * gate * (inner_tanh + 1)\n grad_x = grad_output * gate_gelu\n grad_gelu = grad_output * x\n grad_gate = grad_gelu * (0.5 * (1 + inner_tanh) + 0.5 * gate * (1 - \n inner_tanh * inner_tanh) * beta * (1 + kappa * 3 * gate * gate))\n tl.store(grad_input_ptr + row_idx * grad_input_row_stride + col_idx *\n grad_input_col_stride + tl.arange(0, BLOCK_SIZE // 2) *\n grad_input_page_stride, grad_x, mask=tl.arange(0, BLOCK_SIZE // 2) <\n n_pages // 2)\n tl.store(grad_input_ptr + row_idx * grad_input_row_stride + col_idx *\n grad_input_col_stride + (tl.arange(0, BLOCK_SIZE // 2) + n_pages //\n 2) * grad_input_page_stride, grad_gate, mask=tl.arange(0, \n BLOCK_SIZE // 2) < n_pages // 2)\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/GELUglu.py" }, { "uuid": "b78a037f-d294-4568-94ea-bab6c450fa01", "file_name": "associative_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/associative_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _associative_rnn_scan_bwd_kernel():\n pass\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/associative_rnn_scan.py" }, { "uuid": "fd49ac89-d287-4343-b1e7-e546da6abbf4", "file_name": "triton_jagged_tensor_ops.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef tensor_elementwise_mul(x, y):\n return x * y\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/jagged/triton_jagged_tensor_ops.py" }, { "uuid": "b2943844-2b11-4fe4-b90a-1c6e1ebcd741", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_first_order_fwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, sph_1_0_ptr: tl.tensor, sph_1_1_ptr: tl.tensor, sph_1_2_ptr: tl\n .tensor, BLOCK_SIZE: tl.constexpr, vector_length: tl.constexpr):\n \"\"\"\n First order spherical harmonics in Triton.\n\n Computationally not that intensive, as we're just applying\n a sqrt 3 to the coordinates, but also good for validating\n the kernel performs as intended.\n\n Parameters\n ----------\n x_ptr, y_ptr, z_ptr : tl.tensor\n Pointers to the coordinate tensors.\n sph_1_0_ptr, sph_1_1_ptr, sph_1_2_ptr : tl.tensor\n Points to tensors to write outputs to. Assumed to\n be the same length as the input tensors.\n block_size : tl.constexpr\n Vector length of contiguous elements to load into memory\n within a given block.\n vector_length : tl.constexpr\n The maximum/total length of the vectors, assumed to\n be the same for every one. This is used to calculate\n the mask to keep operations within bounds.\n \"\"\"\n sqrt_3 = 3 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n sph_1_0 = sqrt_3 * x\n sph_1_1 = sqrt_3 * y\n sph_1_2 = sqrt_3 * z\n sph_1_0_start = sph_1_0_ptr + offset\n sph_1_1_start = sph_1_1_ptr + offset\n sph_1_2_start = sph_1_2_ptr + offset\n tl.store(sph_1_0_start, sph_1_0, mask=offset < vector_length)\n tl.store(sph_1_1_start, sph_1_1, mask=offset < vector_length)\n tl.store(sph_1_2_start, sph_1_2, mask=offset < vector_length)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "6b382133-1769-4334-a6ac-ea7373510dc5", "file_name": "GELUglu.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/GELUglu.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef tanh(x):\n tanh_neg = (tl.math.exp(x * 2) - 1) / (tl.math.exp(x * 2) + 1)\n tanh_pos = (1 - tl.math.exp(-2 * x)) / (1 + tl.math.exp(-2 * x))\n tanh = tl.where(x > 0, tanh_pos, tanh_neg)\n return tanh\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/GELUglu.py" }, { "uuid": "fe78e351-fd17-4f43-a401-eb4f64797791", "file_name": "triton_fused_attn_ad.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_attn_ad.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'TOTAL_SLOTS': lambda args: sum(args['CODEBOOK_SIZE'] **\n i for i in range(1, args['CODEBOOK_NUM'] + 1))})\n@triton.jit\ndef _fwd_kernel(Q, CODEBOOK_K, CODEBOOK_V, KCNT, VCNT, Out, softmax_scale,\n stride_qb, stride_qh, stride_qm, stride_kb, stride_kh, stride_kn,\n stride_vb, stride_vh, stride_vn, stride_ob, stride_oh, stride_om,\n nheads, seqlen_q, CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, CODEBOOK_SIZE:\n tl.constexpr, CODEBOOK_NUM: tl.constexpr, TOTAL_SLOTS: tl.constexpr,\n IS_CAUSAL: tl.constexpr, BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n Q_block_ptr = tl.make_block_ptr(base=Q + (off_b * stride_qb + off_h *\n stride_qh), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_qm, 1),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_HEADDIM\n ), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + (off_b * stride_kb + off_h *\n stride_kh), shape=(TOTAL_SLOTS, BLOCK_HEADDIM), strides=(stride_kn,\n 1), offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n V_block_ptr = tl.make_block_ptr(base=V + (off_b * stride_vb + off_h *\n stride_vh), shape=(TOTAL_SLOTS, BLOCK_HEADDIM), strides=(stride_vn,\n 1), offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n lse_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc_o = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M:\n q = tl.load(Q_block_ptr)\n else:\n q = tl.load(Q_block_ptr, boundary_check=(0,), padding_option='zero')\n offset = 0\n for level_idx in range(1, CODEBOOK_NUM + 1):\n K_inner_block_ptr = K_block_ptr\n V_inner_block_ptr = V_block_ptr\n z_value = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n z_idx = tl.zeros([BLOCK_M], dtype=tl.int32)\n for start_n in range(0, CODEBOOK_SIZE, BLOCK_N):\n k = tl.load(K_inner_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, tl.trans(k))\n qk_max = tl.max(qk, 1)\n m_ij = tl.maximum(qk_max * softmax_scale, lse_i)\n p = tl.exp(qk * softmax_scale - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n qk_max_indices = tl.argmax(qk, 1) + start_n\n update_codebook = z_value < qk_max\n z_idx = tl.where(update_codebook, qk_max_indices, z_idx)\n z_value = tl.where()\n acc_o_scale = tl.exp(m_i - m_ij)\n acc_o = acc_o * acc_o_scale[:, None]\n v = tl.load(V_inner_block_ptr)\n p = p.to(v.dtype)\n acc_o += tl.dot(p, v)\n m_i = m_ij\n l_i_new = tl.exp(lse_i - m_ij) + l_ij\n lse_i = m_ij + tl.log(l_i_new)\n K_inner_block_ptr = tl.advance(K_inner_block_ptr, (BLOCK_N, 0))\n V_inner_block_ptr = tl.advance(V_inner_block_ptr, (BLOCK_N, 0))\n end_n = seqlen_k if not IS_CAUSAL else tl.minimum((start_m + 1) *\n BLOCK_M, seqlen_k)\n for start_n in range(0, end_n, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_N & EVEN_M:\n k = tl.load(K_block_ptr)\n else:\n k = tl.load(K_block_ptr, boundary_check=(0,), padding_option='zero'\n )\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, tl.trans(k))\n if not EVEN_N:\n qk += tl.where((start_n + offs_n)[None, :] < seqlen_k, 0, NEGINF)\n if IS_CAUSAL:\n qk += tl.where(offs_m[:, None] >= (start_n + offs_n)[None, :], \n 0, NEGINF)\n m_ij = tl.maximum(tl.max(qk, 1) * softmax_scale, lse_i)\n p = tl.exp(qk * softmax_scale - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n acc_o_scale = tl.exp(m_i - m_ij)\n acc_o = acc_o * acc_o_scale[:, None]\n if EVEN_N & EVEN_M:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(0,), padding_option='zero'\n )\n p = p.to(v.dtype)\n acc_o += tl.dot(p, v)\n m_i = m_ij\n l_i_new = tl.exp(lse_i - m_ij) + l_ij\n lse_i = m_ij + tl.log(l_i_new)\n K_block_ptr = tl.advance(K_block_ptr, (BLOCK_N, 0))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n o_scale = tl.exp(m_i - lse_i)\n acc_o = acc_o * o_scale[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc_o)\n else:\n tl.store(out_ptrs, acc_o, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_attn_ad.py" }, { "uuid": "5dee5ab7-230c-4c73-b3fd-4aa6aef7426c", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [1, 2, 4, 8, 16]], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef bwd_prepare_wy_repr_kernel(k, v, beta, A, dw, du, dk, dv, dbeta,\n offsets, indices, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (BT, T), (1, BT), (0, \n i_t * BT), (BT, BT), (0, 1))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (BT, T), (1, H *\n BT), (0, i_t * BT), (BT, BT), (0, 1))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_dbeta = tl.zeros([BT], dtype=tl.float32)\n b_dA = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_du = tl.make_block_ptr(du + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_du = tl.make_block_ptr(du + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_v_beta = (b_v * b_beta[:, None]).to(b_v.dtype)\n b_du = tl.load(p_du, boundary_check=(0, 1))\n b_dA += tl.dot(b_du, tl.trans(b_v_beta), allow_tf32=False)\n b_dv_beta = tl.dot(b_A, b_du, allow_tf32=False)\n b_dv = b_dv_beta * b_beta[:, None]\n b_dbeta += tl.sum(b_dv_beta * b_v, 1)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_k_beta = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_dw = tl.load(p_dw, boundary_check=(0, 1))\n b_dA += tl.dot(b_dw, tl.trans(b_k_beta), allow_tf32=False)\n b_dk_beta = tl.dot(b_A, b_dw, allow_tf32=False)\n b_dk = b_dk_beta * b_beta[:, None]\n b_dbeta += tl.sum(b_dk_beta * b_k, 1)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n b_dA = tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :],\n b_dA, 0)\n b_dA = tl.dot(b_dA.to(b_A.dtype), b_A)\n b_dA = tl.dot(b_A, b_dA.to(b_A.dtype))\n b_dA = tl.where(tl.arange(0, BT)[:, None] > tl.arange(0, BT)[None, :], \n -b_dA, 0).to(k.dtype.element_ty)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dk = tl.load(p_dk, boundary_check=(0, 1))\n b_k_beta = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_dk_beta = tl.dot(b_dA, b_k, allow_tf32=False)\n b_dbeta += tl.sum(b_dk_beta * b_k, 1)\n b_dk += tl.dot(tl.trans(b_dA), b_k_beta, allow_tf32=False)\n b_dk += b_dk_beta * b_beta[:, None]\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n if HEAD_FIRST:\n p_dbeta = tl.make_block_ptr(dbeta + i_bh * T, (T,), (1,), (i_t * BT\n ,), (BT,), (0,))\n else:\n p_dbeta = tl.make_block_ptr(dbeta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n tl.store(p_dbeta, b_dbeta.to(p_dbeta.dtype.element_ty), boundary_check=(0,)\n )\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/wy_fast.py" }, { "uuid": "a64c01e5-8feb-4826-8caa-64280d7be379", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BK', 'NC', 'BT'])\n@triton.jit\ndef chunk_gla_bwd_kernel_intra(q, k, g, dA, dq, dk, offsets, indices, T: tl\n .constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BC: tl.\n constexpr, BK: tl.constexpr, NC: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_t, i_i = i_c // NC, i_c % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n if i_t * BT + i_i * BC >= T:\n return\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_dq = tl.zeros([BC, BK], dtype=tl.float32)\n if i_i > 0:\n if HEAD_FIRST:\n p_gn = tl.max_contiguous(tl.multiple_of(g + (i_bh * T + i_t *\n BT + i_i * BC) * K + o_k, BK), BK)\n else:\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + \n i_i * BC) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n for i_j in range(0, i_i):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1),\n (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, \n 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (\n H * K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (\n 1, 0))\n p_dA = tl.make_block_ptr(dA + (bos * H + i_h) * BT, (T, BT),\n (H * BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC),\n (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_kg = b_k * tl.exp(b_gn[None, :] - b_gk)\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dq += tl.dot(b_dA, b_kg)\n b_dq *= tl.exp(b_g - b_gn[None, :])\n o_i = tl.arange(0, BC)\n m_dA = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n if HEAD_FIRST:\n o_dA = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_i * BC\n p_kj = tl.max_contiguous(tl.multiple_of(k + (i_bh * T + i_t * BT + \n i_i * BC) * K + o_k, BK), BK)\n p_gkj = tl.max_contiguous(tl.multiple_of(g + (i_bh * T + i_t * BT +\n i_i * BC) * K + o_k, BK), BK)\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n o_dA = bos * H * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * H * BT + i_h * BT + i_i * BC\n p_kj = tl.max_contiguous(tl.multiple_of(k + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gkj = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_dA = tl.load(dA + o_dA + j, mask=m_dA, other=0)\n b_kj = tl.load(p_kj, mask=m_k, other=0).to(tl.float32)\n b_gkj = tl.load(p_gkj, mask=m_k, other=0).to(tl.float32)\n m_i = o_i[:, None] >= j\n b_dq += tl.where(m_i, b_dA[:, None] * b_kj[None, :] * tl.exp(b_g -\n b_gkj[None, :]), 0.0)\n p_kj += K if HEAD_FIRST else H * K\n p_gkj += K if HEAD_FIRST else H * K\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.debug_barrier()\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K, 1\n ), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_dk = tl.zeros([BC, BK], dtype=tl.float32)\n NC = min(NC, tl.cdiv(T - i_t * BT, BC))\n if i_i < NC - 1:\n if HEAD_FIRST:\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bh * T * K + (i_t *\n BT + i_i * BC + BC - 1) * K + o_k, BK), BK)\n else:\n p_gn = tl.max_contiguous(tl.multiple_of(g + bos * H * K + (i_t *\n BT + i_i * BC + BC - 1) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n for i_j in range(i_i + 1, NC):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (BT, T), (1,\n BT), (i_i * BC, i_t * BT + i_j * BC), (BC, BC), (0, 1))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + (bos * H + i_h) * BT, (BT, T),\n (1, H * BT), (i_i * BC, i_t * BT + i_j * BC), (BC, BC),\n (0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_qg = b_q * tl.exp(b_g - b_gn[None, :])\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dk += tl.dot(b_dA, b_qg)\n b_dk *= tl.exp(b_gn[None, :] - b_gk)\n if HEAD_FIRST:\n o_dA = i_bh * T * BT + (i_t * BT + i_i * BC\n ) * BT + i_i * BC + tl.arange(0, BC)\n p_qj = tl.max_contiguous(tl.multiple_of(q + (i_bh * T + i_t * BT + \n i_i * BC) * K + o_k, BK), BK)\n p_gqj = tl.max_contiguous(tl.multiple_of(g + (i_bh * T + i_t * BT +\n i_i * BC) * K + o_k, BK), BK)\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n o_dA = bos * H * BT + (i_t * BT + i_i * BC\n ) * H * BT + i_h * BT + i_i * BC + tl.arange(0, BC)\n p_qj = tl.max_contiguous(tl.multiple_of(q + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gqj = tl.max_contiguous(tl.multiple_of(g + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_dA = tl.load(dA + o_dA + j * (1 if HEAD_FIRST else H) * BT)\n b_qj = tl.load(p_qj, mask=m_k, other=0).to(tl.float32)\n b_gqj = tl.load(p_gqj, mask=m_k, other=0).to(tl.float32)\n m_i = o_i[:, None] <= j\n b_dk += tl.where(m_i, b_dA[:, None] * b_qj[None, :] * tl.exp(b_gqj[\n None, :] - b_gk), 0.0)\n p_qj += K if HEAD_FIRST else H * K\n p_gqj += K if HEAD_FIRST else H * K\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "be7559f4-befc-4c5a-86c2-f17eaa7ed922", "file_name": "block_offsets.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/block_offsets.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.jit\ndef block_offsets_2d(shape_x, shape_y, stride_x, stride_y, offset_x,\n offset_y, block_shape_x, block_shape_y, require_mask=False):\n offs_x = tl.arange(0, block_shape_x) + offset_x\n offs_y = tl.arange(0, block_shape_y) + offset_y\n ptrs = offs_x[:, None] * stride_x + offs_y[None, :] * stride_y\n if require_mask:\n mask = (offs_x[:, None] < shape_x) & (offs_y[None, :] < shape_y)\n return ptrs, mask\n else:\n return ptrs\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/block_offsets.py" }, { "uuid": "49a57e59-6b3a-4a5b-a54d-579bb92b5c93", "file_name": "triton_implicit_gemm_1x1_0x0_1x1.py", "repo_name": "l1351868270/implicit_gemm.triton", "file_path": "triton_implicit_gemm_1x1_0x0_1x1.py", "commit_hash": "64eb8548ccf4576883c928f6315be8b24680a455", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['GEMM_M', 'GEMM_N',\n 'GEMM_K'])\n@triton.jit\ndef conv2d_kernel_1x1_1x1_0x0_1x1(x_ptr, w_ptr, y_ptr, N, C, H, W, K, P, Q,\n R, S, U, V, pad_h, pad_w, dila_h, dila_w, GEMM_M, GEMM_N, GEMM_K,\n stride_am, stride_ak, stride_bk, stride_bn, stride_cm, stride_cn,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(GEMM_M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(GEMM_N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n gemm_i = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % GEMM_M\n gemm_j = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % GEMM_N\n n = gemm_i // (P * Q)\n npq_residual = gemm_i % (P * Q)\n p = npq_residual // Q\n q = npq_residual % Q\n k = gemm_j\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % GEMM_M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % GEMM_N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = x_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n b_ptrs = w_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] *\n stride_bn)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for idx_k in range(0, tl.cdiv(GEMM_K, BLOCK_SIZE_K)):\n gemm_k = idx_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n r = gemm_k // (S * C)\n rsc_residual = gemm_k % (S * C)\n s = rsc_residual // C\n c = rsc_residual % C\n h = p[:, None] * U + r[None, :] * dila_h - pad_h\n w = q[:, None] * V + s[None, :] * dila_w - pad_w\n mask_x = (h >= 0) & (h < H) & (w >= 0) & (w < W)\n mask_w = (r < R) & (s < S) & (c < C)\n offs_x = n[:, None] * H * W * C + h * W * C + w * C + c\n offs_w = k[None, :] * R * S * C + r[:, None] * S * C + s[:, None\n ] * C + c[:, None]\n x_ptrs = x_ptr + offs_x\n w_ptrs = w_ptr + offs_w\n a = tl.load(a_ptrs, mask=offs_k[None, :] < GEMM_K - idx_k *\n BLOCK_SIZE_K, other=0.0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < GEMM_K - idx_k *\n BLOCK_SIZE_K, other=0.0)\n accumulator = tl.dot(a, b, accumulator, out_dtype=tl.float32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n c = accumulator.to(tl.float16)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = y_ptr + stride_cm * offs_cm[:, None] + stride_cn * offs_cn[None, :\n ]\n c_mask = (offs_cm[:, None] < GEMM_M) & (offs_cn[None, :] < GEMM_N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/l1351868270/implicit_gemm.triton/blob/64eb8548ccf4576883c928f6315be8b24680a455/triton_implicit_gemm_1x1_0x0_1x1.py" }, { "uuid": "66ca0a7e-3044-4054-9572-e48a84e580fd", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(list(filter(keep, configsOrig)), key=['N_CTX'])\n@triton.jit\ndef _attn_fwd(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v, desc_o,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.constexpr, STAGE: tl.\n constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE: tl.constexpr,\n ENABLE_WS: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n pid = tl.program_id(0)\n off_hz = tl.program_id(1)\n _attn_fwd_compute(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid,\n Z, H, N_CTX, BLOCK_M, BLOCK_N, HEAD_DIM, STAGE, ENABLE_TMA,\n LOOP_SCHEDULE)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "d159d9b3-bf80-48b6-adf0-f8ae054b043a", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef mlstm_matmul_kernel_backward(dH, dB, Q, K, V, dQ, dK, dV, F, dF, I, dI,\n M, B, NH: tl.constexpr, S: tl.constexpr, D: tl.constexpr, SB: tl.constexpr\n ):\n bh_id = tl.program_id(0)\n sb_id = tl.program_id(1)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n batch_offset_dh = batch_id * NH * S * D + head_id * S * D\n batch_offset_f = batch_id * NH * S + head_id * S\n offset_dh = tl.arange(0, SB) + sb_id * SB\n offset_vk = tl.arange(0, SB) + sb_id * SB\n d_range = tl.arange(0, D)\n dh_range = batch_offset_dh + offset_dh[:, None] * D + d_range[None, :]\n dh_mask = (offset_dh[:, None] < S) & (d_range[None, :] < D)\n dh = tl.load(dH + dh_range, dh_mask)\n m = tl.load(M + batch_offset_f + offset_dh, offset_dh < S)\n b = tl.load(B + batch_offset_f + offset_dh, offset_dh < S)\n f = tl.load(F + batch_offset_f + offset_dh, offset_dh < S)\n db = tl.load(dB + batch_offset_f + offset_dh, offset_dh < S)\n q = tl.load(Q + dh_range, dh_mask)\n scale = tl.sqrt(tl.full((1,), D, dtype=tl.float32))\n n = tl.maximum(tl.abs(b), tl.exp(-m)) + 1e-06\n f = tl.cumsum(tl.log(tl.sigmoid(f)))\n f_low = f\n df_acc = tl.zeros((SB,), dtype=tl.float32)\n dq_acc = tl.zeros((SB, D), dtype=tl.float32)\n for j in range(sb_id, -1, -1):\n vk_range = batch_offset_dh + offset_vk[:, None] * D + d_range[None, :]\n vk_mask = (offset_vk[:, None] < S) & (d_range[None, :] < D)\n f_next = tl.load(F + batch_offset_f + offset_vk, offset_vk < S)\n i = tl.load(I + batch_offset_f + offset_vk, offset_vk < S)\n f_next = tl.log(tl.sigmoid(f_next))\n if j == sb_id:\n f_next = tl.cumsum(f_next)\n d = f[:, None] - f_next[None, :] + i[None, :]\n mask = offset_dh[:, None] >= offset_vk[None, :]\n d = tl.where(mask, d, -float('inf'))\n else:\n f += tl.sum(f_next)\n f_next = tl.cumsum(f_next)\n d = f[:, None] - f_next[None, :] + i[None, :]\n d = tl.exp(d - m[:, None])\n v = tl.load(V + vk_range, vk_mask)\n dc_tilde = matrix_mult(dh, tl.trans(v), SB) * (1 / n)[:, None] + db[\n :, None]\n k = tl.load(K + vk_range, vk_mask) / scale\n dq_acc += matrix_mult(dc_tilde * d, k, SB)\n c_tilde = matrix_mult(q, tl.trans(k), SB) * d\n df_acc += tl.sum(c_tilde * dc_tilde, 1)\n offset_vk -= SB\n tl.store(dQ + dh_range, dq_acc, dh_mask)\n offset_q = tl.arange(0, SB) + sb_id * SB\n f = tl.zeros((1,), dtype=tl.float32)\n v = tl.load(V + dh_range, dh_mask)\n k = tl.load(K + dh_range, dh_mask)\n i = tl.load(I + batch_offset_f + offset_dh, offset_dh < S)\n dk_acc = tl.zeros((SB, D), dtype=tl.float32)\n dv_acc = tl.zeros((SB, D), dtype=tl.float32)\n di_acc = tl.zeros((SB,), dtype=tl.float32)\n for j in range(sb_id, tl.cdiv(S, SB)):\n q_range = batch_offset_dh + offset_q[:, None] * D + d_range[None, :]\n q_mask = (offset_q[:, None] < S) & (d_range[None, :] < D)\n f_next = tl.load(F + batch_offset_f + offset_q, offset_q < S)\n f_next = tl.log(tl.sigmoid(f_next))\n f_next_sum = tl.sum(f_next)\n f_next = f + tl.cumsum(f_next)\n d = f_next[None, :] - f_low[:, None] + i[:, None]\n f += f_next_sum\n if j == sb_id:\n mask = offset_dh[:, None] <= offset_q[None, :]\n d = tl.where(mask, d, -float('inf'))\n dh = tl.load(dH + q_range, q_mask)\n m = tl.load(M + batch_offset_f + offset_q, offset_q < S)\n b = tl.load(B + batch_offset_f + offset_q, offset_q < S)\n db = tl.load(dB + batch_offset_f + offset_q, offset_q < S)\n d = tl.exp(d - m[None, :])\n n = tl.maximum(tl.abs(b), tl.exp(-m)) + 1e-06\n dc_tilde_T = matrix_mult(v, tl.trans(dh), SB) * (1 / n)[None, :] + db[\n None, :]\n q = tl.load(Q + q_range, q_mask) / scale\n dk_acc += matrix_mult(dc_tilde_T * d, q, SB)\n c_tilde_T = matrix_mult(k, tl.trans(q), SB) * d\n dv_acc += matrix_mult(c_tilde_T / n[None, :], dh, SB)\n di_acc += tl.sum(c_tilde_T * dc_tilde_T, 1)\n offset_q += SB\n tl.store(dK + dh_range, dk_acc, dh_mask)\n tl.store(dV + dh_range, dv_acc, dh_mask)\n tl.store(dI + batch_offset_f + offset_dh, di_acc, offset_dh < S)\n tl.store(dF + batch_offset_f + offset_dh + 1, di_acc - df_acc, \n offset_dh + 1 < S)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "aaf9342a-2fc0-47a4-a123-58f4a92788de", "file_name": "layernorm_gated.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/layernorm_gated.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'HAS_BIAS': lambda args: args['B'] is not None, 'HAS_Z':\n lambda args: args['Z'] is not None})\n@triton.jit\ndef layer_norm_fwd_kernel(X, Y, W, B, Z, Mean, Rstd, stride_x_row,\n stride_y_row, stride_z_row, M, N, eps, BLOCK_N: tl.constexpr, HAS_BIAS:\n tl.constexpr, HAS_Z: tl.constexpr, NORM_BEFORE_GATE: tl.constexpr,\n IS_RMS_NORM: tl.constexpr):\n row = tl.program_id(0)\n group = tl.program_id(1)\n X += row * stride_x_row + group * N\n Y += row * stride_y_row + group * N\n if HAS_Z:\n Z += row * stride_z_row + group * N\n if not IS_RMS_NORM:\n Mean += group * M\n Rstd += group * M\n W += group * N\n if HAS_BIAS:\n B += group * N\n cols = tl.arange(0, BLOCK_N)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n if HAS_Z and not NORM_BEFORE_GATE:\n z = tl.load(Z + cols, mask=cols < N).to(tl.float32)\n x *= z * tl.sigmoid(z)\n if not IS_RMS_NORM:\n mean = tl.sum(x, axis=0) / N\n tl.store(Mean + row, mean)\n xbar = tl.where(cols < N, x - mean, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n else:\n xbar = tl.where(cols < N, x, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n tl.store(Rstd + row, rstd)\n mask = cols < N\n w = tl.load(W + cols, mask=mask).to(tl.float32)\n if HAS_BIAS:\n b = tl.load(B + cols, mask=mask).to(tl.float32)\n x_hat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n y = x_hat * w + b if HAS_BIAS else x_hat * w\n if HAS_Z and NORM_BEFORE_GATE:\n z = tl.load(Z + cols, mask=mask).to(tl.float32)\n y *= z * tl.sigmoid(z)\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/layernorm_gated.py" }, { "uuid": "e45d6b24-d5c8-45cc-b1bf-50ded8c8c077", "file_name": "bgmv_expand.py", "repo_name": "IBM/vllm", "file_path": "vllm/lora/ops/bgmv_expand.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _bgmv_expand_kernel(input_ptr, lora_ptr, out_ptr, N, K, lora_indices,\n xm_stride, xk_stride, l0_stride, lora_k_stride, lora_n_stride,\n cm_stride, cn_stride, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,\n SPLIT_N: tl.constexpr, EVEN_K: tl.constexpr, ADD_INPUTS: tl.constexpr,\n CAST_TYPE: tl.constexpr):\n \"\"\"\n GroupGEMV, additionally, introducing SPLIT_N can improve large hidden_size's\n performance\n \"\"\"\n pid_sn = tl.program_id(axis=0)\n cur_batch = tl.program_id(axis=1)\n lora_index = tl.load(lora_indices + cur_batch)\n if lora_index == -1:\n return\n offset_k = tl.arange(0, BLOCK_K)\n offset_n = tl.arange(0, BLOCK_N)\n if EVEN_K:\n tiled_a = tl.load(input_ptr + cur_batch * xm_stride + offset_k *\n xk_stride)\n else:\n tiled_a = tl.load(input_ptr + cur_batch * xm_stride + offset_k *\n xk_stride, mask=offset_k < K, other=0)\n split_n_length = tl.cdiv(N, SPLIT_N)\n if CAST_TYPE:\n tiled_a = tiled_a.to(lora_ptr.dtype.element_ty)\n b_ptr = (lora_ptr + l0_stride * lora_index + pid_sn * split_n_length *\n lora_k_stride)\n c_ptr = out_ptr + cur_batch * cm_stride + pid_sn * split_n_length\n for n in range(0, split_n_length, BLOCK_N):\n current_n = n + offset_n\n current_n_c = tl.max_contiguous(current_n, BLOCK_N)\n b_ptr_mask = (current_n[:, None] < split_n_length) & (offset_k[None,\n :] < K)\n c_mask = current_n < split_n_length\n tiled_b = tl.load(b_ptr + current_n_c[:, None] * lora_k_stride + \n offset_k[None, :] * lora_n_stride, mask=b_ptr_mask, other=0.0)\n if ADD_INPUTS:\n tiled_out = tl.load(c_ptr + current_n * cn_stride, mask=c_mask,\n other=0.0)\n accumulator = tl.sum(tiled_a * tiled_b, 1) + tiled_out\n else:\n accumulator = tl.sum(tiled_a * tiled_b, 1)\n tl.store(c_ptr + current_n * cn_stride, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/lora/ops/bgmv_expand.py" }, { "uuid": "1f2dca18-a3cd-441e-8a5f-75bcbedf659d", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef scan_add_op(x1, x2):\n return x1 + x2\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "43a7b7ff-eadb-490b-9acd-84f7d2a3ee0f", "file_name": "test_fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "tests/test_fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef attention_fwd_kernel(q, k, v, h, o, s_qh, s_qt, s_qd, s_hh, s_ht, T,\n scale, BT: tl.constexpr, BD: tl.constexpr, NT: tl.constexpr, STORE: tl.\n constexpr, IFCOND: tl.constexpr):\n i_bh = tl.program_id(0)\n b_h = tl.zeros([BD, BD], dtype=tl.float32)\n for i in range(0, tl.cdiv(T, BT)):\n p_q = tl.make_block_ptr(q + i_bh * s_qh, (T, BD), (s_qt, s_qd), (i *\n BT, 0), (BT, BD), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_qh, (BD, T), (s_qd, s_qt), (0,\n i * BT), (BD, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_qh, (T, BD), (s_qt, s_qd), (i *\n BT, 0), (BT, BD), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * s_hh, (NT * BD, BD), (s_ht, s_qd\n ), (i * BD, 0), (BD, BD), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * s_qh, (T, BD), (s_qt, s_qd), (i *\n BT, 0), (BT, BD), (1, 0))\n if STORE:\n tl.store(p_h, b_h.to(p_h.dtype.element_ty))\n b_q = tl.load(p_q)\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k)\n b_v = tl.load(p_v)\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_o = tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n if IFCOND:\n if i == 0:\n b_h = tl.dot(b_k, b_v, allow_tf32=False)\n else:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False)\n b_h += tl.dot(b_k, b_v, allow_tf32=False)\n else:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False)\n b_h += tl.dot(b_k, b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/tests/test_fused_chunk.py" }, { "uuid": "242c3dab-c302-4bf0-96fc-8162444aedf6", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps) for BK in [32, 64] for BV in [64, 128] for num_warps in [2, \n 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_gla_bwd_kernel_dv(k, g, A, do, dh, dv, offsets, indices, T: tl.\n constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.\n constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (BT, T), (1, BT), (0, \n i_t * BT), (BT, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (BT, T), (1, H *\n BT), (0, i_t * BT), (BT, BT), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H * V, \n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H * V, \n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_A = tl.where(tl.arange(0, BT)[:, None] <= tl.arange(0, BT)[None, :],\n b_A, 0.0)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dv = tl.dot(b_A, b_do.to(b_A.dtype), allow_tf32=False)\n for i_k in range(tl.cdiv(K, BK)):\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_gk = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + i_bh * T * K + min(\n i_t * BT + BT, T) * K - K + o_k, BK), BK)\n p_dh = tl.make_block_ptr(dh + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_gk = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_gn = tl.max_contiguous(tl.multiple_of(g + (bos + min(i_t * BT +\n BT, T) - 1) * H * K + i_h * K + o_k, BK), BK)\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_gn = tl.exp(tl.load(p_gn, mask=m_k, other=0)[None, :] - b_gk)\n b_k = (b_k * b_gn).to(b_k.dtype)\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dv += tl.dot(b_k, b_dh.to(b_k.dtype))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "80930cb4-c6ca-4869-ac5f-29e8b9906e6b", "file_name": "paged_attn.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _inner_paged_attn_unroll_4_kernel(q, k_cache, v_cache, stride_km,\n block_base_ptrs, base_offs_kv, alibi_slope, block_offs, seq_len, qkv,\n qk_max, exp_sum, BLOCK_SIZE: tl.constexpr, LO: tl.constexpr, HI: tl.\n constexpr):\n for block_idx in range(LO, HI, 4):\n offs_kv_0 = tl.load(block_base_ptrs + block_idx + 0\n ) * stride_km + base_offs_kv\n offs_kv_1 = tl.load(block_base_ptrs + block_idx + 1\n ) * stride_km + base_offs_kv\n offs_kv_2 = tl.load(block_base_ptrs + block_idx + 2\n ) * stride_km + base_offs_kv\n offs_kv_3 = tl.load(block_base_ptrs + block_idx + 3\n ) * stride_km + base_offs_kv\n k_0 = tl.load(k_cache + offs_kv_0)\n k_1 = tl.load(k_cache + offs_kv_1)\n k_2 = tl.load(k_cache + offs_kv_2)\n k_3 = tl.load(k_cache + offs_kv_3)\n v_0 = tl.load(v_cache + offs_kv_0)\n v_1 = tl.load(v_cache + offs_kv_1)\n v_2 = tl.load(v_cache + offs_kv_2)\n v_3 = tl.load(v_cache + offs_kv_3)\n _qk_0 = tl.sum((q[None, :] * k_0).to(tl.float32), axis=1)\n _qk_1 = tl.sum((q[None, :] * k_1).to(tl.float32), axis=1)\n _qk_2 = tl.sum((q[None, :] * k_2).to(tl.float32), axis=1)\n _qk_3 = tl.sum((q[None, :] * k_3).to(tl.float32), axis=1)\n if alibi_slope is not None:\n _qk_0 += alibi_slope * ((block_idx + 0) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_1 += alibi_slope * ((block_idx + 1) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_2 += alibi_slope * ((block_idx + 2) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_3 += alibi_slope * ((block_idx + 3) * BLOCK_SIZE +\n block_offs - seq_len + 1)\n _qk_max = tl.maximum(tl.max(_qk_0, axis=0), qk_max)\n _qk_max = tl.maximum(tl.max(_qk_1, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_2, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_3, axis=0), _qk_max)\n exp_tmp = tl.exp(_qk_0 - _qk_max) + tl.exp(_qk_1 - _qk_max) + tl.exp(\n _qk_2 - _qk_max) + tl.exp(_qk_3 - _qk_max)\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(exp_tmp, axis=0)\n qkv_sum_tmp = tl.exp(_qk_0[:, None] - _qk_max).to(v_cache.dtype.\n element_ty) * v_0 + tl.exp(_qk_1[:, None] - _qk_max).to(v_cache\n .dtype.element_ty) * v_1 + tl.exp(_qk_2[:, None] - _qk_max).to(\n v_cache.dtype.element_ty) * v_2 + tl.exp(_qk_3[:, None] - _qk_max\n ).to(v_cache.dtype.element_ty) * v_3\n qkv = (qkv * (exp_sum * tl.exp(qk_max - _qk_max)) + qkv_sum_tmp\n ) / _exp_sum\n qk_max = _qk_max\n exp_sum = _exp_sum\n return qkv, qk_max, exp_sum\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn.py" }, { "uuid": "57901932-eb13-48bb-80fb-5ac1397e137c", "file_name": "swiglu.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/swiglu.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef swiglu_backward(grad_output_ptr, grad_e_ptr, grad_g_ptr, e_ptr, g_ptr,\n n_cols, sigmoid_ptr, f_ptr, grad_output_stride, grad_e_stride,\n grad_g_stride, e_stride, g_stride, sigmoid_stride, f_stride, BLOCK_SIZE:\n tl.constexpr):\n pid = tl.program_id(axis=0)\n col_offset = tl.arange(0, BLOCK_SIZE)\n mask = col_offset < n_cols\n grad_output_row = tl.load(grad_output_ptr + pid * grad_output_stride +\n col_offset, mask=mask)\n e_row = tl.load(e_ptr + pid * e_stride + col_offset, mask=mask)\n g_row = tl.load(g_ptr + pid * g_stride + col_offset, mask=mask)\n sigmoid_row = tl.load(sigmoid_ptr + pid * sigmoid_stride + col_offset,\n mask=mask)\n f_row = tl.load(f_ptr + pid * f_stride + col_offset, mask=mask)\n grad_g_row = grad_output_row * f_row\n grad_e_row = grad_output_row * g_row * sigmoid_row * (1.0 + e_row * (\n 1.0 - sigmoid_row))\n tl.store(grad_e_ptr + pid * grad_e_stride + col_offset, grad_e_row,\n mask=mask)\n tl.store(grad_g_ptr + pid * grad_g_stride + col_offset, grad_g_row,\n mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/swiglu.py" }, { "uuid": "ca5df2aa-d6b2-436b-ad6e-334a25e38f83", "file_name": "lightning_attn2_no_decay.py", "repo_name": "OpenNLPLab/lightning-attention", "file_path": "lightning_attn/ops/triton/lightning_attn2_no_decay.py", "commit_hash": "d7439519541e966084eeaaf3ffd63eecc216f414", "starcount": 0, "input": "@triton.jit\ndef _bwd_inter_kernel(Q, K, V, DO, DQ, DK, DV, b: tl.constexpr, h: tl.\n constexpr, n: tl.constexpr, d: tl.constexpr, e: tl.constexpr, BLOCK: tl\n .constexpr, NUM_BLOCK: tl.constexpr, CBLOCK: tl.constexpr, NUM_CBLOCK:\n tl.constexpr):\n off_bh = tl.program_id(0)\n off_bh % h\n qk_offset = off_bh * n * d\n v_offset = off_bh * n * e\n o_offset = off_bh * n * e\n DQ_block_ptr = DQ + qk_offset + tl.arange(0, CBLOCK)[:, None\n ] * d + tl.arange(0, d)[None, :]\n K_block_ptr = K + qk_offset + tl.arange(0, CBLOCK)[:, None\n ] * d + tl.arange(0, d)[None, :]\n V_trans_block_ptr = V + v_offset + tl.arange(0, CBLOCK)[None, :\n ] * e + tl.arange(0, e)[:, None]\n DO_block_ptr = DO + o_offset + tl.arange(0, CBLOCK)[:, None\n ] * e + tl.arange(0, e)[None, :]\n off_block1 = tl.arange(0, CBLOCK)\n off_block2 = tl.arange(0, CBLOCK)\n kv_trans = tl.zeros([e, d], dtype=tl.float32)\n for i in range(NUM_BLOCK):\n for j in range(NUM_CBLOCK):\n if i > 0:\n do = tl.load(DO_block_ptr, mask=off_block1[:, None] < n,\n other=0.0).to(tl.float32)\n dq_inter = tl.dot(do, kv_trans)\n dq = dq_inter + tl.load(DQ_block_ptr, mask=off_block1[:,\n None] < n, other=0.0)\n tl.store(DQ_block_ptr, dq.to(DQ_block_ptr.dtype.element_ty),\n mask=off_block1[:, None] < n)\n DQ_block_ptr += CBLOCK * d\n DO_block_ptr += CBLOCK * e\n off_block1 += CBLOCK\n kv_trans_current = tl.zeros([e, d], dtype=tl.float32)\n for j in range(NUM_CBLOCK):\n v_trans = tl.load(V_trans_block_ptr, mask=off_block2[None, :] <\n n, other=0.0).to(tl.float32)\n k = tl.load(K_block_ptr, mask=off_block2[:, None] < n, other=0.0\n ).to(tl.float32)\n kv_trans_current += tl.dot(v_trans, k)\n K_block_ptr += CBLOCK * d\n V_trans_block_ptr += CBLOCK * e\n off_block2 += CBLOCK\n kv_trans += kv_trans_current\n m = NUM_BLOCK * BLOCK\n off_block1 = m + tl.arange(0, CBLOCK)\n off_block2 = m + tl.arange(0, CBLOCK)\n Q_trans_block_ptr = Q + qk_offset + m * d + tl.arange(0, CBLOCK)[None, :\n ] * d + tl.arange(0, d)[:, None]\n K_block_ptr = K + qk_offset + m * d + tl.arange(0, CBLOCK)[:, None\n ] * d + tl.arange(0, d)[None, :]\n V_trans_block_ptr = V + v_offset + m * e + tl.arange(0, CBLOCK)[None, :\n ] * e + tl.arange(0, e)[:, None]\n DK_trans_block_ptr = DK + qk_offset + m * d + tl.arange(0, CBLOCK)[None, :\n ] * d + tl.arange(0, d)[:, None]\n DV_block_ptr = DV + v_offset + m * e + tl.arange(0, CBLOCK)[:, None\n ] * e + tl.arange(0, e)[None, :]\n DO_block_ptr = DO + o_offset + m * e + tl.arange(0, CBLOCK)[:, None\n ] * e + tl.arange(0, e)[None, :]\n dkv = tl.zeros([d, e], dtype=tl.float32)\n for i in range(NUM_BLOCK - 1, -1, -1):\n for j in range(NUM_CBLOCK - 1, -1, -1):\n K_block_ptr -= CBLOCK * d\n V_trans_block_ptr -= CBLOCK * e\n DK_trans_block_ptr -= CBLOCK * d\n DV_block_ptr -= CBLOCK * e\n off_block1 -= CBLOCK\n if i < NUM_BLOCK - 1:\n k = tl.load(K_block_ptr, mask=off_block1[:, None] < n,\n other=0.0).to(tl.float32)\n v_trans = tl.load(V_trans_block_ptr, mask=off_block1[None,\n :] < n, other=0.0).to(tl.float32)\n dk_inter_trans = tl.dot(dkv, v_trans)\n dv_inter = tl.dot(k, dkv)\n dk_trans = dk_inter_trans + tl.load(DK_trans_block_ptr,\n mask=off_block1[None, :] < n, other=0.0)\n dv = dv_inter + tl.load(DV_block_ptr, mask=off_block1[:,\n None] < n, other=0.0)\n tl.store(DK_trans_block_ptr, dk_trans.to(DK_trans_block_ptr\n .dtype.element_ty), mask=off_block1[None, :] < n)\n tl.store(DV_block_ptr, dv.to(DV_block_ptr.dtype.element_ty),\n mask=off_block1[:, None] < n)\n dkv_current = tl.zeros([d, e], dtype=tl.float32)\n for j in range(NUM_CBLOCK - 1, -1, -1):\n DO_block_ptr -= CBLOCK * e\n Q_trans_block_ptr -= CBLOCK * d\n off_block2 -= CBLOCK\n do = tl.load(DO_block_ptr, mask=off_block2[:, None] < n, other=0.0\n ).to(tl.float32)\n q_trans = tl.load(Q_trans_block_ptr, mask=off_block2[None, :] <\n n, other=0.0).to(tl.float32)\n dkv_current += tl.dot(q_trans, do)\n dkv += dkv_current\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/OpenNLPLab/lightning-attention/blob/d7439519541e966084eeaaf3ffd63eecc216f414/lightning_attn/ops/triton/lightning_attn2_no_decay.py" }, { "uuid": "c521d63c-9555-41f2-9185-de188587390f", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_linear_attn_bwd_kernel_dh(q, do, dh, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, s_h_h, s_h_t, scale, T: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NT:\n tl.constexpr):\n i_k, i_v, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n for i_t in range(NT - 1, -1, -1):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh, b_dh.to(p_dh.dtype.element_ty), boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dh += tl.dot(b_q, b_do.to(b_q.dtype), allow_tf32=False)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/chunk.py" }, { "uuid": "89f28703-00f8-4324-8d3c-5d383c132016", "file_name": "normalization.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/kernels/normalization.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_modulation_fwd(X, Y, W, B, Mean, Rstd, stride, seq_len, N,\n eps, BLOCK_SIZE: tl.constexpr):\n row = tl.program_id(0)\n batch_idx = row // seq_len\n Y += row * stride\n X += row * stride\n W += batch_idx * stride\n B += batch_idx * stride\n cols = tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n x = tl.load(X + cols, mask=mask, other=0.0)\n w = tl.load(W + cols, mask=mask, other=0.0)\n b = tl.load(B + cols, mask=mask, other=0.0)\n mean = tl.sum(x, axis=0) / N\n var = tl.sum(x * x, axis=0) / N - mean * mean\n rstd = tl.rsqrt(var + eps)\n tl.store(Mean + row, mean)\n tl.store(Rstd + row, rstd)\n y = (x - mean) * rstd * (1 + w) + b\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/kernels/normalization.py" }, { "uuid": "50f5f29f-f284-422f-95ef-6638cd047f96", "file_name": "avgpool.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/avgpool.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _AvgPoolCeilStats_cl3d_impl(X_ptr, Out_ptr, Mean_ptr, Sqmean_ptr,\n h_input, w_input, d_input, d_output, batch_stride_input, H_stride_input,\n W_stride_input, batch_stride_output, H_stride_output, W_stride_output,\n numel_no_channels_output, num_channels: tl.constexpr, almost_half_d: tl\n .constexpr):\n batch = tl.program_id(0)\n H = tl.program_id(1)\n W = tl.program_id(2)\n Out_ptr += (batch * batch_stride_output + H * H_stride_output + W *\n W_stride_output)\n output = tl.zeros([almost_half_d, num_channels], dtype=tl.float32)\n pair_offset = tl.arange(0, 2)\n channels_offset = tl.arange(0, num_channels)\n d_offset = tl.arange(0, almost_half_d)\n offset = d_offset[:, None, None] * (2 * num_channels) + channels_offset[\n None, :, None] + pair_offset[None, None, :] * num_channels\n output_offset = d_offset[:, None] * num_channels + channels_offset[None, :]\n mask_input = offset < d_input * num_channels\n output_mask = output_offset < d_output * num_channels\n norm_step = tl.sum(mask_input.to(tl.float32), axis=2).to(tl.float32)\n norm_step = tl.where(norm_step != 0, norm_step, 1.0)\n num_norm = 1\n Temp_ptr = (X_ptr + batch * batch_stride_input + 2 * H * H_stride_input +\n 2 * W * W_stride_input)\n x = tl.load(Temp_ptr + offset, mask=mask_input, other=0.0).to(tl.float32)\n x = tl.sum(x, axis=2)\n output += x\n W_skip = False\n if 2 * (W + 1) > w_input:\n W_skip = True\n else:\n Temp_ptr = (X_ptr + batch * batch_stride_input + 2 * H *\n H_stride_input + (2 * W + 1) * W_stride_input)\n x = tl.load(Temp_ptr + offset, mask=mask_input, other=0.0).to(tl.\n float32)\n x = tl.sum(x, axis=2)\n output += x\n num_norm += 1\n H_skip = False\n if 2 * (H + 1) > h_input:\n H_skip = True\n else:\n Temp_ptr = X_ptr + batch * batch_stride_input + (2 * H + 1\n ) * H_stride_input + 2 * W * W_stride_input\n x = tl.load(Temp_ptr + offset, mask=mask_input, other=0.0).to(tl.\n float32)\n x = tl.sum(x, axis=2)\n output += x\n num_norm += 1\n if not H_skip and not W_skip:\n Temp_ptr = X_ptr + batch * batch_stride_input + (2 * H + 1\n ) * H_stride_input + (2 * W + 1) * W_stride_input\n x = tl.load(Temp_ptr + offset, mask=mask_input, other=0.0).to(tl.\n float32)\n x = tl.sum(x, axis=2)\n output += x\n num_norm += 1\n output = output / (norm_step * num_norm)\n tl.store(Out_ptr + output_offset, output, mask=output_mask)\n output = tl.trans(output)\n mean = tl.sum(output, axis=1) / numel_no_channels_output\n sqmean = tl.sum(output * output, axis=1) / numel_no_channels_output\n tl.atomic_add(Mean_ptr + channels_offset, mean)\n tl.atomic_add(Sqmean_ptr + channels_offset, sqmean)\n", "category": { "Functionality": [ "Normalization", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/avgpool.py" }, { "uuid": "44cf831b-a88e-40b6-914b-3c52caca46e3", "file_name": "softmax.py", "repo_name": "shaRk-033/learn", "file_path": "learn_triton/softmax.py", "commit_hash": "3108e580bf00448a10fd41e3885fa952b46439ab", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel(inp_ptr, out_ptr, b, t, c, BLOCK_SIZE: tl.constexpr):\n bid = tl.program_id(0)\n tid = tl.program_id(1)\n if bid >= b or tid >= t:\n return\n cols = tl.arange(0, BLOCK_SIZE)\n offset = bid * t * c + tid * c + cols\n mask = cols < c\n x = tl.load(inp_ptr + offset, mask=mask, other=float('-inf'))\n maxx = tl.max(x, axis=0)\n x = x - maxx\n expx = tl.exp(x)\n sumx = tl.sum(expx, axis=0)\n outx = expx / sumx\n tl.store(out_ptr + offset, outx, mask=mask)\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "CC0" ], "github_url": "https://github.com/shaRk-033/learn/blob/3108e580bf00448a10fd41e3885fa952b46439ab/learn_triton/softmax.py" }, { "uuid": "f4086042-eb57-44c2-8406-648d389752ae", "file_name": "matmul.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/matmul.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef leaky_relu(x):\n return tl.where(x >= 0, x, 0.01 * x)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/matmul.py" }, { "uuid": "9d977a77-0a9d-44fe-8a4a-f1679ef7d33d", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_V(k, v, z, h, A, do, dh, dq, dk, dv, dA, s_k_h,\n s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, s_h_h, s_h_t, s_h_d, scale, T: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_p = tl.maximum(i_t * BT - 1, 0)\n n_bh = tl.num_programs(2)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_zc = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), ((i_t *\n BT + BT - 1) * K + i_k * BK,), (BK,), (0,))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (BT, T), (1, BT), (0, i_t *\n BT), (BT, BT), (0, 1))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_k = tl.exp(b_k - b_zc[None, :]).to(b_k.dtype)\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_dA = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * V * K, (V, K), (\n s_h_d, s_h_t), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, s_h_d), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * n_bh + i_bh) * s_v_h, (T, V),\n (s_v_t, s_v_d), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dv = tl.dot(b_k, b_dh, allow_tf32=False)\n if i_k == 0:\n b_dv += tl.dot(b_A, b_do, allow_tf32=False)\n b_do = (b_do * scale).to(b_do.dtype)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n b_dA += tl.dot(b_do, tl.trans(b_v), allow_tf32=False)\n b_dq += tl.dot(b_do, b_h, allow_tf32=False)\n b_dk += tl.dot(b_v, tl.trans(b_dh), allow_tf32=False)\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_zp = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), (i_p * K +\n i_k * BK,), (BK,), (0,))\n b_zp = tl.load(p_zp, boundary_check=(0,))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_z = tl.exp(b_zp[None, :] - b_z)\n b_dq = b_dq * b_z\n b_dk = b_dk * b_k\n p_dq = tl.make_block_ptr(dq + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_dA = tl.where(m_s, b_dA, 0.0).to(b_k.dtype)\n if i_k == 0:\n tl.store(p_dA, b_dA.to(p_dA.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "dd0ac36c-0d7f-4fec-8eaf-5ab99edcd368", "file_name": "quant_triton.py", "repo_name": "CompendiumLabs/ziggy", "file_path": "ziggy/backends/quant_triton.py", "commit_hash": "bd12fe50ca3475743f62ae26d4c184108e441e03", "starcount": 0, "input": "@triton.jit\ndef matmul_float_kernel(A, B, C, N, M, K, stride_an, stride_ak, stride_bk,\n stride_bm, stride_cn, stride_cm, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_K: tl.constexpr):\n dtype = C.dtype.element_ty\n pid_n = tl.program_id(0)\n pid_m = tl.program_id(1)\n rn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n rm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n rk = tl.arange(0, BLOCK_SIZE_K)\n mask_a = rn[:, None] < N\n mask_b = rm[None, :] < M\n mask_c = mask_a & mask_b\n A1 = A + (rn[:, None] * stride_an + rk[None, :] * stride_ak)\n B1 = B + (rk[:, None] * stride_bk + rm[None, :] * stride_bm)\n C1 = C + (rn[:, None] * stride_cn + rm[None, :] * stride_cm)\n acc = tl.zeros((BLOCK_SIZE_N, BLOCK_SIZE_M), dtype=dtype)\n for k in range(0, K, BLOCK_SIZE_K):\n a = tl.load(A1, mask=mask_a)\n b = tl.load(B1, mask=mask_b)\n acc += tl.dot(a, b, out_dtype=dtype)\n A1 += BLOCK_SIZE_K * stride_ak\n B1 += BLOCK_SIZE_K * stride_bk\n tl.store(C1, acc, mask=mask_c)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/CompendiumLabs/ziggy/blob/bd12fe50ca3475743f62ae26d4c184108e441e03/ziggy/backends/quant_triton.py" }, { "uuid": "f2af12dc-f012-439b-bcf8-16486d668412", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_intra_V(q, k, z, A, s_k_h, s_k_t, s_k_d, scale, T:\n tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BK:\n tl.constexpr, NC: tl.constexpr):\n i_k, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_t, i_i, i_j = i_c // (NC * NC), i_c % (NC * NC) // NC, i_c % (NC * NC\n ) % NC\n n_bh = tl.num_programs(2)\n if i_i > i_j:\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_A = tl.make_block_ptr(A + (i_k * n_bh + i_bh) * T * BT, (T, BT),\n (BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), ((\n i_t * BT + i_i * BC) * K + i_k * BK,), (BK,), (0,))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_q = (b_q * tl.exp(b_zn[None, :] - b_z) * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_k = tl.exp(b_k - b_zn[:, None]).to(b_k.dtype)\n b_A = tl.dot(b_q, b_k, allow_tf32=False)\n tl.store(p_A, b_A.to(A.dtype.element_ty), boundary_check=(0, 1))\n elif i_i == i_j:\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T * K,), (s_k_d,), ((i_t *\n BT + i_j * BC) * K + i_k * BK,), (BK,), (0,))\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n o_i = tl.arange(0, BC)\n o_A = (i_bh + i_k * n_bh) * T * BT + (i_t * BT + i_i * BC + tl.\n arange(0, BC)) * BT + i_j * BC\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n for j in range(0, BC):\n b_k = tl.load(p_k, boundary_check=(0,)).to(tl.float32)\n b_A = tl.sum(b_q * tl.exp(b_k[None, :] - b_z) * scale, 1)\n b_A = tl.where(o_i >= j, b_A, 0.0)\n tl.store(A + o_A + j, b_A.to(b_q.dtype), mask=m_A)\n p_k = tl.advance(p_k, (K,))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "e8622bcb-db14-44d9-adcb-257ca07eab7d", "file_name": "scaled_quant.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/fp8/scaled_quant.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef dynamic_scaled_cast(inpt_ptr: torch.Tensor, output_ptr: torch.Tensor,\n abs_max_ptr: torch.Tensor, spin_lock: torch.Tensor, numel: int, XBLOCK:\n tl.constexpr, float8_dtype: tl.constexpr, max_val: tl.constexpr):\n \"\"\"Quantize tensor to fp8 using current global absmax\"\"\"\n n_blocks = tl.num_programs(0)\n offset = tl.program_id(0) * XBLOCK\n index = offset + tl.arange(0, XBLOCK)[:]\n index = tl.max_contiguous(tl.multiple_of(index, XBLOCK), XBLOCK)\n mask = index < numel\n inpt = tl.load(inpt_ptr + index, mask=mask)\n block_max = tl.max(tl.abs(inpt))\n tl.atomic_max(abs_max_ptr, block_max)\n tl.atomic_add(spin_lock, 1, sem='release')\n while tl.load(spin_lock, volatile=True) < n_blocks:\n pass\n scale = max_val / tl.clamp(tl.load(abs_max_ptr), -1000000000000.0,\n float('inf'))\n scaled_inpt = inpt * scale\n scaled_inpt = tl.clamp(scaled_inpt, -1 * max_val, max_val)\n tl.store(output_ptr + index, scaled_inpt.to(float8_dtype), mask=mask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/fp8/scaled_quant.py" }, { "uuid": "45e590dd-7a3c-444a-bf55-6af49405bf85", "file_name": "k_fused_matmul_fw.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_fused_matmul_fw.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_ROW': 16, 'BLOCK_COL': 16},\n num_stages=5, num_warps=1), triton.Config({'BLOCK_ROW': 32, 'BLOCK_COL':\n 32}, num_stages=5, num_warps=1), triton.Config({'BLOCK_ROW': 64,\n 'BLOCK_COL': 32}, num_stages=5, num_warps=2), triton.Config({\n 'BLOCK_ROW': 32, 'BLOCK_COL': 64}, num_stages=5, num_warps=2), triton.\n Config({'BLOCK_ROW': 128, 'BLOCK_COL': 64}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_ROW': 64, 'BLOCK_COL': 128}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_ROW': 128, 'BLOCK_COL': 128},\n num_stages=4, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef kernel_fma(OUT, ACT_INPUTS, INPUT, WEIGHT, BIAS, M, N, K, stride_om,\n stride_im, stride_wn, stride_wk, **META):\n \"\"\"\n Kernel for computing Out = activation(A x W + C)\n\n - Input has shape (M, K)\n - Weight has shape (K, N)\n - Bias has shape (N,)\n - Output has shape (M, N)\n - ActInputs (optional) has shape (M, N)\n\n 'ActInputs' optionally saves the A x W + C intermediate for backward computations\n\n This kernel will consolidate over K\n \"\"\"\n BLOCK_M, GROUP_M = META['BLOCK_ROW'], META['GROUP_ROW']\n BLOCK_N, BLOCK_K = META['BLOCK_COL'], META['BLOCK_K']\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_M)\n num_pid_n = tl.cdiv(N, BLOCK_N)\n num_pid_in_group = GROUP_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_M\n GROUP_M = min(num_pid_m - first_pid_m, GROUP_M)\n pid_m = first_pid_m + pid % GROUP_M\n pid_n = pid % num_pid_in_group // GROUP_M\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n rk = tl.arange(0, BLOCK_K)\n input_ptrs = INPUT + rm[:, None] * stride_im + rk[None, :]\n weight_ptrs = WEIGHT + rk[:, None] * stride_wk + rn[None, :] * stride_wn\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n if META['BIAS']:\n bias = tl.load(BIAS + rn, mask=rn < N, other=0.0).to(tl.float32)\n acc += bias[None, :]\n for _ in range(K, 0, -BLOCK_K):\n a = tl.load(input_ptrs, mask=(rk[None, :] < K) & (rm[:, None] < M),\n other=0.0)\n w = tl.load(weight_ptrs, mask=(rk[:, None] < K) & (rn[None, :] < N),\n other=0.0)\n acc += tl.dot(a, w).to(tl.float32)\n input_ptrs += BLOCK_K\n weight_ptrs += BLOCK_K * stride_wk\n if META['SAVE_ACT_INPUTS']:\n act_in_ptrs = ACT_INPUTS + rm[:, None] * stride_om + rn[None, :]\n tl.store(act_in_ptrs, acc, mask=(rm[:, None] < M) & (rn[None, :] < N))\n if META['ACTIVATION']:\n acc = META['ACTIVATION'](acc)\n out_ptrs = OUT + rm[:, None] * stride_om + rn[None, :]\n tl.store(out_ptrs, acc, mask=(rm[:, None] < M) & (rn[None, :] < N))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_fused_matmul_fw.py" }, { "uuid": "f7ae9f93-489e-4fd5-b45e-db9d45f58144", "file_name": "quant_triton.py", "repo_name": "CompendiumLabs/ziggy", "file_path": "ziggy/backends/quant_triton.py", "commit_hash": "bd12fe50ca3475743f62ae26d4c184108e441e03", "starcount": 0, "input": "@triton.jit\ndef matmul_quant_kernel(A, B, C, N, M, K, K1, stride_an, stride_ak,\n stride_bk, stride_bm, stride_cn, stride_cm, scale, zero_point, BITS: tl\n .constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, BLOCK_SIZE_K1: tl.constexpr):\n dtype = C.dtype.element_ty\n zero_point_ty = tl.full((), zero_point, dtype=dtype)\n scale_ty = tl.full((), scale, dtype=dtype)\n QFACT = 8 // BITS\n QMASK = (1 << BITS) - 1\n QMASK_INT = tl.full((), QMASK, dtype=tl.uint8)\n pid_n = tl.program_id(0)\n pid_m = tl.program_id(1)\n rn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n rm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n rk = tl.arange(0, BLOCK_SIZE_K)\n rk1, rq1 = rk // QFACT, rk % QFACT\n a_shift = BITS * rq1\n mask_a = rn[:, None] < N\n mask_b = rm[None, :] < M\n mask_c = mask_a & mask_b\n A1 = A + (rn[:, None] * stride_an + rk1[None, :] * stride_ak)\n B1 = B + (rk[:, None] * stride_bk + rm[None, :] * stride_bm)\n C1 = C + (rn[:, None] * stride_cn + rm[None, :] * stride_cm)\n acc = tl.zeros((BLOCK_SIZE_N, BLOCK_SIZE_M), dtype=dtype)\n for k in range(0, K, BLOCK_SIZE_K):\n aq = tl.load(A1, mask=mask_a)\n b = tl.load(B1, mask=mask_b)\n ai = aq >> a_shift & QMASK_INT\n a = ai.to(dtype) - zero_point_ty\n b1 = b.to(dtype)\n acc += tl.dot(a, b1, out_dtype=dtype)\n A1 += BLOCK_SIZE_K1 * stride_ak\n B1 += BLOCK_SIZE_K * stride_bk\n acc *= scale_ty\n tl.store(C1, acc, mask=mask_c)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "fp32", "int8", "uint8" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/CompendiumLabs/ziggy/blob/bd12fe50ca3475743f62ae26d4c184108e441e03/ziggy/backends/quant_triton.py" }, { "uuid": "4f055ba2-8e8d-4b65-989b-b19e4874a19b", "file_name": "06-fused-attention.py", "repo_name": "triton-lang/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "a2b398e0bb1b120f31cf386d6ae3261c3ab84207", "starcount": 0, "input": "@triton.jit\ndef _attn_bwd_preprocess(O, DO, Delta, Z, H, N_CTX, BLOCK_M: tl.constexpr,\n HEAD_DIM: tl.constexpr):\n off_m = tl.program_id(0) * BLOCK_M + tl.arange(0, BLOCK_M)\n off_hz = tl.program_id(1)\n off_n = tl.arange(0, HEAD_DIM)\n o = tl.load(O + off_hz * HEAD_DIM * N_CTX + off_m[:, None] * HEAD_DIM +\n off_n[None, :])\n do = tl.load(DO + off_hz * HEAD_DIM * N_CTX + off_m[:, None] * HEAD_DIM +\n off_n[None, :]).to(tl.float32)\n delta = tl.sum(o * do, axis=1)\n tl.store(Delta + off_hz * N_CTX + off_m, delta)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/triton/blob/a2b398e0bb1b120f31cf386d6ae3261c3ab84207/python/tutorials/06-fused-attention.py" }, { "uuid": "b076a099-4288-404c-911a-b081727d520c", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BC', 'BK'])\n@triton.jit\ndef chunk_rwkv6_fwd_A_kernel_intra_sub_intra_split(q, k, gi, ge, u, A,\n offsets, indices, scale, B: tl.constexpr, T: tl.constexpr, H: tl.\n constexpr, K: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BK: tl.\n constexpr, NC: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.\n constexpr):\n i_k, i_tc, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_t, i_i = i_tc // NC, i_tc % NC\n i_j = i_i\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n if i_t * BT + i_i * BC >= T:\n return\n o_i = tl.arange(0, BC)\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n if HEAD_FIRST:\n o_A = (i_k * B * H + i_bh) * T * BC + (i_t * BT + i_i * BC + tl.\n arange(0, BC)) * BC\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(ge + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_qj = tl.max_contiguous(tl.multiple_of(q + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n p_kj = tl.max_contiguous(tl.multiple_of(k + (i_bh * T + i_t * BT + \n i_j * BC) * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(gi + (i_bh * T + i_t * BT +\n i_j * BC) * K + o_k, BK), BK)\n else:\n o_A = (i_k * all + bos + i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * H * BC + i_h * BC\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_g = tl.make_block_ptr(ge + (bos * H + i_h) * K, (T, K), (H * K, 1\n ), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_qj = tl.max_contiguous(tl.multiple_of(q + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_kj = tl.max_contiguous(tl.multiple_of(k + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gk = tl.max_contiguous(tl.multiple_of(gi + (bos + i_t * BT + i_j *\n BC) * H * K + i_h * K + o_k, BK), BK)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n p_u = tl.make_block_ptr(u + i_h * K, (K,), (1,), i_k * BK, (BK,), (0,))\n b_u = tl.load(p_u, boundary_check=(0,))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_qj = tl.load(p_qj, mask=m_k, other=0).to(tl.float32)\n b_kj = tl.load(p_kj, mask=m_k, other=0).to(tl.float32)\n b_gk = tl.load(p_gk, mask=m_k, other=0).to(tl.float32)\n b_A = tl.sum(b_q * b_kj[None, :] * tl.exp(b_g - b_gk[None, :]), 1)\n b_A = tl.where(o_i > j, b_A * scale, 0.0)\n b_A = tl.where(o_i != j, b_A, tl.sum(b_qj * b_kj * b_u * scale))\n tl.store(A + o_A + j, b_A, mask=m_A)\n p_qj += K if HEAD_FIRST else H * K\n p_kj += K if HEAD_FIRST else H * K\n p_gk += K if HEAD_FIRST else H * K\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Coalesced", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "a0025e28-0746-4d9e-bb24-18053ce379b0", "file_name": "z_order.py", "repo_name": "Kitsunetic/space-filling-pytorch", "file_path": "space_filling_pytorch/functional/z_order.py", "commit_hash": "0de955ad1036973ee7506c5a0124c208acec722d", "starcount": 0, "input": "@triton.jit\ndef _calculate_zorder(fx, fy, fz, space_size):\n x = ((fx + 1) / 2 * space_size).to(tl.int64)\n y = ((fy + 1) / 2 * space_size).to(tl.int64)\n z = ((fz + 1) / 2 * space_size).to(tl.int64)\n x = tl.minimum(tl.maximum(x, 0), space_size - 1)\n y = tl.minimum(tl.maximum(y, 0), space_size - 1)\n z = tl.minimum(tl.maximum(z, 0), space_size - 1)\n ret = 0\n for i in tl.static_range(0, 16):\n q = 1 << i\n ret |= (x & q) << 2 * i + 2\n ret |= (y & q) << 2 * i + 1\n ret |= (z & q) << 2 * i + 0\n return ret\n", "category": { "Functionality": [], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/space-filling-pytorch/blob/0de955ad1036973ee7506c5a0124c208acec722d/space_filling_pytorch/functional/z_order.py" }, { "uuid": "834e54f1-1ce6-424e-a37a-b8bc89efdeec", "file_name": "cross_entropy.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/cross_entropy.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_cross_entropy_forward(input_ptr, input_stride, target_ptr,\n target_stride, loss_output_ptr, loss_output_stride, num_classes,\n num_valid_targets, ignore_label, smoothing_factor: tl.constexpr,\n reduction_mode: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n row_id = tl.program_id(0).to(tl.int64)\n target_ptr += row_id * target_stride\n target_label = tl.load(target_ptr)\n input_ptr += row_id * input_stride\n if target_label == ignore_label:\n for i in range(0, num_classes, BLOCK_SIZE):\n input_offsets = i + tl.arange(0, BLOCK_SIZE)\n tl.store(input_ptr + input_offsets, 0.0, mask=input_offsets <\n num_classes)\n return\n loss_output_ptr += row_id * loss_output_stride\n max_val = float('-inf')\n normalization_factor = 0.0\n target_input_val = tl.load(input_ptr + target_label)\n smoothing_sum = 0.0\n epsilon = smoothing_factor / num_classes\n for i in range(0, num_classes, BLOCK_SIZE):\n input_offsets = i + tl.arange(0, BLOCK_SIZE)\n input_block = tl.load(input_ptr + input_offsets, mask=input_offsets <\n num_classes, other=float('-inf'))\n block_max = tl.max(input_block)\n if smoothing_factor > 0:\n smoothing_sum += tl.sum(tl.where(input_offsets < num_classes, -\n epsilon * input_block, 0.0))\n new_max = tl.maximum(max_val, block_max)\n normalization_factor = normalization_factor * tl.exp(max_val - new_max\n ) + tl.sum(tl.exp(input_block - new_max))\n max_val = new_max\n for i in range(0, num_classes, BLOCK_SIZE):\n input_offsets = i + tl.arange(0, BLOCK_SIZE)\n input_block = tl.load(input_ptr + input_offsets, mask=input_offsets <\n num_classes, other=float('-inf'))\n if reduction_mode == 'mean':\n input_block = (tl.exp(input_block - max_val) /\n normalization_factor - epsilon) / num_valid_targets\n else:\n input_block = tl.exp(input_block - max_val\n ) / normalization_factor - epsilon\n tl.store(input_ptr + input_offsets, input_block, mask=input_offsets <\n num_classes)\n tl.debug_barrier()\n row_loss = -(target_input_val - max_val - tl.log(normalization_factor))\n if smoothing_factor > 0:\n smooth_loss = smoothing_sum + smoothing_factor * (max_val + tl.log(\n normalization_factor))\n row_loss = row_loss * (1 - smoothing_factor) + smooth_loss\n if reduction_mode == 'mean':\n row_loss /= num_valid_targets\n updated_target_val = tl.load(input_ptr + target_label)\n if reduction_mode == 'mean':\n updated_target_val += -(1 - smoothing_factor) / num_valid_targets\n else:\n updated_target_val += -(1 - smoothing_factor)\n tl.store(loss_output_ptr, row_loss)\n tl.store(input_ptr + target_label, updated_target_val)\n", "category": { "Functionality": [ "Backpropagation", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/cross_entropy.py" }, { "uuid": "514b2699-68b0-4166-9e48-359401f2a1ee", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_linear_attn_bwd_kernel_dqkv(q, k, v, h, do, dh, dq, dk, dv, s_k_h,\n s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, s_h_h, s_h_t, scale, T: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr,\n BV: tl.constexpr, NT: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n o_i = tl.arange(0, BT)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_s = tl.dot(b_k, b_q, allow_tf32=False) * scale\n b_s = tl.where(o_i[:, None] <= o_i[None, :], b_s, 0)\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_ds = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h, (V, NT * K), (1, s_h_t),\n (i_v * BV, i_t * K + i_k * BK), (BV, BK), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + i_bh * s_h_h, (NT * K, V), (s_h_t, 1),\n (i_t * K + i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * n_bh + i_bh) * s_v_h, (T, V),\n (s_v_t, s_v_d), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_ds += tl.dot(b_do, tl.trans(b_v), allow_tf32=False)\n b_dq += tl.dot(b_do, b_h, allow_tf32=False) * scale\n b_dk += tl.dot(b_v, tl.trans(b_dh), allow_tf32=False)\n b_dv = tl.dot(b_k, b_dh, allow_tf32=False) + tl.dot(b_s.to(b_q.\n dtype), b_do, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n b_ds = tl.where(o_i[:, None] >= o_i[None, :], b_ds * scale, 0).to(b_q.dtype\n )\n b_dq += tl.dot(b_ds, b_k, allow_tf32=False)\n b_dk += tl.trans(tl.dot(b_q, b_ds, allow_tf32=False))\n p_dq = tl.make_block_ptr(dq + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/chunk.py" }, { "uuid": "f35c6d9e-1bb6-42a6-b3bf-22b95cb2e626", "file_name": "mhmoe_bwd.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe_bwd.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef _mlp_wide_kernel_bwd_dw1w2(pid_h, pid_e, x_ptr, w1_ptr, w2_ptr, o_ptr,\n dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D: tl.constexpr, E, stride_xb,\n stride_xd, stride_w1d, stride_w1e, stride_w2e, stride_w2d, stride_ob,\n stride_od, stride_dxb, stride_dxd, stride_dw1d, stride_dw1e,\n stride_dw2e, stride_dw2d, stride_dob, stride_dod, BLOCK_SIZE_B: tl.\n constexpr, BLOCK_SIZE_E: tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp_bwd_dw1w2\n Z = X @ W1, H = f(Z), O = H @ W2\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n - dX has shape (B, D)\n - dW1 has shape (D, E)\n - dW2 has shape (E, D)\n - dO has shape (B, D)\n \"\"\"\n TARGET_TYPE = x_ptr.type.element_ty\n offs_b = tl.arange(0, BLOCK_SIZE_B)\n offs_d = tl.arange(0, D)\n offs_e = tl.arange(0, BLOCK_SIZE_E)\n x_ptrs = x_ptr + ((pid_h * B + offs_b[:, None]) * stride_xb + offs_d[\n None, :] * stride_xd)\n do_ptrs = do_ptr + ((pid_h * B + offs_b[:, None]) * stride_dob + offs_d\n [None, :] * stride_dod)\n do_mask = (offs_b[:, None] < B) & (offs_d[None, :] < D)\n w1_ptrs = w1_ptr + ((pid_h * D + offs_d[:, None]) * stride_w1d + (pid_e *\n BLOCK_SIZE_E + offs_e[None, :]) * stride_w1e)\n w1_mask = (offs_d[:, None] < D) & (offs_e[None, :] < E - pid_e *\n BLOCK_SIZE_E)\n w2_ptrs = w2_ptr + ((pid_h * E + pid_e * BLOCK_SIZE_E + offs_e[:, None]\n ) * stride_w2e + offs_d[None, :] * stride_w2d)\n w2_mask = (offs_e[:, None] < E - pid_e * BLOCK_SIZE_E) & (offs_d[None,\n :] < D)\n w1 = tl.load(w1_ptrs, mask=w1_mask, other=0.0)\n w2 = tl.load(w2_ptrs, mask=w2_mask, other=0.0)\n do = tl.load(do_ptrs, mask=do_mask, other=0.0)\n dw1 = tl.zeros((D, BLOCK_SIZE_E), dtype=tl.float32)\n dw2 = tl.zeros((BLOCK_SIZE_E, D), dtype=tl.float32)\n for b in range(0, tl.cdiv(B, BLOCK_SIZE_B)):\n x_mask = (offs_b[:, None] < B - b * BLOCK_SIZE_B) & (offs_d[None, :\n ] < D)\n do_mask = (offs_b[:, None] < B - b * BLOCK_SIZE_B) & (offs_d[None,\n :] < D)\n x = tl.load(x_ptrs, mask=x_mask, other=0.0)\n do = tl.load(do_ptrs, mask=do_mask, other=0.0)\n z = tl.dot(x, w1, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n h = leaky_relu(z).to(TARGET_TYPE)\n else:\n h = z.to(TARGET_TYPE)\n dh = tl.dot(do, tl.trans(w2), out_dtype=tl.float32)\n dw2 += tl.dot(tl.trans(h), do, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n dz = (dh * d_leacky_relu_inv_backward(z)).to(TARGET_TYPE)\n else:\n dz = dh.to(TARGET_TYPE)\n dw1 += tl.dot(tl.trans(x), dz, out_dtype=tl.float32)\n x_ptrs += BLOCK_SIZE_B * stride_xb\n do_ptrs += BLOCK_SIZE_B * stride_dob\n return dw1, dw2\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe_bwd.py" }, { "uuid": "d8147557-5e28-4b54-9d2b-db80fd84ae11", "file_name": "utils.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/utils.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _soft_threshold(a0, a1, a2, a3):\n x1, x2, x3, x4, x5, x6 = tl.abs(a0) > tl.abs(a1), tl.abs(a0) > tl.abs(a2\n ), tl.abs(a0) > tl.abs(a3), tl.abs(a1) > tl.abs(a2), tl.abs(a1\n ) > tl.abs(a3), tl.abs(a2) > tl.abs(a3)\n m0, m1, m2, m3 = (x2 & x3 | x1 & x2 | x1 & x3, ~x1 & x5 | x4 & x5 | ~x1 &\n x4, ~x2 & ~x4 | ~x2 & x6 | ~x4 & x6, ~x3 & ~x5 | ~x3 & ~x6 | ~x5 & ~x6)\n threshold = tl.minimum(tl.maximum(tl.minimum(tl.abs(a0), tl.abs(a1)),\n tl.minimum(tl.abs(a2), tl.abs(a3))), tl.minimum(tl.maximum(tl.abs(\n a0), tl.abs(a1)), tl.maximum(tl.abs(a2), tl.abs(a3))))\n s0 = tl.where(a0 > 0, a0 - threshold, a0 + threshold)\n s1 = tl.where(a1 > 0, a1 - threshold, a1 + threshold)\n s2 = tl.where(a2 > 0, a2 - threshold, a2 + threshold)\n s3 = tl.where(a3 > 0, a3 - threshold, a3 + threshold)\n return s0, s1, s2, s3, m0, m1, m2, m3\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/utils.py" }, { "uuid": "3e563cf1-4a15-483f-8db0-7b40621112a6", "file_name": "RzLinearForward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearForward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 128, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64,\n 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': 32}, num_stages=5, num_warps=2),\n triton.Config({'BLOCK_SIZE_M': 16, 'BLOCK_SIZE_N': 32, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 16,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 16, 'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 16, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 16, 'BLOCK_SIZE_K': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_M': 32,\n 'BLOCK_SIZE_N': 16, 'BLOCK_SIZE_K': 32}, num_stages=3, num_warps=4)],\n key=['M', 'N', 'K'])\n@triton.jit\ndef rz_linear_forward_kernel_fp32(a_ptr, b_ptr, c_ptr, init_factor, M, N, K,\n H, stride_am, stride_ak, stride_cm, stride_cn, R7: int, R6: int, R5:\n int, R4: int, R3: int, R2: int, R1: int, R0: int, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE: tl.constexpr):\n rz_linear_forward_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=c_ptr,\n init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=stride_am,\n stride_ak=stride_ak, stride_cm=stride_cm, stride_cn=stride_cn,\n allow_tf32=False, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1,\n R0=R0, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=BLOCK_SIZE_N,\n BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearForward.py" }, { "uuid": "5e4fffd9-e14a-4bf7-a094-9d0f4377b78b", "file_name": "y_4.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_4.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef fourth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n CONST000 = 2.0\n CONST001 = 4.5\n CONST002 = 2.25\n CONST006 = 9.48683298050514\n CONST008 = 12.0\n CONST012 = 28.4604989415154\n CONST014 = 40.2492235949962\n CONST015 = -37.6497011940334\n CONST016 = -6.70820393249937\n CONST017 = -26.6223590239483\n CONST018 = -21.3453742061366\n CONST019 = -20.1246117974981\n CONST020 = -18.8248505970167\n CONST021 = -18.0\n CONST022 = -14.2302494707577\n CONST023 = -10.0623058987491\n CONST024 = -9.0\n CONST025 = -8.87411967464942\n CONST026 = -7.11512473537885\n CONST027 = -6.27495019900557\n CONST028 = -3.35410196624968\n VAR07 = x * x * x\n VAR08 = x * x\n VAR16 = y * y * y\n VAR17 = y * y\n VAR25 = z * z * z\n VAR26 = z * z\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += CONST015 * g_7 * x * y * z + CONST022 * g_5 * x * y * z + g_0 * (\n CONST017 * VAR08 * z - CONST025 * VAR25) + g_1 * y * (CONST020 *\n VAR08 - CONST020 * VAR26) + g_2 * (-CONST019 * VAR17 * z + CONST023 *\n VAR08 * z + CONST028 * VAR25) + g_3 * (CONST006 * VAR16 + CONST018 *\n VAR08 * y + CONST026 * VAR26 * y) + g_4 * (CONST000 * x * (CONST002 *\n VAR26 + CONST024 * VAR17) + CONST001 * VAR07) + g_6 * (-CONST016 *\n VAR07 + CONST019 * VAR17 * x) + g_8 * (CONST017 * VAR26 * x - \n CONST025 * VAR07)\n g_y += CONST000 * g_6 * y * (CONST023 * VAR08 - CONST023 * VAR26\n ) + CONST014 * g_2 * x * y * z + g_1 * (-CONST020 * VAR26 * x + \n CONST027 * VAR07) + g_3 * (CONST026 * VAR07 + x * (CONST012 * VAR17 +\n CONST026 * VAR26)) + g_4 * (CONST008 * VAR16 + CONST021 * VAR08 * y +\n CONST021 * VAR26 * y) + g_5 * (CONST026 * VAR25 + z * (CONST012 *\n VAR17 + CONST026 * VAR08)) + g_7 * (CONST020 * VAR08 * z - CONST027 *\n VAR25)\n g_z += -CONST015 * g_1 * x * y * z + CONST022 * g_3 * x * y * z + g_0 * (\n -CONST017 * VAR26 * x + CONST025 * VAR07) + g_2 * (CONST028 * VAR07 +\n x * (-CONST019 * VAR17 + CONST023 * VAR26)) + g_4 * (CONST001 *\n VAR08 * z + CONST001 * VAR25 + CONST021 * VAR17 * z) + g_5 * (\n CONST006 * VAR16 + CONST018 * VAR26 * y + CONST026 * VAR08 * y\n ) + g_6 * (CONST016 * VAR25 - CONST019 * VAR17 * z) + g_7 * y * (\n CONST020 * VAR08 - CONST020 * VAR26) + g_8 * (CONST017 * VAR08 * z -\n CONST025 * VAR25)\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_4.py" }, { "uuid": "13dbadc6-77e5-4822-8ad4-db75cbf0f44b", "file_name": "flash_triton.py", "repo_name": "MayDomine/Burst-Attention", "file_path": "burst_attn/flash_triton.py", "commit_hash": "b088c554072935074ea9c643de5ee363be5ab1f6", "starcount": 0, "input": "@triton.jit\ndef _bwd_kernel_one_col_block(start_n, Q, K, V, Bias, DO, DQ, DK, DV, LSE,\n D, softmax_scale, stride_qm, stride_kn, stride_vn, stride_bm,\n stride_dom, stride_dqm, stride_dkn, stride_dvn, seqlen_q, seqlen_k,\n headdim, ATOMIC_ADD: tl.constexpr, BIAS_TYPE: tl.constexpr, IS_CAUSAL:\n tl.constexpr, BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N:\n tl.constexpr, EVEN_HEADDIM: tl.constexpr, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr):\n begin_m = 0 if not IS_CAUSAL else start_n * BLOCK_N // BLOCK_M * BLOCK_M\n offs_qm = begin_m + tl.arange(0, BLOCK_M)\n offs_n = start_n * BLOCK_N + tl.arange(0, BLOCK_N)\n offs_m = tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n q_ptrs = Q + (offs_qm[:, None] * stride_qm + offs_d[None, :])\n k_ptrs = K + (offs_n[:, None] * stride_kn + offs_d[None, :])\n v_ptrs = V + (offs_n[:, None] * stride_vn + offs_d[None, :])\n do_ptrs = DO + (offs_qm[:, None] * stride_dom + offs_d[None, :])\n dq_ptrs = DQ + (offs_qm[:, None] * stride_dqm + offs_d[None, :])\n if BIAS_TYPE == 'vector':\n b_ptrs = Bias + offs_n\n elif BIAS_TYPE == 'matrix':\n b_ptrs = Bias + (offs_qm[:, None] * stride_bm + offs_n[None, :])\n dv = tl.zeros([BLOCK_N, BLOCK_HEADDIM], dtype=tl.float32)\n dk = tl.zeros([BLOCK_N, BLOCK_HEADDIM], dtype=tl.float32)\n if begin_m >= seqlen_q:\n dv_ptrs = DV + (offs_n[:, None] * stride_dvn + offs_d[None, :])\n dk_ptrs = DK + (offs_n[:, None] * stride_dkn + offs_d[None, :])\n _bwd_store_dk_dv(dk_ptrs, dv_ptrs, dk, dv, offs_n, offs_d, seqlen_k,\n headdim, EVEN_M=EVEN_M, EVEN_N=EVEN_N, EVEN_HEADDIM=EVEN_HEADDIM)\n return\n if EVEN_N & EVEN_M:\n if EVEN_HEADDIM:\n k = tl.load(k_ptrs)\n v = tl.load(v_ptrs)\n else:\n k = tl.load(k_ptrs, mask=offs_d[None, :] < headdim, other=0.0)\n v = tl.load(v_ptrs, mask=offs_d[None, :] < headdim, other=0.0)\n elif EVEN_HEADDIM:\n k = tl.load(k_ptrs, mask=offs_n[:, None] < seqlen_k, other=0.0)\n v = tl.load(v_ptrs, mask=offs_n[:, None] < seqlen_k, other=0.0)\n else:\n k = tl.load(k_ptrs, mask=(offs_n[:, None] < seqlen_k) & (offs_d[\n None, :] < headdim), other=0.0)\n v = tl.load(v_ptrs, mask=(offs_n[:, None] < seqlen_k) & (offs_d[\n None, :] < headdim), other=0.0)\n num_block_m = tl.cdiv(seqlen_q, BLOCK_M)\n for start_m in range(begin_m, num_block_m * BLOCK_M, BLOCK_M):\n start_m = tl.multiple_of(start_m, BLOCK_M)\n offs_m_curr = start_m + offs_m\n if EVEN_M & EVEN_HEADDIM:\n q = tl.load(q_ptrs)\n elif EVEN_HEADDIM:\n q = tl.load(q_ptrs, mask=offs_m_curr[:, None] < seqlen_q, other=0.0\n )\n else:\n q = tl.load(q_ptrs, mask=(offs_m_curr[:, None] < seqlen_q) & (\n offs_d[None, :] < headdim), other=0.0)\n qk = tl.dot(q, k, trans_b=True)\n if not EVEN_N:\n qk = tl.where(offs_n[None, :] < seqlen_k, qk, float('-inf'))\n if IS_CAUSAL:\n qk = tl.where(offs_m_curr[:, None] >= offs_n[None, :], qk,\n float('-inf'))\n if BIAS_TYPE != 'none':\n tl.debug_barrier()\n if BIAS_TYPE == 'vector':\n if EVEN_N:\n bias = tl.load(b_ptrs).to(tl.float32)\n else:\n bias = tl.load(b_ptrs, mask=offs_n < seqlen_k, other=0.0\n ).to(tl.float32)\n bias = bias[None, :]\n elif BIAS_TYPE == 'matrix':\n if EVEN_M & EVEN_N:\n bias = tl.load(b_ptrs).to(tl.float32)\n else:\n bias = tl.load(b_ptrs, mask=(offs_m_curr[:, None] <\n seqlen_q) & (offs_n[None, :] < seqlen_k), other=0.0\n ).to(tl.float32)\n qk = qk * softmax_scale + bias\n if not EVEN_M & EVEN_HEADDIM:\n tl.debug_barrier()\n lse_i = tl.load(LSE + offs_m_curr)\n if BIAS_TYPE == 'none':\n p = tl.exp(qk * softmax_scale - lse_i[:, None])\n else:\n p = tl.exp(qk - lse_i[:, None])\n if EVEN_M & EVEN_HEADDIM:\n do = tl.load(do_ptrs)\n else:\n do = tl.load(do_ptrs, mask=(offs_m_curr[:, None] < seqlen_q) &\n (offs_d[None, :] < headdim), other=0.0)\n dv += tl.dot(p.to(do.dtype), do, trans_a=True)\n if not EVEN_M & EVEN_HEADDIM:\n tl.debug_barrier()\n dp = tl.dot(do, v, trans_b=True)\n if not EVEN_HEADDIM:\n tl.debug_barrier()\n Di = tl.load(D + offs_m_curr)\n ds = (p * (dp - Di[:, None]) * softmax_scale).to(q.dtype)\n dk += tl.dot(ds, q, trans_a=True)\n if not EVEN_M & EVEN_HEADDIM:\n tl.debug_barrier()\n if not ATOMIC_ADD:\n if EVEN_M & EVEN_HEADDIM:\n dq = tl.load(dq_ptrs, eviction_policy='evict_last')\n dq += tl.dot(ds, k)\n tl.store(dq_ptrs, dq, eviction_policy='evict_last')\n elif EVEN_HEADDIM:\n dq = tl.load(dq_ptrs, mask=offs_m_curr[:, None] < seqlen_q,\n other=0.0, eviction_policy='evict_last')\n dq += tl.dot(ds, k)\n tl.store(dq_ptrs, dq, mask=offs_m_curr[:, None] < seqlen_q,\n eviction_policy='evict_last')\n else:\n dq = tl.load(dq_ptrs, mask=(offs_m_curr[:, None] < seqlen_q\n ) & (offs_d[None, :] < headdim), other=0.0,\n eviction_policy='evict_last')\n dq += tl.dot(ds, k)\n tl.store(dq_ptrs, dq, mask=(offs_m_curr[:, None] < seqlen_q\n ) & (offs_d[None, :] < headdim), eviction_policy=\n 'evict_last')\n else:\n dq = tl.dot(ds, k)\n if EVEN_M & EVEN_HEADDIM:\n tl.atomic_add(dq_ptrs, dq)\n elif EVEN_HEADDIM:\n tl.atomic_add(dq_ptrs, dq, mask=offs_m_curr[:, None] < seqlen_q\n )\n else:\n tl.atomic_add(dq_ptrs, dq, mask=(offs_m_curr[:, None] <\n seqlen_q) & (offs_d[None, :] < headdim))\n dq_ptrs += BLOCK_M * stride_dqm\n q_ptrs += BLOCK_M * stride_qm\n do_ptrs += BLOCK_M * stride_dom\n if BIAS_TYPE == 'matrix':\n b_ptrs += BLOCK_M * stride_bm\n dv_ptrs = DV + (offs_n[:, None] * stride_dvn + offs_d[None, :])\n dk_ptrs = DK + (offs_n[:, None] * stride_dkn + offs_d[None, :])\n _bwd_store_dk_dv(dk_ptrs, dv_ptrs, dk, dv, offs_n, offs_d, seqlen_k,\n headdim, EVEN_M=EVEN_M, EVEN_N=EVEN_N, EVEN_HEADDIM=EVEN_HEADDIM)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms", "Matrix Multiplication", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MayDomine/Burst-Attention/blob/b088c554072935074ea9c643de5ee363be5ab1f6/burst_attn/flash_triton.py" }, { "uuid": "5b0222d0-40c9-44d6-9305-fa0136e4416c", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rebased/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef _parallel_rebased_bwd_dkv(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dk,\n dv, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, scale, B: tl.constexpr, H:\n tl.constexpr, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BTL:\n tl.constexpr, BTS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTL, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_c *\n BTL, i_v * BV), (BTL, BV), (1, 0))\n b_k, b_v = tl.load(p_k, boundary_check=(0, 1)), tl.load(p_v,\n boundary_check=(0, 1))\n b_dk, b_dv = tl.zeros([BTL, BK], dtype=tl.float32), tl.zeros([BTL, BV],\n dtype=tl.float32)\n for i in range(tl.cdiv(T, BTS) * BTS - BTS, (i_c + 1) * BTL - BTS, -BTS):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i), (BK, BTS), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (V, T), (s_v_d, s_v_t),\n (i_v * BV, i), (BV, BTS), (0, 1))\n p_dz = dz + i_bh * T + i + tl.arange(0, BTS)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_dz = tl.load(p_dz, mask=i + tl.arange(0, BTS) < T)\n b_s = tl.dot(b_k.to(b_q.dtype), b_q, allow_tf32=False) * scale\n b_s2 = b_s * b_s\n b_dv += tl.dot(b_s2.to(b_q.dtype), tl.trans(b_do), allow_tf32=False)\n b_ds = tl.dot(b_v, b_do, allow_tf32=False) * scale\n if i_v == 0:\n b_ds += b_dz[None, :] * scale\n else:\n b_ds = b_ds\n b_dk += tl.dot((2 * b_ds * b_s).to(b_q.dtype), tl.trans(b_q),\n allow_tf32=False)\n tl.debug_barrier()\n o_q, o_k = tl.arange(0, BTS), tl.arange(0, BTL)\n for i in range(i_c * BTL, (i_c + 1) * BTL, BTS):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i), (BK, BTS), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (V, T), (s_v_d, s_v_t),\n (i_v * BV, i), (BV, BTS), (0, 1))\n p_dz = dz + i_bh * T + i + tl.arange(0, BTS)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)).to(b_q.dtype)\n b_dz = tl.load(p_dz, mask=i + tl.arange(0, BTS) < T)\n m_s = o_k[:, None] <= o_q[None, :]\n b_s = tl.dot(b_k, b_q, allow_tf32=False) * scale\n b_s2 = b_s * b_s\n b_s = tl.where(m_s, b_s, 0)\n b_s2 = tl.where(m_s, b_s2, 0)\n b_ds = tl.dot(b_v, b_do, allow_tf32=False)\n if i_v == 0:\n b_ds += b_dz[None, :]\n else:\n b_ds = b_ds\n b_ds = tl.where(m_s, b_ds, 0) * scale\n b_dv += tl.dot(b_s2.to(b_q.dtype), tl.trans(b_do), allow_tf32=False)\n b_dk += tl.dot((2 * b_ds * b_s).to(b_q.dtype), tl.trans(b_q),\n allow_tf32=False)\n o_q += BTS\n p_dk = tl.make_block_ptr(dk + (i_bh + B * H * i_v) * s_k_h, (T, K), (\n s_k_t, s_k_d), (i_c * BTL, i_k * BK), (BTL, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_bh + B * H * i_k) * s_v_h, (T, V), (\n s_v_t, s_v_d), (i_c * BTL, i_v * BV), (BTL, BV), (1, 0))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n return\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rebased/parallel.py" }, { "uuid": "6e8a194d-0aed-429d-8a29-942bafe62aad", "file_name": "tl_evaluate.py", "repo_name": "2986002971/TSP_GA", "file_path": "algorithm/tl_evaluate.py", "commit_hash": "930dd889a3b99e18cd9e07c344fc9cbc3ce6d9c8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE': 32}, num_warps=4),\n triton.Config({'BLOCK_SIZE': 64}, num_warps=8), triton.Config({\n 'BLOCK_SIZE': 128}, num_warps=8), triton.Config({'BLOCK_SIZE': 256},\n num_warps=16)], key=['n_paths', 'n_cities'])\n@triton.jit\ndef evaluate_paths_kernel(dist_matrix_ptr, paths_ptr, n_cities: tl.\n constexpr, next_power_of_2: tl.constexpr, n_paths: tl.constexpr,\n output_ptr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n \u8bc4\u4f30\u6240\u6709\u8def\u5f84\u7684\u8ddd\u79bb\uff0c\u627e\u51fa\u6700\u77ed\u8def\u5f84\n \"\"\"\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_paths\n path_start = offsets * n_cities\n city_offsets = tl.arange(0, next_power_of_2)\n city_mask = city_offsets < n_cities\n \"\"\"\n \u5229\u7528\u5e7f\u64ad\u673a\u5236\uff0c\u4e00\u6b21\u6027\u52a0\u8f7d\u4e00\u7ec4\u8def\u5f84\u7684\u6240\u6709\u57ce\u5e02\u7d22\u5f15\n \u5047\u8bbe\n BLOCK_SIZE = 2\n n_cities = 3\n\n \u5219\u53ef\u77e5\n path_start = [0, 3]\n\n \u5219\n city_offsets = [0, 1, 2]\n path_start[:, None] = [[0],\n [3]]\n city_offsets[None, :] = [[0, 1, 2]]\n\n \u52a0\u8f7d\u5f53\u524d\u57ce\u5e02\u7684\u7d22\u5f15\uff0c\u5e7f\u64ad\u8fd0\u7b97\uff1a\n [[0, 1, 2],\n [3, 4, 5]]\n\n \u52a0\u8f7d\u4e0b\u4e00\u4e2a\u57ce\u5e02\u7684\u7d22\u5f15\uff08\u6a21\u8fd0\u7b97\uff09\uff1a\n [[1, 2, 0],\n [4, 5, 3]]\n \"\"\"\n curr_cities = tl.load(paths_ptr + path_start[:, None] + city_offsets[\n None, :], mask=mask[:, None] & city_mask[None, :])\n next_cities = tl.load(paths_ptr + path_start[:, None] + ((city_offsets +\n 1) % n_cities)[None, :], mask=mask[:, None] & city_mask[None, :])\n dists = tl.load(dist_matrix_ptr + curr_cities * n_cities + next_cities,\n mask=mask[:, None])\n distances = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n distances = tl.sum(dists, axis=1)\n tl.store(output_ptr + offsets, distances, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/2986002971/TSP_GA/blob/930dd889a3b99e18cd9e07c344fc9cbc3ce6d9c8/algorithm/tl_evaluate.py" }, { "uuid": "705819f8-d177-4232-b148-dca7e6e633ff", "file_name": "paged_attn_v2.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn_v2.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _single_query_cached_kv_attention_v2_unroll4(exp_sums, max_logits, out,\n q, k_cache, v_cache, head_mapping, scale, block_tables, seq_lens,\n partiton_size, max_num_blocks_per_seq, alibi_slopes, stride_qm,\n stride_qn, stride_om, stride_on, stride_ok, stride_km, stride_kn,\n stride_kk, stride_exp_m, stride_exp_n, BLOCK_SIZE: tl.constexpr,\n HEAD_SIZE: tl.constexpr):\n seq_idx = tl.program_id(axis=1)\n par_idx = tl.program_id(axis=2)\n seq_len = tl.load(seq_lens + seq_idx)\n if par_idx * partiton_size >= seq_len:\n return\n num_context_blocks = tl.cdiv(seq_len, BLOCK_SIZE)\n num_blocks_per_par = partiton_size // BLOCK_SIZE\n start_block_idx = par_idx * num_blocks_per_par\n end_block_idx = tl.minimum(start_block_idx + num_blocks_per_par,\n num_context_blocks)\n head_idx = tl.program_id(axis=0)\n kv_head_idx = tl.load(head_mapping + head_idx)\n if alibi_slopes is None:\n alibi_slope = 0.0\n else:\n alibi_slope = tl.load(alibi_slopes + head_idx)\n block_offs = tl.arange(0, BLOCK_SIZE)\n head_size_offs = tl.arange(0, HEAD_SIZE)\n q = tl.load(q + seq_idx * stride_qm + head_idx * stride_qn + head_size_offs\n )\n q = (q * scale).to(tl.float16)\n qkv = tl.zeros([BLOCK_SIZE, HEAD_SIZE], dtype=tl.float32)\n qk_max = float('-inf')\n exp_sum = 0.0\n fp16_0 = tl.zeros([1, 1], dtype=k_cache.dtype.element_ty)\n base_offs_kv = kv_head_idx * stride_kn + block_offs[:, None\n ] * stride_kk + head_size_offs[None, :]\n block_base_ptrs = block_tables + seq_idx * max_num_blocks_per_seq\n for block_idx in range(start_block_idx, end_block_idx, 4):\n mask_0 = block_offs[:, None] < seq_len - (block_idx + 0) * BLOCK_SIZE\n mask_1 = block_offs[:, None] < seq_len - (block_idx + 1) * BLOCK_SIZE\n mask_2 = block_offs[:, None] < seq_len - (block_idx + 2) * BLOCK_SIZE\n mask_3 = block_offs[:, None] < seq_len - (block_idx + 3) * BLOCK_SIZE\n offs_kv_0 = tl.load(block_base_ptrs + block_idx + 0\n ) * stride_km + base_offs_kv\n offs_kv_1 = tl.load(block_base_ptrs + block_idx + 1\n ) * stride_km + base_offs_kv\n offs_kv_2 = tl.load(block_base_ptrs + block_idx + 2\n ) * stride_km + base_offs_kv\n offs_kv_3 = tl.load(block_base_ptrs + block_idx + 3\n ) * stride_km + base_offs_kv\n k_0 = tl.load(k_cache + offs_kv_0, mask=mask_0, other=fp16_0)\n k_1 = tl.load(k_cache + offs_kv_1, mask=mask_1, other=fp16_0)\n k_2 = tl.load(k_cache + offs_kv_2, mask=mask_2, other=fp16_0)\n k_3 = tl.load(k_cache + offs_kv_3, mask=mask_3, other=fp16_0)\n v_0 = tl.load(v_cache + offs_kv_0, mask=mask_0, other=fp16_0)\n v_1 = tl.load(v_cache + offs_kv_1, mask=mask_1, other=fp16_0)\n v_2 = tl.load(v_cache + offs_kv_2, mask=mask_2, other=fp16_0)\n v_3 = tl.load(v_cache + offs_kv_3, mask=mask_3, other=fp16_0)\n _qk_0 = tl.sum((q[None, :] * k_0).to(tl.float32), axis=1)\n _qk_1 = tl.sum((q[None, :] * k_1).to(tl.float32), axis=1)\n _qk_2 = tl.sum((q[None, :] * k_2).to(tl.float32), axis=1)\n _qk_3 = tl.sum((q[None, :] * k_3).to(tl.float32), axis=1)\n _qk_0 += alibi_slope * ((block_idx + 0) * BLOCK_SIZE + block_offs -\n seq_len + 1)\n _qk_1 += alibi_slope * ((block_idx + 1) * BLOCK_SIZE + block_offs -\n seq_len + 1)\n _qk_2 += alibi_slope * ((block_idx + 2) * BLOCK_SIZE + block_offs -\n seq_len + 1)\n _qk_3 += alibi_slope * ((block_idx + 3) * BLOCK_SIZE + block_offs -\n seq_len + 1)\n _qk_max = tl.maximum(tl.max(_qk_0, axis=0), qk_max)\n _qk_max = tl.maximum(tl.max(_qk_1, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_2, axis=0), _qk_max)\n _qk_max = tl.maximum(tl.max(_qk_3, axis=0), _qk_max)\n qk_0 = tl.where(mask_0, _qk_0[:, None], float('-inf'))\n qk_1 = tl.where(mask_1, _qk_1[:, None], float('-inf'))\n qk_2 = tl.where(mask_2, _qk_2[:, None], float('-inf'))\n qk_3 = tl.where(mask_3, _qk_3[:, None], float('-inf'))\n _exp_sum = exp_sum * tl.exp(qk_max - _qk_max) + tl.sum(tl.exp(_qk_0 -\n _qk_max), axis=0) + tl.sum(tl.exp(_qk_1 - _qk_max), axis=0\n ) + tl.sum(tl.exp(_qk_2 - _qk_max), axis=0) + tl.sum(tl.exp(\n _qk_3 - _qk_max), axis=0)\n qkv = qkv * (exp_sum * tl.exp(qk_max - _qk_max) / _exp_sum) + tl.exp(\n qk_0 - _qk_max) / _exp_sum * v_0 + tl.exp(qk_1 - _qk_max\n ) / _exp_sum * v_1 + tl.exp(qk_2 - _qk_max\n ) / _exp_sum * v_2 + tl.exp(qk_3 - _qk_max) / _exp_sum * v_3\n qk_max = _qk_max\n exp_sum = _exp_sum\n offs_exp = seq_idx * stride_exp_m + head_idx * stride_exp_n + par_idx\n tl.store(exp_sums + offs_exp, exp_sum)\n tl.store(max_logits + offs_exp, qk_max)\n offs_out = (seq_idx * stride_om + head_idx * stride_on + par_idx *\n stride_ok + head_size_offs)\n tl.store(out + offs_out, tl.sum(qkv, axis=0))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn_v2.py" }, { "uuid": "60a6b4c9-ca74-46f7-b620-ed6b512cc8aa", "file_name": "chunk_h_split.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_split.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [2, 4, 8] for num_stages in [2, 3]], key=['BT', 'USE_G',\n 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_fwd_kernel_h_split(k, v, g, gk, gv, hs, hr, h0, ht, offsets,\n split_indices, T: tl.constexpr, S: tl.constexpr, H: tl.constexpr, K: tl\n .constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl\n .constexpr, USE_G: tl.constexpr, USE_GK: tl.constexpr, USE_GV: tl.\n constexpr, USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.\n constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_sh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_ss, i_h = i_sh // H, i_sh % H\n if USE_OFFSETS:\n i_n, i_s = tl.load(split_indices + i_ss * 2).to(tl.int32), tl.load(\n split_indices + i_ss * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NS = tl.cdiv(T, S)\n else:\n NS = tl.cdiv(T, S)\n i_n, i_s = i_ss // NS, i_ss % NS\n bos, eos = i_n * T, i_n * T + T\n i_nh = i_n * H + i_h\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if i_s == 0:\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n p_hr = tl.make_block_ptr(hr + i_sh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_hr, b_h.to(p_hr.dtype.element_ty), boundary_check=(0, 1))\n for i_t in range(tl.cdiv(i_s * S, BT), tl.cdiv(min(i_s * S + S, T), BT)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_nh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_nh * T + last_idx)\n p_g = g + i_nh * T + i_t * BT + tl.arange(0, BT)\n p_g = tl.max_contiguous(tl.multiple_of(p_g, BT), BT)\n else:\n b_g_last = tl.load(g + bos * H + last_idx * H + i_h)\n p_g = g + bos * H + (i_t * BT + tl.arange(0, BT)) * H + i_h\n b_h *= tl.exp(b_g_last)\n b_g = tl.load(p_g, mask=i_t * BT + tl.arange(0, BT) < T, other=0.0)\n b_v = (b_v * tl.exp(b_g_last - b_g)[:, None]).to(b_v.dtype)\n if USE_GK:\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(gk + i_nh * T * K, (K, T), (1, K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = (gk + i_nh * T * K + last_idx * K + i_k * BK +\n tl.arange(0, BK))\n else:\n p_gk = tl.make_block_ptr(gk + (bos * H + i_h) * K, (K, T),\n (1, H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) <\n K, other=0.0)\n b_h *= tl.exp(b_gk_last)[:, None]\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_k = (b_k * tl.exp(b_gk_last[:, None] - b_gk)).to(b_k.dtype)\n if USE_GV:\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(gv + i_nh * T * V, (T, V), (V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = (gv + i_nh * T * V + last_idx * V + i_v * BV +\n tl.arange(0, BV))\n else:\n p_gv = tl.make_block_ptr(gv + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) <\n V, other=0.0)\n b_h *= tl.exp(b_gv_last)[None, :]\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_v = (b_v * tl.exp(b_gv_last[None, :] - b_gv)).to(b_v.dtype)\n b_h += tl.dot(b_k, b_v)\n if NS > 1:\n p_hs = tl.make_block_ptr(hs + i_sh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_hs, b_h.to(p_hs.dtype.element_ty), boundary_check=(0, 1))\n elif STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_split.py" }, { "uuid": "8a0c1d45-0ee4-4b70-a724-b28e532e0284", "file_name": "lightningAttention2.py", "repo_name": "Computational-Machine-Intelligence/LeetDecoding", "file_path": "leetDecoding/methods/lightningAttention2.py", "commit_hash": "1b545c2f5bacc155255250d1f70ac9484744559a", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel(Q, K, V, Out, S, b: tl.constexpr, h: tl.constexpr, n: tl.\n constexpr, d: tl.constexpr, e: tl.constexpr, BLOCK: tl.constexpr,\n NUM_BLOCK: tl.constexpr, BLOCK_MODEL: tl.constexpr):\n off_bh = tl.program_id(0)\n off_h = off_bh % h\n off_e = tl.program_id(1)\n qk_offset = off_bh * n * d\n v_offset = off_bh * n * e\n o_offset = off_bh * n * e\n e_offset = off_e * BLOCK_MODEL\n Q_block_ptr = Q + qk_offset + tl.arange(0, d)[None, :]\n K_trans_block_ptr = K + qk_offset + tl.arange(0, d)[:, None]\n V_block_ptr = V + v_offset + e_offset + tl.arange(0, BLOCK_MODEL)[None, :]\n O_block_ptr = Out + o_offset + e_offset + tl.arange(0, BLOCK_MODEL)[None, :\n ]\n S_block_ptr = S + off_h\n s = tl.load(S_block_ptr)\n off_block = tl.arange(0, BLOCK)\n q_decay = tl.exp(-s.to(tl.float32) * off_block[:, None])\n k_trans_decay = tl.exp(-s.to(tl.float32) * (BLOCK - off_block[None, :]))\n block_decay = tl.exp(-s.to(tl.float32) * BLOCK)\n index = off_block[:, None] - off_block[None, :]\n s_index = s * index\n s_index = tl.where(index >= 0, -s_index, float('-inf'))\n diag_decay = tl.exp(s_index)\n kv = tl.zeros([d, BLOCK_MODEL], dtype=tl.float32)\n for i in range(NUM_BLOCK):\n q = tl.load(Q_block_ptr + off_block[:, None] * d, mask=off_block[:,\n None] < n, other=0.0).to(tl.float32)\n k_trans = tl.load(K_trans_block_ptr + off_block[None, :] * d, mask=\n off_block[None, :] < n, other=0.0).to(tl.float32)\n v = tl.load(V_block_ptr + off_block[:, None] * e, mask=off_block[:,\n None] < n, other=0.0).to(tl.float32)\n qk = tl.dot(q, k_trans) * diag_decay\n o_intra = tl.dot(qk, v)\n o_inter = tl.dot(q, kv) * q_decay\n o = o_intra + o_inter\n tl.store(O_block_ptr + off_block[:, None] * e, o.to(O_block_ptr.\n dtype.element_ty), mask=off_block[:, None] < n)\n kv = block_decay * kv + tl.dot(k_trans * k_trans_decay, v)\n off_block += BLOCK\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Softmax" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Computational-Machine-Intelligence/LeetDecoding/blob/1b545c2f5bacc155255250d1f70ac9484744559a/leetDecoding/methods/lightningAttention2.py" }, { "uuid": "006edbee-aca4-431a-a039-c2ae16158575", "file_name": "swiglu.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/swiglu.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef swiglu_forward_optimized(e_ptr, g_ptr, output_ptr, sigmoid_ptr, f_ptr,\n e_stride, g_stride, output_stride, sigmoid_stride, f_stride, BLOCK_SIZE:\n tl.constexpr, n_cols):\n row_idx = tl.program_id(axis=0)\n col_offset = tl.arange(0, BLOCK_SIZE)\n mask = col_offset < n_cols\n e_ptr += row_idx * e_stride\n g_ptr += row_idx * g_stride\n output_ptr += row_idx * output_stride\n sigmoid_ptr += row_idx * sigmoid_stride\n f_ptr += row_idx * f_stride\n e_row = tl.load(e_ptr + col_offset, mask=mask).to(tl.float32)\n g_row = tl.load(g_ptr + col_offset, mask=mask).to(tl.float32)\n sigmoid_e_row = tl.sigmoid(e_row)\n f_row = e_row * sigmoid_e_row\n tl.store(sigmoid_ptr + col_offset, sigmoid_e_row, mask=mask)\n tl.store(f_ptr + col_offset, f_row, mask=mask)\n output_row = f_row * g_row\n tl.store(output_ptr + col_offset, output_row, mask=mask)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/swiglu.py" }, { "uuid": "8edb5183-1d49-41a4-b064-f713cd7c7a3d", "file_name": "test_triton.py", "repo_name": "pytorch/xla", "file_path": "test/test_triton.py", "commit_hash": "40efdb7b6571ce92797b5ba42619b79c1b147b3e", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd(Q, K, V, sm_scale, M, Out, stride_qz, stride_qh, stride_qm,\n stride_qk, stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vk, stride_vn, stride_oz, stride_oh, stride_om,\n stride_on, Z, H, N_CTX, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,\n HEAD_DIM: tl.constexpr, STAGE: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n off_z = off_hz // H\n off_h = off_hz % H\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, HEAD_DIM), order=(1, 0))\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, HEAD_DIM), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(HEAD_DIM,\n N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0), block_shape\n =(HEAD_DIM, BLOCK_N), order=(0, 1))\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, HEAD_DIM), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, HEAD_DIM], dtype=tl.float32)\n qk_scale = sm_scale\n qk_scale *= 1.44269504\n q = tl.load(Q_block_ptr)\n if STAGE & 1:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, HEAD_DIM, BLOCK_N, 4 -\n STAGE, offs_m, offs_n, N_CTX, V.dtype.element_ty == tl.float8e5)\n if STAGE & 2:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, HEAD_DIM, BLOCK_N, 2,\n offs_m, offs_n, N_CTX, V.dtype.element_ty == tl.float8e5)\n m_i += tl.math.log2(l_i)\n acc = acc / l_i[:, None]\n m_ptrs = M + off_hz * N_CTX + offs_m\n tl.store(m_ptrs, m_i)\n tl.store(O_block_ptr, acc.to(Out.type.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Softmax" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch/xla/blob/40efdb7b6571ce92797b5ba42619b79c1b147b3e/test/test_triton.py" }, { "uuid": "8c5238cc-c037-4b47-b27f-b517a0dadced", "file_name": "cross_entropy_loss_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/cross_entropy_loss_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef cross_entropy_loss_forward_kernel(input_pointer, target_pointer,\n weight_pointer, sum_weights_pointer, output_pointer, batch_dim,\n feat_dim, input_batch_stride, input_feat_stride, weighted: tl.constexpr,\n BLOCK_SIZE_BATCH: tl.constexpr, BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Measures the mean cross entropy loss between the input and target,\n with optional reweighing of each class.\n\n Args:\n input_pointer: Pointer to the input.\n The input must be of shape [batch_dim, feat_dim].\n target_pointer: Pointer to the target.\n The target must be of shape [batch_dim].\n weight_pointer: Pointer to an optional class weight vector.\n The class weight vector, if provided, must be of shape [feat_dim].\n sum_weights_pointer: Pointer to a container the sum of the class weights is written to.\n The container must be of shape [batch_dim/BLOCK_SIZE_BATCH].\n output_pointer: Pointer to a container the loss is written to.\n The container must be of shape [batch_dim/BLOCK_SIZE_BATCH].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n weighted: Flag for weighing each class.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n target = tl.load(target_pointer + batch_offset, mask=batch_mask)\n pred_pointer = (input_pointer + input_feat_stride * target + \n input_batch_stride * batch_offset)\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :], other=-float('inf')).to(tl.float32)\n pred = tl.load(pred_pointer, mask=batch_mask).to(tl.float32)\n mx = tl.max(input, axis=1)\n input -= mx[:, None]\n loss = tl.log(tl.sum(tl.exp(input), axis=1)) - pred + mx\n if weighted:\n weight = tl.load(weight_pointer + target, mask=batch_mask).to(tl.\n float32)\n loss *= weight\n tl.store(sum_weights_pointer + batch_pid, tl.sum(weight))\n else:\n loss /= batch_dim\n tl.store(output_pointer + batch_pid, tl.sum(loss))\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/cross_entropy_loss_kernels.py" }, { "uuid": "a74682cf-3a90-4677-b098-f7898cae3980", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/hgrn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BD': 32}, num_warps=1), triton.\n Config({'BD': 32}, num_warps=2), triton.Config({'BD': 32}, num_warps=4),\n triton.Config({'BD': 32}, num_warps=8), triton.Config({'BD': 64},\n num_warps=1), triton.Config({'BD': 64}, num_warps=2), triton.Config({\n 'BD': 64}, num_warps=4), triton.Config({'BD': 64}, num_warps=8), triton\n .Config({'BD': 128}, num_warps=1), triton.Config({'BD': 128}, num_warps\n =2), triton.Config({'BD': 128}, num_warps=4), triton.Config({'BD': 128},\n num_warps=8)], key=['D'])\n@triton.jit\ndef chunk_hgrn_bwd_kernel_h(g, gc, dx, do, T: tl.constexpr, D: tl.constexpr,\n BT: tl.constexpr, BD: tl.constexpr):\n i_d, i_t, i_b = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_d = i_d * BD + tl.arange(0, BD)\n mask = o_d < D\n BC = min(BT, T - i_t * BT)\n NT = tl.num_programs(1)\n p_g = g + (i_b * T + i_t * BT + BC - 1) * D + o_d\n p_gc = gc + (i_b * T + i_t * BT + BC - 1) * D + o_d\n p_dx = dx + (i_b * T + i_t * BT + BC - 1) * D + o_d\n p_do = do + (i_b * T + i_t * BT + BC - 1) * D + o_d\n if i_t == NT - 1:\n b_gc = tl.zeros([BD], dtype=tl.float32)\n else:\n b_gc = tl.load(g + (i_b * T + i_t * BT + BT) * D + o_d, mask=mask,\n other=0).to(tl.float32)\n b_dh = tl.zeros([BD], dtype=tl.float32)\n for _ in range(BC - 1, -1, -1):\n tl.store(p_gc, b_gc.to(p_gc.dtype.element_ty), mask=mask)\n b_g = tl.load(p_g, mask=mask, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask, other=0).to(tl.float32)\n b_gc = b_gc + b_g\n b_dh = b_dh + b_do\n b_dx = b_dh\n b_dh = b_dh * tl.exp(b_g)\n tl.store(p_dx, b_dx.to(p_dx.dtype.element_ty), mask=mask)\n p_g -= D\n p_gc -= D\n p_dx -= D\n p_do -= D\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/hgrn/chunk.py" }, { "uuid": "09e3a5f7-b511-46a3-93e4-ca2098887d89", "file_name": "triton_chunk.py", "repo_name": "NX-AI/xlstm-jax", "file_path": "xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py", "commit_hash": "6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7", "starcount": 0, "input": "@triton.jit\ndef chunk_mlstm_bwd_kernel_dqkvif(q, k, v, C, m, m_total, norm, i, f, dh,\n dC, dq, dk, dv, s_qk_h, s_qk_t, s_qk_d, s_vh_h, s_vh_t, s_vh_d, s_C_h,\n s_C_t, scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr, NT: tl.constexpr):\n i_k, i_t, i_bC = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n o_i = tl.arange(0, BT)\n p_q = tl.make_block_ptr(q + i_bC * s_qk_h, (K, T), (s_qk_d, s_qk_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bC * s_qk_h, (T, K), (s_qk_t, s_qk_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_s = tl.dot(b_k, b_q, allow_tf32=False)\n p_f = f + i_bC * T + i_t * BT + tl.arange(0, BT)\n p_i = i + i_bC * T + i_t * BT + tl.arange(0, BT)\n b_f = tl.load(p_f)\n b_f_last = tl.load(f + i_bC * T + i_t * BT + BT - 1)\n b_m = tl.load(m + i_bC * (NT + 1) + i_t)\n b_m_total = tl.load(m_total + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_norm = tl.load(norm + i_bC * T + i_t * BT + tl.arange(0, BT))\n b_i = tl.load(p_i)\n mask = tl.math.exp2(b_i[:, None] + b_f[None, :] - b_f[:, None] -\n b_m_total[None, :])\n mask = tl.where(o_i[:, None] <= o_i[None, :], mask * scale, 0)\n b_s = b_s * mask\n b_m_next = tl.load(m + i_bC * (NT + 1) + i_t + 1)\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_ds = tl.zeros([BT, BT], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n p_v = tl.make_block_ptr(v + i_bC * s_vh_h, (T, V), (s_vh_t, s_vh_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_C = tl.make_block_ptr(C + i_bC * s_C_h, (V, NT * K), (1, s_C_t),\n (i_v * BV, i_t * K + i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + i_bC * s_vh_h, (T, V), (s_vh_t,\n s_vh_d), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dC = tl.make_block_ptr(dC + i_bC * s_C_h, (NT * K, V), (s_C_t, 1),\n (i_t * K + i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * n_bh + i_bC) * s_vh_h, (T, V),\n (s_vh_t, s_vh_d), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_C = tl.load(p_C, boundary_check=(0, 1))\n b_dC = tl.load(p_dC, boundary_check=(0, 1))\n b_ds += tl.dot(b_dh, tl.trans(b_v), allow_tf32=False)\n b_dq += tl.dot(b_dh, b_C, allow_tf32=False) * scale\n b_dk += tl.dot(b_v, tl.trans(b_dC), allow_tf32=False)\n b_dv = tl.dot(b_k, b_dC, allow_tf32=False) * tl.math.exp2(b_i - b_f +\n b_f_last - b_m_next)[:, None] + tl.dot(b_s.to(b_q.dtype) /\n b_norm[None, :], b_dh, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n b_dq = b_dq * tl.math.exp2(b_f + b_m - b_m_total)[:, None] / b_norm[:, None\n ]\n b_dk = b_dk * tl.math.exp2(b_i - b_f + b_f_last - b_m_next)[:, None]\n b_ds = b_ds * tl.trans(mask)\n b_ds = b_ds.to(b_k.dtype)\n b_dq += tl.dot(b_ds, b_k, allow_tf32=False) / b_norm[:, None]\n b_dk += tl.trans(tl.dot(b_q / b_norm[None, :], b_ds, allow_tf32=False))\n p_dq = tl.make_block_ptr(dq + i_bC * s_qk_h, (T, K), (s_qk_t, s_qk_d),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bC * s_qk_h, (T, K), (s_qk_t, s_qk_d),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "Apache", "BSD" ], "github_url": "https://github.com/NX-AI/xlstm-jax/blob/6615e620ba4ecdbe4fd9cc4e9a5a313b133e84a7/xlstm_jax/models/xlstm_pytorch/blocks/mlstm/backend/triton_chunk.py" }, { "uuid": "b533c264-f2a6-46f8-ac1f-f1b856309aba", "file_name": "wy_fast.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gated_delta_rule/wy_fast.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=num_warps) for\n num_warps in [2, 4, 8]], key=['BK'])\n@triton.jit\ndef fwd_prepare_wy_repr_kernel_chunk32(k, g, beta, Aw, Au, offsets, indices,\n T: tl.constexpr, K: tl.constexpr, H: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr, BC: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n b_Aw = tl.zeros([BC, BC], dtype=tl.float32)\n if HEAD_FIRST:\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n else:\n p_beta = tl.make_block_ptr(beta + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kb = (b_k * b_beta[:, None]).to(b_k.dtype)\n b_Aw += tl.dot(b_kb, tl.trans(b_k))\n b_Aw = -tl.where(tl.arange(0, BC)[:, None] > tl.arange(0, BC)[None, :],\n b_Aw, 0)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n else:\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_Au = b_Aw * tl.exp(b_g[:, None] - b_g[None, :])\n for i in range(1, BC):\n mask = tl.arange(0, BC) == i\n b_aw = tl.sum(tl.where(mask[:, None], b_Aw, 0), 0)\n b_au = tl.sum(tl.where(mask[:, None], b_Au, 0), 0)\n b_aw = b_aw + tl.sum(b_aw[:, None] * b_Aw, 0) * (tl.arange(0, BC) < i)\n b_au = b_au + tl.sum(b_au[:, None] * b_Au, 0) * (tl.arange(0, BC) < i)\n b_Aw = tl.where(mask[:, None], b_aw, b_Aw)\n b_Au = tl.where(mask[:, None], b_au, b_Au)\n b_Aw += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n b_Au += tl.arange(0, BC)[:, None] == tl.arange(0, BC)[None, :]\n if HEAD_FIRST:\n p_Aw = tl.make_block_ptr(Aw + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BC, BC), (1, 0))\n p_Au = tl.make_block_ptr(Au + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BC, BC), (1, 0))\n else:\n p_Aw = tl.make_block_ptr(Aw + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BC, BC), (1, 0))\n p_Au = tl.make_block_ptr(Au + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT, 0), (BC, BC), (1, 0))\n tl.store(p_Aw, b_Aw.to(p_Aw.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_Au, b_Au.to(p_Au.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gated_delta_rule/wy_fast.py" }, { "uuid": "d7b0c935-63df-4ee8-a4db-e04227fcfa37", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef load_1d(ptr, sz: tl.constexpr, n, max, stride=1):\n \"\"\"Chunk 1d vector (defined by ptr) into 1d grid, where each chunk has size sz.\n Load the nth chunk. Ie, load [n*sz,...,(n+1)*sz-1].\"\"\"\n offs = get_1d_offest(sz, n)\n mask = get_1d_mask(offs, max)\n return tl.load(ptr + offs, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "abd8d704-a5d9-4edd-8154-cd775adf20b5", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef bwd_inner_chunk(q, k, g, dA, dq, dk, s_k_h, s_k_t, s_k_d, T: tl.\n constexpr, K: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n p_g = tl.make_block_ptr(g + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0, 1)).to(tl.float32)\n mask = i_k * BK + tl.arange(0, BK) < K\n o_i = tl.arange(0, BT)\n p_q = q + i_bh * s_k_h + i_k * BK + i_t * BT * K + tl.arange(0, BK)\n p_dq = dq + i_bh * s_k_h + i_k * BK + i_t * BT * K + tl.arange(0, BK)\n p_gq = g + i_bh * s_k_h + i_k * BK + i_t * BT * K + tl.arange(0, BK)\n p_dA = dA + i_bh * (tl.cdiv(T, BT) * BT * BT) + i_t * BT * BT + tl.arange(\n 0, BT)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n for i in range(BT):\n _q = tl.load(p_q, mask=mask, other=0)\n gq = tl.load(p_gq, mask=mask, other=0).to(tl.float32)\n score = tl.exp(gq[None, :] - b_g)\n score = tl.where(o_i[:, None] <= i, score, 0)\n _dA = tl.load(p_dA)\n _dA = tl.where(o_i <= i, _dA, 0)\n b_dk += _dA[:, None] * score * _q[None, :]\n b_dq = tl.sum(_dA[:, None] * score * b_k, axis=0)\n tl.store(p_dq, b_dq, mask=mask)\n p_q += K\n p_dq += K\n p_gq += K\n p_dA += BT\n p_dk = tl.make_block_ptr(dk + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dk, b_dk.to(dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/fused_chunk.py" }, { "uuid": "dfffff6c-5718-4d9e-8554-1123df93f9ca", "file_name": "ln_linear_triton_2.py", "repo_name": "ethansmith2000/fused-layer-norm", "file_path": "ln_linear_triton_2.py", "commit_hash": "84fe243a829364acdcfd7cd70b699db04838af0f", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_bwd_dx_fused(DX, DY, DSc, DSh, Y, Sc, Sh, Mean, Rstd, Lock,\n stride, N, GROUP_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr):\n row = tl.program_id(0)\n cols = tl.arange(0, BLOCK_SIZE_N)\n mask = cols < N\n Y += row * stride\n DY += row * stride\n DX += row * stride\n lock_id = row % GROUP_SIZE_M\n Lock += lock_id\n Count = Lock + GROUP_SIZE_M\n DSc = DSc + lock_id * N + cols\n DSh = DSh + lock_id * N + cols\n y = tl.load(Y + cols, mask=mask, other=0).to(tl.float32)\n dy = tl.load(DY + cols, mask=mask, other=0).to(tl.float32)\n sc = tl.load(Sc + cols, mask=mask).to(tl.float32)\n sh = tl.load(Sh + cols, mask=mask).to(tl.float32)\n mean = tl.load(Mean + row)\n rstd = tl.load(Rstd + row)\n xhat = (y - sh) / sc\n scdy = sc * dy\n xhat = tl.where(mask, xhat, 0.0)\n scdy = tl.where(mask, scdy, 0.0)\n c1 = tl.sum(xhat * scdy, axis=0) / N\n c2 = tl.sum(scdy, axis=0) / N\n dx = (scdy - (xhat * c1 + c2)) * rstd\n tl.store(DX + cols, dx, mask=mask)\n partial_dsc = (dy * xhat).to(sc.dtype)\n partial_dsh = dy.to(sc.dtype)\n while tl.atomic_cas(Lock, 0, 1) == 1:\n pass\n count = tl.load(Count)\n if count == 0:\n tl.atomic_xchg(Count, 1)\n else:\n partial_dsc += tl.load(DSc, mask=mask)\n partial_dsh += tl.load(DSh, mask=mask)\n tl.store(DSc, partial_dsc, mask=mask)\n tl.store(DSh, partial_dsh, mask=mask)\n tl.atomic_xchg(Lock, 0)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Shared Memory Intensive" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ethansmith2000/fused-layer-norm/blob/84fe243a829364acdcfd7cd70b699db04838af0f/ln_linear_triton_2.py" }, { "uuid": "0556ec3b-dfff-4fcf-bfe4-7f2f435207f6", "file_name": "test_sampler.py", "repo_name": "Coco58323/vllm_blend", "file_path": "tests/kernels/test_sampler.py", "commit_hash": "1fe36887b3c8402d71d119f6a2ff545c2fffff4d", "starcount": 0, "input": "@triton.jit\ndef _uniform_to_exponential_kernel(input, output, n: tl.constexpr):\n idx = tl.arange(0, n)\n x = tl.load(input + idx)\n y = _uniform_to_exponential(x)\n tl.store(output + idx, y)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Coco58323/vllm_blend/blob/1fe36887b3c8402d71d119f6a2ff545c2fffff4d/tests/kernels/test_sampler.py" }, { "uuid": "88444d28-55e3-434c-8f2a-ca5d9b2c5a02", "file_name": "triton_conv3d.py", "repo_name": "l1351868270/implicit_gemm.triton", "file_path": "triton_conv3d.py", "commit_hash": "64eb8548ccf4576883c928f6315be8b24680a455", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['N', 'C', 'D', 'H',\n 'W', 'K', 'D_out', 'H_out', 'W_out', 'T', 'R', 'S', 'stride_d',\n 'stride_h', 'stride_w', 'pad_d', 'pad_h', 'pad_w', 'dila_d', 'dila_h',\n 'dila_w'])\n@triton.jit\ndef conv3d_kernel(x_ptr, w_ptr, y_ptr, N, C, D, H, W, K, D_out, H_out,\n W_out, T, R, S, stride_d, stride_h, stride_w, pad_d, pad_h, pad_w,\n dila_d, dila_h, dila_w, GEMM_M, GEMM_N, GEMM_K, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(GEMM_M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(GEMM_N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n gemm_i = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % GEMM_M\n gemm_j = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % GEMM_N\n n = gemm_i // (D_out * H_out * W_out)\n ndhw_residual = gemm_i % (D_out * H_out * W_out)\n d_out = ndhw_residual // (H_out * W_out)\n dhw_residual = ndhw_residual % (H_out * W_out)\n h_out = dhw_residual // W_out\n w_out = dhw_residual % W_out\n k = gemm_j\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for idx_k in range(0, tl.cdiv(GEMM_K, BLOCK_SIZE_K)):\n gemm_k = idx_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n t = gemm_k // (R * S * C)\n trsc_residual = gemm_k % (R * S * C)\n r = trsc_residual // (S * C)\n rsc_residual = gemm_k % (S * C)\n s = rsc_residual // C\n c = rsc_residual % C\n d = d_out[:, None] * stride_d + t[None, :] * dila_d - pad_d\n h = h_out[:, None] * stride_h + r[None, :] * dila_h - pad_h\n w = w_out[:, None] * stride_w + s[None, :] * dila_w - pad_w\n mask_x = (d >= 0) & (d < D) & (h >= 0) & (h < H) & (w >= 0) & (w < W)\n mask_w = (t < T) & (r < R) & (s < S) & (c < C)\n offs_x = n[:, None\n ] * D * H * W * C + d * H * W * C + h * W * C + w * C + c\n offs_w = k[None, :] * T * R * S * C + t[:, None] * R * S * C + r[:,\n None] * S * C + s[:, None] * C + c[:, None]\n x_ptrs = x_ptr + offs_x\n w_ptrs = w_ptr + offs_w\n x_data = tl.load(x_ptrs, mask=mask_x, other=0.0)\n w_data = tl.load(w_ptrs, mask=mask_w[:, None], other=0.0)\n accumulator = tl.dot(x_data, w_data, accumulator)\n c_data = accumulator.to(tl.float16)\n offs_y = gemm_i[:, None] * GEMM_N + gemm_j[None, :]\n mask_y = (gemm_i[:, None] < GEMM_M) & (gemm_j[None, :] < GEMM_N)\n y_ptrs = y_ptr + offs_y\n tl.store(y_ptrs, c_data, mask=mask_y)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/l1351868270/implicit_gemm.triton/blob/64eb8548ccf4576883c928f6315be8b24680a455/triton_conv3d.py" }, { "uuid": "0cdc9206-f8ac-4983-a3c9-9a7b7091b772", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_o(p, v, o, rv, cv, pv, s_qk_h, s_qk_t, s_qk_d,\n s_sk_h, s_sk_t, s_sk_m, T, BT: tl.constexpr, BM: tl.constexpr, BV: tl.\n constexpr, DM: tl.constexpr, DV: tl.constexpr, NT: tl.constexpr):\n i_v, i_m, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n p_p = tl.make_block_ptr(p + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m), (\n 0, i_m * BM), (BT, BM), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_qk_h, (T, DV), (s_qk_t, s_qk_d), (\n 0, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (i_m * n_bh + i_bh) * s_qk_h, (T, DV), (\n s_qk_t, s_qk_d), (0, i_v * BV), (BT, BV), (1, 0))\n p_rv = tl.make_block_ptr(rv + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_cv = tl.make_block_ptr(cv + i_bh * s_sk_h, (DM, T), (s_sk_m, s_sk_t),\n (i_m * BM, 0), (BM, BT), (0, 1))\n p_pv = tl.make_block_ptr(pv + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n (0, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_hv = tl.zeros([BM, BV], dtype=tl.float32)\n for _ in range(NT):\n b_p = tl.load(p_p, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_rv = tl.load(p_rv, boundary_check=(0,))\n b_cv = tl.load(p_cv, boundary_check=(0, 1))\n b_pv = tl.load(p_pv, boundary_check=(0, 1))\n b_p = b_p * b_pv\n b_inter = tl.dot((b_p * b_rv[None, :]).to(b_v.dtype), b_hv.to(b_v.\n dtype), allow_tf32=False)\n b_intra = tl.where(m_s, tl.dot(b_p.to(b_v.dtype), b_cv, allow_tf32=\n False), 0)\n b_intra = tl.dot(b_intra.to(b_v.dtype), b_v, allow_tf32=False)\n b_o = b_inter + b_intra\n b_hv = b_hv * b_rv[:, None] + tl.dot(b_cv, b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_p = tl.advance(p_p, (BT, 0))\n p_v = tl.advance(p_v, (BT, 0))\n p_o = tl.advance(p_o, (BT, 0))\n p_rv = tl.advance(p_rv, (DM,))\n p_cv = tl.advance(p_cv, (0, BT))\n p_pv = tl.advance(p_pv, (BT, 0))\n", "category": { "Functionality": [ "Matrix Multiplication", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "aa3dc7ca-31b5-4d4d-864c-523094a3cabe", "file_name": "blocksparse_logsumexp.py", "repo_name": "kimiasa/Experiments", "file_path": "src/models/attention/blocksparse_logsumexp.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.heuristics({'num_warps': lambda *args, **meta: num_warps(args[3] *\n meta['BLOCK'])})\n@triton.heuristics({'TN': lambda *args, **meta: next_power_of_2(args[3] *\n meta['BLOCK'])})\n@triton.jit\ndef _forward(X, OUT, LUT, sizemax, stride_zx, stride_zout, stride_hout, **meta\n ):\n TN = meta['TN']\n BLOCK = meta['BLOCK']\n pidhm = tl.program_id(0)\n pidz = tl.program_id(1)\n rxm = pidhm % BLOCK\n rbm = pidhm // BLOCK\n rxn = tl.arange(0, TN) % BLOCK\n rbn = tl.arange(0, TN) // BLOCK\n header = LUT + rbm * 2\n size = tl.load(header + 0)\n offset = tl.load(header + 1)\n check = rbn < size\n rbmn = tl.where(check, rbn, size - 1)\n blockid = tl.load(LUT + offset + rbmn * 4 + 0)\n rowid = tl.load(LUT + offset + rbmn * 4 + 2)\n headid = tl.load(LUT + offset + rbmn * 4 + 3)\n px = X + pidz * stride_zx + blockid * BLOCK * BLOCK + rxm * BLOCK + rxn\n x = tl.load(px, mask=check, other=-float('inf'))\n x = x.to(tl.float32)\n c = tl.max(x, axis=0)\n out = tl.log(tl.sum(tl.exp(x - c), axis=0)) + c\n pout = (OUT + pidz * stride_zout + headid * stride_hout + rowid * BLOCK +\n rxm)\n tl.store(pout, out)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/models/attention/blocksparse_logsumexp.py" }, { "uuid": "090c7a0b-2d5b-41b2-ae7d-fd6bf3dd7f24", "file_name": "06-fused-attention.py", "repo_name": "2lambda123/triton", "file_path": "python/tutorials/06-fused-attention.py", "commit_hash": "09e27725b89043a07f49c440db6a9aedcfba8432", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel(Q, K, V, sm_scale, L, Out, stride_qz, stride_qh, stride_qm,\n stride_qk, stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vk, stride_vn, stride_oz, stride_oh, stride_om,\n stride_on, Z, H, N_CTX, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.\n constexpr, BLOCK_N: tl.constexpr, IS_CAUSAL: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n qvk_offset = off_hz * stride_qh\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(\n BLOCK_DMODEL, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504\n q = tl.load(Q_block_ptr)\n q = (q * qk_scale).to(tl.float16)\n lo = 0\n hi = (start_m + 1) * BLOCK_M if IS_CAUSAL else N_CTX\n for start_n in range(lo, hi, BLOCK_N):\n k = tl.load(K_block_ptr)\n v = tl.load(V_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n if IS_CAUSAL:\n qk = tl.where(offs_m[:, None] >= start_n + offs_n[None, :], qk,\n float('-inf'))\n qk += tl.dot(q, k)\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc_scale = l_i * 0 + alpha\n acc *= acc_scale[:, None]\n acc += tl.dot(p.to(tl.float16), v)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n acc = acc / l_i[:, None]\n l_ptrs = L + off_hz * N_CTX + offs_m\n tl.store(l_ptrs, m_i + tl.math.log2(l_i))\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n tl.store(O_block_ptr, acc.to(tl.float16))\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/2lambda123/triton/blob/09e27725b89043a07f49c440db6a9aedcfba8432/python/tutorials/06-fused-attention.py" }, { "uuid": "3756e1f0-c01b-4b42-bb9d-de07cfbb77e8", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=4)], key=['BT', 'BK',\n 'BV'])\n@triton.jit\ndef chunk_simple_gla_fwd_kernel_o(q, k, v, h, g, o, offsets, indices, scale,\n T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT:\n tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NT: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_s = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (\n V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n b_s += tl.dot(b_q, b_k, allow_tf32=False)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n else:\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0,))\n b_o = b_o * tl.exp(b_g)[:, None]\n b_s = b_s * tl.exp(b_g[:, None] - b_g[None, :])\n b_s = tl.where(m_s, b_s, 0)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_o = (b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)) * scale\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Quantization" ], "Data Type": [ "bf16", "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/chunk.py" }, { "uuid": "4fceec9b-8d2a-47cc-a208-fb9e821e4377", "file_name": "fused_moe_a16w4.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/fused_moe_a16w4.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _fused_moe_kernel_a16w4_perchannel(A, B, C, scale_b_ptr,\n zero_points_ptr, topk_weights_ptr, sorted_token_ids_ptr, expert_ids_ptr,\n num_tokens_post_padded_ptr, N, K, EM, num_valid_tokens, stride_am,\n stride_ak, stride_be, stride_bn, stride_bk, stride_cm, stride_cn,\n stride_scale_be, stride_scale_bn, stride_scale_bk, stride_zero_points_e,\n stride_zero_points_n, stride_zero_points_k, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr, MUL_ROUTED_WEIGHT: tl.constexpr, top_k: tl.constexpr,\n add_zero_points: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(EM, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n num_tokens_post_padded = tl.load(num_tokens_post_padded_ptr)\n if pid_m * BLOCK_SIZE_M >= num_tokens_post_padded:\n return\n offs_token_id = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)\n token_mask = offs_token < num_valid_tokens\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N * 2) // 2) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = A + (offs_token[:, None] // top_k * stride_am + offs_k[None, :\n ] * stride_ak)\n off_experts = tl.load(expert_ids_ptr + pid_m)\n b_ptrs = B + off_experts * stride_be + (offs_k[None, :] * stride_bk + \n offs_bn[:, None] * stride_bn)\n if add_zero_points:\n offs_zero_points = pid_n * BLOCK_SIZE_N * 2 + tl.arange(0, 2 *\n BLOCK_SIZE_N)\n zero_points_ptrs = (zero_points_ptr + off_experts *\n stride_zero_points_e + offs_zero_points)\n _ZERO_POINT0 = tl.zeros([1], dtype=zero_points_ptr.dtype.element_ty)\n zero_points_vals = tl.load(zero_points_ptrs, mask=offs_zero_points <\n 2 * N, other=_ZERO_POINT0)\n _A0 = tl.zeros([1, 1], dtype=A.dtype.element_ty)\n _B0 = tl.zeros([1, 1], dtype=B.dtype.element_ty)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N * 2), dtype=tl.float32)\n l_shifter = (1 - tl.arange(0, BLOCK_SIZE_N * 2) % 2) * 4\n for k in range(tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=token_mask[:, None] & (offs_k[None, :] < K -\n k * BLOCK_SIZE_K), other=_A0)\n b = tl.load(b_ptrs, mask=offs_k[None, :] < K - k * BLOCK_SIZE_K,\n other=_B0)\n b = (b << l_shifter[:, None]).to(tl.int8).__rshift__(4)\n if add_zero_points:\n b -= zero_points_vals[:, None]\n b = tl.trans(b)\n b = b.to(a_ptrs.dtype.element_ty)\n accumulator += tl.dot(a, b, out_dtype=tl.float32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n offs_scale = pid_n * BLOCK_SIZE_N * 2 + tl.arange(0, BLOCK_SIZE_N * 2)\n scale_ptrs = (scale_b_ptr + off_experts * stride_scale_be + offs_scale *\n stride_scale_bn)\n _SCALE0 = tl.zeros([1], dtype=scale_b_ptr.dtype.element_ty)\n scales = tl.load(scale_ptrs, mask=offs_scale < 2 * N, other=_SCALE0)\n accumulator *= scales[None, :]\n if MUL_ROUTED_WEIGHT:\n moe_weight = tl.load(topk_weights_ptr + offs_token, mask=token_mask,\n other=0.0)\n accumulator = accumulator * moe_weight[:, None]\n accumulator = accumulator.to(A.dtype.element_ty)\n offs_cn = pid_n * BLOCK_SIZE_N * 2 + tl.arange(0, BLOCK_SIZE_N * 2)\n c_ptrs = C + stride_cm * offs_token[:, None] + stride_cn * offs_cn[None, :]\n c_mask = token_mask[:, None] & (offs_cn[None, :] < N * 2)\n tl.store(c_ptrs, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Quantization", "Top-K Selection", "Matrix Multiplication" ], "Data Type": [ "int8", "bf16", "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Transposed Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/fused_moe_a16w4.py" }, { "uuid": "a8ad76d1-6af5-4b88-892c-7131230d4b1c", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=[\n 'BT'])\n@triton.jit\ndef chunk_retention_fwd_kernel_h(k, v, h, h0, ht, offsets, chunk_offsets, T:\n tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl\n .constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_INITIAL_STATE: tl.\n constexpr, STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr,\n HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n o_i = tl.arange(0, BT)\n d_b, d_i = tl.math.exp2(BT * b_b), tl.math.exp2((BT - o_i - 1) * b_b)\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n for i_t in range(NT):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_nh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + ((boh + i_t) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n if i_t == NT - 1 and T % BT != 0:\n d_b = tl.math.exp2(T % BT * b_b)\n d_i = tl.math.exp2((T % BT - o_i - 1) * b_b)\n b_h = d_b * b_h + tl.dot(b_k, (b_v * d_i[:, None]).to(b_k.dtype),\n allow_tf32=False)\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/chunk.py" }, { "uuid": "49950adc-5589-4676-af7f-0b95a107d8e9", "file_name": "dot_triton.py", "repo_name": "markdewing/AI_kernels", "file_path": "dot/triton/dot_triton.py", "commit_hash": "32b2fe4b1e81cf60a16ef188e37f2d47428ce23d", "starcount": 0, "input": "@triton.jit\ndef dot_product_kernel(x_ptr, y_ptr, output_ptr, n_elements, BLOCK_SIZE: tl\n .constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n x = tl.load(x_ptr + offsets, mask=mask)\n y = tl.load(y_ptr + offsets, mask=mask)\n z = x * y\n c = tl.sum(z)\n tl.atomic_add(output_ptr, c)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/markdewing/AI_kernels/blob/32b2fe4b1e81cf60a16ef188e37f2d47428ce23d/dot/triton/dot_triton.py" }, { "uuid": "23cd9919-1bc6-4aea-9f69-aad2aa2f2839", "file_name": "sb_varlen_bwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_bwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.jit\ndef locked_add(Lock_ptr, Count_ptr, A_ptrs, a, B_ptrs, b, N_mask, NO_N_MASK,\n D_mask, NO_D_MASK: tl.constexpr):\n while tl.atomic_cas(Lock_ptr, 0, 1) == 1:\n pass\n count = tl.load(Count_ptr, eviction_policy='evict_last')\n if NO_D_MASK:\n if NO_N_MASK:\n if count == 0:\n tl.store(Count_ptr, True, eviction_policy='evict_last')\n else:\n a += tl.load(A_ptrs, eviction_policy='evict_last')\n b += tl.load(B_ptrs, eviction_policy='evict_last')\n tl.store(A_ptrs, a, eviction_policy='evict_last')\n tl.store(B_ptrs, b, eviction_policy='evict_last')\n else:\n if count == 0:\n tl.store(Count_ptr, True, eviction_policy='evict_last')\n else:\n a += tl.load(A_ptrs, mask=N_mask[:, None], eviction_policy=\n 'evict_last')\n b += tl.load(B_ptrs, mask=N_mask[:, None], eviction_policy=\n 'evict_last')\n tl.store(A_ptrs, a, mask=N_mask[:, None], eviction_policy=\n 'evict_last')\n tl.store(B_ptrs, b, mask=N_mask[:, None], eviction_policy=\n 'evict_last')\n else:\n mask = N_mask[:, None] & D_mask[None, :]\n if count == 0:\n tl.store(Count_ptr, True, eviction_policy='evict_last')\n else:\n a += tl.load(A_ptrs, mask=mask, eviction_policy='evict_last')\n b += tl.load(B_ptrs, mask=mask, eviction_policy='evict_last')\n tl.store(A_ptrs, a, mask=mask, eviction_policy='evict_last')\n tl.store(B_ptrs, b, mask=mask, eviction_policy='evict_last')\n tl.atomic_xchg(Lock_ptr, 0)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_bwd.py" }, { "uuid": "7f7cdfd8-dd2a-4c5f-825b-860f5d4fc16a", "file_name": "y_1.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_1.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef first_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_Y10 = tl.load(sph_grad_ptr + output_row_offset, mask=\n output_row_offset < output_numel)\n g_Y11 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_Y12 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n CONST_00 = tl.sqrt(3.0)\n g_x += CONST_00 * g_Y10\n g_y += CONST_00 * g_Y11\n g_z += CONST_00 * g_Y12\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_1.py" }, { "uuid": "2a143289-7f7a-4301-8cd6-b7852faa3ceb", "file_name": "triton_flash_attention.py", "repo_name": "IBM/vllm", "file_path": "vllm/attention/ops/triton_flash_attention.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 256, 'BLOCK_N': 64,\n 'waves_per_eu': 2, 'PRE_LOAD_V': False}, num_stages=1, num_warps=8),\n triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128, 'waves_per_eu': 2,\n 'PRE_LOAD_V': False}, num_stages=1, num_warps=4), triton.Config({\n 'BLOCK_M': 256, 'BLOCK_N': 128, 'waves_per_eu': 2, 'PRE_LOAD_V': False},\n num_stages=1, num_warps=8), triton.Config({'BLOCK_M': 128, 'BLOCK_N': \n 64, 'waves_per_eu': 1, 'PRE_LOAD_V': False}, num_stages=1, num_warps=4),\n triton.Config({'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 3,\n 'PRE_LOAD_V': True}, num_stages=1, num_warps=4), triton.Config({\n 'BLOCK_M': 128, 'BLOCK_N': 64, 'waves_per_eu': 3, 'PRE_LOAD_V': False},\n num_stages=1, num_warps=4), triton.Config({'BLOCK_M': 64, 'BLOCK_N': 64,\n 'waves_per_eu': 4, 'PRE_LOAD_V': False}, num_stages=1, num_warps=8),\n triton.Config({'BLOCK_M': 32, 'BLOCK_N': 32, 'waves_per_eu': 4,\n 'PRE_LOAD_V': False}, num_stages=1, num_warps=8), triton.Config({\n 'BLOCK_M': 16, 'BLOCK_N': 16, 'waves_per_eu': 1, 'PRE_LOAD_V': False},\n num_stages=1, num_warps=4)], key=['IS_CAUSAL', 'dropout_p', 'BLOCK_DMODEL']\n )\n@triton.jit\ndef attn_fwd(Q, K, V, bias, sm_scale, L, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, stride_bz, stride_bh, stride_bm, stride_bn,\n cu_seqlens_q, cu_seqlens_k, dropout_p, philox_seed, philox_offset_base,\n encoded_softmax, HQ: tl.constexpr, HK: tl.constexpr,\n ACTUAL_BLOCK_DMODEL: tl.constexpr, MAX_SEQLENS_Q: tl.constexpr,\n MAX_SEQLENS_K: tl.constexpr, VARLEN: tl.constexpr, IS_CAUSAL: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N:\n tl.constexpr, PRE_LOAD_V: tl.constexpr, BIAS_TYPE: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, RETURN_ENCODED_SOFTMAX: tl.constexpr):\n start_m = tl.program_id(0)\n off_h_q = tl.program_id(1)\n off_z = tl.program_id(2)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n if VARLEN:\n cu_seqlens_q_start = tl.load(cu_seqlens_q + off_z)\n cu_seqlens_q_end = tl.load(cu_seqlens_q + off_z + 1)\n seqlen_q = cu_seqlens_q_end - cu_seqlens_q_start\n if start_m * BLOCK_M > seqlen_q:\n return\n cu_seqlens_k_start = tl.load(cu_seqlens_k + off_z)\n cu_seqlens_k_end = tl.load(cu_seqlens_k + off_z + 1)\n seqlen_k = cu_seqlens_k_end - cu_seqlens_k_start\n else:\n cu_seqlens_q_start = 0\n cu_seqlens_k_start = 0\n seqlen_q = MAX_SEQLENS_Q\n seqlen_k = MAX_SEQLENS_K\n n_blocks = cdiv_fn(seqlen_k, BLOCK_N)\n if IS_CAUSAL:\n n_blocks_seqlen = cdiv_fn((start_m + 1) * BLOCK_M + seqlen_k -\n seqlen_q, BLOCK_N)\n n_blocks = min(n_blocks, n_blocks_seqlen)\n if n_blocks <= 0:\n o_offset = (off_z * stride_oz + cu_seqlens_q_start * stride_om +\n off_h_q * stride_oh)\n O_block_ptr = tl.make_block_ptr(base=Out + o_offset, shape=(\n seqlen_q, BLOCK_DMODEL), strides=(stride_om, stride_on),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M,\n BLOCK_DMODEL), order=(1, 0))\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=Out.type.element_ty)\n return\n GROUP_SIZE: tl.constexpr = HQ // HK\n off_h_k = off_h_q // GROUP_SIZE if GROUP_SIZE != 1 else off_h_q\n n_extra_tokens = 0\n if seqlen_k < BLOCK_N:\n n_extra_tokens = BLOCK_N - seqlen_k\n elif seqlen_k % BLOCK_N:\n n_extra_tokens = seqlen_k % BLOCK_N\n padded_head = ACTUAL_BLOCK_DMODEL != BLOCK_DMODEL\n q_offset = (off_z * stride_qz + off_h_q * stride_qh + \n cu_seqlens_q_start * stride_qm)\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(seqlen_q,\n ACTUAL_BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(\n start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(\n 1, 0))\n k_offset = (off_z * stride_kz + off_h_k * stride_kh + \n cu_seqlens_k_start * stride_kn)\n K_block_ptr = tl.make_block_ptr(base=K + k_offset, shape=(\n ACTUAL_BLOCK_DMODEL, seqlen_k), strides=(stride_kk, stride_kn),\n offsets=(0, 0), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n v_offset = (off_z * stride_vz + off_h_k * stride_vh + \n cu_seqlens_k_start * stride_vk)\n V_block_ptr = tl.make_block_ptr(base=V + v_offset, shape=(seqlen_k,\n ACTUAL_BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0\n ), block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n if BIAS_TYPE != 0:\n bias_ptr = tl.make_block_ptr(base=bias + off_h_q * stride_bh, shape\n =(seqlen_q, seqlen_k), strides=(stride_bm, stride_bn), offsets=\n (start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_N), order=(\n 1, 0))\n else:\n bias_ptr = None\n if ENABLE_DROPOUT:\n batch_philox_offset = philox_offset_base + (off_z * HQ + off_h_q\n ) * seqlen_q * seqlen_k\n else:\n batch_philox_offset = 0\n if RETURN_ENCODED_SOFTMAX:\n encoded_softmax_block_ptr = tl.make_block_ptr(base=encoded_softmax +\n off_h_q * seqlen_q * seqlen_k, shape=(seqlen_q, seqlen_k),\n strides=(seqlen_k, 1), offsets=(start_m * BLOCK_M, 0),\n block_shape=(BLOCK_M, BLOCK_N), order=(1, 0))\n else:\n encoded_softmax_block_ptr = 0\n m_i = tl.full([BLOCK_M], float('-inf'), dtype=tl.float32)\n l_i = tl.full([BLOCK_M], 1.0, dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504089\n q = load_fn(Q_block_ptr, True, padded_head, 'zero')\n q = (q * qk_scale).to(Q_block_ptr.type.element_ty)\n padded_block_k = n_extra_tokens != 0\n is_modulo_mn = not padded_block_k and seqlen_q % BLOCK_M == 0\n if IS_CAUSAL:\n masked_blocks = BLOCK_M // BLOCK_N + (not is_modulo_mn)\n else:\n masked_blocks = padded_block_k\n masked_blocks = min(masked_blocks, n_blocks)\n n_full_blocks = n_blocks - masked_blocks\n block_min = 0\n block_max = n_blocks * BLOCK_N\n if n_full_blocks > 0:\n block_max = (n_blocks - masked_blocks) * BLOCK_N\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, seqlen_k, dropout_p, philox_seed,\n batch_philox_offset, encoded_softmax_block_ptr, block_min,\n block_max, 0, 0, 0, bias_ptr, False, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, offs_m, offs_n, PRE_LOAD_V, False, ENABLE_DROPOUT,\n RETURN_ENCODED_SOFTMAX, padded_head)\n block_min = block_max\n block_max = n_blocks * BLOCK_N\n tl.debug_barrier()\n if masked_blocks > 0:\n offs_n_causal = offs_n + (seqlen_q - seqlen_k) if IS_CAUSAL else 0\n K_block_ptr = tl.advance(K_block_ptr, (0, n_full_blocks * BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (n_full_blocks * BLOCK_N, 0))\n if bias_ptr is not None:\n bias_ptr = tl.advance(bias_ptr, (0, n_full_blocks * BLOCK_N))\n if RETURN_ENCODED_SOFTMAX:\n encoded_softmax_block_ptr = tl.advance(encoded_softmax_block_ptr,\n (0, n_full_blocks))\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, seqlen_k, dropout_p, philox_seed,\n batch_philox_offset, encoded_softmax_block_ptr, block_min,\n block_max, offs_n_causal, masked_blocks, n_extra_tokens,\n bias_ptr, IS_CAUSAL, BLOCK_M, BLOCK_DMODEL, BLOCK_N, offs_m,\n offs_n, PRE_LOAD_V, True, ENABLE_DROPOUT,\n RETURN_ENCODED_SOFTMAX, padded_head)\n acc = acc / l_i[:, None]\n if ENABLE_DROPOUT:\n acc = acc / (1 - dropout_p)\n end_m_idx = (start_m + 1) * BLOCK_M\n start_m_idx = start_m * BLOCK_M\n causal_start_idx = seqlen_q - seqlen_k\n acc = acc.to(Out.type.element_ty)\n if IS_CAUSAL:\n if causal_start_idx > start_m_idx and causal_start_idx < end_m_idx:\n out_mask_boundary = tl.full((BLOCK_DMODEL,), causal_start_idx,\n dtype=tl.int32)\n mask_m_offsets = start_m_idx + tl.arange(0, BLOCK_M)\n out_ptrs_mask = mask_m_offsets[:, None] >= out_mask_boundary[\n None, :]\n z = 0.0\n acc = tl.where(out_ptrs_mask, acc, z.to(acc.type.element_ty))\n o_offset = (off_z * stride_oz + cu_seqlens_q_start * stride_om + \n off_h_q * stride_oh)\n O_block_ptr = tl.make_block_ptr(base=Out + o_offset, shape=(seqlen_q,\n ACTUAL_BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(\n start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(\n 1, 0))\n tl.store(O_block_ptr, acc, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/attention/ops/triton_flash_attention.py" }, { "uuid": "06dc48e5-e255-4b73-9331-51d5c246c0ca", "file_name": "dropout_rng.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/dropout_rng.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef debug_fill_dropout_rng(R, stride_rz, stride_rh, stride_rm, stride_rn,\n seqlen_q, seqlen_k, philox_seed, philox_offset_base, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n d_offset = off_h * stride_rh + off_z * stride_rz\n num_h = tl.num_programs(1)\n off_zh = off_z * num_h + off_h * 1\n batch_philox_offset = philox_offset_base + off_zh * seqlen_q * seqlen_k\n R_block_ptr = tl.make_block_ptr(base=R + d_offset, shape=(seqlen_q,\n seqlen_k), strides=(stride_rm, stride_rn), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_N), order=(1, 0))\n for start_n in range(0, seqlen_k, BLOCK_N):\n philox_offset = (batch_philox_offset + start_m * BLOCK_M * seqlen_k +\n start_n)\n rng = dropout_rng(philox_seed, philox_offset, BLOCK_M, BLOCK_N,\n seqlen_k)\n tl.store(R_block_ptr, rng.to(R_block_ptr.type.element_ty),\n boundary_check=(0, 1))\n R_block_ptr = tl.advance(R_block_ptr, (0, BLOCK_N))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/dropout_rng.py" }, { "uuid": "2fcb6b4b-d342-4810-8e57-787ada488273", "file_name": "mhmoe_bwd.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe_bwd.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef _mlp_wide_kernel_bwd_dx(pid_h, pid_b, x_ptr, w1_ptr, w2_ptr, o_ptr,\n dx_ptr, dw1_ptr, dw2_ptr, do_ptr, H, B, D: tl.constexpr, E, stride_xb,\n stride_xd, stride_w1d, stride_w1e, stride_w2e, stride_w2d, stride_ob,\n stride_od, stride_dxb, stride_dxd, stride_dw1d, stride_dw1e,\n stride_dw2e, stride_dw2d, stride_dob, stride_dod, BLOCK_SIZE_B: tl.\n constexpr, BLOCK_SIZE_E: tl.constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp_bwd_dx\n Z = X @ W1, H = f(Z), O = H @ W2\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n - dX has shape (B, D)\n - dW1 has shape (D, E)\n - dW2 has shape (E, D)\n - dO has shape (B, D)\n \"\"\"\n TARGET_TYPE = x_ptr.type.element_ty\n offs_b = tl.arange(0, BLOCK_SIZE_B)\n offs_d = tl.arange(0, D)\n offs_e = tl.arange(0, BLOCK_SIZE_E)\n x_ptrs = x_ptr + ((pid_h * B + pid_b * BLOCK_SIZE_B + offs_b[:, None]) *\n stride_xb + offs_d[None, :] * stride_xd)\n x_mask = (offs_b[:, None] < B - pid_b * BLOCK_SIZE_B) & (offs_d[None, :\n ] < D)\n do_ptrs = do_ptr + ((pid_h * B + pid_b * BLOCK_SIZE_B + offs_b[:, None]\n ) * stride_dob + offs_d[None, :] * stride_dod)\n do_mask = (offs_b[:, None] < B - pid_b * BLOCK_SIZE_B) & (offs_d[None,\n :] < D)\n w1_ptrs = w1_ptr + ((pid_h * D + offs_d[:, None]) * stride_w1d + offs_e\n [None, :] * stride_w1e)\n w2_ptrs = w2_ptr + ((pid_h * E + offs_e[:, None]) * stride_w2e + offs_d\n [None, :] * stride_w2d)\n dw1_ptrs = dw1_ptr + ((pid_h * D + offs_d[:, None]) * stride_dw1d + \n offs_e[None, :] * stride_dw1e)\n dw2_ptrs = dw2_ptr + ((pid_h * E + offs_e[:, None]) * stride_dw2e + \n offs_d[None, :] * stride_dw2d)\n x = tl.load(x_ptrs, mask=x_mask, other=0.0)\n do = tl.load(do_ptrs, mask=do_mask, other=0.0)\n dx = tl.zeros((BLOCK_SIZE_B, D), dtype=tl.float32)\n for e in range(0, tl.cdiv(E, BLOCK_SIZE_E)):\n w1_mask = (offs_d[:, None] < D) & (offs_e[None, :] < E - e *\n BLOCK_SIZE_E)\n w2_mask = (offs_e[:, None] < E - e * BLOCK_SIZE_E) & (offs_d[None,\n :] < D)\n w1 = tl.load(w1_ptrs, mask=w1_mask, other=0.0)\n w2 = tl.load(w2_ptrs, mask=w2_mask, other=0.0)\n z = tl.dot(x, w1, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n h = leaky_relu(z).to(TARGET_TYPE)\n else:\n h = z.to(TARGET_TYPE)\n dh = tl.dot(do, tl.trans(w2), out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n dz = (dh * d_leacky_relu_inv_backward(z)).to(TARGET_TYPE)\n else:\n dz = dh.to(TARGET_TYPE)\n dx += tl.dot(dz, tl.trans(w1), out_dtype=tl.float32)\n w1_ptrs += BLOCK_SIZE_E * stride_w1e\n w2_ptrs += BLOCK_SIZE_E * stride_w2e\n dw1_ptrs += BLOCK_SIZE_E * stride_dw1e\n dw2_ptrs += BLOCK_SIZE_E * stride_dw2e\n return dx\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe_bwd.py" }, { "uuid": "c290ae95-140d-49ca-bf58-a327ab667240", "file_name": "smem_triton_matmul.py", "repo_name": "WesKwong/gemm-example-cuda2py", "file_path": "triton_mm/smem_triton_matmul.py", "commit_hash": "901c4488a79b6d71f7a4dc15dcdfc9546b879a23", "starcount": 0, "input": "@triton.jit\ndef smem_triton_matmul(c_ptr, a_ptr, b_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_cm, stride_cn, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr):\n raw_pid_m = tl.program_id(0)\n raw_pid_n = tl.program_id(1)\n num_program_m = tl.num_programs(0)\n num_program_n = tl.num_programs(1)\n group_id = raw_pid_m // GROUP_SIZE_M\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_program_m - first_pid_m, GROUP_SIZE_M)\n linear_pid_in_group = (raw_pid_m - first_pid_m) * num_program_n + raw_pid_n\n pid_m = first_pid_m + linear_pid_in_group % group_size_m\n pid_n = linear_pid_in_group // group_size_m\n offset_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offset_bn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n offset_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offset_am[:, None] * stride_am + offset_k[None, :] *\n stride_ak)\n b_ptrs = b_ptr + (offset_k[:, None] * stride_bk + offset_bn[None, :] *\n stride_bn)\n res = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=offset_k[None, :] < K - k * BLOCK_SIZE_K,\n other=0.0)\n b = tl.load(b_ptrs, mask=offset_k[None, :] < K - k * BLOCK_SIZE_K,\n other=0.0)\n res += tl.dot(a, b, allow_tf32=False)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n c_ptrs = c_ptr + (offset_am[:, None] * stride_cm + offset_bn[None, :] *\n stride_cn)\n c_mask = (offset_am[:, None] < M) & (offset_bn[None, :] < N)\n tl.store(c_ptrs, res, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/WesKwong/gemm-example-cuda2py/blob/901c4488a79b6d71f7a4dc15dcdfc9546b879a23/triton_mm/smem_triton_matmul.py" }, { "uuid": "60cd7074-f5da-4801-bf48-534ee82c78c0", "file_name": "copy.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/copy.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@eval(\n \"\"\"triton.heuristics({\n 'BLOCK_M': lambda kwargs: min(4096, triton.next_power_of_2(kwargs['size_inp_0'])),\n 'BATCH_STRIDE_INP_IS_1': lambda kwargs: kwargs['batch_stride_inp'] == 1,\n 'STRIDE_INP_0_IS_1': lambda kwargs: kwargs['stride_inp_0'] == 1,\n 'BATCH_STRIDE_OUT_IS_1': lambda kwargs: kwargs['batch_stride_out'] == 1,\n 'STRIDE_OUT_0_IS_1': lambda kwargs: kwargs['stride_out_0'] == 1,\n})\"\"\"\n )\n@eval(\n \"\"\"triton.heuristics({\n 'num_warps': lambda kwargs: max(1, min(16, kwargs['BLOCK_M'] // 32)),\n})\"\"\"\n )\n@triton.jit\ndef copy_2d_kernel(output_ptr, input_ptr, bs, size_inp_0, batch_stride_inp,\n stride_inp_0, batch_stride_out, stride_out_0, BATCH_STRIDE_INP_IS_1: tl\n .constexpr, STRIDE_INP_0_IS_1: tl.constexpr, BATCH_STRIDE_OUT_IS_1: tl.\n constexpr, STRIDE_OUT_0_IS_1: tl.constexpr, BLOCK_M: tl.constexpr):\n pid = tl.program_id(0)\n pid_batch = tl.program_id(1)\n grid_m = tl.cdiv(size_inp_0, BLOCK_M)\n pid_m = pid\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n A = input_ptr + (1 if BATCH_STRIDE_INP_IS_1 else batch_stride_inp\n ) * pid_batch + rm * (1 if STRIDE_INP_0_IS_1 else stride_inp_0)\n B = output_ptr + (1 if BATCH_STRIDE_OUT_IS_1 else batch_stride_out\n ) * pid_batch + rm * (1 if STRIDE_OUT_0_IS_1 else stride_out_0)\n mask = rm < size_inp_0\n a = tl.load(A, mask=mask)\n tl.store(B, a, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/copy.py" }, { "uuid": "52b19649-738b-4b5d-b8bd-609bca2dcadc", "file_name": "preprocess_cumsum_gk.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/gla_triton/inter_chunk_contribution/preprocess_cumsum_gk.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef stable_log_sigmoid(x):\n max_value = tl.where(x < 0, x, 0)\n abs_value = tl.where(x > 0, x, -x)\n return max_value - tl.log(1 + tl.exp(-abs_value))\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/gla_triton/inter_chunk_contribution/preprocess_cumsum_gk.py" }, { "uuid": "1da3bedd-0ea9-4a1e-b787-49c4893f39be", "file_name": "fused_moe_a16w4.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/fused_moe_a16w4.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _fused_moe_kernel_a16w4_subchannel(A, B, C, scale_b_ptr,\n zero_points_ptr, topk_weights_ptr, sorted_token_ids_ptr, expert_ids_ptr,\n num_tokens_post_padded_ptr, N, K, EM, num_valid_tokens, stride_am,\n stride_ak, stride_be, stride_bn, stride_bk, stride_cm, stride_cn,\n stride_scale_be, stride_scale_bn, stride_scale_bk, stride_zero_points_e,\n stride_zero_points_n, stride_zero_points_k, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr, MUL_ROUTED_WEIGHT: tl.constexpr, top_k: tl.constexpr,\n add_zero_points: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(EM, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % num_pid_in_group % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n num_tokens_post_padded = tl.load(num_tokens_post_padded_ptr)\n if pid_m * BLOCK_SIZE_M >= num_tokens_post_padded:\n return\n offs_token_id = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_token = tl.load(sorted_token_ids_ptr + offs_token_id)\n token_mask = offs_token < num_valid_tokens\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N * 2) // 2) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = A + (offs_token[:, None] // top_k * stride_am + offs_k[None, :\n ] * stride_ak)\n off_experts = tl.load(expert_ids_ptr + pid_m)\n b_ptrs = B + off_experts * stride_be + (offs_k[:, None] * stride_bk + \n offs_bn[None, :] * stride_bn)\n if add_zero_points:\n offs_zp_n = (pid_n * BLOCK_SIZE_N * 2 + tl.arange(0, 2 * BLOCK_SIZE_N)\n ) % (2 * N)\n _ZERO_POINT0 = tl.zeros([1], dtype=zero_points_ptr.dtype.element_ty)\n _A0 = tl.zeros([1, 1], dtype=A.dtype.element_ty)\n _B0 = tl.zeros([1, 1], dtype=B.dtype.element_ty)\n _SCALE0 = tl.zeros([1], dtype=scale_b_ptr.dtype.element_ty)\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N * 2), dtype=tl.float32)\n l_shifter = (1 - tl.arange(0, BLOCK_SIZE_N * 2) % 2) * 4\n for k in range(tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs, mask=token_mask[:, None] & (offs_k[None, :] < K -\n k * BLOCK_SIZE_K), other=_A0)\n b = tl.load(b_ptrs, mask=offs_k[:, None] < K - k * BLOCK_SIZE_K,\n other=_B0)\n b = (b << l_shifter[None, :]).to(tl.int8).__rshift__(4)\n if add_zero_points:\n zp_ptrs = (zero_points_ptr + off_experts * stride_zero_points_e +\n offs_zp_n * stride_zero_points_n + k)\n zero_points_vals = tl.load(zp_ptrs)\n b = b - zero_points_vals[None, :]\n offs_scale_n = pid_n * BLOCK_SIZE_N * 2 + tl.arange(0, 2 * BLOCK_SIZE_N\n )\n scale_b_ptrs = (scale_b_ptr + off_experts * stride_scale_be + \n offs_scale_n * stride_scale_bn + k)\n scales_val = tl.load(scale_b_ptrs, mask=offs_scale_n < 2 * N, other\n =_SCALE0)\n b = b * scales_val[None, :]\n accumulator += tl.dot(a, b, out_dtype=tl.float32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs += BLOCK_SIZE_K * stride_bk\n if MUL_ROUTED_WEIGHT:\n moe_weight = tl.load(topk_weights_ptr + offs_token, mask=token_mask,\n other=0.0)\n accumulator = accumulator * moe_weight[:, None]\n accumulator = accumulator.to(A.dtype.element_ty)\n offs_cn = pid_n * BLOCK_SIZE_N * 2 + tl.arange(0, BLOCK_SIZE_N * 2)\n c_ptrs = C + stride_cm * offs_token[:, None] + stride_cn * offs_cn[None, :]\n c_mask = token_mask[:, None] & (offs_cn[None, :] < N * 2)\n tl.store(c_ptrs, accumulator, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Attention Mechanisms" ], "Data Type": [ "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/fused_moe_a16w4.py" }, { "uuid": "72381e7b-efbe-42ec-bcc7-02dd2d8675ed", "file_name": "y_0.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_0.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef zeroth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_0.py" }, { "uuid": "96d3e5c8-a2b2-4caf-a2d2-f0b0671b6574", "file_name": "quantize.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/quantize.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _compute_exp(group_max, rounding_mode, rand_bits, MBITS: tl.constexpr):\n \"\"\"Compute shared exponent of group using specified rounding mode.\n\n Args:\n group_max (Tensor): Group of values to compute exponent of.\n rounding_mode (int or RoundingMode): Which rounding mode to use.\n rand_bits (int): Random integer values used for stochastic rounding.\n mbits (int): Number of mantissa bits in target mx4 format.\n\n Returns:\n Tensor: Shared exponent of group.\n \"\"\"\n MBITS_FP32: tl.constexpr = 23\n M_ROUND: tl.constexpr = (1 << MBITS_FP32 - MBITS - 1) - 1\n RAND_MASK: tl.constexpr = (1 << MBITS_FP32 - MBITS) - 1\n if rounding_mode == 0:\n return tl.floor(tl.log2(group_max) + 0.5)\n if rounding_mode == 1:\n return _floor_log2(group_max)\n elif rounding_mode == 2:\n group_max = group_max.to(tl.int32, bitcast=True) + M_ROUND\n return _floor_log2(group_max)\n elif rounding_mode == 3:\n group_max = group_max.to(tl.int32, bitcast=True) + (RAND_MASK &\n rand_bits)\n return _floor_log2(group_max)\n else:\n return tl.ceil(tl.log2(group_max))\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/quantize.py" }, { "uuid": "30aea82c-19d0-417f-9cf2-abd252b59a7d", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_intra_V(q, k, z, dA, dq, dk, s_k_h, s_k_t, s_k_d,\n T: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr,\n BK: tl.constexpr, NC: tl.constexpr):\n i_k, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_t, i_i = i_c // NC, i_c % NC\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), ((i_t *\n BT + i_i * BC) * K + i_k * BK,), (BK,), (0,))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_zq = tl.exp(b_zn[None, :] - b_z)\n b_dq = tl.zeros([BC, BK], dtype=tl.float32)\n for i_j in range(0, i_i):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kz = tl.exp(b_k - b_zn[None, :]).to(b_k.dtype)\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dq += tl.dot(b_dA, b_kz, allow_tf32=False)\n b_dq *= b_zq\n o_i = tl.arange(0, BC)\n o_dA = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_i * BC\n m_dA = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n for j in range(0, BC):\n p_kj = tl.make_block_ptr(k + i_bh * s_k_h, (T * K,), (1,), ((i_t *\n BT + i_i * BC + j) * K + i_k * BK,), (BK,), (0,))\n b_dA = tl.load(dA + o_dA + j, mask=m_dA, other=0)\n b_kj = tl.load(p_kj, boundary_check=(0,)).to(tl.float32)\n m_i = o_i[:, None] >= j\n b_dq += tl.where(m_i, b_dA[:, None] * tl.exp(b_kj[None, :] - b_z), 0.0)\n p_dq = tl.make_block_ptr(dq + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.debug_barrier()\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (s_k_d,), ((i_t *\n BT + i_i * BC + BC - 1) * K + i_k * BK,), (BK,), (0,))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_kz = tl.exp(b_k - b_zn[None, :])\n b_dk = tl.zeros([BC, BK], dtype=tl.float32)\n for i_j in range(i_i + 1, NC):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_j * BC, i_i * BC), (BC, BC), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_qz = (b_q * tl.exp(b_zn[None, :] - b_z)).to(b_q.dtype)\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dk += tl.dot(tl.trans(b_dA), b_qz, allow_tf32=False)\n b_dk *= b_kz\n o_dA = i_bh * T * BT + (i_t * BT + i_i * BC) * BT + i_i * BC + tl.arange(\n 0, BC)\n for j in range(0, BC):\n p_qj = tl.make_block_ptr(q + i_bh * s_k_h, (T * K,), (1,), ((i_t *\n BT + i_i * BC + j) * K + i_k * BK,), (BK,), (0,))\n p_zj = tl.make_block_ptr(z + i_bh * s_k_h, (T * K,), (1,), ((i_t *\n BT + i_i * BC + j) * K + i_k * BK,), (BK,), (0,))\n b_dA = tl.load(dA + o_dA + j * BT, mask=i_t * BT + i_i * BC + j < T,\n other=0)\n b_qj = tl.load(p_qj, boundary_check=(0,)).to(tl.float32)\n b_zj = tl.load(p_zj, boundary_check=(0,)).to(tl.float32)\n m_i = o_i[:, None] <= j\n b_dk += tl.where(m_i, b_dA[:, None] * b_qj[None, :] * tl.exp(b_k -\n b_zj[None, :]), 0.0)\n p_dk = tl.make_block_ptr(dk + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "0e7cd672-1e72-48ba-b85f-b3d9b3529a63", "file_name": "rtn_kernel.py", "repo_name": "ArthurinRUC/libquant", "file_path": "libquant/triton/rtn_kernel.py", "commit_hash": "f2a42a78a96e867862d24d931b70500332ece5cb", "starcount": 0, "input": "@triton.jit\ndef quant_rtn_triton(mat: tl.tensor, scale: tl.tensor, zero_point: tl.\n tensor, quant_dim: int, nbits: int, per_channel: bool, per_tensor: bool,\n use_zero_point: bool, group_size: int, scale_dtype: tl.dtype,\n zero_dtype: tl.dtype, quant_dtype: tl.dtype, device: tl.dtype) ->tl.Tuple[\n tl.tensor, tl.tensor]:\n origin_shape = mat.shape\n if group_size is None:\n group_size = origin_shape[-1]\n mat = mat.reshape(-1, group_size)\n if use_zero_point:\n qmin, qmax = 0, 2 ** nbits - 1\n xmin, xmax = tl.min(mat, axis=quant_dim), tl.max(mat, axis=quant_dim)\n scale = (xmax - xmin).div(qmax).clamp(min=1e-05).to(scale_dtype).to(\n device)\n zero_point = (-xmin / scale).to(zero_dtype).to(device)\n if not per_channel and not per_tensor:\n scale = scale.unsqueeze(1)\n zero_point = zero_point.unsqueeze(1)\n x = mat.div(scale).add(zero_point).round().clamp(qmin, qmax).to(\n quant_dtype).to(device)\n else:\n qmin, qmax = -2 ** (nbits - 1), 2 ** (nbits - 1) - 1\n xabsmax = tl.max(tl.abs(mat), axis=quant_dim)\n scale = xabsmax.div(qmax).clamp(min=1e-05).to(scale_dtype).to(device)\n if not per_channel and not per_tensor:\n scale = scale.unsqueeze(1)\n x = mat.div(scale).round().clamp(qmin, qmax).to(quant_dtype).to(device)\n return x.reshape(origin_shape), scale\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ArthurinRUC/libquant/blob/f2a42a78a96e867862d24d931b70500332ece5cb/libquant/triton/rtn_kernel.py" }, { "uuid": "d19a6587-227e-47d3-82af-4397af3e33c3", "file_name": "glu_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/glu_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=element_wise_kernel_configs(), key=['size'])\n@triton.jit\ndef glu_backward_kernel(output_grad_pointer, input1_pointer, input2_pointer,\n input1_grad_pointer, input2_grad_pointer, size, param, act_func: tl.\n constexpr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n Calculates the input gradient of the gated linear unit.\n\n Args:\n output_grad_pointer: Pointer to the unit's output gradients.\n The output gradients must be contiguous and contain size elements.\n input1_pointer: Pointer to the first half of the input that was gated.\n The first half must be contiguous and contain size elements.\n input2_pointer: Pointer to the second half of the input that was gated.\n The second half must be contiguous and contain size elements.\n input1_grad_pointer: Pointer to a container the first half's gradients are written to.\n The container must be contiguous and contain size elements.\n input2_grad_pointer: Pointer to a container the second half's gradients are written to.\n The container must be contiguous and contain size elements.\n size: Number of elements in each half of the input.\n param: Parameter in the case of parameterized activation functions.\n act_func: Name of activation function to apply.\n Options are 'sigmoid', 'tanh', 'relu', 'gelu', 'silu',\n 'relu6', 'hardsigmoid', 'hardswish', 'selu', 'mish', and 'leaky_relu'.\n BLOCK_SIZE: Block size.\n \"\"\"\n pid = tl.program_id(axis=0)\n offset = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offset < size\n output_grad = tl.load(output_grad_pointer + offset, mask=mask)\n input1 = tl.load(input1_pointer + offset, mask=mask)\n input2 = tl.load(input2_pointer + offset, mask=mask)\n input1_grad = output_grad * apply_act_func(input2, None, None, None,\n param, act_func, False)\n input2_grad = output_grad * input1 * apply_act_func_grad(1, input2,\n None, None, None, param, act_func, False)\n tl.store(input1_grad_pointer + offset, input1_grad, mask=mask)\n tl.store(input2_grad_pointer + offset, input2_grad, mask=mask)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/glu_kernels.py" }, { "uuid": "14d6b032-07e3-479f-afba-018a5bb6e96f", "file_name": "modulation.py", "repo_name": "ai-compiler-study/triton-kernels", "file_path": "triton_kernels/ops/modulation.py", "commit_hash": "2308e5e9d965059fe2d19b4d535debac4970b69e", "starcount": 0, "input": "@triton.jit\ndef triton_modulation_scale_shift(x_ptr, modulation_ptr, output_ptr,\n batch_size, head_size, modulation_size, is_mod1, XBLOCK: tl.constexpr):\n pid = tl.program_id(0)\n xoffset = pid * XBLOCK + tl.arange(0, XBLOCK)[:]\n batch_idx = xoffset // batch_size\n head_dim_idx = xoffset % head_size\n modulation_offset = head_dim_idx + modulation_size * batch_idx\n x = tl.load(x_ptr + xoffset, None)\n if is_mod1:\n shift = tl.load(modulation_ptr + (modulation_offset + head_size * 0\n ), None, eviction_policy='evict_last')\n scale = tl.load(modulation_ptr + (modulation_offset + head_size * 1\n ), None, eviction_policy='evict_last')\n else:\n shift = tl.load(modulation_ptr + (modulation_offset + head_size * 3\n ), None, eviction_policy='evict_last')\n scale = tl.load(modulation_ptr + (modulation_offset + head_size * 4\n ), None, eviction_policy='evict_last')\n output = (scale + 1.0) * x + shift\n tl.store(output_ptr + xoffset, output, None)\n", "category": { "Functionality": [ "Elementwise Operations", "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ai-compiler-study/triton-kernels/blob/2308e5e9d965059fe2d19b4d535debac4970b69e/triton_kernels/ops/modulation.py" }, { "uuid": "f5fa9512-df93-43c8-be9e-b332055b0317", "file_name": "sampling.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/sampling.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef _logsumexp(X, OUT, xm_stride, xn_stride, out_stride, N, BLOCK_N: tl.\n constexpr):\n rm = tl.program_id(0)\n alpha = tl.zeros((1,), tl.float32) + -float('inf')\n res = tl.zeros((1,), tl.float32)\n for bn in range(0, N, BLOCK_N):\n rn = bn + tl.arange(0, BLOCK_N)\n Xmn = X + rm * xm_stride + rn * xn_stride\n x = tl.load(Xmn, mask=rn < N, other=-float('inf'))\n c = tl.max(x, axis=0)\n res = tl.where(c > alpha, res * tl.exp(alpha - c), res)\n alpha = tl.where(c > alpha, c, alpha)\n res += tl.sum(tl.exp(x - alpha), axis=0)\n out = tl.log(res) + alpha\n rm = tl.program_id(0) + tl.arange(0, 1)\n OUT = OUT + rm * out_stride\n tl.store(OUT, out)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/sampling.py" }, { "uuid": "c95d09f9-2474-4dce-8b77-528236596854", "file_name": "softmax.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/softmax.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_backward(grad_out_ptr, probs_ptr, grad_in_ptr,\n grad_stride, probs_stride, out_stride, seq_len, BLOCK_SIZE: tl.\n constexpr, num_warps: tl.constexpr):\n batch_idx = tl.program_id(0)\n probs_start_ptr = probs_ptr + batch_idx * probs_stride\n grad_start_ptr = grad_in_ptr + batch_idx * grad_stride\n pos_offsets = tl.arange(0, BLOCK_SIZE)\n probs_ptrs = probs_start_ptr + pos_offsets\n grad_ptrs = grad_start_ptr + pos_offsets\n valid_mask = pos_offsets < seq_len\n probs_vals = tl.load(probs_ptrs, mask=valid_mask, other=0.0)\n grad_vals = tl.load(grad_ptrs, mask=valid_mask, other=0.0)\n grad_times_probs = probs_vals * grad_vals\n final_grad = grad_times_probs - probs_vals * tl.sum(grad_times_probs,\n axis=0)\n out_start_ptr = grad_out_ptr + batch_idx * out_stride\n out_ptrs = out_start_ptr + pos_offsets\n tl.store(out_ptrs, final_grad, mask=valid_mask)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/softmax.py" }, { "uuid": "3f008594-2d5f-43ff-9467-54adf244ea10", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/hgrn/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_hgrn_bwd_kernel_o(g, gc, o, dx, dg, s_b, s_t, s_d, T: tl.\n constexpr, D: tl.constexpr, BT: tl.constexpr, BD: tl.constexpr):\n i_d, i_b = tl.program_id(0), tl.program_id(1)\n o_d = i_d * BD + tl.arange(0, BD)\n mask = o_d < D\n for i_t in range(tl.cdiv(T, BT) - 1, -1, -1):\n p_g = tl.make_block_ptr(g + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT, i_d * BD), (BT, BD), (1, 0))\n p_gc = tl.make_block_ptr(gc + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT, i_d * BD), (BT, BD), (1, 0))\n p_o = tl.make_block_ptr(o + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT - 1, i_d * BD), (BT, BD), (1, 0))\n p_dx = tl.make_block_ptr(dx + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT, i_d * BD), (BT, BD), (1, 0))\n p_dg = tl.make_block_ptr(dg + i_b * s_b, (T, D), (s_t, s_d), (i_t *\n BT, i_d * BD), (BT, BD), (1, 0))\n mask_t = mask & ((i_t + 1) * BT < T)\n b_ht = tl.load(dx + i_b * T * D + (i_t + 1) * BT * D + o_d, mask=\n mask_t, other=0).to(tl.float32)\n b_g = tl.load(p_g, boundary_check=(0, 1)).to(tl.float32)\n b_gc = tl.load(p_gc, boundary_check=(0, 1)).to(tl.float32)\n b_o = tl.load(p_o, boundary_check=(0, 1)).to(tl.float32)\n b_dx = tl.load(p_dx, boundary_check=(0, 1)).to(tl.float32)\n b_dx = b_dx + tl.exp(b_gc) * b_ht[None, :]\n b_dg = b_o * b_dx * tl.exp(b_g)\n tl.store(p_dx, b_dx.to(p_dx.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/hgrn/chunk.py" }, { "uuid": "943d5d1b-75b2-49d6-8775-f5cd28ee9e60", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BT': 16}, num_warps=2), triton.\n Config({'BT': 32}, num_warps=4), triton.Config({'BT': 32}, num_warps=2),\n triton.Config({'BT': 64}, num_warps=8), triton.Config({'BT': 64},\n num_warps=4)], key=[])\n@triton.jit\ndef chunk_global_cumsum_scalar_kernel(s, o, offsets, T: tl.constexpr, H: tl\n .constexpr, BT: tl.constexpr, HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl\n .constexpr):\n i_bh = tl.program_id(0)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_b).to(tl.int32), tl.load(offsets +\n i_b + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n b_z = tl.zeros([], dtype=tl.float32)\n for i_t in range(tl.cdiv(T, BT)):\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_o = tl.make_block_ptr(o + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n else:\n p_s = tl.make_block_ptr(s + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_o = tl.make_block_ptr(o + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n b_s = tl.load(p_s, boundary_check=(0,)).to(tl.float32)\n b_o = tl.cumsum(b_s, axis=0) + b_z[None]\n b_z += tl.sum(b_s, axis=0)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "d4e4674a-0ac2-49d8-bf16-e5324188a47b", "file_name": "triton_ops.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/triton_ops.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _soft_threshold24_triton(dense_ptr, sparse_ptr, mask_ptr,\n dense_row_stride, sparse_row_stride, mask_row_stride, dense_col_stride,\n sparse_col_stride, mask_col_stride, m, k, BLOCK_SIZE: tl.constexpr,\n ARRAY_LAYOUT: tl.constexpr):\n if ARRAY_LAYOUT == 'row':\n row_idx = tl.program_id(0)\n col_idx = tl.program_id(1) * 4 * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE\n ) * 4\n mask = col_idx < k\n elif ARRAY_LAYOUT == 'col':\n row_idx = tl.arange(0, BLOCK_SIZE) + tl.program_id(0) * BLOCK_SIZE\n col_idx = tl.program_id(1) * 4\n mask = row_idx < m\n dense_40 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 0) * dense_col_stride, mask=mask)\n dense_41 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 1) * dense_col_stride, mask=mask)\n dense_42 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 2) * dense_col_stride, mask=mask)\n dense_43 = tl.load(dense_ptr + row_idx * dense_row_stride + (col_idx + \n 3) * dense_col_stride, mask=mask)\n dense_40, dense_41, dense_42, dense_43, m0, m1, m2, m3 = _soft_threshold(\n dense_40, dense_41, dense_42, dense_43)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 0) *\n sparse_col_stride, dense_40, mask=mask & m0)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 1) *\n sparse_col_stride, dense_41, mask=mask & m1)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 2) *\n sparse_col_stride, dense_42, mask=mask & m2)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + (col_idx + 3) *\n sparse_col_stride, dense_43, mask=mask & m3)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 0) *\n mask_col_stride, m0, mask=mask & m0)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 1) *\n mask_col_stride, m1, mask=mask & m1)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 2) *\n mask_col_stride, m2, mask=mask & m2)\n tl.store(mask_ptr + row_idx * mask_row_stride + (col_idx + 3) *\n mask_col_stride, m3, mask=mask & m3)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/triton_ops.py" }, { "uuid": "05304651-6ea3-4b33-a724-8242f59e5ec0", "file_name": "mamba_ssm.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/model_executor/layers/mamba/ops/mamba_ssm.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.jit\ndef softplus(dt):\n dt = tl.where(dt <= 20.0, tl.math.log1p(tl.exp(dt)), dt)\n return dt\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/model_executor/layers/mamba/ops/mamba_ssm.py" }, { "uuid": "a24a6db0-d013-472f-aa2f-4b7f7c770497", "file_name": "causal_product_bwd.py", "repo_name": "calclavia/Triton-Transformer", "file_path": "ttx/attention/causal_product_bwd.py", "commit_hash": "d1d1e5b5651cf7959866b0198d90a665e1f45354", "starcount": 0, "input": "@triton.jit\ndef causal_product_bwd_kernel(q_ptr, k_ptr, v_ptr, grad_out, grad_Q_ptr,\n grad_K_ptr, grad_V_ptr, batch, length, dim, vdim, **meta):\n BLOCK_SIZE = meta['BLOCK_SIZE']\n pid = tl.program_id(axis=0)\n state = tl.zeros((BLOCK_SIZE, BLOCK_SIZE), dtype=tl.float32)\n cur_qk_pos = pid * matrix_size * dim\n cur_v_pos = pid * matrix_size * vdim\n dim_ptrs = tl.arange(0, BLOCK_SIZE)\n qkmask = dim_ptrs < dim\n vmask = dim_ptrs < vdim\n for _ in range(0, length, 1):\n qk_row_offsets = cur_qk_pos + dim_ptrs\n v_row_offsets = cur_v_pos + dim_ptrs\n k = tl.load(k_ptr + qk_row_offsets, mask=qkmask, other=0)\n v = tl.load(v_ptr + v_row_offsets, mask=vmask, other=0)\n context = tl.dot(k[:, None], v[None, :])\n state += context\n g = tl.load(grad_out + v_row_offsets, mask=vmask, other=0)\n grad_q = tl.dot(state, g[:, None])\n tl.store(grad_Q_ptr + qk_row_offsets[:, None], grad_q, mask=qkmask[\n :, None])\n cur_qk_pos += dim\n cur_v_pos += vdim\n \"\"\"\n state *= 0\n\n for _ in range(0, length, 1):\n # Move back one row\n cur_pos -= dim\n\n # Offset for a single row in Q, K, V\n row_offsets = cur_pos + dim_ptrs\n\n # Load the current row of Q, K, V vectors. All are vectors of shape [dim]\n q = tl.load(q_ptr + row_offsets, mask=mask, other=0)\n k = tl.load(k_ptr + row_offsets, mask=mask, other=0)\n v = tl.load(v_ptr + row_offsets, mask=vmask, other=0)\n # Load gradient\n g = tl.load(grad_out + row_offsets, mask=vmask, other=0)\n # Compute context [D, M] matrix from [D, 1] x [1, M]\n context = tl.dot(q[:, None], g[None, :])\n # state += context\n\n # Compute gradients [1, D] x [D, M] => [1, M]\n grad_v = tl.dot(k[None, :], context)\n grad_v = tl.reshape(grad_v, (meta['BLOCK_SIZE'],))\n # grad_v = tl.dot(k[None, :], state)\n\n # Enabling the follownig leads to a hang\n\n # grad_k = tl.dot(state, v[:, None])\n # print(grad_v.shape)\n # print(grad_k.shape)\n # Store the result of this row\n # tl.store(grad_V_ptr + row_offsets[None,\n # :], grad_v, mask=vmask[None, :])\n tl.store(grad_V_ptr + row_offsets, grad_v, mask=vmask)\n # tl.store(grad_K_ptr + row_offsets[:, None], grad_k, mask=mask[:, None])\n \"\"\"\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/calclavia/Triton-Transformer/blob/d1d1e5b5651cf7959866b0198d90a665e1f45354/ttx/attention/causal_product_bwd.py" }, { "uuid": "e1a91636-50d2-4089-a5a6-18102bcab37e", "file_name": "k_layer_norm.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_layer_norm.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_fw(X, Y, W, B, M, V, stride, N, eps, **META):\n \"\"\"\n Fused layernorm kernel over a 3d tensor.\n The layer norm is applied over the last dimension.\n\n Compute\n y = (x - E(x))/(sqrt(var(x) + epsilon)) * gamma + beta\n \"\"\"\n y = _layer_norm_non_affine(X, M, V, stride, N, eps, META)\n y = _affine(W, B, N, y, META)\n _store(y, Y, stride, N, META)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_layer_norm.py" }, { "uuid": "9bdd2ff5-9f28-4614-bdb9-b519f0ff99ea", "file_name": "paged_attn_v1.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/paged_attn_v1.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _single_query_cached_kv_attention_v1(out, q, k_cache, v_cache,\n head_mapping, scale, block_tables, seq_lens, max_num_blocks_per_seq,\n stride_qm, stride_qn, stride_om, stride_on, stride_km, stride_kn,\n stride_kk, SLOT_SIZE: tl.constexpr, HEAD_SIZE: tl.constexpr):\n head_idx = tl.program_id(axis=0)\n token_idx = tl.program_id(axis=1)\n kv_head_idx = tl.load(head_mapping + head_idx)\n offs_q = token_idx * stride_qm + head_idx * stride_qn + tl.arange(0,\n HEAD_SIZE)\n q = tl.load(q + offs_q)\n q = (q * scale).to(tl.float16)\n seq_len = tl.load(seq_lens + token_idx)\n qkv = tl.zeros([SLOT_SIZE, HEAD_SIZE], dtype=tl.float32)\n m_prev = tl.zeros([1, 1], tl.float32) - float('inf')\n d_prev = tl.zeros([1, 1], tl.float32)\n slot_offs = tl.arange(0, SLOT_SIZE)\n head_size_offs = tl.arange(0, HEAD_SIZE)\n block_base_ptrs = block_tables + token_idx * max_num_blocks_per_seq\n kv_base_offs = kv_head_idx * stride_kn + slot_offs[:, None\n ] * stride_kk + head_size_offs[None, :]\n for i in range(0, tl.cdiv(seq_len, SLOT_SIZE)):\n block_idx = tl.load(block_base_ptrs + i)\n mask = (slot_offs[:, None] < seq_len - i * SLOT_SIZE) & (head_size_offs\n [None, :] < HEAD_SIZE)\n kv_offs = block_idx * stride_km + kv_base_offs\n k = tl.load(k_cache + kv_offs, mask=mask, other=0.0)\n v = tl.load(v_cache + kv_offs, mask=mask, other=0.0)\n x_i = tl.sum(q[None, :] * k, axis=1)[:, None]\n x_i = tl.where(slot_offs[:, None] < seq_len - i * SLOT_SIZE, x_i,\n float('-inf'))\n m_i = tl.maximum(m_prev, tl.max(x_i, axis=0))\n d_i = d_prev * tl.exp(m_prev - m_i) + tl.sum(tl.exp(x_i - m_i), axis=0)\n qkv = qkv * (d_prev * tl.exp(m_prev - m_i) / d_i) + tl.exp(x_i - m_i\n ) / d_i * v\n m_prev = m_i\n d_prev = d_i\n offs_q = token_idx * stride_om + head_idx * stride_on + tl.arange(0,\n HEAD_SIZE)\n tl.store(out + offs_q, tl.sum(qkv, axis=0))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/paged_attn_v1.py" }, { "uuid": "2bb44c20-7403-4987-8920-de61d4b20097", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_second_order_bwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, g_x_ptr: tl.tensor, g_y_ptr: tl.tensor, g_z_ptr: tl.tensor,\n g_1_0_ptr: tl.tensor, g_1_1_ptr: tl.tensor, g_1_2_ptr: tl.tensor,\n g_2_0_ptr: tl.tensor, g_2_1_ptr: tl.tensor, g_2_2_ptr: tl.tensor,\n g_2_3_ptr: tl.tensor, g_2_4_ptr: tl.tensor, BLOCK_SIZE: tl.constexpr,\n vector_length: tl.constexpr):\n sqrt_3 = 3 ** 0.5\n sqrt_5 = 5 ** 0.5\n sqrt_15 = 15 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n g_1_0 = tl.load(g_1_0_ptr + offset, mask=offset < vector_length)\n g_1_1 = tl.load(g_1_1_ptr + offset, mask=offset < vector_length)\n g_1_2 = tl.load(g_1_2_ptr + offset, mask=offset < vector_length)\n g_x = sqrt_3 * g_1_0\n g_y = sqrt_3 * g_1_1\n g_z = sqrt_3 * g_1_2\n g_2_0 = tl.load(g_2_0_ptr + offset, mask=offset < vector_length)\n g_2_1 = tl.load(g_2_1_ptr + offset, mask=offset < vector_length)\n g_2_2 = tl.load(g_2_2_ptr + offset, mask=offset < vector_length)\n g_2_3 = tl.load(g_2_3_ptr + offset, mask=offset < vector_length)\n g_2_4 = tl.load(g_2_4_ptr + offset, mask=offset < vector_length)\n g_x += sqrt_15 * z * g_2_0\n g_z += sqrt_15 * x * g_2_0\n g_x += sqrt_15 * y * g_2_1\n g_y += sqrt_15 * x * g_2_1\n g_y += sqrt_15 * z * g_2_2\n g_z += sqrt_15 * y * g_2_2\n g_x += -1.0 * sqrt_5 * x * g_2_3\n g_y += 2.0 * sqrt_5 * y * g_2_3\n g_z += -1.0 * sqrt_5 * z * g_2_3\n g_x += -1.0 * sqrt_15 * x * g_2_4\n g_z += sqrt_15 * z * g_2_4\n tl.store(g_x_ptr + offset, g_x, mask=offset < vector_length)\n tl.store(g_y_ptr + offset, g_y, mask=offset < vector_length)\n tl.store(g_z_ptr + offset, g_z, mask=offset < vector_length)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "cc1b6b08-4b84-41f0-8801-561eb1ccdb1d", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_mean/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES_RAGGED, BLOCK_SIZES_M, NUM_WARPS,\n NUM_STAGES)], key=['M'])\n@triton.jit\ndef triton_jagged_mean_kernel_variable_length_loop_buffer_then_sum(\n input_ptr_values, input_ptr_offsets, output_ptr, M, BLOCK_SIZE_RAGGED:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_ragged = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_ragged\n ), tl.load(input_ptr_offsets + (pid_ragged + 1))\n ragged_len = ragged_end - ragged_start\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n buffer += tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer_sum = tl.sum(buffer, axis=0)\n buffer_view = buffer_sum.reshape((BLOCK_SIZE_M,))\n buffer_view_mean = buffer_view * (1 / ragged_len)\n output_offsets = offsets_m + pid_ragged * M\n output_mask = output_offsets < M * (pid_ragged + 1)\n tl.store(output_ptr + output_offsets, buffer_view_mean, mask=output_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_mean/kernels.py" }, { "uuid": "c2c30b99-5b11-48aa-a966-7d545ba2a465", "file_name": "cvmm.py", "repo_name": "dtadpole/nanoGPT_lightning", "file_path": "cvmm.py", "commit_hash": "5db66f7714a9a40191f4f208ecbb650ad8c93cc6", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N':\n 64, 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 64}, num_stages=\n 4, num_warps=4), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 32}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 4}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 64}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 32}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 8}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 8}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 8}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 16}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 16}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 64}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 64}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 32, 'BLOCK_SIZE_N': 64,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 32}, num_stages=4,\n num_warps=4), triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 32,\n 'BLOCK_SIZE_K': 16, 'GROUP_SIZE_M': 8, 'K_BLOCKS': 32}, num_stages=4,\n num_warps=4)], key=['M', 'N', 'K', 'float32_out', 'allow_tf32',\n 'op_float16'], reset_to_zero=['c_ptr'])\n@triton.jit\ndef cvmm_backward_kernel3(a_ptr, b_ptr, c_ptr, index_ptr, sel_ptr,\n out_index_ptr, M, N, K, stride_am, stride_ak, stride_bk, stride_bn,\n stride_co, stride_cm, stride_cn, stride_index, stride_sel,\n stride_out_index, out_index_is_none: tl.constexpr, float32_out: tl.\n constexpr, allow_tf32: tl.constexpr, op_float16: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr, K_BLOCKS: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (M, K), B has shape (K, N) and C has shape (M, N)\n \"\"\"\n pid = tl.program_id(axis=0)\n k_block_id = tl.program_id(axis=1)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n a_ptrs_this = a_ptr + offs_am[:, None] * stride_am\n b_ptrs_this = b_ptr + offs_bn[None, :] * stride_bn\n block_start_index = k_block_id * BLOCK_SIZE_K * K_BLOCKS\n block_end_index = min(block_start_index + BLOCK_SIZE_K * K_BLOCKS, K) - 1\n first_mat = tl.load(sel_ptr + stride_sel * block_start_index)\n last_mat = tl.load(sel_ptr + stride_sel * block_end_index)\n for matrix_index in range(first_mat, last_mat + 1):\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n start_i = block_start_index\n end_i = block_end_index + 1\n while start_i < end_i:\n middle = (start_i + end_i) // 2\n middle_matrix = tl.load(sel_ptr + middle * stride_sel)\n if middle_matrix < matrix_index:\n start_i = middle + 1\n else:\n end_i = middle\n start_i2 = start_i\n end_i = block_end_index + 1\n while start_i2 < end_i:\n middle = (start_i2 + end_i) // 2\n middle_matrix = tl.load(sel_ptr + middle * stride_sel)\n if middle_matrix <= matrix_index:\n start_i2 = middle + 1\n else:\n end_i = middle\n end_i = start_i2\n count = end_i - start_i\n block_mem_indices_f_base = start_i + tl.arange(0, BLOCK_SIZE_K)\n if count > 0:\n for k in range((count + BLOCK_SIZE_K - 1) // BLOCK_SIZE_K):\n block_mem_indices_f = (block_mem_indices_f_base + k *\n BLOCK_SIZE_K)\n block_mem_indices = block_mem_indices_f % K\n a_index = tl.load(index_ptr + stride_index * block_mem_indices)\n if out_index_is_none:\n b_index = a_index\n else:\n b_index = tl.load(out_index_ptr + stride_out_index *\n block_mem_indices)\n sel_ok = block_mem_indices_f < end_i\n a_ptrs = a_ptrs_this + a_index[None, :] * stride_ak\n b_ptrs = b_ptrs_this + b_index[:, None] * stride_bk\n a = tl.load(a_ptrs, mask=sel_ok[None, :], other=0.0)\n b = tl.load(b_ptrs, mask=sel_ok[:, None], other=0.0)\n if op_float16:\n a = a.to(tl.float16)\n b = b.to(tl.float16)\n accumulator += tl.dot(a, b, allow_tf32=allow_tf32)\n if float32_out:\n c = accumulator\n else:\n c = accumulator.to(tl.float16)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + stride_co * matrix_index + stride_cm * offs_cm[\n :, None] + stride_cn * offs_cn[None, :]\n c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)\n tl.atomic_add(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp16" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/nanoGPT_lightning/blob/5db66f7714a9a40191f4f208ecbb650ad8c93cc6/cvmm.py" }, { "uuid": "fbb2a0d9-7c7c-42af-8046-40b931ce9c09", "file_name": "flash_triton.py", "repo_name": "MayDomine/Burst-Attention", "file_path": "burst_attn/flash_triton.py", "commit_hash": "b088c554072935074ea9c643de5ee363be5ab1f6", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128,\n 'SEQUENCE_PARALLEL': False}, num_warps=8, num_stages=1, pre_hook=\n init_to_zero('DQ')), triton.Config({'BLOCK_M': 128, 'BLOCK_N': 128,\n 'SEQUENCE_PARALLEL': True}, num_warps=8, num_stages=1, pre_hook=\n init_to_zero('DQ'))], key=['CACHE_KEY_SEQLEN_Q', 'CACHE_KEY_SEQLEN_K',\n 'BIAS_TYPE', 'IS_CAUSAL', 'BLOCK_HEADDIM'])\n@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0, 'EVEN_HEADDIM': lambda args: args['headdim'] == args[\n 'BLOCK_HEADDIM']})\n@triton.jit\ndef _bwd_kernel(Q, K, V, Bias, DO, DQ, DK, DV, LSE, D, softmax_scale,\n stride_qb, stride_qh, stride_qm, stride_kb, stride_kh, stride_kn,\n stride_vb, stride_vh, stride_vn, stride_bb, stride_bh, stride_bm,\n stride_dob, stride_doh, stride_dom, stride_dqb, stride_dqh, stride_dqm,\n stride_dkb, stride_dkh, stride_dkn, stride_dvb, stride_dvh, stride_dvn,\n nheads, seqlen_q, seqlen_k, seqlen_q_rounded, headdim,\n CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, BIAS_TYPE: tl.constexpr,\n IS_CAUSAL: tl.constexpr, BLOCK_HEADDIM: tl.constexpr, SEQUENCE_PARALLEL:\n tl.constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr, EVEN_HEADDIM:\n tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n Q += off_b * stride_qb + off_h * stride_qh\n K += off_b * stride_kb + off_h * stride_kh\n V += off_b * stride_vb + off_h * stride_vh\n DO += off_b * stride_dob + off_h * stride_doh\n DQ += off_b * stride_dqb + off_h * stride_dqh\n DK += off_b * stride_dkb + off_h * stride_dkh\n DV += off_b * stride_dvb + off_h * stride_dvh\n if BIAS_TYPE != 'none':\n Bias += off_b * stride_bb + off_h * stride_bh\n D += off_hb * seqlen_q_rounded\n LSE += off_hb * seqlen_q_rounded\n if not SEQUENCE_PARALLEL:\n num_block_n = tl.cdiv(seqlen_k, BLOCK_N)\n for start_n in range(0, num_block_n):\n _bwd_kernel_one_col_block(start_n, Q, K, V, Bias, DO, DQ, DK,\n DV, LSE, D, softmax_scale, stride_qm, stride_kn, stride_vn,\n stride_bm, stride_dom, stride_dqm, stride_dkn, stride_dvn,\n seqlen_q, seqlen_k, headdim, ATOMIC_ADD=False, BIAS_TYPE=\n BIAS_TYPE, IS_CAUSAL=IS_CAUSAL, BLOCK_HEADDIM=BLOCK_HEADDIM,\n EVEN_M=EVEN_M, EVEN_N=EVEN_N, EVEN_HEADDIM=EVEN_HEADDIM,\n BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N)\n else:\n start_n = tl.program_id(0)\n _bwd_kernel_one_col_block(start_n, Q, K, V, Bias, DO, DQ, DK, DV,\n LSE, D, softmax_scale, stride_qm, stride_kn, stride_vn,\n stride_bm, stride_dom, stride_dqm, stride_dkn, stride_dvn,\n seqlen_q, seqlen_k, headdim, ATOMIC_ADD=True, BIAS_TYPE=\n BIAS_TYPE, IS_CAUSAL=IS_CAUSAL, BLOCK_HEADDIM=BLOCK_HEADDIM,\n EVEN_M=EVEN_M, EVEN_N=EVEN_N, EVEN_HEADDIM=EVEN_HEADDIM,\n BLOCK_M=BLOCK_M, BLOCK_N=BLOCK_N)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp16" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Tiled", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MayDomine/Burst-Attention/blob/b088c554072935074ea9c643de5ee363be5ab1f6/burst_attn/flash_triton.py" }, { "uuid": "cbbfcf20-c932-4670-846d-fb6982e7b184", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK, BV in [(32, 64), (64, 32), (\n 64, 64), (64, 128), (128, 64)] for num_warps in [1, 2, 4] for\n num_stages in [2, 3, 4]], key=['BT'])\n@triton.jit\ndef chunk_delta_rule_fwd_kernel_prepare_dv(q, k, do, dv, offsets, indices,\n scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_k.dtype)\n b_A += tl.dot(b_k, b_q, allow_tf32=False)\n b_A = tl.where(tl.arange(0, BT)[:, None] <= tl.arange(0, BT)[None, :],\n b_A, 0).to(do.dtype.element_ty)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_dv = tl.dot(b_A, b_do, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/chunk.py" }, { "uuid": "a3bb1f0d-12d4-4f1f-af81-35201c7a5bc1", "file_name": "gemm_streamk_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef linear_tile(tile_id, M: tl.constexpr, N: tl.constexpr, K: tl.constexpr,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n pid_m = tile_id // tl.cdiv(N, BLOCK_SIZE_N)\n pid_n = tile_id % tl.cdiv(N, BLOCK_SIZE_N)\n return pid_m, pid_n\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py" }, { "uuid": "f1703945-6176-40cb-8eaf-73d5f402dbbb", "file_name": "sb_varlen_fwd.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/sb_varlen_fwd.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.jit\ndef _forward_one_row(seq_block_id, seq_length, qk_scale, M_range, N_range,\n D_range, D_mask, cm, Q_head_seq_ptr, stride_qm, stride_qd: tl.constexpr,\n K_head_seq_ptr, stride_kn, stride_kd: tl.constexpr, V_head_seq_ptr,\n stride_vn, stride_vd: tl.constexpr, O_head_seq_ptr, stride_om,\n stride_od: tl.constexpr, R_head_seq_ptr, stride_rm, A_head_seq_ptr,\n stride_am, W_head_seq_ptr, stride_wm, stride_wn, BLOCK_D: tl.constexpr,\n NO_D_MASK: tl.constexpr, NO_M_MASK: tl.constexpr, NO_N_MASK: tl.\n constexpr, ALLOW_TF32: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl\n .constexpr, no_grad: tl.constexpr=False, acc_dtype: tl.constexpr=tl.\n float32, return_attention: tl.constexpr=False, is_compiling: tl.\n constexpr=False, use_cumsum: tl.constexpr=False, attend_current: tl.\n constexpr=False):\n block_start_offset = BLOCK_M * seq_block_id\n M_blk_idxs = block_start_offset + M_range\n M_mask = M_blk_idxs < seq_length\n NO_M_MASK = block_start_offset + BLOCK_M - 1 < seq_length\n N_blk_idxs_start = block_start_offset + BLOCK_M\n N_blk_idxs = N_blk_idxs_start + N_range\n Q_blk_ptrs = Q_head_seq_ptr + (stride_qm * M_blk_idxs[:, None] + \n stride_qd * D_range[None, :])\n K_blk_ptrs = K_head_seq_ptr + (stride_kn * N_blk_idxs[:, None] + \n stride_kd * D_range[None, :])\n V_blk_ptrs = V_head_seq_ptr + (stride_vn * N_blk_idxs[:, None] + \n stride_vd * D_range[None, :])\n O_blk_ptrs = O_head_seq_ptr + (stride_om * M_blk_idxs[:, None] + \n stride_od * D_range[None, :])\n R_blk_ptrs = R_head_seq_ptr + stride_rm * M_blk_idxs\n A_blk_ptrs = A_head_seq_ptr + stride_am * M_blk_idxs\n if NO_D_MASK:\n if NO_M_MASK:\n q = tl.load(Q_blk_ptrs)\n else:\n q = tl.load(Q_blk_ptrs, mask=M_mask[:, None], other=0.0)\n else:\n q = tl.load(Q_blk_ptrs, mask=M_mask[:, None] & D_mask[None, :],\n other=0.0)\n iters = N_blk_idxs_start // BLOCK_N\n neg_log_acc = tl.zeros([BLOCK_M], dtype=acc_dtype)\n acc = tl.zeros([BLOCK_M, BLOCK_D], dtype=acc_dtype)\n for i in range(iters):\n N_blk_idxs -= BLOCK_N\n N_blk_idxs_start -= BLOCK_N\n K_blk_ptrs -= BLOCK_N * stride_kn\n V_blk_ptrs -= BLOCK_N * stride_vn\n N_mask = N_blk_idxs < seq_length\n k, v = load_kv(K_blk_ptrs, V_blk_ptrs, N_mask=N_mask, NO_N_MASK=\n N_blk_idxs_start + BLOCK_N - 1 < seq_length, D_mask=D_mask,\n NO_D_MASK=NO_D_MASK)\n on_band = i < BLOCK_M // BLOCK_N\n p, _, neg_log_acc = compute_block(q, k, qk_scale, neg_log_acc,\n M_blk_idxs, N_blk_idxs, cm, on_band, ALLOW_TF32, attend_current\n =attend_current, backward=False, is_compiling=is_compiling,\n use_cumsum=use_cumsum)\n acc = tl.dot(p.to(v.dtype), v, acc, allow_tf32=ALLOW_TF32)\n if return_attention:\n tl.store(W_head_seq_ptr + stride_wm * M_blk_idxs[:, None] + \n stride_wn * N_blk_idxs[None, :], p, mask=(M_blk_idxs <\n seq_length)[:, None] & (N_blk_idxs < seq_length)[None, :])\n if NO_M_MASK:\n tl.store(R_blk_ptrs, tl.math.exp2(neg_log_acc))\n tl.store(A_blk_ptrs, neg_log_acc.to(A_head_seq_ptr.type.element_ty))\n else:\n tl.store(R_blk_ptrs, tl.math.exp2(neg_log_acc), mask=M_mask)\n tl.store(A_blk_ptrs, neg_log_acc.to(A_head_seq_ptr.type.element_ty),\n mask=M_mask)\n if NO_D_MASK:\n tl.store(O_blk_ptrs, acc.to(O_head_seq_ptr.type.element_ty), mask=\n M_mask[:, None])\n else:\n tl.store(O_blk_ptrs, acc.to(O_head_seq_ptr.type.element_ty), mask=\n M_mask[:, None] & D_mask[None, :])\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops", "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/sb_varlen_fwd.py" }, { "uuid": "4655e66d-50dd-4e01-87a7-dbc096fc693b", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/generalized_delta_rule/iplr/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_fwd_kernel(q, k, v, alpha, beta, o, ha, h0, ht, s_k_h,\n s_v_h, scale, B, H, T, K: tl.constexpr, V: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr,\n STORE_FINAL_STATE: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_v = v + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_alpha = alpha + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_beta = beta + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_o = o + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV)\n p_ha = ha + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV)\n mask_bk = i_k * BK + tl.arange(0, BK) < K\n mask_bv = i_v * BV + tl.arange(0, BV) < V\n mask_kv = mask_bk[None, :] & mask_bv[:, None]\n h = tl.zeros([BV, BK], dtype=tl.float32)\n if USE_INITIAL_STATE:\n p_h0 = h0 + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n h += tl.load(p_h0, mask=mask_kv, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_bk, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_bv, other=0).to(tl.float32)\n b_q = tl.load(p_q, mask=mask_bk, other=0).to(tl.float32) * scale\n b_alpha = tl.load(p_alpha, mask=mask_bk, other=0).to(tl.float32)\n b_beta = tl.load(p_beta, mask=mask_bk, other=0).to(tl.float32)\n tmp = tl.sum(h * b_alpha[None, :], axis=1)\n h += tmp[:, None] * b_beta[None, :] + b_k[None, :] * b_v[:, None]\n _o = h * b_q[None, :]\n _o = tl.sum(_o, axis=1)\n tl.store(p_o, _o.to(p_o.dtype.element_ty), mask=mask_bv)\n tl.store(p_ha, tmp.to(p_ha.dtype.element_ty), mask=mask_bv)\n p_q += K\n p_k += K\n p_o += V\n p_v += V\n p_ha += V\n p_alpha += K\n p_beta += K\n if STORE_FINAL_STATE:\n p_ht = ht + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[None, :]\n ) * V + (i_v * BV + tl.arange(0, BV)[:, None])\n tl.store(p_ht, h.to(p_ht.dtype.element_ty), mask=mask_kv)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access", "Register Intensive" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/generalized_delta_rule/iplr/fused_recurrent.py" }, { "uuid": "5400e181-7552-4332-b506-bdb00f476d7a", "file_name": "layer_norm_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/layer_norm_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef layer_norm_backward_kernel(output_grad_pointer, input_pointer,\n mean_pointer, inv_std_pointer, weight_pointer, input_grad_pointer,\n weight_grad_pointer, bias_grad_pointer, batch_dim, feat_dim,\n output_grad_batch_stride, output_grad_feat_stride, input_batch_stride,\n input_feat_stride, input_grad_batch_stride, input_grad_feat_stride,\n weight_grad_batch_stride, weight_grad_feat_stride,\n bias_grad_batch_stride, bias_grad_feat_stride, scale_by_weight: tl.\n constexpr, add_bias: tl.constexpr, BLOCK_SIZE_BATCH: tl.constexpr,\n BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Calculates the input gradient of layer normalization.\n\n Args:\n output_grad_pointer: Pointer to layer normalization's output gradients.\n The output gradients must be of shape [batch_dim, feat_dim].\n input_pointer: Pointer to the input.\n The input must be of shape [batch_dim, feat_dim].\n mean_pointer: Pointer to the input's mean.\n The mean should be of shape [batch_dim].\n inv_std_pointer: Pointer to the input's inverse standard deviation.\n The inverse standard deviation should be of shape [batch_dim].\n weight_pointer: Pointer to optional weights if affine transform occurred.\n The weights, if provided, must be of shape [feat_dim].\n input_grad_pointer: Pointer to a container the input's gradients are written to.\n The container must be of shape [batch_dim, feat_dim].\n weight_grad_pointer: Pointer to an optional container the weights' row-wise gradients\n are written to if scale_by_weight is True, which should later be summed.\n The container, if provided, must be of shape [batch_dim/BLOCK_SIZE_BATCH, feat_dim].\n bias_grad_pointer: Pointer to an optional container the bias vector's row-wise gradients\n are written to if scale_by_weight and add_bias are True, which should later be summed.\n The container, if provided, must be of shape [batch_dim/BLOCK_SIZE_BATCH, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n output_grad_batch_stride: Stride necessary to jump one element along the\n output gradients' batch dimension.\n output_grad_feat_stride: Stride necessary to jump one element along the\n output gradients' feature dimension.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n input_grad_batch_stride: Stride necessary to jump one element along the\n input gradient container's batch dimension.\n input_grad_feat_stride: Stride necessary to jump one element along the\n input gradient container's feature dimension.\n weight_grad_batch_stride: Stride necessary to jump one element along the\n weight gradient container's batch dimension.\n weight_grad_feat_stride: Stride necessary to jump one element along the\n weight gradient container's feature dimension.\n bias_grad_batch_stride: Stride necessary to jump one element along the\n weight gradient container's batch dimension.\n bias_grad_feat_stride: Stride necessary to jump one element along the\n weight gradient container's feature dimension.\n scale_by_weight: Flag for scaling the normalized output by weights.\n add_bias: Flag for adding a bias vector to the normalized output\n if scale_by_weight is True.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n output_grad_pointer += output_grad_batch_stride * batch_offset[:, None\n ] + output_grad_feat_stride * feat_offset[None, :]\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n input_grad_pointer += input_grad_batch_stride * batch_offset[:, None\n ] + input_grad_feat_stride * feat_offset[None, :]\n output_grad = tl.load(output_grad_pointer, mask=batch_mask[:, None] &\n feat_mask[None, :]).to(tl.float32)\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :]).to(tl.float32)\n mean = tl.load(mean_pointer + batch_offset, mask=batch_mask)\n inv_std = tl.load(inv_std_pointer + batch_offset, mask=batch_mask)\n pre_lin = (input - mean[:, None]) * inv_std[:, None]\n if scale_by_weight:\n weight = tl.load(weight_pointer + feat_offset, mask=feat_mask)\n weight_output_grad_prod = weight * output_grad\n else:\n weight_output_grad_prod = output_grad\n term1 = tl.sum(pre_lin * weight_output_grad_prod, axis=1) / feat_dim\n term1 = pre_lin * term1[:, None]\n term2 = tl.sum(weight_output_grad_prod, axis=1) / feat_dim\n input_grad = inv_std[:, None] * (weight_output_grad_prod - (term1 +\n term2[:, None]))\n tl.store(input_grad_pointer, input_grad, mask=batch_mask[:, None] &\n feat_mask[None, :])\n if scale_by_weight:\n weight_grad_pointer += (weight_grad_batch_stride * batch_pid + \n weight_grad_feat_stride * feat_offset)\n tl.store(weight_grad_pointer, tl.sum(output_grad * pre_lin, axis=0),\n mask=feat_mask)\n if add_bias:\n bias_grad_pointer += (bias_grad_batch_stride * batch_pid + \n bias_grad_feat_stride * feat_offset)\n tl.store(bias_grad_pointer, tl.sum(output_grad, axis=0), mask=\n feat_mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups", "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/layer_norm_kernels.py" }, { "uuid": "c09cde34-9ffc-4939-be5b-e95b46999a0f", "file_name": "softmax_loop_along_reduce_axis_v2.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_loop_along_reduce_axis_v2.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_loop_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n m = tl.maximum(m, inp)\n m = tl.max(m, 0)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n z += e\n z = tl.sum(z, 0)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_loop_along_reduce_axis_v2.py" }, { "uuid": "d41cc477-8ab0-4b21-a14c-3997eac771ce", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BT': BT, 'BK': BK}, num_warps=\n num_warps) for BT in [16, 32, 64] for BK in [32, 64] for num_warps in [\n 1, 2, 4, 8]], key=['K'])\n@triton.jit\ndef fused_recurrent_rwkv6_bwd_kernel_dw(q, k, dq, dk, dw, offsets, scale, T:\n tl.constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BK:\n tl.constexpr, REVERSE: tl.constexpr, HEAD_FIRST: tl.constexpr,\n USE_OFFSETS: tl.constexpr):\n i_k, i_nh = tl.program_id(0), tl.program_id(1)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n T = eos - bos\n NT = tl.cdiv(T, BT)\n o_i = tl.arange(0, BT)\n m_i = tl.where(o_i[:, None] >= o_i[None, :], 1.0, 0.0\n ) if not REVERSE else tl.where(o_i[:, None] <= o_i[None, :], 1.0, 0.0)\n b_z = tl.zeros([BK], dtype=tl.float32)\n i_t = 0 if not REVERSE else NT - 1\n for _ in range(NT):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (T, K), (K, 1), (i_t *\n BT + 1, i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + i_nh * T * K, (T, K), (K, 1), (\n i_t * BT + 1, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_nh * T * K, (T - 1, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_nh * T * K, (T - 1, K), (K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + i_nh * T * K, (T, K), (K, 1), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT + 1, i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + 1, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T - 1, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T - 1, K),\n (H * K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dw = tl.make_block_ptr(dw + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1)).to(tl.float32)\n b_dq = tl.load(p_dq, boundary_check=(0, 1)).to(tl.float32)\n b_k = tl.load(p_k, boundary_check=(0, 1)).to(tl.float32)\n b_dk = tl.load(p_dk, boundary_check=(0, 1)).to(tl.float32)\n b_dw = b_q * b_dq * scale - b_k * b_dk\n b_c = b_z[None, :] + tl.dot(m_i, b_dw, allow_tf32=False)\n tl.store(p_dw, b_c.to(p_dw.dtype.element_ty), boundary_check=(0, 1))\n if i_t >= 0:\n b_z += tl.sum(b_dw, 0)\n i_t += 1 if not REVERSE else -1\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/fused_recurrent.py" }, { "uuid": "ad644dd8-8dd8-4e51-b816-115a5a717ad7", "file_name": "hilbert.py", "repo_name": "Kitsunetic/space-filling-pytorch", "file_path": "space_filling_pytorch/functional/hilbert.py", "commit_hash": "0de955ad1036973ee7506c5a0124c208acec722d", "starcount": 0, "input": "@triton.jit\ndef _calculate_hilbert_distance(fx, fy, fz, space_size):\n x = ((fx + 1) / 2 * space_size).to(tl.int64)\n y = ((fy + 1) / 2 * space_size).to(tl.int64)\n z = ((fz + 1) / 2 * space_size).to(tl.int64)\n x = tl.minimum(tl.maximum(x, 0), space_size - 1)\n y = tl.minimum(tl.maximum(y, 0), space_size - 1)\n z = tl.minimum(tl.maximum(z, 0), space_size - 1)\n for i in tl.static_range(15, 0, -1):\n q = 1 << i\n p = q - 1\n x ^= tl.where(x & q, p, 0)\n cond = y & q\n t = (x ^ y) & p\n x ^= tl.where(cond, p, t)\n y ^= tl.where(cond, 0, t)\n cond = z & q\n t = (x ^ z) & p\n x ^= tl.where(cond, p, t)\n z ^= tl.where(cond, 0, t)\n y ^= x\n z ^= y\n t = 0\n for i in tl.static_range(15, 0, -1):\n q = 1 << i\n t ^= tl.where(z & q, q - 1, 0)\n x ^= t\n y ^= t\n z ^= t\n ret = 0\n for i in tl.static_range(0, 16):\n q = 1 << i\n ret |= (x & q) << 2 * i + 2\n ret |= (y & q) << 2 * i + 1\n ret |= (z & q) << 2 * i + 0\n return ret\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/space-filling-pytorch/blob/0de955ad1036973ee7506c5a0124c208acec722d/space_filling_pytorch/functional/hilbert.py" }, { "uuid": "f6eb3989-cac5-479b-973d-97694fdb700e", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef roll(y, dim=0):\n _, rh2, _ = tl.associative_scan((1 + 0 * y, 0.0 * y, y), dim, roll_op)\n return rh2\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "28746acd-0067-40c2-9349-3abb547bd86d", "file_name": "chunk_h_split.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_split.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_FINAL_STATE_GRADIENT': lambda args: args['dht'] is not\n None, 'STORE_INITIAL_STATE_GRADIENT': lambda args: args['dh0'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [2, 4, 8] for num_stages in [2, 3]], key=['BT', 'USE_G',\n 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_bwd_kernel_dh_split(q, g, gk, gv, do, dht, dhs, dhr, dh0, offsets,\n split_indices, scale, T: tl.constexpr, S: tl.constexpr, HQ: tl.\n constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.\n constexpr, BK: tl.constexpr, BV: tl.constexpr, NG: tl.constexpr, USE_G:\n tl.constexpr, USE_GK: tl.constexpr, USE_GV: tl.constexpr,\n USE_FINAL_STATE_GRADIENT: tl.constexpr, STORE_INITIAL_STATE_GRADIENT:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_sh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_ss, i_hq = i_sh // HQ, i_sh % HQ\n if USE_OFFSETS:\n i_n, i_s = tl.load(split_indices + i_ss * 2).to(tl.int32), tl.load(\n split_indices + i_ss * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NS = tl.cdiv(T, S)\n else:\n NS = tl.cdiv(T, S)\n i_n, i_s = i_ss // NS, i_ss % NS\n bos, eos = i_n * T, i_n * T + T\n i_nh = i_n * HQ + i_hq\n i_ng, i_h = i_nh // NG, i_hq // NG\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n if i_s == NS - 1:\n if USE_FINAL_STATE_GRADIENT:\n p_dht = tl.make_block_ptr(dht + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_dh += tl.load(p_dht, boundary_check=(0, 1)).to(tl.float32)\n p_dhr = tl.make_block_ptr(dhr + i_sh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dhr, b_dh.to(p_dhr.dtype.element_ty), boundary_check=(0, 1))\n for i_t in range(tl.cdiv(min(i_s * S + S, T), BT) - 1, tl.cdiv(i_s * S,\n BT) - 1, -1):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_nh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + i_nh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * HQ + i_hq) * K, (K, T), (1, \n HQ * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_do = tl.make_block_ptr(do + (bos * HQ + i_hq) * V, (T, V), (\n HQ * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_do = tl.load(p_do, boundary_check=(0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n p_g = g + i_ng * T + i_t * BT + tl.arange(0, BT)\n p_g = tl.max_contiguous(tl.multiple_of(p_g, BT), BT)\n b_g_last = tl.load(g + i_ng * T + last_idx)\n else:\n p_g = g + (bos + i_t * BT + tl.arange(0, BT)) * H + i_h\n b_g_last = tl.load(g + (bos + last_idx) * H + i_h)\n b_g = tl.load(p_g, mask=i_t * BT + tl.arange(0, BT) < T, other=0.0)\n b_q = (b_q * tl.exp(b_g)[None, :]).to(b_q.dtype)\n b_dh *= tl.exp(b_g_last)\n if USE_GK:\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(gk + i_ng * T * K, (K, T), (1, K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (i_ng * T + last_idx\n ) * K + i_k * BK + tl.arange(0, BK)\n else:\n p_gk = tl.make_block_ptr(gk + (bos * H + i_h) * K, (K, T),\n (1, H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_q = (b_q * tl.exp(b_gk)).to(b_q.dtype)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) <\n K, other=0.0)\n b_dh *= tl.exp(b_gk_last)[:, None]\n if USE_GV:\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(gv + i_ng * T * V, (T, V), (V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (i_ng * T + last_idx\n ) * V + i_v * BV + tl.arange(0, BV)\n else:\n p_gv = tl.make_block_ptr(gv + (bos * H + i_h) * V, (T, V),\n (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_gv)).to(b_do.dtype)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) <\n V, other=0.0)\n b_dh *= tl.exp(b_gv_last)[None, :]\n b_dh += tl.dot(b_q, b_do)\n if NS > 1:\n p_dhs = tl.make_block_ptr(dhs + i_sh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dhs, b_dh.to(p_dhs.dtype.element_ty), boundary_check=(0, 1))\n elif STORE_INITIAL_STATE_GRADIENT:\n p_dh0 = tl.make_block_ptr(dh0 + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_split.py" }, { "uuid": "66cc7094-2f0e-4a81-9d3e-fc4e2f0954ad", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_fwd_kernel_K(q, k, z, h, o, A, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, s_h_h, s_h_t, s_h_d, scale, T: tl.constexpr, K: tl.\n constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.\n constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_p = tl.maximum(i_t * BT - 1, 0)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, s_h_d), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h, allow_tf32=False)\n b_A += tl.dot(b_q, b_k, allow_tf32=False)\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n p_zp = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), (i_p * V +\n i_v * BV,), (BV,), (0,))\n b_zp = tl.load(p_zp, boundary_check=(0,))\n b_o = b_o * tl.exp(b_zp[None, :] - b_z)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t * BT,\n 0), (BT, BT), (1, 0))\n b_A = tl.where(m_s, b_A, 0.0)\n if i_v == 0:\n tl.store(p_A, b_A.to(p_A.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "036c35d5-8ac1-4fea-a594-dfc3a88a9bfa", "file_name": "rmsnorm.py", "repo_name": "agostini01/rms-norm-exercise", "file_path": "optimized/rmsnorm.py", "commit_hash": "0884cc52a8cde60ff8af0fa58d5b5330ae5db87a", "starcount": 0, "input": "@triton.jit\ndef rms_norm(output_ptr, input_ptr, weights_ptr, stride, N, eps, DTYPE: tl.\n constexpr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n RMS Norm Triton Kernel\n\n Params:\n - input_ptr (tensor): Pointer to Input\n - output_ptr (tensor): Pointer to Output\n - weights_ptr (tensor): Pointer to Scale applied to the normalized input\n - stride (int): Stride to be applied when accessing elements in the input and output tensors\n - N (int): Number of elements to be reduced == input_ptr.shape[-1]\n - eps (half/float): Epsilon value added to the variance to prevent division by zero\n - BLOCK_SIZE (constexpr): Size of the block for computation, provided as a compile-time constant\n\n Usage:\n _rms_norm[grid, block](x, y, self.w, input_stride , N, eps, BLOCK_SIZE)\n \"\"\"\n row = tl.program_id(0)\n output_ptr += row * stride\n input_ptr += row * stride\n tmp = 0\n tmp = tl.zeros([BLOCK_SIZE], dtype=DTYPE)\n for offset in range(0, N, BLOCK_SIZE):\n cols = offset + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n a = tl.load(input_ptr + cols, mask=mask, other=0.0).to(DTYPE)\n tmp += a * a\n rms = tl.sqrt(tl.sum(tmp) / N + eps)\n for offset in range(0, N, BLOCK_SIZE):\n cols = offset + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n x = tl.load(input_ptr + cols, mask=mask, other=0.0, eviction_policy\n ='evict_first').to(DTYPE)\n w = tl.load(weights_ptr + cols, mask=mask)\n x_hat = x / rms\n y = x_hat * w\n tl.store(output_ptr + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32", "fp16", "bf16" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/agostini01/rms-norm-exercise/blob/0884cc52a8cde60ff8af0fa58d5b5330ae5db87a/optimized/rmsnorm.py" }, { "uuid": "55da2e67-0be0-4dfc-aa0d-22b2e71956a3", "file_name": "softmax.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/softmax.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['D'])\n@triton.jit\ndef softmax_fwd_kernel(x, p, D: tl.constexpr, B: tl.constexpr):\n i_n = tl.program_id(0)\n o_d = tl.arange(0, B)\n m_d = o_d < D\n b_x = tl.load(x + i_n * D + o_d, mask=m_d, other=-float('inf'))\n b_m = tl.max(b_x, 0)\n b_x = tl.exp(b_x - b_m)\n b_p = b_x / tl.sum(b_x, 0)\n tl.store(p + i_n * D + o_d, b_p.to(p.dtype.element_ty), mask=m_d)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32", "fp16", "bf16" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/softmax.py" }, { "uuid": "ff97fdfb-b204-4483-bf5b-9713cad36067", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/based/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_based_bwd_kernel(q, k, v, do, dz, dq, dk, dv, s_k_h, s_k_t,\n s_k_d, s_v_h, s_v_t, s_v_d, scale, B: tl.constexpr, H: tl.constexpr, T:\n tl.constexpr, K: tl.constexpr, V: tl.constexpr, BTL: tl.constexpr, BTS:\n tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n i_kv, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n NV = tl.cdiv(V, BV)\n i_k = i_kv // NV\n i_v = i_kv % NV\n i_h = i_bh % H\n _parallel_based_bwd_dq(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dq,\n s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, B, H, T, scale, BTL=BTL,\n BTS=BTS, BK=BK, BV=BV, K=K, V=V)\n tl.debug_barrier()\n _parallel_based_bwd_dkv(i_bh, i_c, i_k, i_v, i_h, q, k, v, do, dz, dk,\n dv, s_k_h, s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, B, H, T, scale, BTL,\n BTS, BK, BV, K, V)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/based/parallel.py" }, { "uuid": "ea89f51b-43ee-4c4b-b14e-5c296ca54f47", "file_name": "cross_entropy_loss.py", "repo_name": "tdrussell/qlora-pipe", "file_path": "kernels/cross_entropy_loss.py", "commit_hash": "6fb7c8eeae52a0e36c41f00628985f29d8330684", "starcount": 0, "input": "@triton.heuristics({'DO_LOGIT_SCALING': lambda args: args['DO_LOGIT_SCALING']})\n@triton.jit\ndef _chunked_cross_entropy_forward(logits_ptr, logits_row_stride, loss_ptr,\n logsumexp_ptr, labels_ptr, VOCAB_SIZE: tl.constexpr, N_CHUNKS: tl.\n constexpr, BLOCK_SIZE: tl.constexpr, DO_LOGIT_SCALING: tl.constexpr,\n LOGIT_SCALE: tl.constexpr):\n \"\"\"\n 256K vocab divided in 4 chunks\n\n |-65536-| |-65536-| |-65536-| |-65536-|\n |-------| |-------| |-------| |-------|\n |-------| |-------| |-------| |-------|\n\n If y == 0: CE_i = 0\n If y == 1: CE_i = logsumexp - x\n\n Notice we can do logsumexp for each chunk and then\n logsumexp[chunk_sum(logsumexp)] == logsumexp\n\n chunk_sum = log[chunk_sum(logsumexp)]\n = log[exp(logsumexp(a)) + ... + exp(logsumexp(z))]\n = log[exp(log[sum(exp(a))]) + ... + exp(log[sum(exp(z))])]\n = log[sum(exp(a)) + ... + sum(exp(z))]\n = logsumexp(x)\n\n This means we can perform a logsumexp for each chunk, then do a\n final logsumexp reduction!\n\n Ie do: logsumexp(chunked_logsumexp) - x\n \"\"\"\n row_idx = tl.program_id(0)\n chunk_idx = tl.program_id(1)\n logits_ptr += row_idx * logits_row_stride.to(tl.int64)\n loss_ptr += row_idx\n logsumexp_ptr += row_idx * N_CHUNKS + chunk_idx\n labels_ptr += row_idx\n col_offsets = chunk_idx * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < VOCAB_SIZE\n label_idx = tl.load(labels_ptr).to(tl.int32)\n logits = tl.load(logits_ptr + col_offsets, mask=mask, other=-float('inf')\n ).to(tl.float32)\n if DO_LOGIT_SCALING:\n logits = LOGIT_SCALE * logits\n pass\n c = tl.max(logits, 0)\n logsumexp = c + tl.log(tl.sum(tl.exp(logits - c), 0))\n if chunk_idx == 0:\n if label_idx != -100:\n x = tl.load(logits_ptr + label_idx).to(tl.float32)\n if DO_LOGIT_SCALING:\n x = LOGIT_SCALE * x\n pass\n loss = -1.0 * x\n else:\n loss = 0.0\n tl.store(loss_ptr, loss)\n pass\n tl.store(logsumexp_ptr, logsumexp)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/tdrussell/qlora-pipe/blob/6fb7c8eeae52a0e36c41f00628985f29d8330684/kernels/cross_entropy_loss.py" }, { "uuid": "d6089944-ecae-4155-ae54-51eac263e597", "file_name": "inout_tensor_parallel.py", "repo_name": "gmgu/study-triton", "file_path": "2_inout_tensor/inout_tensor_parallel.py", "commit_hash": "3a9a24fd3f1de3e7465535ffe72f6deac8a419bd", "starcount": 0, "input": "@triton.jit\ndef copy_kernel(in_ptr, out_ptr, n, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(axis=0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n\n x = tl.load(in_ptr + offsets, mask=mask)\n y = tl.store(out_ptr + offsets, x, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/gmgu/study-triton/blob/3a9a24fd3f1de3e7465535ffe72f6deac8a419bd/2_inout_tensor/inout_tensor_parallel.py" }, { "uuid": "6f93083e-9dd4-4587-99ae-73b0d5ae4397", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_compute_ws(Q, K, V, sm_scale, M, Out, desc_q, desc_k, desc_v,\n desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, off_hz, pid, Z,\n H, N_CTX, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.\n constexpr, STAGE: tl.constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE:\n tl.constexpr):\n start_m = pid\n off_z = off_hz // H\n off_h = off_hz % H\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n K_block_ptr = None\n V_block_ptr = None\n Q_block_ptr = None\n O_block_ptr = None\n if not ENABLE_TMA:\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, HEAD_DIM), order=(1, 0))\n v_order: tl.constexpr = (0, 1\n ) if V.dtype.element_ty == tl.float8e5 else (1, 0)\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, HEAD_DIM), order=v_order)\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(\n HEAD_DIM, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(HEAD_DIM, BLOCK_N), order=(0, 1))\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n HEAD_DIM), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, HEAD_DIM), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, HEAD_DIM], dtype=tl.float32)\n qk_scale = sm_scale\n qk_scale *= 1.44269504\n with tl.async_task([0]):\n if ENABLE_TMA:\n q = tl._experimental_descriptor_load(desc_q, [(qvk_offset //\n stride_qm + start_m * BLOCK_M).to(tl.int32), 0], [BLOCK_M,\n HEAD_DIM], Q.dtype.element_ty)\n else:\n q = tl.load(Q_block_ptr)\n if STAGE & 1:\n acc, l_i, m_i = _attn_fwd_inner_ws(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, desc_k, desc_v, Q, qvk_offset, stride_kn,\n stride_vn, stride_vk, start_m, qk_scale, BLOCK_M, HEAD_DIM,\n BLOCK_N, 4 - STAGE, offs_m, offs_n, N_CTX, V.dtype.element_ty ==\n tl.float8e5, ENABLE_TMA, LOOP_SCHEDULE)\n if STAGE & 2:\n acc, l_i, m_i = _attn_fwd_inner_ws(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, desc_k, desc_v, Q, qvk_offset, stride_kn,\n stride_vn, stride_vk, start_m, qk_scale, BLOCK_M, HEAD_DIM,\n BLOCK_N, 2, offs_m, offs_n, N_CTX, V.dtype.element_ty == tl.\n float8e5, ENABLE_TMA, LOOP_SCHEDULE)\n with tl.async_task([1, 2]):\n m_i += tl.math.log2(l_i)\n acc = acc / l_i[:, None]\n m_ptrs = M + off_hz * N_CTX + offs_m\n tl.store(m_ptrs, m_i)\n if ENABLE_TMA:\n tl._experimental_descriptor_store(desc_o, acc.to(Out.type.\n element_ty), [(qvk_offset // stride_om + start_m * BLOCK_M)\n .to(tl.int32), 0])\n else:\n tl.store(O_block_ptr, acc.to(Out.type.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "899ada78-0cbe-42a7-835e-eb835b7dce73", "file_name": "kernel_benchmark.py", "repo_name": "ruikangliu/FlatQuant", "file_path": "benchmarks/kernel_benchmark.py", "commit_hash": "9d3032065f1688cb3f71ebc8166df6d91440e871", "starcount": 0, "input": "@triton.jit\ndef quant_kernel(src_ptr, stride_srcb, stride_srcm, stride_srcn, dst_ptr,\n stride_dstb, stride_dstm, stride_dstn, output_scale, B, M: tl.constexpr,\n N: tl.constexpr, np2_M: tl.constexpr, np2_N: tl.constexpr):\n \"\"\"\n quant fp16 tensor to int4\n \"\"\"\n batch_id = tl.program_id(axis=0) + tl.program_id(axis=1) * tl.num_programs(\n axis=0)\n index_rows = tl.arange(0, np2_M)\n index_cols = tl.arange(0, np2_N)\n src_ptrs = src_ptr + batch_id * stride_srcb.to(tl.int64) + index_rows[:,\n None] * stride_srcm + index_cols[None, :] * stride_srcn\n src_mask = (index_rows[:, None] < M) & (index_cols[None, :] < N)\n src = tl.load(src_ptrs, mask=src_mask, other=0.0)\n abs_src_val = tl.abs(src)\n max_src_val = tl.max(abs_src_val)\n scale = max_src_val / 7.0\n quant_val = libdevice.llrint(src / scale)\n quant_val = max(-8, min(quant_val, 7))\n quant_val = quant_val.reshape(np2_M, np2_N // 2, 2, can_reorder=False)\n quant_val_even, quant_val_odd = quant_val.split()\n quant_val_odd = quant_val_odd << 4\n res = tl.zeros((np2_M, np2_N // 2), dtype=tl.uint8)\n res = res | quant_val_odd & 240\n res = res | quant_val_even & 15\n offs_resm = tl.arange(0, np2_M)\n offs_resn = tl.arange(0, np2_N // 2)\n dst_ptrs = dst_ptr + stride_dstb.to(tl.int64\n ) * batch_id + stride_dstm * offs_resm[:, None\n ] + stride_dstn * offs_resn[None, :]\n res_mask = (offs_resm[:, None] < M) & (offs_resn[None, :] < N // 2)\n tl.store(dst_ptrs, res, mask=res_mask)\n tl.store(output_scale + batch_id, scale)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "fp16", "uint8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ruikangliu/FlatQuant/blob/9d3032065f1688cb3f71ebc8166df6d91440e871/benchmarks/kernel_benchmark.py" }, { "uuid": "e91bc5a6-77ff-44ee-8f09-c99d4cd87aa7", "file_name": "quant_triton.py", "repo_name": "CompendiumLabs/ziggy", "file_path": "ziggy/backends/quant_triton.py", "commit_hash": "bd12fe50ca3475743f62ae26d4c184108e441e03", "starcount": 0, "input": "@triton.jit\ndef quantize_kernel(X, Y, N, K, K1, scale, zero_point, BITS: tl.constexpr,\n QFACT: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.\n constexpr, BLOCK_SIZE_K1: tl.constexpr):\n dtype = X.dtype.element_ty\n scale_ty = tl.full((), scale, dtype=dtype)\n zero_point_ty = tl.full((), zero_point, dtype=dtype)\n QMASK = (1 << BITS) - 1\n QMASK_FLT = tl.full((), QMASK, dtype=dtype)\n pid_n = tl.program_id(0)\n pid_k = tl.program_id(1)\n bk = tl.arange(0, BLOCK_SIZE_K)\n bk1 = tl.arange(0, BLOCK_SIZE_K1)\n x_shift = BITS * (bk % QFACT)\n rn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n rk = pid_k * BLOCK_SIZE_K + bk\n rk1 = pid_k * BLOCK_SIZE_K1 + bk1\n mask_x = rn[:, None] < N\n mask_y = rn[:, None] < N\n X1 = X + (rn[:, None] * K + rk[None, :])\n Y1 = Y + (rn[:, None] * K1 + rk1[None, :])\n x = tl.load(X1, mask=mask_x)\n xf = clamp(x / scale_ty + zero_point_ty, 0.0, QMASK_FLT)\n xi = tl.math.rint(xf).to(tl.uint8)\n xq = xi << x_shift\n mat = tl.reshape(xq, (BLOCK_SIZE_N, BLOCK_SIZE_K1, QFACT))\n out = tl.sum(mat, axis=2)\n tl.store(Y1, out, mask=mask_y)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "fp32", "fp16", "bf16", "uint8" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/CompendiumLabs/ziggy/blob/bd12fe50ca3475743f62ae26d4c184108e441e03/ziggy/backends/quant_triton.py" }, { "uuid": "55dad000-aa04-4d5a-bea5-663140e7161a", "file_name": "k_dropout.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_dropout.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.autotune(configs=_k_configs, key=['N'])\n@triton.jit\ndef k_dropout_fw(Y, X, BIAS, SEEDS, stride, N, p, **META):\n \"\"\"\n Apply dropout on an input tensor\n Y : Output (M, N)\n X : Input (M, N)\n S : Seeds (M,)\n p : dropout probability\n \"\"\"\n BLOCK_SIZE = META['BLOCK_SIZE']\n row = tl.program_id(axis=0)\n col = tl.program_id(axis=1)\n offsets = row * stride + col * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = col * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE) < N\n x_ptrs = X + offsets\n x = tl.load(x_ptrs, mask=mask)\n if META['USE_BIAS']:\n b_ptrs = BIAS + col * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n b = tl.load(b_ptrs, mask=mask)\n x += b\n if META['ACTIVATION']:\n x = META['ACTIVATION'](x)\n if p > 0.0:\n output = _drop_and_scale(SEEDS, row, p, offsets, x)\n else:\n output = x\n y_ptrs = Y + offsets\n tl.store(y_ptrs, output, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations", "Activation Functions" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_dropout.py" }, { "uuid": "d89888a4-f831-415d-9ee8-3c77f4fc0d29", "file_name": "awq_triton.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/model_executor/layers/quantization/awq_triton.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.jit\ndef awq_gemm_kernel(a_ptr, b_ptr, c_ptr, zeros_ptr, scales_ptr, M, N, K,\n group_size, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, SPLIT_K: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_z = tl.program_id(1)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_m = pid // num_pid_n\n pid_n = pid % num_pid_n\n accumulator_dtype = c_ptr.type.element_ty\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=\n accumulator_dtype)\n reverse_awq_order_tensor = ((tl.arange(0, 2) * 4)[None, :] + tl.arange(\n 0, 4)[:, None]).reshape(8)\n shifts = reverse_awq_order_tensor * 4\n shifts = tl.broadcast_to(shifts[None, :], (BLOCK_SIZE_K * (BLOCK_SIZE_N //\n 8), 8))\n shifts = tl.reshape(shifts, (BLOCK_SIZE_K, BLOCK_SIZE_N))\n offsets_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n masks_am = offsets_am < M\n offsets_bn = pid_n * (BLOCK_SIZE_N // 8) + tl.arange(0, BLOCK_SIZE_N // 8)\n masks_bn = offsets_bn < N // 8\n offsets_zn = pid_n * (BLOCK_SIZE_N // 8) + tl.arange(0, BLOCK_SIZE_N // 8)\n masks_zn = offsets_zn < N // 8\n offsets_sn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n masks_sn = offsets_sn < N\n offsets_k = pid_z * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n offsets_a = K * offsets_am[:, None] + offsets_k[None, :]\n offsets_b = N // 8 * offsets_k[:, None] + offsets_bn[None, :]\n a_ptrs = a_ptr + offsets_a\n b_ptrs = b_ptr + offsets_b\n for k in range(0, tl.cdiv(K, BLOCK_SIZE_K * SPLIT_K)):\n masks_k = offsets_k < K\n masks_a = masks_am[:, None] & masks_k[None, :]\n a = tl.load(a_ptrs, mask=masks_a)\n masks_b = masks_k[:, None] & masks_bn[None, :]\n b = tl.load(b_ptrs, mask=masks_b)\n b = tl.interleave(b, b)\n b = tl.interleave(b, b)\n b = tl.interleave(b, b)\n offsets_szk = (BLOCK_SIZE_K * SPLIT_K * k + pid_z * BLOCK_SIZE_K\n ) // group_size + tl.arange(0, 1)\n offsets_z = N // 8 * offsets_szk[:, None] + offsets_zn[None, :]\n masks_zk = offsets_szk < K // group_size\n masks_z = masks_zk[:, None] & masks_zn[None, :]\n zeros_ptrs = zeros_ptr + offsets_z\n zeros = tl.load(zeros_ptrs, mask=masks_z)\n zeros = tl.interleave(zeros, zeros)\n zeros = tl.interleave(zeros, zeros)\n zeros = tl.interleave(zeros, zeros)\n zeros = tl.broadcast_to(zeros, (BLOCK_SIZE_K, BLOCK_SIZE_N))\n offsets_s = N * offsets_szk[:, None] + offsets_sn[None, :]\n masks_sk = offsets_szk < K // group_size\n masks_s = masks_sk[:, None] & masks_sn[None, :]\n scales_ptrs = scales_ptr + offsets_s\n scales = tl.load(scales_ptrs, mask=masks_s)\n scales = tl.broadcast_to(scales, (BLOCK_SIZE_K, BLOCK_SIZE_N))\n b = b >> shifts & 15\n zeros = zeros >> shifts & 15\n b = (b - zeros) * scales\n b = b.to(c_ptr.type.element_ty)\n accumulator = tl.dot(a, b, accumulator, out_dtype=accumulator_dtype)\n offsets_k += BLOCK_SIZE_K * SPLIT_K\n a_ptrs += BLOCK_SIZE_K * SPLIT_K\n b_ptrs += BLOCK_SIZE_K * SPLIT_K * (N // 8)\n c = accumulator.to(c_ptr.type.element_ty)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptrs = c_ptr + pid_z * N * M + N * offs_cm[:, None] + offs_cn[None, :]\n c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)\n tl.store(c_ptrs, c, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "uint8", "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/model_executor/layers/quantization/awq_triton.py" }, { "uuid": "5b54c71f-c6fd-49ad-b31b-72956c7bdb18", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_chunk_linear_attn_fwd_kernel(q, k, v, o, h0, ht, s_k_h, s_k_t,\n s_k_d, s_v_h, s_v_t, s_v_d, scale, B, H, T, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.constexpr, CHECK:\n tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (0, \n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, 0), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (0, \n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (i_bh + i_k * B * H) * s_v_h, (T, V), (\n s_v_t, s_v_d), (0, i_v * BV), (BT, BV), (1, 0))\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n for i in range(0, tl.cdiv(T, BT)):\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = tl.where(m_s, b_s, 0)\n b_o = tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n if CHECK and i == 0:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_k, b_v, allow_tf32=False)\n else:\n b_o += tl.dot(b_q, b_h.to(b_q.dtype), allow_tf32=False)\n b_h = b_h + tl.dot(b_k, b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n p_q = tl.advance(p_q, (BT, 0))\n p_k = tl.advance(p_k, (0, BT))\n p_v = tl.advance(p_v, (BT, 0))\n p_o = tl.advance(p_o, (BT, 0))\n if STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_bh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/fused_chunk.py" }, { "uuid": "75455e8e-2630-4564-b24a-6cc4c167f9ee", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_intra_KV(v, z, A, do, dv, s_v_h, s_v_t, s_v_d, T:\n tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr, BV:\n tl.constexpr, NC: tl.constexpr):\n i_v, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_t, i_i = i_c // NC, i_c % NC\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_t *\n BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), ((i_t *\n BT + i_i * BC + BC - 1) * V + i_v * BV,), (BV,), (0,))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_dv = tl.zeros([BC, BV], dtype=tl.float32)\n for i_j in range(i_i + 1, NC):\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (BT, T), (1, BT), (i_i *\n BC, i_t * BT + i_j * BC), (BC, BC), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT + i_j * BC, i_v * BV), (BC, BV), (1, 0))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_zn[None, :] - b_z)).to(b_do.dtype)\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_dv += tl.dot(b_A, b_do, allow_tf32=False)\n b_dv *= tl.exp(b_v - b_zn[None, :])\n o_i = tl.arange(0, BC)\n for j in range(0, BC):\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (1,), ((i_t *\n BT + i_i * BC + j) * V + i_v * BV,), (BV,), (0,))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T * BT,), (1,), ((i_t *\n BT + i_i * BC + j) * BT + i_i * BC,), (BC,), (0,))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T * V,), (1,), ((i_t *\n BT + i_i * BC + j) * V + i_v * BV,), (BV,), (0,))\n b_A = tl.load(p_A, boundary_check=(0,))\n b_z = tl.load(p_z, boundary_check=(0,))\n b_do = tl.load(p_do, boundary_check=(0,))\n m_i = o_i[:, None] <= j\n b_dv += tl.where(m_i, tl.exp(b_v - b_z[None, :]) * b_A[:, None] *\n b_do[None, :], 0.0)\n p_dv = tl.make_block_ptr(dv + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication", "Attention Mechanisms", "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "2cc1ebc8-1e04-49be-a864-a110ad100feb", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_dp(v, rv, cv, pv, do, dp, s_qk_h, s_qk_t, s_qk_d,\n s_sk_h, s_sk_t, s_sk_m, T, BT: tl.constexpr, BV: tl.constexpr, BM: tl.\n constexpr, DV: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_m, i_v, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n p_v = tl.make_block_ptr(v + i_bh * s_qk_h, (DV, T), (s_qk_d, s_qk_t), (\n i_v * BV, 0), (BV, BT), (0, 1))\n p_rv = tl.make_block_ptr(rv + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_cv = tl.make_block_ptr(cv + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n (0, i_m * BM), (BT, BM), (1, 0))\n p_pv = tl.make_block_ptr(pv + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n (0, i_m * BM), (BT, BM), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_qk_h, (T, DV), (s_qk_t, s_qk_d),\n (0, i_v * BV), (BT, BV), (1, 0))\n p_dp = tl.make_block_ptr(dp + (i_v * n_bh + i_bh) * s_sk_h, (T, DM), (\n s_sk_t, s_sk_m), (0, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_hv = tl.zeros([BV, BM], dtype=tl.float32)\n for _ in range(NT):\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_rv = tl.load(p_rv, boundary_check=(0,))\n b_cv = tl.load(p_cv, boundary_check=(0, 1))\n b_pv = tl.load(p_pv, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_inter = tl.dot(b_do, b_hv.to(b_do.dtype), allow_tf32=False) * b_rv[\n None, :]\n b_intra = tl.dot(tl.where(m_s, tl.dot(b_do, b_v, allow_tf32=False),\n 0).to(b_v.dtype), b_cv, allow_tf32=False)\n b_dp = (b_inter + b_intra) * b_pv\n b_hv = b_hv * b_rv[None, :] + tl.dot(b_v, b_cv, allow_tf32=False)\n tl.store(p_dp, b_dp.to(p_dp.dtype.element_ty), boundary_check=(0, 1))\n p_v = tl.advance(p_v, (0, BT))\n p_rv = tl.advance(p_rv, (DM,))\n p_cv = tl.advance(p_cv, (BT, 0))\n p_pv = tl.advance(p_pv, (BT, 0))\n p_do = tl.advance(p_do, (BT, 0))\n p_dp = tl.advance(p_dp, (BT, 0))\n", "category": { "Functionality": [ "Matrix Multiplication", "Backpropagation", "Elementwise Operations", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "46b97460-47fd-4e2b-8f02-0a3f885ed908", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _multi_head_jagged_flash_attention_bwd_kernel(q_ptr, k_ptr, v_ptr,\n o_ptr, offset_ptr, dq_ptr, dk_ptr, dv_ptr, do_ptr, delta_ptr, lse_ptr,\n stride_qh, stride_qm, stride_qd, stride_kh, stride_kn, stride_kd,\n stride_vh, stride_vn, stride_vd, stride_oh, stride_om, stride_od,\n stride_lse_h, stride_delta_h, stride_dq_h, stride_dq_m, stride_dq_d,\n stride_dk_h, stride_dk_n, stride_dk_d, stride_dv_h, stride_dv_n,\n stride_dv_d, stride_do_h, stride_do_m, stride_do_d, num_heads: tl.\n constexpr, max_seq_len: tl.constexpr, D: tl.constexpr, allow_tf32: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_D: tl.\n constexpr):\n pid_bh = tl.program_id(axis=1)\n pid_batch = pid_bh // num_heads\n pid_head = pid_bh % num_heads\n begin = tl.load(offset_ptr + pid_batch)\n end = tl.load(offset_ptr + pid_batch + 1)\n seqlen = tl.minimum(end - begin, max_seq_len)\n if seqlen == 0:\n return\n pid_n = tl.program_id(axis=0)\n offs_d = tl.arange(0, BLOCK_D)\n offs_n = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n offs_m = tl.arange(0, BLOCK_M)\n q_ptrs = q_ptr + pid_head * stride_qh + begin * stride_qm + (offs_m[:,\n None] * stride_qm + offs_d[None, :] * stride_qd)\n k_ptrs = k_ptr + pid_head * stride_kh + begin * stride_kn + (offs_n[:,\n None] * stride_kn + offs_d[None, :] * stride_kd)\n v_ptrs = v_ptr + pid_head * stride_vh + begin * stride_vn + (offs_n[:,\n None] * stride_vn + offs_d[None, :] * stride_vd)\n do_ptrs = do_ptr + pid_head * stride_do_h + begin * stride_do_m + (\n offs_m[:, None] * stride_do_m + offs_d[None, :] * stride_do_d)\n k = tl.load(k_ptrs, mask=(offs_d[None, :] < D) & (offs_n[:, None] <\n seqlen), other=0.0)\n v = tl.load(v_ptrs, mask=(offs_d[None, :] < D) & (offs_n[:, None] <\n seqlen), other=0.0)\n dv = tl.zeros([BLOCK_N, BLOCK_D], dtype=tl.float32)\n dk = tl.zeros([BLOCK_N, BLOCK_D], dtype=tl.float32)\n for begin_m in range(0, seqlen, BLOCK_M):\n offs_m_curr = begin_m + offs_m\n q = tl.load(q_ptrs, mask=(offs_d[None, :] < D) & (offs_m_curr[:,\n None] < seqlen), other=0.0)\n qk = tl.dot(q, tl.trans(k), allow_tf32=allow_tf32)\n mn_mask = (offs_m_curr[:, None] < seqlen) & (offs_n[None, :] < seqlen)\n lse_i = tl.load(lse_ptr + pid_head * stride_lse_h + begin +\n offs_m_curr, mask=offs_m_curr < seqlen, other=float('inf'))\n p = tl.exp(qk - lse_i[:, None])\n p = tl.where(mn_mask, p, 0.0)\n p /= max_seq_len\n p = p.to(do_ptr.dtype.element_ty)\n do = tl.load(do_ptrs, mask=(offs_d[None, :] < D) & (offs_m_curr[:,\n None] < seqlen), other=0.0)\n dv += tl.dot(tl.trans(p), do, allow_tf32=allow_tf32)\n dp = tl.dot(do, tl.trans(v), allow_tf32=allow_tf32)\n Di = tl.load(delta_ptr + pid_head * stride_delta_h + begin +\n offs_m_curr, mask=offs_m_curr < seqlen)\n ds = p * (dp - Di[:, None] * max_seq_len)\n ds = ds.to(q_ptr.dtype.element_ty)\n dk += tl.dot(tl.trans(ds), q, allow_tf32=allow_tf32)\n q_ptrs += BLOCK_M * stride_qm\n do_ptrs += BLOCK_M * stride_do_m\n dk_ptrs = dk_ptr + pid_head * stride_dk_h + begin * stride_dk_n + (\n offs_n[:, None] * stride_dk_n + offs_d[None, :] * stride_dk_d)\n dv_ptrs = dv_ptr + pid_head * stride_dv_h + begin * stride_dv_n + (\n offs_n[:, None] * stride_dv_n + offs_d[None, :] * stride_dv_d)\n tl.store(dk_ptrs, dk, mask=(offs_d[None, :] < D) & (offs_n[:, None] <\n seqlen))\n tl.store(dv_ptrs, dv, mask=(offs_d[None, :] < D) & (offs_n[:, None] <\n seqlen))\n start_m = tl.program_id(axis=0) * BLOCK_M\n offs_m_curr = start_m + tl.arange(0, BLOCK_M)\n dq_ptrs_curr = dq_ptr + pid_head * stride_dq_h + begin * stride_dq_m + (\n offs_m_curr[:, None] * stride_dq_m + offs_d[None, :] * stride_dq_d)\n dq_curr = tl.zeros([BLOCK_M, BLOCK_D], dtype=tl.float32)\n q_ptrs_curr = q_ptr + pid_head * stride_qh + begin * stride_qm + (\n offs_m_curr[:, None] * stride_qm + offs_d[None, :] * stride_qd)\n q_curr = tl.load(q_ptrs_curr, mask=(offs_d[None, :] < D) & (offs_m_curr\n [:, None] < seqlen))\n lse_i_curr = tl.load(lse_ptr + pid_head * stride_lse_h + begin +\n offs_m_curr, mask=offs_m_curr < seqlen)\n do_ptrs_curr = do_ptr + pid_head * stride_do_h + begin * stride_do_m + (\n offs_m_curr[:, None] * stride_do_m + offs_d[None, :] * stride_do_d)\n do_curr = tl.load(do_ptrs_curr, mask=(offs_d[None, :] < D) & (\n offs_m_curr[:, None] < seqlen))\n Di_curr = tl.load(delta_ptr + pid_head * stride_delta_h + begin +\n offs_m_curr, mask=offs_m_curr < seqlen)\n block_start = 0\n while block_start < seqlen:\n offs_n_curr = block_start + tl.arange(0, BLOCK_N)\n k_ptrs_curr = k_ptr + pid_head * stride_kh + begin * stride_kn + (\n offs_n_curr[:, None] * stride_kn + offs_d[None, :] * stride_kd)\n v_ptrs_curr = v_ptr + pid_head * stride_vh + begin * stride_vn + (\n offs_n_curr[:, None] * stride_vn + offs_d[None, :] * stride_vd)\n k_curr = tl.load(k_ptrs_curr, mask=(offs_d[None, :] < D) & (\n offs_n_curr[:, None] < seqlen))\n v_curr = tl.load(v_ptrs_curr, mask=(offs_d[None, :] < D) & (\n offs_n_curr[:, None] < seqlen))\n qk_curr = tl.dot(q_curr, tl.trans(k_curr), allow_tf32=allow_tf32)\n mn_mask_curr = (offs_m_curr[:, None] < seqlen) & (offs_n_curr[None,\n :] < seqlen)\n p_curr = tl.exp(qk_curr - lse_i_curr[:, None])\n p_curr = tl.where(mn_mask_curr, p_curr, 0.0)\n p_curr /= max_seq_len\n dp_curr = tl.dot(do_curr, tl.trans(v_curr), allow_tf32=allow_tf32)\n ds_curr = p_curr * (dp_curr - Di_curr[:, None] * max_seq_len)\n ds_curr = ds_curr.to(k_ptr.dtype.element_ty)\n dq_curr += tl.dot(ds_curr, k_curr, allow_tf32=allow_tf32)\n block_start += BLOCK_N\n tl.store(dq_ptrs_curr, dq_curr, mask=(offs_d[None, :] < D) & (\n offs_m_curr[:, None] < seqlen))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "62678117-b269-40bc-af2e-e8df801e151a", "file_name": "addition.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/addition.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _AddStats_cl3d_backward_impl(Addgrad_ptr, Meangrad_ptr, Sqmeangrad_ptr,\n Sum_ptr, Outputgrad_ptr, numel, numel_no_channels, BLOCK_SIZE: tl.\n constexpr, num_channels: tl.constexpr, block_other: tl.constexpr):\n pid = tl.program_id(0)\n Addgrad_ptr += pid * BLOCK_SIZE\n Sum_ptr += pid * BLOCK_SIZE\n Outputgrad_ptr += pid * BLOCK_SIZE\n channels_offset = tl.arange(0, num_channels)\n other_offset = tl.arange(0, block_other)\n offset = channels_offset[None, :] + other_offset[:, None] * num_channels\n mask = (other_offset < numel_no_channels - pid * block_other)[:, None]\n sum = tl.load(Sum_ptr + offset, mask=mask, other=0.0)\n add_grad = tl.load(Addgrad_ptr + offset, mask=mask, other=0.0)\n mean_grad = tl.load(Meangrad_ptr + channels_offset[None, :])\n sqmean_grad = tl.load(Sqmeangrad_ptr + channels_offset[None, :])\n sqmean_grad_part = 2 * sum.to(tl.float32) * sqmean_grad / numel_no_channels\n mean_grad_part = mean_grad / numel_no_channels\n grad = add_grad + sqmean_grad_part + mean_grad_part\n grad = grad.to(tl.float16)\n tl.store(Outputgrad_ptr + offset, grad, mask=mask)\n", "category": { "Functionality": [ "Backpropagation", "Normalization", "Elementwise Operations" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/addition.py" }, { "uuid": "50f8d2cb-95bb-458d-a7f1-0ea3a9eb20e2", "file_name": "fused_cross_entropy.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/fused_cross_entropy.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'HAS_SMOOTHING': lambda args: args['label_smoothing'] >\n 0.0})\n@triton.jit\ndef cross_entropy_fwd_kernel(loss_ptr, lse_ptr, z_loss_ptr, logits_ptr,\n labels_ptr, label_smoothing, logit_scale, lse_square_scale,\n ignore_index, total_classes, class_start_idx, n_cols, n_rows,\n logits_row_stride, BLOCK_SIZE: tl.constexpr, HAS_SMOOTHING: tl.\n constexpr, SPLIT: tl.constexpr):\n row_idx = tl.program_id(0)\n col_block_idx = tl.program_id(1)\n logits_ptr = logits_ptr + row_idx * logits_row_stride.to(tl.int64)\n col_offsets = col_block_idx * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n label_idx = tl.load(labels_ptr + row_idx)\n logits = tl.load(logits_ptr + col_offsets, mask=col_offsets < n_cols,\n other=-float('inf'))\n logits = logits.to(tl.float32) * logit_scale\n max_logits = tl.max(logits, 0)\n if HAS_SMOOTHING:\n sum_logits = tl.sum(tl.where(col_offsets < n_cols, logits, 0.0), 0)\n lse = tl.log(tl.sum(tl.exp(logits - max_logits), 0)) + max_logits\n tl.store(lse_ptr + col_block_idx * n_rows + row_idx, lse)\n if label_idx == ignore_index:\n loss = 0.0\n z_loss = 0.0\n else:\n label_idx -= class_start_idx\n if label_idx >= col_block_idx * BLOCK_SIZE and label_idx < min(n_cols,\n (col_block_idx + 1) * BLOCK_SIZE):\n logits_label = tl.load(logits_ptr + label_idx) * logit_scale\n if HAS_SMOOTHING:\n loss = (lse if not SPLIT else 0.0\n ) - label_smoothing * sum_logits / total_classes - (1 -\n label_smoothing) * logits_label\n else:\n loss = (lse if not SPLIT else 0.0) - logits_label\n elif HAS_SMOOTHING:\n loss = label_smoothing * ((lse if not SPLIT else 0.0) - \n sum_logits / total_classes)\n else:\n loss = 0.0\n if not SPLIT:\n z_loss = lse_square_scale * lse * lse\n loss += z_loss\n else:\n z_loss = 0.0\n tl.store(loss_ptr + col_block_idx * n_rows + row_idx, loss)\n if not SPLIT:\n tl.store(z_loss_ptr + col_block_idx * n_rows + row_idx, z_loss)\n", "category": { "Functionality": [ "Softmax", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/fused_cross_entropy.py" }, { "uuid": "908d9a97-c88c-4037-834b-8db2531abaa4", "file_name": "y_1.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_1.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef first_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor, block_size:\n tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.constexpr,\n col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST_00 = tl.sqrt(3.0)\n Y10 = CONST_00 * x\n Y11 = CONST_00 * y\n Y12 = CONST_00 * z\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y10, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y11, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y12, mask=\n output_row_offset + 2 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_1.py" }, { "uuid": "8f18db57-d2fd-4917-988c-68e1b2c06a4f", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef store_2d(vals, ptr, sz0: tl.constexpr, sz1: tl.constexpr, n0, n1, max0,\n max1, stride0=None, stride1=1):\n \"\"\"Store 2d block into (n0,n1)th chunk of matrix (defined by ptr), where each chunk has size (sz0, sz1)\"\"\"\n stride0 = stride0 or sz1\n offs0 = get_1d_offest(sz0, n0)\n offs1 = get_1d_offest(sz1, n1)\n offs = get_2d_offset(offs0, offs1, stride0, stride1)\n mask = get_2d_mask(offs0, offs1, max0, max1)\n tl.store(ptr + offs, vals, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "df8f566b-5179-4d60-9c4b-96a961c77a70", "file_name": "softmax_split.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_split.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef logsumexp_kernel(out_ptr, in_ptr, M, N, TILE_N: tl.constexpr):\n pid_n = tl.program_id(0)\n num_programs_n = tl.num_programs(0)\n pid_m = tl.program_id(1)\n n_offsets = pid_n * TILE_N + tl.arange(0, TILE_N)\n mask = n_offsets < N\n offset = pid_m * N + n_offsets\n inp = tl.load(in_ptr + offset, mask=mask, other=-float('inf')).to(out_ptr\n .dtype.element_ty)\n m = tl.max(inp, 0)\n e = tl.exp(inp - m)\n z = tl.sum(e, 0)\n logz = m + tl.log(z)\n output_ptrs = out_ptr + pid_m * num_programs_n + pid_n\n tl.store(output_ptrs, logz)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_split.py" }, { "uuid": "92000632-b05c-45c6-918d-cc07885d8e64", "file_name": "10-experimental-tma-store-matrix-multiplication.py", "repo_name": "hgl71964/SIP", "file_path": "benchmarks/10-experimental-tma-store-matrix-multiplication.py", "commit_hash": "767ed720d4bd5cee21670b125b62c434258c532b", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 128,\n 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 8}, num_stages\n =7, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel(a_ptr, b_ptr, c_ptr, M, N, K, stride_am, stride_ak,\n stride_bk, stride_bn, stride_cm, stride_cn, BLOCK_SIZE_M: tl.constexpr,\n BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE_M:\n tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n block_offset_m = pid_m * BLOCK_SIZE_M\n block_offset_n = pid_n * BLOCK_SIZE_N\n a_tile_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(block_offset_m, 0), block_shape=(\n BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_tile_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, block_offset_n), block_shape=(\n BLOCK_SIZE_K, BLOCK_SIZE_N), order=(0, 1))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_tile_ptr)\n b = tl.load(b_tile_ptr)\n accumulator += tl.dot(a, b)\n a_tile_ptr = tl.advance(a_tile_ptr, [0, BLOCK_SIZE_K])\n b_tile_ptr = tl.advance(b_tile_ptr, [BLOCK_SIZE_K, 0])\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(block_offset_m, block_offset_n),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n tl.store(c_block_ptr, accumulator)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled", "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/hgl71964/SIP/blob/767ed720d4bd5cee21670b125b62c434258c532b/benchmarks/10-experimental-tma-store-matrix-multiplication.py" }, { "uuid": "b957f60e-0bd5-47bd-acd6-2d465af4466c", "file_name": "chunk_h_split.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_split.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_FINAL_STATE': lambda args: args['ht'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=['BT', 'USE_G',\n 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_fwd_kernel_h_reduction(g, gk, gv, hs, hr, ht, offsets,\n split_offsets, T: tl.constexpr, S: tl.constexpr, H: tl.constexpr, K: tl\n .constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl\n .constexpr, USE_G: tl.constexpr, USE_GK: tl.constexpr, USE_GV: tl.\n constexpr, STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr,\n HEAD_FIRST: tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NS = tl.cdiv(T, S)\n boh = tl.load(split_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NS = tl.cdiv(T, S)\n boh = i_n * NS\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n for i_s in range(1, NS):\n p_hs = tl.make_block_ptr(hs + ((boh + i_s - 1) * H + i_h) * K * V,\n (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_hr = tl.make_block_ptr(hr + ((boh + i_s) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_hs, boundary_check=(0, 1)).to(tl.float32)\n tl.store(p_hr, b_h.to(p_hr.dtype.element_ty), boundary_check=(0, 1))\n for i_t in range(tl.cdiv(i_s * S, BT), tl.cdiv(min(i_s * S + S, T), BT)\n ):\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_nh * T + last_idx)\n else:\n b_g_last = tl.load(g + bos * H + last_idx * H + i_h)\n b_h *= tl.exp(b_g_last)\n if USE_GK:\n if HEAD_FIRST:\n p_gk_last = (gk + i_nh * T * K + last_idx * K + i_k *\n BK + tl.arange(0, BK))\n else:\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK\n )\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0,\n BK) < K, other=0.0)\n b_h *= tl.exp(b_gk_last)[:, None]\n if USE_GV:\n if HEAD_FIRST:\n p_gv_last = (gv + i_nh * T * V + last_idx * V + i_v *\n BV + tl.arange(0, BV))\n else:\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV\n )\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0,\n BV) < V, other=0.0)\n b_h *= tl.exp(b_gv_last)[None, :]\n if NS > 1:\n if STORE_FINAL_STATE:\n p_hs = tl.make_block_ptr(hs + ((boh + NS - 1) * H + i_h) * K *\n V, (K, V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_hs, boundary_check=(0, 1)).to(tl.float32)\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1)\n )\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_split.py" }, { "uuid": "19ce5a53-d804-465c-95c2-1902ab6d7de8", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BC'])\n@triton.jit\ndef chunk_rwkv6_fwd_A_kernel_intra_sub_intra_merge(A, A2, offsets, indices,\n B: tl.constexpr, T: tl.constexpr, H: tl.constexpr, BT: tl.constexpr, BC:\n tl.constexpr, NK: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_t, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n if i_t * BT + i_c * BC >= T:\n return\n b_A = tl.zeros([BC, BC], dtype=tl.float32)\n for i_k in range(0, NK):\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + (i_k * B * H + i_bh) * T * BC, (T,\n BC), (BC, 1), (i_t * BT + i_c * BC, 0), (BC, BC), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (i_k * all + bos) * H * BC + i_h *\n BC, (T, BC), (H * BC, 1), (i_t * BT + i_c * BC, 0), (BC, BC\n ), (1, 0))\n b_A += tl.load(p_A, boundary_check=(0, 1))\n if HEAD_FIRST:\n p_A2 = tl.make_block_ptr(A2 + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_c * BC, i_c * BC), (BC, BC), (1, 0))\n else:\n p_A2 = tl.make_block_ptr(A2 + (bos * H + i_h) * BT, (T, BT), (H *\n BT, 1), (i_t * BT + i_c * BC, i_c * BC), (BC, BC), (1, 0))\n tl.store(p_A2, b_A.to(A2.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "cdc37f44-be66-44db-8bec-5e91db230ff7", "file_name": "_quantize.py", "repo_name": "IBM/qattn", "file_path": "qattn/nn/functional/_quantize.py", "commit_hash": "07ceda0aceb9afd299d622325944c0c0471827fe", "starcount": 0, "input": "@triton.jit\ndef dequantize(x: tl.tensor, scale: tl.tensor) ->tl.tensor:\n \"\"\"Dequantize quantized tensor to floating point.\n\n Args:\n x (tl.tensor): quantized tensor.\n scale (tl.tensor): quantization scaling factor\n\n Returns:\n tl.tensor: Dequantized floating-point tensor.\n \"\"\"\n return (x * scale).to(tl.float32)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/IBM/qattn/blob/07ceda0aceb9afd299d622325944c0c0471827fe/qattn/nn/functional/_quantize.py" }, { "uuid": "fba78c1a-b444-4758-891c-009b933f193d", "file_name": "conv.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/conv.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@conv_heuristics()\n@triton.jit\ndef _kernel_delta_x_hwc(x, w, bias, y, stride_xn, stride_xc, stride_xh,\n stride_xw, stride_wn, stride_wc, stride_wh, stride_ww, stride_yn,\n stride_yc, stride_yh, stride_yw, delta_xh_ptr, delta_xw_ptr,\n delta_xc_ptr, BATCH, IN_C, IN_H, IN_W, KERNEL_N, KERNEL_H, KERNEL_W,\n OUT_H, OUT_W, stride_h, stride_w, padding_h, padding_w, dilation_h,\n dilation_w, output_padding_h, output_padding_w, groups, ACC_TYPE: tl.\n constexpr, CONV1X1_NHWC: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N:\n tl.constexpr, BLOCK_K: tl.constexpr, GROUP_H: tl.constexpr, WITH_BIAS:\n tl.constexpr):\n \"\"\"\n each program instance computes a [BLOCK_BATCH, BLOCK_N, BLOCK_H, BLOCK_W] block of y\n \"\"\"\n pid_nhw = tl.program_id(0)\n pid_k = tl.program_id(1)\n off_y_k = pid_k * BLOCK_N + tl.arange(0, BLOCK_N)\n off_y_nhw = pid_nhw * BLOCK_M + tl.arange(0, BLOCK_M)\n off_y_n = off_y_nhw // (OUT_H * OUT_W)\n off_y_hw = off_y_nhw % (OUT_H * OUT_W)\n off_y_h = off_y_hw // OUT_W + output_padding_h\n off_y_w = off_y_hw % OUT_W + output_padding_w\n off_x_n = off_y_n\n off_x_h = off_y_h * stride_h - padding_h\n off_x_w = off_y_w * stride_w - padding_w\n off_x_nhw = off_x_n * stride_xn + off_x_h * stride_xh + off_x_w * stride_xw\n off_x_crs = tl.arange(0, BLOCK_K)\n CRS = IN_C * KERNEL_H * KERNEL_W\n if not CONV1X1_NHWC:\n delta_xh_ptrs = delta_xh_ptr + off_x_crs\n delta_xw_ptrs = delta_xw_ptr + off_x_crs\n delta_xc_ptrs = delta_xc_ptr + off_x_crs\n delta_xh = tl.load(delta_xh_ptrs, mask=off_x_crs < CRS, other=0)\n delta_xw = tl.load(delta_xw_ptrs, mask=off_x_crs < CRS, other=0)\n delta_xc = tl.load(delta_xc_ptrs, mask=off_x_crs < CRS, other=0)\n off_x_crs_unpacked = (delta_xh * stride_xh + delta_xw * stride_xw +\n delta_xc * stride_xc)\n x_ptrs = x + off_x_nhw[:, None] + off_x_crs_unpacked[None, :]\n else:\n x_ptrs = x + off_x_nhw[:, None] + off_x_crs[None, :]\n delta_xh = 0\n delta_xw = 0\n mask_x = (off_x_n < BATCH)[:, None] & (off_x_crs < CRS)[None, :] & (\n off_x_h[:, None] + delta_xh[None, :] >= 0) & (off_x_h[:, None] +\n delta_xh[None, :] < IN_H) & (off_x_w[:, None] + delta_xw[None, :] >= 0\n ) & (off_x_w[:, None] + delta_xw[None, :] < IN_W)\n off_w_crs = tl.arange(0, BLOCK_K)\n off_w_k = off_y_k\n w_ptrs = w + off_w_crs[:, None] + off_w_k[None, :] * stride_wn\n mask_w = (off_x_crs < CRS)[:, None] & (off_w_k < KERNEL_N)[None, :]\n matrix_x = tl.load(x_ptrs, mask=mask_x, other=0.0)\n matrix_w = tl.load(w_ptrs, mask=mask_w, other=0.0)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=ACC_TYPE)\n for crs in range(0, CRS, BLOCK_K):\n acc += tl.dot(matrix_x, matrix_w, out_dtype=ACC_TYPE)\n w_ptrs += BLOCK_K\n off_x_crs = crs + BLOCK_K + tl.arange(0, BLOCK_K)\n if not CONV1X1_NHWC:\n delta_xh_ptrs += BLOCK_K\n delta_xw_ptrs += BLOCK_K\n delta_xc_ptrs += BLOCK_K\n delta_xh = tl.load(delta_xh_ptrs, mask=off_x_crs < CRS, other=0)\n delta_xw = tl.load(delta_xw_ptrs, mask=off_x_crs < CRS, other=0)\n delta_xc = tl.load(delta_xc_ptrs, mask=off_x_crs < CRS, other=0)\n off_x_crs_unpacked = (delta_xh * stride_xh + delta_xw *\n stride_xw + delta_xc * stride_xc)\n x_ptrs = x + off_x_nhw[:, None] + off_x_crs_unpacked[None, :]\n else:\n x_ptrs += BLOCK_K\n mask_x = (off_x_n < BATCH)[:, None] & (off_x_crs < CRS)[None, :] & (\n off_x_h[:, None] + delta_xh[None, :] >= 0) & (off_x_h[:, None] +\n delta_xh[None, :] < IN_H) & (off_x_w[:, None] + delta_xw[None,\n :] >= 0) & (off_x_w[:, None] + delta_xw[None, :] < IN_W)\n mask_w = (off_x_crs < CRS)[:, None] & (off_w_k < KERNEL_N)[None, :]\n matrix_x = tl.load(x_ptrs, mask=mask_x, other=0.0)\n matrix_w = tl.load(w_ptrs, mask=mask_w, other=0.0)\n if WITH_BIAS:\n acc += tl.load(bias + off_y_k)[None, :]\n acc = acc.to(y.dtype.element_ty)\n off_y_k = pid_k * BLOCK_N + tl.arange(0, BLOCK_N)\n off_y_nhw = pid_nhw * BLOCK_M + tl.arange(0, BLOCK_M)\n off_y_n = off_y_nhw // (OUT_H * OUT_W)\n off_y_hw = off_y_nhw % (OUT_H * OUT_W)\n off_y_h = off_y_hw // OUT_W + output_padding_h\n off_y_w = off_y_hw % OUT_W + output_padding_w\n y_ptrs = y + off_y_n[:, None] * stride_yn + off_y_h[:, None\n ] * stride_yh + off_y_w[:, None] * stride_yw + off_y_k[None, :\n ] * stride_yc\n mask_y = (off_y_n < BATCH)[:, None] & (off_y_h < OUT_H + output_padding_h)[\n :, None] & (off_y_w < OUT_W + output_padding_w)[:, None] & (off_y_k <\n KERNEL_N)[None, :]\n tl.store(y_ptrs, acc, mask=mask_y)\n return\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/conv.py" }, { "uuid": "c0a72086-6095-4821-ae15-cdbb362b3308", "file_name": "cluster_test.py", "repo_name": "jax-ml/jax-triton", "file_path": "tests/cluster_test.py", "commit_hash": "859cc392bec876d132bd0790ea6c00b6c246dd2b", "starcount": 0, "input": "@triton.jit\ndef dummy_kernel(x_ptr, o_ptr):\n offs = tl.program_id(axis=0) * 4 + tl.arange(0, 4)\n tl.store(o_ptr + offs, tl.load(x_ptr + offs))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/jax-ml/jax-triton/blob/859cc392bec876d132bd0790ea6c00b6c246dd2b/tests/cluster_test.py" }, { "uuid": "99f349d5-d5b7-4d07-b2cd-6f21651e8219", "file_name": "flash_attention.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/flash_attention.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel(Q, K, V, S, Out, sm_scale, TMP, L, M, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_kn, stride_kk,\n stride_vz, stride_vh, stride_vn, stride_vk, stride_oz, stride_oh,\n stride_om, stride_ok, stride_tz, stride_th, stride_tm, stride_lz,\n stride_lh, stride_lm, stride_mz, stride_mh, stride_mm, M_Q, N_CTX,\n BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.\n constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr, CAUSAL: tl.\n constexpr, USE_ALIBI: tl.constexpr):\n start_m = tl.program_id(0) * BLOCK_M\n off_h = tl.program_id(1)\n off_z = tl.program_id(2)\n offs_m = start_m + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n off_q = off_z * stride_qz + off_h * stride_qh + offs_m[:, None\n ] * stride_qm + offs_d[None, :] * stride_qk\n off_k = off_z * stride_kz + off_h * stride_kh + offs_n[:, None\n ] * stride_kn + offs_d[None, :] * stride_kk\n off_v = off_z * stride_vz + off_h * stride_vh + offs_n[:, None\n ] * stride_vn + offs_d[None, :] * stride_vk\n q_ptrs = Q + off_q\n k_ptrs = K + off_k\n v_ptrs = V + off_v\n t_ptrs = TMP + off_z * stride_tz + off_h * stride_th + offs_m * stride_tm\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n if EVEN_M:\n q = tl.load(q_ptrs)\n else:\n q = tl.load(q_ptrs, mask=offs_m[:, None] < M_Q, other=0)\n q = q.to(tl.float16)\n if USE_ALIBI:\n slope = tl.load(S + off_h)\n if CAUSAL & EVEN_M & EVEN_N:\n bound = start_m + BLOCK_M\n else:\n bound = N_CTX\n for start_n in range(0, bound, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_N:\n k = tl.load(k_ptrs)\n else:\n k = tl.load(k_ptrs, mask=start_n + offs_n[:, None] < N_CTX, other=0\n )\n k = k.to(tl.float16)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k, trans_b=True)\n qk *= sm_scale\n if USE_ALIBI & CAUSAL:\n qk += causal_alibi_mask(slope, offs_m, start_n + offs_n, M_Q,\n N_CTX, EVEN_M, EVEN_N)\n elif USE_ALIBI:\n qk += symmetric_alibi_mask(slope, offs_m, start_n + offs_n, M_Q,\n N_CTX, EVEN_M, EVEN_N)\n elif CAUSAL:\n qk += causal_mask(offs_m, start_n + offs_n, M_Q, N_CTX, EVEN_M,\n EVEN_N)\n else:\n qk += bounds_mask(offs_m, start_n + offs_n, M_Q, N_CTX, EVEN_M,\n EVEN_N)\n m_ij = tl.maximum(tl.max(qk, axis=1), -10000)\n p = tl.exp(qk - m_ij[:, None])\n l_ij = tl.sum(p, axis=1)\n m_i_new = tl.maximum(m_i, m_ij)\n alpha = tl.exp(m_i - m_i_new)\n beta = tl.exp(m_ij - m_i_new)\n l_i_new = alpha * l_i + beta * l_ij\n p_scale = beta / l_i_new\n p = p * p_scale[:, None]\n acc_scale = l_i / l_i_new * alpha\n tl.store(t_ptrs, acc_scale)\n acc_scale = tl.load(t_ptrs)\n acc = acc * acc_scale[:, None]\n if EVEN_N:\n v = tl.load(v_ptrs)\n else:\n v = tl.load(v_ptrs, mask=start_n + offs_n[:, None] < N_CTX, other=0\n )\n v = v.to(tl.float16)\n p = p.to(tl.float16)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n v_ptrs += BLOCK_N * stride_vn\n k_ptrs += BLOCK_N * stride_kn\n offs_m = tl.program_id(0) * BLOCK_M + tl.arange(0, BLOCK_M)\n l_ptrs = L + off_z * stride_lz + off_h * stride_lh + offs_m * stride_lm\n m_ptrs = M + off_z * stride_mz + off_h * stride_mh + offs_m * stride_mm\n if EVEN_M:\n tl.store(l_ptrs, l_i)\n tl.store(m_ptrs, m_i)\n else:\n tl.store(l_ptrs, l_i, mask=offs_m < M_Q)\n tl.store(m_ptrs, m_i, mask=offs_m < M_Q)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n off_o = off_z * stride_oz + off_h * stride_oh + offs_m[:, None\n ] * stride_om + offs_d[None, :] * stride_ok\n out_ptrs = Out + off_o\n if EVEN_M:\n tl.store(out_ptrs, acc)\n else:\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < M_Q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/flash_attention.py" }, { "uuid": "e528bce6-ce8b-4667-9ce7-53bb2e0fbc58", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_dk(q, k, rk, ck, ds, dk, dsk, s_qk_h, s_qk_t,\n s_qk_d, s_sk_h, s_sk_t, s_sk_m, T, BT: tl.constexpr, BK: tl.constexpr,\n BM: tl.constexpr, DK: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_k, i_m, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n p_q = tl.make_block_ptr(q + i_bh * s_qk_h, (T, DK), (s_qk_t, s_qk_d), (\n (NT - 1) * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_qk_h, (DK, T), (s_qk_d, s_qk_t), (\n i_k * BK, (NT - 1) * BT), (BK, BT), (0, 1))\n p_rk = tl.make_block_ptr(rk + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_ck = tl.make_block_ptr(ck + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n ((NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n p_ds = tl.make_block_ptr(ds + i_bh * s_sk_h, (DM, T), (s_sk_m, s_sk_t),\n (i_m * BM, (NT - 1) * BT), (BM, BT), (0, 1))\n p_dk = tl.make_block_ptr(dk + (i_m * n_bh + i_bh) * s_qk_h, (T, DK), (\n s_qk_t, s_qk_d), ((NT - 1) * BT, i_k * BK), (BT, BK), (1, 0))\n p_dsk = tl.make_block_ptr(dsk + (i_k * n_bh + i_bh) * s_sk_h, (T, DM),\n (s_sk_t, s_sk_m), ((NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_s, m_t = o_i[:, None] <= o_i[None, :], o_i[:, None] >= o_i[None, :]\n b_dhk = tl.zeros([BM, BK], dtype=tl.float32)\n for i in range(NT):\n p_rk = tl.make_block_ptr(rk + i_bh * s_sk_t * NT, (NT * DM,), (\n s_sk_m,), ((NT - i) % NT * DM + i_m * BM,), (BM,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_rk = tl.load(p_rk, boundary_check=(0,))\n b_ck = tl.load(p_ck, boundary_check=(0, 1))\n b_ds = tl.load(p_ds, boundary_check=(0, 1))\n b_inter = tl.dot((b_ck * b_rk[None, :]).to(b_q.dtype), b_dhk.to(b_q\n .dtype), allow_tf32=False)\n b_intra = tl.dot(tl.where(m_s, tl.dot(b_ck, b_ds, allow_tf32=False),\n 0.0).to(b_q.dtype), b_q, allow_tf32=False)\n b_dk = b_inter + b_intra\n b_inter = tl.dot(b_dhk.to(b_k.dtype), b_k, allow_tf32=False) * b_rk[\n :, None]\n b_intra = tl.dot(b_ds, tl.where(m_t, tl.dot(b_q, b_k, allow_tf32=\n False), 0.0).to(b_q.dtype), allow_tf32=False)\n b_dsk = b_ck * tl.trans(b_inter + b_intra)\n b_dhk = b_dhk * b_rk[:, None] + tl.dot(b_ds, b_q, allow_tf32=False)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dsk, b_dsk.to(p_dsk.dtype.element_ty), boundary_check=(0, 1)\n )\n p_q = tl.advance(p_q, (-BT, 0))\n p_k = tl.advance(p_k, (0, -BT))\n p_ck = tl.advance(p_ck, (-BT, 0))\n p_ds = tl.advance(p_ds, (0, -BT))\n p_dk = tl.advance(p_dk, (-BT, 0))\n p_dsk = tl.advance(p_dsk, (-BT, 0))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "47a0737b-519d-4b88-a3af-0251a50b9828", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/linear_attn/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_linear_attn_bwd_kernel(q, k, v, do, dq, dk, dv, h0,\n s_k_h, s_v_h, scale, B, H, T, K: tl.constexpr, V: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, USE_INITIAL_STATE: tl.constexpr):\n i_v, i_k, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK)\n p_v = v + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_do = do + i_bh * s_v_h + i_v * BV + tl.arange(0, BV)\n p_dq = dq + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(0, BK)\n mask_bk = i_k * BK + tl.arange(0, BK) < K\n mask_bv = i_v * BV + tl.arange(0, BV) < V\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n if USE_INITIAL_STATE:\n mask_kv = mask_bk[:, None] & mask_bv[None, :]\n p_h0 = h0 + i_bh * K * V + (i_k * BK + tl.arange(0, BK)[:, None]\n ) * V + (i_v * BV + tl.arange(0, BV)[None, :])\n b_h += tl.load(p_h0, mask=mask_kv, other=0).to(tl.float32)\n for _ in range(0, T):\n b_k = tl.load(p_k, mask=mask_bk, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_bv, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_bv, other=0).to(tl.float32)\n b_h += b_k[:, None] * b_v[None, :]\n _d_q = b_h * b_do[None, :]\n d_q = tl.sum(_d_q, axis=1) * scale\n tl.store(p_dq, d_q.to(p_dq.dtype.element_ty), mask=mask_bk)\n p_k += K\n p_do += V\n p_v += V\n p_dq += K\n tl.debug_barrier()\n p_q = q + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_k = k + i_bh * s_k_h + i_k * BK + tl.arange(0, BK) + (T - 1) * K\n p_do = do + i_bh * s_v_h + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_v = v + i_bh * s_v_h + i_v * BV + tl.arange(0, BV) + (T - 1) * V\n p_dk = dk + (i_bh + i_v * B * H) * s_k_h + i_k * BK + tl.arange(0, BK) + (T\n - 1) * K\n p_dv = dv + (i_bh + i_k * B * H) * s_v_h + i_v * BV + tl.arange(0, BV) + (T\n - 1) * V\n d_h = tl.zeros([BK, BV], dtype=tl.float32)\n for _ in range(T):\n b_do = tl.load(p_do, mask=mask_bv, other=0).to(tl.float32)\n b_q = tl.load(p_q, mask=mask_bk, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_bk, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_bv, other=0).to(tl.float32)\n d_h += b_q[:, None] * b_do[None, :]\n d_k = tl.sum(d_h * b_v[None, :], axis=1)\n d_v = tl.sum(d_h * b_k[:, None], axis=0)\n tl.store(p_dk, d_k.to(p_dk.dtype.element_ty), mask=mask_bk)\n tl.store(p_dv, d_v.to(p_dv.dtype.element_ty), mask=mask_bv)\n p_do -= V\n p_q -= K\n p_k -= K\n p_v -= V\n p_dk -= K\n p_dv -= V\n", "category": { "Functionality": [ "Attention Mechanisms", "Recurrent Neural Networks", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/linear_attn/fused_recurrent.py" }, { "uuid": "47931159-10d0-421b-8cec-3607da49ce15", "file_name": "scratch.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/scratch.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef apply_dropout(x, offsets, p, seed, mask_val=0.0):\n scale = 1 / (1 - p)\n rand = tl.rand(seed, offsets)\n return tl.where(rand > p, x * scale, mask_val)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/scratch.py" }, { "uuid": "3dcdbcd6-e7fc-47f6-a45e-152876ac2a6c", "file_name": "gemm_postop_gelu_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=2, num_warps=32), triton.Config({'BLOCK_SIZE_M': \n 256, 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4,\n 'grf_mode': 'large'}, num_stages=3, num_warps=32), triton.Config({\n 'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32),\n triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K':\n 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=2, num_warps=32\n ), triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512,\n 'BLOCK_SIZE_K': 64, 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages\n =2, num_warps=32)], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers(a_ptr, b_ptr, c_ptr, M: tl.constexpr,\n N: tl.constexpr, K: tl.constexpr, stride_am: tl.constexpr, stride_ak:\n tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.constexpr,\n stride_cm: tl.constexpr, stride_cn: tl.constexpr, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n a_block_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c = gelu(accumulator)\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_postop_gelu_benchmark.py" }, { "uuid": "c2013b8d-c916-45ca-9e2e-44a7016851d9", "file_name": "swiglu.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/swiglu.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_swiglu_forward(input_a_ptr, input_b_ptr, output_ptr, row_stride,\n num_columns: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n prog_id = tl.program_id(0).to(tl.int64)\n input_a_ptr += prog_id * row_stride\n input_b_ptr += prog_id * row_stride\n output_ptr += prog_id * row_stride\n column_offsets = tl.arange(0, BLOCK_SIZE)\n active_mask = column_offsets < num_columns\n input_a_row = tl.load(input_a_ptr + column_offsets, mask=active_mask,\n other=0).to(tl.float32)\n input_b_row = tl.load(input_b_ptr + column_offsets, mask=active_mask,\n other=0)\n result_row = silu(input_a_row) * input_b_row\n tl.store(output_ptr + column_offsets, result_row, mask=active_mask)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/swiglu.py" }, { "uuid": "852c0812-545a-4d54-a311-09ef7b9a1c60", "file_name": "gemm_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 256,\n 'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode':\n 'large'}, num_stages=s, num_warps=32) for s in [1, 2, 3]] + [triton.\n Config({'BLOCK_SIZE_M': 256, 'BLOCK_SIZE_N': 128, 'BLOCK_SIZE_K': 32,\n 'GROUP_SIZE_M': 4, 'grf_mode': 'large'}, num_stages=s, num_warps=32) for\n s in [2, 3, 4]] + [triton.Config({'BLOCK_SIZE_M': 64, 'BLOCK_SIZE_N': \n 128, 'BLOCK_SIZE_K': 32, 'GROUP_SIZE_M': 4, 'grf_mode': 'large'},\n num_stages=s, num_warps=32) for s in [2]] + [triton.Config({\n 'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N': 512, 'BLOCK_SIZE_K': 64,\n 'GROUP_SIZE_M': 1, 'grf_mode': 'large'}, num_stages=s, num_warps=32) for\n s in [2, 3]], key=['M', 'N', 'K'])\n@triton.jit\ndef matmul_kernel_with_block_pointers(a_ptr, b_ptr, c_ptr, M: tl.constexpr,\n N: tl.constexpr, K: tl.constexpr, stride_am: tl.constexpr, stride_ak:\n tl.constexpr, stride_bk: tl.constexpr, stride_bn: tl.constexpr,\n stride_cm: tl.constexpr, stride_cn: tl.constexpr, BLOCK_SIZE_M: tl.\n constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr,\n GROUP_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n a_block_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_block_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, K, BLOCK_SIZE_K):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n accumulator += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n c = accumulator.to(tl.float32)\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=(1, 0))\n tl.store(c_block_ptr, c, boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_benchmark.py" }, { "uuid": "8fca3bd0-a9e4-43f9-9d3d-89cfd7925602", "file_name": "bnrelu.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/bnrelu.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _ApplyBNReLU_cl3d_impl(X_ptr, Out_ptr, Weight_ptr, Bias_ptr,\n numel_no_channels, BLOCK_SIZE: tl.constexpr, num_channels: tl.constexpr,\n block_other: tl.constexpr):\n pid = tl.program_id(0)\n X_ptr += pid * BLOCK_SIZE\n Out_ptr += pid * BLOCK_SIZE\n channels_offset = tl.arange(0, num_channels)\n other_offset = tl.arange(0, block_other)\n offset = channels_offset[None, :] + other_offset[:, None] * num_channels\n mask = (other_offset < numel_no_channels - pid * block_other)[:, None]\n x = tl.load(X_ptr + offset, mask=mask, other=0).to(tl.float32)\n weight = tl.load(Weight_ptr + channels_offset[None, :])\n bias = tl.load(Bias_ptr + channels_offset[None, :])\n output = x * weight + bias\n output = tl.maximum(output, 0.0)\n tl.store(Out_ptr + offset, output, mask=mask)\n", "category": { "Functionality": [ "Normalization", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/bnrelu.py" }, { "uuid": "817c1276-c556-4c1d-b4c5-f46a380bd438", "file_name": "test_autodiff.py", "repo_name": "srush/triton-autodiff", "file_path": "tests/test_autodiff.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef tr2(X, dX, dY):\n r = tl.arange(0, 16)\n r2 = tl.arange(0, 16)[:, None]\n x = tl.load(X + r)\n dy = tl.load(dY + 16 * r2 + r)\n tl.static_print('shape', dy.shape)\n dx = dcomp2dx(x, dy)\n tl.static_print('shape', dx.shape)\n tl.store(dX + r, dx)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/tests/test_autodiff.py" }, { "uuid": "0390ce58-3047-487a-b922-61daab851d88", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/launch_latency/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.jit\ndef nop_kernel():\n pass\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/launch_latency/kernels.py" }, { "uuid": "a2951d7f-12bc-4c56-a281-b5e60b0cf38c", "file_name": "3_mat_mul.py", "repo_name": "DataLama/triton-tutorials", "file_path": "tutorials/basic/3_mat_mul.py", "commit_hash": "95fb36429bdae3333cfcde76b18a00781ba5953e", "starcount": 0, "input": "@triton.jit\ndef matmul_kernel(x_ptr, y_ptr, z_ptr, m_size, k_size, n_size, m_block_size:\n tl.constexpr, k_block_size: tl.constexpr, n_block_size: tl.constexpr):\n pid = tl.program_id(0)\n num_n_blocks = tl.cdiv(n_size, n_block_size)\n m_block = pid // num_n_blocks\n n_block = pid % num_n_blocks\n m_offsets = tl.arange(0, m_block_size) + m_block * m_block_size\n n_offsets = tl.arange(0, n_block_size) + n_block * n_block_size\n k_offsets = tl.arange(0, k_block_size)\n x_ptrs = x_ptr + m_offsets[:, None] * k_size + k_offsets[None, :]\n y_ptrs = y_ptr + k_offsets[:, None] * n_size + n_offsets[None, :]\n z_ptrs = z_ptr + m_offsets[:, None] * n_size + n_offsets[None, :]\n z = tl.zeros((m_block_size, n_block_size), dtype=tl.float32)\n for _ in range(0, k_size, k_block_size):\n x_sub = tl.load(x_ptrs)\n y_sub = tl.load(y_ptrs)\n z += tl.dot(x_sub, y_sub, allow_tf32=False)\n x_ptrs += k_block_size\n y_ptrs += k_block_size * n_size\n tl.store(z_ptrs, z)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/DataLama/triton-tutorials/blob/95fb36429bdae3333cfcde76b18a00781ba5953e/tutorials/basic/3_mat_mul.py" }, { "uuid": "d5aed4cd-281b-47ba-b953-7ad565ff7b41", "file_name": "test_inductor.py", "repo_name": "triton-lang/kernels", "file_path": "test/test_inductor.py", "commit_hash": "eeeebdd8be7d13629de22d600621e6234057eed3", "starcount": 0, "input": "@triton.jit\ndef triton_(in_ptr0, out_ptr0, XBLOCK: tl.constexpr):\n xoffset = tl.program_id(0) * XBLOCK\n xindex = xoffset + tl.arange(0, XBLOCK)[:]\n x1 = xindex // 8 % 8\n x0 = xindex % 8\n x2 = xindex // 64\n x5 = xindex\n tmp0 = -1 + x1\n tmp1 = -1 + x0\n tmp2 = 2 + x1\n tmp3 = 2 + x0\n tmp4 = 0\n tmp5 = tl.where(tmp0 != tmp0, tmp0, tl.where(tmp0 > tmp4, tmp0, tmp4))\n tmp6 = tl.where(tmp1 != tmp1, tmp1, tl.where(tmp1 > tmp4, tmp1, tmp4))\n tmp7 = 8\n tmp8 = tl.where(tmp2 != tmp2, tmp2, tl.where(tmp2 < tmp7, tmp2, tmp7))\n tmp9 = tl.where(tmp3 != tmp3, tmp3, tl.where(tmp3 < tmp7, tmp3, tmp7))\n tmp10 = tmp5 + tmp4\n tmp11 = tmp6 + tmp4\n tmp12 = 1\n tmp13 = tmp8 - tmp12\n tmp14 = tl.where(tmp10 != tmp10, tmp10, tl.where(tmp10 < tmp13, tmp10,\n tmp13))\n tmp15 = tmp9 - tmp12\n tmp16 = tl.where(tmp11 != tmp11, tmp11, tl.where(tmp11 < tmp15, tmp11,\n tmp15))\n tmp17 = tl.load(in_ptr0 + (tmp16 + 8 * tmp14 + 64 * x2), None).to(tl.\n float32)\n tmp18 = tmp17 / 9\n tmp19 = tmp10 < tmp8\n tmp20 = tmp11 < tmp9\n tmp21 = tmp19 & tmp20\n tmp22 = 0.0\n tmp23 = tl.where(tmp21, tmp18, tmp22)\n tmp24 = tmp6 + tmp12\n tmp25 = tl.where(tmp24 != tmp24, tmp24, tl.where(tmp24 < tmp15, tmp24,\n tmp15))\n tmp26 = tl.load(in_ptr0 + (tmp25 + 8 * tmp14 + 64 * x2), None).to(tl.\n float32)\n tmp27 = tmp26 / 9\n tmp28 = tmp24 < tmp9\n tmp29 = tmp19 & tmp28\n tmp30 = tmp23 + tmp27\n tmp31 = tl.where(tmp29, tmp30, tmp23)\n tmp32 = 2\n tmp33 = tmp6 + tmp32\n tmp34 = tl.where(tmp33 != tmp33, tmp33, tl.where(tmp33 < tmp15, tmp33,\n tmp15))\n tmp35 = tl.load(in_ptr0 + (tmp34 + 8 * tmp14 + 64 * x2), None).to(tl.\n float32)\n tmp36 = tmp35 / 9\n tmp37 = tmp33 < tmp9\n tmp38 = tmp19 & tmp37\n tmp39 = tmp31 + tmp36\n tmp40 = tl.where(tmp38, tmp39, tmp31)\n tmp41 = tmp5 + tmp12\n tmp42 = tl.where(tmp41 != tmp41, tmp41, tl.where(tmp41 < tmp13, tmp41,\n tmp13))\n tmp43 = tl.load(in_ptr0 + (tmp16 + 8 * tmp42 + 64 * x2), None).to(tl.\n float32)\n tmp44 = tmp43 / 9\n tmp45 = tmp41 < tmp8\n tmp46 = tmp45 & tmp20\n tmp47 = tmp40 + tmp44\n tmp48 = tl.where(tmp46, tmp47, tmp40)\n tmp49 = tl.load(in_ptr0 + (tmp25 + 8 * tmp42 + 64 * x2), None).to(tl.\n float32)\n tmp50 = tmp49 / 9\n tmp51 = tmp45 & tmp28\n tmp52 = tmp48 + tmp50\n tmp53 = tl.where(tmp51, tmp52, tmp48)\n tmp54 = tl.load(in_ptr0 + (tmp34 + 8 * tmp42 + 64 * x2), None).to(tl.\n float32)\n tmp55 = tmp54 / 9\n tmp56 = tmp45 & tmp37\n tmp57 = tmp53 + tmp55\n tmp58 = tl.where(tmp56, tmp57, tmp53)\n tmp59 = tmp5 + tmp32\n tmp60 = tl.where(tmp59 != tmp59, tmp59, tl.where(tmp59 < tmp13, tmp59,\n tmp13))\n tmp61 = tl.load(in_ptr0 + (tmp16 + 8 * tmp60 + 64 * x2), None).to(tl.\n float32)\n tmp62 = tmp61 / 9\n tmp63 = tmp59 < tmp8\n tmp64 = tmp63 & tmp20\n tmp65 = tmp58 + tmp62\n tmp66 = tl.where(tmp64, tmp65, tmp58)\n tmp67 = tl.load(in_ptr0 + (tmp25 + 8 * tmp60 + 64 * x2), None).to(tl.\n float32)\n tmp68 = tmp67 / 9\n tmp69 = tmp63 & tmp28\n tmp70 = tmp66 + tmp68\n tmp71 = tl.where(tmp69, tmp70, tmp66)\n tmp72 = tl.load(in_ptr0 + (tmp34 + 8 * tmp60 + 64 * x2), None).to(tl.\n float32)\n tmp73 = tmp72 / 9\n tmp74 = tmp63 & tmp37\n tmp75 = tmp71 + tmp73\n tmp76 = tl.where(tmp74, tmp75, tmp71)\n tl.store(out_ptr0 + (x5 + tl.zeros([XBLOCK], tl.int32)), tmp76, None)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/triton-lang/kernels/blob/eeeebdd8be7d13629de22d600621e6234057eed3/test/test_inductor.py" }, { "uuid": "e039d6a9-bf1b-4d2b-a12a-b4c00fb3c499", "file_name": "chunk_fuse.py", "repo_name": "elephantmipt/rebased_minimal", "file_path": "flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py", "commit_hash": "e7b945509972fab9f9c1c7be431abf7d6bf62c95", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_dv(do, v, rv, cv, p, dv, dsv, s_qk_h, s_qk_t,\n s_qk_d, s_sk_h, s_sk_t, s_sk_m, T, BT: tl.constexpr, BV: tl.constexpr,\n BM: tl.constexpr, DV: tl.constexpr, DM: tl.constexpr, NT: tl.constexpr):\n i_v, i_m, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n n_bh = tl.num_programs(2)\n p_do = tl.make_block_ptr(do + i_bh * s_qk_h, (T, DV), (s_qk_t, s_qk_d),\n ((NT - 1) * BT, i_v * BV), (BT, BV), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_qk_h, (DV, T), (s_qk_d, s_qk_t), (\n i_v * BV, (NT - 1) * BT), (BV, BT), (0, 1))\n p_rv = tl.make_block_ptr(rv + i_bh * s_sk_t * NT, (NT * DM,), (s_sk_m,),\n (i_m * BM,), (BM,), (0,))\n p_cv = tl.make_block_ptr(cv + i_bh * s_sk_h, (T, DM), (s_sk_t, s_sk_m),\n ((NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n p_p = tl.make_block_ptr(p + i_bh * s_sk_h, (DM, T), (s_sk_m, s_sk_t), (\n i_m * BM, (NT - 1) * BT), (BM, BT), (0, 1))\n p_dv = tl.make_block_ptr(dv + (i_m * n_bh + i_bh) * s_qk_h, (T, DV), (\n s_qk_t, s_qk_d), ((NT - 1) * BT, i_v * BV), (BT, BV), (1, 0))\n p_dsv = tl.make_block_ptr(dsv + (i_v * n_bh + i_bh) * s_sk_h, (T, DM),\n (s_sk_t, s_sk_m), ((NT - 1) * BT, i_m * BM), (BT, BM), (1, 0))\n o_i = tl.arange(0, BT)\n m_s, m_t = o_i[:, None] <= o_i[None, :], o_i[:, None] >= o_i[None, :]\n b_dhv = tl.zeros([BM, BV], dtype=tl.float32)\n for i in range(NT):\n p_rv = tl.make_block_ptr(rv + i_bh * s_sk_t * NT, (NT * DM,), (\n s_sk_m,), ((NT - i) % NT * DM + i_m * BM,), (BM,), (0,))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_rv = tl.load(p_rv, boundary_check=(0,))\n b_cv = tl.load(p_cv, boundary_check=(0, 1))\n b_p = tl.load(p_p, boundary_check=(0, 1))\n b_inter = tl.dot((b_cv * b_rv[None, :]).to(b_do.dtype), b_dhv.to(\n b_do.dtype), allow_tf32=False)\n b_intra = tl.dot(tl.where(m_s, tl.dot(b_cv, b_p, allow_tf32=False),\n 0.0).to(b_do.dtype), b_do, allow_tf32=False)\n b_dv = b_inter + b_intra\n b_inter = tl.dot(b_dhv.to(b_v.dtype), b_v, allow_tf32=False) * b_rv[\n :, None]\n b_intra = tl.dot(b_p, tl.where(m_t, tl.dot(b_do, b_v, allow_tf32=\n False), 0.0).to(b_do.dtype), allow_tf32=False)\n b_dsv = b_cv * tl.trans(b_inter + b_intra)\n b_dhv = b_dhv * b_rv[:, None] + tl.dot(b_p, b_do, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dsv, b_dsv.to(p_dsv.dtype.element_ty), boundary_check=(0, 1)\n )\n p_do = tl.advance(p_do, (-BT, 0))\n p_v = tl.advance(p_v, (0, -BT))\n p_cv = tl.advance(p_cv, (-BT, 0))\n p_p = tl.advance(p_p, (0, -BT))\n p_dv = tl.advance(p_dv, (-BT, 0))\n p_dsv = tl.advance(p_dsv, (-BT, 0))\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/elephantmipt/rebased_minimal/blob/e7b945509972fab9f9c1c7be431abf7d6bf62c95/flash_linear_attention/fla/ops/triton/abc/chunk_fuse.py" }, { "uuid": "b6e5ba5c-cdbe-470c-b934-3a35c1c5bedd", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BS': BS}, num_warps=num_warps) for\n BS in [16, 32, 64] for num_warps in [2, 4, 8]], key=['S', 'BT'])\n@triton.jit\ndef chunk_local_reversed_cumsum_vector_kernel(s, o, offsets, indices, T: tl\n .constexpr, H: tl.constexpr, S: tl.constexpr, BT: tl.constexpr, BS: tl.\n constexpr, HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_s, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_s = tl.where(o_i[:, None] <= o_i[None, :], 1.0, 0.0)\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T * S, (T, S), (S, 1), (i_t * BT,\n i_s * BS), (BT, BS), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * S, (T, S), (S, 1), (i_t * BT,\n i_s * BS), (BT, BS), (1, 0))\n else:\n p_s = tl.make_block_ptr(s + (bos * H + i_h) * S, (T, S), (H * S, 1),\n (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * S, (T, S), (H * S, 1),\n (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_o = tl.dot(m_s, b_s, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "7f6f8b3f-9d2a-4ae0-a2ad-35655192d89f", "file_name": "_flash_attention.py", "repo_name": "IBM/qattn", "file_path": "qattn/nn/functional/_flash_attention.py", "commit_hash": "07ceda0aceb9afd299d622325944c0c0471827fe", "starcount": 0, "input": "@triton.autotune(configs=_get_configs(), key=['N_CTX', 'H', 'Z'])\n@triton.heuristics({'EVEN_CTX': lambda args: args['N_CTX'] % args['BLOCK_M'\n ] == 0})\n@triton.jit\ndef _fwd_kernel(Q, K, V, sm_scale, qkv_scale_ptr, out_scale_ptr, Out,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX, EVEN_CTX: tl.\n constexpr, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N:\n tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n off_z = off_hz // H\n off_h = off_hz % H\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(\n BLOCK_DMODEL, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qkv_scale = tl.load(qkv_scale_ptr)\n qk_scale = qkv_scale * qkv_scale * sm_scale * 1.44269504\n if EVEN_CTX:\n q = tl.load(Q_block_ptr)\n else:\n q = tl.load(Q_block_ptr, boundary_check=(0,), padding_option='zero')\n for start_n in range(0, N_CTX, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_CTX:\n k = tl.load(K_block_ptr)\n else:\n k = tl.load(K_block_ptr, boundary_check=(1,), padding_option='zero'\n )\n qk = tl.dot(q, k, allow_tf32=False, out_dtype=tl.int32)\n qk_fp32 = qk * qk_scale\n m_ij = tl.maximum(m_i, tl.max(qk_fp32, 1))\n p = tl.math.exp2(qk_fp32 - m_ij[:, None])\n alpha = tl.math.exp2(m_i - m_ij)\n m_i = m_ij\n if EVEN_CTX:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(0,), padding_option='zero'\n )\n v = (v * qkv_scale).to(tl.bfloat16)\n acc *= alpha[:, None]\n acc += tl.dot(p.to(tl.bfloat16), v, allow_tf32=True)\n l_i = l_i * alpha + tl.sum(p, 1)\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n out_scale = tl.load(out_scale_ptr)\n acc = tl.math.llrint(acc / (l_i[:, None] * out_scale)).to(tl.int8)\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n if EVEN_CTX:\n tl.store(O_block_ptr, acc)\n else:\n tl.store(O_block_ptr, acc, boundary_check=(0,))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication", "Quantization" ], "Data Type": [ "bf16", "int8" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/IBM/qattn/blob/07ceda0aceb9afd299d622325944c0c0471827fe/qattn/nn/functional/_flash_attention.py" }, { "uuid": "e981bb06-78d6-48a1-8fb8-10d5a6f3bfc8", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef d_sigmoid(o):\n return o * (1 - o)\n", "category": { "Functionality": [ "Activation Functions", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "f79fde84-d03b-40dd-bc48-598749dc2167", "file_name": "layer_norm_dquant.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/layer_norm_dquant.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_dquant_kernel(X, Y, W, B, out, scale, stride, N, eps,\n BLOCK_SIZE: tl.constexpr):\n row = tl.program_id(0)\n Y += row * stride\n X += row * stride\n out += row * stride\n _mean = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n a = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n _mean += a\n mean = tl.sum(_mean, axis=0) / N\n _var = tl.zeros([BLOCK_SIZE], dtype=tl.float32)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n x = tl.where(cols < N, x - mean, 0.0)\n _var += x * x\n var = tl.sum(_var, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n _max_x = 0.0\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n w = tl.load(W + cols, mask=mask)\n b = tl.load(B + cols, mask=mask)\n x = tl.load(X + cols, mask=mask, other=0.0).to(tl.float32)\n _norm = (x - mean) * rstd * w + b\n tl.store(out + cols, _norm, mask=mask)\n _max_x = tl.maximum(_max_x, tl.max(tl.abs(_norm), axis=0))\n scale_x = _max_x / 127.0\n tl.store(scale + row, scale_x)\n for off in range(0, N, BLOCK_SIZE):\n cols = off + tl.arange(0, BLOCK_SIZE)\n mask = cols < N\n _norm = tl.load(out + cols, mask=mask, other=0.0)\n _norm = _norm / scale_x + 0.5\n tl.store(Y + cols, _norm.to(tl.int8), mask=mask)\n", "category": { "Functionality": [ "Normalization", "Quantization" ], "Data Type": [ "int8", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Register Intensive" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/layer_norm_dquant.py" }, { "uuid": "4e233564-be5f-4852-b99c-34dbe18c056e", "file_name": "sparse_copy.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_copy.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef copy_dense_to_sparse_kernel(input_ptr, output_ptr, scores_ptr,\n sparse_rows_ptr, num_columns: tl.constexpr, num_experts_per_token: tl.\n constexpr, block_size: tl.constexpr):\n dense_row = tl.program_id(0)\n offsets = tl.arange(0, block_size) + block_size * tl.program_id(1)\n mask = None if num_columns % block_size == 0 else offsets < num_columns\n out = tl.load(input_ptr + dense_row * num_columns + offsets, mask=mask)\n for top_index in range(num_experts_per_token):\n sparse_row = tl.load(sparse_rows_ptr + dense_row *\n num_experts_per_token + top_index)\n out_scaled = out if scores_ptr is None else out * tl.load(\n scores_ptr + dense_row * num_experts_per_token + top_index).to(tl\n .float32)\n tl.store(output_ptr + sparse_row * num_columns + offsets,\n out_scaled, mask=mask)\n", "category": { "Functionality": [ "Top-K Selection" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_copy.py" }, { "uuid": "82c88b83-f264-4ebd-b42a-842e936a1e5b", "file_name": "activation.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/activation.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@triton.jit\ndef silu(x):\n return x * tl.sigmoid(x.to(tl.float32)).to(x.dtype)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/activation.py" }, { "uuid": "0ea9b7a0-8530-4964-b178-926fbf55411b", "file_name": "triton_kernels.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/triton_kernels.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef _triton_fourth_order_bwd(x_ptr: tl.tensor, y_ptr: tl.tensor, z_ptr: tl.\n tensor, g_x_ptr: tl.tensor, g_y_ptr: tl.tensor, g_z_ptr: tl.tensor,\n g_1_0_ptr: tl.tensor, g_1_1_ptr: tl.tensor, g_1_2_ptr: tl.tensor,\n g_2_0_ptr: tl.tensor, g_2_1_ptr: tl.tensor, g_2_2_ptr: tl.tensor,\n g_2_3_ptr: tl.tensor, g_2_4_ptr: tl.tensor, g_3_0_ptr: tl.tensor,\n g_3_1_ptr: tl.tensor, g_3_2_ptr: tl.tensor, g_3_3_ptr: tl.tensor,\n g_3_4_ptr: tl.tensor, g_3_5_ptr: tl.tensor, g_3_6_ptr: tl.tensor,\n g_4_0_ptr: tl.tensor, g_4_1_ptr: tl.tensor, g_4_2_ptr: tl.tensor,\n g_4_3_ptr: tl.tensor, g_4_4_ptr: tl.tensor, g_4_5_ptr: tl.tensor,\n g_4_6_ptr: tl.tensor, g_4_7_ptr: tl.tensor, g_4_8_ptr: tl.tensor,\n BLOCK_SIZE: tl.constexpr, vector_length: tl.constexpr):\n sqrt_3 = 3 ** 0.5\n sqrt_5 = 5 ** 0.5\n sqrt_15 = 15 ** 0.5\n block_id = tl.program_id(0)\n offset = tl.arange(0, BLOCK_SIZE) + BLOCK_SIZE * block_id\n x_row_start = x_ptr + offset\n y_row_start = y_ptr + offset\n z_row_start = z_ptr + offset\n x = tl.load(x_row_start, mask=offset < vector_length)\n y = tl.load(y_row_start, mask=offset < vector_length)\n z = tl.load(z_row_start, mask=offset < vector_length)\n g_1_0 = tl.load(g_1_0_ptr + offset, mask=offset < vector_length)\n g_1_1 = tl.load(g_1_1_ptr + offset, mask=offset < vector_length)\n g_1_2 = tl.load(g_1_2_ptr + offset, mask=offset < vector_length)\n g_x = sqrt_3 * g_1_0\n g_y = sqrt_3 * g_1_1\n g_z = sqrt_3 * g_1_2\n g_2_0 = tl.load(g_2_0_ptr + offset, mask=offset < vector_length)\n g_2_1 = tl.load(g_2_1_ptr + offset, mask=offset < vector_length)\n g_2_2 = tl.load(g_2_2_ptr + offset, mask=offset < vector_length)\n g_2_3 = tl.load(g_2_3_ptr + offset, mask=offset < vector_length)\n g_2_4 = tl.load(g_2_4_ptr + offset, mask=offset < vector_length)\n g_x += sqrt_15 * z * g_2_0\n g_z += sqrt_15 * x * g_2_0\n g_x += sqrt_15 * y * g_2_1\n g_y += sqrt_15 * x * g_2_1\n g_y += sqrt_15 * z * g_2_2\n g_z += sqrt_15 * y * g_2_2\n g_x += -1.0 * sqrt_5 * x * g_2_3\n g_y += 2.0 * sqrt_5 * y * g_2_3\n g_z += -1.0 * sqrt_5 * z * g_2_3\n g_x += -1.0 * sqrt_15 * x * g_2_4\n g_z += sqrt_15 * z * g_2_4\n g_3_0 = tl.load(g_3_0_ptr + offset, mask=offset < vector_length)\n g_3_1 = tl.load(g_3_1_ptr + offset, mask=offset < vector_length)\n g_3_2 = tl.load(g_3_2_ptr + offset, mask=offset < vector_length)\n g_3_3 = tl.load(g_3_3_ptr + offset, mask=offset < vector_length)\n g_3_4 = tl.load(g_3_4_ptr + offset, mask=offset < vector_length)\n g_3_5 = tl.load(g_3_5_ptr + offset, mask=offset < vector_length)\n g_3_6 = tl.load(g_3_6_ptr + offset, mask=offset < vector_length)\n sq_x = x * x\n sq_y = y * y\n sq_z = z * z\n cu_z = sq_z * z\n cu_x = sq_x * x\n cu_y = sq_y * y\n g_x += sqrt_15 * g_3_0 * (-1.62018517460196 * sq_x + 1.08012344973464 *\n sq_z + 0.540061724867322 * sq_z)\n g_x += 2.64575131106459 * sqrt_15 * g_3_1 * y * z\n g_x -= g_3_2 * (4.8605555238059 * sq_x - 6.48074069840786 * sq_y + \n 1.62018517460197 * sq_z)\n g_x -= 7.93725393319377 * g_3_3 * x * y\n g_x -= 3.24037034920393 * g_3_4 * x * z\n g_x -= 2.64575131106459 * sqrt_15 * g_3_5 * x * y\n g_x -= sqrt_15 * g_3_6 * z * (1.08012344973464 * x + 2.16024689946929 * x)\n g_y += 2.64575131106459 * sqrt_15 * g_3_1 * x * z\n g_y += 12.9614813968157 * g_3_2 * x * y\n g_y -= g_3_3 * (3.96862696659689 * sq_x - 7.93725393319377 * sq_y + \n 3.96862696659689 * sq_z)\n g_y += 12.9614813968157 * g_3_4 * y * z\n g_y -= 1.3228756555323 * sqrt_15 * g_3_5 * (sq_x - sq_z)\n g_z += sqrt_15 * g_3_0 * x * (1.08012344973464 * z + 2.16024689946929 * z)\n g_z += 2.64575131106459 * sqrt_15 * g_3_1 * x * y\n g_z -= 3.24037034920393 * g_3_2 * x * z\n g_z -= 7.93725393319377 * g_3_3 * y * z\n g_z -= g_3_4 * (1.62018517460197 * sq_x - 6.48074069840786 * sq_y + \n 4.8605555238059 * sq_z)\n g_z += 2.64575131106459 * sqrt_15 * g_3_5 * y * z\n g_z -= sqrt_15 * g_3_6 * (1.08012344973464 * sq_x + 0.540061724867322 *\n sq_x - 1.62018517460196 * sq_z)\n g_4_0 = tl.load(g_4_0_ptr + offset, mask=offset < vector_length)\n g_4_1 = tl.load(g_4_1_ptr + offset, mask=offset < vector_length)\n g_4_2 = tl.load(g_4_2_ptr + offset, mask=offset < vector_length)\n g_4_3 = tl.load(g_4_3_ptr + offset, mask=offset < vector_length)\n g_4_4 = tl.load(g_4_4_ptr + offset, mask=offset < vector_length)\n g_4_5 = tl.load(g_4_5_ptr + offset, mask=offset < vector_length)\n g_4_6 = tl.load(g_4_6_ptr + offset, mask=offset < vector_length)\n g_4_7 = tl.load(g_4_7_ptr + offset, mask=offset < vector_length)\n g_4_8 = tl.load(g_4_8_ptr + offset, mask=offset < vector_length)\n g_x -= sqrt_15 * g_4_0 * (3.43693177121688 * sq_x * z + \n 3.43693177121688 * sq_x * z - 1.14564392373896 * cu_z - \n 1.14564392373896 * cu_z)\n g_x += sqrt_15 * g_4_1 * y * (-4.8605555238059 * sq_x + \n 3.24037034920393 * sq_z + 1.62018517460197 * sq_z)\n g_x -= g_4_2 * (0.649519052838329 * sqrt_15 * sq_x * z + \n 7.54672942406179 * sq_x * z - 2.59807621135332 * sqrt_15 * sq_y * z -\n 10.0623058987491 * sq_y * z + 0.21650635094611 * sqrt_15 * cu_z + \n 2.51557647468726 * cu_z)\n g_x -= g_4_3 * y * (0.918558653543692 * sqrt_15 * sq_x + \n 16.0090306546024 * sq_x - 9.48683298050514 * sq_y + \n 0.918558653543692 * sqrt_15 * sq_z + 5.33634355153414 * sq_z + \n 0.459279326771846 * sqrt_15 * (sq_x - sq_z))\n g_x += g_4_4 * (-9.0 * x * sq_y + 2.25 * x * sq_z - 9.0 * x * sq_y + \n 2.25 * x * sq_z + 4.5 * cu_x)\n g_x -= g_4_5 * y * z * (-0.918558653543692 * sqrt_15 * x + \n 10.6726871030683 * x + 1.83711730708738 * sqrt_15 * x)\n g_x -= g_4_6 * (2.59807621135332 * sqrt_15 * x * sq_y - \n 0.21650635094611 * sqrt_15 * x * sq_z + 2.51557647468726 * x * sq_z +\n 10.0623058987491 * x * sq_y - 2.51557647468726 * x * sq_z + \n 0.21650635094611 * sqrt_15 * x * sq_z - 5.03115294937453 * cu_x - \n 0.433012701892219 * sqrt_15 * cu_x)\n g_x -= sqrt_15 * g_4_7 * y * z * (3.24037034920393 * x + \n 6.48074069840786 * x)\n g_x -= sqrt_15 * g_4_8 * (1.14564392373896 * x * sq_z + \n 4.58257569495584 * x * sq_z + 1.14564392373896 * x * sq_z - \n 2.29128784747792 * cu_x)\n g_y += sqrt_15 * g_4_1 * x * (-1.62018517460197 * sq_x + \n 3.24037034920393 * sq_z + 1.62018517460197 * sq_z)\n g_y += g_4_2 * x * z * (5.19615242270663 * sqrt_15 * y + \n 20.1246117974981 * y)\n g_y -= g_4_3 * x * (5.33634355153414 * sq_x - 28.4604989415154 * sq_y +\n 0.918558653543692 * sqrt_15 * sq_z + 5.33634355153414 * sq_z + \n 0.459279326771846 * sqrt_15 * (sq_x - sq_z))\n g_y -= g_4_4 * (9.0 * sq_x * y + 9.0 * sq_x * y + 9.0 * y * sq_z + 9.0 *\n y * sq_z - 12.0 * cu_y)\n g_y -= g_4_5 * z * (0.918558653543692 * sqrt_15 * sq_x + \n 5.33634355153414 * sq_x - 28.4604989415154 * sq_y + \n 5.33634355153414 * sq_z - 0.459279326771846 * sqrt_15 * (sq_x - sq_z))\n g_y -= g_4_6 * (10.0623058987491 * sq_x * y + 2.59807621135332 *\n sqrt_15 * y * (sq_x - sq_z) - 10.0623058987491 * y * sq_z)\n g_y -= sqrt_15 * g_4_7 * z * (3.24037034920393 * sq_x + \n 1.62018517460197 * sq_x - 1.62018517460197 * sq_z)\n g_z -= sqrt_15 * g_4_0 * (1.14564392373896 * cu_x - 3.43693177121688 *\n x * sq_z - 3.43693177121688 * x * sq_z + 1.14564392373896 * cu_x)\n g_z += sqrt_15 * g_4_1 * x * y * (3.24037034920393 * z + \n 6.48074069840786 * z)\n g_z -= g_4_2 * (0.21650635094611 * sqrt_15 * cu_x - 2.59807621135332 *\n sqrt_15 * x * sq_y - 10.0623058987491 * x * sq_y + \n 0.649519052838329 * sqrt_15 * x * sq_z + 7.54672942406179 * x *\n sq_z + 2.51557647468726 * cu_x)\n g_z -= g_4_3 * x * y * (-0.918558653543692 * sqrt_15 * z + \n 10.6726871030683 * z + 1.83711730708738 * sqrt_15 * z)\n g_z += g_4_4 * (2.25 * sq_x * z + 2.25 * sq_x * z - 9.0 * sq_y * z - \n 9.0 * sq_y * z + 4.5 * cu_z)\n g_z -= g_4_5 * y * (0.918558653543692 * sqrt_15 * sq_x + \n 5.33634355153414 * sq_x - 9.48683298050514 * sq_y + \n 0.918558653543692 * sqrt_15 * sq_z + 16.0090306546024 * sq_z - \n 0.459279326771846 * sqrt_15 * (sq_x - sq_z))\n g_z += g_4_6 * (-0.21650635094611 * sqrt_15 * sq_x * z + \n 2.51557647468726 * sq_x * z - 2.51557647468726 * sq_x * z + \n 0.21650635094611 * sqrt_15 * sq_x * z + 2.59807621135332 * sqrt_15 *\n sq_y * z + 10.0623058987491 * sq_y * z - 5.03115294937453 * cu_z - \n 0.433012701892219 * sqrt_15 * cu_z)\n g_z -= sqrt_15 * g_4_7 * y * (3.24037034920393 * sq_x + \n 1.62018517460197 * sq_x - 4.8605555238059 * sq_z)\n g_z -= sqrt_15 * g_4_8 * (1.14564392373896 * sq_x * z + \n 4.58257569495584 * sq_x * z + 1.14564392373896 * sq_x * z - \n 2.29128784747792 * cu_z)\n tl.store(g_x_ptr + offset, g_x, mask=offset < vector_length)\n tl.store(g_y_ptr + offset, g_y, mask=offset < vector_length)\n tl.store(g_z_ptr + offset, g_z, mask=offset < vector_length)\n", "category": { "Functionality": [ "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced", "Register Intensive" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/triton_kernels.py" }, { "uuid": "77276a0a-ca29-4f47-ba40-e00bfa0d002c", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_N': b_n,\n 'BLOCK_SIZE_K': b_k}, num_warps=w) for b_n, b_k, w in itertools.product\n ([(4 ** n) for n in range(7)], [(4 ** n) for n in range(4)], [2, 4, 8])\n ], key=['N'])\n@triton.jit\ndef triton_sum_kernel_2D_result_dim_1_buffer_then_sum(input_ptr, output_ptr,\n M: tl.constexpr, N: tl.constexpr, K: tl.constexpr, BLOCK_SIZE_N: tl.\n constexpr, BLOCK_SIZE_K: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_m = pid // tl.cdiv(K, BLOCK_SIZE_K)\n pid_k = pid % tl.cdiv(K, BLOCK_SIZE_K)\n buffer = tl.zeros((BLOCK_SIZE_N, BLOCK_SIZE_K), dtype=tl.float32)\n block_start_k = pid_k * BLOCK_SIZE_K\n offsets_k = block_start_k + tl.arange(0, BLOCK_SIZE_K)\n mask_k = offsets_k < K\n for block_start_n in range(0, N, BLOCK_SIZE_N):\n offsets_n = block_start_n + tl.arange(0, BLOCK_SIZE_N)\n mask_n = offsets_n < N\n idxs_base = offsets_n[:, None] * K + offsets_k\n idxs = idxs_base + pid_m * N * K\n mask = mask_n[:, None] & mask_k\n input = tl.load(input_ptr + idxs, mask=mask, other=0)\n buffer += input\n output = tl.sum(buffer, axis=0)\n output_offsets = pid_m * K + offsets_k\n tl.store(output_ptr + output_offsets, output, mask=mask_k)\n", "category": { "Functionality": [ "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/sum/kernels.py" }, { "uuid": "819bf337-44ca-4907-932b-9e1c4bbf4365", "file_name": "pointwise.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/pointwise.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_fill_kernel(input_ptr, value: tl.constexpr, numel: tl.constexpr,\n dtype: tl.constexpr, block_size: tl.constexpr):\n block_start = tl.program_id(axis=0).to(tl.int64) * block_size\n offsets = block_start + tl.arange(0, block_size)\n mask = offsets < numel\n tl.store(input_ptr + offsets, tl.full((block_size,), value, dtype),\n mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/pointwise.py" }, { "uuid": "903ee2c1-1f8e-43cb-94cc-41866b2e116f", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef calc_p_loss(input, target, size, p_loss: tl.constexpr, reduction: tl.\n constexpr):\n \"\"\"\n Measures the L1 or squared L2 norm of the difference between the input\n and target (i.e., mean absolute error or mean squared error).\n\n Args:\n input: Input.\n The input must be of shape [BLOCK_SIZE].\n target: Target.\n The target must be of shape [BLOCK_SIZE].\n size: Number of elements in the input and target.\n This value is used only if reduction is 'mean'.\n p_loss: p-norm used to compute the error.\n Options are 1 for MAE and 2 for MSE.\n reduction: Reduction strategy for the output.\n Options are 'none' for no reduction, 'mean' for averaging the error\n across all entries, and 'sum' for summing the error across all entries.\n\n Returns:\n Error.\n \"\"\"\n input = input.to(tl.float32)\n target = target.to(tl.float32)\n diff = input - target\n if p_loss == 1:\n error = tl.abs(diff)\n elif p_loss == 2:\n error = diff * diff\n if reduction == 'none':\n output = error\n elif reduction == 'mean':\n output = tl.sum(error) / size\n elif reduction == 'sum':\n output = tl.sum(error)\n return output\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "cc350db1-2b6c-4dc4-9911-76e59d19de8e", "file_name": "quant_per_block.py", "repo_name": "rodjjo/editorium", "file_path": "editorium/app/server/pipelines/cogvideo/sageattention/quant_per_block.py", "commit_hash": "7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694", "starcount": 0, "input": "@triton.jit\ndef q_kernel_per_block_int8(X, X_int8, BLK: tl.constexpr, Scale, L, C: tl.\n constexpr, scale_stride):\n off_b = tl.program_id(1)\n off_blk = tl.program_id(0)\n x_offset = off_b * L * C\n offs_m = off_blk * BLK + tl.arange(0, BLK)\n offs_k = tl.arange(0, C)\n x_ptrs = X + x_offset + offs_m[:, None] * C + offs_k[None, :]\n x_int8_ptrs = X_int8 + x_offset + offs_m[:, None] * C + offs_k[None, :]\n scale_ptrs = Scale + off_b * scale_stride + off_blk\n x = tl.load(x_ptrs, mask=offs_m[:, None] < L)\n x *= C ** -0.5 * 1.44269504\n scale = tl.max(tl.abs(x)) / 127.0\n x_int8 = x / scale\n x_int8 += 0.5 * tl.where(x_int8 >= 0, 1, -1)\n x_int8 = x_int8.to(tl.int8)\n tl.store(x_int8_ptrs, x_int8, mask=offs_m[:, None] < L)\n tl.store(scale_ptrs, scale)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "int8", "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/rodjjo/editorium/blob/7b92e2c92a144bf23bbe6fe88e3d513ffcf7d694/editorium/app/server/pipelines/cogvideo/sageattention/quant_per_block.py" }, { "uuid": "f225f117-ee5a-49a5-a8cd-9527e6e0e161", "file_name": "triton_mars_adamw.py", "repo_name": "lessw2020/MARS-AdamW-PyTorch", "file_path": "triton_mars_adamw.py", "commit_hash": "c312b763d079f38291492bc911e8ea8aa1967433", "starcount": 0, "input": "@triton.jit\ndef mars_adamw_kernel(param_ptr, grad_ptr, exp_avg_ptr, exp_avg_sq_ptr,\n prev_grad_ptr, lr, beta1, beta2, eps, weight_decay, gamma,\n max_grad_norm, step, bias_correction1, bias_correction2, n_elements,\n BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(0)\n block_start = pid * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n mask = offsets < n_elements\n param = tl.load(param_ptr + offsets, mask=mask)\n grad = tl.load(grad_ptr + offsets, mask=mask)\n exp_avg = tl.load(exp_avg_ptr + offsets, mask=mask)\n exp_avg_sq = tl.load(exp_avg_sq_ptr + offsets, mask=mask)\n prev_grad = tl.load(prev_grad_ptr + offsets, mask=mask)\n grad_diff = grad - prev_grad\n correction = gamma * beta1 / (1 - beta1) * grad_diff\n c_t = grad + correction\n c_t_norm = tl.sqrt(tl.sum(c_t * c_t))\n scale = tl.where(c_t_norm > max_grad_norm, max_grad_norm / c_t_norm, 1.0)\n c_t = c_t * scale\n exp_avg = beta1 * exp_avg + (1 - beta1) * c_t\n exp_avg_sq = beta2 * exp_avg_sq + (1 - beta2) * (c_t * c_t)\n tl.store(prev_grad_ptr + offsets, grad, mask=mask)\n step_size = lr / bias_correction1\n denom = tl.sqrt(exp_avg_sq) / tl.sqrt(bias_correction2) + eps\n update = exp_avg / denom\n param = param - step_size * (update + weight_decay * param)\n tl.store(param_ptr + offsets, param, mask=mask)\n tl.store(exp_avg_ptr + offsets, exp_avg, mask=mask)\n tl.store(exp_avg_sq_ptr + offsets, exp_avg_sq, mask=mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/lessw2020/MARS-AdamW-PyTorch/blob/c312b763d079f38291492bc911e8ea8aa1967433/triton_mars_adamw.py" }, { "uuid": "4282b81a-47ee-476a-b8f3-60d4b209555f", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_K(q, k, v, z, h, A, do, dh, dq, dk, dv, dA, s_k_h,\n s_k_t, s_k_d, s_v_h, s_v_t, s_v_d, s_h_h, s_h_t, s_h_d, scale, T: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_p = tl.maximum(i_t * BT - 1, 0)\n n_bh = tl.num_programs(2)\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_A = tl.make_block_ptr(A + (i_k * n_bh + i_bh) * T * BT, (T, BT), (BT,\n 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_A = tl.dot((b_q * scale).to(b_q.dtype), tl.trans(b_k), allow_tf32=False)\n b_A = tl.where(m_s, b_A, 0.0)\n tl.store(p_A, b_A.to(p_A.dtype.element_ty), boundary_check=(0, 1))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_zp = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), (i_p *\n V + i_v * BV,), (BV,), (0,))\n p_zc = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), ((\n i_t * BT + BT - 1) * V + i_v * BV,), (BV,), (0,))\n p_h = tl.make_block_ptr(h + i_bh * s_h_h + i_t * K * V, (V, K), (\n s_h_d, s_h_t), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_dh = tl.make_block_ptr(dh + i_bh * s_h_h + i_t * K * V, (K, V), (\n s_h_t, s_h_d), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * n_bh + i_bh) * s_v_h, (T, V),\n (s_v_t, s_v_d), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n b_zp = tl.load(p_zp, boundary_check=(0,))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_v = tl.exp(b_v - b_zc[None, :]).to(b_v.dtype)\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_z = tl.exp(b_zp[None, :] - b_z)\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * b_z * scale).to(b_do.dtype)\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dq += tl.dot(b_do, b_h, allow_tf32=False)\n b_dk += tl.dot(b_v, tl.trans(b_dh), allow_tf32=False)\n b_dv = b_v * tl.dot(b_k, b_dh, allow_tf32=False)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dq += tl.dot(b_dA, b_k, allow_tf32=False)\n b_dk += tl.dot(tl.trans(b_dA).to(b_k.dtype), b_q, allow_tf32=False)\n p_dq = tl.make_block_ptr(dq + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (\n i_t * BT, i_k * BK), (BT, BK), (1, 0))\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Cooperative Groups" ], "Memory Access Pattern": [ "Strided Access", "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "adfad45d-a068-444b-b194-56d3022e2f4a", "file_name": "scratch.py", "repo_name": "falkaer/multi-scale-music", "file_path": "seq/scratch.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.jit\ndef _dropout(X, O, stride_x1, stride_x2, stride_o1, stride_o2, dropout_prob,\n dropout_seed, M, N, BLOCK: tl.constexpr):\n offs_m = tl.program_id(0) * BLOCK + tl.arange(0, BLOCK)\n offs_n = tl.program_id(1) * BLOCK + tl.arange(0, BLOCK)\n X = X + offs_m[:, None] * stride_x1 + offs_n[None, :] * stride_x2\n x = tl.load(X, mask=(offs_m[:, None] < M) & (offs_n[None, :] < N))\n offsets = offs_m[:, None] * M + offs_n[None, :]\n x = apply_dropout(x, offsets, dropout_prob, dropout_seed)\n O = O + offs_m[:, None] * stride_o1 + offs_n[None, :] * stride_o2\n tl.store(O, x, mask=(offs_m[:, None] < M) & (offs_n[None, :] < N))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/seq/scratch.py" }, { "uuid": "dbf37971-a262-44ef-989d-77aeac137b61", "file_name": "utils.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/utils.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _sparse24(x0, x1, x2, x3):\n a1, a2, a3, a4, a5, a6 = tl.abs(x0) > tl.abs(x1), tl.abs(x0) > tl.abs(x2\n ), tl.abs(x0) > tl.abs(x3), tl.abs(x1) > tl.abs(x2), tl.abs(x1\n ) > tl.abs(x3), tl.abs(x2) > tl.abs(x3)\n m0, m1, m2, m3 = (a2 & a3 | a1 & a2 | a1 & a3, ~a1 & a5 | a4 & a5 | ~a1 &\n a4, ~a2 & ~a4 | ~a2 & a6 | ~a4 & a6, ~a3 & ~a5 | ~a3 & ~a6 | ~a5 & ~a6)\n return x0, x1, x2, x3, m0, m1, m2, m3\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/utils.py" }, { "uuid": "52dd01fd-ccd7-4456-9d0e-9fcf7c68fc38", "file_name": "GELUglu.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/GELUglu.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _gelu_glu_fwd_kernel_(output_ptr, input_ptr, output_row_stride,\n input_row_stride, output_col_stride, input_col_stride, n_rows, n_cols,\n BLOCK_SIZE: tl.constexpr):\n col_idx = tl.program_id(0)\n row_idx = tl.arange(0, BLOCK_SIZE)\n x = tl.load(input_ptr + row_idx * input_row_stride + col_idx *\n input_col_stride, mask=tl.arange(0, BLOCK_SIZE) < n_rows, other=-\n float('inf'))\n gate = tl.load(input_ptr + row_idx * input_row_stride + (col_idx + \n n_cols // 2) * input_col_stride, mask=tl.arange(0, BLOCK_SIZE) <\n n_rows, other=-float('inf'))\n gate_cube = gate * gate * gate\n beta = 0.7978845608028654\n kappa = 0.044715\n inner = beta * (gate + kappa * gate_cube)\n inner_tanh = tanh(inner)\n gate_gelu = 0.5 * gate * (inner_tanh + 1)\n gelu_glu = gate_gelu * x\n tl.store(output_ptr + row_idx * output_row_stride + col_idx *\n output_col_stride, gelu_glu, mask=tl.arange(0, BLOCK_SIZE) < n_rows)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/GELUglu.py" }, { "uuid": "38d42e7c-347d-4ccf-b10b-1860c22d5877", "file_name": "chunk_h_parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['h0'] is not\n None, 'STORE_FINAL_STATE': lambda args: args['ht'] is not None,\n 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=[\n 'BT', 'USE_G', 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_fwd_kernel_h_parallel(k, v, h, g, gk, gv, h0, ht, offsets,\n indices, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.\n constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_G:\n tl.constexpr, USE_GK: tl.constexpr, USE_GV: tl.constexpr,\n USE_INITIAL_STATE: tl.constexpr, STORE_FINAL_STATE: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_kv, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n NV = tl.cdiv(V, BV)\n i_k, i_v = i_kv // NV, i_kv % NV\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n bos, eos = i_b * T, i_b * T + T\n NT = tl.cdiv(T, BT)\n i_n, i_tg = i_b, i_b * NT + i_t\n i_nh = i_n * H + i_h\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k * BK,\n i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (K, V), (V, \n 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H * K),\n (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (V, 1\n ), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n if i_t == 0:\n if USE_INITIAL_STATE:\n p_h0 = tl.make_block_ptr(h0 + i_nh * K * V, (K, V), (V, 1), (\n i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_h = tl.load(p_h0, boundary_check=(0, 1)).to(tl.float32)\n else:\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_bh * T + last_idx)\n p_g = g + i_bh * T + i_t * BT + tl.arange(0, BT)\n p_g = tl.max_contiguous(tl.multiple_of(p_g, BT), BT)\n else:\n b_g_last = tl.load(g + bos * H + last_idx * H + i_h)\n p_g = g + bos * H + (i_t * BT + tl.arange(0, BT)) * H + i_h\n b_g = tl.load(p_g, mask=i_t * BT + tl.arange(0, BT) < T, other=0.0)\n b_v = (b_v * tl.exp(b_g_last - b_g)[:, None]).to(b_v.dtype)\n if USE_GK:\n if HEAD_FIRST:\n p_gk = tl.make_block_ptr(gk + i_bh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = (gk + i_bh * T * K + last_idx * K + i_k * BK + tl.\n arange(0, BK))\n else:\n p_gk = tl.make_block_ptr(gk + (bos * H + i_h) * K, (K, T), (1, \n H * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) < K,\n other=0.0)\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_k = (b_k * tl.exp(b_gk_last[:, None] - b_gk)).to(b_k.dtype)\n if USE_GV:\n if HEAD_FIRST:\n p_gv = tl.make_block_ptr(gv + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = (gv + i_bh * T * V + last_idx * V + i_v * BV + tl.\n arange(0, BV))\n else:\n p_gv = tl.make_block_ptr(gv + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) < V,\n other=0.0)\n b_gv = tl.load(p_gv, boundary_check=(0, 1))\n b_v = (b_v * tl.exp(b_gv_last[None, :] - b_gv)).to(b_v.dtype)\n b_h = tl.dot(b_k, b_v)\n if i_t < NT - 1:\n if HEAD_FIRST:\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t + 1) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_h = tl.make_block_ptr(h + ((i_tg + 1) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n elif STORE_FINAL_STATE:\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups", "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_parallel.py" }, { "uuid": "fa2c1086-b9be-4a8b-ae3e-2b5cda3eb8d6", "file_name": "fused_chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/fused_chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef prepare_qg_kg(q, k, g, qg, kg, s_k_h, scale, K: tl.constexpr, BT: tl.\n constexpr, BK: tl.constexpr):\n i_k, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n p_q = q + i_bh * s_k_h + i_c * BT * K + i_k * BK + tl.arange(0, BK)\n p_g = g + i_bh * s_k_h + i_c * BT * K + i_k * BK + tl.arange(0, BK)\n p_k = k + i_bh * s_k_h + i_c * BT * K + i_k * BK + tl.arange(0, BK)\n p_qg = qg + i_bh * s_k_h + i_c * BT * K + i_k * BK + tl.arange(0, BK)\n p_kg = kg + i_bh * s_k_h + i_c * BT * K + i_k * BK + tl.arange(0, BK)\n mask = i_k * BK + tl.arange(0, BK) < K\n last_decay = tl.load(g + i_bh * s_k_h + (i_c * BT + BT - 1) * K + i_k *\n BK + tl.arange(0, BK))\n for i in range(BT):\n b_q = tl.load(p_q, mask=mask, other=0)\n b_k = tl.load(p_k, mask=mask, other=0)\n _g = tl.load(p_g, mask=mask, other=0).to(tl.float32)\n b_q *= tl.exp(_g) * scale\n b_k *= tl.exp(last_decay - _g)\n tl.store(p_kg, b_k.to(p_kg.dtype.element_ty), mask=mask)\n tl.store(p_qg, b_q.to(p_qg.dtype.element_ty), mask=mask)\n p_q += K\n p_g += K\n p_k += K\n p_kg += K\n p_qg += K\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/fused_chunk.py" }, { "uuid": "c79e3bed-77f3-4997-8cb9-825857d15dba", "file_name": "blocksparse_attention_kernel.py", "repo_name": "Charlie-XIAO/sparse-vllm", "file_path": "vllm/attention/ops/blocksparse_attention/blocksparse_attention_kernel.py", "commit_hash": "d228909a30b0c245c35417fb7d2acdf9a3690042", "starcount": 0, "input": "@triton.heuristics({'M_LT_N': lambda kwargs: kwargs['BLOCK_M'] < kwargs[\n 'BLOCK_N']})\n@triton.jit\ndef _fwd_kernel_batch_inference(Q, K, V, Out, sm_scale, q_batch_starts,\n q_batch_ends, k_batch_starts, k_batch_ends, q_batch_ids, q_start_sids,\n stride_qb, stride_qt, stride_qh, stride_qd, stride_kb, stride_kt,\n stride_kh, stride_kd, stride_vb, stride_vt, stride_vh, stride_vd,\n stride_ob, stride_ot, stride_oh, stride_od, layout_crow_ptr,\n layout_col_ptr, layout_crow_stride_h, layout_crow_stride_m,\n layout_col_stride_h, layout_col_stride_m, q_k_ratio, HAS_BATCH_DIM: tl.\n constexpr, D_HEAD: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.\n constexpr, BLOCK_D: tl.constexpr, BLOCK_M_LOADING: tl.constexpr, EVEN_D:\n tl.constexpr, M_LT_N: tl.constexpr):\n \"\"\"\n NOTATION:\n pid: position id\n sid: storage id\n sbid: storage block id\n pbid: position block id\n offs_m, offs_n: storage offsets of m-dim(q, row) and n-dim(k, col)\n\n TODO(linxihui):\n Optimize grouped-attn\n \"\"\"\n off_zm = tl.program_id(0)\n off_h = tl.program_id(1)\n off_h_for_kv = off_h // q_k_ratio\n if HAS_BATCH_DIM:\n off_z = tl.program_id(2)\n Q += off_z * stride_qb\n K += off_z * stride_kb\n V += off_z * stride_vb\n Out += off_z * stride_ob\n start_m = off_zm\n q_start_sid = start_m * BLOCK_M\n else:\n off_z = tl.load(q_batch_ids + off_zm).to(tl.int32)\n q_start_sid = tl.load(q_start_sids + off_zm)\n start_m = q_start_sid // BLOCK_M\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M_LOADING)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_D)\n q_cu_start = tl.load(q_batch_starts + off_z).to(tl.int32)\n q_seqlen = tl.load(q_batch_ends + off_z).to(tl.int32) - q_cu_start\n k_cu_start = tl.load(k_batch_starts + off_z).to(tl.int32)\n k_seqlen = tl.load(k_batch_ends + off_z).to(tl.int32) - k_cu_start\n past_len = k_seqlen - q_seqlen\n Q += q_cu_start * stride_qt + off_h * stride_qh\n K += k_cu_start * stride_kt + off_h_for_kv * stride_kh\n V += k_cu_start * stride_vt + off_h_for_kv * stride_vh\n Out += q_cu_start * stride_ot + off_h * stride_oh\n q_pbid = (past_len + q_start_sid) // BLOCK_M\n if EVEN_D:\n q = tl.load(Q + offs_m[:, None] * stride_qt + offs_d[None, :] *\n stride_qd, mask=offs_m[:, None] < q_seqlen)\n else:\n q = tl.load(Q + offs_m[:, None] * stride_qt + offs_d[None, :] *\n stride_qd, mask=(offs_m[:, None] < q_seqlen) & (offs_d[None, :] <\n D_HEAD), other=0)\n sparse_crow_ptr = (layout_crow_ptr + off_h * layout_crow_stride_h + \n q_pbid * layout_crow_stride_m)\n k_block_start = tl.load(sparse_crow_ptr).to(tl.int32)\n k_block_end = tl.load(sparse_crow_ptr + 1).to(tl.int32)\n m_i = tl.zeros([BLOCK_M_LOADING], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M_LOADING], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M_LOADING, BLOCK_D], dtype=tl.float32)\n k_ptrs = K + offs_n[None, :] * stride_kt + offs_d[:, None] * stride_kd\n v_ptrs = V + offs_n[:, None] * stride_vt + offs_d[None, :] * stride_vd\n sm_scale *= 1.44269504\n for k_block_col_idx in range(k_block_start, k_block_end - 1):\n acc, l_i, m_i = _fwd_kernel_inner(acc, l_i, m_i, q, Q,\n k_block_col_idx, layout_col_ptr, layout_col_stride_h,\n layout_col_stride_m, k_ptrs, v_ptrs, off_h, offs_m, offs_n,\n offs_d, stride_kt, stride_vt, sm_scale, k_seqlen, past_len, \n False, BLOCK_M_LOADING, BLOCK_N, D_HEAD, EVEN_D, M_LT_N)\n acc, l_i, m_i = _fwd_kernel_inner(acc, l_i, m_i, q, Q, k_block_end - 1,\n layout_col_ptr, layout_col_stride_h, layout_col_stride_m, k_ptrs,\n v_ptrs, off_h, offs_m, offs_n, offs_d, stride_kt, stride_vt,\n sm_scale, k_seqlen, past_len, True, BLOCK_M_LOADING, BLOCK_N,\n D_HEAD, EVEN_D, M_LT_N)\n m_i += tl.math.log2(l_i)\n acc = acc / l_i[:, None]\n if EVEN_D:\n tl.store(Out + offs_m[:, None] * stride_ot + offs_d[None, :] *\n stride_od, acc, mask=offs_m[:, None] < q_seqlen)\n else:\n tl.store(Out + offs_m[:, None] * stride_ot + offs_d[None, :] *\n stride_od, acc, mask=(offs_m[:, None] < q_seqlen) & (offs_d[\n None, :] < D_HEAD))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/Charlie-XIAO/sparse-vllm/blob/d228909a30b0c245c35417fb7d2acdf9a3690042/vllm/attention/ops/blocksparse_attention/blocksparse_attention_kernel.py" }, { "uuid": "c300b4e5-1dbd-46a8-8b9f-f7553220381b", "file_name": "activations.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/activations.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['D'])\n@triton.jit\ndef logsigmoid_bwd_kernel(x, dx, dy, temperature, T: tl.constexpr, D: tl.\n constexpr, B: tl.constexpr):\n i = tl.program_id(0)\n o_i = i * B + tl.arange(0, B)\n m_i = o_i < T\n b_x = tl.load(x + o_i, mask=m_i, other=0.0).to(tl.float32)\n b_dy = tl.load(dy + o_i, mask=m_i, other=0.0).to(tl.float32)\n b_dx = b_dy * (1.0 - tl.sigmoid(b_x)) / temperature\n tl.store(dx + o_i, b_dx.to(dx.dtype.element_ty), mask=m_i)\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/activations.py" }, { "uuid": "b43d8c40-6f78-4266-94b9-fa7ef9d6e79b", "file_name": "fused_attention.py", "repo_name": "jax-ml/jax-triton", "file_path": "examples/fused_attention.py", "commit_hash": "859cc392bec876d132bd0790ea6c00b6c246dd2b", "starcount": 0, "input": "@triton.jit\ndef fused_attention_kernel(Q, K, V, stride_qz, stride_qh, stride_qm,\n stride_qk, stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vk, stride_vn, stride_oz, stride_oh, stride_om,\n stride_on, Z, H, N_CTX, L, M, Out, BLOCK_M: tl.constexpr, BLOCK_DMODEL:\n tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n off_q = off_hz * stride_qh + offs_m[:, None] * stride_qm + offs_d[None, :\n ] * stride_qk\n off_k = off_hz * stride_qh + offs_n[None, :] * stride_kn + offs_d[:, None\n ] * stride_kk\n off_v = off_hz * stride_qh + offs_n[:, None] * stride_qm + offs_d[None, :\n ] * stride_qk\n q_ptrs = Q + off_q\n k_ptrs = K + off_k\n v_ptrs = V + off_v\n m_prev = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_prev = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n q = tl.load(q_ptrs)\n for start_n in range(0, (start_m + 1) * BLOCK_M, BLOCK_N):\n k = tl.load(k_ptrs)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n m_curr = tl.maximum(tl.max(qk, 1), m_prev)\n l_prev *= tl.exp(m_prev - m_curr)\n p = tl.exp(qk - m_curr[:, None])\n l_curr = tl.sum(p, 1) + l_prev\n l_rcp = 1.0 / l_curr\n p *= l_rcp\n acc *= (l_prev * l_rcp)[:, None]\n p = p.to(tl.float16)\n v = tl.load(v_ptrs)\n acc += tl.dot(p, v)\n l_prev = l_curr\n m_prev = m_curr\n k_ptrs += BLOCK_N * stride_kn\n v_ptrs += BLOCK_N * stride_vk\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n l_ptrs = L + off_hz * N_CTX + offs_m\n m_ptrs = M + off_hz * N_CTX + offs_m\n tl.store(l_ptrs, l_prev)\n tl.store(m_ptrs, m_prev)\n offs_n = tl.arange(0, BLOCK_DMODEL)\n off_o = off_hz * stride_oh + offs_m[:, None] * stride_om + offs_n[None, :\n ] * stride_on\n out_ptrs = Out + off_o\n tl.store(out_ptrs, acc)\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/jax-ml/jax-triton/blob/859cc392bec876d132bd0790ea6c00b6c246dd2b/examples/fused_attention.py" }, { "uuid": "4cfcaf22-7a0b-419b-aee9-80c0e072e341", "file_name": "p_loss_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/p_loss_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=element_wise_kernel_configs(), key=['size'])\n@triton.jit\ndef p_loss_forward_kernel(input_pointer, target_pointer, output_pointer,\n size, p_loss: tl.constexpr, reduction: tl.constexpr, BLOCK_SIZE: tl.\n constexpr):\n \"\"\"\n Measures the L1 or squared L2 norm of the difference between the input\n and target (i.e., mean absolute error or mean squared error).\n\n Args:\n input_pointer: Pointer to the input.\n The input must be of shape [size].\n target_pointer: Pointer to the target.\n The target must be of shape [size].\n output_pointer: Pointer to a container the error is written to.\n The container must be of shape [size] if reduction is 'none',\n and otherwise of shape [size/BLOCK_SIZE].\n size: Number of elements in the input and target.\n p_loss: p-norm used to compute the error.\n Options are 1 for MAE and 2 for MSE.\n reduction: Reduction strategy for the output.\n Options are 'none' for no reduction, 'mean' for averaging the error\n across all entries, and 'sum' for summing the error across all entries.\n If a reduction method is specified, the reduced result of each\n program is written to a separate index in the output container,\n which should later be summed.\n BLOCK_SIZE: Block size.\n \"\"\"\n pid = tl.program_id(axis=0)\n offset = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = offset < size\n input = tl.load(input_pointer + offset, mask=mask).to(tl.float32)\n target = tl.load(target_pointer + offset, mask=mask).to(tl.float32)\n diff = input - target\n if p_loss == 1:\n error = tl.abs(diff)\n elif p_loss == 2:\n error = diff * diff\n if reduction == 'none':\n tl.store(output_pointer + offset, error, mask=mask)\n elif reduction == 'mean':\n tl.store(output_pointer + pid, tl.sum(error) / size)\n elif reduction == 'sum':\n tl.store(output_pointer + pid, tl.sum(error))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Memory-Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/p_loss_kernels.py" }, { "uuid": "06715f51-47ba-4d5e-b5b1-762ebe00b772", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_rcum_inter(s, z, ss, doo, s_s_h, s_s_t, s_s_d, T:\n tl.constexpr, S: tl.constexpr, BT: tl.constexpr, BS: tl.constexpr, NT:\n tl.constexpr):\n i_m, i_bh = tl.program_id(0), tl.program_id(1)\n b_sp = tl.zeros([BS], dtype=tl.float32)\n b_zp = tl.full([BS], float('inf'), dtype=tl.float32)\n for i_t in range(NT - 1, -1, -1):\n p_s = tl.make_block_ptr(s + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (\n i_t * BT, i_m * BS), (BT, BS), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * s_s_h, (T, S), (s_s_t, s_s_d), (\n i_t * BT, i_m * BS), (BT, BS), (1, 0))\n p_zc = tl.make_block_ptr(z + i_bh * s_s_h, (T * S,), (s_s_d,), (i_t *\n BT * S + i_m * BS,), (BS,), (0,))\n p_ss = tl.make_block_ptr(ss + i_bh * s_s_h, (T, S), (s_s_t, s_s_d),\n (i_t * BT, i_m * BS), (BT, BS), (1, 0))\n p_doo = tl.make_block_ptr(doo + i_bh * s_s_h, (T, S), (s_s_t, s_s_d\n ), (i_t * BT, i_m * BS), (BT, BS), (1, 0))\n b_zc = tl.load(p_zc, boundary_check=(0,))\n b_s = tl.load(p_s, boundary_check=(0, 1))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_ss = tl.load(p_ss, boundary_check=(0, 1))\n b_doo = tl.exp(b_s - b_zp[None, :]) * b_sp[None, :]\n tl.store(p_doo, b_doo.to(p_doo.dtype.element_ty), boundary_check=(0, 1)\n )\n b_sp = b_sp * tl.exp(b_zc - b_zp) + tl.sum(b_ss * tl.exp(b_zc[None,\n :] - b_z), 0)\n b_zp = b_zc\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "a7157c38-ed86-4b92-a574-24221d10c58b", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_backward_input_grad_core(a_ptr, b_ptr, c_ptr, init_factor, M,\n N, K, H, stride_am, stride_an, stride_cm, stride_ck, R7: int, R6: int,\n R5: int, R4: int, R3: int, R2: int, R1: int, R0: int, allow_tf32: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = (A x B^T)\n A has shape (M, N), B has shape H->(K, N) and C has shape (M, K)\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_k = tl.cdiv(K, BLOCK_SIZE_K)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid // num_pid_k\n pid_k = pid % num_pid_k\n offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_an = tl.arange(0, BLOCK_SIZE_N)\n a_ptrs = a_ptr + offs_am[:, None] * stride_am + offs_an[None, :\n ] * stride_an\n b_offset = b_ptr + tl.arange(0, BLOCK_SIZE_N)[:, None] + tl.arange(0,\n BLOCK_SIZE_K)[None, :] * BLOCK_SIZE_N\n b_ptrs = b_offset + ((pid_k * R3 + 0 * R2 + R1) % R0 * R0 + (pid_k * R7 +\n 0 * R5 + R4) % R0) % (H - BLOCK_SIZE_K * BLOCK_SIZE_N)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_ck = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n a_zero = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n b_zero = tl.zeros((BLOCK_SIZE_N, BLOCK_SIZE_K), dtype=tl.float32)\n c = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_K), dtype=tl.float32)\n for n in range(0, tl.cdiv(N, BLOCK_SIZE_N)):\n offs_n = n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n a_mask = (offs_cm[:, None] < M) & (offs_n[None, :] < N)\n b_mask = (offs_n[:, None] < N) & (offs_ck[None, :] < K)\n a = tl.load(a_ptrs, mask=a_mask, other=a_zero)\n b = tl.load(b_ptrs, mask=b_mask, other=b_zero)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_N * stride_an\n b_ptrs = b_offset + ((pid_k * R3 + (n + 1) * R2 + R1) % R0 * R0 + (\n pid_k * R7 + (n + 1) * R5 + R4) % R0) % (H - BLOCK_SIZE_K *\n BLOCK_SIZE_N)\n offs_ck = pid_k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n c_ptrs = c_ptr + stride_cm * offs_cm[:, None] + stride_ck * offs_ck[None, :\n ]\n c_mask = (offs_cm[:, None] < M) & (offs_ck[None, :] < K)\n tl.store(c_ptrs, c * init_factor, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled", "Coalesced", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "05d08524-53cf-4f3e-9cb8-78a7df7efc34", "file_name": "y_6.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_6.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef sixth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_9 = tl.load(sph_grad_ptr + output_row_offset + 9, mask=\n output_row_offset + 9 < output_numel)\n g_10 = tl.load(sph_grad_ptr + output_row_offset + 10, mask=\n output_row_offset + 10 < output_numel)\n g_11 = tl.load(sph_grad_ptr + output_row_offset + 11, mask=\n output_row_offset + 11 < output_numel)\n g_12 = tl.load(sph_grad_ptr + output_row_offset + 12, mask=\n output_row_offset + 12 < output_numel)\n CONST000 = 2.0\n CONST002 = 4.0\n CONST003 = 3.0\n CONST004 = 6.53117523880657\n CONST006 = 8.94318001328386\n CONST007 = 8.38944649544891\n CONST008 = 10.3266947761614\n CONST009 = 9.79676285820985\n CONST013 = 16.3279380970164\n CONST014 = 17.8863600265677\n CONST015 = 16.5227116418583\n CONST016 = 20.6533895523229\n CONST017 = 20.2812259244849\n CONST018 = 21.6333076527839\n CONST020 = 17.8863600265677\n CONST022 = 29.3902885746295\n CONST024 = 35.7727200531355\n CONST026 = 40.5624518489699\n CONST028 = 41.9472324772445\n CONST029 = 48.9838142910493\n CONST030 = 51.6334738808072\n CONST035 = 71.5454401062709\n CONST037 = 81.1249036979398\n CONST039 = 82.6135582092915\n CONST040 = -3.26558761940328\n CONST042 = 117.561154298518\n CONST046 = 208.99760764181\n CONST048 = -251.683394863467\n CONST049 = -214.636320318813\n CONST050 = -214.636320318813\n CONST051 = 16.5227116418583\n CONST052 = -167.788929908978\n CONST053 = -156.748205731358\n CONST054 = -145.309475774982\n CONST055 = -123.920337313937\n CONST056 = -117.561154298518\n CONST057 = 3.26558761940328\n CONST058 = -108.16653826392\n CONST059 = -107.318160159406\n CONST060 = -104.498803820905\n CONST061 = -104.498803820905\n CONST062 = -83.8944649544891\n CONST063 = -82.6135582092915\n CONST064 = -78.3741028656788\n CONST065 = -72.6547378874909\n CONST066 = -71.5454401062709\n CONST067 = -58.7805771492591\n CONST068 = -54.0832691319598\n CONST069 = -52.2494019104525\n CONST070 = -52.2494019104525\n CONST071 = -48.9838142910492\n CONST072 = -41.3067791046458\n CONST073 = -39.1870514328394\n CONST074 = -35.7727200531355\n CONST075 = -29.3902885746295\n CONST076 = -27.0416345659799\n CONST077 = -26.1247009552263\n CONST078 = -26.1247009552263\n CONST079 = -19.5935257164197\n CONST080 = -14.5309475774982\n CONST081 = -13.52081728299\n CONST082 = -10.7318160159406\n CONST083 = -9.79676285820985\n CONST084 = -7.15454401062709\n CONST085 = -6.76040864149498\n CONST086 = -3.38020432074749\n CONST087 = -1.63279380970164\n VAR07 = x * x * x\n VAR08 = x * x\n VAR05 = VAR07 * VAR08\n VAR06 = VAR08 * VAR08\n VAR16 = y * y * y\n VAR17 = y * y\n VAR14 = VAR16 * VAR17\n VAR15 = VAR17 * VAR17\n VAR25 = z * z * z\n VAR26 = z * z\n VAR23 = VAR25 * VAR26\n VAR24 = VAR26 * VAR26\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += g_0 * (CONST054 * VAR08 * VAR25 - CONST065 * VAR06 * z - \n CONST080 * VAR23) + g_1 * y * (CONST028 * VAR06 + CONST028 * VAR24 +\n CONST048 * VAR08 * VAR26) + g_10 * (CONST000 * x * (CONST006 *\n VAR24 + CONST059 * VAR17 * VAR26) + CONST002 * VAR07 * (CONST006 *\n VAR26 + CONST014 * VAR17) + CONST082 * VAR05) + g_11 * y * (-\n CONST052 * VAR07 * z + CONST052 * VAR25 * x) + g_12 * (-CONST054 *\n VAR07 * VAR26 + CONST065 * VAR24 * x + CONST080 * VAR05) + g_2 * (-\n CONST074 * VAR06 * z + CONST084 * VAR23 + VAR17 * (CONST049 * VAR08 *\n z - CONST066 * VAR25)) + g_3 * (VAR16 * (CONST064 * VAR08 - \n CONST064 * VAR26) + y * (CONST029 * VAR06 + CONST067 * VAR08 *\n VAR26 + CONST075 * VAR24)) + g_4 * (CONST003 * VAR08 * (CONST004 *\n VAR25 + CONST069 * VAR17 * z) + CONST013 * VAR06 * z - CONST040 *\n VAR23 - CONST070 * VAR15 * z + CONST070 * VAR17 * VAR25) + g_5 * (\n CONST003 * VAR08 * (CONST016 * VAR26 * y + CONST072 * VAR16) + \n CONST008 * VAR24 * y + CONST015 * VAR14 + CONST030 * VAR06 * y + \n CONST072 * VAR16 * VAR26) + g_6 * (CONST000 * x * (CONST026 * VAR17 *\n VAR26 + CONST076 * VAR15 + CONST086 * VAR24) + CONST002 * VAR07 * (\n CONST017 * VAR17 + CONST086 * VAR26) + CONST085 * VAR05) + g_7 * (-\n CONST072 * VAR25 * x * y + z * (CONST063 * VAR16 * x - CONST072 *\n VAR07 * y)) + g_8 * (CONST000 * x * (CONST077 * VAR15 - CONST087 *\n VAR24) + CONST002 * VAR07 * (-CONST077 * VAR17 + CONST087 * VAR26) +\n CONST083 * VAR05) + g_9 * (CONST053 * VAR16 * x * z + y * (CONST042 *\n VAR07 * z - CONST073 * VAR25 * x))\n g_y += CONST000 * g_2 * y * (CONST066 * VAR07 * z - CONST066 * VAR25 * x\n ) + g_1 * (CONST007 * VAR05 + CONST028 * VAR24 * x + CONST062 *\n VAR07 * VAR26) + g_10 * (CONST024 * VAR06 * y + CONST050 * VAR08 *\n VAR26 * y - CONST074 * VAR24 * y) + g_11 * (CONST007 * VAR23 + \n CONST028 * VAR06 * z + CONST062 * VAR08 * VAR25) + g_3 * (CONST003 *\n VAR17 * (-CONST064 * VAR26 * x + CONST078 * VAR07) + CONST009 *\n VAR05 + CONST075 * VAR24 * x + CONST079 * VAR07 * VAR26) + g_4 * (\n CONST061 * VAR07 * y * z + x * (CONST046 * VAR16 * z + CONST060 *\n VAR25 * y)) + g_5 * (CONST008 * VAR05 + VAR07 * (CONST016 * VAR26 +\n CONST055 * VAR17) + x * (CONST008 * VAR24 + CONST055 * VAR17 *\n VAR26 - CONST063 * VAR15)) + g_6 * (CONST018 * VAR14 + CONST026 *\n VAR06 * y + CONST026 * VAR24 * y + CONST058 * VAR16 * VAR26 + VAR08 *\n (CONST037 * VAR26 * y + CONST058 * VAR16)) + g_7 * (CONST008 *\n VAR23 + VAR25 * (CONST016 * VAR08 + CONST055 * VAR17) + z * (\n CONST008 * VAR06 + CONST039 * VAR15 + CONST055 * VAR08 * VAR17)\n ) + g_8 * (CONST060 * VAR08 * VAR16 - CONST060 * VAR16 * VAR26 + \n CONST069 * VAR24 * y - CONST070 * VAR06 * y) + g_9 * (CONST003 *\n VAR17 * (CONST064 * VAR08 * z - CONST077 * VAR25) + CONST022 *\n VAR06 * z - CONST079 * VAR08 * VAR25 + CONST083 * VAR23)\n g_z += g_0 * (CONST054 * VAR07 * VAR26 - CONST065 * VAR24 * x - \n CONST080 * VAR05) + g_1 * y * (CONST052 * VAR07 * z - CONST052 *\n VAR25 * x) + g_10 * (CONST020 * VAR06 * z + CONST035 * VAR17 *\n VAR25 + CONST082 * VAR23 + VAR08 * (CONST050 * VAR17 * z - CONST074 *\n VAR25)) + g_11 * y * (CONST028 * VAR06 + CONST028 * VAR24 + \n CONST048 * VAR08 * VAR26) + g_12 * (CONST054 * VAR08 * VAR25 - \n CONST065 * VAR06 * z - CONST080 * VAR23) + g_2 * (CONST074 * VAR24 *\n x - CONST084 * VAR05 + VAR17 * (-CONST049 * VAR26 * x + CONST066 *\n VAR07)) + g_3 * (-CONST053 * VAR16 * x * z + y * (CONST056 * VAR25 *\n x + CONST073 * VAR07 * z)) + g_4 * (CONST057 * VAR05 + VAR07 * (\n CONST069 * VAR17 - CONST079 * VAR26) + x * (CONST013 * VAR24 + \n CONST053 * VAR17 * VAR26 - CONST070 * VAR15)) + g_5 * (-CONST072 *\n VAR07 * y * z + x * (CONST063 * VAR16 * z - CONST072 * VAR25 * y)\n ) + g_6 * (CONST037 * VAR17 * VAR25 + CONST068 * VAR15 * z + \n CONST085 * VAR06 * z + CONST085 * VAR23 + VAR08 * (CONST037 * VAR17 *\n z + CONST081 * VAR25)) + g_7 * (CONST003 * VAR26 * (CONST016 *\n VAR08 * y + CONST072 * VAR16) + CONST008 * VAR06 * y + CONST030 *\n VAR24 * y + CONST051 * VAR14 + CONST072 * VAR08 * VAR16) + g_8 * (\n CONST004 * VAR08 * VAR25 + CONST040 * VAR06 * z + CONST061 * VAR17 *\n VAR25 - CONST070 * VAR15 * z - CONST083 * VAR23) + g_9 * (VAR16 * (\n CONST064 * VAR08 - CONST064 * VAR26) + y * (CONST022 * VAR06 - \n CONST067 * VAR08 * VAR26 + CONST071 * VAR24))\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_6.py" }, { "uuid": "a0f70947-0554-494b-86bd-c3544da457a5", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BK', 'NC', 'BT'])\n@triton.jit\ndef chunk_rwkv6_bwd_kernel_intra(q, k, gi, ge, dA, dq, dk, offsets, indices,\n T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, BT: tl.constexpr, BC:\n tl.constexpr, BK: tl.constexpr, NC: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_k, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_t, i_i = i_c // NC, i_c % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n if i_t * BT + i_i * BC >= T:\n return\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_ge = tl.make_block_ptr(ge + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n p_ge = tl.make_block_ptr(ge + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n b_ge = tl.load(p_ge, boundary_check=(0, 1))\n b_dq = tl.zeros([BC, BK], dtype=tl.float32)\n if i_i > 0:\n if HEAD_FIRST:\n p_gn = tl.max_contiguous(tl.multiple_of(gi + (i_bh * T + i_t *\n BT + i_i * BC) * K + o_k, BK), BK)\n else:\n p_gn = tl.max_contiguous(tl.multiple_of(gi + (bos + i_t * BT + \n i_i * BC) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n for i_j in range(0, i_i):\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(gi + i_bh * T * K, (T, K), (K, 1),\n (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (T, BT), (BT, \n 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(gi + (bos * H + i_h) * K, (T, K),\n (H * K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK),\n (1, 0))\n p_dA = tl.make_block_ptr(dA + (bos * H + i_h) * BT, (T, BT),\n (H * BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC),\n (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_kg = b_k * tl.exp(b_gn[None, :] - b_gk)\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dq += tl.dot(b_dA, b_kg)\n b_dq *= tl.exp(b_ge - b_gn[None, :])\n o_i = tl.arange(0, BC)\n m_dA = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n if HEAD_FIRST:\n o_dA = i_bh * T * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * BT + i_i * BC\n p_kj = tl.max_contiguous(tl.multiple_of(k + (i_bh * T + i_t * BT + \n i_i * BC) * K + o_k, BK), BK)\n p_gkj = tl.max_contiguous(tl.multiple_of(gi + (i_bh * T + i_t * BT +\n i_i * BC) * K + o_k, BK), BK)\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n o_dA = bos * H * BT + (i_t * BT + i_i * BC + tl.arange(0, BC)\n ) * H * BT + i_h * BT + i_i * BC\n p_kj = tl.max_contiguous(tl.multiple_of(k + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gkj = tl.max_contiguous(tl.multiple_of(gi + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_dA = tl.load(dA + o_dA + j, mask=m_dA, other=0)\n b_kj = tl.load(p_kj, mask=m_k, other=0).to(tl.float32)\n b_gkj = tl.load(p_gkj, mask=m_k, other=0).to(tl.float32)\n m_i = o_i[:, None] > j\n b_dq += tl.where(m_i, b_dA[:, None] * b_kj[None, :] * tl.exp(b_ge -\n b_gkj[None, :]), 0.0)\n p_kj += K if HEAD_FIRST else H * K\n p_gkj += K if HEAD_FIRST else H * K\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.debug_barrier()\n if HEAD_FIRST:\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT +\n i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(gi + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_gk = tl.make_block_ptr(gi + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_dk = tl.zeros([BC, BK], dtype=tl.float32)\n NC = min(NC, tl.cdiv(T - i_t * BT, BC))\n if i_i < NC - 1:\n if HEAD_FIRST:\n p_gn = tl.max_contiguous(tl.multiple_of(gi + i_bh * T * K + (\n i_t * BT + i_i * BC + BC - 1) * K + o_k, BK), BK)\n else:\n p_gn = tl.max_contiguous(tl.multiple_of(gi + bos * H * K + (i_t *\n BT + i_i * BC + BC - 1) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n for i_j in range(i_i + 1, NC):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_ge = tl.make_block_ptr(ge + i_bh * T * K, (T, K), (K, 1),\n (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_dA = tl.make_block_ptr(dA + i_bh * T * BT, (BT, T), (1,\n BT), (i_i * BC, i_t * BT + i_j * BC), (BC, BC), (0, 1))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK), (1, 0))\n p_ge = tl.make_block_ptr(ge + (bos * H + i_h) * K, (T, K),\n (H * K, 1), (i_t * BT + i_j * BC, i_k * BK), (BC, BK),\n (1, 0))\n p_dA = tl.make_block_ptr(dA + (bos * H + i_h) * BT, (BT, T),\n (1, H * BT), (i_i * BC, i_t * BT + i_j * BC), (BC, BC),\n (0, 1))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_ge = tl.load(p_ge, boundary_check=(0, 1))\n b_qg = b_q * tl.exp(b_ge - b_gn[None, :])\n b_dA = tl.load(p_dA, boundary_check=(0, 1))\n b_dk += tl.dot(b_dA, b_qg)\n b_dk *= tl.exp(b_gn[None, :] - b_gk)\n if HEAD_FIRST:\n o_dA = i_bh * T * BT + (i_t * BT + i_i * BC\n ) * BT + i_i * BC + tl.arange(0, BC)\n p_qj = tl.max_contiguous(tl.multiple_of(q + (i_bh * T + i_t * BT + \n i_i * BC) * K + o_k, BK), BK)\n p_gqj = tl.max_contiguous(tl.multiple_of(ge + (i_bh * T + i_t * BT +\n i_i * BC) * K + o_k, BK), BK)\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n else:\n o_dA = bos * H * BT + (i_t * BT + i_i * BC\n ) * H * BT + i_h * BT + i_i * BC + tl.arange(0, BC)\n p_qj = tl.max_contiguous(tl.multiple_of(q + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_gqj = tl.max_contiguous(tl.multiple_of(ge + (bos + i_t * BT + i_i *\n BC) * H * K + i_h * K + o_k, BK), BK)\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n for j in range(0, min(BC, T - i_t * BT - i_i * BC)):\n b_dA = tl.load(dA + o_dA + j * (1 if HEAD_FIRST else H) * BT)\n b_qj = tl.load(p_qj, mask=m_k, other=0).to(tl.float32)\n b_gqj = tl.load(p_gqj, mask=m_k, other=0).to(tl.float32)\n m_i = o_i[:, None] < j\n b_dk += tl.where(m_i, b_dA[:, None] * b_qj[None, :] * tl.exp(b_gqj[\n None, :] - b_gk), 0.0)\n p_qj += K if HEAD_FIRST else H * K\n p_gqj += K if HEAD_FIRST else H * K\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "7dce9668-e8af-4269-bead-36df38944bcf", "file_name": "test_trampolines.py", "repo_name": "makslevental/triton-pp", "file_path": "tests/test_trampolines.py", "commit_hash": "e2b3e2a35d96007fa1ae129432cf8e99f44588a1", "starcount": 0, "input": "@triton.jit\ndef kernel_0123():\n c64 = arith.constant(64)\n v0 = tl.get_program_id(axis='x')\n air.channel('bob')\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/makslevental/triton-pp/blob/e2b3e2a35d96007fa1ae129432cf8e99f44588a1/tests/test_trampolines.py" }, { "uuid": "4c1cbb13-c951-420c-9482-b1b3dfa04e72", "file_name": "flash_attn_v2.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/flash_attn_v2.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _triton_attn_fwd(Q, K, V, sm_scale, Out, stride_qz, stride_qh,\n stride_qm, stride_qk, stride_kz, stride_kh, stride_km, stride_kk,\n stride_vz, stride_vh, stride_vm, stride_vk, stride_oz, stride_oh,\n stride_om, stride_ok, Z, H, N_CTX, POWER_OF_2_N_CTX: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.\n constexpr, STAGE: tl.constexpr, GROUPS: tl.constexpr, ORDER_12: tl.\n constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n off_z = off_hz // H\n off_h = off_hz % H\n off_g = tl.program_id(2)\n q_offset = off_z.to(tl.int64) * stride_qz + (off_h * GROUPS + off_g).to(tl\n .int64) * stride_qh\n k_offset = off_z.to(tl.int64) * stride_kz + off_h.to(tl.int64) * stride_kh\n v_offset = off_z.to(tl.int64) * stride_vz + off_h.to(tl.int64) * stride_vh\n o_offset = off_z.to(tl.int64) * stride_oz + (off_h * GROUPS + off_g).to(tl\n .int64) * stride_oh\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n V_block_ptr = tl.make_block_ptr(base=V + v_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vm, stride_vk), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + k_offset, shape=(BLOCK_DMODEL,\n N_CTX), strides=(stride_kk, stride_km), offsets=(0, 0), block_shape\n =(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n O_block_ptr = tl.make_block_ptr(base=Out + o_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_ok), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale\n qk_scale *= 1.44269504\n q = tl.load(Q_block_ptr, boundary_check=(0, 1))\n if ORDER_12:\n if STAGE & 1:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, 4 - STAGE, offs_m, offs_n, N_CTX)\n if STAGE & 2:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, 2, offs_m, offs_n, N_CTX)\n else:\n if STAGE & 2:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, 2, offs_m, offs_n, N_CTX)\n if STAGE & 1:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, BLOCK_DMODEL,\n BLOCK_N, 4 - STAGE, offs_m, offs_n, N_CTX)\n acc = acc / l_i[:, None]\n tl.store(O_block_ptr, acc.to(Out.type.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/flash_attn_v2.py" }, { "uuid": "5d6abe36-b7ab-46ee-8bc8-8b128a0ced17", "file_name": "mhmoe_bwd.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe_bwd.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.jit\ndef d_leacky_relu_inv_backward(x):\n return tl.where(x >= 0, 1.0, 0.01)\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe_bwd.py" }, { "uuid": "ded8c553-2ca2-4e7d-9912-b022a9f954cd", "file_name": "seqlen_utils.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/seqlen_utils.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef code_to_seqlen_kernel(code_ptr, seqlen_ptr, B, N, BLK: tl.constexpr):\n pid = tl.program_id(0)\n out = tl.zeros((1,), dtype=tl.int32)\n for nidx in range(tl.cdiv(N, BLK)):\n offs_n = nidx * BLK + tl.arange(0, BLK)\n mask_n = offs_n < N\n code = tl.load(code_ptr + offs_n, mask=mask_n, other=32767 << 48)\n bidx = (code >> 48 & 32767).to(tl.int32)\n x = tl.min((bidx == pid).to(tl.int32) * (offs_n - 65535), axis=0)\n out = tl.minimum(out, x)\n out = tl.where(out == 0, -1, out + 65535)\n tl.store(seqlen_ptr + pid + tl.arange(0, 1), out)\n tl.store(seqlen_ptr + B, N, mask=pid == B - 1)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/seqlen_utils.py" }, { "uuid": "6138d269-eae2-4f97-9029-ca31d8e08751", "file_name": "triton_gather_gemv.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/gather_gemv/triton_gather_gemv.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'XBLOCK': 1, 'RBLOCK': 2048},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 64, 'RBLOCK': 8},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 64, 'RBLOCK': 4},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 8, 'RBLOCK': 512},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 8, 'RBLOCK': 256},\n num_stages=1, num_warps=8), triton.Config({'XBLOCK': 64, 'RBLOCK': 64},\n num_stages=1, num_warps=8)], key=['xnumel', 'rnumel'])\n@triton.jit\ndef triton_red_fused_mv_0(in_ptr0, in_ptr1, in_ptr2, out_ptr1, xnumel,\n rnumel, XBLOCK: tl.constexpr, RBLOCK: tl.constexpr):\n xoffset = tl.program_id(0).to(tl.int64) * XBLOCK\n xindex = xoffset + tl.arange(0, XBLOCK)[:, None].to(tl.int64)\n xmask = xindex < xnumel\n rbase = tl.arange(0, RBLOCK)[None, :].to(tl.int64)\n x0 = xindex\n tmp0 = tl.load(in_ptr0 + x0 // rnumel, None, eviction_policy='evict_last')\n _tmp11 = tl.full([XBLOCK, RBLOCK], 0, tl.float32)\n for roffset in range(0, rnumel, RBLOCK):\n rindex = roffset + rbase\n rmask = rindex < rnumel\n r1 = rindex\n tmp7 = tl.load(in_ptr2 + r1, None, eviction_policy='evict_last').to(tl\n .float32)\n tmp1 = tmp0 + 8\n tmp2 = tmp0 < 0\n tmp3 = tl.where(tmp2, tmp1, tmp0)\n tmp4 = tl.load(in_ptr1 + (r1 + rnumel * (x0 % rnumel) + rnumel *\n rnumel * tmp3), None, eviction_policy='evict_first')\n tmp5 = tmp4.to(tl.float32)\n tmp6 = tmp5.to(tl.float32)\n tmp8 = tmp7.to(tl.float32)\n tmp9 = tmp6 * tmp8\n tmp10 = tl.broadcast_to(tmp9, [XBLOCK, RBLOCK])\n tmp12 = _tmp11 + tmp10\n _tmp11 = tmp12\n tmp11 = tl.sum(_tmp11, 1)[:, None]\n tmp13 = tmp11.to(tl.float32)\n tl.store(out_ptr1 + x0, tmp13, None)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/gather_gemv/triton_gather_gemv.py" }, { "uuid": "98971ea6-db2e-4e5f-a174-4421a69d2430", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/retention/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_retention_bwd_kernel_dkv(i_bh, i_t, i_k, i_v, i_h, q, k, v, do,\n dk, dv, scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr, K: tl\n .constexpr, V: tl.constexpr, BT: tl.constexpr, BS: tl.constexpr, BK: tl\n .constexpr, BV: tl.constexpr):\n b_b = tl.math.log2(1 - tl.math.exp2(-5 - i_h * 1.0))\n d_b = tl.math.exp2(b_b * BS)\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT, \n i_k * BK), (BT, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT, \n i_v * BV), (BT, BV), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_dv = tl.zeros([BT, BV], dtype=tl.float32)\n NTS = tl.cdiv(T, BS)\n d_h = tl.math.exp2((BT - tl.arange(0, BT)) * b_b)\n b_kd = (b_k * d_h[:, None]).to(b_k.dtype)\n d_q = tl.math.exp2(tl.arange(0, BS) * b_b)\n for i in range(NTS * BS - BS, (i_t + 1) * BT - BS, -BS):\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i, i_k *\n BK), (BS, BK), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i, i_v *\n BV), (BS, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * d_q[:, None]).to(b_do.dtype)\n b_dk *= d_b\n b_dv *= d_b\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False)\n b_s = tl.dot(b_kd, tl.trans(b_q), allow_tf32=False)\n b_dk += tl.dot(b_ds.to(b_q.dtype), b_q, allow_tf32=False)\n b_dv += tl.dot(b_s.to(b_do.dtype), b_do, allow_tf32=False)\n b_dk *= d_h[:, None] * scale\n b_dv *= scale\n tl.debug_barrier()\n o_q, o_k = tl.arange(0, BS), tl.arange(0, BT)\n for i in range(i_t * BT, (i_t + 1) * BT, BS):\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i, i_k *\n BK), (BS, BK), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (i, i_v *\n BV), (BS, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n m_s = o_k[:, None] <= o_q[None, :]\n d_s = tl.where(m_s, tl.math.exp2((-o_k[:, None] + o_q[None, :]) *\n b_b.to(tl.float32)), 0) * scale\n b_ds = tl.dot(b_v, tl.trans(b_do), allow_tf32=False) * d_s\n b_s = tl.dot(b_k, tl.trans(b_q), allow_tf32=False) * d_s\n b_dk += tl.dot(b_ds.to(b_q.dtype), b_q, allow_tf32=False)\n b_dv += tl.dot(b_s.to(b_q.dtype), b_do, allow_tf32=False)\n o_q += BS\n p_dk = tl.make_block_ptr(dk + (i_v * B * H + i_bh) * T * K, (T, K), (K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dv = tl.make_block_ptr(dv + (i_k * B * H + i_bh) * T * V, (T, V), (V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/retention/parallel.py" }, { "uuid": "1b335466-e870-434b-8c7d-160154dc930f", "file_name": "k_layer_norm.py", "repo_name": "cpuhrsch/torchfused", "file_path": "torchfused/triton/k_layer_norm.py", "commit_hash": "6c40ed160dcecbe7825f268f7c86bccd359e0ebf", "starcount": 0, "input": "@triton.jit\ndef _layer_norm_bwd_dx_fused(DX, DY, DW, DB, Y, W, B, V, Lock, stride, N,\n **META):\n GROUP_SIZE_M = META['GROUP_SIZE_M']\n BLOCK_SIZE_N = META['BLOCK_SIZE_N']\n row = tl.program_id(0)\n cols = tl.arange(0, BLOCK_SIZE_N)\n y_ptrs = Y + row * stride + cols\n dy_ptrs = DY + row * stride + cols\n w_ptrs = W + cols\n b_ptrs = B + cols\n lock_id = row % GROUP_SIZE_M\n Lock += lock_id\n Count = Lock + GROUP_SIZE_M\n y = tl.load(y_ptrs, mask=cols < N, other=0).to(tl.float32)\n dy = tl.load(dy_ptrs, mask=cols < N, other=0).to(tl.float32)\n w = tl.load(w_ptrs, mask=cols < N, other=0).to(tl.float32)\n b = tl.load(b_ptrs, mask=cols < N, other=0).to(tl.float32)\n rstd = tl.load(V + row)\n xhat = (y - b) / w\n wdy = w * dy\n xhat = tl.where(cols < N, xhat, 0.0)\n wdy = tl.where(cols < N, wdy, 0.0)\n mean1 = tl.sum(xhat * wdy, axis=0) / N\n mean2 = tl.sum(wdy, axis=0) / N\n dx = (wdy - (xhat * mean1 + mean2)) * rstd\n _store(dx, DX, stride, N, META)\n partial_dw = (dy * xhat).to(w.dtype)\n partial_db = dy.to(w.dtype)\n while tl.atomic_cas(Lock, 0, 1) == 1:\n pass\n count = tl.load(Count)\n dw_ptrs = DW + lock_id * N + cols\n db_ptrs = DB + lock_id * N + cols\n if count == 0:\n tl.atomic_xchg(Count, 1)\n else:\n partial_dw += tl.load(dw_ptrs, mask=cols < N, other=0.0)\n partial_db += tl.load(db_ptrs, mask=cols < N, other=0.0)\n tl.store(dw_ptrs, partial_dw, mask=cols < N)\n tl.store(db_ptrs, partial_db, mask=cols < N)\n tl.atomic_xchg(Lock, 0)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/cpuhrsch/torchfused/blob/6c40ed160dcecbe7825f268f7c86bccd359e0ebf/torchfused/triton/k_layer_norm.py" }, { "uuid": "e5d45e57-5c7b-4d2f-bf3e-65b3b35a34ee", "file_name": "softmax_loop_along_reduce_axis_v1.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_loop_along_reduce_axis_v1.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_loop_v1(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr):\n pid_m = tl.program_id(0)\n m = tl.full((), value=-float('inf'), dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n m = tl.maximum(m, tl.max(inp, 0))\n z = tl.full((), value=0, dtype=output_ptr.dtype.element_ty)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n z += tl.sum(e)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_loop_along_reduce_axis_v1.py" }, { "uuid": "5de2aa3e-085e-4400-b082-14c3014eba37", "file_name": "softplus.py", "repo_name": "shawntan/stickbreaking-attention", "file_path": "stickbreaking_attention/sb_varlen/softplus.py", "commit_hash": "8dd32ad5e58f0ee0232fd4782dc53d354ff8d283", "starcount": 0, "input": "@triton.jit\ndef softplus(x, is_compiling: tl.constexpr=False):\n if is_compiling:\n tl.static_print('Using triton softplus.')\n out = tl.where(x < 15.0, tl.math.log2(1 + tl.math.exp2(x)), x)\n return out\n else:\n out = tl.inline_asm_elementwise(asm=asm_str, constraints=\n constraints_str, pack=NUM_REG, args=[x], dtype=tl.float32,\n is_pure=True)\n return out\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Non-Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/shawntan/stickbreaking-attention/blob/8dd32ad5e58f0ee0232fd4782dc53d354ff8d283/stickbreaking_attention/sb_varlen/softplus.py" }, { "uuid": "a68d784e-b08f-44c8-afff-6f1cd84ee225", "file_name": "gemm_streamk_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef mac_loop(a_ptr, b_ptr, c_ptr, M: tl.constexpr, N: tl.constexpr, K: tl.\n constexpr, stride_am: tl.constexpr, stride_ak: tl.constexpr, stride_bk:\n tl.constexpr, stride_bn: tl.constexpr, stride_cm: tl.constexpr,\n stride_cn: tl.constexpr, iters_per_tile, start_iter, end_iter,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr):\n tile_id = start_iter // iters_per_tile\n remain_iters = start_iter % iters_per_tile\n if GROUP_SIZE_M > 0:\n pid_m, pid_n = swizzle_tile(tile_id, M, N, K, BLOCK_SIZE_M,\n BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M)\n else:\n pid_m, pid_n = linear_tile(tile_id, M, N, K, BLOCK_SIZE_M,\n BLOCK_SIZE_N, BLOCK_SIZE_K, GROUP_SIZE_M)\n a_ptr += BLOCK_SIZE_K * stride_ak * remain_iters\n a_block_ptr = tl.make_block_ptr(base=a_ptr, shape=(M, K), strides=(\n stride_am, stride_ak), offsets=(pid_m * BLOCK_SIZE_M, 0),\n block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_K), order=(1, 0))\n b_ptr += BLOCK_SIZE_K * stride_bk * remain_iters\n b_block_ptr = tl.make_block_ptr(base=b_ptr, shape=(K, N), strides=(\n stride_bk, stride_bn), offsets=(0, pid_n * BLOCK_SIZE_N),\n block_shape=(BLOCK_SIZE_K, BLOCK_SIZE_N), order=(1, 0))\n acc = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(start_iter, end_iter):\n a = tl.load(a_block_ptr, boundary_check=(0, 1))\n b = tl.load(b_block_ptr, boundary_check=(0, 1))\n acc += tl.dot(a, b)\n a_block_ptr = tl.advance(a_block_ptr, (0, BLOCK_SIZE_K))\n b_block_ptr = tl.advance(b_block_ptr, (BLOCK_SIZE_K, 0))\n if remain_iters == 0 and end_iter % iters_per_tile == 0:\n c_block_ptr = tl.make_block_ptr(base=c_ptr, shape=(M, N), strides=(\n stride_cm, stride_cn), offsets=(pid_m * BLOCK_SIZE_M, pid_n *\n BLOCK_SIZE_N), block_shape=(BLOCK_SIZE_M, BLOCK_SIZE_N), order=\n (1, 0))\n tl.store(c_block_ptr, acc, boundary_check=(0, 1))\n else:\n rm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n rn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n c_ptr_ = c_ptr + rm[:, None] * stride_cm + rn[None, :] * stride_cn\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n tl.atomic_add(c_ptr_, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/gemm_streamk_benchmark.py" }, { "uuid": "a730fe03-8fd6-4e0a-9e86-85418a5bb767", "file_name": "memory.py", "repo_name": "USC-NSL/DisagMoE", "file_path": "disagmoe/ops/memory.py", "commit_hash": "6e86ce027a9622109ce81e691af1a48c1d5dbaf2", "starcount": 0, "input": "@triton.jit\ndef _permute_tokens_kernel(out_ptr, in_ptr, mapping, hidden_size,\n BLOCK_SIZE: tl.constexpr):\n token_id = tl.program_id(axis=0)\n block_id = tl.program_id(axis=1)\n target_pos = tl.load(mapping + token_id)\n src_start = token_id * hidden_size + block_id * BLOCK_SIZE\n src_offsets = src_start + tl.arange(0, BLOCK_SIZE)\n src_data = tl.load(in_ptr + src_offsets)\n target_start = target_pos * hidden_size + block_id * BLOCK_SIZE\n target_offsets = target_start + tl.arange(0, BLOCK_SIZE)\n tl.store(out_ptr + target_offsets, src_data)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Transposed Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/USC-NSL/DisagMoE/blob/6e86ce027a9622109ce81e691af1a48c1d5dbaf2/disagmoe/ops/memory.py" }, { "uuid": "dec34255-4bf5-4a35-bd29-31122d76da6e", "file_name": "quantization.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/quantization.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _DequantUint8Window_impl(input_ptr, output_ptr, numel, window,\n BLOCK_SIZE: tl.constexpr):\n tid = tl.program_id(0)\n input_ptr += tid * BLOCK_SIZE\n output_ptr += tid * BLOCK_SIZE\n offset = tl.arange(0, BLOCK_SIZE)\n mask = offset < numel - tid * BLOCK_SIZE\n input = tl.load(input_ptr + offset, mask=mask).to(tl.float32)\n input = input * (2 * window / 255) - window\n tl.store(output_ptr + offset, input, mask=mask)\n", "category": { "Functionality": [ "Quantization" ], "Data Type": [ "uint8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/quantization.py" }, { "uuid": "6a43bf82-bfad-4982-8ad6-8c9316f953e6", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef cross_entropy_loss(input, pred):\n \"\"\"\n Measures the per-row cross entropy loss given\n input and predicted logits corresponding to target class.\n\n Args:\n input: Input.\n The input must be of shape [BLOCK_SIZE1, BLOCK_SIZE2].\n pred: Predicted logits corresponding to target class.\n The predictions must be of shape [BLOCK_SIZE1].\n\n Returns:\n Loss.\n \"\"\"\n input = input.to(tl.float32)\n pred = pred.to(tl.float32)\n mx = tl.max(input, axis=1)\n input -= mx[:, None]\n loss = tl.log(tl.sum(tl.exp(input), axis=1)) - pred + mx\n return loss\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "115476f9-cb8c-4ec2-895c-340862360239", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=MATMUL_CONFIGS, key=['m_key', 'n_key', 'k_key'],\n prune_configs_by={'early_config_prune': prune_configs_block,\n 'perf_model': estimate_matmul_time, 'top_k': 10})\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.jit\ndef _kernel_matmul_fp8_block_fastacc(A, B, C, M, N, K, m_key, n_key, k_key,\n A_scale, B_scale, scale_block_m: tl.constexpr, scale_block_n: tl.\n constexpr, scale_block_k: tl.constexpr, stride_am, stride_ak, stride_bn,\n stride_bk, stride_cm, stride_cn, stride_scale_am, stride_scale_ak,\n stride_scale_bn, stride_scale_bk, dot_out_dtype: tl.constexpr,\n allow_tf32: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr,\n BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, SPLIT_K: tl.constexpr,\n EVEN_K: tl.constexpr, AB_DTYPE: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with block-wise scales\n\n Performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles and\n A and B scaled by a scaling factor per [scale_block_m, scale_block_k] and\n [scale_block_n, scale_block_k] tiles\n respectively.\n\n Todo:\n * Support scale_block_{mnk} < BLOCK{MNK} for each dim.\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n m_key (int): Autotuning key for M dimension of input tensor.\n n_key (int): Autotuning key for N dimension of input tensor.\n k_key (int): Autotuning key for K dimension of input tensor.\n A_scale (TensorWrapper): [cdiv(M, scale_block_m), cdiv(K, scale_block_k)] reciprocal scale tensor per block. A * A_scale = original A\n B_scale (TensorWrapper): [cdiv(N, scale_block_n), cdiv(K, scale_block_k)] reciprocal scale tensor per block. B * B_scale = original B\n scale_block_m (int): Block size for M dimension of A_scale.\n scale_block_n (int): Block size for N dimension of B_scale.\n scale_block_k (int): Block size for K dimension of A_scale and B_scale.\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n stride_scale_am (int): Stride of M dimension of A_scale.\n stride_scale_ak (int): Stride of K dimension of A_scale.\n stride_scale_bn (int): Stride of N dimension of B_scale.\n stride_scale_bk (int): Stride of K dimension of B_scale.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n assert BLOCK_M < scale_block_m\n assert BLOCK_N < scale_block_n\n assert BLOCK_K < scale_block_k\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rk[:, None] * stride_bk + rbn[None, :] * stride_bn)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n _0 = tl.zeros((1, 1), dtype=C.dtype.element_ty)\n scale_m = pid_m * BLOCK_M // scale_block_m\n scale_n = pid_n * BLOCK_N // scale_block_n\n k_multiple = scale_block_k // BLOCK_K\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n if EVEN_K:\n a = tl.load(A)\n b = tl.load(B)\n else:\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_0)\n b = tl.load(B, mask=rk[:, None] < k_remaining, other=_0)\n if AB_DTYPE:\n a = a.to(C.dtype.element_ty)\n b = b.to(C.dtype.element_ty)\n acc = tl.dot(a, b, acc, out_dtype=dot_out_dtype, allow_tf32=allow_tf32)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n pid_k = k * SPLIT_K + pid_z\n if (pid_k + 1) % k_multiple == 0 or k_remaining < BLOCK_K * SPLIT_K:\n scale_k = pid_k // k_multiple\n scale_k_next = scale_k + 1\n a_scale = tl.load(A_scale + scale_m * stride_scale_am + scale_k *\n stride_scale_ak)\n b_scale = tl.load(B_scale + scale_n * stride_scale_bn + scale_k *\n stride_scale_bk)\n scale = a_scale * b_scale\n if k + 1 == tl.cdiv(K, BLOCK_K * SPLIT_K):\n scale_next_inv_scale = scale\n else:\n a_scale_next = tl.load(A_scale + scale_m * stride_scale_am +\n scale_k_next * stride_scale_ak)\n b_scale_next = tl.load(B_scale + scale_n * stride_scale_bn +\n scale_k_next * stride_scale_bk)\n scale_next = a_scale_next * b_scale_next\n scale_next_inv_scale = scale / scale_next\n acc *= scale_next_inv_scale\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n acc = acc.to(C.dtype.element_ty)\n c = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if SPLIT_K == 1:\n tl.store(c, acc, mask=mask)\n else:\n tl.atomic_add(c, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "5514dae5-9a0b-4b86-9296-8b765d29d9a5", "file_name": "math.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/math.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.jit\ndef update_welford(input, prev_count, prev_mean, prev_var, curr_count, mask:\n tl.constexpr):\n \"\"\"\n Updates count, mean, and variance (M2) statistics for Welford's algorithm.\n\n Args:\n input: Input used to update statistics.\n The input must be of the same shape as the mask.\n prev_count: Previous count statistic to update.\n prev_mean: Previous mean statistic to update.\n prev_var: Previous variance (M2) statistic to update.\n curr_count: Count of elements in current input.\n mask: Mask indicating which elements should be included in the calculations.\n The mask must be of the same shape as the input.\n\n Returns:\n Updated count, mean, and variance (M2) statistics\n \"\"\"\n input = input.to(tl.float32)\n count = prev_count + curr_count\n mean = (tl.sum(input) - curr_count * prev_mean) / count\n deltas = tl.where(mask, (input - mean) * (input - prev_mean), 0.0)\n var = prev_var + tl.sum(deltas)\n return count, mean, var\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/math.py" }, { "uuid": "094af577-4f53-4a31-868b-1e8681830008", "file_name": "outer_softmax.py", "repo_name": "iclementine/optimize_softmax", "file_path": "outer_softmax.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel(output_ptr, input_ptr, M, N, K, TILE_N: tl.constexpr,\n TILE_K: tl.constexpr):\n pid_k = tl.program_id(0)\n pid_m = tl.program_id(1)\n k_offsets = pid_k * TILE_K + tl.arange(0, TILE_K)\n n_offsets = tl.arange(0, TILE_N)\n offset = pid_m * N * K + n_offsets[:, None] * K + k_offsets\n mask = (n_offsets[:, None] < N) & (k_offsets < K)\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .type.element_ty)\n m = tl.max(inp, 0)\n e = tl.exp(inp - m[None, :])\n z = tl.sum(e, 0)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/outer_softmax.py" }, { "uuid": "0a7754cd-aa42-48c9-a0f9-486516dcd1a4", "file_name": "group_norm.py", "repo_name": "chengzeyi/stable-fast", "file_path": "src/sfast/triton/ops/group_norm.py", "commit_hash": "3a6f35c7045f8f6812515957ca62ef37260ff080", "starcount": 0, "input": "@eval(\n \"\"\"triton.heuristics({\n 'ROW_SIZE':\n lambda kwargs: triton.next_power_of_2(kwargs['C'] // kwargs['groups']),\n 'BLOCK_SIZE':\n lambda kwargs: max(\n 1, min(triton.next_power_of_2(kwargs['cluster_size']),\n 4096 // (triton.next_power_of_2(kwargs['C'] // kwargs['groups']))\n )),\n})\"\"\"\n )\n@eval(\n \"\"\"triton.heuristics({\n 'num_warps':\n lambda kwargs: max(1, min(16, kwargs['ROW_SIZE'] * kwargs['BLOCK_SIZE'] // 128)),\n 'C_G': lambda kwargs: kwargs['C'] // kwargs['groups'],\n})\"\"\"\n )\n@triton.jit\ndef group_norm_4d_channels_last_forward_collect_stats_kernel_stage_1(input_ptr,\n N, C, HxW, groups, cluster_size, cluster_num, cluster_mean_ptr,\n cluster_m2_ptr, cluster_weight_ptr, C_G, ROW_SIZE: tl.constexpr,\n BLOCK_SIZE: tl.constexpr):\n group = tl.program_id(0)\n cluster = tl.program_id(1)\n pid_batch = tl.program_id(2)\n offset = pid_batch * C * HxW + group * C_G\n X = input_ptr + offset\n _mean = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n _m2 = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n _weight = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n row = tl.arange(0, ROW_SIZE)\n start = cluster * cluster_size\n end = start + cluster_size\n end = min(end, HxW)\n for off in range(start, end, BLOCK_SIZE):\n r = off + tl.arange(0, BLOCK_SIZE)\n m2_ = tl.zeros((BLOCK_SIZE, ROW_SIZE), dtype=tl.float32)\n mask = (r < end)[:, None] & (row[None, :] < C_G)\n weight_ = mask.to(tl.float32)\n x = tl.load(X + (r * C)[:, None] + row[None, :], mask=mask).to(tl.\n float32)\n _mean, _m2, _weight = welford_combine(_mean, _m2, _weight, x, m2_,\n weight_)\n _mean = tl.view(_mean, (BLOCK_SIZE * ROW_SIZE,))\n _m2 = tl.view(_m2, (BLOCK_SIZE * ROW_SIZE,))\n _weight = tl.view(_weight, (BLOCK_SIZE * ROW_SIZE,))\n mean, m2, weight = tl.reduce((_mean, _m2, _weight), 0, welford_combine)\n offset = pid_batch * groups * cluster_num + group * cluster_num + cluster\n tl.store(cluster_mean_ptr + offset, mean)\n tl.store(cluster_m2_ptr + offset, m2)\n tl.store(cluster_weight_ptr + offset, weight)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/chengzeyi/stable-fast/blob/3a6f35c7045f8f6812515957ca62ef37260ff080/src/sfast/triton/ops/group_norm.py" }, { "uuid": "fd13e143-89d0-45f8-b215-8f6705c789eb", "file_name": "blocksparse_matmul.py", "repo_name": "kimiasa/Experiments", "file_path": "src/models/attention/blocksparse_matmul.py", "commit_hash": "c4e73bfefd8290695ec52b6386b6b81838ca94a1", "starcount": 0, "input": "@triton.jit\ndef _kernel(A, B, C, stride_za, stride_ha, stride_ma, stride_ka, stride_zb,\n stride_hb, stride_kb, stride_nb, stride_zc, stride_hc, stride_mc,\n stride_nc, DS0, DS1, SDD_K, SDD_off_width, lut, locks, nlocks, **meta):\n TM = meta['TM']\n TN = meta['TN']\n TK = meta['TK']\n TZ = meta['TZ']\n BLOCK = meta['BLOCK']\n pid0 = tl.program_id(0)\n pid1 = tl.program_id(1)\n pidz = tl.program_id(2)\n if meta['SDD']:\n pid1 = pid1 + SDD_off_width\n blockidm = tl.arange(0, TM) // BLOCK\n blockidn = tl.arange(0, TN) // BLOCK\n offlutm = blockidm * (TN // BLOCK) * 4\n offlutn = blockidn * 4\n header = lut + pid1 * (TM // BLOCK) * (TN // BLOCK) * 4\n z = tl.load(header + 0)\n i = tl.load(header + 1 + offlutm)\n j = tl.load(header + 2 + offlutn)\n AS1 = SDD_K // TZ\n lockid = tl.where(TZ > 1, 1, 0)\n offka = pid0 * AS1\n offkb = pid0 * AS1\n offmc = 0\n offnc = 0\n offpa = 0\n offpb = 0\n maxid = TZ\n offhc = 0\n offha = z\n offhb = z\n ram = i * BLOCK + tl.arange(0, TM) % BLOCK\n rbn = j * BLOCK + tl.arange(0, TN) % BLOCK\n else:\n header = lut + pid0 * 6\n offset = tl.load(header + 0)\n AS1 = tl.load(header + 1)\n column = tl.load(header + 2)\n depth = tl.load(header + 3)\n lockid = tl.load(header + 4)\n maxid = tl.load(header + 5)\n pinc = lut + offset\n offhc = depth\n if meta['DSD']:\n offnc = pid1 * TN\n offmc = column * TM\n offpc = 0\n offnb = pid1 * TN\n offkb = tl.load(pinc)\n offkb = tl.multiple_of(offkb, 8)\n offpb = 0\n offma = 0\n offka = 0\n offpa = tl.load(pinc + 1)\n offpa = tl.multiple_of(offpa, 8)\n offpa = offpa * BLOCK * BLOCK\n offha = 0\n offhb = depth\n else:\n offmc = pid1 * TM\n offnc = column * TN\n offpc = 0\n offma = pid1 * TM\n offka = tl.load(pinc)\n offka = tl.multiple_of(offka, 8)\n offpa = 0\n offnb = 0\n offkb = 0\n offpb = tl.load(pinc + 1)\n offpb = tl.multiple_of(offpb, 8)\n offpb = offpb * BLOCK * BLOCK\n offha = depth\n offhb = 0\n ram = offma + tl.arange(0, TM)\n rbn = offnb + tl.arange(0, TN)\n rka = offka + tl.arange(0, TK)\n rkb = offkb + tl.arange(0, TK)\n pa = A + pidz * stride_za + offha * stride_ha + offpa + ram[:, None\n ] * stride_ma + rka[None, :] * stride_ka\n pb = B + pidz * stride_zb + offhb * stride_hb + offpb + rbn[None, :\n ] * stride_nb + rkb[:, None] * stride_kb\n if meta['DDS']:\n checkam = ram[:, None] < DS0\n else:\n checkam = AS1 > 0\n if meta['DSD']:\n checkbn = rbn[None, :] < DS0\n else:\n checkbn = AS1 > 0\n a = tl.load(pa, mask=checkam, other=0.0)\n b = tl.load(pb, mask=checkbn, other=0.0)\n acc = tl.zeros((TM, TN), dtype=tl.float32)\n for k in range(AS1, 0, -TK):\n acc += tl.dot(a, b)\n if meta['SDD']:\n inc_a = TK * stride_ka\n inc_b = TK * stride_kb\n else:\n pinc += 2\n if meta['DSD']:\n inc_b = tl.load(pinc)\n inc_a = tl.load(pinc + 1)\n inc_b = tl.multiple_of(inc_b, 8)\n inc_a = tl.multiple_of(inc_a, 8)\n inc_b = inc_b * stride_kb\n if meta['DDS']:\n inc_a = tl.load(pinc)\n inc_b = tl.load(pinc + 1)\n inc_a = tl.multiple_of(inc_a, 8)\n inc_b = tl.multiple_of(inc_b, 8)\n inc_a = inc_a * stride_ka\n pa += inc_a\n pb += inc_b\n checkak = k > TK\n checkbk = k > TK\n checka = checkam & checkak\n checkb = checkbn & checkbk\n a = tl.load(pa, mask=checka)\n b = tl.load(pb, mask=checkb)\n c = acc.to(C.dtype.element_ty)\n if meta['SDD']:\n checkc = True\n rr_blockidm = tl.arange(0, TM) // BLOCK\n rr_blockidn = tl.arange(0, TN) // BLOCK\n rr_offlutm = rr_blockidm * (TN // BLOCK) * 4\n rr_offlutn = rr_blockidn * 4\n off_bkid = 3 + rr_offlutm[:, None] + rr_offlutn[None, :]\n bkid = tl.load(header + off_bkid)\n offpc = bkid * BLOCK * BLOCK\n rcm = tl.arange(0, TM) % BLOCK\n rcn = tl.arange(0, TN) % BLOCK\n else:\n rcm = offmc + tl.arange(0, TM)\n rcn = offnc + tl.arange(0, TN)\n if meta['DSD']:\n checkc = rcn[None, :] < DS0\n if meta['DDS']:\n checkc = rcm[:, None] < DS0\n pc = C + offpc + offhc * stride_hc + pidz * stride_zc + rcm[:, None\n ] * stride_mc + rcn[None, :] * stride_nc\n if lockid == 0:\n tl.store(pc, c, mask=checkc)\n else:\n plock = locks + tl.program_id(2) * nlocks * tl.num_programs(1\n ) + tl.program_id(1) * nlocks + lockid - 1\n pcount = plock + tl.num_programs(2) * tl.num_programs(1) * nlocks\n while tl.atomic_cas(plock, 0, 1) == 1:\n pass\n count = tl.load(pcount)\n if count == 0:\n tl.store(pc, c, mask=checkc)\n else:\n d = tl.load(pc, mask=checkc)\n tl.store(pc, d + c, mask=checkc)\n tl.atomic_xchg(pcount, (count + 1) % maxid)\n tl.atomic_xchg(plock, 0)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced", "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/kimiasa/Experiments/blob/c4e73bfefd8290695ec52b6386b6b81838ca94a1/src/models/attention/blocksparse_matmul.py" }, { "uuid": "9822ff51-7759-462c-94c3-f99295b342b9", "file_name": "seqlen_utils.py", "repo_name": "Kitsunetic/kitsu", "file_path": "kitsu/nn/seqlen_utils.py", "commit_hash": "826967a493c89753ac2cf1e28b52b79998fc9076", "starcount": 0, "input": "@triton.jit\ndef padding_index_kernel(seqlen_ptr, new_seqlen_ptr, new_max_seqlen,\n idx_ptr, window_size, BLK_N: tl.constexpr):\n pid_b = tl.program_id(0)\n i1 = tl.load(seqlen_ptr + pid_b).to(tl.int32)\n j1 = tl.load(seqlen_ptr + pid_b + 1).to(tl.int32)\n i2 = tl.load(new_seqlen_ptr + pid_b).to(tl.int32)\n j2 = tl.load(new_seqlen_ptr + pid_b + 1).to(tl.int32)\n for pid_n in range(tl.cdiv(new_max_seqlen, BLK_N)):\n offs_idx = pid_n * BLK_N + tl.arange(0, BLK_N)\n mask_idx = offs_idx < j2 - i2\n idx_ptrs = idx_ptr + i2 + offs_idx\n idx = i1 + offs_idx.to(tl.int32)\n tmp = clamp(idx - window_size, i1, j1 - 1)\n idx_out = tl.where(idx < j1, idx, tmp)\n tl.store(idx_ptrs, idx_out, mask=mask_idx)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/kitsu/blob/826967a493c89753ac2cf1e28b52b79998fc9076/kitsu/nn/seqlen_utils.py" }, { "uuid": "176b1708-5add-44dc-a5d9-163681f5d85f", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _multi_head_jagged_flash_attention_bwd_preprocess_kernel(o_ptr,\n o_offset_ptr, do_ptr, delta_ptr, stride_oh, stride_om, stride_od,\n stride_delta_h, num_heads: tl.constexpr, max_seq_len: tl.constexpr, D:\n tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_D: tl.constexpr):\n pid_m = tl.program_id(axis=0)\n pid_bh = tl.program_id(axis=1)\n pid_batch = pid_bh // num_heads\n pid_head = pid_bh % num_heads\n begin_o = tl.load(o_offset_ptr + pid_batch)\n end_o = tl.load(o_offset_ptr + pid_batch + 1)\n M = end_o - begin_o\n M = tl.minimum(M, max_seq_len)\n if M == 0:\n return\n offs_om = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_od = tl.arange(0, BLOCK_D)\n o_offsets = offs_om[:, None] * stride_om + offs_od[None, :\n ] * stride_od + pid_head * stride_oh + begin_o * stride_om\n o_ptrs = o_ptr + o_offsets\n do_ptrs = do_ptr + o_offsets\n o_mask = (offs_om[:, None] < M) & (offs_od[None, :] < D)\n o = tl.load(o_ptrs, mask=o_mask)\n do = tl.load(do_ptrs, mask=o_mask)\n delta = tl.sum(o * do, axis=1)\n tl.store(delta_ptr + pid_head * stride_delta_h + begin_o + offs_om,\n delta, mask=offs_om < M)\n", "category": { "Functionality": [ "Attention Mechanisms", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "8f0a1ee8-5be7-4e8c-824f-b08939f27687", "file_name": "y_8.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_8.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef eighth_order_bwd(coord_ptr: tl.tensor, coord_grad_ptr: tl.tensor,\n sph_grad_ptr: tl.tensor, block_size: tl.constexpr, coord_numel: tl.\n constexpr, output_numel: tl.constexpr, col_offset: tl.constexpr,\n output_stride: tl.constexpr):\n block_id = tl.program_id(0)\n coord_stride = 3\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n g_0 = tl.load(sph_grad_ptr + output_row_offset, mask=output_row_offset <\n output_numel)\n g_1 = tl.load(sph_grad_ptr + output_row_offset + 1, mask=\n output_row_offset + 1 < output_numel)\n g_2 = tl.load(sph_grad_ptr + output_row_offset + 2, mask=\n output_row_offset + 2 < output_numel)\n g_3 = tl.load(sph_grad_ptr + output_row_offset + 3, mask=\n output_row_offset + 3 < output_numel)\n g_4 = tl.load(sph_grad_ptr + output_row_offset + 4, mask=\n output_row_offset + 4 < output_numel)\n g_5 = tl.load(sph_grad_ptr + output_row_offset + 5, mask=\n output_row_offset + 5 < output_numel)\n g_6 = tl.load(sph_grad_ptr + output_row_offset + 6, mask=\n output_row_offset + 6 < output_numel)\n g_7 = tl.load(sph_grad_ptr + output_row_offset + 7, mask=\n output_row_offset + 7 < output_numel)\n g_8 = tl.load(sph_grad_ptr + output_row_offset + 8, mask=\n output_row_offset + 8 < output_numel)\n g_9 = tl.load(sph_grad_ptr + output_row_offset + 9, mask=\n output_row_offset + 9 < output_numel)\n g_10 = tl.load(sph_grad_ptr + output_row_offset + 10, mask=\n output_row_offset + 10 < output_numel)\n g_11 = tl.load(sph_grad_ptr + output_row_offset + 11, mask=\n output_row_offset + 11 < output_numel)\n g_12 = tl.load(sph_grad_ptr + output_row_offset + 12, mask=\n output_row_offset + 12 < output_numel)\n g_13 = tl.load(sph_grad_ptr + output_row_offset + 13, mask=\n output_row_offset + 13 < output_numel)\n g_14 = tl.load(sph_grad_ptr + output_row_offset + 14, mask=\n output_row_offset + 14 < output_numel)\n g_15 = tl.load(sph_grad_ptr + output_row_offset + 15, mask=\n output_row_offset + 15 < output_numel)\n g_16 = tl.load(sph_grad_ptr + output_row_offset + 16, mask=\n output_row_offset + 16 < output_numel)\n CONST000 = 2.0\n CONST001 = 3.0\n CONST002 = 4.50964677801932\n CONST004 = 5.0\n CONST005 = 6.78376969317208\n CONST006 = 4.0\n CONST007 = 9.01929355603863\n CONST008 = 6.76447016702898\n CONST009 = 6.0\n CONST011 = 13.5675393863442\n CONST012 = 15.0965641786467\n CONST013 = 13.136713523081\n CONST015 = 13.136713523081\n CONST017 = 19.4042118494929\n CONST019 = -489.184589393411\n CONST020 = 24.738633753706\n CONST023 = 26.2734270461621\n CONST024 = 27.0578806681159\n CONST025 = 24.738633753706\n CONST026 = 32.9848450049413\n CONST027 = 33.9188484658604\n CONST028 = 550.332663067587\n CONST030 = -978.369178786822\n CONST031 = 48.5105296237322\n CONST033 = 51.744564931981\n CONST035 = 48.9184589393411\n CONST041 = 65.6835676154051\n CONST043 = -1467.55376818023\n CONST045 = -12.2296147348353\n CONST047 = 582.126355484786\n CONST048 = -437.890450769368\n CONST049 = -434.108258927137\n CONST050 = -434.108258927137\n CONST052 = -432.926090689854\n CONST054 = -1447.02752975712\n CONST055 = 91.9569946615672\n CONST056 = -420.374832738593\n CONST057 = 6.46807061649763\n CONST058 = 97.0210592474644\n CONST061 = 103.489129863962\n CONST062 = -407.026181590325\n CONST063 = 108.231522672464\n CONST065 = 110.066532613517\n CONST066 = 110.066532613517\n CONST067 = 620.934779183772\n CONST068 = -396.284809689477\n CONST070 = 132.094936563159\n CONST071 = 434.108258927137\n CONST073 = 649.389136034781\n CONST076 = -366.888442045058\n CONST077 = -366.888442045058\n CONST078 = -361.756882439281\n CONST080 = -6.78376969317208\n CONST082 = -350.312360615494\n CONST083 = -346.340872551883\n CONST084 = -346.340872551883\n CONST085 = 173.170436275942\n CONST086 = 173.170436275942\n CONST088 = 183.444221022529\n CONST089 = 183.444221022529\n CONST090 = -325.62094527226\n CONST091 = -13.5289403340579\n CONST092 = -13.5675393863442\n CONST093 = 194.042118494929\n CONST095 = 197.050702846215\n CONST096 = -11.3224231339851\n CONST097 = 203.513090795162\n CONST098 = -814.05236318065\n CONST102 = -814.05236318065\n CONST104 = 217.054129463568\n CONST105 = 216.463045344927\n CONST106 = 220.133065227035\n CONST107 = -291.063177742393\n CONST108 = 220.133065227035\n CONST109 = -792.569619378954\n CONST111 = -271.350787726883\n CONST112 = 244.592294696705\n CONST113 = 244.592294696706\n CONST114 = 244.592294696706\n CONST115 = -776.168473979715\n CONST116 = -262.734270461621\n CONST117 = -259.755654413913\n CONST118 = -258.722824659905\n CONST120 = 262.734270461621\n CONST121 = -244.215708954195\n CONST122 = 271.350787726883\n CONST124 = -236.460843415458\n CONST127 = -217.054129463568\n CONST128 = -216.463045344927\n CONST129 = -216.463045344927\n CONST130 = -216.463045344927\n CONST131 = -723.513764878561\n CONST133 = -210.187416369296\n CONST134 = -210.187416369296\n CONST135 = 814.05236318065\n CONST136 = -197.050702846215\n CONST137 = 317.027847751582\n CONST138 = -194.042118494929\n CONST139 = -13.136713523081\n CONST140 = 324.694568017391\n CONST142 = 324.694568017391\n CONST143 = -175.156180307747\n CONST146 = -162.81047263613\n CONST147 = -162.347284008695\n CONST148 = 865.852181379709\n CONST149 = -158.513923875791\n CONST151 = -144.702752975712\n CONST152 = -649.389136034782\n CONST153 = -129.877827206956\n CONST154 = -129.361412329953\n CONST155 = 388.084236989858\n CONST157 = -115.446957517294\n CONST158 = -108.231522672464\n CONST159 = -108.231522672464\n CONST160 = 407.026181590325\n CONST161 = -103.489129863962\n CONST162 = -97.0210592474644\n CONST163 = -94.7025823384056\n CONST165 = -91.9569946615672\n CONST167 = -87.5780901538735\n CONST168 = -85.6073031438469\n CONST169 = -85.6073031438469\n CONST170 = -81.1736420043477\n CONST171 = 432.926090689854\n CONST172 = -79.2569619378954\n CONST173 = -81.1736420043477\n CONST177 = -79.2569619378954\n CONST178 = -72.3513764878561\n CONST179 = -72.1543484483091\n CONST180 = -70.0624721230988\n CONST181 = -72.1543484483091\n CONST182 = -67.8376969317208\n CONST183 = -65.6835676154052\n CONST184 = -61.1480736741764\n CONST185 = -1085.27064731784\n CONST186 = -61.1480736741764\n CONST187 = -1085.40315090753\n CONST188 = -57.7234787586472\n CONST189 = -12.9361412329953\n CONST190 = -1085.27064731784\n CONST191 = -52.8379746252636\n CONST192 = -51.744564931981\n CONST193 = -1585.13923875791\n CONST194 = -48.5105296237322\n CONST195 = -47.4863878522046\n CONST197 = 978.369178786822\n CONST198 = -517.44564931981\n CONST199 = -40.7026181590325\n CONST200 = -40.5868210021738\n CONST201 = -39.4101405692431\n CONST202 = -40.7026181590325\n CONST203 = -36.0771742241545\n CONST204 = -1056.75949250527\n CONST205 = -29.1063177742393\n CONST206 = 485.105296237322\n CONST207 = -26.2734270461621\n CONST208 = -26.4189873126318\n CONST209 = -1050.93708184648\n CONST210 = -22.6382471577417\n CONST211 = -20.6718218536732\n CONST212 = -19.4042118494929\n CONST213 = -20.3513090795162\n CONST214 = -528.379746252636\n CONST215 = -15.0965641786467\n CONST216 = -13.5675393863442\n CONST217 = -525.468540923241\n CONST218 = -11.3224231339851\n CONST219 = -13.5289403340579\n CONST220 = -9.70210592474644\n CONST221 = -10.3359109268366\n CONST222 = -6.46807061649763\n CONST223 = -13.136713523081\n CONST224 = -12.2296147348353\n CONST225 = -3.23403530824881\n CONST226 = -1034.89129863962\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR03 = VAR06 * VAR07\n VAR04 = VAR07 * VAR07\n VAR05 = VAR07 * VAR08\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR12 = VAR15 * VAR16\n VAR13 = VAR16 * VAR16\n VAR14 = VAR16 * VAR17\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n VAR21 = VAR24 * VAR25\n VAR22 = VAR25 * VAR25\n VAR23 = VAR25 * VAR26\n g_x = tl.load(coord_grad_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n g_y = tl.load(coord_grad_ptr + coord_row_offset + 1, mask=\n coord_row_offset + 1 < coord_numel)\n g_z = tl.load(coord_grad_ptr + coord_row_offset + 2, mask=\n coord_row_offset + 2 < coord_numel)\n g_x += g_0 * (CONST049 * VAR08 * VAR23 - CONST131 * VAR06 * VAR25 + \n CONST151 * VAR04 * z - CONST211 * VAR21) + g_1 * y * (CONST178 *\n VAR04 - CONST178 * VAR22 + CONST185 * VAR08 * VAR24 - CONST190 *\n VAR06 * VAR26) + g_10 * (CONST017 * VAR05 * VAR26 + CONST161 *\n VAR13 * x - CONST189 * VAR03 - CONST198 * VAR07 * VAR15 + CONST222 *\n VAR22 * x + VAR17 * (CONST058 * VAR24 * x + CONST107 * VAR05 + \n CONST138 * VAR07 * VAR26)) + g_11 * (CONST056 * VAR14 * x * z + \n VAR16 * (-CONST082 * VAR25 * x - CONST209 * VAR07 * z) + y * (\n CONST116 * VAR07 * VAR25 + CONST124 * VAR05 * z + CONST207 * VAR23 * x)\n ) + g_12 * (CONST011 * VAR03 + CONST182 * VAR07 * VAR24 + CONST199 *\n VAR05 * VAR26 + CONST216 * VAR22 * x + VAR15 * (CONST098 * VAR26 *\n x + CONST122 * VAR07) + VAR17 * (-CONST102 * VAR07 * VAR26 + \n CONST121 * VAR05 + CONST160 * VAR24 * x)) + g_13 * (VAR16 * (-\n CONST030 * VAR07 * z + CONST030 * VAR25 * x) + y * (CONST076 *\n VAR05 * z + CONST106 * VAR23 * x + CONST112 * VAR07 * VAR25)\n ) + g_14 * (CONST012 * VAR03 + CONST149 * VAR05 * VAR26 - CONST191 *\n VAR22 * x + VAR17 * (CONST109 * VAR24 * x + CONST149 * VAR05 - \n CONST193 * VAR07 * VAR26)) + g_15 * y * (CONST050 * VAR05 * z + \n CONST050 * VAR23 * x - CONST054 * VAR07 * VAR25) + g_16 * (CONST050 *\n VAR05 * VAR26 - CONST131 * VAR07 * VAR24 + CONST151 * VAR22 * x - \n CONST211 * VAR03) + g_2 * (CONST001 * VAR08 * (-CONST208 * VAR23 + \n CONST214 * VAR17 * VAR25) + CONST004 * VAR06 * (-CONST149 * VAR17 *\n z - CONST208 * VAR25) - CONST149 * VAR17 * VAR23 + CONST172 * VAR04 *\n z + CONST218 * VAR21) + g_3 * (VAR16 * (CONST043 * VAR08 * VAR26 + \n CONST113 * VAR06 + CONST114 * VAR24) + y * (CONST028 * VAR06 *\n VAR26 + CONST088 * VAR08 * VAR24 + CONST168 * VAR04 + CONST184 * VAR22)\n ) + g_4 * (CONST001 * VAR08 * (CONST005 * VAR23 + CONST111 * VAR15 *\n z) + CONST004 * VAR06 * (CONST080 * VAR25 - CONST146 * VAR17 * z) +\n CONST005 * VAR21 - CONST111 * VAR15 * VAR25 + CONST146 * VAR17 *\n VAR23 + CONST195 * VAR04 * z) + g_5 * (VAR14 * (CONST133 * VAR08 - \n CONST134 * VAR26) + VAR16 * (-CONST048 * VAR06 + CONST116 * VAR24 +\n CONST217 * VAR08 * VAR26) + y * (CONST041 * VAR06 * VAR26 + \n CONST095 * VAR08 * VAR24 + CONST165 * VAR04 - CONST201 * VAR22)\n ) + g_6 * (CONST001 * VAR08 * (CONST093 * VAR17 * VAR25 + CONST118 *\n VAR15 * z + CONST220 * VAR23) + CONST004 * VAR06 * (-CONST162 *\n VAR17 * z + CONST220 * VAR25) + CONST118 * VAR15 * VAR25 - CONST161 *\n VAR13 * z - CONST162 * VAR17 * VAR23 + CONST210 * VAR04 * z + \n CONST225 * VAR21) + g_7 * (CONST001 * VAR08 * (-CONST128 * VAR16 *\n VAR26 + CONST153 * VAR14 + CONST200 * VAR24 * y) + CONST004 * VAR06 *\n (CONST063 * VAR16 + CONST200 * VAR26 * y) + CONST020 * VAR12 + \n CONST153 * VAR14 * VAR26 - CONST158 * VAR16 * VAR24 + CONST163 *\n VAR04 * y + CONST219 * VAR22 * y) + g_8 * (CONST000 * x * (CONST002 *\n VAR22 - CONST128 * VAR15 * VAR26 + CONST158 * VAR17 * VAR24 + \n CONST188 * VAR13) + CONST006 * VAR07 * (CONST008 * VAR24 - CONST158 *\n VAR15 + CONST159 * VAR17 * VAR26) + CONST007 * VAR03 + CONST009 *\n VAR05 * (CONST002 * VAR26 + CONST203 * VAR17)) + g_9 * (CONST173 *\n VAR23 * x * y + VAR25 * (CONST147 * VAR07 * y + CONST171 * VAR16 *\n x) + z * (CONST117 * VAR14 * x + CONST170 * VAR05 * y + CONST171 *\n VAR07 * VAR16))\n g_y += CONST000 * g_14 * y * (-CONST068 * VAR06 * VAR26 + CONST068 *\n VAR08 * VAR24 + CONST208 * VAR04 - CONST208 * VAR22) + g_1 * (\n CONST078 * VAR07 * VAR24 + CONST104 * VAR05 * VAR26 - CONST178 *\n VAR22 * x + CONST221 * VAR03) + g_10 * (CONST000 * y * (CONST031 *\n VAR08 * VAR24 + CONST031 * VAR22 + CONST194 * VAR04 + CONST194 *\n VAR06 * VAR26) + CONST006 * VAR16 * (-CONST154 * VAR06 + CONST154 *\n VAR24) + CONST009 * VAR14 * (CONST033 * VAR26 + CONST192 * VAR08)\n ) + g_11 * (CONST001 * VAR17 * (-CONST116 * VAR06 * z - CONST143 *\n VAR08 * VAR25 + CONST167 * VAR23) + CONST004 * VAR15 * (CONST134 *\n VAR08 * z - CONST180 * VAR25) + CONST013 * VAR21 + CONST183 * VAR06 *\n VAR25 + CONST201 * VAR04 * z + CONST223 * VAR08 * VAR23) + g_12 * (\n CONST000 * y * (CONST097 * VAR06 * VAR26 + CONST097 * VAR08 * VAR24 +\n CONST199 * VAR04 + CONST199 * VAR22) + CONST006 * VAR16 * (CONST062 *\n VAR08 * VAR26 - CONST182 * VAR06 - CONST182 * VAR24)) + g_13 * (\n CONST001 * VAR17 * (CONST019 * VAR08 * VAR25 + CONST035 * VAR23 + \n CONST113 * VAR06 * z) + CONST065 * VAR08 * VAR23 - CONST184 * VAR06 *\n VAR25 + CONST186 * VAR04 * z + CONST224 * VAR21) + g_15 * (-\n CONST078 * VAR06 * VAR25 + CONST127 * VAR08 * VAR23 + CONST178 *\n VAR04 * z - CONST221 * VAR21) + g_2 * (CONST137 * VAR05 * y * z + \n CONST137 * VAR23 * x * y + CONST204 * VAR07 * VAR25 * y) + g_3 * (\n CONST001 * VAR17 * (CONST019 * VAR07 * VAR26 + CONST035 * VAR05 + \n CONST114 * VAR24 * x) + CONST045 * VAR03 + CONST066 * VAR05 * VAR26 +\n CONST184 * VAR22 * x - CONST186 * VAR07 * VAR24) + g_4 * (-CONST090 *\n VAR05 * y * z + CONST187 * VAR07 * VAR16 * z + x * (CONST090 *\n VAR23 * y - CONST187 * VAR16 * VAR25)) + g_5 * (CONST001 * VAR17 *\n (CONST116 * VAR24 * x + CONST143 * VAR07 * VAR26 - CONST167 * VAR05\n ) + CONST004 * VAR15 * (-CONST134 * VAR26 * x + CONST180 * VAR07) +\n CONST015 * VAR05 * VAR26 + CONST041 * VAR07 * VAR24 + CONST139 *\n VAR03 - CONST201 * VAR22 * x) + g_6 * (-CONST138 * VAR05 * y * z + \n VAR07 * (CONST155 * VAR25 * y + CONST226 * VAR16 * z) + x * (\n CONST067 * VAR14 * z - CONST138 * VAR23 * y + CONST226 * VAR16 * VAR25)\n ) + g_7 * (CONST219 * VAR03 + VAR05 * (CONST142 * VAR17 + CONST200 *\n VAR26) + VAR07 * (CONST152 * VAR15 - CONST152 * VAR17 * VAR26 + \n CONST200 * VAR24) + x * (CONST085 * VAR13 + CONST140 * VAR17 *\n VAR24 + CONST152 * VAR15 * VAR26 + CONST219 * VAR22)) + g_8 * (\n CONST026 * VAR12 - CONST052 * VAR16 * VAR24 + CONST084 * VAR14 *\n VAR26 + CONST179 * VAR04 * y + CONST181 * VAR22 * y + VAR06 * (-\n CONST052 * VAR16 + CONST129 * VAR26 * y) + VAR08 * (CONST083 *\n VAR14 + CONST128 * VAR24 * y + CONST148 * VAR16 * VAR26)) + g_9 * (\n CONST219 * VAR21 + VAR23 * (CONST142 * VAR17 + CONST200 * VAR08) + \n VAR25 * (CONST073 * VAR08 * VAR17 + CONST152 * VAR15 + CONST200 *\n VAR06) + z * (CONST086 * VAR13 + CONST091 * VAR04 + CONST142 *\n VAR06 * VAR17 + CONST152 * VAR08 * VAR15))\n g_z += g_0 * (-CONST049 * VAR05 * VAR26 + CONST131 * VAR07 * VAR24 - \n CONST151 * VAR22 * x + CONST211 * VAR03) + g_1 * y * (-CONST050 *\n VAR23 * x + CONST054 * VAR07 * VAR25 + CONST071 * VAR05 * z) + g_10 * (\n CONST057 * VAR04 * z + CONST061 * VAR13 * z + CONST189 * VAR21 + \n CONST198 * VAR15 * VAR25 + CONST212 * VAR08 * VAR23 + VAR17 * (\n CONST093 * VAR08 * VAR25 - CONST107 * VAR23 + CONST162 * VAR06 * z)\n ) + g_11 * (VAR14 * (-CONST133 * VAR26 + CONST134 * VAR08) + VAR16 *\n (CONST048 * VAR24 - CONST116 * VAR06 - CONST217 * VAR08 * VAR26) + \n y * (CONST055 * VAR22 + CONST136 * VAR06 * VAR26 + CONST183 * VAR08 *\n VAR24 + CONST201 * VAR04)) + g_12 * (CONST011 * VAR21 + CONST092 *\n VAR04 * z + CONST182 * VAR06 * VAR25 + CONST202 * VAR08 * VAR23 + \n VAR15 * (CONST098 * VAR08 * z + CONST122 * VAR25) + VAR17 * (-\n CONST102 * VAR08 * VAR25 + CONST121 * VAR23 + CONST160 * VAR06 * z)\n ) + g_13 * (VAR16 * (CONST043 * VAR08 * VAR26 + CONST113 * VAR06 + \n CONST113 * VAR24) + y * (CONST028 * VAR08 * VAR24 + CONST089 *\n VAR06 * VAR26 + CONST169 * VAR22 + CONST186 * VAR04)) + g_14 * (-\n CONST149 * VAR08 * VAR23 + CONST191 * VAR04 * z + CONST215 * VAR21 +\n VAR17 * (-CONST109 * VAR06 * z - CONST149 * VAR23 + CONST193 *\n VAR08 * VAR25)) + g_15 * y * (CONST178 * VAR04 - CONST178 * VAR22 -\n CONST185 * VAR06 * VAR26 + CONST190 * VAR08 * VAR24) + g_16 * (\n CONST050 * VAR08 * VAR23 - CONST131 * VAR06 * VAR25 + CONST151 *\n VAR04 * z - CONST211 * VAR21) + g_2 * (CONST096 * VAR03 + VAR05 * (\n -CONST149 * VAR17 - CONST177 * VAR26) + VAR07 * (CONST070 * VAR24 +\n CONST193 * VAR17 * VAR26) + x * (-CONST109 * VAR17 * VAR24 + \n CONST177 * VAR22)) + g_3 * (VAR16 * (CONST030 * VAR07 * z + \n CONST197 * VAR25 * x) + y * (CONST077 * VAR23 * x + CONST108 *\n VAR05 * z + CONST114 * VAR07 * VAR25)) + g_4 * (CONST080 * VAR03 + \n VAR05 * (-CONST146 * VAR17 + CONST213 * VAR26) + VAR07 * (CONST027 *\n VAR24 + CONST111 * VAR15) + x * (CONST102 * VAR17 * VAR24 + \n CONST135 * VAR15 * VAR26 - CONST195 * VAR22)) + g_5 * (-CONST056 *\n VAR14 * x * z + VAR16 * (CONST082 * VAR07 * z + CONST209 * VAR25 *\n x) + y * (CONST023 * VAR05 * z + CONST120 * VAR07 * VAR25 - \n CONST124 * VAR23 * x)) + g_6 * (CONST225 * VAR03 + VAR05 * (-\n CONST162 * VAR17 + CONST205 * VAR26) + VAR07 * (CONST047 * VAR17 *\n VAR26 + CONST118 * VAR15 + CONST194 * VAR24) + x * (CONST115 *\n VAR15 * VAR26 - CONST161 * VAR13 + CONST206 * VAR17 * VAR24 + \n CONST210 * VAR22)) + g_7 * (CONST173 * VAR05 * y * z + VAR07 * (-\n CONST052 * VAR16 * z + CONST147 * VAR25 * y) + x * (-CONST052 *\n VAR16 * VAR25 + CONST117 * VAR14 * z + CONST173 * VAR23 * y)) + g_8 * (\n CONST007 * VAR04 * z + CONST007 * VAR21 - CONST052 * VAR15 * VAR25 +\n CONST130 * VAR17 * VAR23 + CONST157 * VAR13 * z + VAR06 * (CONST024 *\n VAR25 + CONST129 * VAR17 * z) + VAR08 * (CONST024 * VAR23 - \n CONST052 * VAR15 * z + CONST052 * VAR17 * VAR25)) + g_9 * (CONST001 *\n VAR26 * (CONST105 * VAR08 * VAR16 + CONST153 * VAR14 + CONST200 *\n VAR06 * y) + CONST004 * VAR24 * (CONST063 * VAR16 + CONST200 *\n VAR08 * y) + CONST025 * VAR12 + CONST063 * VAR06 * VAR16 + CONST091 *\n VAR04 * y + CONST153 * VAR08 * VAR14 + CONST163 * VAR22 * y)\n tl.store(coord_grad_ptr + coord_row_offset, g_x, mask=coord_row_offset <\n coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 1, g_y, mask=\n coord_row_offset + 1 < coord_numel)\n tl.store(coord_grad_ptr + coord_row_offset + 2, g_z, mask=\n coord_row_offset + 2 < coord_numel)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_8.py" }, { "uuid": "e6ddf2c9-7f59-4c42-b78f-bc7715065c3e", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BT': BT}, num_warps=num_warps) for\n BT in [16, 32, 64] for num_warps in [2, 4, 8]], key=['S'])\n@triton.jit\ndef chunk_global_reversed_cumsum_vector_kernel(s, z, offsets, T: tl.\n constexpr, H: tl.constexpr, S: tl.constexpr, BT: tl.constexpr, BS: tl.\n constexpr, HEAD_FIRST: tl.constexpr, USE_OFFSETS: tl.constexpr):\n i_s, i_bh = tl.program_id(0), tl.program_id(1)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_b).to(tl.int32), tl.load(offsets +\n i_b + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n o_i = tl.arange(0, BT)\n m_s = tl.where(o_i[:, None] <= o_i[None, :], 1.0, 0.0)\n b_z = tl.zeros([BS], dtype=tl.float32)\n for i_t in range(tl.cdiv(T, BT) - 1, -1, -1):\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T * S, (T, S), (S, 1), (i_t *\n BT, i_s * BS), (BT, BS), (1, 0))\n p_z = tl.make_block_ptr(z + i_bh * T * S, (T, S), (S, 1), (i_t *\n BT, i_s * BS), (BT, BS), (1, 0))\n else:\n p_s = tl.make_block_ptr(s + (bos * H + i_h) * S, (T, S), (H * S,\n 1), (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n p_z = tl.make_block_ptr(z + (bos * H + i_h) * S, (T, S), (H * S,\n 1), (i_t * BT, i_s * BS), (BT, BS), (1, 0))\n b_s = tl.load(p_s, boundary_check=(0, 1)).to(tl.float32)\n b_c = b_z[None, :] + tl.dot(m_s, b_s, allow_tf32=False)\n tl.store(p_z, b_c.to(p_z.dtype.element_ty), boundary_check=(0, 1))\n if i_t >= 0:\n b_z += tl.sum(b_s, 0)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "f0ab72b8-9381-4758-a492-d2577626d98d", "file_name": "flash_triton.py", "repo_name": "MayDomine/Burst-Attention", "file_path": "burst_attn/flash_triton.py", "commit_hash": "b088c554072935074ea9c643de5ee363be5ab1f6", "starcount": 0, "input": "@triton.jit\ndef _bwd_preprocess_do_o_dot(Out, DO, Delta, stride_ob, stride_oh,\n stride_om, stride_dob, stride_doh, stride_dom, nheads, seqlen_q,\n seqlen_q_rounded, headdim, BLOCK_M: tl.constexpr, BLOCK_HEADDIM: tl.\n constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n o = tl.load(Out + off_b * stride_ob + off_h * stride_oh + offs_m[:,\n None] * stride_om + offs_d[None, :], mask=(offs_m[:, None] <\n seqlen_q) & (offs_d[None, :] < headdim), other=0.0).to(tl.float32)\n do = tl.load(DO + off_b * stride_dob + off_h * stride_doh + offs_m[:,\n None] * stride_dom + offs_d[None, :], mask=(offs_m[:, None] <\n seqlen_q) & (offs_d[None, :] < headdim), other=0.0).to(tl.float32)\n delta = tl.sum(o * do, axis=1)\n tl.store(Delta + off_hb * seqlen_q_rounded + offs_m, delta)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/MayDomine/Burst-Attention/blob/b088c554072935074ea9c643de5ee363be5ab1f6/burst_attn/flash_triton.py" }, { "uuid": "278158ef-9d13-42d9-9403-ad874e38674a", "file_name": "shape.py", "repo_name": "2niuhe/triton_utils", "file_path": "src/triton_utils/shape.py", "commit_hash": "6184906ac3b86dac3ccbfac128ec393ccecde5df", "starcount": 0, "input": "@triton.jit\ndef store_full_2d(vals, ptr, sz0: tl.constexpr, sz1: tl.constexpr, stride0=\n None, stride1=1):\n \"\"\"Store 2d block into matrix (defined by ptr)\"\"\"\n stride0 = stride0 or sz1\n offs = get_2d_offset(tl.arange(0, sz0), tl.arange(0, sz1), stride0, stride1\n )\n mask = get_2d_mask(tl.arange(0, sz0), tl.arange(0, sz1), sz0, sz1)\n tl.store(ptr + offs, vals, mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/2niuhe/triton_utils/blob/6184906ac3b86dac3ccbfac128ec393ccecde5df/src/triton_utils/shape.py" }, { "uuid": "b0e2d0fb-4469-4b96-82eb-ab68f3187e7b", "file_name": "triton_kernel.py", "repo_name": "yann-Choho/projet_PPML", "file_path": "notebooks/triton_kernel.py", "commit_hash": "9274e0561443b01f029ee6e0737f922f71d2da39", "starcount": 0, "input": "@triton.autotune(configs=get_autotune_config(), key=['M', 'N', 'K'])\n@triton.jit\ndef ff_llama(a_ptr, w1_ptr, w3_ptr, out_ptr, M, N, K, stride_am, stride_ak,\n stride_w1k, stride_w1n, stride_w3k, stride_w3n, stride_outm,\n stride_outn, USE_FP8: tl.constexpr, EPS: tl.constexpr, BLOCK_SIZE_M: tl\n .constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K: tl.constexpr):\n \"\"\"\n w1 and w3 are weights (linear layers)\n F.silu(w1(x)) * w3(x)\n \"\"\"\n pid = tl.program_id(axis=0)\n pid_m = pid // tl.cdiv(N, BLOCK_SIZE_N)\n pid_n = pid % tl.cdiv(N, BLOCK_SIZE_N)\n offs_am = (pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)) % M\n offs_bn = (pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)) % N\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n w1_ptrs = w1_ptr + (offs_k[:, None] * stride_w1k + offs_bn[None, :] *\n stride_w1n)\n w3_ptrs = w3_ptr + (offs_k[:, None] * stride_w3k + offs_bn[None, :] *\n stride_w3n)\n acc1 = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n acc2 = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n for _ in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n a = tl.load(a_ptrs)\n b = tl.load(w1_ptrs)\n if USE_FP8:\n b = b.to(tl.float8e5, bitcast=True)\n b = b.to(tl.float32)\n b = b.to(tl.float16)\n acc1 += tl.dot(a, b)\n c = tl.load(w3_ptrs)\n if USE_FP8:\n c = c.to(tl.float8e5, bitcast=True)\n c = c.to(tl.float32)\n c = c.to(tl.float16)\n acc2 += tl.dot(a, c)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n w1_ptrs += BLOCK_SIZE_K * stride_w1k\n w3_ptrs += BLOCK_SIZE_K * stride_w3k\n acc1 = acc1\n acc2 = acc2\n accumulator = acc1 * tl.sigmoid(acc1) * acc2\n offs_outm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_outn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n out_ptrs = out_ptr + (stride_outm * offs_outm[:, None] + stride_outn *\n offs_outn[None, :])\n out_mask = (offs_outm[:, None] < M) & (offs_outn[None, :] < N)\n tl.store(out_ptrs, accumulator, mask=out_mask)\n", "category": { "Functionality": [ "Activation Functions", "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/yann-Choho/projet_PPML/blob/9274e0561443b01f029ee6e0737f922f71d2da39/notebooks/triton_kernel.py" }, { "uuid": "ea665a0c-9ad0-4547-bcd9-8f5d72e5f94b", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef mlstm_matmul_kernel(Q, K, V, F, I, M, B, H, NH: tl.constexpr, S: tl.\n constexpr, D: tl.constexpr, SB: tl.constexpr):\n bh_id = tl.program_id(0)\n sb_id = tl.program_id(1)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n batch_offset_q = batch_id * NH * S * D + head_id * S * D\n batch_offset_f = batch_id * NH * S + head_id * S\n offset_q = tl.arange(0, SB) + sb_id * SB\n offset_k = tl.arange(0, SB) + sb_id * SB\n d_range = tl.arange(0, D)\n q_range = batch_offset_q + offset_q[:, None] * D + d_range[None, :]\n q_mask = (offset_q[:, None] < S) & (d_range[None, :] < D)\n q = tl.load(Q + q_range, q_mask)\n f = tl.load(F + batch_offset_f + offset_q, offset_q < S)\n f = tl.cumsum(tl.log(tl.sigmoid(f)))\n c_acc = tl.zeros((SB, D), dtype=tl.float32)\n b_acc = tl.zeros((SB,), dtype=tl.float32)\n m_acc = tl.zeros((SB,), dtype=tl.float32) - float('inf')\n for j in range(sb_id, -1, -1):\n kv_range = batch_offset_q + offset_k[:, None] * D + d_range[None, :]\n kv_mask = (offset_k[:, None] < S) & (d_range[None, :] < D)\n k = tl.load(K + kv_range, kv_mask) / tl.sqrt(tl.full((1,), D, dtype\n =tl.float32))\n v = tl.load(V + kv_range, kv_mask)\n f_next = tl.load(F + batch_offset_f + offset_k, offset_k < S)\n i = tl.load(I + batch_offset_f + offset_k, offset_k < S)\n f_next = tl.log(tl.sigmoid(f_next))\n if j == sb_id:\n f_next = tl.cumsum(f_next)\n d = f[:, None] - f_next[None, :] + i[None, :]\n mask = offset_q[:, None] >= offset_k[None, :]\n d = tl.where(mask, d, -float('inf'))\n else:\n f += tl.sum(f_next)\n f_next = tl.cumsum(f_next)\n d = f[:, None] - f_next[None, :] + i[None, :]\n m = tl.maximum(tl.max(d, 1), m_acc)\n d = tl.exp(d - m[:, None])\n c = matrix_mult(q, tl.trans(k), SB) * d\n b_acc = b_acc * tl.exp(m_acc - m) + tl.sum(c, 1)\n c = matrix_mult(c, v, SB)\n c_acc = c_acc * tl.exp(m_acc - m)[:, None] + c\n m_acc = m\n offset_k -= SB\n n = tl.maximum(tl.abs(b_acc), tl.exp(-m_acc)) + 1e-06\n h = c_acc / n[:, None]\n tl.store(H + q_range, h, q_mask)\n tl.store(B + batch_offset_f + offset_q, b_acc, offset_q < S)\n tl.store(M + batch_offset_f + offset_q, m_acc, offset_q < S)\n", "category": { "Functionality": [ "Matrix Multiplication", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "27fc8e86-3d25-4ff7-b9cb-308bd627ca58", "file_name": "sequential_rnn_scan.py", "repo_name": "TushaarGVS/linear-rnn", "file_path": "linear_rnn/triton/sequential_rnn_scan.py", "commit_hash": "48320589b73154484be7d09a144923a2b9e56b85", "starcount": 0, "input": "@triton.jit\ndef _sequential_rnn_scan_fwd_kernel(x_ptr, a_ptr, h0_ptr, out_ptr,\n stride_x_batch, stride_x_len, stride_x_dim, stride_a_batch,\n stride_a_len, stride_a_dim, stride_h0_batch, stride_h0_dim,\n stride_out_batch, stride_out_dim, seq_len: tl.constexpr, BLOCK_SIZE: tl\n .constexpr):\n pid_batch = tl.program_id(0)\n pid_dim = tl.program_id(1)\n x_ptr += pid_batch * stride_x_batch\n a_ptr += pid_batch * stride_a_batch\n ht_ptr = h0_ptr + pid_batch * stride_h0_batch\n out_ptr += pid_batch * stride_out_batch\n offsets = pid_dim * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n x_ptrs = x_ptr + offsets * stride_x_dim\n a_ptrs = a_ptr + offsets * stride_a_dim\n ht_ptrs = ht_ptr + offsets * stride_h0_dim\n out_ptrs = out_ptr + offsets * stride_out_dim\n h_t = tl.load(ht_ptrs).to(tl.float32)\n for t in range(seq_len):\n x_t = tl.load(x_ptrs).to(tl.float32)\n a_t = tl.load(a_ptrs).to(tl.float32)\n h_t = a_t * h_t + x_t\n if t < seq_len - 1:\n x_ptrs += stride_x_len\n a_ptrs += stride_a_len\n tl.store(out_ptrs, h_t.to(out_ptr.dtype.element_ty))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/TushaarGVS/linear-rnn/blob/48320589b73154484be7d09a144923a2b9e56b85/linear_rnn/triton/sequential_rnn_scan.py" }, { "uuid": "70061971-e534-482c-8c08-07c373e9ef4d", "file_name": "mse.py", "repo_name": "l1351868270/implicit_gemm.triton", "file_path": "triton_kernel/mse.py", "commit_hash": "64eb8548ccf4576883c928f6315be8b24680a455", "starcount": 0, "input": "@triton.jit\ndef _ld_mse_fwd_kernel(loss_ptr, input_ptr, target_ptr, loss_row_stride,\n input_row_stride, target_row_stride, n_rows, n_cols, BLOCK_SIZE: tl.\n constexpr):\n pid = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n input_ptrs = input_ptr + pid * input_row_stride + col_offsets\n target_ptrs = target_ptr + pid * target_row_stride + col_offsets\n input = tl.load(input_ptrs, mask=mask, other=0.0)\n target = tl.load(target_ptrs, mask=mask, other=0.0)\n loss = tl.sum((input - target) * (input - target)) / n_cols\n loss_ptrs = loss_ptr + pid\n tl.store(loss_ptrs, loss, mask=pid < n_rows)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/l1351868270/implicit_gemm.triton/blob/64eb8548ccf4576883c928f6315be8b24680a455/triton_kernel/mse.py" }, { "uuid": "e6c654b9-0a74-43ae-8353-03aef9101762", "file_name": "snake.py", "repo_name": "falkaer/multi-scale-music", "file_path": "snake.py", "commit_hash": "a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16)], key=['C'])\n@triton.jit\ndef _snake_fwd_triton(X, OUT, ALPHA, CR, X_stride1, X_stride2, X_stride3,\n OUT_stride1, OUT_stride2, OUT_stride3, A_stride, C_stride, C, N, CORR:\n tl.constexpr, BLOCK_SIZE: tl.constexpr):\n pid = tl.program_id(0)\n batch_idx = pid // C\n channel_idx = pid % C\n block_start = tl.program_id(1) * BLOCK_SIZE\n offsets = block_start + tl.arange(0, BLOCK_SIZE)\n X = X + batch_idx * X_stride1 + channel_idx * X_stride2\n x = tl.load(X + offsets * X_stride3, mask=offsets < N)\n alpha = tl.load(ALPHA + channel_idx * A_stride)\n sinax = tl.sin((alpha * x).to(tl.float32)).to(x.type)\n out = x + sinax * sinax / alpha\n if CORR:\n cr = tl.load(CR + channel_idx * C_stride)\n out = out / cr\n OUT = OUT + batch_idx * OUT_stride1 + channel_idx * OUT_stride2\n tl.store(OUT + offsets * OUT_stride3, out, mask=offsets < N)\n", "category": { "Functionality": [ "Elementwise Operations", "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/falkaer/multi-scale-music/blob/a7794ddfb3bbd95b70acf3fe72a08d8a1d47564d/snake.py" }, { "uuid": "b05a8075-2ff7-49c6-891a-44aefc01ecb3", "file_name": "softmax.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/softmax.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['D'])\n@triton.jit\ndef softmax_bwd_kernel(p, dp, ds, D: tl.constexpr, B: tl.constexpr):\n i_n = tl.program_id(0)\n o_d = tl.arange(0, B)\n m_d = o_d < D\n b_p = tl.load(p + i_n * D + o_d, mask=m_d, other=0.0)\n b_dp = tl.load(dp + i_n * D + o_d, mask=m_d, other=0.0)\n b_pp = tl.sum(b_p * b_dp, 0)\n b_ds = b_p * b_dp - b_p * b_pp\n tl.store(ds + i_n * D + o_d, b_ds.to(ds.dtype.element_ty), mask=m_d)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/softmax.py" }, { "uuid": "203cae00-18cd-4f73-9919-f4c8e964f077", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_K': b}, num_warps=w) for\n b, w in itertools.product([2, 4, 16, 32, 128, 256], [2, 4, 8])], key=['N'])\n@triton.jit\ndef triton_sum_kernel_2D_result_dim_1(input_ptr, output_ptr, M: tl.\n constexpr, N: tl.constexpr, K: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_m = pid // tl.cdiv(K, BLOCK_SIZE_K)\n pid_k = pid % tl.cdiv(K, BLOCK_SIZE_K)\n block_start_n = 0\n block_start_k = pid_k * BLOCK_SIZE_K\n offsets_n = block_start_n + tl.arange(0, BLOCK_SIZE_N)\n offsets_k = block_start_k + tl.arange(0, BLOCK_SIZE_K)\n mask_n = offsets_n < N\n mask_k = offsets_k < K\n idxs_base = offsets_n[:, None] * K + offsets_k\n idxs = idxs_base + pid_m * N * K\n mask = mask_n[:, None] & mask_k\n input = tl.load(input_ptr + idxs, mask=mask, other=0)\n output = tl.sum(input, axis=0)\n output_offsets = pid_m * K + offsets_k\n tl.store(output_ptr + output_offsets, output, mask=mask_k)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/sum/kernels.py" }, { "uuid": "683528ff-21dc-4e7c-be90-58e192bdd603", "file_name": "gemm_a16w8.py", "repo_name": "AlibabaPAI/FLASHNN", "file_path": "flashnn/triton_kernels/gemm_a16w8.py", "commit_hash": "528a9301587f5fb135b25d973a87ba0a40a703a7", "starcount": 0, "input": "@triton.jit\ndef _triton_gemm_a16w8_sub_channel_kernel(A, B, C, scale_b, bias,\n zero_points, M, N, K, stride_am, stride_ak, stride_bn, stride_bk,\n stride_cm, stride_cn, stride_zpk, stride_zpn, stride_scalek,\n stride_scalen, add_bias: tl.constexpr, add_zero_points: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr,\n GROUP_M: tl.constexpr, SPLIT_K: tl.constexpr):\n pid = tl.program_id(0)\n pid_z = tl.program_id(1)\n grid_m = tl.cdiv(M, BLOCK_M)\n grid_n = tl.cdiv(N, BLOCK_N)\n width = GROUP_M * grid_n\n group_id = pid // width\n group_size = min(grid_m - group_id * GROUP_M, GROUP_M)\n pid_m = group_id * GROUP_M + pid % group_size\n pid_n = pid % width // group_size\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n ram = tl.max_contiguous(tl.multiple_of(rm % M, BLOCK_M), BLOCK_M)\n rbn = tl.max_contiguous(tl.multiple_of(rn % N, BLOCK_N), BLOCK_N)\n rk = pid_z * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A + (ram[:, None] * stride_am + rk[None, :] * stride_ak)\n B = B + (rbn[:, None] * stride_bn + rk[None, :] * stride_bk)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n scale_w_offs = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n _SCALE0 = tl.zeros([1], dtype=scale_b.dtype.element_ty)\n for k in range(0, tl.cdiv(K, BLOCK_K * SPLIT_K)):\n k_remaining = K - k * (BLOCK_K * SPLIT_K)\n _A0 = tl.zeros((1, 1), dtype=A.dtype.element_ty)\n a = tl.load(A, mask=rk[None, :] < k_remaining, other=_A0)\n _B0 = tl.zeros((1, 1), dtype=B.dtype.element_ty)\n b = tl.load(B, mask=rk[None, :] < k_remaining, other=_B0)\n if add_zero_points:\n _ZERO_POINT0 = tl.zeros([1], dtype=zero_points.dtype.element_ty)\n zero_points_offs = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n zero_points_ptrs = zero_points + (k * SPLIT_K + pid_z\n ) * stride_zpk + zero_points_offs\n zero_points_vals = tl.load(zero_points_ptrs, mask=\n zero_points_offs < N, other=_ZERO_POINT0)\n b = b - zero_points_vals[:, None]\n scale_ptrs = (scale_b + k * SPLIT_K * stride_scalek + pid_z *\n stride_scalek + scale_w_offs)\n scales = tl.load(scale_ptrs, mask=scale_w_offs < N, other=_SCALE0)\n b_fp = b * scales[:, None]\n b_fp = tl.trans(b_fp)\n acc += tl.dot(a, b_fp, out_dtype=tl.float32, allow_tf32=True)\n A += BLOCK_K * SPLIT_K * stride_ak\n B += BLOCK_K * SPLIT_K * stride_bk\n acc = acc.to(C.dtype.element_ty)\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n C = C + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n if add_bias:\n offs_bias = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n bias_ptrs = bias + offs_bias\n _BIAS0 = tl.zeros([1], dtype=bias.dtype.element_ty)\n bias_vals = tl.load(bias_ptrs, mask=offs_bias < N, other=_BIAS0)\n if pid_z == 0:\n acc += bias_vals[None, :]\n if SPLIT_K == 1:\n tl.store(C, acc, mask=mask)\n else:\n tl.atomic_add(C, acc, mask=mask)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/AlibabaPAI/FLASHNN/blob/528a9301587f5fb135b25d973a87ba0a40a703a7/flashnn/triton_kernels/gemm_a16w8.py" }, { "uuid": "c5831adf-3388-428d-9adb-9b92d80bed77", "file_name": "layernorm.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/layernorm.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['N', 'HAS_RESIDUAL', 'STORE_RESIDUAL_OUT',\n 'IS_RMS_NORM', 'HAS_BIAS'])\n@triton.jit\ndef layer_norm_fwd_kernel(X, Y, W, B, RESIDUAL, RESIDUAL_OUT, Mean, Rstd,\n stride_x_row, stride_y_row, stride_res_row, stride_res_out_row, N, G,\n eps, IS_RMS_NORM: tl.constexpr, BLOCK_N: tl.constexpr, HAS_RESIDUAL: tl\n .constexpr, STORE_RESIDUAL_OUT: tl.constexpr, HAS_WEIGHT: tl.constexpr,\n HAS_BIAS: tl.constexpr):\n row = tl.program_id(0)\n group = row % G\n X += row * stride_x_row\n Y += row * stride_y_row\n if HAS_RESIDUAL:\n RESIDUAL += row * stride_res_row\n if STORE_RESIDUAL_OUT:\n RESIDUAL_OUT += row * stride_res_out_row\n cols = tl.arange(0, BLOCK_N)\n x = tl.load(X + cols, mask=cols < N, other=0.0).to(tl.float32)\n if HAS_RESIDUAL:\n residual = tl.load(RESIDUAL + cols, mask=cols < N, other=0.0).to(tl\n .float32)\n x += residual\n if STORE_RESIDUAL_OUT:\n tl.store(RESIDUAL_OUT + cols, x, mask=cols < N)\n if not IS_RMS_NORM:\n mean = tl.sum(x, axis=0) / N\n tl.store(Mean + row, mean)\n xbar = tl.where(cols < N, x - mean, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n else:\n xbar = tl.where(cols < N, x, 0.0)\n var = tl.sum(xbar * xbar, axis=0) / N\n rstd = 1 / tl.sqrt(var + eps)\n tl.store(Rstd + row, rstd)\n mask = cols < N\n if HAS_WEIGHT:\n w = tl.load(W + group * stride_x_row + cols, mask=mask).to(tl.float32)\n if HAS_BIAS:\n b = tl.load(B + group * stride_x_row + cols, mask=mask).to(tl.float32)\n x_hat = (x - mean) * rstd if not IS_RMS_NORM else x * rstd\n y = x_hat * w if HAS_WEIGHT else x_hat\n if HAS_BIAS:\n y = y + b\n tl.store(Y + cols, y, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/layernorm.py" }, { "uuid": "ec15a21e-2872-4637-b17e-81c3c60d4e50", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gsa/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64] for BV in [32, 64] for\n num_warps in [2, 4, 8] for num_stages in [2, 3, 4]], key=['BT'])\n@triton.jit\ndef chunk_gsa_fwd_k_kernel_inter(q, k, h, g, o, A, offsets, indices, scale,\n T: tl.constexpr, HQ: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V:\n tl.constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, NG:\n tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_bg = i_bh // NG\n i_b, i_hq = i_bh // HQ, i_bh % HQ\n i_h = i_hq // NG\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n o_i = tl.arange(0, BT)\n m_s = o_i[:, None] >= o_i[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n b_A = tl.zeros([BT, BT], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bg * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_bg * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * HQ + i_hq) * K, (T, K), (HQ *\n K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT), (BK, BT), (0, 1))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (\n V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_o += tl.dot(b_q, b_h)\n b_A += tl.dot(b_q, b_k)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bg * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * HQ + i_hq) * V, (T, V), (HQ * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_A = tl.make_block_ptr(A + (bos * HQ + i_hq) * BT, (T, BT), (HQ *\n BT, 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_o = b_o * tl.exp(b_g)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n b_A = tl.where(m_s, b_A, 0.0)\n if i_v == 0:\n tl.store(p_A, b_A.to(p_A.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Transposed Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gsa/chunk.py" }, { "uuid": "4b05f8aa-476d-4b90-b0cb-9c78955c0028", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef reduce_mlstm_triton(F_REDUCED_IN, F_REDUCED_OUT, C, N, NH: tl.constexpr,\n D: tl.constexpr, NSB: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n bh_id = tl.program_id(0)\n x_id = tl.program_id(1)\n y_id = tl.program_id(2)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n nsb_range = tl.arange(0, NSB)\n nsb_range_2d = tl.arange(0, NSB)[:, None]\n nsb_range_3d = tl.arange(0, NSB)[:, None, None]\n block_range = tl.arange(0, BLOCK_SIZE)\n block_range_2d = block_range[None, :]\n x_range = block_range + x_id * BLOCK_SIZE\n x_range_3d = x_range[None, :, None]\n y_range = block_range + y_id * BLOCK_SIZE\n y_range_3d = y_range[None, None, :]\n batch_offset_f = batch_id * NH * NSB + head_id * NSB\n batch_offset_n = batch_id * NH * NSB * D + head_id * NSB * D\n batch_offset_c = batch_id * NH * NSB * D * D + head_id * NSB * D * D\n f = tl.load(F_REDUCED_IN + batch_offset_f + nsb_range)\n c_range = (batch_offset_c + nsb_range_3d * D * D + x_range_3d * D +\n y_range_3d)\n c_mask = (nsb_range_3d < NSB) & (x_range_3d < D) & (y_range_3d < D)\n c = tl.load(C + c_range, c_mask)\n f_reduced, c = tl.associative_scan((tl.broadcast_to(f[:, None, None], (\n NSB, BLOCK_SIZE, BLOCK_SIZE)), c), 0, scan_op)\n tl.store(C + c_range, c, c_mask)\n if x_id == 0 and y_id == 0:\n f_range = batch_offset_f + nsb_range_3d + block_range[None, :, None\n ] * 0 + block_range[None, None, :] * 0\n f_mask = (nsb_range_3d < NSB) & (block_range[None, :, None] == 0) & (\n block_range[None, None, :] == 0)\n tl.store(F_REDUCED_OUT + f_range, f_reduced, f_mask)\n if x_id == 0:\n n_range = (batch_offset_n + nsb_range_2d * D + block_range_2d + \n y_id * BLOCK_SIZE)\n n_mask = (nsb_range_2d < NSB) & (block_range_2d + y_id * BLOCK_SIZE < D\n )\n n = tl.load(N + n_range, n_mask)\n _, n = tl.associative_scan((tl.broadcast_to(f[:, None], (NSB,\n BLOCK_SIZE)), n), 0, scan_op)\n tl.store(N + n_range, n, n_mask)\n", "category": { "Functionality": [ "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "c775be82-a8e2-4755-9d15-d9d2fdf331a0", "file_name": "mlstm_scan.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_scan.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef roll_op(a1, b1_last, b1_cur, a2, b2_last, b2_cur):\n return a1 + a2, tl.where(a2 == 1, b1_cur, 0) + b2_last, b2_cur\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_scan.py" }, { "uuid": "723fee45-0116-4b18-9403-354cfe2b1f3a", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef jagged_2_softmax_backward_kernel(grad_output_ptr, softmax_output_ptr,\n grad_input_ptr, offsets_row_ptr, offsets_col_ptr, offsets_overall_ptr,\n grad_output_stride, softmax_output_stride, grad_input_stride, transpose,\n max_seq_len_row: tl.constexpr, max_seq_len_col: tl.constexpr,\n BLOCK_SIZE: tl.constexpr):\n pid_batch = tl.program_id(0)\n pid_head = tl.program_id(1)\n begin = tl.load(offsets_overall_ptr + pid_batch)\n if transpose:\n N = tl.load(offsets_row_ptr + pid_batch + 1) - tl.load(\n offsets_row_ptr + pid_batch)\n H = tl.load(offsets_col_ptr + pid_batch + 1) - tl.load(\n offsets_col_ptr + pid_batch)\n stride_n = H\n stride_h = H // H\n H = tl.minimum(max_seq_len_col, H)\n N = tl.minimum(max_seq_len_row, N)\n else:\n N = tl.load(offsets_col_ptr + pid_batch + 1) - tl.load(\n offsets_col_ptr + pid_batch)\n H = tl.load(offsets_row_ptr + pid_batch + 1) - tl.load(\n offsets_row_ptr + pid_batch)\n stride_h = N\n stride_n = N // N\n H = tl.minimum(max_seq_len_row, H)\n N = tl.minimum(max_seq_len_col, N)\n if pid_head >= H:\n return\n if H == 0 or N == 0:\n pass\n start_ptr = grad_output_ptr + begin * grad_output_stride\n offsets = tl.arange(0, BLOCK_SIZE)\n grad_output_ptrs = (start_ptr + offsets * grad_output_stride * stride_n +\n pid_head * grad_output_stride * stride_h)\n softmax_output_ptrs = (softmax_output_ptr + begin *\n softmax_output_stride + offsets * softmax_output_stride * stride_n +\n pid_head * softmax_output_stride * stride_h)\n grad_output_row = tl.load(grad_output_ptrs, mask=offsets < N, other=0.0)\n softmax_output_row = tl.load(softmax_output_ptrs, mask=offsets < N,\n other=0.0)\n sum_value = tl.sum(grad_output_row * softmax_output_row, axis=0)\n grad_input_row = (grad_output_row - sum_value) * softmax_output_row\n grad_input_row_start_ptr = grad_input_ptr + begin * grad_input_stride\n grad_input_ptrs = (grad_input_row_start_ptr + offsets *\n grad_input_stride * stride_n + pid_head * grad_input_stride * stride_h)\n tl.store(grad_input_ptrs, grad_input_row, mask=offsets < N)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "59b8c65e-8a9d-4eb0-8a49-f36eda5a4381", "file_name": "kl.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/kl.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_kl_forward(y_pred_ptr, y_pred_stride, y_true_ptr, y_true_stride,\n output_loss_ptr, output_loss_stride, num_classes, epsilon, BLOCK_SIZE:\n tl.constexpr, log_target: tl.constexpr=False, reduction_mode: tl.\n constexpr=REDUCE_BATCH_MEAN):\n row_id = tl.program_id(0).to(tl.int64)\n y_pred_ptr += row_id * y_pred_stride\n y_true_ptr += row_id * y_true_stride\n output_loss_ptr += row_id * output_loss_stride\n base_offsets = tl.arange(0, BLOCK_SIZE)\n loss_sum = 0.0\n for i in range(0, num_classes, BLOCK_SIZE):\n offsets = i + base_offsets\n mask = offsets < num_classes\n y_pred = tl.load(y_pred_ptr + offsets, mask=mask, other=0.0)\n y_true = tl.load(y_true_ptr + offsets, mask=mask, other=0.0)\n if not log_target:\n loss = y_true * (tl.log(tl.maximum(y_true, epsilon)) - y_pred)\n else:\n loss = tl.exp(y_true) * (y_true - y_pred)\n if reduction_mode == REDUCE_NONE:\n tl.store(output_loss_ptr + offsets, loss, mask=mask)\n else:\n loss_sum += tl.sum(loss, axis=0)\n if reduction_mode != REDUCE_NONE:\n tl.store(output_loss_ptr, loss_sum)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/kl.py" }, { "uuid": "30740efe-faab-4c6a-a9da-b62c8d379e71", "file_name": "test.py", "repo_name": "Aalanli/AMDGPUExperiments", "file_path": "test.py", "commit_hash": "2a6fd9e1e81d1916e3d87db4dda930e2fa417527", "starcount": 0, "input": "@triton.jit\ndef test(at, bt, ct, k):\n midx = tl.arange(0, 32)\n kidx = tl.arange(0, 32)\n nidx = tl.arange(0, 32)\n aidx = midx[:, None] * 32 + kidx[None, :]\n bidx = kidx[:, None] * 32 + nidx[None, :]\n cidx = midx[:, None] * 32 + nidx[None, :]\n a_ptrs = at + aidx\n b_ptrs = bt + bidx\n c_ptrs = ct + cidx\n for i in range(k):\n a = tl.load(a_ptrs)\n b = tl.load(b_ptrs)\n x = tl.dot(a, b)\n tl.atomic_add(c_ptrs, x)\n a_ptrs += 32\n b_ptrs += 32\n c_ptrs += 32\n", "category": { "Functionality": [ "Matrix Multiplication", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Aalanli/AMDGPUExperiments/blob/2a6fd9e1e81d1916e3d87db4dda930e2fa417527/test.py" }, { "uuid": "f7119a9c-0bf5-469a-844f-759f16760205", "file_name": "fused_rotary_emb.py", "repo_name": "tascj/kaggle-lmsys-chatbot-arena", "file_path": "human_pref/inference/ops/fused_rotary_emb.py", "commit_hash": "83cd93d50b9283c18711e8c63e4e1c6399c7b9ce", "starcount": 0, "input": "@wrap_jit_func(type_hint=dict(Q=Tensor, K=Tensor, PostionIds=Tensor,\n InvFreq=Tensor, scaling_factor=float, OutQ=Tensor, OutK=Tensor,\n stride_bq=int, stride_sq=int, stride_hq=int, stride_dq=int, stride_bk=\n int, stride_sk=int, stride_hk=int, stride_dk=int, stride_bp=int,\n stride_sp=int, max_seq_len=int, BLOCK=torch.int32, BLOCK_HQ=torch.int32,\n BLOCK_HK=torch.int32, BLOCK_F=torch.int32))\n@triton.jit\ndef _fused_rotary_emb_kernel(Q, K, PostionIds, InvFreq, scaling_factor,\n OutQ, OutK, stride_bq, stride_sq, stride_hq: tl.constexpr, stride_dq:\n tl.constexpr, stride_bk, stride_sk, stride_hk: tl.constexpr, stride_dk:\n tl.constexpr, stride_bp, stride_sp, max_seq_len, BLOCK: tl.constexpr,\n BLOCK_HQ: tl.constexpr, BLOCK_HK: tl.constexpr, BLOCK_F: tl.constexpr):\n \"\"\"fused rotary emb kernel.\"\"\"\n batch_id = tl.program_id(0)\n seq_block_id = tl.program_id(1)\n s_off = seq_block_id * BLOCK + tl.arange(0, BLOCK)[:, None]\n f_off = tl.arange(0, BLOCK_F)[None, :]\n s_mask = s_off < max_seq_len\n bp_off = stride_bp * batch_id\n p_off = bp_off + stride_sp * s_off\n sq_off = batch_id * stride_bq + s_off * stride_sq\n q0_off = sq_off + f_off * stride_dq\n q1_off = q0_off + BLOCK_F * stride_dq\n sk_off = batch_id * stride_bk + s_off * stride_sk\n k0_off = sk_off + f_off * stride_dk\n k1_off = k0_off + BLOCK_F * stride_dk\n inv_freq = tl.load(InvFreq + f_off).to(tl.float32)\n position_ids = tl.load(PostionIds + p_off, mask=s_mask).to(tl.float32)\n position_ids = position_ids / scaling_factor\n pos_freq = position_ids * inv_freq\n cos = tl.cos(pos_freq).to(Q.dtype.element_ty)\n sin = tl.sin(pos_freq).to(Q.dtype.element_ty)\n for h in range(BLOCK_HQ):\n q0 = tl.load(Q + q0_off + h * stride_hq, mask=s_mask)\n q1 = tl.load(Q + q1_off + h * stride_hq, mask=s_mask)\n q0_out = q0 * cos - q1 * sin\n tl.store(OutQ + q0_off + h * stride_hq, q0_out, mask=s_mask)\n q1_out = q1 * cos + q0 * sin\n tl.store(OutQ + q1_off + h * stride_hq, q1_out, mask=s_mask)\n for h in range(BLOCK_HK):\n k0 = tl.load(K + k0_off + h * stride_hk, mask=s_mask)\n k1 = tl.load(K + k1_off + h * stride_hk, mask=s_mask)\n k0_out = k0 * cos - k1 * sin\n tl.store(OutK + k0_off + h * stride_hk, k0_out, mask=s_mask)\n k1_out = k1 * cos + k0 * sin\n tl.store(OutK + k1_off + h * stride_hk, k1_out, mask=s_mask)\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32", "fp16", "bf16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/tascj/kaggle-lmsys-chatbot-arena/blob/83cd93d50b9283c18711e8c63e4e1c6399c7b9ce/human_pref/inference/ops/fused_rotary_emb.py" }, { "uuid": "4efaee35-c75d-4f5c-8424-f258ebfd3ef4", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps) for BK in [32, 64] for BV in [64, 128] for num_warps in [2, \n 4, 8]], key=['BT'])\n@triton.jit\ndef chunk_gla_fwd_kernel_o(q, v, g, h, o, A, offsets, indices, scale, T: tl\n .constexpr, H: tl.constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.\n constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_OFFSETS: tl.\n constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n m_s = tl.arange(0, BT)[:, None] >= tl.arange(0, BT)[None, :]\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_g = tl.make_block_ptr(g + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_g = tl.make_block_ptr(g + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (K, V), (\n V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_g = tl.load(p_g, boundary_check=(0, 1))\n b_qg = (b_q * tl.exp(b_g)).to(b_q.dtype)\n b_h = tl.load(p_h, boundary_check=(0, 1))\n if i_k >= 0:\n b_o += tl.dot(b_qg, b_h.to(b_qg.dtype))\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + i_bh * T * V, (T, V), (V, 1), (i_t * BT,\n i_v * BV), (BT, BV), (1, 0))\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT, 0), (BT, BT), (1, 0))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_o = tl.make_block_ptr(o + (bos * H + i_h) * V, (T, V), (H * V, 1),\n (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT, 0), (BT, BT), (1, 0))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_A = tl.load(p_A, boundary_check=(0, 1))\n b_A = tl.where(m_s, b_A, 0.0).to(b_v.dtype)\n b_o += tl.dot(b_A, b_v, allow_tf32=False)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/gla/chunk.py" }, { "uuid": "2d261111-e9c4-4247-abba-85e8407ab595", "file_name": "triton_sll.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _multi_head_jagged_flash_attention_fwd_kernel(q_ptr, k_ptr, v_ptr,\n offset_ptr, o_ptr, lse_i_ptr, stride_qh, stride_qm, stride_qd,\n stride_kh, stride_kn, stride_kd, stride_vh, stride_vn, stride_vd,\n stride_oh, stride_om, stride_od, stride_lse_h, num_heads: tl.constexpr,\n max_seq_len: tl.constexpr, D: tl.constexpr, allow_tf32: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, BLOCK_D: tl.constexpr):\n pid_m = tl.program_id(axis=0)\n pid_bh = tl.program_id(axis=1)\n pid_batch = pid_bh // num_heads\n pid_head = pid_bh % num_heads\n begin = tl.load(offset_ptr + pid_batch)\n end = tl.load(offset_ptr + pid_batch + 1)\n seqlen = end - begin\n seqlen = tl.minimum(seqlen, max_seq_len)\n if pid_m * BLOCK_M >= seqlen:\n return\n offs_m = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_D)\n acc = tl.zeros([BLOCK_M, BLOCK_D], dtype=tl.float32)\n mi = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n li = tl.zeros([BLOCK_M], dtype=tl.float32)\n for j in range(0, seqlen, BLOCK_N):\n offs_n = tl.arange(0, BLOCK_N) + j\n q_ptrs = q_ptr + pid_head * stride_qh + begin * stride_qm + (offs_m\n [:, None] * stride_qm + offs_d[None, :] * stride_qd)\n k_ptrs = k_ptr + pid_head * stride_kh + begin * stride_kn + (offs_n\n [None, :] * stride_kn + offs_d[:, None] * stride_kd)\n qk = tl.zeros((BLOCK_M, BLOCK_N), dtype=tl.float32)\n for d in range(0, D, BLOCK_D):\n curr_d = d + offs_d\n q = tl.load(q_ptrs, mask=(curr_d[None, :] < D) & (offs_m[:,\n None] < seqlen), other=0.0)\n k = tl.load(k_ptrs, mask=(curr_d[:, None] < D) & (offs_n[None,\n :] < seqlen), other=0.0)\n qk += tl.dot(q, k, allow_tf32=allow_tf32)\n q_ptrs += BLOCK_D * stride_qd\n k_ptrs += BLOCK_D * stride_kd\n mi_new = tl.maximum(tl.max(qk, axis=1), mi)\n mn_mask = (offs_m[:, None] < seqlen) & (offs_n[None, :] < seqlen)\n p = tl.exp(qk - mi_new[:, None])\n p = tl.where(mn_mask, p, 0.0)\n lij_hat = tl.sum(p, axis=1)\n alpha = tl.exp(mi - mi_new)\n li = alpha * li + lij_hat\n acc = alpha[:, None] * acc\n v_ptrs = v_ptr + pid_head * stride_vh + begin * stride_vn + (offs_d\n [None, :] * stride_vd + offs_n[:, None] * stride_vn)\n v = tl.load(v_ptrs, mask=(offs_d[None, :] < D) & (offs_n[:, None] <\n seqlen), other=0.0)\n p /= max_seq_len\n p = p.to(v_ptr.dtype.element_ty)\n acc += tl.dot(p, v, allow_tf32=allow_tf32)\n mi = mi_new\n lse_i = mi + tl.math.log(li)\n lse_i_offsets = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n lse_i_ptrs = lse_i_ptr + pid_head * stride_lse_h + begin + lse_i_offsets\n tl.store(lse_i_ptrs, lse_i, mask=lse_i_offsets < seqlen)\n acc = acc / li[:, None]\n o_ptrs = o_ptr + (pid_head * stride_oh + begin * stride_om + offs_m[:,\n None] * stride_om + offs_d[None, :] * stride_od)\n o_mask = (offs_m[:, None] < seqlen) & (offs_d[None, :] < D)\n tl.store(o_ptrs, acc, mask=o_mask)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp32", "bf16" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings", "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/sll/triton_sll.py" }, { "uuid": "aa5c6a98-da4b-4b90-9be0-e4a00ab26b49", "file_name": "mlstm_matmul.py", "repo_name": "LukasBluebaum/xLSTM-Triton-CUDA-Implementation", "file_path": "mlstm_matmul.py", "commit_hash": "6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b", "starcount": 0, "input": "@triton.jit\ndef mlstm_matmul_kernel_backward_db(dH, Q, K, V, F, I, M, B, dB, NH: tl.\n constexpr, S: tl.constexpr, D: tl.constexpr, SB: tl.constexpr):\n bh_id = tl.program_id(0)\n sb_id = tl.program_id(1)\n batch_id = bh_id // NH\n head_id = bh_id % NH\n batch_offset_dh = batch_id * NH * S * D + head_id * S * D\n batch_offset_f = batch_id * NH * S + head_id * S\n offset_dh = tl.arange(0, SB) + sb_id * SB\n offset_vk = tl.arange(0, SB) + sb_id * SB\n d_range = tl.arange(0, D)\n dh_range = batch_offset_dh + offset_dh[:, None] * D + d_range[None, :]\n dh_mask = (offset_dh[:, None] < S) & (d_range[None, :] < D)\n dh = tl.load(dH + dh_range, dh_mask)\n q = tl.load(Q + dh_range, dh_mask)\n m = tl.load(M + batch_offset_f + offset_dh, offset_dh < S)\n f = tl.load(F + batch_offset_f + offset_dh, offset_dh < S)\n f = tl.cumsum(tl.log(tl.sigmoid(f)))\n scale = tl.sqrt(tl.full((1,), D, dtype=tl.float32))\n dn_acc = tl.zeros((SB,), dtype=tl.float32)\n for j in range(sb_id, -1, -1):\n vk_range = batch_offset_dh + offset_vk[:, None] * D + d_range[None, :]\n vk_mask = (offset_vk[:, None] < S) & (d_range[None, :] < D)\n v = tl.load(V + vk_range, vk_mask)\n f_next = tl.load(F + batch_offset_f + offset_vk, offset_vk < S)\n i = tl.load(I + batch_offset_f + offset_vk, offset_vk < S)\n f_next = tl.log(tl.sigmoid(f_next))\n if j == sb_id:\n f_next = tl.cumsum(f_next)\n d = f[:, None] - f_next[None, :] + i[None, :]\n mask = offset_dh[:, None] >= offset_vk[None, :]\n d = tl.where(mask, d, -float('inf'))\n else:\n f += tl.sum(f_next)\n f_next = tl.cumsum(f_next)\n d = f[:, None] - f_next[None, :] + i[None, :]\n d = tl.exp(d - m[:, None])\n dc = matrix_mult(dh, tl.trans(v), SB)\n k = tl.load(K + vk_range, vk_mask) / scale\n c_tilde = matrix_mult(q, tl.trans(k), SB) * d\n dn_acc += tl.sum(c_tilde * dc, 1)\n offset_vk -= SB\n b = tl.load(B + batch_offset_f + offset_dh, offset_dh < S)\n n = tl.maximum(tl.abs(b), tl.exp(-m)) + 1e-06\n dn = -dn_acc * (1 / tl.exp(tl.log(n) * 2.0))\n db = sign(b) * dn * tl.where(tl.abs(b) > tl.exp(-m), 1.0, 0.0)\n tl.store(dB + batch_offset_f + offset_dh, db, offset_dh < S)\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/LukasBluebaum/xLSTM-Triton-CUDA-Implementation/blob/6fb49b89cc74e7dadd0f3d56db05684bb4e86f4b/mlstm_matmul.py" }, { "uuid": "03082872-4113-4a3f-8432-9b3df03409c0", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK}, num_warps=num_warps,\n num_stages=num_stages) for BK in [32, 64] for num_warps in [1, 2, 4, 8] for\n num_stages in [2, 3, 4]], key=['BC'])\n@triton.jit\ndef chunk_rwkv6_fwd_A_kernel_intra_sub_inter(q, k, gi, ge, A, offsets,\n indices, scale, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, BT:\n tl.constexpr, BC: tl.constexpr, BK: tl.constexpr, NC: tl.constexpr,\n USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.constexpr):\n i_t, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n i_i, i_j = i_c // NC, i_c % NC\n if USE_OFFSETS:\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n else:\n bos, eos = i_b * T, i_b * T + T\n if i_t * BT + i_i * BC >= T:\n return\n if i_i <= i_j:\n return\n b_A = tl.zeros([BC, BC], dtype=tl.float32)\n for i_k in range(tl.cdiv(K, BK)):\n o_k = i_k * BK + tl.arange(0, BK)\n m_k = o_k < K\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_gq = tl.make_block_ptr(ge + i_bh * T * K, (T, K), (K, 1), (\n i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (K, T), (1, K), (i_k *\n BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gk = tl.make_block_ptr(gi + i_bh * T * K, (K, T), (1, K), (\n i_k * BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gn = tl.max_contiguous(tl.multiple_of(gi + (i_bh * T + i_t *\n BT + i_i * BC) * K + o_k, BK), BK)\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K,\n 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_gq = tl.make_block_ptr(ge + (bos * H + i_h) * K, (T, K), (H *\n K, 1), (i_t * BT + i_i * BC, i_k * BK), (BC, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (K, T), (1, H *\n K), (i_k * BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gk = tl.make_block_ptr(gi + (bos * H + i_h) * K, (K, T), (1, \n H * K), (i_k * BK, i_t * BT + i_j * BC), (BK, BC), (0, 1))\n p_gn = tl.max_contiguous(tl.multiple_of(gi + (bos + i_t * BT + \n i_i * BC) * H * K + i_h * K + o_k, BK), BK)\n b_gn = tl.load(p_gn, mask=m_k, other=0)\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_gq = tl.load(p_gq, boundary_check=(0, 1))\n b_qg = b_q * tl.exp(b_gq - b_gn[None, :]) * scale\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_gk = tl.load(p_gk, boundary_check=(0, 1))\n b_kg = b_k * tl.exp(b_gn[:, None] - b_gk)\n b_A += tl.dot(b_qg, b_kg)\n if HEAD_FIRST:\n p_A = tl.make_block_ptr(A + i_bh * T * BT, (T, BT), (BT, 1), (i_t *\n BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n else:\n p_A = tl.make_block_ptr(A + (bos * H + i_h) * BT, (T, BT), (H * BT,\n 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n tl.store(p_A, b_A.to(A.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Recurrent Neural Networks", "Attention Mechanisms", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/chunk.py" }, { "uuid": "af45c3e7-e57c-45df-8d0a-061adf132ddc", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_sum/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES, BLOCK_SIZES, NUM_WARPS, NUM_STAGES)],\n key=['M'])\n@triton.jit\ndef triton_jagged_sum_kernel_variable_length_loop_buffer_then_sum(\n input_ptr_values, input_ptr_offsets, output_ptr, M, BLOCK_SIZE_RAGGED:\n tl.constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_ragged = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_ragged\n ), tl.load(input_ptr_offsets + (pid_ragged + 1))\n for block_start_ragged in range(ragged_start, ragged_end, BLOCK_SIZE_RAGGED\n ):\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n buffer += tl.load(input_ptr_values + idxs, mask=mask, other=0)\n buffer_sum = tl.sum(buffer, axis=0)\n buffer_view = buffer_sum.reshape((BLOCK_SIZE_M,))\n output_offsets = offsets_m + pid_ragged * M\n output_mask = output_offsets < M * (pid_ragged + 1)\n tl.store(output_ptr + output_offsets, buffer_view, mask=output_mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_sum/kernels.py" }, { "uuid": "7505340d-3573-43b3-becd-e287423981c1", "file_name": "triton_flash_attention.py", "repo_name": "IBM/vllm", "file_path": "vllm/attention/ops/triton_flash_attention.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef load_fn(block_ptr, first, second, pad):\n if first and second:\n tensor = tl.load(block_ptr, boundary_check=(0, 1), padding_option=pad)\n elif first:\n tensor = tl.load(block_ptr, boundary_check=(0,), padding_option=pad)\n elif second:\n tensor = tl.load(block_ptr, boundary_check=(1,), padding_option=pad)\n else:\n tensor = tl.load(block_ptr)\n return tensor\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/attention/ops/triton_flash_attention.py" }, { "uuid": "feab1add-a03a-45e1-9a8b-92ffbf911c83", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/based/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_based_fwd_kernel(q, k, v, o, z, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, scale, B: tl.constexpr, H: tl.constexpr, T: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BTL: tl.constexpr, BTS: tl.constexpr,\n BK: tl.constexpr, BV: tl.constexpr):\n i_kv, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n NV = tl.cdiv(V, BV)\n i_k = i_kv // NV\n i_v = i_kv % NV\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTL, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, 0), (BK, BTS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (0, \n i_v * BV), (BTS, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_o = tl.zeros([BTL, BV], dtype=tl.float32)\n b_z = tl.zeros([BTL], dtype=tl.float32)\n for _ in range(0, i_c * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = 1 + b_s + 0.5 * b_s * b_s\n b_z += tl.sum(b_s, axis=1)\n b_o = b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n p_k = tl.advance(p_k, (0, BTS))\n p_v = tl.advance(p_v, (BTS, 0))\n tl.debug_barrier()\n o_q = tl.arange(0, BTL)\n o_k = tl.arange(0, BTS)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, i_c * BTL), (BK, BTS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_c *\n BTL, i_v * BV), (BTS, BV), (1, 0))\n for _ in range(i_c * BTL, (i_c + 1) * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n m_s = o_q[:, None] >= o_k[None, :]\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = 1 + b_s + 0.5 * b_s * b_s\n b_s = tl.where(m_s, b_s, 0)\n b_z += tl.sum(b_s, axis=1)\n b_o += tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n p_k = tl.advance(p_k, (0, BTS))\n p_v = tl.advance(p_v, (BTS, 0))\n o_k += BTS\n p_o = tl.make_block_ptr(o + (i_bh + B * H * i_k) * s_v_h, (T, V), (\n s_v_t, s_v_d), (i_c * BTL, i_v * BV), (BTL, BV), (1, 0))\n p_z = z + (i_bh + B * H * i_k) * T + i_c * BTL + tl.arange(0, BTL)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_z, b_z.to(p_z.dtype.element_ty), mask=i_c * BTL + tl.arange(\n 0, BTL) < T)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/based/parallel.py" }, { "uuid": "84ed0301-81a1-45f6-b51b-ce832f2a056f", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8)], key=['BT', 'BK', 'BV'])\n@triton.jit\ndef chunk_simple_gla_bwd_kernel_dqkg(q, k, v, h, g, do, dh, dq, dk, dg,\n offsets, indices, scale, B: tl.constexpr, T: tl.constexpr, H: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BK: tl.\n constexpr, BV: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST: tl.\n constexpr):\n i_k, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n i_tg = i_t\n i_n, i_t = tl.load(indices + i_t * 2).to(tl.int32), tl.load(indices +\n i_t * 2 + 1).to(tl.int32)\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n all = T\n T = eos - bos\n NT = tl.cdiv(T, BT)\n else:\n NT = tl.cdiv(T, BT)\n i_tg = i_b * NT + i_t\n bos, eos = i_b * T, i_b * T + T\n all = B * T\n o_i = tl.arange(0, BT)\n if HEAD_FIRST:\n p_g = tl.make_block_ptr(g + i_bh * T, (T,), (1,), (i_t * BT,), (BT,\n ), (0,))\n b_g_last = tl.load(g + i_bh * T + min(i_t * BT + BT, T) - 1)\n else:\n p_g = tl.make_block_ptr(g + bos * H + i_h, (T,), (H,), (i_t * BT,),\n (BT,), (0,))\n b_g_last = tl.load(g + (bos + min(i_t * BT + BT, T) - 1) * H + i_h)\n b_g = tl.load(p_g, boundary_check=(0,))\n b_dq = tl.zeros([BT, BK], dtype=tl.float32)\n b_dk = tl.zeros([BT, BK], dtype=tl.float32)\n b_ds = tl.zeros([BT, BT], dtype=tl.float32)\n b_dg = tl.zeros([BT], dtype=tl.float32)\n b_dg_last = tl.zeros([1], dtype=tl.float32)\n for i_v in range(tl.cdiv(V, BV)):\n if HEAD_FIRST:\n p_v = tl.make_block_ptr(v + i_bh * T * V, (T, V), (V, 1), (i_t *\n BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * T * V, (T, V), (V, 1), (\n i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_bh * NT + i_t) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_bh * NT + i_t) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n else:\n p_v = tl.make_block_ptr(v + (bos * H + i_h) * V, (T, V), (H * V,\n 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_do = tl.make_block_ptr(do + (bos * H + i_h) * V, (T, V), (H *\n V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0))\n p_h = tl.make_block_ptr(h + (i_tg * H + i_h) * K * V, (V, K), (\n 1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n p_dh = tl.make_block_ptr(dh + (i_tg * H + i_h) * K * V, (V, K),\n (1, V), (i_v * BV, i_k * BK), (BV, BK), (0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_h = tl.load(p_h, boundary_check=(0, 1))\n b_dh = tl.load(p_dh, boundary_check=(0, 1))\n b_dg_last += tl.sum(b_h * b_dh)\n b_ds += tl.dot(b_do, tl.trans(b_v))\n b_dq += tl.dot(b_do, b_h.to(b_do.dtype))\n b_dk += tl.dot(b_v, b_dh.to(b_v.dtype))\n if HEAD_FIRST:\n p_q = tl.make_block_ptr(q + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * T * K, (T, K), (K, 1), (i_t * BT,\n i_k * BK), (BT, BK), (1, 0))\n p_dq = tl.make_block_ptr(dq + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + i_bh * T * K, (T, K), (K, 1), (i_t *\n BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + (i_k * B * H + i_bh) * T, (T,), (1,),\n (i_t * BT,), (BT,), (0,))\n else:\n p_q = tl.make_block_ptr(q + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_k = tl.make_block_ptr(k + (bos * H + i_h) * K, (T, K), (H * K, 1),\n (i_t * BT, i_k * BK), (BK, BT), (0, 1))\n p_dq = tl.make_block_ptr(dq + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dk = tl.make_block_ptr(dk + (bos * H + i_h) * K, (T, K), (H * K, \n 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0))\n p_dg = tl.make_block_ptr(dg + (i_k * all + bos) * H + i_h, (T,), (H\n ,), (i_t * BT,), (BT,), (0,))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_dg_last *= tl.exp(b_g_last)\n b_dq = b_dq * tl.exp(b_g)[:, None] * scale\n b_dk = b_dk * tl.exp(-b_g + b_g_last)[:, None]\n b_dg_last += tl.sum(b_dk * b_k)\n b_ds = tl.where(o_i[:, None] >= o_i[None, :], b_ds * scale * tl.exp(b_g\n [:, None] - b_g[None, :]), 0)\n b_ds = b_ds.to(b_k.dtype)\n b_dq += tl.dot(b_ds, b_k)\n b_dk += tl.dot(tl.trans(b_ds), b_q)\n b_dg += tl.sum(b_q * b_dq - b_k * b_dk, axis=1)\n b_dg = tl.where(o_i < min(BT, T - i_t * BT) - 1, b_dg, b_dg + b_dg_last)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_dg, b_dg.to(p_dg.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/chunk.py" }, { "uuid": "35265897-fe76-4437-a48d-a82641778823", "file_name": "hilbert.py", "repo_name": "Kitsunetic/space-filling-pytorch", "file_path": "space_filling_pytorch/functional/hilbert.py", "commit_hash": "0de955ad1036973ee7506c5a0124c208acec722d", "starcount": 0, "input": "@triton.jit\ndef _encode_hilbert_kernel(xyz_ptr, code_ptr, B, N, space_size, x_offset,\n y_offset, z_offset, str_xyz_B, str_xyz_N, str_xyz_C, BLK: tl.constexpr,\n ASSIGN_BATCH_INDEX: tl.constexpr):\n pid_b = tl.program_id(0)\n pid_n = tl.program_id(1)\n offs_n = pid_n * BLK + tl.arange(0, BLK)\n mask_n = offs_n < N\n xyz_ptrs = xyz_ptr + pid_b * str_xyz_B + offs_n * str_xyz_N\n fx = tl.load(xyz_ptrs + x_offset * str_xyz_C, mask=mask_n)\n fy = tl.load(xyz_ptrs + y_offset * str_xyz_C, mask=mask_n)\n fz = tl.load(xyz_ptrs + z_offset * str_xyz_C, mask=mask_n)\n ret = _calculate_hilbert_distance(fx, fy, fz, space_size)\n if ASSIGN_BATCH_INDEX:\n ret |= pid_b.to(tl.int64) << 48\n tl.store(code_ptr + pid_b * N + offs_n, ret, mask=mask_n)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Kitsunetic/space-filling-pytorch/blob/0de955ad1036973ee7506c5a0124c208acec722d/space_filling_pytorch/functional/hilbert.py" }, { "uuid": "f7e0aaee-d0e9-4cb0-8788-587e3a9bf44c", "file_name": "triton_flash_attention.py", "repo_name": "IBM/vllm", "file_path": "vllm/attention/ops/triton_flash_attention.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr, V_block_ptr, start_m,\n actual_seqlen_k, dropout_p, philox_seed, batch_philox_offset,\n encoded_softmax_block_ptr, block_min, block_max, offs_n_causal,\n masked_blocks, n_extra_tokens, bias_ptr, IS_CAUSAL: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.\n constexpr, OFFS_M: tl.constexpr, OFFS_N: tl.constexpr, PRE_LOAD_V: tl.\n constexpr, MASK_STEPS: tl.constexpr, ENABLE_DROPOUT: tl.constexpr,\n RETURN_ENCODED_SOFTMAX: tl.constexpr, PADDED_HEAD: tl.constexpr):\n for start_n in range(block_min, block_max, BLOCK_N):\n k = load_fn(K_block_ptr, PADDED_HEAD, MASK_STEPS and n_extra_tokens !=\n 0, 'zero')\n if PRE_LOAD_V:\n v = load_fn(V_block_ptr, MASK_STEPS and n_extra_tokens != 0,\n PADDED_HEAD, 'zero')\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n if MASK_STEPS:\n if start_n + BLOCK_N == block_max and n_extra_tokens != 0:\n boundary_m = tl.full([BLOCK_M], actual_seqlen_k, dtype=tl.int32\n )\n size_n = start_n + OFFS_N[None, :]\n mask = size_n < boundary_m[:, None]\n qk = tl.where(mask, qk, float('-inf'))\n if IS_CAUSAL:\n causal_boundary = start_n + offs_n_causal\n causal_mask = OFFS_M[:, None] >= causal_boundary[None, :]\n qk = tl.where(causal_mask, qk, float('-inf'))\n qk += tl.dot(q, k)\n if bias_ptr is not None:\n bias = load_fn(bias_ptr, False, MASK_STEPS and n_extra_tokens !=\n 0, 'zero')\n qk += bias * 1.44269504089\n m_ij = tl.maximum(m_i, tl.max(qk, 1))\n qk = qk - m_ij[:, None]\n p = tl.math.exp2(qk)\n l_ij = tl.sum(p, 1)\n if ENABLE_DROPOUT:\n philox_offset = (batch_philox_offset + start_m * BLOCK_M *\n actual_seqlen_k + start_n - BLOCK_N)\n keep = dropout_mask(philox_seed, philox_offset, dropout_p,\n BLOCK_M, BLOCK_N, actual_seqlen_k)\n if RETURN_ENCODED_SOFTMAX:\n tl.store(encoded_softmax_block_ptr, tl.where(keep, p, -p).\n to(encoded_softmax_block_ptr.type.element_ty))\n p = tl.where(keep, p, 0.0)\n elif RETURN_ENCODED_SOFTMAX:\n tl.store(encoded_softmax_block_ptr, p.to(\n encoded_softmax_block_ptr.type.element_ty))\n alpha = tl.math.exp2(m_i - m_ij)\n acc = acc * alpha[:, None]\n if not PRE_LOAD_V:\n v = load_fn(V_block_ptr, MASK_STEPS and n_extra_tokens != 0,\n PADDED_HEAD, 'zero')\n l_i = l_i * alpha + l_ij\n m_i = m_ij\n acc += tl.dot(p.to(V_block_ptr.type.element_ty), v)\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n if bias_ptr is not None:\n bias_ptr = tl.advance(bias_ptr, (0, BLOCK_N))\n if RETURN_ENCODED_SOFTMAX:\n encoded_softmax_block_ptr = tl.advance(encoded_softmax_block_ptr,\n (0, BLOCK_N))\n return acc, l_i, m_i\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/attention/ops/triton_flash_attention.py" }, { "uuid": "49a964a1-bf73-4726-98df-82a3e693bd2f", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=MATMUL_CONFIGS + [Config({'BLOCK_M': 128,\n 'BLOCK_N': 128, 'BLOCK_K': 128, 'SPLIT_K': 1}, num_stages=3, num_warps=\n 8)], key=['m_key', 'n_key', 'k_key'])\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.jit\ndef _kernel_matmul_fp8_row_no_fast_acc(A_ptr, B_ptr, C_ptr, M, N, K, m_key,\n n_key, k_key, A_scale, B_scale, Bias, stride_am, stride_ak, stride_bn,\n stride_bk, stride_cm, stride_cn, dot_out_dtype: tl.constexpr,\n allow_tf32: tl.constexpr, fp8_fast_accum: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.\n constexpr, SPLIT_K: tl.constexpr, EVEN_K: tl.constexpr, USE_BIAS: tl.\n constexpr, AB_DTYPE: tl.constexpr, NUM_SMS: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with row-wise scales\n\n performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles.\n\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n m_key (int): Autotuning key for M dimension of input tensor.\n n_key (int): Autotuning key for N dimension of input tensor.\n k_key (int): Autotuning key for K dimension of input tensor.\n A_scale (TensorWrapper): [M] reciprocal scale tensor per row. A * A_scale = original A\n B_scale (TensorWrapper): [N] reciprocal scale tensor per row. B * B_scale = original B\n Bias (TensorWrapper): [N] Optional bias tensor.\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n USE_BIAS(bool): Whether to use bias.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n start_pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_M)\n num_pid_n = tl.cdiv(N, BLOCK_N)\n k_tiles = tl.cdiv(K, BLOCK_K)\n num_tiles = num_pid_m * num_pid_n\n tiles_per_SM = num_tiles // NUM_SMS\n if start_pid < num_tiles % NUM_SMS:\n tiles_per_SM += 1\n tile_id = start_pid - NUM_SMS\n ki = -1\n offs_k_for_mask = tl.arange(0, BLOCK_K)\n num_pid_in_group = GROUP_M * num_pid_n\n pid_m = 0\n pid_n = 0\n offs_am = tl.arange(0, BLOCK_M)\n offs_bn = tl.arange(0, BLOCK_N)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n for _ in range(0, k_tiles * tiles_per_SM):\n ki = tl.where(ki == k_tiles - 1, 0, ki + 1)\n if ki == 0:\n tile_id += NUM_SMS\n group_id = tile_id // num_pid_in_group\n first_pid_m = group_id * GROUP_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_M)\n pid_m = first_pid_m + tile_id % group_size_m\n pid_n = tile_id % num_pid_in_group // group_size_m\n start_m = pid_m * BLOCK_M\n start_n = pid_n * BLOCK_N\n offs_am = start_m + tl.arange(0, BLOCK_M)\n offs_bn = start_n + tl.arange(0, BLOCK_N)\n offs_am = tl.where(offs_am < M, offs_am, 0)\n offs_bn = tl.where(offs_bn < N, offs_bn, 0)\n offs_am = tl.max_contiguous(tl.multiple_of(offs_am, BLOCK_M),\n BLOCK_M)\n offs_bn = tl.max_contiguous(tl.multiple_of(offs_bn, BLOCK_N),\n BLOCK_N)\n offs_k = ki * BLOCK_K + tl.arange(0, BLOCK_K)\n A = A_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] * stride_ak\n )\n B = B_ptr + (offs_k[:, None] * stride_bk + offs_bn[None, :] * stride_bn\n )\n a = tl.load(A, mask=offs_k_for_mask[None, :] < K - ki * BLOCK_K,\n other=0.0)\n b = tl.load(B, mask=offs_k_for_mask[:, None] < K - ki * BLOCK_K,\n other=0.0)\n acc += tl.dot(a, b, out_dtype=dot_out_dtype, allow_tf32=allow_tf32)\n if ki == k_tiles - 1:\n rm = pid_m * BLOCK_M + tl.arange(0, BLOCK_M)\n rn = pid_n * BLOCK_N + tl.arange(0, BLOCK_N)\n a_scale = tl.load(A_scale + rm, mask=rm < M)\n b_scale = tl.load(B_scale + rn, mask=rn < N)\n scale = a_scale[:, None] * b_scale[None, :]\n acc *= scale\n if USE_BIAS:\n bias = tl.load(Bias + rn, mask=rn < N)\n acc += bias[None, :]\n acc = acc.to(C_ptr.dtype.element_ty)\n C = C_ptr + (rm[:, None] * stride_cm + rn[None, :] * stride_cn)\n mask = (rm < M)[:, None] & (rn < N)[None, :]\n tl.store(C, acc, mask=mask)\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "1c6094ba-7870-44ef-a8cd-0333dd051641", "file_name": "activations.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/modules/activations.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4), triton.Config({},\n num_warps=8), triton.Config({}, num_warps=16), triton.Config({},\n num_warps=32)], key=['D'])\n@triton.jit\ndef logsigmoid_fwd_kernel(x, y, temperature, T: tl.constexpr, D: tl.\n constexpr, B: tl.constexpr):\n i = tl.program_id(0)\n o_i = i * B + tl.arange(0, B)\n m_i = o_i < T\n b_x = tl.load(x + o_i, mask=m_i, other=0.0).to(tl.float32)\n b_m = tl.minimum(0.0, b_x)\n b_z = 1.0 + tl.exp(-tl.abs(b_x))\n b_y = (b_m - tl.log(b_z)) / temperature\n tl.store(y + o_i, b_y.to(y.dtype.element_ty), mask=m_i)\n", "category": { "Functionality": [ "Activation Functions" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/modules/activations.py" }, { "uuid": "7de4e638-bcf1-4f0d-ae73-3e9eb9ad0241", "file_name": "transposable_semi_structured.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/transposable_semi_structured.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.jit\ndef _to_transposable_sparse_semi_structured_kernel(dense_ptr, sparse_ptr,\n mask_raw_ptr, mask_ptr, dense_row_stride, dense_col_stride,\n sparse_row_stride, sparse_col_stride, mask_raw_row_stride,\n mask_raw_col_stride, mask_row_stride, mask_col_stride, m, k, n, abs,\n BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0) * 32 + (tl.arange(0, 128) // 16 * 4)[None, :\n ] + (tl.arange(0, 16) // 4)[:, None]\n col_idx = tl.program_id(1) * 64 + (tl.arange(0, 128) % 16 * 4)[None, :] + (\n tl.arange(0, 16) % 4)[:, None]\n dense = tl.load(dense_ptr + row_idx * dense_row_stride + col_idx *\n dense_col_stride)\n mask_raw = tl.load(mask_raw_ptr + tl.arange(0, 16)[None, :] *\n mask_raw_col_stride + tl.arange(0, BLOCK_SIZE)[:, None] *\n mask_raw_row_stride, mask=tl.arange(0, BLOCK_SIZE)[:, None] < n,\n other=0)\n sum = tl.dot(mask_raw, tl.abs(dense)) if abs else tl.dot(mask_raw, dense)\n sum = tl.where(tl.arange(0, BLOCK_SIZE)[:, None] < n, sum, -float('inf'))\n max = tl.argmax(sum, 0)\n mask_idx = max[None, :] * 16 + tl.arange(0, 16)[:, None]\n mask = tl.load(mask_raw_ptr + mask_idx).to(tl.int1)\n tl.store(sparse_ptr + row_idx * sparse_row_stride + col_idx *\n sparse_col_stride, dense, mask=mask)\n tl.store(mask_ptr + row_idx * mask_row_stride + col_idx *\n mask_col_stride, mask)\n", "category": { "Functionality": [ "Top-K Selection", "Elementwise Operations" ], "Data Type": [], "Performance Objective": [ "Compute Bound", "Memory-Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Blocked Access", "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/transposable_semi_structured.py" }, { "uuid": "7b3ef975-67fb-4aaf-98b2-e7dc5ae1976a", "file_name": "prefix_prefill.py", "repo_name": "IBM/vllm", "file_path": "vllm/attention/ops/prefix_prefill.py", "commit_hash": "99523dd62be2ecf6c6db15e8133aaaf7855e7e86", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel_flash_attn_v2(Q, K, V, K_cache, V_cache, B_Loc, sm_scale,\n B_Start_Loc, B_Seqlen, B_Ctxlen, block_size, x, Out, stride_b_loc_b,\n stride_b_loc_s, stride_qbs, stride_qh, stride_qd, stride_kbs, stride_kh,\n stride_kd, stride_vbs, stride_vh, stride_vd, stride_obs, stride_oh,\n stride_od, stride_k_cache_bs, stride_k_cache_h, stride_k_cache_d,\n stride_k_cache_bl, stride_k_cache_x, stride_v_cache_bs,\n stride_v_cache_h, stride_v_cache_d, stride_v_cache_bl,\n num_queries_per_kv: int, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.\n constexpr, BLOCK_N: tl.constexpr):\n cur_batch = tl.program_id(0)\n cur_head = tl.program_id(1)\n start_m = tl.program_id(2)\n cur_kv_head = cur_head // num_queries_per_kv\n cur_batch_ctx_len = tl.load(B_Ctxlen + cur_batch)\n cur_batch_seq_len = tl.load(B_Seqlen + cur_batch)\n cur_batch_in_all_start_index = tl.load(B_Start_Loc + cur_batch)\n block_start_loc = BLOCK_M * start_m\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_DMODEL)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n off_q = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_qbs + cur_head * stride_qh + offs_d[None, :] * stride_qd\n q = tl.load(Q + off_q, mask=offs_m[:, None] < cur_batch_seq_len -\n cur_batch_ctx_len, other=0.0)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n for start_n in range(0, cur_batch_ctx_len, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n bn = tl.load(B_Loc + cur_batch * stride_b_loc_b + (start_n + offs_n\n ) // block_size * stride_b_loc_s, mask=start_n + offs_n <\n cur_batch_ctx_len, other=0)\n off_k = bn[None, :\n ] * stride_k_cache_bs + cur_kv_head * stride_k_cache_h + offs_d[\n :, None] // x * stride_k_cache_d + (start_n + offs_n[None, :]\n ) % block_size * stride_k_cache_bl + offs_d[:, None\n ] % x * stride_k_cache_x\n off_v = bn[:, None\n ] * stride_v_cache_bs + cur_kv_head * stride_v_cache_h + offs_d[\n None, :] * stride_v_cache_d + (start_n + offs_n[:, None]\n ) % block_size * stride_v_cache_bl\n k = tl.load(K_cache + off_k, mask=start_n + offs_n[None, :] <\n cur_batch_ctx_len, other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n qk = tl.where(start_n + offs_n[None, :] < cur_batch_ctx_len, qk,\n float('-inf'))\n qk *= sm_scale\n m_ij = tl.max(qk, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n p = tl.math.exp(qk - m_i_new[:, None])\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp(m_i - m_i_new)\n l_i_new = alpha * l_i + l_ij\n acc_scale = alpha\n acc = acc * acc_scale[:, None]\n v = tl.load(V_cache + off_v, mask=start_n + offs_n[:, None] <\n cur_batch_ctx_len, other=0.0)\n p = p.to(v.dtype)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n off_k = offs_n[None, :] * stride_kbs + cur_kv_head * stride_kh + offs_d[\n :, None] * stride_kd\n off_v = offs_n[:, None] * stride_vbs + cur_kv_head * stride_vh + offs_d[\n None, :] * stride_vd\n k_ptrs = K + off_k\n v_ptrs = V + off_v\n block_mask = tl.where(block_start_loc < cur_batch_seq_len -\n cur_batch_ctx_len, 1, 0)\n for start_n in range(0, block_mask * (start_m + 1) * BLOCK_M, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n k = tl.load(k_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_kbs, mask=start_n + offs_n[None, :] < cur_batch_seq_len -\n cur_batch_ctx_len, other=0.0)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, k)\n qk *= sm_scale\n qk = tl.where(offs_m[:, None] >= start_n + offs_n[None, :], qk,\n float('-inf'))\n m_ij = tl.max(qk, 1)\n m_i_new = tl.maximum(m_i, m_ij)\n p = tl.math.exp(qk - m_i_new[:, None])\n l_ij = tl.sum(p, 1)\n alpha = tl.math.exp(m_i - m_i_new)\n l_i_new = alpha * l_i + l_ij\n acc_scale = alpha\n acc = acc * acc_scale[:, None]\n v = tl.load(v_ptrs + (cur_batch_in_all_start_index + start_n) *\n stride_vbs, mask=start_n + offs_n[:, None] < cur_batch_seq_len -\n cur_batch_ctx_len, other=0.0)\n p = p.to(v.dtype)\n acc += tl.dot(p, v)\n l_i = l_i_new\n m_i = m_i_new\n off_o = (cur_batch_in_all_start_index + offs_m[:, None]\n ) * stride_obs + cur_head * stride_oh + offs_d[None, :] * stride_od\n out_ptrs = Out + off_o\n tl.store(out_ptrs, acc, mask=offs_m[:, None] < cur_batch_seq_len -\n cur_batch_ctx_len)\n return\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IBM/vllm/blob/99523dd62be2ecf6c6db15e8133aaaf7855e7e86/vllm/attention/ops/prefix_prefill.py" }, { "uuid": "6d49d736-8ea9-4cd8-ba62-bcb2f44902ea", "file_name": "chunk.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/abc/chunk.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef chunk_abc_bwd_kernel_intra_K(v, z, do, dA, s_v_h, s_v_t, s_v_d, scale,\n T: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BC: tl.constexpr,\n BV: tl.constexpr, NC: tl.constexpr):\n i_v, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_t, i_i, i_j = i_c // (NC * NC), i_c % (NC * NC) // NC, i_c % (NC * NC\n ) % NC\n n_bh = tl.num_programs(2)\n if i_i > i_j:\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (V, T), (s_v_d, s_v_t), (\n i_v * BV, i_t * BT + i_j * BC), (BV, BC), (0, 1))\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_zn = tl.make_block_ptr(z + i_bh * s_v_h, (T * V,), (s_v_d,), ((\n i_t * BT + i_i * BC) * V + i_v * BV,), (BV,), (0,))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_dA = tl.make_block_ptr(dA + (i_bh + i_v * n_bh) * T * BT, (T, BT),\n (BT, 1), (i_t * BT + i_i * BC, i_j * BC), (BC, BC), (1, 0))\n b_zn = tl.load(p_zn, boundary_check=(0,))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1))\n b_do = (b_do * tl.exp(b_zn[None, :] - b_z) * scale).to(b_do.dtype)\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_v = tl.exp(b_v - b_zn[:, None]).to(b_v.dtype)\n b_dA = tl.dot(b_do, b_v, allow_tf32=False)\n tl.store(p_dA, b_dA.to(dA.dtype.element_ty), boundary_check=(0, 1))\n elif i_i == i_j:\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T * V,), (s_v_d,), ((i_t *\n BT + i_j * BC) * V + i_v * BV,), (BV,), (0,))\n p_z = tl.make_block_ptr(z + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (\n i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n p_do = tl.make_block_ptr(do + i_bh * s_v_h, (T, V), (s_v_t, s_v_d),\n (i_t * BT + i_i * BC, i_v * BV), (BC, BV), (1, 0))\n b_z = tl.load(p_z, boundary_check=(0, 1))\n b_do = tl.load(p_do, boundary_check=(0, 1)) * scale\n o_i = tl.arange(0, BC)\n o_A = (i_bh + i_v * n_bh) * T * BT + (i_t * BT + i_i * BC + tl.\n arange(0, BC)) * BT + i_j * BC\n m_A = i_t * BT + i_i * BC + tl.arange(0, BC) < T\n for j in range(0, BC):\n b_v = tl.load(p_v, boundary_check=(0,)).to(tl.float32)\n b_dA = tl.sum(b_do * tl.exp(b_v[None, :] - b_z), 1)\n b_dA = tl.where(o_i >= j, b_dA, 0)\n tl.store(dA + o_A + j, b_dA.to(b_do.dtype), mask=m_A)\n p_v = tl.advance(p_v, (V,))\n", "category": { "Functionality": [ "Backpropagation", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/abc/chunk.py" }, { "uuid": "abbc7553-4ca9-4830-a5ff-405e42b5cd6b", "file_name": "rwkv_log.py", "repo_name": "berlino/seq_icl", "file_path": "src/models/sequence/rnn/scan_triton/rwkv_log.py", "commit_hash": "9b9223d15348b5a415fb453ed988ed5f7ab9fbdc", "starcount": 0, "input": "@triton.jit\ndef logsubexp(a, b, log_eps: tl.constexpr):\n max_ab = tl.maximum(tl.maximum(a, b), log_eps)\n return max_ab + tl.log(tl.exp(a - max_ab) - tl.exp(b - max_ab))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Low Latency" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/berlino/seq_icl/blob/9b9223d15348b5a415fb453ed988ed5f7ab9fbdc/src/models/sequence/rnn/scan_triton/rwkv_log.py" }, { "uuid": "a1e6cbbe-2b59-4e14-81c5-dd969b3c4059", "file_name": "triton_fused_attention.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/kernels/triton_fused_attention.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(list(filter(keep, configsTmaWSPersistent)), key=['N_CTX'])\n@triton.jit\ndef _attn_fwd_tma_ws_persistent(Q, K, V, sm_scale, M, Out, desc_q, desc_k,\n desc_v, desc_o, stride_qz, stride_qh, stride_qm, stride_qk, stride_kz,\n stride_kh, stride_kn, stride_kk, stride_vz, stride_vh, stride_vk,\n stride_vn, stride_oz, stride_oh, stride_om, stride_on, Z, H, N_CTX,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr, HEAD_DIM: tl.constexpr,\n STAGE: tl.constexpr, ENABLE_TMA: tl.constexpr, LOOP_SCHEDULE: tl.\n constexpr, ENABLE_WS: tl.constexpr, GRID_MULTIPLE: tl.constexpr):\n tl.static_assert(BLOCK_N <= HEAD_DIM)\n n_tile_num = tl.cdiv(N_CTX, BLOCK_M)\n prog_id = tl.program_id(0)\n num_progs = tl.num_programs(0)\n total_tiles = n_tile_num * Z * H\n tiles_per_sm = total_tiles // num_progs\n if prog_id < total_tiles % num_progs:\n tiles_per_sm += 1\n tile_idx = prog_id\n for _ in range(0, tiles_per_sm):\n pid = tile_idx % n_tile_num\n off_hz = tile_idx // n_tile_num\n _attn_fwd_compute_ws(Q, K, V, sm_scale, M, Out, desc_q, desc_k,\n desc_v, desc_o, stride_qz, stride_qh, stride_qm, stride_qk,\n stride_kz, stride_kh, stride_kn, stride_kk, stride_vz,\n stride_vh, stride_vk, stride_vn, stride_oz, stride_oh,\n stride_om, stride_on, off_hz, pid, Z, H, N_CTX, BLOCK_M,\n BLOCK_N, HEAD_DIM, STAGE, ENABLE_TMA, LOOP_SCHEDULE)\n tile_idx += num_progs\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/kernels/triton_fused_attention.py" }, { "uuid": "4e993c1c-6857-48f0-95ea-0de66ed768a8", "file_name": "avgpool.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/avgpool.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _AvgPoolCeilStats_cl3d_backward_impl(Inpgrad_ptr, Outgrad_ptr,\n Output_ptr, Meangrad_ptr, Sqmeangrad_ptr, h_outgrad, w_outgrad,\n d_outgrad, d_inpgrad, batch_stride_outgrad, H_stride_outgrad,\n W_stride_outgrad, batch_stride_inpgrad, H_stride_inpgrad,\n W_stride_inpgrad, numel_no_channels_inpgrad, num_channels: tl.constexpr,\n almost_half_d: tl.constexpr):\n batch = tl.program_id(0)\n H = tl.program_id(1)\n W = tl.program_id(2)\n Inpgrad_ptr += (batch * batch_stride_inpgrad + H * H_stride_inpgrad + W *\n W_stride_inpgrad)\n Output_ptr += (batch * batch_stride_inpgrad + H * H_stride_inpgrad + W *\n W_stride_inpgrad)\n pair_offset = tl.arange(0, 2)\n channels_offset = tl.arange(0, num_channels)\n d_offset = tl.arange(0, almost_half_d)\n inpgrad_offset = d_offset[:, None, None] * num_channels + channels_offset[\n None, :, None]\n outgrad_offset = d_offset[:, None, None] * (2 * num_channels\n ) + channels_offset[None, :, None] + pair_offset[None, None, :\n ] * num_channels\n inpgrad_mask = d_offset[:, None, None] < d_inpgrad\n outgrad_mask = d_offset[:, None, None] * 2 + pair_offset[None, None, :\n ] < d_outgrad\n inpgrad = tl.load(Inpgrad_ptr + inpgrad_offset, mask=inpgrad_mask,\n other=0.0)\n output = tl.load(Output_ptr + inpgrad_offset, mask=inpgrad_mask, other=0.0)\n meangrad = tl.load(Meangrad_ptr + channels_offset)[None, :, None]\n sqmeangrad = tl.load(Sqmeangrad_ptr + channels_offset)[None, :, None]\n normalizer = tl.sum(outgrad_mask.to(tl.float16), axis=2)[:, :, None].to(tl\n .float16)\n W_skip = False\n if 2 * (W + 1) > w_outgrad:\n W_skip = True\n else:\n normalizer *= 2\n H_skip = False\n if 2 * (H + 1) > h_outgrad:\n H_skip = True\n else:\n normalizer *= 2\n meangrad = meangrad / numel_no_channels_inpgrad\n sqmeangrad = 2 * output.to(tl.float32\n ) * sqmeangrad / numel_no_channels_inpgrad\n grad = (inpgrad + meangrad + sqmeangrad) / normalizer\n Tmp_ptr = (Outgrad_ptr + batch * batch_stride_outgrad + 2 * H *\n H_stride_outgrad + 2 * W * W_stride_outgrad)\n tl.store(Tmp_ptr + outgrad_offset, grad, mask=outgrad_mask)\n if not W_skip:\n Tmp_ptr = (Outgrad_ptr + batch * batch_stride_outgrad + 2 * H *\n H_stride_outgrad + (2 * W + 1) * W_stride_outgrad)\n tl.store(Tmp_ptr + outgrad_offset, grad, mask=outgrad_mask)\n if not H_skip:\n Tmp_ptr = Outgrad_ptr + batch * batch_stride_outgrad + (2 * H + 1\n ) * H_stride_outgrad + 2 * W * W_stride_outgrad\n tl.store(Tmp_ptr + outgrad_offset, grad, mask=outgrad_mask)\n if not H_skip and not W_skip:\n Tmp_ptr = Outgrad_ptr + batch * batch_stride_outgrad + (2 * H + 1\n ) * H_stride_outgrad + (2 * W + 1) * W_stride_outgrad\n tl.store(Tmp_ptr + outgrad_offset, grad, mask=outgrad_mask)\n", "category": { "Functionality": [ "Backpropagation" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/avgpool.py" }, { "uuid": "d2863f4d-a943-457c-8fe8-8bab49d63b2d", "file_name": "chunk_h_parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/common/chunk_h_parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'STORE_FINAL_STATE': lambda args: args['ht'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BK': BK, 'BV': BV}, num_warps=\n num_warps, num_stages=num_stages) for BK in [32, 64, 128] for BV in [32,\n 64, 128] for num_warps in [2, 4, 8, 16] for num_stages in [2, 3]], key=\n ['BT', 'USE_G', 'USE_GK', 'USE_GV'])\n@triton.jit\ndef chunk_fwd_kernel_h_reduction(h, g, gk, gv, kvt, ht, offsets,\n chunk_offsets, T: tl.constexpr, H: tl.constexpr, K: tl.constexpr, V: tl\n .constexpr, BT: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr, USE_G:\n tl.constexpr, USE_GK: tl.constexpr, USE_GV: tl.constexpr,\n STORE_FINAL_STATE: tl.constexpr, USE_OFFSETS: tl.constexpr, HEAD_FIRST:\n tl.constexpr):\n i_k, i_v, i_nh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int32), tl.load(offsets +\n i_n + 1).to(tl.int32)\n T = eos - bos\n NT = tl.cdiv(T, BT)\n boh = tl.load(chunk_offsets + i_n).to(tl.int32)\n else:\n bos, eos = i_n * T, i_n * T + T\n NT = tl.cdiv(T, BT)\n boh = i_n * NT\n b_h = tl.zeros([BK, BV], dtype=tl.float32)\n for i_t in range(NT):\n if HEAD_FIRST:\n p_h = tl.make_block_ptr(h + (i_nh * NT + i_t) * K * V, (K, V),\n (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n else:\n p_h = tl.make_block_ptr(h + ((boh + i_t) * H + i_h) * K * V, (K,\n V), (V, 1), (i_k * BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_h, boundary_check=(0, 1)).to(tl.float32)\n if i_t > 0:\n tl.store(p_h, b_h.to(p_h.dtype.element_ty), boundary_check=(0, 1))\n last_idx = min(i_t * BT + BT, T) - 1\n if USE_G:\n if HEAD_FIRST:\n b_g_last = tl.load(g + i_nh * T + last_idx)\n else:\n b_g_last = tl.load(g + bos * H + last_idx * H + i_h)\n b_h *= tl.exp(b_g_last)\n if USE_GK:\n if HEAD_FIRST:\n p_gk_last = (gk + i_nh * T * K + last_idx * K + i_k * BK +\n tl.arange(0, BK))\n else:\n p_gk_last = gk + (bos + last_idx\n ) * H * K + i_h * K + i_k * BK + tl.arange(0, BK)\n p_gk_last = tl.max_contiguous(tl.multiple_of(p_gk_last, BK), BK)\n b_gk_last = tl.load(p_gk_last, mask=i_k * BK + tl.arange(0, BK) <\n K, other=0.0)\n b_h *= tl.exp(b_gk_last)[:, None]\n if USE_GV:\n if HEAD_FIRST:\n p_gv_last = (gv + i_nh * T * V + last_idx * V + i_v * BV +\n tl.arange(0, BV))\n else:\n p_gv_last = gv + (bos + last_idx\n ) * H * V + i_h * V + i_v * BV + tl.arange(0, BV)\n p_gv_last = tl.max_contiguous(tl.multiple_of(p_gv_last, BV), BV)\n b_gv_last = tl.load(p_gv_last, mask=i_v * BV + tl.arange(0, BV) <\n V, other=0.0)\n b_h *= tl.exp(b_gv_last)[None, :]\n if STORE_FINAL_STATE:\n p_kvt = tl.make_block_ptr(kvt + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n p_ht = tl.make_block_ptr(ht + i_nh * K * V, (K, V), (V, 1), (i_k *\n BK, i_v * BV), (BK, BV), (1, 0))\n b_h += tl.load(p_kvt, boundary_check=(0, 1)).to(tl.float32)\n tl.store(p_ht, b_h.to(p_ht.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/common/chunk_h_parallel.py" }, { "uuid": "e88a9daf-61e9-4aae-bbd8-4d5f74361199", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/simple_gla/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'NV': lambda args: triton.cdiv(args['V'], args['BV'])})\n@triton.jit\ndef parallel_simple_gla_bwd_kernel(q, k, v, g, do, dq, dk, dv, dg, s_k_h,\n s_k_t, s_v_h, s_v_t, scale, B: tl.constexpr, H: tl.constexpr, T: tl.\n constexpr, K: tl.constexpr, V: tl.constexpr, BT: tl.constexpr, BS: tl.\n constexpr, BK: tl.constexpr, BV: tl.constexpr, NV: tl.constexpr):\n i_kv, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n i_k, i_v = i_kv // NV, i_kv % NV\n parallel_simple_gla_bwd_kernel_dq(i_bh, i_t, i_k, i_v, i_kv, q, k, v, g,\n do, dq, dg, s_k_h, s_k_t, s_v_h, s_v_t, scale, B=B, H=H, T=T, K=K,\n V=V, BT=BT, BS=BS, BK=BK, BV=BV)\n tl.debug_barrier()\n parallel_simple_gla_bwd_kernel_dkv(i_bh, i_t, i_k, i_v, i_kv, q, k, v,\n g, do, dk, dv, dg, s_k_h, s_k_t, s_v_h, s_v_t, scale, B, H, T, K, V,\n BT, BS, BK, BV)\n", "category": { "Functionality": [ "Backpropagation", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/simple_gla/parallel.py" }, { "uuid": "ba44918d-689f-49fc-8bc9-8cd9eb5ecc57", "file_name": "gelu_and_mul.py", "repo_name": "tascj/kaggle-lmsys-chatbot-arena", "file_path": "human_pref/inference/ops/gelu_and_mul.py", "commit_hash": "83cd93d50b9283c18711e8c63e4e1c6399c7b9ce", "starcount": 0, "input": "@triton.jit\ndef _gelu_and_mul_kernel(input_ptr, stride_input_m, stride_input_n,\n stride_output_m, stride_output_n, size_m, size_n, BLOCK_M: tl.constexpr,\n BLOCK_N: tl.constexpr):\n tid = tl.program_id(0)\n input_m_offsets = tid * BLOCK_M + tl.arange(0, BLOCK_M)\n output_m_offsets = tid * BLOCK_M + tl.arange(0, BLOCK_M)\n pid = tl.program_id(1)\n input_n_offsets = pid * BLOCK_N + tl.arange(0, BLOCK_N)\n output_n_offsets = pid * BLOCK_N + tl.arange(0, BLOCK_N)\n up_offsets = input_m_offsets[:, None] * stride_input_m + (input_n_offsets\n [None, :] + size_n) * stride_input_n\n gate_offsets = input_m_offsets[:, None] * stride_input_m + input_n_offsets[\n None, :] * stride_input_n\n res_offsets = output_m_offsets[:, None\n ] * stride_output_m + output_n_offsets[None, :] * stride_output_n\n up = tl.load(input_ptr + up_offsets, mask=(input_n_offsets < size_n)[\n None, :] * (input_m_offsets < size_m)[:, None], other=0.0)\n gate = tl.load(input_ptr + gate_offsets, mask=(input_n_offsets < size_n\n )[None, :] * (input_m_offsets < size_m)[:, None], other=0.0).to(tl.\n float32)\n gate = gelu(gate)\n gate = gate.to(input_ptr.dtype.element_ty)\n tl.store(input_ptr + res_offsets, up * gate, mask=(output_n_offsets <\n size_n)[None, :] * (output_m_offsets < size_m)[:, None])\n", "category": { "Functionality": [ "Activation Functions", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [], "Parallelization Strategy": [], "Memory Access Pattern": [] }, "licenses": [ "Apache" ], "github_url": "https://github.com/tascj/kaggle-lmsys-chatbot-arena/blob/83cd93d50b9283c18711e8c63e4e1c6399c7b9ce/human_pref/inference/ops/gelu_and_mul.py" }, { "uuid": "db060ba9-fe89-418b-807d-5beda14cd648", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/delta_rule/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'OUTPUT_ATTENTIONS': lambda args: args['attn'] is not None}\n )\n@triton.jit\ndef parallel_delta_rule_fwd_kernel(q, k, k2, v, beta, o, o_new, attn, s_k_h,\n s_k_t, s_v_h, s_v_t, T: tl.constexpr, K: tl.constexpr, V: tl.constexpr,\n BT: tl.constexpr, BS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n OUTPUT_ATTENTIONS: tl.constexpr):\n i_t, i_bh = tl.program_id(0), tl.program_id(1)\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, 1), (i_t * BT,\n 0), (BT, BK), (1, 0))\n b_q = tl.zeros([BT, BK], dtype=tl.float32)\n b_q += tl.load(p_q, boundary_check=(0, 1))\n b_o = tl.zeros([BT, BV], dtype=tl.float32)\n p_o = tl.make_block_ptr(o + i_bh * s_v_h, (T, V), (s_v_t, 1), (i_t * BT,\n 0), (BT, BV), (1, 0))\n b_o += tl.load(p_o, boundary_check=(0, 1))\n for offset in range((i_t + 1) * BT - 2 * BS, i_t * BT - BS, -BS):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (1, s_k_t), (0,\n offset), (BK, BS), (0, 1))\n p_k2 = tl.make_block_ptr(k2 + i_bh * s_k_h, (T, K), (s_k_t, 1), (\n offset, 0), (BS, BK), (1, 0))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, 1), (\n offset, 0), (BS, BV), (1, 0))\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (offset,),\n (BS,), (0,))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n m_s = tl.arange(0, BT) >= offset - i_t * BT + BS\n b_s = tl.dot(b_q.to(b_k.dtype), b_k, allow_tf32=False)\n b_s = tl.where(m_s[:, None], b_s, 0)\n b_o += tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n b_k2 = (tl.load(p_k2, boundary_check=(0, 1)) * b_beta[:, None]).to(b_v\n .dtype)\n b_q -= tl.dot(b_s.to(b_v.dtype), b_k2, allow_tf32=False)\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(attn + i_bh * T * T, (T, T), (T, 1), (\n i_t * BT, offset), (BT, BS), (1, 0))\n tl.store(p_a, b_s.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n for offset in range(i_t * BT - BS, -BS, -BS):\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (1, s_k_t), (0,\n offset), (BK, BS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, 1), (\n offset, 0), (BS, BV), (1, 0))\n p_beta = tl.make_block_ptr(beta + i_bh * T, (T,), (1,), (offset,),\n (BS,), (0,))\n p_k2 = tl.make_block_ptr(k2 + i_bh * s_k_h, (T, K), (s_k_t, 1), (\n offset, 0), (BS, BK), (1, 0))\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_beta = tl.load(p_beta, boundary_check=(0,))\n b_s = tl.dot(b_q.to(b_k.dtype), b_k, allow_tf32=False)\n b_o += tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n b_k2 = (tl.load(p_k2, boundary_check=(0, 1)) * b_beta[:, None]).to(b_v\n .dtype)\n b_q -= tl.dot(b_s.to(b_v.dtype), b_k2, allow_tf32=False).to(b_q.dtype)\n if OUTPUT_ATTENTIONS:\n p_a = tl.make_block_ptr(attn + i_bh * T * T, (T, T), (T, 1), (\n i_t * BT, offset), (BT, BS), (1, 0))\n tl.store(p_a, b_s.to(p_a.dtype.element_ty), boundary_check=(0, 1))\n p_o_new = tl.make_block_ptr(o_new + i_bh * s_v_h, (T, V), (s_v_t, 1), (\n i_t * BT, 0), (BT, BV), (1, 0))\n tl.store(p_o_new, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n", "category": { "Functionality": [ "Matrix Multiplication", "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/delta_rule/parallel.py" }, { "uuid": "520e593c-f72d-4d79-8df6-fa4beed24ea7", "file_name": "fp8_gemm.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.autotune(configs=[Config({'BLOCK_M': 128, 'BLOCK_N': 256, 'BLOCK_K':\n 128, 'SPLIT_K': 1}, num_stages=3, num_warps=8), Config({'BLOCK_M': 256,\n 'BLOCK_N': 128, 'BLOCK_K': 128, 'SPLIT_K': 1}, num_stages=3, num_warps=\n 8), Config({'BLOCK_M': 256, 'BLOCK_N': 64, 'BLOCK_K': 128, 'SPLIT_K': 1\n }, num_stages=4, num_warps=4), Config({'BLOCK_M': 64, 'BLOCK_N': 256,\n 'BLOCK_K': 128, 'SPLIT_K': 1}, num_stages=4, num_warps=4), Config({\n 'BLOCK_M': 128, 'BLOCK_N': 128, 'BLOCK_K': 128, 'SPLIT_K': 1},\n num_stages=4, num_warps=4), Config({'BLOCK_M': 128, 'BLOCK_N': 64,\n 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages=4, num_warps=4), Config({\n 'BLOCK_M': 64, 'BLOCK_N': 128, 'BLOCK_K': 64, 'SPLIT_K': 1}, num_stages\n =4, num_warps=4), Config({'BLOCK_M': 64, 'BLOCK_N': 64, 'BLOCK_K': 512,\n 'SPLIT_K': 1}, num_stages=3, num_warps=4)], key=['m_key', 'n_key', 'k_key']\n )\n@triton.heuristics({'EVEN_K': lambda args: args['K'] % (args['BLOCK_K'] *\n args['SPLIT_K']) == 0})\n@triton.jit\ndef _kernel_matmul_fp8_row_tma_persistent(A_ptr, B_ptr, C_ptr, M, N, K,\n m_key, n_key, k_key, A_scale, B_scale, Bias, stride_am, stride_ak,\n stride_bn, stride_bk, stride_cm, stride_cn, dot_out_dtype: tl.constexpr,\n c_dtype: tl.constexpr, bias_dtype: tl.constexpr, allow_tf32: tl.\n constexpr, fp8_fast_accum: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_N:\n tl.constexpr, BLOCK_K: tl.constexpr, GROUP_M: tl.constexpr, AB_DTYPE:\n tl.constexpr, SPLIT_K: tl.constexpr, EVEN_K: tl.constexpr, NUM_SMS: tl.\n constexpr, USE_BIAS: tl.constexpr) ->None:\n \"\"\"Matmul kernel of [M, K] @ [N, K] with row-wise scales\n\n performs swizzled matmul in [BLOCK_M, BLOCK_K] with [BLOCK_K, BLOCK_N] tiles.\n\n Args:\n A (TensorWrapper): [M, K] input tensor.\n B (TensorWrapper): [N, K] input tensor.\n C (TensorWrapper): [M, N] output tensor.\n M (int): M dimension of input tensor.\n N (int): N dimension of input tensor.\n K (int): K dimension of input tensor.\n A_scale (TensorWrapper): [M] reciprocal scale tensor per row. A * A_scale = original A\n B_scale (TensorWrapper): [N] reciprocal scale tensor per row. B * B_scale = original B\n stride_am (int): Stride of M dimension of A.\n stride_ak (int): Stride of K dimension of A.\n stride_bn (int): Stride of N dimension of B.\n stride_bk (int): Stride of K dimension of B.\n stride_cm (int): Stride of M dimension of C.\n stride_cn (int): Stride of N dimension of C.\n dot_out_dtype (torch.dtype): Output type of tensor core.\n allow_tf32 (bool): Whether to use TF32 for tensor core.\n fp8_fast_accum (bool): Whether to use fast accumulation for tensor core.\n BLOCK_M (int): Block size for M dimension.\n BLOCK_N (int): Block size for N dimension.\n BLOCK_K (int): Block size for K dimension.\n GROUP_M (int): Number of groups for M dimension swizzle.\n SPLIT_K (int): Number of SM's to launch per row.\n EVEN_K (bool): Whether K is evenly divisible by BLOCK_K * SPLIT_K.\n AB_DTYPE (bool): Wether to cast A and B to C.dtype before tensor core.\n \"\"\"\n start_pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_M)\n num_pid_n = tl.cdiv(N, BLOCK_N)\n k_tiles = tl.cdiv(K, BLOCK_K)\n num_tiles = num_pid_m * num_pid_n\n tiles_per_SM = num_tiles // NUM_SMS\n if start_pid < num_tiles % NUM_SMS:\n tiles_per_SM += 1\n tile_id = start_pid - NUM_SMS\n ki = -1\n pid_m = 0\n pid_n = 0\n offs_am = 0\n offs_bn = 0\n num_pid_in_group = GROUP_M * num_pid_n\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n dtype_fp8 = tl.float8e4nv\n scale_dtype = tl.float32\n for _ in range(0, k_tiles * tiles_per_SM):\n ki = tl.where(ki == k_tiles - 1, 0, ki + 1)\n if ki == 0:\n tile_id += NUM_SMS\n group_id = tile_id // num_pid_in_group\n first_pid_m = group_id * GROUP_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_M)\n pid_m = first_pid_m + tile_id % group_size_m\n pid_n = tile_id % num_pid_in_group // group_size_m\n offs_am = pid_m * BLOCK_M\n offs_bn = pid_n * BLOCK_N\n offs_am = tl.multiple_of(offs_am, BLOCK_M)\n offs_bn = tl.multiple_of(offs_bn, BLOCK_N)\n offs_k = ki * BLOCK_K\n a = tl._experimental_descriptor_load(A_ptr, [offs_am, offs_k], [\n BLOCK_M, BLOCK_K], dtype_fp8)\n b = tl._experimental_descriptor_load(B_ptr, [offs_bn, offs_k], [\n BLOCK_N, BLOCK_K], dtype_fp8)\n if fp8_fast_accum:\n acc = tl.dot(a, b.T, acc, out_dtype=dot_out_dtype, allow_tf32=\n allow_tf32)\n else:\n acc += tl.dot(a, b.T, out_dtype=dot_out_dtype, allow_tf32=\n allow_tf32)\n if ki == k_tiles - 1:\n a_scale = tl._experimental_descriptor_load(A_scale, [offs_am],\n [BLOCK_M], scale_dtype)\n b_scale = tl._experimental_descriptor_load(B_scale, [offs_bn],\n [BLOCK_N], scale_dtype)\n scale = a_scale[:, None] * b_scale[None, :]\n acc *= scale\n if USE_BIAS:\n bias = tl._experimental_descriptor_load(Bias, [offs_bn], [\n BLOCK_N], bias_dtype)\n acc += bias[None, :]\n acc = acc.to(c_dtype)\n tl._experimental_descriptor_store(C_ptr, acc, [offs_am, offs_bn])\n acc = tl.zeros((BLOCK_M, BLOCK_N), dtype=dot_out_dtype)\n", "category": { "Functionality": [ "Matrix Multiplication", "Quantization" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/experimental/gemm/triton_gemm/fp8_gemm.py" }, { "uuid": "d240495b-66c0-479d-a4bb-97581826f003", "file_name": "mhmoe.py", "repo_name": "dtadpole/triton-playground", "file_path": "mhmoe.py", "commit_hash": "2d317976722d63080133b1bf88b1f0cdec98f831", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_B': 32, 'BLOCK_SIZE_E':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_B': 64,\n 'BLOCK_SIZE_E': 32}, num_stages=4, num_warps=4), triton.Config({\n 'BLOCK_SIZE_B': 32, 'BLOCK_SIZE_E': 64}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_B': 64, 'BLOCK_SIZE_E': 64}, num_stages=3,\n num_warps=4)], key=['B', 'D', 'E'])\n@triton.jit\ndef mlp_wide_kernel_fwd(x_ptr, w1_ptr, w2_ptr, o_ptr, H, B, D: tl.constexpr,\n E, stride_xb, stride_xd, stride_w1d, stride_w1e, stride_w2e, stride_w2d,\n stride_ob, stride_od, BLOCK_SIZE_B: tl.constexpr, BLOCK_SIZE_E: tl.\n constexpr, ACTIVATION: tl.constexpr):\n \"\"\"Kernel for computing the mlp\n Z = X @ W1, H = f(Z), O = H @ W2.\n - X has shape (B, D)\n - W1 has shape (D, E)\n - W2 has shape (E, D)\n - O has shape (B, D)\n \"\"\"\n pid = tl.program_id(axis=0)\n batch_groups = tl.cdiv(B, BLOCK_SIZE_B)\n pid_b = pid % batch_groups\n pid_h = pid // batch_groups\n TARGET_TYPE = x_ptr.type.element_ty\n x_ptrs = tl.make_block_ptr(base=x_ptr, shape=(B * H, D), strides=(\n stride_xb, stride_xd), offsets=(pid_h * B + pid_b * BLOCK_SIZE_B, 0\n ), block_shape=(BLOCK_SIZE_B, D), order=(1, 0))\n w1_ptrs = tl.make_block_ptr(base=w1_ptr, shape=(D * H, E), strides=(\n stride_w1d, stride_w1e), offsets=(pid_h * D, 0), block_shape=(D,\n BLOCK_SIZE_E), order=(1, 0))\n w2_ptrs = tl.make_block_ptr(base=w2_ptr, shape=(E * H, D), strides=(\n stride_w2e, stride_w2d), offsets=(pid_h * E, 0), block_shape=(\n BLOCK_SIZE_E, D), order=(1, 0))\n o_ptrs = tl.make_block_ptr(base=o_ptr, shape=(B * H, D), strides=(\n stride_ob, stride_od), offsets=(pid_h * B + pid_b * BLOCK_SIZE_B, 0\n ), block_shape=(BLOCK_SIZE_B, D), order=(1, 0))\n x = tl.load(x_ptrs)\n o = tl.zeros((BLOCK_SIZE_B, D), dtype=tl.float32)\n for e in range(0, tl.cdiv(E, BLOCK_SIZE_E)):\n w1 = tl.load(w1_ptrs)\n w2 = tl.load(w2_ptrs)\n z = tl.dot(x, w1, out_dtype=tl.float32)\n if ACTIVATION == 'leaky_relu':\n z = leaky_relu(z).to(TARGET_TYPE)\n elif ACTIVATION == 'silu':\n z = silu(z).to(TARGET_TYPE)\n elif ACTIVATION == 'sigmoid':\n z = tl.sigmoid(z).to(TARGET_TYPE)\n else:\n z = z.to(TARGET_TYPE)\n o = tl.dot(z, w2, o, out_dtype=tl.float32)\n w1_ptrs = tl.advance(w1_ptrs, (0, BLOCK_SIZE_E))\n w2_ptrs = tl.advance(w2_ptrs, (BLOCK_SIZE_E, 0))\n o = o.to(TARGET_TYPE)\n tl.store(o_ptrs, o)\n", "category": { "Functionality": [ "Activation Functions", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dtadpole/triton-playground/blob/2d317976722d63080133b1bf88b1f0cdec98f831/mhmoe.py" }, { "uuid": "d3df060f-25ae-4f53-8fb1-4c7cff1669ee", "file_name": "quantize.py", "repo_name": "pytorch/FBGEMM", "file_path": "fbgemm_gpu/fbgemm_gpu/triton/quantize.py", "commit_hash": "fe980ab54a6e28818d81c8694b6564e7f804418b", "starcount": 0, "input": "@triton.jit\ndef _kernel_dequantize_mx4(A, mx4_lookup_table, out, M, GROUPS_PER_THREAD,\n GROUP_SIZE: tl.constexpr, GROUP_LOAD: tl.constexpr, USE_INT64: tl.constexpr\n ) ->None:\n \"\"\"Dequantize a packed MX4 tensor and apply scaling.\n\n Args:\n A (Tensor): [M] MX4 tensor packed into int8.\n shared_exp (Tensor): Int8 tensor representing group exponent.\n mx4_lookup_table (Tensor): Map from mx4 integer value to floating point.\n M (int): Total number of elements in input.\n GROUPS_PER_THREAD (int): Number of groups each thread is responsible for.\n GROUP_SIZE (int): Size of chunks that use the same shared exponent.\n GROUP_LOAD (int): Number of groups to process simultaneously.\n USE_INT64 (bool): Whether to use int64 for indexing.\n \"\"\"\n MX4_BIT_MASK: tl.constexpr = 15\n FP32_EXP_BIAS: tl.constexpr = 127\n PACKED_GROUP_SIZE: tl.constexpr = GROUP_SIZE // 2 + 1\n pid = tl.program_id(0)\n if USE_INT64:\n pid = pid.to(tl.int64)\n M = tl.cast(M, tl.int64)\n GROUPS_PER_THREAD = tl.cast(GROUPS_PER_THREAD, tl.int64)\n INPUT_CHUNK_SIZE = GROUPS_PER_THREAD * PACKED_GROUP_SIZE\n OUTPUT_CHUNK_SIZE = GROUPS_PER_THREAD * GROUP_SIZE\n OUTPUT_SIZE = M // PACKED_GROUP_SIZE * GROUP_SIZE\n input_start = pid * (GROUPS_PER_THREAD * PACKED_GROUP_SIZE)\n exp_start = input_start + GROUP_SIZE // 2\n output_start = pid * OUTPUT_CHUNK_SIZE\n input_offset = tl.arange(0, GROUP_LOAD * GROUP_SIZE // 2)\n exp_indices = input_offset // (GROUP_SIZE // 2)\n input_offset = input_offset + exp_indices + input_start\n output_offset = tl.arange(0, GROUP_LOAD * GROUP_SIZE) + output_start\n exp_offset = exp_indices * PACKED_GROUP_SIZE + exp_start\n for _k in range(0, tl.cdiv(GROUPS_PER_THREAD, GROUP_LOAD)):\n a = tl.load(A + input_offset, mask=(input_offset < M) & (\n input_offset < INPUT_CHUNK_SIZE * (pid + 1)), other=0.0)\n low_mx4 = a & MX4_BIT_MASK\n high_mx4 = a >> 4 & MX4_BIT_MASK\n low_fp32 = tl.load(mx4_lookup_table + low_mx4)\n high_fp32 = tl.load(mx4_lookup_table + high_mx4)\n exp = tl.load(A + exp_offset, mask=(exp_offset < M) & (exp_offset <\n INPUT_CHUNK_SIZE * (pid + 1)), other=0.0)\n exp = exp.to(tl.int16) - FP32_EXP_BIAS\n scale = tl.exp2(exp.to(tl.float64)).to(tl.float32)\n scaled_low_fp32 = scale * low_fp32\n scaled_high_fp32 = scale * high_fp32\n scaled_fp32 = tl.interleave(scaled_low_fp32, scaled_high_fp32)\n tl.store(out + output_offset, scaled_fp32, mask=(output_offset <\n OUTPUT_SIZE) & (output_offset < OUTPUT_CHUNK_SIZE * (pid + 1)))\n input_offset += GROUP_LOAD * PACKED_GROUP_SIZE\n exp_offset += GROUP_LOAD * PACKED_GROUP_SIZE\n output_offset += GROUP_LOAD * GROUP_SIZE\n", "category": { "Functionality": [ "Quantization", "Elementwise Operations" ], "Data Type": [ "int8", "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD", "MIT" ], "github_url": "https://github.com/pytorch/FBGEMM/blob/fe980ab54a6e28818d81c8694b6564e7f804418b/fbgemm_gpu/fbgemm_gpu/triton/quantize.py" }, { "uuid": "9f4731c2-0c44-4143-a92f-bcfed7921b0a", "file_name": "normalization.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/normalization.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_normalization_backward_kernel_1(grad_input_ptr, grad_output_ptr,\n grad_weight_partial_ptr, grad_bias_partial_ptr, output_ptr, weight_ptr,\n bias_ptr, inv_var_ptr, n_cols, n_rows, has_bias: tl.constexpr,\n zero_centered: tl.constexpr, block_size: tl.constexpr, block_size_row:\n tl.constexpr):\n rows = tl.program_id(0) * block_size_row + tl.arange(0, block_size_row)[\n :, None]\n row_mask = rows < n_rows\n cols = tl.arange(0, block_size)[None, :]\n col_mask = cols < n_cols\n mask = col_mask & row_mask\n offsets = rows * n_cols + cols\n output = tl.load(output_ptr + offsets, mask=mask, other=0).to(tl.float32)\n grad_output = tl.load(grad_output_ptr + offsets, mask=mask, other=0).to(tl\n .float32)\n weight = tl.load(weight_ptr + cols, mask=col_mask).to(tl.float32)\n if zero_centered:\n weight += 1\n inv_var = tl.load(inv_var_ptr + rows, mask=row_mask)\n if has_bias:\n bias = tl.load(bias_ptr + cols, mask=col_mask).to(tl.float32)\n output = output - bias\n input_normalized = tl.where(mask, output / weight, 0.0)\n weight_grad_output = tl.where(mask, weight * grad_output * inv_var, 0.0)\n grad_input = weight_grad_output - input_normalized * (tl.sum(\n input_normalized * weight_grad_output, axis=1)[:, None] / n_cols)\n if has_bias:\n grad_input = grad_input - tl.sum(weight_grad_output, axis=1)[:, None\n ] / n_cols\n tl.store(grad_input_ptr + offsets, grad_input, mask=mask)\n parameter_offsets = tl.program_id(0) * n_cols + cols\n grad_weight_partial_ptr = grad_weight_partial_ptr + parameter_offsets\n grad_weight_partial = (grad_output * input_normalized).to(weight.dtype)\n grad_weight_partial = tl.sum(grad_weight_partial, axis=0)[None, :]\n if has_bias:\n grad_bias_partial_ptr = grad_bias_partial_ptr + parameter_offsets\n grad_bias_partial = tl.sum(grad_output.to(weight.dtype), axis=0)[\n None, :]\n tl.store(grad_weight_partial_ptr, grad_weight_partial, mask=col_mask)\n if has_bias:\n tl.store(grad_bias_partial_ptr, grad_bias_partial, mask=col_mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation", "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/normalization.py" }, { "uuid": "5a3b3d77-505a-428b-9f7e-43a71233c09b", "file_name": "fp8_matmul.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/fp8/fp8_matmul.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef matmul_kernel_tma_persistent(a_desc_ptr, a_scale_ptr, b_desc_ptr,\n b_scale_ptr, c_desc_ptr, M, N, K, stride_a_scale_m, stride_b_scale_n,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE_M: tl.constexpr, NUM_SMS: tl.constexpr,\n output_dtype: tl.constexpr, ROW_WISE_SCALING: tl.constexpr):\n tl.inline_asm_elementwise(\n 'fence.proxy.tensormap::generic.acquire.gpu [$1], 128; // $0 dummy reg'\n , '=r, l', [a_desc_ptr], dtype=tl.int32, is_pure=False, pack=1)\n tl.inline_asm_elementwise(\n 'fence.proxy.tensormap::generic.acquire.gpu [$1], 128; // $0 dummy reg'\n , '=r, l', [b_desc_ptr], dtype=tl.int32, is_pure=False, pack=1)\n tl.inline_asm_elementwise(\n 'fence.proxy.tensormap::generic.acquire.gpu [$1], 128; // $0 dummy reg'\n , '=r, l', [c_desc_ptr], dtype=tl.int32, is_pure=False, pack=1)\n dtype = tl.float8e4nv\n start_pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n k_tiles = tl.cdiv(K, BLOCK_SIZE_K)\n num_tiles = num_pid_m * num_pid_n\n tiles_per_SM = num_tiles // NUM_SMS\n if start_pid < num_tiles % NUM_SMS:\n tiles_per_SM += 1\n tile_id = start_pid - NUM_SMS\n ki = -1\n pid_m = 0\n pid_n = 0\n offs_am = 0\n offs_bn = 0\n num_pid_in_group = GROUP_SIZE_M * num_pid_n\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n a_scale, b_scale = load_scales(a_scale_ptr, b_scale_ptr, ROW_WISE_SCALING)\n for _ in range(0, k_tiles * tiles_per_SM):\n ki = tl.where(ki == k_tiles - 1, 0, ki + 1)\n if ki == 0:\n tile_id += NUM_SMS\n group_id = tile_id // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE_M\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE_M)\n pid_m = first_pid_m + tile_id % group_size_m\n pid_n = tile_id % num_pid_in_group // group_size_m\n offs_am = pid_m * BLOCK_SIZE_M\n offs_bn = pid_n * BLOCK_SIZE_N\n offs_k = ki * BLOCK_SIZE_K\n a = tl._experimental_descriptor_load(a_desc_ptr, [offs_am, offs_k],\n [BLOCK_SIZE_M, BLOCK_SIZE_K], dtype)\n b = tl._experimental_descriptor_load(b_desc_ptr, [offs_bn, offs_k],\n [BLOCK_SIZE_N, BLOCK_SIZE_K], dtype)\n accumulator = tl.dot(a, b.T, accumulator)\n if ki == k_tiles - 1:\n offs_cm = offs_am + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = offs_bn + tl.arange(0, BLOCK_SIZE_N)\n accumulator = apply_scaling(accumulator, a_scale, b_scale,\n ROW_WISE_SCALING, offs_cm, offs_cn, M, N, stride_a_scale_m,\n stride_b_scale_n)\n c = accumulator.to(output_dtype)\n tl._experimental_descriptor_store(c_desc_ptr, c, [offs_am, offs_bn]\n )\n accumulator = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.\n float32)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Persistent Kernels" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/fp8/fp8_matmul.py" }, { "uuid": "40bd775e-ef2e-4eda-8c59-25ebdea73d19", "file_name": "RzLinearBackward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearBackward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_N': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=4, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': \n 32}, num_stages=4, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=8),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=8), triton.Config({'BLOCK_SIZE_N': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=3, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': \n 32}, num_stages=3, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M': 32}, num_stages=2, num_warps=8),\n triton.Config({'BLOCK_SIZE_N': 256, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=2, num_warps=8), triton.Config({'BLOCK_SIZE_N': 256,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 256, 'BLOCK_SIZE_M':\n 32}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M': 32}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 128, 'BLOCK_SIZE_M':\n 32}, num_stages=2, num_warps=4), triton.Config({'BLOCK_SIZE_N': 128,\n 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': 32}, num_stages=2, num_warps=4),\n triton.Config({'BLOCK_SIZE_N': 64, 'BLOCK_SIZE_K': 64, 'BLOCK_SIZE_M': \n 32}, num_stages=2, num_warps=4)], key=['M', 'N', 'K'])\n@triton.jit\ndef rz_linear_backward_weight_grad_kernel_tf32(a_ptr, b_ptr, c_ptr,\n init_factor, M, N, K, H, stride_am, stride_ak, stride_bm, stride_bn, R7:\n int, R6: int, R5: int, R4: int, R3: int, R2: int, R1: int, R0: int,\n BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr, BLOCK_SIZE_K:\n tl.constexpr, GROUP_SIZE: tl.constexpr):\n rz_linear_backward_weight_grad_core(a_ptr=a_ptr, b_ptr=b_ptr, c_ptr=\n c_ptr, init_factor=init_factor, M=M, N=N, K=K, H=H, stride_am=\n stride_am, stride_ak=stride_ak, stride_bm=stride_bm, stride_bn=\n stride_bn, R7=R7, R6=R6, R5=R5, R4=R4, R3=R3, R2=R2, R1=R1, R0=R0,\n allow_tf32=True, BLOCK_SIZE_M=BLOCK_SIZE_M, BLOCK_SIZE_N=\n BLOCK_SIZE_N, BLOCK_SIZE_K=BLOCK_SIZE_K, GROUP_SIZE=GROUP_SIZE)\n", "category": { "Functionality": [ "Matrix Multiplication", "Backpropagation" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearBackward.py" }, { "uuid": "0657cbe4-31fe-41a2-aee4-95f95ff84d3e", "file_name": "masks.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/flash/masks.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef causal_mask_triton(score, batch, head, seq_len_q, seq_len_kv):\n score = tl.where(seq_len_q >= seq_len_kv, score, float('-inf'))\n return score\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/flash/masks.py" }, { "uuid": "40cd1d4b-831e-4e99-84f0-0996d5aa95be", "file_name": "bwd_split_kernel.py", "repo_name": "ROCm/aotriton", "file_path": "test/bwd_split_kernel.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.jit\ndef dot(BLOCK_M: tl.constexpr, QDIM: tl.constexpr, KDIM: tl.constexpr, q, k):\n if BLOCK_M == 1:\n return tl.sum(tl.view(q, [QDIM]) * tl.view(k, [KDIM]))\n else:\n return tl.dot(q, k)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/test/bwd_split_kernel.py" }, { "uuid": "17bb60bc-fa4c-439e-b572-df79bd2eeab3", "file_name": "triton_fused_attn2.py", "repo_name": "LouChao98/vqtree", "file_path": "ops/triton_fused_attn2.py", "commit_hash": "27a53274df7a804bce27dffcce5f5be73f64b6f3", "starcount": 0, "input": "@triton.heuristics({'EVEN_M': lambda args: args['seqlen_q'] % args[\n 'BLOCK_M'] == 0, 'EVEN_N': lambda args: args['seqlen_k'] % args[\n 'BLOCK_N'] == 0})\n@triton.jit\ndef _fwd_kernel(Q, K, V, Out, softmax_scale, stride_qb, stride_qh,\n stride_qm, stride_kb, stride_kh, stride_kn, stride_vb, stride_vh,\n stride_vn, stride_ob, stride_oh, stride_om, nheads, seqlen_q, seqlen_k,\n CACHE_KEY_SEQLEN_Q, CACHE_KEY_SEQLEN_K, IS_CAUSAL: tl.constexpr,\n BLOCK_HEADDIM: tl.constexpr, EVEN_M: tl.constexpr, EVEN_N: tl.constexpr,\n BLOCK_M: tl.constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hb = tl.program_id(1)\n off_b = off_hb // nheads\n off_h = off_hb % nheads\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n Q_block_ptr = tl.make_block_ptr(base=Q + (off_b * stride_qb + off_h *\n stride_qh), shape=(seqlen_q, BLOCK_HEADDIM), strides=(stride_qm, 1),\n offsets=(start_m * BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_HEADDIM\n ), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + (off_b * stride_kb + off_h *\n stride_kh), shape=(seqlen_k, BLOCK_HEADDIM), strides=(stride_kn, 1),\n offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n V_block_ptr = tl.make_block_ptr(base=V + (off_b * stride_vb + off_h *\n stride_vh), shape=(seqlen_k, BLOCK_HEADDIM), strides=(stride_vn, 1),\n offsets=(0, 0), block_shape=(BLOCK_N, BLOCK_HEADDIM), order=(1, 0))\n lse_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) + NEGINF\n acc_o = tl.zeros([BLOCK_M, BLOCK_HEADDIM], dtype=tl.float32)\n if EVEN_M:\n q = tl.load(Q_block_ptr)\n else:\n q = tl.load(Q_block_ptr, boundary_check=(0,), padding_option='zero')\n end_n = seqlen_k if not IS_CAUSAL else tl.minimum((start_m + 1) *\n BLOCK_M, seqlen_k)\n for start_n in range(0, end_n, BLOCK_N):\n start_n = tl.multiple_of(start_n, BLOCK_N)\n if EVEN_N & EVEN_M:\n k = tl.load(K_block_ptr)\n else:\n k = tl.load(K_block_ptr, boundary_check=(0,), padding_option='zero'\n )\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=tl.float32)\n qk += tl.dot(q, tl.trans(k))\n if not EVEN_N:\n qk += tl.where((start_n + offs_n)[None, :] < seqlen_k, 0, NEGINF)\n if IS_CAUSAL:\n qk += tl.where(offs_m[:, None] >= (start_n + offs_n)[None, :], \n 0, NEGINF)\n m_ij = tl.maximum(tl.max(qk, 1) * softmax_scale, lse_i)\n p = tl.exp(qk * softmax_scale - m_ij[:, None])\n l_ij = tl.sum(p, 1)\n acc_o_scale = tl.exp(m_i - m_ij)\n acc_o = acc_o * acc_o_scale[:, None]\n if EVEN_N & EVEN_M:\n v = tl.load(V_block_ptr)\n else:\n v = tl.load(V_block_ptr, boundary_check=(0,), padding_option='zero'\n )\n p = p.to(v.dtype)\n acc_o += tl.dot(p, v)\n m_i = m_ij\n l_i_new = tl.exp(lse_i - m_ij) + l_ij\n lse_i = m_ij + tl.log(l_i_new)\n K_block_ptr = tl.advance(K_block_ptr, (BLOCK_N, 0))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n o_scale = tl.exp(m_i - lse_i)\n acc_o = acc_o * o_scale[:, None]\n start_m = tl.program_id(0)\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_d = tl.arange(0, BLOCK_HEADDIM)\n out_ptrs = Out + off_b * stride_ob + off_h * stride_oh + (offs_m[:,\n None] * stride_om + offs_d[None, :])\n if EVEN_M:\n tl.store(out_ptrs, acc_o)\n else:\n tl.store(out_ptrs, acc_o, mask=offs_m[:, None] < seqlen_q)\n", "category": { "Functionality": [ "Attention Mechanisms", "Softmax", "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LouChao98/vqtree/blob/27a53274df7a804bce27dffcce5f5be73f64b6f3/ops/triton_fused_attn2.py" }, { "uuid": "2186ae8f-a1c1-4eda-9e86-5e9dad2b7585", "file_name": "tuned_bwd.py", "repo_name": "ROCm/aotriton", "file_path": "tritonsrc/tuned_bwd.py", "commit_hash": "016f733e8ff746450e066f78bed68709ccd93e60", "starcount": 0, "input": "@triton.autotune(configs=TRITON_CONFIG_LIST_BWD, key=['BLOCK_DMODEL',\n 'max_seqlen_q', 'max_seqlen_k'])\n@triton.jit\ndef tuned_bwd_kernel_dq(Q, K, V, B, sm_scale, Out, DO, DQ, DB, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dqz, stride_dqh, stride_dqm, stride_dqk,\n stride_dbz, stride_dbh, stride_dbm, stride_dbn, cu_seqlens_q,\n cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k, head_dim,\n dropout_p, philox_seed, philox_offset_base, BLOCK_M: tl.constexpr,\n BLOCK_DMODEL: tl.constexpr, BLOCK_N: tl.constexpr, CAUSAL: tl.constexpr,\n ENABLE_DROPOUT: tl.constexpr, PADDED_HEAD: tl.constexpr, BIAS_TYPE: tl.\n constexpr):\n bare_bwd_kernel_dq(Q, K, V, B, sm_scale, Out, DO, DQ, DB, L, D,\n stride_qz, stride_qh, stride_qm, stride_qk, stride_kz, stride_kh,\n stride_kn, stride_kk, stride_vz, stride_vh, stride_vk, stride_vn,\n stride_bz, stride_bh, stride_bm, stride_bn, stride_oz, stride_oh,\n stride_om, stride_ok, stride_dqz, stride_dqh, stride_dqm,\n stride_dqk, stride_dbz, stride_dbh, stride_dbm, stride_dbn,\n cu_seqlens_q, cu_seqlens_k, num_seqlens, max_seqlen_q, max_seqlen_k,\n head_dim, dropout_p, philox_seed, philox_offset_base, BLOCK_M,\n BLOCK_DMODEL, BLOCK_N, CAUSAL, ENABLE_DROPOUT, PADDED_HEAD=\n PADDED_HEAD, BIAS_TYPE=BIAS_TYPE)\n", "category": { "Functionality": [ "Quantization", "Backpropagation" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ROCm/aotriton/blob/016f733e8ff746450e066f78bed68709ccd93e60/tritonsrc/tuned_bwd.py" }, { "uuid": "0e6f0fcf-9cae-4955-907d-a1026597b579", "file_name": "RzLinearForward.py", "repo_name": "apd10/RzLinear", "file_path": "python/rz_linear/impl/RzLinearForward.py", "commit_hash": "eb56657b2de0a97f398f88af421b0fbcbc5469c9", "starcount": 0, "input": "@triton.jit\ndef rz_linear_forward_core(a_ptr, b_ptr, c_ptr, init_factor, M: int, N: int,\n K: int, H: int, stride_am, stride_ak, stride_cm, stride_cn, allow_tf32:\n tl.constexpr, R7: int, R6: int, R5: int, R4: int, R3: int, R2: int, R1:\n int, R0: int, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr, GROUP_SIZE: tl.constexpr):\n \"\"\"Kernel for computing the matmul C = A x B.\n A has shape (M, K), B has shape (K, N) and C has shape (M, N)\n \"\"\"\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n num_pid_in_group = GROUP_SIZE * num_pid_n\n group_id = pid // num_pid_in_group\n first_pid_m = group_id * GROUP_SIZE\n group_size_m = min(num_pid_m - first_pid_m, GROUP_SIZE)\n pid_m = first_pid_m + pid % group_size_m\n pid_n = pid % num_pid_in_group // group_size_m\n offs_am = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n a_ptrs = a_ptr + (offs_am[:, None] * stride_am + offs_k[None, :] *\n stride_ak)\n b_offset = b_ptr + offs_k[:, None] * BLOCK_SIZE_N + tl.arange(0,\n BLOCK_SIZE_N)[None, :]\n b_ptrs = b_offset + ((0 * R3 + pid_n * R2 + R1) % R0 * R0 + (0 * R7 + \n pid_n * R5 + R4) % R0) % (H - BLOCK_SIZE_K * BLOCK_SIZE_N)\n c = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_N), dtype=tl.float32)\n offs_cm = pid_m * BLOCK_SIZE_M + tl.arange(0, BLOCK_SIZE_M)\n offs_cn = pid_n * BLOCK_SIZE_N + tl.arange(0, BLOCK_SIZE_N)\n a_zero = tl.zeros((BLOCK_SIZE_M, BLOCK_SIZE_K), dtype=tl.float32)\n b_zero = tl.zeros((BLOCK_SIZE_K, BLOCK_SIZE_N), dtype=tl.float32)\n for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n offs_k = k * BLOCK_SIZE_K + tl.arange(0, BLOCK_SIZE_K)\n a_mask = (offs_cm[:, None] < M) & (offs_k[None, :] < K)\n b_mask = (offs_k[:, None] < K) & (offs_cn[None, :] < N)\n a = tl.load(a_ptrs, mask=a_mask, other=a_zero)\n b = tl.load(b_ptrs, mask=b_mask, other=b_zero)\n c += tl.dot(a, b, allow_tf32=allow_tf32)\n a_ptrs += BLOCK_SIZE_K * stride_ak\n b_ptrs = b_offset + (((k + 1) * R3 + pid_n * R2 + R1) % R0 * R0 + (\n (k + 1) * R7 + pid_n * R5 + R4) % R0) % (H - BLOCK_SIZE_K *\n BLOCK_SIZE_N)\n c_ptrs = c_ptr + stride_cm * offs_cm[:, None] + stride_cn * offs_cn[None, :\n ]\n c_mask = (offs_cm[:, None] < M) & (offs_cn[None, :] < N)\n tl.store(c_ptrs, c * init_factor, mask=c_mask)\n", "category": { "Functionality": [ "Matrix Multiplication" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Cooperative Groups" ], "Memory Access Pattern": [ "Blocked Access", "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/apd10/RzLinear/blob/eb56657b2de0a97f398f88af421b0fbcbc5469c9/python/rz_linear/impl/RzLinearForward.py" }, { "uuid": "f66b57d6-8434-4700-927a-a112b18f64e5", "file_name": "cross_entropy.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/cross_entropy.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef triton_cross_entropy_forward_backward_kernel(logits_ptr, labels_ptr,\n grad_logits_ptr, losses_ptr, grad_losses, n_cols, logits_stride_0,\n grad_logits_stride_0, logits_scale_factor: tl.constexpr, block_size: tl\n .constexpr):\n block_idx = tl.program_id(0).to(tl.int64)\n col_offsets = tl.arange(0, block_size)\n logits_ptr = logits_ptr + block_idx * logits_stride_0\n mask = col_offsets < n_cols\n logits = tl.load(logits_ptr + col_offsets, mask=mask, other=-float('inf')\n ).to(tl.float32)\n if logits_scale_factor != 1.0:\n logits *= logits_scale_factor\n max_logits = tl.max(logits, 0)\n exp_logits = tl.exp(logits - max_logits)\n sum_exp_logits = tl.sum(exp_logits, 0)\n label_idx = tl.load(labels_ptr + block_idx)\n label_logits = tl.load(logits_ptr + label_idx).to(tl.float32)\n if label_idx < 0:\n loss = 0.0\n else:\n loss = tl.log(sum_exp_logits) + max_logits - label_logits\n tl.store(losses_ptr + block_idx, loss)\n grad_logits_ptr = grad_logits_ptr + block_idx * grad_logits_stride_0\n col_offsets = tl.arange(0, block_size)\n label_idx = tl.load(labels_ptr + block_idx)\n exp_logits = exp_logits / sum_exp_logits\n if logits_scale_factor != 1.0:\n exp_logits *= logits_scale_factor\n if label_idx < 0:\n grad_losses = 0.0\n grad_logits = grad_losses * tl.where(col_offsets == label_idx, \n exp_logits - 1.0, exp_logits)\n tl.store(grad_logits_ptr + col_offsets, grad_logits, mask=mask)\n", "category": { "Functionality": [ "Softmax", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/cross_entropy.py" }, { "uuid": "dc459f02-1c1e-4b41-baca-462de7e6a012", "file_name": "ops.py", "repo_name": "srush/triton-autodiff", "file_path": "triton_autodiff/ops.py", "commit_hash": "f9d1a04d048e3252bfd222646db7175ad60a3c7c", "starcount": 0, "input": "@triton.jit\ndef zeroslike(x):\n return tl.zeros(x.shape, tl.float32)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/srush/triton-autodiff/blob/f9d1a04d048e3252bfd222646db7175ad60a3c7c/triton_autodiff/ops.py" }, { "uuid": "2af621bf-a5fd-4ee0-a77d-7c7225403ab3", "file_name": "sparse_copy.py", "repo_name": "ServiceNow/Fast-LLM", "file_path": "fast_llm/functional/triton/sparse_copy.py", "commit_hash": "8b46289079da67cba99628448a6b6083dac083cf", "starcount": 0, "input": "@triton.jit\ndef copy_sparse_to_dense_kernel(input_ptr, output_ptr, scores_ptr,\n sparse_rows_ptr, num_columns: tl.constexpr, num_experts_per_token: tl.\n constexpr, block_size: tl.constexpr):\n dense_row = tl.program_id(0)\n offsets = tl.arange(0, block_size) + block_size * tl.program_id(1)\n mask = None if num_columns % block_size == 0 else offsets < num_columns\n out = tl.zeros((block_size,), tl.float32)\n for top_index in range(num_experts_per_token):\n sparse_row = tl.load(sparse_rows_ptr + dense_row *\n num_experts_per_token + top_index)\n input_ = tl.load(input_ptr + sparse_row * num_columns + offsets,\n mask=mask)\n if scores_ptr is not None:\n input_ *= tl.load(scores_ptr + dense_row *\n num_experts_per_token + top_index).to(tl.float32)\n out += input_\n tl.store(output_ptr + dense_row * num_columns + offsets, out, mask=mask)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32", "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/ServiceNow/Fast-LLM/blob/8b46289079da67cba99628448a6b6083dac083cf/fast_llm/functional/triton/sparse_copy.py" }, { "uuid": "c6143804-3cfd-4d1f-ab60-f8d9dbef8b8b", "file_name": "kernels.py", "repo_name": "pytorch-labs/tritonbench", "file_path": "tritonbench/operators/jagged_softmax/kernels.py", "commit_hash": "3a5dccb159834968567a2e45e561dc1aeaa8f8a8", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_RAGGED': b_r,\n 'BLOCK_SIZE_M': b_m}, num_warps=w, num_stages=s) for b_r, b_m, w, s in\n itertools.product(BLOCK_SIZES_RAGGED, BLOCK_SIZES_M, NUM_WARPS,\n NUM_STAGES)], key=['M'])\n@triton.jit\ndef triton_jagged_softmax_kernel_simple_fused_buffer_then_sum(input_ptr_values,\n input_ptr_offsets, output_ptr, M, MAX_SEQLEN, BLOCK_SIZE_RAGGED: tl.\n constexpr, BLOCK_SIZE_M: tl.constexpr):\n pid = tl.program_id(axis=0)\n pid_b = pid // tl.cdiv(M, BLOCK_SIZE_M)\n pid_m = pid % tl.cdiv(M, BLOCK_SIZE_M)\n buffer = tl.zeros((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), dtype=tl.float32)\n block_start_m = pid_m * BLOCK_SIZE_M\n offsets_m = block_start_m + tl.arange(0, BLOCK_SIZE_M)\n mask_m = offsets_m < M\n ragged_start, ragged_end = tl.load(input_ptr_offsets + pid_b), tl.load(\n input_ptr_offsets + (pid_b + 1))\n buffer_max_all = tl.full((BLOCK_SIZE_RAGGED, BLOCK_SIZE_M), value=float\n ('-inf'), dtype=tl.float32)\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=float('-inf')\n )\n buffer_max_all = tl.maximum(buffer_max_all, input)\n buffer_max = tl.max(buffer_max_all, axis=0, keep_dims=True)\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=float('-inf')\n )\n buffer += tl.exp(input - buffer_max)\n buffer_exp_sum = tl.sum(buffer, axis=0)\n for block_pos in range(0, MAX_SEQLEN, BLOCK_SIZE_RAGGED):\n block_start_ragged = ragged_start + block_pos\n offsets_ragged = block_start_ragged + tl.arange(0, BLOCK_SIZE_RAGGED)\n mask_ragged = offsets_ragged < ragged_end\n idxs = offsets_ragged[:, None] * M + offsets_m\n mask = mask_ragged[:, None] & mask_m\n input = tl.load(input_ptr_values + idxs, mask=mask, other=float('-inf')\n )\n output = tl.fdiv(tl.exp(input - buffer_max), buffer_exp_sum)\n tl.store(output_ptr + idxs, output, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/pytorch-labs/tritonbench/blob/3a5dccb159834968567a2e45e561dc1aeaa8f8a8/tritonbench/operators/jagged_softmax/kernels.py" }, { "uuid": "97976f05-d763-4664-a07a-d3f7a68ba825", "file_name": "rms_norm_kernels.py", "repo_name": "BobMcDear/attorch", "file_path": "attorch/rms_norm_kernels.py", "commit_hash": "da06cb6236bb47195e33fe3986ed21c675ed94cc", "starcount": 0, "input": "@triton.autotune(configs=warps_kernel_configs(), key=['batch_dim', 'feat_dim'])\n@triton.heuristics({'BLOCK_SIZE_BATCH': BLOCK_SIZE_BATCH_heuristic,\n 'BLOCK_SIZE_FEAT': lambda args: next_power_of_2(args['feat_dim'])})\n@triton.jit\ndef rms_norm_backward_kernel(output_grad_pointer, input_pointer,\n inv_rms_pointer, weight_pointer, input_grad_pointer,\n weight_grad_pointer, batch_dim, feat_dim, output_grad_batch_stride,\n output_grad_feat_stride, input_batch_stride, input_feat_stride,\n input_grad_batch_stride, input_grad_feat_stride,\n weight_grad_batch_stride, weight_grad_feat_stride, scale_by_weight: tl.\n constexpr, BLOCK_SIZE_BATCH: tl.constexpr, BLOCK_SIZE_FEAT: tl.constexpr):\n \"\"\"\n Calculates the input gradient of root mean square normalization.\n\n Args:\n output_grad_pointer: Pointer to root mean square normalization's output gradients.\n The output gradients must be of shape [batch_dim, feat_dim].\n input_pointer: Pointer to the input.\n The input must be of shape [batch_dim, feat_dim].\n inv_rms_pointer: Pointer to the input's inverse root mean square.\n The inverse root mean square should be of shape [batch_dim].\n weight_pointer: Pointer to optional weights if affine transform occurred.\n The weights, if provided, must be of shape [feat_dim].\n input_grad_pointer: Pointer to a container the input's gradients are written to.\n The container must be of shape [batch_dim, feat_dim].\n weight_grad_pointer: Pointer to an optional container the weights' row-wise gradients\n are written to if scale_by_weight is True, which should later be summed.\n The container, if provided, must be of shape [batch_dim/BLOCK_SIZE_BATCH, feat_dim].\n bias_grad_pointer: Pointer to an optional container the bias vector's row-wise gradients\n are written to if scale_by_weight and add_bias are True, which should later be summed.\n The container, if provided, must be of shape [batch_dim/BLOCK_SIZE_BATCH, feat_dim].\n batch_dim: Batch dimension.\n feat_dim: Dimensionality of the features.\n output_grad_batch_stride: Stride necessary to jump one element along the\n output gradients' batch dimension.\n output_grad_feat_stride: Stride necessary to jump one element along the\n output gradients' feature dimension.\n input_batch_stride: Stride necessary to jump one element along the\n input's batch dimension.\n input_feat_stride: Stride necessary to jump one element along the\n input's feature dimension.\n input_grad_batch_stride: Stride necessary to jump one element along the\n input gradient container's batch dimension.\n input_grad_feat_stride: Stride necessary to jump one element along the\n input gradient container's feature dimension.\n weight_grad_batch_stride: Stride necessary to jump one element along the\n weight gradient container's batch dimension.\n weight_grad_feat_stride: Stride necessary to jump one element along the\n weight gradient container's feature dimension.\n scale_by_weight: Flag for scaling the normalized output by weights.\n BLOCK_SIZE_BATCH: Block size across the batch dimension.\n BLOCK_SIZE_FEAT: Block size across the feature dimension.\n \"\"\"\n batch_pid = tl.program_id(axis=0)\n batch_offset = batch_pid * BLOCK_SIZE_BATCH + tl.arange(0, BLOCK_SIZE_BATCH\n )\n feat_offset = tl.arange(0, BLOCK_SIZE_FEAT)\n batch_mask = batch_offset < batch_dim\n feat_mask = feat_offset < feat_dim\n output_grad_pointer += output_grad_batch_stride * batch_offset[:, None\n ] + output_grad_feat_stride * feat_offset[None, :]\n input_pointer += input_batch_stride * batch_offset[:, None\n ] + input_feat_stride * feat_offset[None, :]\n input_grad_pointer += input_grad_batch_stride * batch_offset[:, None\n ] + input_grad_feat_stride * feat_offset[None, :]\n output_grad = tl.load(output_grad_pointer, mask=batch_mask[:, None] &\n feat_mask[None, :]).to(tl.float32)\n input = tl.load(input_pointer, mask=batch_mask[:, None] & feat_mask[\n None, :]).to(tl.float32)\n inv_rms = tl.load(inv_rms_pointer + batch_offset, mask=batch_mask)\n pre_lin = input * inv_rms[:, None]\n if scale_by_weight:\n weight = tl.load(weight_pointer + feat_offset, mask=feat_mask)\n weight_output_grad_prod = weight * output_grad\n else:\n weight_output_grad_prod = output_grad\n term1 = input * tl.sum(input * weight_output_grad_prod, axis=1)\n term2 = inv_rms[:, None] * inv_rms[:, None]\n input_grad = inv_rms[:, None] * (weight_output_grad_prod - term1 *\n term2 / feat_dim)\n tl.store(input_grad_pointer, input_grad, mask=batch_mask[:, None] &\n feat_mask[None, :])\n if scale_by_weight:\n weight_grad_pointer += (weight_grad_batch_stride * batch_pid + \n weight_grad_feat_stride * feat_offset)\n tl.store(weight_grad_pointer, tl.sum(output_grad * pre_lin, axis=0),\n mask=feat_mask)\n", "category": { "Functionality": [ "Normalization", "Backpropagation" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/BobMcDear/attorch/blob/da06cb6236bb47195e33fe3986ed21c675ed94cc/attorch/rms_norm_kernels.py" }, { "uuid": "617a6f86-5188-4419-b333-c0d0a02f6e0f", "file_name": "softmax_online_v2_spec_rev_evict.py", "repo_name": "iclementine/optimize_softmax", "file_path": "softmax_online_v2_spec_rev_evict.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online_v2(output_ptr, input_ptr, M, N, TILE_N: tl.constexpr\n ):\n pid_m = tl.program_id(0)\n m = tl.full((TILE_N,), value=-float('inf'), dtype=output_ptr.dtype.\n element_ty)\n z = tl.full((TILE_N,), value=0, dtype=output_ptr.dtype.element_ty)\n prev_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, prev_multiple, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs).to(output_ptr.dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n for start_n in range(prev_multiple, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf')).to(output_ptr\n .dtype.element_ty)\n new_m = tl.maximum(m, inp)\n new_z = tl.exp(m - new_m) * z + tl.exp(inp - new_m)\n m = new_m\n z = new_z\n final_m = tl.max(m, 0)\n z = tl.sum(tl.exp(m - final_m) * z)\n m = final_m\n prev_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, TILE_N, TILE_N):\n n_offsets = prev_multiple - start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n mask = n_offsets < N\n inp = tl.load(input_ptrs, mask=mask, other=-float('inf'),\n eviction_policy='evict_first').to(output_ptr.dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out, mask=mask)\n for start_n in range(TILE_N, N, TILE_N):\n n_offsets = prev_multiple - start_n + tl.arange(0, TILE_N)\n offset = pid_m * N + n_offsets\n input_ptrs = input_ptr + offset\n inp = tl.load(input_ptrs, eviction_policy='evict_first').to(output_ptr\n .dtype.element_ty)\n e = tl.exp(inp - m)\n out = e / z\n output_ptrs = output_ptr + offset\n tl.store(output_ptrs, out)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/softmax_online_v2_spec_rev_evict.py" }, { "uuid": "ac0acde3-97ef-443c-937e-f8500c232164", "file_name": "random_matrix.py", "repo_name": "Forkxz/TritonDeepLearningKernel", "file_path": "kernel/dropconnect/random_matrix.py", "commit_hash": "add54b6318e8fa5fdbf8c7b47659de9fceaa5691", "starcount": 0, "input": "@triton.autotune(configs=[triton.Config({'BLOCK_SIZE_M': 8, 'BLOCK_SIZE_N':\n 4, 'BLOCK_SIZE_K': 32})], key=['M', 'N', 'K'])\n@triton.jit\ndef random_matrix_kernel(r_ptr, seed, M, K, N, stride_dm, stride_dk,\n stride_dn, BLOCK_SIZE_M: tl.constexpr, BLOCK_SIZE_N: tl.constexpr,\n BLOCK_SIZE_K: tl.constexpr):\n pid = tl.program_id(axis=0)\n num_pid_m = tl.cdiv(M, BLOCK_SIZE_M)\n num_pid_n = tl.cdiv(N, BLOCK_SIZE_N)\n pid_m = pid // num_pid_n\n pid_n = pid % num_pid_n\n offset_m = pid_m * BLOCK_SIZE_M\n offset_n = pid_n * BLOCK_SIZE_N\n offset_k = 0\n d_offsets = block_offsets_3d(M, K, N, stride_dm, stride_dk, stride_dn,\n offset_m, offset_k, offset_n, BLOCK_SIZE_M, BLOCK_SIZE_K, BLOCK_SIZE_N)\n offs_k = tl.arange(0, BLOCK_SIZE_K)\n for k in range(0, tl.cdiv(K, BLOCK_SIZE_K)):\n k_mask = offs_k[None, :, None] < K - k * BLOCK_SIZE_K\n random_masks = tl.random.rand(seed, d_offsets) > 0.5\n tl.store(r_ptr + d_offsets, random_masks.to(tl.int8), mask=k_mask)\n d_offsets += BLOCK_SIZE_K * stride_dk\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "int8" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/Forkxz/TritonDeepLearningKernel/blob/add54b6318e8fa5fdbf8c7b47659de9fceaa5691/kernel/dropconnect/random_matrix.py" }, { "uuid": "6670d8a8-c520-453d-87db-e31e9f5517c5", "file_name": "test_triton_basics.py", "repo_name": "tucommenceapousser/xformers", "file_path": "tests/test_triton_basics.py", "commit_hash": "c97e3d917cfdad4a38acd4e9d776030d25ab9141", "starcount": 0, "input": "@triton.jit\ndef k_mean(X, Mean, Var, stride, N, BLOCK_SIZE_N: tl.constexpr):\n \"\"\"\n Fused layernorm kernel over a 3d tensor.\n The layer norm is applied over the last dimension.\n\n Compute\n y = (x - E(x))/(sqrt(var(x) + epsilon)) * gamma + beta\n \"\"\"\n row = tl.program_id(0)\n cols = tl.arange(0, BLOCK_SIZE_N)\n x_ptrs = X + row * stride + cols\n x = tl.load(x_ptrs, mask=cols < N, other=0.0).to(tl.float32)\n x = tl.where(cols < N, x, 0.0)\n x_mean = tl.sum(x, axis=0) / N\n x_zm = x - x_mean\n x_zm = tl.where(cols < N, x_zm, 0.0)\n x_var = tl.sum(x_zm * x_zm, axis=0) / N\n tl.store(Mean + row, x_mean)\n tl.store(Var + row, x_var)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/tucommenceapousser/xformers/blob/c97e3d917cfdad4a38acd4e9d776030d25ab9141/tests/test_triton_basics.py" }, { "uuid": "52ce8da6-a14c-4648-8839-2497e5c7cd47", "file_name": "parallel.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rebased/parallel.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.jit\ndef parallel_rebased_fwd_kernel(q, k, v, o, z, s_k_h, s_k_t, s_k_d, s_v_h,\n s_v_t, s_v_d, scale, B, H, T, K: tl.constexpr, V: tl.constexpr, BTL: tl\n .constexpr, BTS: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr):\n i_kv, i_c, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2)\n NV = tl.cdiv(V, BV)\n i_k = i_kv // NV\n i_v = i_kv % NV\n p_q = tl.make_block_ptr(q + i_bh * s_k_h, (T, K), (s_k_t, s_k_d), (i_c *\n BTL, i_k * BK), (BTL, BK), (1, 0))\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, 0), (BK, BTS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (0, \n i_v * BV), (BTS, BV), (1, 0))\n b_q = tl.load(p_q, boundary_check=(0, 1))\n b_q = (b_q * scale).to(b_q.dtype)\n b_o = tl.zeros([BTL, BV], dtype=tl.float32)\n b_z = tl.zeros([BTL], dtype=tl.float32)\n for _ in range(0, i_c * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = b_s * b_s\n b_z += tl.sum(b_s, axis=1)\n b_o = b_o + tl.dot(b_s.to(b_v.dtype), b_v, allow_tf32=False)\n p_k = tl.advance(p_k, (0, BTS))\n p_v = tl.advance(p_v, (BTS, 0))\n tl.debug_barrier()\n o_q = tl.arange(0, BTL)\n o_k = tl.arange(0, BTS)\n p_k = tl.make_block_ptr(k + i_bh * s_k_h, (K, T), (s_k_d, s_k_t), (i_k *\n BK, i_c * BTL), (BK, BTS), (0, 1))\n p_v = tl.make_block_ptr(v + i_bh * s_v_h, (T, V), (s_v_t, s_v_d), (i_c *\n BTL, i_v * BV), (BTS, BV), (1, 0))\n for _ in range(i_c * BTL, (i_c + 1) * BTL, BTS):\n b_k = tl.load(p_k, boundary_check=(0, 1))\n b_v = tl.load(p_v, boundary_check=(0, 1))\n m_s = o_q[:, None] >= o_k[None, :]\n b_s = tl.dot(b_q, b_k, allow_tf32=False)\n b_s = b_s * b_s\n b_s = tl.where(m_s, b_s, 0)\n b_z += tl.sum(b_s, axis=1)\n b_o += tl.dot(b_s.to(b_q.dtype), b_v, allow_tf32=False)\n p_k = tl.advance(p_k, (0, BTS))\n p_v = tl.advance(p_v, (BTS, 0))\n o_k += BTS\n p_o = tl.make_block_ptr(o + (i_bh + B * H * i_k) * s_v_h, (T, V), (\n s_v_t, s_v_d), (i_c * BTL, i_v * BV), (BTL, BV), (1, 0))\n p_z = z + (i_bh + B * H * i_k) * T + i_c * BTL + tl.arange(0, BTL)\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1))\n tl.store(p_z, b_z.to(p_z.dtype.element_ty), mask=i_c * BTL + tl.arange(\n 0, BTL) < T)\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput", "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rebased/parallel.py" }, { "uuid": "a2f2c846-80e3-4ee0-8813-8cc6f55128f3", "file_name": "sparse_optimizer.py", "repo_name": "huyz2023/2by4-pretrain", "file_path": "sparse/sparse_optimizer.py", "commit_hash": "9e330125dea71e5a3dee235f4efb8869f9e4cdd0", "starcount": 0, "input": "@triton.autotune(configs=get_configs(), key=['m'])\n@triton.jit\ndef _inverse(F_ptr, out_ptr, F_row_stride, out_row_stride, F_col_stride,\n out_col_stride, F_page_stride, out_page_stride, m, BLOCK_SIZE: tl.constexpr\n ):\n row_idx = tl.program_id(0) * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)\n mask = row_idx < m\n a11 = tl.load(F_ptr + row_idx * F_row_stride + 0 * F_col_stride + 0 *\n F_page_stride, mask=mask)\n a12 = tl.load(F_ptr + row_idx * F_row_stride + 0 * F_col_stride + 1 *\n F_page_stride, mask=mask)\n a13 = tl.load(F_ptr + row_idx * F_row_stride + 0 * F_col_stride + 2 *\n F_page_stride, mask=mask)\n a14 = tl.load(F_ptr + row_idx * F_row_stride + 0 * F_col_stride + 3 *\n F_page_stride, mask=mask)\n a21 = tl.load(F_ptr + row_idx * F_row_stride + 1 * F_col_stride + 0 *\n F_page_stride, mask=mask)\n a22 = tl.load(F_ptr + row_idx * F_row_stride + 1 * F_col_stride + 1 *\n F_page_stride, mask=mask)\n a23 = tl.load(F_ptr + row_idx * F_row_stride + 1 * F_col_stride + 2 *\n F_page_stride, mask=mask)\n a24 = tl.load(F_ptr + row_idx * F_row_stride + 1 * F_col_stride + 3 *\n F_page_stride, mask=mask)\n a31 = tl.load(F_ptr + row_idx * F_row_stride + 2 * F_col_stride + 0 *\n F_page_stride, mask=mask)\n a32 = tl.load(F_ptr + row_idx * F_row_stride + 2 * F_col_stride + 1 *\n F_page_stride, mask=mask)\n a33 = tl.load(F_ptr + row_idx * F_row_stride + 2 * F_col_stride + 2 *\n F_page_stride, mask=mask)\n a34 = tl.load(F_ptr + row_idx * F_row_stride + 2 * F_col_stride + 3 *\n F_page_stride, mask=mask)\n a41 = tl.load(F_ptr + row_idx * F_row_stride + 3 * F_col_stride + 0 *\n F_page_stride, mask=mask)\n a42 = tl.load(F_ptr + row_idx * F_row_stride + 3 * F_col_stride + 1 *\n F_page_stride, mask=mask)\n a43 = tl.load(F_ptr + row_idx * F_row_stride + 3 * F_col_stride + 2 *\n F_page_stride, mask=mask)\n a44 = tl.load(F_ptr + row_idx * F_row_stride + 3 * F_col_stride + 3 *\n F_page_stride, mask=mask)\n det = (a11 * a22 * a33 * a44 - a12 * a23 * a34 * a41 + a13 * a24 * a31 *\n a42 - a14 * a21 * a32 * a43 + a14 * a23 * a32 * a41 - a11 * a24 *\n a33 * a42 + a12 * a21 * a34 * a43 - a13 * a22 * a31 * a44 + a12 *\n a23 * a31 * a44 - a13 * a21 * a34 * a42 + a11 * a24 * a32 * a43 - \n a14 * a22 * a33 * a41 + a14 * a21 * a33 * a42 - a12 * a24 * a31 *\n a43 + a13 * a22 * a34 * a41 - a11 * a23 * a32 * a44 + a13 * a21 *\n a32 * a44 - a11 * a22 * a34 * a43 + a12 * a24 * a33 * a41 - a14 *\n a23 * a31 * a42 + a14 * a22 * a31 * a43 - a13 * a24 * a32 * a41 + \n a11 * a23 * a34 * a42 - a12 * a21 * a33 * a44)\n c11 = (a22 * a33 * a44 + a23 * a34 * a42 + a24 * a32 * a43 - a24 * a33 *\n a42 - a23 * a32 * a44 - a22 * a34 * a43)\n c12 = -(a21 * a33 * a44 + a23 * a34 * a41 + a24 * a31 * a43 - a24 * a33 *\n a41 - a23 * a31 * a44 - a21 * a34 * a43)\n c13 = (a21 * a32 * a44 + a22 * a34 * a41 + a24 * a31 * a42 - a24 * a32 *\n a41 - a22 * a31 * a44 - a21 * a34 * a42)\n c14 = -(a21 * a32 * a43 + a22 * a33 * a41 + a23 * a31 * a42 - a23 * a32 *\n a41 - a22 * a31 * a43 - a21 * a33 * a42)\n c21 = -(a12 * a33 * a44 + a13 * a34 * a42 + a14 * a32 * a43 - a14 * a33 *\n a42 - a13 * a32 * a44 - a12 * a34 * a43)\n c22 = (a11 * a33 * a44 + a13 * a34 * a41 + a14 * a31 * a43 - a14 * a33 *\n a41 - a13 * a31 * a44 - a11 * a34 * a43)\n c23 = -(a11 * a32 * a44 + a12 * a34 * a41 + a14 * a31 * a42 - a14 * a32 *\n a41 - a12 * a31 * a44 - a11 * a34 * a42)\n c24 = (a11 * a32 * a43 + a12 * a33 * a41 + a13 * a31 * a42 - a13 * a32 *\n a41 - a12 * a31 * a43 - a11 * a33 * a42)\n c31 = (a12 * a23 * a44 + a13 * a24 * a42 + a14 * a22 * a43 - a14 * a23 *\n a42 - a13 * a22 * a44 - a12 * a24 * a43)\n c32 = -(a11 * a23 * a44 + a13 * a24 * a41 + a14 * a21 * a43 - a14 * a23 *\n a41 - a13 * a21 * a44 - a11 * a24 * a43)\n c33 = (a11 * a22 * a44 + a12 * a24 * a41 + a14 * a21 * a42 - a14 * a22 *\n a41 - a12 * a21 * a44 - a11 * a24 * a42)\n c34 = -(a11 * a22 * a43 + a12 * a23 * a41 + a13 * a21 * a42 - a13 * a22 *\n a41 - a12 * a21 * a43 - a11 * a23 * a42)\n c41 = -(a12 * a23 * a34 + a13 * a24 * a32 + a14 * a22 * a33 - a14 * a23 *\n a32 - a13 * a22 * a34 - a12 * a24 * a33)\n c42 = (a11 * a23 * a34 + a13 * a24 * a31 + a14 * a21 * a33 - a14 * a23 *\n a31 - a13 * a21 * a34 - a11 * a24 * a33)\n c43 = -(a11 * a22 * a34 + a12 * a24 * a31 + a14 * a21 * a32 - a14 * a22 *\n a31 - a12 * a21 * a34 - a11 * a24 * a32)\n c44 = (a11 * a22 * a33 + a12 * a23 * a31 + a13 * a21 * a32 - a13 * a22 *\n a31 - a12 * a21 * a33 - a11 * a23 * a32)\n tl.store(out_ptr + row_idx * out_row_stride + 0 * out_col_stride + 0 *\n out_page_stride, c11 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 0 * out_col_stride + 1 *\n out_page_stride, c21 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 0 * out_col_stride + 2 *\n out_page_stride, c31 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 0 * out_col_stride + 3 *\n out_page_stride, c41 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 1 * out_col_stride + 0 *\n out_page_stride, c12 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 1 * out_col_stride + 1 *\n out_page_stride, c22 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 1 * out_col_stride + 2 *\n out_page_stride, c32 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 1 * out_col_stride + 3 *\n out_page_stride, c42 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 2 * out_col_stride + 0 *\n out_page_stride, c13 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 2 * out_col_stride + 1 *\n out_page_stride, c23 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 2 * out_col_stride + 2 *\n out_page_stride, c33 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 2 * out_col_stride + 3 *\n out_page_stride, c43 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 3 * out_col_stride + 0 *\n out_page_stride, c14 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 3 * out_col_stride + 1 *\n out_page_stride, c24 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 3 * out_col_stride + 2 *\n out_page_stride, c34 / det, mask=mask)\n tl.store(out_ptr + row_idx * out_row_stride + 3 * out_col_stride + 3 *\n out_page_stride, c44 / det, mask=mask)\n", "category": { "Functionality": [], "Data Type": [], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/huyz2023/2by4-pretrain/blob/9e330125dea71e5a3dee235f4efb8869f9e4cdd0/sparse/sparse_optimizer.py" }, { "uuid": "464215f1-3063-4a65-8777-6e5fd10319d0", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/rwkv6/fused_recurrent.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_INITIAL_STATE': lambda args: args['dh0'] is not\n None, 'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({}, num_warps=1), triton.Config({},\n num_warps=2), triton.Config({}, num_warps=4)], key=['BK', 'BV'])\n@triton.jit\ndef fused_recurrent_rwkv6_bwd_kernel_dkv(q, k, v, w, u, do, dk, dk1, dv,\n dh0, offsets, scale, B: tl.constexpr, T: tl.constexpr, H: tl.constexpr,\n K: tl.constexpr, V: tl.constexpr, BK: tl.constexpr, BV: tl.constexpr,\n REVERSE: tl.constexpr, USE_INITIAL_STATE: tl.constexpr, USE_OFFSETS: tl\n .constexpr, HEAD_FIRST: tl.constexpr):\n i_v, i_k, i_nh = tl.program_id(0).to(tl.int64), tl.program_id(1).to(tl.\n int64), tl.program_id(2).to(tl.int64)\n i_n, i_h = i_nh // H, i_nh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_n).to(tl.int64), tl.load(offsets +\n i_n + 1).to(tl.int64)\n all = T\n T = eos - bos\n else:\n bos, eos = i_n * T, i_n * T + T\n all = B * T\n o_k = i_k * BK + tl.arange(0, BK)\n o_v = i_v * BV + tl.arange(0, BV)\n if HEAD_FIRST:\n p_q = q + i_nh * T * K + ((T - 1) * K if not REVERSE else 0) + o_k\n p_k = k + i_nh * T * K + ((T - 1) * K if not REVERSE else 0) + o_k\n p_v = v + i_nh * T * V + ((T - 1) * V if not REVERSE else 0) + o_v\n p_w = w + i_nh * T * K + ((T - 1) * K if not REVERSE else 0) + o_k\n p_do = do + i_nh * T * V + ((T - 1) * V if not REVERSE else 0) + o_v\n p_dk = dk + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if not\n REVERSE else 0) + o_k\n p_dk1 = dk1 + (i_v * B * H + i_nh) * T * K + ((T - 1) * K if not\n REVERSE else 0) + o_k\n p_dv = dv + (i_k * B * H + i_nh) * T * V + ((T - 1) * V if not\n REVERSE else 0) + o_v\n else:\n p_q = q + (bos + (T - 1 if not REVERSE else 0)) * H * K + i_h * K + o_k\n p_k = k + (bos + (T - 1 if not REVERSE else 0)) * H * K + i_h * K + o_k\n p_v = v + (bos + (T - 1 if not REVERSE else 0)) * H * V + i_h * V + o_v\n p_w = w + (bos + (T - 1 if not REVERSE else 0)) * H * K + i_h * K + o_k\n p_do = do + (bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + o_v\n p_dk = dk + (i_v * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + o_k\n p_dk1 = dk1 + (i_v * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * K + i_h * K + o_k\n p_dv = dv + (i_k * all + bos + (T - 1 if not REVERSE else 0)\n ) * H * V + i_h * V + o_v\n p_u = u + i_h * K + o_k\n mask_k = o_k < K\n mask_v = o_v < V\n mask_h = mask_k[:, None] & mask_v[None, :]\n b_u = tl.load(p_u, mask=mask_k, other=0).to(tl.float32)\n b_dh = tl.zeros([BK, BV], dtype=tl.float32)\n for _ in range(T - 1, -1, -1):\n b_q = tl.load(p_q, mask=mask_k, other=0).to(tl.float32) * scale\n b_k = tl.load(p_k, mask=mask_k, other=0).to(tl.float32)\n b_v = tl.load(p_v, mask=mask_v, other=0).to(tl.float32)\n b_w = tl.load(p_w, mask=mask_k, other=0).to(tl.float32)\n b_do = tl.load(p_do, mask=mask_v, other=0).to(tl.float32)\n b_dkv = b_q[:, None] * b_do[None, :]\n b_dk = tl.sum(b_dh * b_v[None, :], 1)\n tl.store(p_dk1, b_dk.to(p_dk1.dtype.element_ty), mask=mask_k)\n b_dk += tl.sum(b_dkv * b_u[:, None] * b_v[None, :], 1)\n b_dv = tl.sum((b_dh + b_dkv * b_u[:, None]) * b_k[:, None], 0)\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty), mask=mask_k)\n tl.store(p_dv, b_dv.to(p_dv.dtype.element_ty), mask=mask_v)\n b_dh *= tl.exp(b_w)[:, None]\n b_dh += b_dkv\n p_q += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_k += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_v += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_w += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_do += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n p_dk += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_dk1 += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * K\n p_dv += (-1 if not REVERSE else 1) * (1 if HEAD_FIRST else H) * V\n if USE_INITIAL_STATE:\n p_dh0 = dh0 + i_nh * K * V + o_k[:, None] * V + o_v[None, :]\n tl.store(p_dh0, b_dh.to(p_dh0.dtype.element_ty), mask=mask_h)\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/rwkv6/fused_recurrent.py" }, { "uuid": "9233b706-1ad9-479f-95dd-2f0d42a6e5fc", "file_name": "flash_4.py", "repo_name": "LitingLin/LoRAT", "file_path": "trackit/runner/evaluation/distributed/tracker_evaluator/components/segmentation/segment_anything_fast/flash_4.py", "commit_hash": "d7515a51174b037f122ce4ac6c56d668b0ee152b", "starcount": 0, "input": "@triton.jit\ndef _fwd_kernel_aligned(Q, K, V, B0, sm_scale, Out, stride_qh, stride_qm,\n stride_qk, stride_kh, stride_kn, stride_kk, stride_vh, stride_vk,\n stride_vn, stride_oh, stride_om, stride_on, stride_b0h, stride_b0m, Z,\n H, N_CTX, P_SEQ, OUT_DTYPE: tl.constexpr, BIAS_LAST_SIZE: tl.constexpr,\n B0_NUMEL: tl.constexpr, BLOCK_DMODEL: tl.constexpr, BLOCK_M: tl.\n constexpr, BLOCK_N: tl.constexpr):\n start_m = tl.program_id(0)\n off_hz = tl.program_id(1)\n q_offset = off_hz * stride_qh\n kv_offset = off_hz * stride_kh\n Q_block_ptr = tl.make_block_ptr(base=Q + q_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + kv_offset, shape=(BLOCK_DMODEL,\n N_CTX + P_SEQ), strides=(stride_kk, stride_kn), offsets=(0, 0),\n block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n V_block_ptr = tl.make_block_ptr(base=V + kv_offset, shape=(N_CTX +\n P_SEQ, BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0\n ), block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32)\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale * 1.44269504\n q = tl.load(Q_block_ptr)\n q = (q * qk_scale).to(OUT_DTYPE)\n lo = 0\n hi = N_CTX + P_SEQ\n b_ptr_offsets_m = tl.arange(0, BLOCK_M)\n b_offset = off_hz * stride_b0h\n b_ptr_offsets_n_1 = tl.arange(0, BLOCK_N) % BIAS_LAST_SIZE + BIAS_LAST_SIZE\n b1 = tl.load(B0 + b_offset + ((start_m * BLOCK_M + b_ptr_offsets_m) *\n stride_b0m)[:, None] + b_ptr_offsets_n_1[None, :])\n for start_n in range(lo, hi, BLOCK_N):\n k = tl.load(K_block_ptr)\n v = tl.load(V_block_ptr)\n qk = tl.zeros([BLOCK_M, BLOCK_N], dtype=OUT_DTYPE)\n qk += tl.dot(q, k)\n b0 = tl.load(B0 + b_offset + ((start_m * BLOCK_M + b_ptr_offsets_m) *\n stride_b0m)[:, None] + start_n // BLOCK_N)\n qk += (b0 + b1) * 1.44269504\n m_i_new = tl.maximum(m_i, tl.max(qk, 1))\n alpha = tl.math.exp2(m_i - m_i_new)\n p = tl.math.exp2(qk - m_i_new[:, None])\n acc *= alpha[:, None]\n acc += tl.dot(p.to(OUT_DTYPE), v)\n l_i = l_i * alpha + tl.sum(p, 1)\n m_i = m_i_new\n K_block_ptr = tl.advance(K_block_ptr, (0, BLOCK_N))\n V_block_ptr = tl.advance(V_block_ptr, (BLOCK_N, 0))\n acc = acc / l_i[:, None]\n O_block_ptr = tl.make_block_ptr(base=Out + q_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n tl.store(O_block_ptr, acc.to(OUT_DTYPE))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Coalesced" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/LitingLin/LoRAT/blob/d7515a51174b037f122ce4ac6c56d668b0ee152b/trackit/runner/evaluation/distributed/tracker_evaluator/components/segmentation/segment_anything_fast/flash_4.py" }, { "uuid": "f3027f3b-527d-4872-925c-33213b5e854d", "file_name": "outer_softmax_online.py", "repo_name": "iclementine/optimize_softmax", "file_path": "outer_softmax_online.py", "commit_hash": "6ddeee3481dd5e63f4a30b946c417e97bc4494bf", "starcount": 0, "input": "@triton.jit\ndef softmax_kernel_online(output_ptr, input_ptr, M, N, K, TILE_N: tl.\n constexpr, TILE_K: tl.constexpr):\n pid_k = tl.program_id(0)\n pid_m = tl.program_id(1)\n k_offsets = pid_k * TILE_K + tl.arange(0, TILE_K)\n m = tl.full([TILE_N, TILE_K], value=float('-inf'), dtype=tl.float32)\n z = tl.full([TILE_N, TILE_K], value=0.0, dtype=tl.float32)\n for start_n in range(0, N, TILE_N):\n n_offsets = start_n + tl.arange(0, TILE_N)\n offsets = pid_m * N * K + n_offsets[:, None] * K + k_offsets\n mask = (n_offsets[:, None] < N) & (k_offsets < K)\n inp = tl.load(input_ptr + offsets, mask=mask, other=-float('inf'))\n m_new = tl.maximum(m, inp)\n alpha = tl.exp(m - m_new)\n z = z * alpha + tl.exp(inp - m_new)\n m = m_new\n m_reduced = tl.max(m, 0)\n z = tl.sum(z * tl.exp(m - m_reduced[None, :]), 0)\n m = m_reduced\n previous_multiple = prev_multiple_of(N, TILE_N)\n for start_n in range(0, N, TILE_N):\n n_offsets = previous_multiple - start_n + tl.arange(0, TILE_N)\n offsets = pid_m * N * K + n_offsets[:, None] * K + k_offsets\n mask = (n_offsets[:, None] < N) & (k_offsets[None, :] < K)\n inp = tl.load(input_ptr + offsets, mask=mask, other=-float('inf'))\n o = tl.exp(inp - m[None, :]) / z[None, :]\n tl.store(output_ptr + offsets, o, mask=mask)\n", "category": { "Functionality": [ "Softmax" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/iclementine/optimize_softmax/blob/6ddeee3481dd5e63f4a30b946c417e97bc4494bf/outer_softmax_online.py" }, { "uuid": "df855118-c357-4a08-a639-b101eb791b9c", "file_name": "fused_recurrent.py", "repo_name": "sustcsonglin/hope-fla", "file_path": "fla/ops/hope/fused_recurrent.py", "commit_hash": "0750c9a9a360fb72236dfaaaf21496959c5ef48d", "starcount": 0, "input": "@triton.jit\ndef fused_recurrent_bwd_kernel(q, k, k_l2, dq, dk, dk_l2, dk_l2_partial_fwd,\n dk_l2_partial_bwd, dq_reflected, dk_reflected, T, D: tl.constexpr, BK:\n tl.constexpr):\n i_b, i_h = tl.program_id(0), tl.program_id(1)\n d_h = tl.zeros([BK, BK], dtype=tl.float32)\n offset = i_b * T * D + i_h * BK + tl.arange(0, BK) + (T - 1) * D\n p_q = q + offset\n p_k = k + offset\n p_k_l2 = k_l2 + offset\n p_dq_reflected = dq_reflected + offset\n p_dk_reflected = dk_reflected + offset\n p_dq = dq + offset\n p_dk = dk + offset\n p_dk_l2 = dk_l2 + offset\n p_dk_l2_partial_fwd = dk_l2_partial_fwd + offset\n p_dk_l2_partial_bwd = dk_l2_partial_bwd + offset\n for _ in range(T):\n b_q = tl.load(p_q).to(tl.float32)\n b_k = tl.load(p_k).to(tl.float32)\n b_k_l2 = tl.load(p_k_l2).to(tl.float32)\n b_dq_reflected = tl.load(p_dq_reflected).to(tl.float32)\n b_dk_reflected = tl.load(p_dk_reflected).to(tl.float32)\n d_h += b_q[None, :] * b_dq_reflected[:, None] + b_k[None, :\n ] * b_dk_reflected[:, None]\n b_dk_l2_partial_fwd = tl.load(p_dk_l2_partial_fwd).to(tl.float32)\n b_dk_l2 = -2 * tl.sum(b_dk_l2_partial_fwd[:, None] * d_h, axis=0)\n tl.store(p_dk_l2, b_dk_l2.to(p_dk_l2.dtype.element_ty))\n b_dk_l2_partial = tl.sum(d_h * b_k_l2[None, :], axis=1)\n d_h -= 2 * b_k_l2[None, :] * b_dk_l2_partial[:, None]\n tl.store(p_dk_l2_partial_bwd, b_dk_l2_partial.to(\n p_dk_l2_partial_bwd.dtype.element_ty))\n p_dq_reflected -= D\n p_dk_reflected -= D\n p_q -= D\n p_k -= D\n p_k_l2 -= D\n p_dk_l2_partial_fwd -= D\n p_dk_l2_partial_bwd -= D\n p_dk_l2 -= D\n tl.debug_barrier()\n offset = i_b * T * D + i_h * BK + tl.arange(0, BK)\n p_q = q + offset\n p_k = k + offset\n p_k_l2 = k_l2 + offset\n p_dq_reflected = dq_reflected + offset\n p_dk_reflected = dk_reflected + offset\n p_dq = dq + offset\n p_dk = dk + offset\n p_dk_l2 = dk_l2 + offset\n p_dk_l2_partial_bwd = dk_l2_partial_bwd + offset\n h = tl.zeros([BK, BK], dtype=tl.float32) + (tl.arange(0, BK)[:, None] ==\n tl.arange(0, BK)[None, :])\n for _ in range(T):\n b_k_l2 = tl.load(p_k_l2).to(tl.float32)\n b_dk_l2_partial = tl.load(p_dk_l2_partial_bwd).to(tl.float32)\n b_dk_l2 = -2 * tl.sum(h * b_dk_l2_partial[:, None], axis=0)\n b_dk_l2 += tl.load(p_dk_l2)\n tl.store(p_dk_l2, b_dk_l2.to(p_dk_l2.dtype.element_ty))\n tmp = tl.sum(h * b_k_l2[None, :], axis=1)\n h -= 2 * b_k_l2[None, :] * tmp[:, None]\n b_dq_reflected = tl.load(p_dq_reflected).to(tl.float32)\n b_dk_reflected = tl.load(p_dk_reflected).to(tl.float32)\n b_dq = tl.sum(b_dq_reflected[:, None] * h, axis=0)\n b_dk = tl.sum(b_dk_reflected[:, None] * h, axis=0)\n tl.store(p_dq, b_dq.to(p_dq.dtype.element_ty))\n tl.store(p_dk, b_dk.to(p_dk.dtype.element_ty))\n p_q += D\n p_k += D\n p_k_l2 += D\n p_dq_reflected += D\n p_dk_reflected += D\n p_dk_l2 += D\n p_dk_l2_partial_bwd += D\n p_dq += D\n p_dk += D\n", "category": { "Functionality": [ "Backpropagation", "Recurrent Neural Networks" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled", "Blocked Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/hope-fla/blob/0750c9a9a360fb72236dfaaaf21496959c5ef48d/fla/ops/hope/fused_recurrent.py" }, { "uuid": "2f55269a-e5f4-4bb7-88a8-6d4fb70c6ff0", "file_name": "rope.py", "repo_name": "dame-cell/Triformer", "file_path": "triformer/rope.py", "commit_hash": "0712537d576166b93fa09aa9509b2661b9ed8a68", "starcount": 0, "input": "@triton.heuristics({'BACKWARD_PASS': lambda args: bool(args['BACKWARD_PASS'])})\n@triton.jit\ndef _rope_embedding(Q, Q_row_stride, cos, cos_row_stride, sin,\n sin_row_stride, seqlen, head_dim: tl.constexpr, n_heads: tl.constexpr,\n BACKWARD_PASS: tl.constexpr, BLOCK_SIZE: tl.constexpr):\n \"\"\"\n Calculates the RoPE Embedding quickly\n RoPE is Q * cos + rotate_half(Q) * sin\n See our blog post for more info\n \"\"\"\n ROPE_GROUP_SIZE = 4\n row_position = tl.program_id(0)\n group_head_position = tl.program_id(1)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n half_head_dim = head_dim // 2\n mask = col_offsets < half_head_dim\n sin1 = tl.load(sin + row_position % seqlen * sin_row_stride + \n half_head_dim * 0 + col_offsets, mask=mask, other=0)\n cos1 = tl.load(cos + row_position % seqlen * cos_row_stride + \n half_head_dim * 0 + col_offsets, mask=mask, other=0)\n if BACKWARD_PASS:\n sin1 = -sin1\n pass\n head_start = group_head_position * ROPE_GROUP_SIZE\n head_end = min(head_start + ROPE_GROUP_SIZE, n_heads)\n for k in range(head_start, head_end):\n offs_q1 = row_position * Q_row_stride + k * head_dim + col_offsets\n offs_q2 = (row_position * Q_row_stride + k * head_dim + col_offsets +\n half_head_dim)\n Q1 = tl.load(Q + offs_q1, mask=mask, other=0).to(sin1.dtype)\n Q2 = tl.load(Q + offs_q2, mask=mask, other=0).to(sin1.dtype)\n tl.store(Q + offs_q1, Q1 * cos1 - Q2 * sin1, mask=mask)\n tl.store(Q + offs_q2, Q2 * cos1 + Q1 * sin1, mask=mask)\n pass\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Coalesced" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/dame-cell/Triformer/blob/0712537d576166b93fa09aa9509b2661b9ed8a68/triformer/rope.py" }, { "uuid": "0556f753-1a94-4e65-a541-a0d3c5e13c41", "file_name": "cumsum.py", "repo_name": "sustcsonglin/flash-linear-attention", "file_path": "fla/ops/utils/cumsum.py", "commit_hash": "5968de9a22c096326b19859cfe05dac36155c31d", "starcount": 0, "input": "@triton.heuristics({'USE_OFFSETS': lambda args: args['offsets'] is not None})\n@triton.autotune(configs=[triton.Config({'BT': 16}, num_warps=2), triton.\n Config({'BT': 32}, num_warps=4), triton.Config({'BT': 32}, num_warps=2),\n triton.Config({'BT': 64}, num_warps=8), triton.Config({'BT': 64},\n num_warps=4)], key=[])\n@triton.jit\ndef chunk_global_reversed_cumsum_scalar_kernel(s, o, offsets, T: tl.\n constexpr, H: tl.constexpr, BT: tl.constexpr, HEAD_FIRST: tl.constexpr,\n USE_OFFSETS: tl.constexpr):\n i_bh = tl.program_id(0)\n i_b, i_h = i_bh // H, i_bh % H\n if USE_OFFSETS:\n bos, eos = tl.load(offsets + i_b).to(tl.int32), tl.load(offsets +\n i_b + 1).to(tl.int32)\n else:\n bos, eos = i_b * T, i_b * T + T\n T = eos - bos\n b_z = tl.zeros([], dtype=tl.float32)\n for i_t in range(tl.cdiv(T, BT) - 1, -1, -1):\n if HEAD_FIRST:\n p_s = tl.make_block_ptr(s + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n p_o = tl.make_block_ptr(o + i_bh * T, (T,), (1,), (i_t * BT,),\n (BT,), (0,))\n else:\n p_s = tl.make_block_ptr(s + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n p_o = tl.make_block_ptr(o + bos * H + i_h, (T,), (H,), (i_t *\n BT,), (BT,), (0,))\n b_s = tl.load(p_s, boundary_check=(0,)).to(tl.float32)\n b_zz = tl.sum(b_s, axis=0)\n b_z += b_zz\n b_o = b_s - tl.cumsum(b_s, axis=0) + b_z[None]\n tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0,))\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/sustcsonglin/flash-linear-attention/blob/5968de9a22c096326b19859cfe05dac36155c31d/fla/ops/utils/cumsum.py" }, { "uuid": "11947c31-82e7-420d-82ef-4b852131022a", "file_name": "rmsnorm.py", "repo_name": "ardywibowo/triton-mode", "file_path": "kernels/rmsnorm.py", "commit_hash": "5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1", "starcount": 0, "input": "@triton.jit\ndef triton_rmsnorm_forward(Y_ptr, Y_row_stride, X_ptr, X_row_stride, W_ptr,\n RSTD_ptr, RSTD_row_stride, n_cols, eps, offset, BLOCK_SIZE: tl.constexpr):\n row_idx = tl.program_id(0)\n col_offsets = tl.arange(0, BLOCK_SIZE)\n mask = col_offsets < n_cols\n Y_ptr += row_idx * Y_row_stride\n X_ptr += row_idx * X_row_stride\n RSTD_ptr += row_idx * RSTD_row_stride\n X_row = tl.load(X_ptr + col_offsets, mask=mask, other=0)\n X_row_dtype = X_row.dtype\n W_row = tl.load(W_ptr + col_offsets, mask=mask, other=0)\n X_row = X_row.to(tl.float32)\n mean_square = tl.sum(X_row * X_row, axis=0) / n_cols\n rstd = tl.libdevice.rsqrt(mean_square + eps)\n tl.store(RSTD_ptr, rstd)\n X_row = X_row * rstd\n X_row = X_row.to(X_row_dtype)\n Y_row = X_row * (offset + W_row)\n tl.store(Y_ptr + col_offsets, Y_row, mask=mask)\n", "category": { "Functionality": [ "Normalization" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/ardywibowo/triton-mode/blob/5cd773ec95e25e23c6b75e312c7a9a1c6eb650b1/kernels/rmsnorm.py" }, { "uuid": "c11fd5e3-13e4-4c89-b431-45f0b4f5fe6c", "file_name": "linear.py", "repo_name": "neuro-ml/kerops", "file_path": "kerops/kernels/linear.py", "commit_hash": "735336775e825d5cb06b8850d25423661b12d1ac", "starcount": 0, "input": "@triton.jit\ndef _ReLULinearAddBackward(input_ptr, grad_ptr, input_grad_ptr, weight_ptr,\n weight_grad_ptr, numel_no_channels, in_channels: tl.constexpr,\n out_channels: tl.constexpr, D_block: tl.constexpr, _ILP: tl.constexpr):\n pid = tl.program_id(0)\n input_ptr += pid * _ILP * in_channels * D_block\n grad_ptr += pid * _ILP * out_channels * D_block\n input_grad_ptr += pid * _ILP * in_channels * D_block\n weight_grad_ptr += pid * in_channels * out_channels\n in_channels_offset = tl.arange(0, in_channels)\n out_channels_offset = tl.arange(0, out_channels)\n d_offset = tl.arange(0, D_block)\n input_offset = d_offset[:, None] * in_channels + in_channels_offset[None, :\n ]\n output_offset = d_offset[:, None] * out_channels + out_channels_offset[\n None, :]\n weight_offset = out_channels_offset[:, None] + in_channels_offset[None, :\n ] * out_channels\n weight_grad_offset = in_channels_offset[:, None\n ] * out_channels + out_channels_offset[None, :]\n weight = tl.load(weight_ptr + weight_offset)\n weight_grad = tl.zeros([in_channels, out_channels], dtype=tl.float32)\n for i in tl.static_range(0, _ILP):\n mask = d_offset[:, None] < numel_no_channels - (pid * _ILP + i\n ) * D_block\n input = tl.load(input_ptr + input_offset, mask=mask, other=0.0)\n grad = tl.load(grad_ptr + output_offset, mask=mask, other=0.0)\n weight_grad += tl.dot(tl.trans(tl.maximum(input, 0.0).to(tl.float16\n )), grad, out_dtype=tl.float32, allow_tf32=True)\n input_grad = tl.dot(grad, weight, out_dtype=tl.float32, allow_tf32=True\n ).to(tl.float16) * (input > 0)\n tl.store(input_grad_ptr + input_offset, input_grad, mask=mask)\n grad_ptr += out_channels * D_block\n input_grad_ptr += in_channels * D_block\n input_ptr += in_channels * D_block\n tl.store(weight_grad_ptr + weight_grad_offset, weight_grad)\n", "category": { "Functionality": [ "Backpropagation", "Activation Functions" ], "Data Type": [ "fp16", "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/neuro-ml/kerops/blob/735336775e825d5cb06b8850d25423661b12d1ac/kerops/kernels/linear.py" }, { "uuid": "ffe33cc0-6fd8-45d2-bdf4-eedd126fdd10", "file_name": "flash_attention_fwd_benchmark.py", "repo_name": "intel/intel-xpu-backend-for-triton", "file_path": "benchmarks/triton_kernels_benchmark/flash_attention_fwd_benchmark.py", "commit_hash": "6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2", "starcount": 0, "input": "@triton.jit\ndef _attn_fwd(Q, K, V, sm_scale, M, Out, stride_qz: tl.constexpr, stride_qh:\n tl.constexpr, stride_qm: tl.constexpr, stride_qk: tl.constexpr,\n stride_kz: tl.constexpr, stride_kh: tl.constexpr, stride_kn: tl.\n constexpr, stride_kk: tl.constexpr, stride_vz: tl.constexpr, stride_vh:\n tl.constexpr, stride_vk: tl.constexpr, stride_vn: tl.constexpr,\n stride_oz: tl.constexpr, stride_oh: tl.constexpr, stride_om: tl.\n constexpr, stride_on: tl.constexpr, Z: tl.constexpr, H: tl.constexpr,\n N_CTX: tl.constexpr, BLOCK_M: tl.constexpr, BLOCK_DMODEL: tl.constexpr,\n BLOCK_N: tl.constexpr, STAGE: tl.constexpr):\n start_m = tl.program_id(2)\n off_z = tl.program_id(0)\n off_h = tl.program_id(1)\n qvk_offset = off_z.to(tl.int64) * stride_qz + off_h.to(tl.int64\n ) * stride_qh\n if N_CTX <= 512:\n start_m = tl.program_id(0)\n off_z = tl.program_id(2)\n qvk_offset = off_z.to(tl.int64) * stride_qh\n Q_block_ptr = tl.make_block_ptr(base=Q + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_qm, stride_qk), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n V_block_ptr = tl.make_block_ptr(base=V + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_vk, stride_vn), offsets=(0, 0),\n block_shape=(BLOCK_N, BLOCK_DMODEL), order=(1, 0))\n K_block_ptr = tl.make_block_ptr(base=K + qvk_offset, shape=(\n BLOCK_DMODEL, N_CTX), strides=(stride_kk, stride_kn), offsets=(0, 0\n ), block_shape=(BLOCK_DMODEL, BLOCK_N), order=(0, 1))\n O_block_ptr = tl.make_block_ptr(base=Out + qvk_offset, shape=(N_CTX,\n BLOCK_DMODEL), strides=(stride_om, stride_on), offsets=(start_m *\n BLOCK_M, 0), block_shape=(BLOCK_M, BLOCK_DMODEL), order=(1, 0))\n offs_m = start_m * BLOCK_M + tl.arange(0, BLOCK_M)\n offs_n = tl.arange(0, BLOCK_N)\n m_i = tl.zeros([BLOCK_M], dtype=tl.float32) - float('inf')\n l_i = tl.zeros([BLOCK_M], dtype=tl.float32) + 1.0\n acc = tl.zeros([BLOCK_M, BLOCK_DMODEL], dtype=tl.float32)\n qk_scale = sm_scale\n qk_scale *= 1.44269504\n q = tl.load(Q_block_ptr)\n if STAGE & 1:\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, BLOCK_DMODEL, BLOCK_N,\n 4 - STAGE, offs_m, offs_n, N_CTX)\n if STAGE & 2:\n tl.debug_barrier()\n acc, l_i, m_i = _attn_fwd_inner(acc, l_i, m_i, q, K_block_ptr,\n V_block_ptr, start_m, qk_scale, BLOCK_M, BLOCK_DMODEL, BLOCK_N,\n 2, offs_m, offs_n, N_CTX)\n m_i += tl.math.log2(l_i)\n acc = acc / l_i[:, None]\n tl.store(O_block_ptr, acc.to(Out.type.element_ty))\n", "category": { "Functionality": [ "Attention Mechanisms" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound", "High Throughput" ], "Parallelization Strategy": [ "Thread-Block Mappings" ], "Memory Access Pattern": [ "Tiled" ] }, "licenses": [ "MIT" ], "github_url": "https://github.com/intel/intel-xpu-backend-for-triton/blob/6ee08cd29ec3cd8b8eb3f92b9c93977fc6f6e5c2/benchmarks/triton_kernels_benchmark/flash_attention_fwd_benchmark.py" }, { "uuid": "6c2b085e-9a9b-4d4a-8365-f732191bf5c6", "file_name": "y_5.py", "repo_name": "IntelLabs/EquiTriton", "file_path": "src/equitriton/sph_harm/direct/y_5.py", "commit_hash": "1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c", "starcount": 0, "input": "@triton.jit\ndef fifth_order_fwd(coord_ptr: tl.tensor, output_ptr: tl.tensor, block_size:\n tl.constexpr, coord_numel: tl.constexpr, output_numel: tl.constexpr,\n col_offset: tl.constexpr, output_stride: tl.constexpr):\n coord_stride = 3\n block_id = tl.program_id(0)\n coord_striding = tl.arange(0, block_size) * coord_stride\n coord_row_offset = coord_striding + block_size * coord_stride * block_id\n x = tl.load(coord_ptr + coord_row_offset, mask=coord_row_offset <\n coord_numel)\n y = tl.load(coord_ptr + coord_row_offset + 1, mask=coord_row_offset + 1 <\n coord_numel)\n z = tl.load(coord_ptr + coord_row_offset + 2, mask=coord_row_offset + 2 <\n coord_numel)\n CONST000 = 1.73430461568895\n CONST001 = 2.32681380862329\n CONST002 = 1.60565407233314\n CONST003 = 3.21130814466628\n CONST004 = 3.3166247903554\n CONST005 = 6.21867148191637\n CONST006 = 6.21867148191637\n CONST007 = 1.60565407233314\n CONST009 = 11.6340690431164\n CONST010 = 12.8452325786651\n CONST011 = 12.4373429638327\n CONST012 = 12.8452325786651\n CONST013 = 13.8744369255116\n CONST017 = 33.9852909359329\n CONST018 = 7.35803132638072\n CONST020 = -44.1481879582843\n CONST021 = -41.6233107765348\n CONST022 = -29.4321253055229\n CONST023 = -23.2681380862329\n CONST024 = -19.2678488679977\n CONST025 = -19.2678488679977\n CONST026 = -16.9926454679664\n CONST027 = -16.9926454679664\n CONST028 = -13.8744369255116\n CONST029 = -16.583123951777\n CONST030 = 3.4686092313779\n CONST031 = -8.49632273398321\n CONST032 = -5.20291384706685\n CONST033 = -3.4686092313779\n CONST034 = -1.73430461568895\n VAR05 = x * x * x * x * x\n VAR06 = x * x * x * x\n VAR07 = x * x * x\n VAR08 = x * x\n VAR14 = y * y * y * y * y\n VAR15 = y * y * y * y\n VAR16 = y * y * y\n VAR17 = y * y\n VAR23 = z * z * z * z * z\n VAR24 = z * z * z * z\n VAR25 = z * z * z\n VAR26 = z * z\n Y00 = CONST001 * VAR05 + CONST009 * VAR24 * x + CONST023 * VAR07 * VAR26\n Y01 = y * (CONST022 * VAR07 * z - CONST022 * VAR25 * x)\n Y02 = CONST000 * VAR05 + VAR07 * (CONST028 * VAR17 + CONST033 * VAR26\n ) + x * (-CONST021 * VAR17 * VAR26 + CONST032 * VAR24)\n Y03 = CONST027 * VAR07 * y * z + x * (CONST017 * VAR16 * z + CONST026 *\n VAR25 * y)\n Y04 = CONST002 * VAR05 + VAR07 * (CONST003 * VAR26 + CONST025 * VAR17\n ) + x * (CONST002 * VAR24 + CONST010 * VAR15 + CONST024 * VAR17 * VAR26\n )\n Y05 = CONST004 * VAR14 + VAR16 * (CONST029 * VAR08 + CONST029 * VAR26\n ) + y * (CONST005 * VAR06 + CONST006 * VAR24 + CONST011 * VAR08 * VAR26\n )\n Y06 = CONST002 * VAR23 + VAR25 * (CONST003 * VAR08 + CONST024 * VAR17\n ) + z * (CONST007 * VAR06 + CONST012 * VAR15 + CONST024 * VAR08 * VAR17\n )\n Y07 = VAR16 * (CONST026 * VAR08 - CONST026 * VAR26) + y * (-CONST031 *\n VAR06 + CONST031 * VAR24)\n Y08 = CONST034 * VAR23 + VAR25 * (CONST013 * VAR17 + CONST030 * VAR08\n ) + z * (CONST021 * VAR08 * VAR17 - CONST032 * VAR06)\n Y09 = y * (CONST018 * VAR06 + CONST018 * VAR24 + CONST020 * VAR08 * VAR26)\n Y10 = CONST001 * VAR23 + CONST009 * VAR06 * z + CONST023 * VAR08 * VAR25\n output_striding = tl.arange(0, block_size) * output_stride\n output_row_offset = (output_striding + block_size * output_stride *\n block_id + col_offset)\n tl.store(output_ptr + output_row_offset, Y00, mask=output_row_offset <\n output_numel)\n tl.store(output_ptr + output_row_offset + 1, Y01, mask=\n output_row_offset + 1 < output_numel)\n tl.store(output_ptr + output_row_offset + 2, Y02, mask=\n output_row_offset + 2 < output_numel)\n tl.store(output_ptr + output_row_offset + 3, Y03, mask=\n output_row_offset + 3 < output_numel)\n tl.store(output_ptr + output_row_offset + 4, Y04, mask=\n output_row_offset + 4 < output_numel)\n tl.store(output_ptr + output_row_offset + 5, Y05, mask=\n output_row_offset + 5 < output_numel)\n tl.store(output_ptr + output_row_offset + 6, Y06, mask=\n output_row_offset + 6 < output_numel)\n tl.store(output_ptr + output_row_offset + 7, Y07, mask=\n output_row_offset + 7 < output_numel)\n tl.store(output_ptr + output_row_offset + 8, Y08, mask=\n output_row_offset + 8 < output_numel)\n tl.store(output_ptr + output_row_offset + 9, Y09, mask=\n output_row_offset + 9 < output_numel)\n tl.store(output_ptr + output_row_offset + 10, Y10, mask=\n output_row_offset + 10 < output_numel)\n", "category": { "Functionality": [ "Elementwise Operations" ], "Data Type": [ "fp32" ], "Performance Objective": [ "Compute Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "Apache" ], "github_url": "https://github.com/IntelLabs/EquiTriton/blob/1cbf04f69b512a5c1d8ff4880dbf6e17fe089d4c/src/equitriton/sph_harm/direct/y_5.py" }, { "uuid": "a0b42e56-4bd9-44e8-83f0-ca330317f885", "file_name": "fp8_matmul.py", "repo_name": "drisspg/transformer_nuggets", "file_path": "transformer_nuggets/fp8/fp8_matmul.py", "commit_hash": "a4c66bbeebaa479ad8b6ed82d7efbafa41b17260", "starcount": 0, "input": "@triton.jit\ndef load_scales(a_scale_ptr, b_scale_ptr, ROW_WISE_SCALING: tl.constexpr):\n if ROW_WISE_SCALING:\n return a_scale_ptr, b_scale_ptr\n else:\n a_scale = tl.load(a_scale_ptr)\n b_scale = tl.load(b_scale_ptr)\n return a_scale, b_scale\n", "category": { "Functionality": [], "Data Type": [ "fp32" ], "Performance Objective": [ "Memory-Bound" ], "Parallelization Strategy": [ "Grid-Stride Loops" ], "Memory Access Pattern": [ "Strided Access" ] }, "licenses": [ "BSD" ], "github_url": "https://github.com/drisspg/transformer_nuggets/blob/a4c66bbeebaa479ad8b6ed82d7efbafa41b17260/transformer_nuggets/fp8/fp8_matmul.py" } ]