Add QK swizzle option

This commit is contained in:
MHYang
2025-04-29 16:58:15 +00:00
parent c204cdc382
commit 1b0885c207
8 changed files with 35 additions and 0 deletions

View File

@@ -7,6 +7,8 @@ add_executable(${EXAMPLE_REDUCE} EXCLUDE_FROM_ALL flash_attention_fwd.cpp)
target_include_directories(${EXAMPLE_REDUCE} PRIVATE ${CMAKE_CURRENT_LIST_DIR})
set(EXAMPLE_REDUCE_COMPILE_OPTIONS)
# list(APPEND EXAMPLE_REDUCE_COMPILE_OPTIONS -v --save-temps -Wno-gnu-line-marker)
# NOTE: we turn off undefined-func-template to let source compile without explicit declare function specializations
list(APPEND EXAMPLE_REDUCE_COMPILE_OPTIONS -Wno-undefined-func-template -Wno-float-equal)
@@ -16,6 +18,12 @@ if(ENABLE_TOY_FA_FWD_OPT)
target_compile_definitions(${EXAMPLE_REDUCE} PRIVATE TOY_FA_FWD_OPT)
endif()
option(ENABLE_TOY_FA_FWD_QK_SWIZZLE "Enable toy FA fwd QK swizzle" OFF)
if(ENABLE_TOY_FA_FWD_QK_SWIZZLE)
message("Compiling with toy FA fwd QK swizzle")
target_compile_definitions(${EXAMPLE_REDUCE} PRIVATE TOY_FA_FWD_QK_SWIZZLE)
endif()
target_compile_options(${EXAMPLE_REDUCE} PRIVATE ${EXAMPLE_REDUCE_COMPILE_OPTIONS})
# TODO: we have to turn off this global prop, otherwise the progress bar generated

View File

@@ -23,7 +23,12 @@ struct BlockGemmARegBSmemCRegV1DefaultPolicy
}
else if constexpr(kM0 == 128)
{
#if !defined(TOY_FA_FWD_QK_SWIZZLE)
return make_tuple(WarpGemmMfmaF16F16F32M32N32K8TransposedCDistribution{}, 4, 1);
#else
#pragma message("Enable toy FA fwd QK swizzle")
return make_tuple(WarpGemmMfmaF16F16F32M32N32K16TransposedCDistribution{}, 4, 1);
#endif
}
else
{

View File

@@ -23,7 +23,11 @@ struct BlockGemmARegBSmemCRegV1K8Policy
}
else if constexpr(kM0 == 128)
{
#if !defined(TOY_FA_FWD_QK_SWIZZLE)
return make_tuple(WarpGemmMfmaF16F16F32M32N32K16TransposedCDistribution{}, 4, 1);
#else
return make_tuple(WarpGemmMfmaF16F16F32M32N32K16SwizzleBTransposedCDistribution{}, 4, 1);
#endif
}
else
{

View File

@@ -63,7 +63,11 @@ struct FlashAttentionFwdImpl
{
constexpr index_t kNPerBlock = kN1PerBlock;
constexpr index_t kKPerBlock = kK1PerBlock;
#if !defined(TOY_FA_FWD_QK_SWIZZLE)
constexpr index_t kKPack = 4;
#else
constexpr index_t kKPack = 8;
#endif
constexpr auto dataTypeSize = sizeof(VDataType);
constexpr auto NLdsLayer =

View File

@@ -6,6 +6,7 @@ if(FLASH_ATTENTION_FWD_ENABLE_APIS STREQUAL "all")
endif()
option(TOY_FA_FWD_OPT "Enable toy flash attention forward optimization" ON)
option(TOY_FA_FWD_QK_SWIZZLE "Enable toy flash attention forward QK swizzle" OFF)
execute_process(
COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/generate.py

View File

@@ -23,7 +23,12 @@ struct BlockGemmARegBSmemCRegV1DefaultPolicy
}
else if constexpr(kM0 == 128)
{
#if !defined(TOY_FA_FWD_QK_SWIZZLE)
return make_tuple(WarpGemmMfmaF16F16F32M32N32K8TransposedCDistribution{}, 4, 1);
#else
#pragma message("Enable toy FA fwd QK swizzle")
return make_tuple(WarpGemmMfmaF16F16F32M32N32K16TransposedCDistribution{}, 4, 1);
#endif
}
else
{

View File

@@ -23,7 +23,11 @@ struct BlockGemmARegBSmemCRegV1K8Policy
}
else if constexpr(kM0 == 128)
{
#if !defined(TOY_FA_FWD_QK_SWIZZLE)
return make_tuple(WarpGemmMfmaF16F16F32M32N32K16TransposedCDistribution{}, 4, 1);
#else
return make_tuple(WarpGemmMfmaF16F16F32M32N32K16SwizzleBTransposedCDistribution{}, 4, 1);
#endif
}
else
{

View File

@@ -63,7 +63,11 @@ struct FlashAttentionFwdImpl
{
constexpr index_t kNPerBlock = kN1PerBlock;
constexpr index_t kKPerBlock = kK1PerBlock;
#if !defined(TOY_FA_FWD_QK_SWIZZLE)
constexpr index_t kKPack = 4;
#else
constexpr index_t kKPack = 8;
#endif
constexpr auto dataTypeSize = sizeof(VDataType);
constexpr auto NLdsLayer =