// Copyright © 2023-2025 Advanced Micro Devices, Inc.
// SPDX-License-Identifier: MIT

#include "../shim.attn_fwd.h"
#include <aotriton/_internal/triton_kernel.h>
#include <aotriton/_internal/kernel_cluster.h>
#include <aotriton/_internal/log.h>
#include <aotriton/cpp_tune.h>
#include <assert.h>
#include <string_view>

#define CURRENT_ENTRY_PUBLIC Autotune_attn_fwd__A0__F24

#define ARRAY_SIZE(array)  (sizeof(array) / sizeof(array[0]))

namespace { // Anonymous namespace

using namespace std::literals::string_view_literals;

#if AOTRITON_BUILD_FOR_TUNING
// PSels and Copts in JSON String
static const char* kernel_psels[] = {
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 32, "BLOCK_N": 16, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 32, "PRE_LOAD_V": false, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 32, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 32, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 32, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 32, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 32, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 64, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 64, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 64, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 64, "BLOCK_N": 64, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 128, "BLOCK_N": 128, "PRE_LOAD_V": false, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 128, "BLOCK_N": 128, "PRE_LOAD_V": false, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 128, "BLOCK_N": 128, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 128, "BLOCK_N": 128, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 256, "BLOCK_N": 64, "PRE_LOAD_V": false, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 256, "BLOCK_N": 64, "PRE_LOAD_V": false, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 256, "BLOCK_N": 64, "PRE_LOAD_V": false, "NUM_XCDS": 8})xyzw",
  R"xyzw({"PERSISTENT_TYPE": 0, "GRID_CU_MULTIP": 2, "BLOCK_M": 256, "BLOCK_N": 64, "PRE_LOAD_V": true, "NUM_XCDS": 8})xyzw"
};
static const char* kernel_copts[] = {
  R"xyzw({"waves_per_eu": 3, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 1, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 1, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 2, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 2, "num_warps": 4, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 3, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 4, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 1, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 2, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 3, "num_warps": 2, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 4, "num_warps": 4, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 1, "num_warps": 4, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 2, "num_warps": 4, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 1, "num_warps": 4, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 2, "num_warps": 4, "num_stages": 1})xyzw",
  R"xyzw({"waves_per_eu": 1, "num_warps": 8, "num_stages": 4})xyzw",
  R"xyzw({"waves_per_eu": 2, "num_warps": 8, "num_stages": 4})xyzw",
  R"xyzw({"waves_per_eu": 3, "num_warps": 8, "num_stages": 4})xyzw",
  R"xyzw({"waves_per_eu": 3, "num_warps": 8, "num_stages": 4})xyzw"
};
#endif

struct PerfFields {
  int16_t BLOCK_M;
    int16_t BLOCK_N;
    int8_t  PERSISTENT_TYPE;
    int8_t  GRID_CU_MULTIP;
    int8_t  NUM_XCDS;
    bool    PRE_LOAD_V;
};

static PerfFields image_perf_list [] = {
    { .BLOCK_M = 32, .BLOCK_N = 16, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 32, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = false },
    { .BLOCK_M = 64, .BLOCK_N = 32, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 32, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 32, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 32, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 32, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 64, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 128, .BLOCK_N = 128, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = false },
    { .BLOCK_M = 128, .BLOCK_N = 128, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = false },
    { .BLOCK_M = 128, .BLOCK_N = 128, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 128, .BLOCK_N = 128, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true },
    { .BLOCK_M = 256, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = false },
    { .BLOCK_M = 256, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = false },
    { .BLOCK_M = 256, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = false },
    { .BLOCK_M = 256, .BLOCK_N = 64, .PERSISTENT_TYPE = 0, .GRID_CU_MULTIP = 2, .NUM_XCDS = 8, .PRE_LOAD_V = true }
};

// u8R generates char8_t which is poorly supported almost everywhere.
// TODO: deduplicate FLATZIP_PATH via shim.cc packed_string
constexpr pstring_view FLATZIP_PATH
#if defined(_WIN32)
{ LR"xyzw(amd-gfx950/flash/attn_fwd.zip)xyzw" };
#else
{ R"xyzw(amd-gfx950/flash/attn_fwd.zip)xyzw" };
#endif
constexpr std::string_view FUNC_NAME   { R"xyzw(Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0)xyzw"   };
constexpr std::string_view ARCH_NAME { R"xyzw(gfx950)xyzw" };

// Checksum can be confirmed with `echo -n '<string>' | b2sum -l 64`
// For example:
//   $ echo -n 'amd-gfx110x/flash/attn_fwd/FONLY__^bf16@16,128,False,False,0,0___gfx1100__P__32_32_0_2_False__CO__wave3_warp2_stg1-Gpu-gfx1100' | b2sum -l 64
//   c4b51ee645d79580  -
static AOTRITON_NS::TritonKernelCompactMeta meta_list[] = {
    { 0xe96fd6a7u, 0xea2d207cu, 0, 84 }, // e96fd6a7ea2d207c = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=32;BLOCK_N=16;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=3;num_warps=2;num_stages=1;;arch=gfx950
    { 0xe3806018u, 0x3106e423u, 124, 209 }, // e38060183106e423 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=32;PRE_LOAD_V=False;NUM_XCDS=8;;#CO;waves_per_eu=1;num_warps=2;num_stages=1;;arch=gfx950
    { 0x79c973e2u, 0x74fb7983u, 249, 209 }, // 79c973e274fb7983 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=32;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=1;num_warps=2;num_stages=1;;arch=gfx950
    { 0xced12c37u, 0xf91ddfa9u, 249, 333 }, // ced12c37f91ddfa9 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=32;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=2;num_warps=2;num_stages=1;;arch=gfx950
    { 0x80e2d541u, 0x1937cf07u, 249, 373 }, // 80e2d5411937cf07 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=32;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=2;num_warps=4;num_stages=1;;arch=gfx950
    { 0x5d1a5cdbu, 0xa3c4da1au, 249, 84 }, // 5d1a5cdba3c4da1a = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=32;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=3;num_warps=2;num_stages=1;;arch=gfx950
    { 0xaa54ffd0u, 0xddb24111u, 249, 413 }, // aa54ffd0ddb24111 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=32;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=4;num_warps=2;num_stages=1;;arch=gfx950
    { 0x8f1c8ce6u, 0x832c1272u, 453, 209 }, // 8f1c8ce6832c1272 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=64;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=1;num_warps=2;num_stages=1;;arch=gfx950
    { 0xf6e0f440u, 0x19d3d866u, 453, 333 }, // f6e0f44019d3d866 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=64;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=2;num_warps=2;num_stages=1;;arch=gfx950
    { 0xe2d8db27u, 0x466690a4u, 453, 84 }, // e2d8db27466690a4 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=64;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=3;num_warps=2;num_stages=1;;arch=gfx950
    { 0xf26ef885u, 0x0d3ee07fu, 453, 537 }, // f26ef8850d3ee07f = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=64;BLOCK_N=64;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=4;num_warps=4;num_stages=1;;arch=gfx950
    { 0xcde1827du, 0xe05e6c8bu, 577, 664 }, // cde1827de05e6c8b = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=128;BLOCK_N=128;PRE_LOAD_V=False;NUM_XCDS=8;;#CO;waves_per_eu=1;num_warps=4;num_stages=1;;arch=gfx950
    { 0x0a44e522u, 0xa2a0a7d8u, 577, 373 }, // 0a44e522a2a0a7d8 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=128;BLOCK_N=128;PRE_LOAD_V=False;NUM_XCDS=8;;#CO;waves_per_eu=2;num_warps=4;num_stages=1;;arch=gfx950
    { 0x6196cc08u, 0x494c93afu, 704, 664 }, // 6196cc08494c93af = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=128;BLOCK_N=128;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=1;num_warps=4;num_stages=1;;arch=gfx950
    { 0xb14a92f9u, 0xd63bebacu, 704, 373 }, // b14a92f9d63bebac = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=128;BLOCK_N=128;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=2;num_warps=4;num_stages=1;;arch=gfx950
    { 0xb2dba330u, 0x77550eb4u, 790, 876 }, // b2dba33077550eb4 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=256;BLOCK_N=64;PRE_LOAD_V=False;NUM_XCDS=8;;#CO;waves_per_eu=1;num_warps=8;num_stages=4;;arch=gfx950
    { 0x37526c89u, 0x3a465d44u, 790, 916 }, // 37526c893a465d44 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=256;BLOCK_N=64;PRE_LOAD_V=False;NUM_XCDS=8;;#CO;waves_per_eu=2;num_warps=8;num_stages=4;;arch=gfx950
    { 0x5dc2da20u, 0x47f4ffddu, 790, 956 }, // 5dc2da2047f4ffdd = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=256;BLOCK_N=64;PRE_LOAD_V=False;NUM_XCDS=8;;#CO;waves_per_eu=3;num_warps=8;num_stages=4;;arch=gfx950
    { 0xcb4efd84u, 0x2e33e851u, 996, 956 }, // cb4efd842e33e851 = b2sum -l 64 <<< amd-gfx950/flash/attn_fwd.zip;;#F;Q='*fp16:16';BLOCK_DMODEL=32;PADDED_HEAD=True;ENABLE_DROPOUT=False;CAUSAL_TYPE=0;BIAS_TYPE=0;;#P;PERSISTENT_TYPE=0;GRID_CU_MULTIP=2;BLOCK_M=256;BLOCK_N=64;PRE_LOAD_V=True;NUM_XCDS=8;;#CO;waves_per_eu=3;num_warps=8;num_stages=4;;arch=gfx950
};

static constexpr int kTotalNumKernels = ARRAY_SIZE(meta_list);

using AOTRITON_NS::v3::flash::autotune::attn_fwd_packed_string;

static AOTRITON_NS::TritonKernelCluster<kTotalNumKernels>
kernel_cluster(meta_list,
               attn_fwd_packed_string);

static int8_t lut[1][10][10] =
{
// GPU gfx950_mod0
{{ 0, 5,10,10,10,13,13,13,12,13},
 { 5, 4,10,10,13,13,12,13,13,14},
 { 5, 5, 3,11,11, 9, 9, 9, 9, 9},
 { 5, 5, 5, 6, 9,13,13,13,13,13},
 { 2, 6, 3, 5, 9,13,13,13,13,13},
 { 2, 2, 5, 2, 8,13,13,13,13,13},
 { 2, 6, 6, 5, 9,13,13,13,14,14},
 { 1, 2, 2, 2, 7,13,14,13,14,13},
 { 5, 5, 3, 3, 9,15,16,16,16,17},
 { 5,18, 5, 5,18,13,16,17,16,17}}
// End of GPU gfx950_mod0
}
;

}; // End of anonymous namespace

namespace AOTRITON_NS::v3::flash::autotune {

// using AOTRITON_NS::v2::flash::AttnFwdContext;

// Returns the selected kernel_index, or -1 when no valid kernel was selected.
// The kernel_index is logged by the caller (lookup_optimal in shim.cc) so the
// AOTRITON_LOG machinery is not duplicated across every generated autotune TU.
int CURRENT_ENTRY_PUBLIC(AttnFwdContext& context, int mod_number) {
#if AOTRITON_BUILD_FOR_TUNING
    constexpr int kLutInTuningModeAlwaysReturnZero = 0;
    AOTRITON_LOG(LOG_DEBUG,
                 "Autotune_attn_fwd__A0__F24 "
                 "kTotalNumKernels = %d _has_preferred_kernel = %d",
                 kTotalNumKernels, context._has_preferred_kernel);
#ifndef NDEBUG
    assert(attn_fwd__lut_lambda__0(*context.params, mod_number, lut) == kLutInTuningModeAlwaysReturnZero);
#endif
    int preferred = context._has_preferred_kernel;
    int kernel_index = preferred < 0 ? kLutInTuningModeAlwaysReturnZero : preferred;
#else
    auto kernel_index = attn_fwd__lut_lambda__0(*context.params, mod_number, lut);
#endif
    if (kernel_index < 0 || kernel_index >= kTotalNumKernels) {
        return -1;
    }
    context.kernel_on_device = kernel_cluster.get(kernel_index);
    context.pp_args_index = 6;
    context.flatzip_path = FLATZIP_PATH;
    // aks2_entry IS the func_name (supplied by f.unified_signature)
    context.aks2_entry   = FUNC_NAME;
    context.func_name = FUNC_NAME;
    context.arch_name = ARCH_NAME;
#if AOTRITON_BUILD_FOR_TUNING
    context._total_number_of_kernels = kTotalNumKernels;
    context._preferred_kernel_psels = kernel_psels[kernel_index];
    context._preferred_kernel_copts = kernel_copts[kernel_index];
#endif
    const auto& perf = image_perf_list[kernel_index];
    context.PERSISTENT_TYPE = perf.PERSISTENT_TYPE;
    context.GRID_CU_MULTIP = perf.GRID_CU_MULTIP;
    context.BLOCK_M = perf.BLOCK_M;
    context.BLOCK_N = perf.BLOCK_N;
    context.PRE_LOAD_V = perf.PRE_LOAD_V;
    context.NUM_XCDS = perf.NUM_XCDS;
    return kernel_index;
}

#undef CURRENT_ENTRY_PUBLIC
}

// Human-readable Signature 
// Q = "*fp16:16"
// Sm_scale = "fp32"
// L = "*fp32:16"
// Q_descale = 0
// stride_bz = 0
// stride_bh = 0
// stride_bm = 0
// stride_az = 0
// Num_head_q = "i32"
// cu_seqlens_q = "*i32:16"
// BLOCK_DMODEL = 32
// Hdim_qk = "i32"
// PADDED_HEAD = True
// ENABLE_DROPOUT = False
// dropout_p = 0
// philox_seed_ptr = 0
// philox_offset2 = 0
// RETURN_ENCODED_SOFTMAX = False
// CAUSAL_TYPE = 0
// Window_left = 0
// Window_right = 0
// BIAS_TYPE = 0
// USE_ALIBI = False
// INT8 = False
// persistent_atomic_counter = 0
// Num_CU = "i32"

// ('SELECT * FROM FLASH$attn_fwd WHERE gpu IN (?) AND inputs$Q_dtype = ? AND inputs$BLOCK_DMODEL = ? AND inputs$PADDED_HEAD = ? AND inputs$ENABLE_DROPOUT = ? AND inputs$CAUSAL_TYPE = ? AND inputs$BIAS_TYPE = ?', ['gfx950_mod0', 'torch.float16', 32, False, False, 0, 0])

// vim: set fileencoding=utf-8

