v4.3 update. (#2709)

* v4.3 update.

* Update the cute_dsl_api changelog's doc link

* Update version to 4.3.0

* Update the example link

* Update doc to encourage user to install DSL from requirements.txt

---------

Co-authored-by: Larry Wu <larwu@nvidia.com>
This commit is contained in:
Junkai-Wu
2025-10-21 14:26:30 -04:00
committed by GitHub
co-authored by Larry Wu
parent e6e2cc29f5
commit b1d6e2c9b3
244 changed files with 59272 additions and 10455 deletions
@@ -110,6 +110,8 @@ set(TEST_BWD_MLA_VARLEN --b=1 --h=4 --q=512 --k=512 --d=192 --d_vo=128 --verify
set(TEST_MLA_SEP_REDUCTION --b=1 --k=4096 --split_kv=8 --page=128 --verify)
set(TEST_MLA_FUSE_REDUCTION --b=1 --k=4096 --split_kv=8 --page=128 --fuse_reduction --verify)
set(TEST_MLA_LARGE_SPLIT_KV --verify --split_kv=20 --page=128)
if(NOT WIN32 AND (NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND (CUTLASS_NVCC_ARCHS MATCHES 100a))
foreach(PREC fp8 fp16)
@@ -171,6 +173,7 @@ if(NOT WIN32 AND (NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND (CUTLASS_NVCC
77_blackwell_mla.cu
TEST_COMMAND_OPTIONS
TEST_MLA_BASIC
TEST_MLA_LARGE_SPLIT_KV
TEST_MLA_SEP_REDUCTION
TEST_MLA_FUSE_REDUCTION
)
@@ -183,6 +186,7 @@ if(NOT WIN32 AND (NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) AND (CUTLASS_NVCC
77_blackwell_mla.cu
TEST_COMMAND_OPTIONS
TEST_MLA_BASIC
TEST_MLA_LARGE_SPLIT_KV
TEST_MLA_SEP_REDUCTION
TEST_MLA_FUSE_REDUCTION
)
@@ -78,7 +78,7 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
using StagesQ = cutlass::gemm::collective::StageCount<StageCountQ>;
using StagesKV = cutlass::gemm::collective::StageCount<StageCountKV>;
using ClusterShape = Shape<_1, _1, _1>;
static const int Alignment = 128 / sizeof_bits_v<Element>;
@@ -668,7 +668,7 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
pipeline_c.producer_acquire(pipeline_c_producer_state);
ElementQK acc_scale = 0.5f * ::exp2f(scale * (old_row_max - row_max_safe));
ElementQK acc_scale = (old_row_max == row_max_safe) ? 0.5f : 0.5f * ::exp2f(scale * (old_row_max - row_max_safe));
row_sum *= acc_scale;
// row_sum = sum(reg_S)
float2 local_row_sum_f32x2 = make_float2(row_sum, row_sum);
@@ -934,13 +934,16 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
}
Tensor tTMrO_i = tTMrO(_, i).compose(make_layout(shape<0>(tTMrO)));
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO_i); j += 2) {
float2 in = make_float2(tTMrO_i(j), tTMrO_i(j+1));
float2 out;
cute::mul(out, scale_f32x2, in);
tTMrO_i(j) = out.x;
tTMrO_i(j+1) = out.y;
if (scale != 1.0f) {
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO_i); j += 2) {
float2 in = make_float2(tTMrO_i(j), tTMrO_i(j+1));
float2 out;
cute::mul(out, scale_f32x2, in);
tTMrO_i(j) = out.x;
tTMrO_i(j+1) = out.y;
}
}
copy_out(i);
@@ -1009,11 +1012,14 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
copy(tiled_tmem_loadv, tTMEM_LOADVtS0, tTMEM_LOADVrS);
// e^(scale * (old_max - new_max)
float scale = ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
float scale = (tTMEM_LOADVrS(kIdxOldRowMax) == tTMEM_LOADVrS(kIdxNewRowMax)) ? 1.0f : ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
pipeline_o.consumer_wait(pipeline_o_consumer_state);
correction_rescale(scale, uint32_t(TmemAllocation::O0));
bool warp_do_correction = __any_sync(0xFFFFFFFF, scale != 1.0f);
if (warp_do_correction) {
correction_rescale(scale, uint32_t(TmemAllocation::O0));
}
pipeline_s1_c.consumer_release(pipeline_s1_c_consumer_state);
++pipeline_s1_c_consumer_state;
@@ -1027,11 +1033,14 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
copy(tiled_tmem_loadv, tTMEM_LOADVtS1, tTMEM_LOADVrS);
scale = ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
scale = (tTMEM_LOADVrS(kIdxOldRowMax) == tTMEM_LOADVrS(kIdxNewRowMax)) ? 1.0f : ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
pipeline_o.consumer_wait(pipeline_o_consumer_state);
correction_rescale(scale, uint32_t(TmemAllocation::O1));
warp_do_correction = __any_sync(0xFFFFFFFF, scale != 1.0f);
if (warp_do_correction) {
correction_rescale(scale, uint32_t(TmemAllocation::O1));
}
pipeline_s0_c.consumer_release(pipeline_s0_c_consumer_state);
++pipeline_s0_c_consumer_state;
@@ -1071,7 +1080,7 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
// store to smem
Tensor sO = make_tensor(make_smem_ptr(shared_storage_epi.smem_o.data()), typename TensorStorageEpi::SmemLayoutO{});
Tensor gLSE = make_tensor(make_gmem_ptr(epilogue.params.ptr_LSE), select<0,3>(problem_shape), epilogue.params.dLSE);
correction_epilogue(params.scale_output / tTMEM_LOADVrS(kIdxFinalRowSum), _0{}, sO);
if (epilogue.params.ptr_LSE != nullptr) {
@@ -1171,10 +1180,10 @@ struct Sm100FmhaFwdMainloopTmaWarpspecialized {
auto tOgO = thr_copy.partition_D(sO);
auto tOrO = make_tensor<ElementOut>(shape(tOgO(_,_,_,_0{})));
clear(tOrO);
copy(tiled_copy, tOrO, tOgO(_,_,_,_0{}));
#endif
if (epilogue.params.ptr_LSE != nullptr) {
int row_idx = thread_idx + get<0>(TileShape{}) * get<0>(blk_coord);
@@ -86,10 +86,10 @@ struct Sm100FmhaGenMainloopWarpspecialized {
static constexpr int StageCountQ = get<1>(TileShape{}) == 256 ? 1 : 2;
static constexpr int StageCountKV = 256 * 11 / get<1>(TileShape{});
using StagesQ = cutlass::gemm::collective::StageCount<StageCountQ>;
using StagesKV = cutlass::gemm::collective::StageCount<StageCountKV>;
using ClusterShape = Shape<_1, _1, _1>;
static const int Alignment = 128 / sizeof_bits_v<Element>;
@@ -187,7 +187,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
SmemLayoutQ, SmemLayoutK, SmemLayoutV,
PipelineQ, PipelineKV, TileShape, Mask
>;
struct Arguments {
typename Load::Arguments load;
@@ -622,7 +622,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
NumericArrayConverter<Element, ElementQK, kConversionsPerStep> convert;
const int kReleasePipeCount = 10; // must be multiple of 2
order_s.wait();
CUTLASS_PRAGMA_UNROLL
@@ -646,7 +646,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
}
tTMEM_STORErS_x4_e[i / kConversionsPerStep] = convert(in_conv);
if (i == size(tTMEM_LOADrS) - kReleasePipeCount) {
order_s.arrive();
}
@@ -672,7 +672,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
pipeline_c.producer_acquire(pipeline_c_producer_state);
ElementQK acc_scale = 0.5f * ::exp2f(scale * (old_row_max - row_max_safe));
ElementQK acc_scale = (old_row_max == row_max_safe) ? 0.5f : 0.5f * ::exp2f(scale * (old_row_max - row_max_safe));
row_sum *= acc_scale;
// row_sum = sum(reg_S)
float2 local_row_sum_f32x2 = make_float2(row_sum, row_sum);
@@ -700,7 +700,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
cute::add(local_row_sum_2, local_row_sum_2, local_row_sum_3);
cute::add(local_row_sum_f32x2, local_row_sum_f32x2, local_row_sum_2);
float local_row_sum = local_row_sum_f32x2.x + local_row_sum_f32x2.y;
row_sum = local_row_sum;
if (final_call) {
@@ -781,7 +781,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
template<class Vector, class GTensor, class CTensor, class Shape, class Epilogue>
CUTLASS_DEVICE auto
correction_epilogue(
float scale_softmax_log2, float scale_out, Vector const& v0, Vector const& v1,
float scale_softmax_log2, float scale_out, Vector const& v0, Vector const& v1,
GTensor& gO, CTensor const& cO, Shape const& g_shape,
Epilogue const& epilogue) {
@@ -794,13 +794,13 @@ struct Sm100FmhaGenMainloopWarpspecialized {
// good values would be either 32 or 64
const int kCorrectionTileSize = 32 / sizeof(ElementOut);
using TMEM_LOAD = std::conditional_t<kCorrectionTileSize == 32, SM100_TMEM_LOAD_32dp32b32x, SM100_TMEM_LOAD_32dp32b16x>; // 4x32 threads with 64 cols of 32b elem
using TMEM_LOAD = std::conditional_t<kCorrectionTileSize == 32, SM100_TMEM_LOAD_32dp32b32x, SM100_TMEM_LOAD_32dp32b16x>; // 4x32 threads with 64 cols of 32b elem
typename CollectiveMmaPV::TiledMma mma;
Tensor tOtO = partition_fragment_C(mma, select<0,1>(TileShapePV{}));
Tensor tOcO = mma.get_slice(0).partition_C(cO);
Tensor tOgO = mma.get_slice(0).partition_C(gO);
Tensor tOtO_i = tOtO.compose(make_layout(make_shape(_128{}, Int<kCorrectionTileSize>{})));
Tensor tOcO_i = tOcO.compose(make_layout(make_shape(_128{}, Int<kCorrectionTileSize>{})));
Tensor tOgO_i = tOgO.compose(make_layout(make_shape(_128{}, Int<kCorrectionTileSize>{})));
@@ -812,7 +812,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
auto tiled_tmem_load = make_tmem_copy(TMEM_LOAD{}, tOtO_i);
auto thr_tmem_load = tiled_tmem_load.get_slice(thread_idx);
Tensor tTMEM_LOADtO0 = thr_tmem_load.partition_S(tOtO0);
Tensor tTMEM_LOADtO1 = thr_tmem_load.partition_S(tOtO1);
Tensor tTMEM_LOADcO = thr_tmem_load.partition_D(tOcO_i);
@@ -841,10 +841,10 @@ struct Sm100FmhaGenMainloopWarpspecialized {
Tensor tTMrO0 = make_tensor<ElementPV>(shape(tTMEM_LOADcO));
Tensor tTMrO1 = make_tensor<ElementPV>(shape(tTMEM_LOADcO));
copy(tiled_tmem_load, tTMEM_LOADtO0_i, tTMrO0);
copy(tiled_tmem_load, tTMEM_LOADtO1_i, tTMrO1);
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO0); j += 2) {
float2 in0 = make_float2(tTMrO0(j), tTMrO0(j+1));
@@ -891,24 +891,24 @@ struct Sm100FmhaGenMainloopWarpspecialized {
// good values would be either 32 or 64
const int kCorrectionTileSize = 32;
using TMEM_LOAD = SM100_TMEM_LOAD_32dp32b32x; // 4x32 threads with 64 cols of 32b elem
using TMEM_LOAD = SM100_TMEM_LOAD_32dp32b32x; // 4x32 threads with 64 cols of 32b elem
using TMEM_STORE = SM100_TMEM_STORE_32dp32b32x; // 4x32 threads with 64 cols of 32b elem
typename CollectiveMmaPV::TiledMma mma;
Tensor cO = make_identity_tensor(select<0,1>(TileShapePV{}));
Tensor tOtO = partition_fragment_C(mma, select<0,1>(TileShapePV{}));
Tensor tOcO = mma.get_slice(0).partition_C(cO);
Tensor tOtO_i = tOtO.compose(make_layout(make_shape(_128{}, Int<kCorrectionTileSize>{})));
Tensor tOcO_i = tOcO.compose(make_layout(make_shape(_128{}, Int<kCorrectionTileSize>{})));
tOtO_i.data() = tOtO_i.data().get() + tmem_O;
auto tiled_tmem_load = make_tmem_copy(TMEM_LOAD{}, tOtO_i);
auto thr_tmem_load = tiled_tmem_load.get_slice(thread_idx);
auto tiled_tmem_store = make_tmem_copy(TMEM_STORE{}, tOtO_i);
auto thr_tmem_store = tiled_tmem_store.get_slice(thread_idx);
Tensor tTMEM_LOADtO = thr_tmem_load.partition_S(tOtO_i);
Tensor tTMEM_LOADcO = thr_tmem_load.partition_D(tOcO_i);
Tensor tTMEM_STOREtO = thr_tmem_store.partition_D(tOtO_i);
@@ -918,7 +918,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
float2 scale_f32x2 = make_float2(scale, scale);
Tensor tTMrO = make_tensor<ElementPV>(make_shape(shape(tTMEM_LOADcO), Int<get<2>(TileShape{}) / kCorrectionTileSize>{}));
auto copy_in = [&](int i) {
Tensor tTMEM_LOADtO_i = tTMEM_LOADtO;
tTMEM_LOADtO_i.data() = tTMEM_LOADtO_i.data().get() + uint32_t(i * kCorrectionTileSize);
@@ -948,13 +948,16 @@ struct Sm100FmhaGenMainloopWarpspecialized {
}
Tensor tTMrO_i = tTMrO(_, i).compose(make_layout(shape<0>(tTMrO)));
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO_i); j += 2) {
float2 in = make_float2(tTMrO_i(j), tTMrO_i(j+1));
float2 out;
cute::mul(out, scale_f32x2, in);
tTMrO_i(j) = out.x;
tTMrO_i(j+1) = out.y;
if (scale != 1.0f) {
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO_i); j += 2) {
float2 in = make_float2(tTMrO_i(j), tTMrO_i(j+1));
float2 out;
cute::mul(out, scale_f32x2, in);
tTMrO_i(j) = out.x;
tTMrO_i(j+1) = out.y;
}
}
copy_out(i);
@@ -981,7 +984,7 @@ struct Sm100FmhaGenMainloopWarpspecialized {
Tensor cS = make_identity_tensor(select<0,1>(TileShapeQK{}));
Tensor tScS = typename CollectiveMmaQK::TiledMma{}.get_slice(0).partition_C(cS);
Tensor tStS_v = tStS.compose(make_layout(make_shape(_128{}, _2{})));
Tensor tScS_v = tScS.compose(make_layout(make_shape(_128{}, _2{})));
@@ -1019,11 +1022,14 @@ struct Sm100FmhaGenMainloopWarpspecialized {
copy(tiled_tmem_loadv, tTMEM_LOADVtS0, tTMEM_LOADVrS);
// e^(scale * (old_max - new_max)
float scale = ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
float scale = (tTMEM_LOADVrS(kIdxOldRowMax) == tTMEM_LOADVrS(kIdxNewRowMax)) ? 1.0f : ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
pipeline_o.consumer_wait(pipeline_o_consumer_state);
correction_rescale(scale, uint32_t(TmemAllocation::O0));
bool warp_do_correction = __any_sync(0xFFFFFFFF, scale != 1.0f);
if (warp_do_correction) {
correction_rescale(scale, uint32_t(TmemAllocation::O0));
}
pipeline_s1_c.consumer_release(pipeline_s1_c_consumer_state);
++pipeline_s1_c_consumer_state;
@@ -1037,11 +1043,14 @@ struct Sm100FmhaGenMainloopWarpspecialized {
copy(tiled_tmem_loadv, tTMEM_LOADVtS1, tTMEM_LOADVrS);
scale = ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
scale = (tTMEM_LOADVrS(kIdxOldRowMax) == tTMEM_LOADVrS(kIdxNewRowMax)) ? 1.0f : ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
pipeline_o.consumer_wait(pipeline_o_consumer_state);
correction_rescale(scale, uint32_t(TmemAllocation::O1));
warp_do_correction = __any_sync(0xFFFFFFFF, scale != 1.0f);
if (warp_do_correction) {
correction_rescale(scale, uint32_t(TmemAllocation::O1));
}
pipeline_s0_c.consumer_release(pipeline_s0_c_consumer_state);
++pipeline_s0_c_consumer_state;
@@ -77,7 +77,7 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
static constexpr int StageCountK = 1;
static constexpr int StageCountV = 1;
static constexpr int StageCountKV = StageCountK + StageCountV;
// Support StageCountKV > 2 in the future.
// Support StageCountKV > 2 in the future.
static_assert(StageCountK == 1 && StageCountV == 1, "Only support StageCountK = StageCountV = 1!");
static_assert(std::is_same_v<ThreadShape, Shape<_2, _1, _1>>, "Only support ThreadShape = Shape<_2, _1, _1>");
@@ -116,24 +116,24 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
using SmemLayoutV = decltype(unstageSmemLayout(typename CollectiveMmaPV::SmemLayoutB{}, Int<StageCountV>{}));
using SmemStorageOneStageO = decltype(make_layout(replace<2>(TileShapePV{}, _1{})));
// Since the shared memory is not sufficient if we use separate Q, K, V, and O shared memory,
// we reuse shared memory for V and O to address this problem,
// Since the shared memory is not sufficient if we use separate Q, K, V, and O shared memory,
// we reuse shared memory for V and O to address this problem,
// and a barrier has been added to coordinate access to shared memory.
static constexpr bool IsOrderLoadEpilogue = std::is_same_v<OrderLoadEpilogue, cute::true_type>;
static const int NumWarpsEpilogue = 1;
static const int NumWarpsLoad = 1;
struct TensorStorageQKVO {
cute::array_aligned<Element, cute::cosize_v<SmemLayoutQ>> smem_q;
cute::array_aligned<Element, cute::cosize_v<SmemLayoutK>> smem_k;
cute::array_aligned<Element, cute::cosize_v<SmemLayoutK>> smem_k;
cute::array_aligned<Element, cute::cosize_v<SmemLayoutV>> smem_o; // use as O0
cute::array_aligned<Element, cute::cosize_v<SmemLayoutV>> smem_v; // use as V0 and O1
};
struct TensorStorageQKV {
cute::array_aligned<Element, cute::cosize_v<SmemLayoutQ>> smem_q;
cute::array_aligned<Element, cute::cosize_v<SmemLayoutK>> smem_k;
cute::array_aligned<Element, cute::cosize_v<SmemLayoutK>> smem_k;
cute::array_aligned<Element, cute::cosize_v<SmemLayoutV>> smem_v;
};
@@ -689,7 +689,7 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
pipeline_c.producer_acquire(pipeline_c_producer_state);
ElementQK acc_scale = 0.5f * ::exp2f(scale * (old_row_max - row_max_safe));
ElementQK acc_scale = (old_row_max == row_max_safe) ? 0.5f : 0.5f * ::exp2f(scale * (old_row_max - row_max_safe));
row_sum *= acc_scale;
// row_sum = sum(reg_S)
float2 local_row_sum_f32x2 = make_float2(row_sum, row_sum);
@@ -755,7 +755,7 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
Tensor cS = domain_offset(logical_offset, cS_base);
pipeline_c.producer_acquire(pipeline_c_producer_state);
constexpr bool NeedMask = !std::is_same_v<Mask, NoMask>;
CUTLASS_PRAGMA_NO_UNROLL
@@ -841,13 +841,15 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
copy(tiled_tmem_load, tTMEM_LOADtO_i, tTMrO);
#ifndef ONLY_SOFTMAX
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO); j += 2) {
float2 in = make_float2(tTMrO(j), tTMrO(j+1));
float2 out;
cute::mul(out, scale_f32x2, in);
tTMrO(j) = out.x;
tTMrO(j+1) = out.y;
if (scale != 1.0f) {
CUTLASS_PRAGMA_UNROLL
for (int j = 0; j < size(tTMrO); j += 2) {
float2 in = make_float2(tTMrO(j), tTMrO(j+1));
float2 out;
cute::mul(out, scale_f32x2, in);
tTMrO(j) = out.x;
tTMrO(j+1) = out.y;
}
}
#endif
@@ -1017,11 +1019,14 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
copy(tiled_tmem_loadv, tTMEM_LOADVtS0, tTMEM_LOADVrS);
// e^(scale * (old_max - new_max)
float scale = ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
float scale = (tTMEM_LOADVrS(kIdxOldRowMax) == tTMEM_LOADVrS(kIdxNewRowMax)) ? 1.0f : ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
pipeline_o.consumer_wait(pipeline_o_consumer_state);
correction_rescale(scale, uint32_t(TmemAllocation::O0));
bool warp_do_correction = __any_sync(0xFFFFFFFF, scale != 1.0f);
if (warp_do_correction) {
correction_rescale(scale, uint32_t(TmemAllocation::O0));
}
pipeline_s1_c.consumer_release(pipeline_s1_c_consumer_state);
++pipeline_s1_c_consumer_state;
@@ -1035,11 +1040,14 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
copy(tiled_tmem_loadv, tTMEM_LOADVtS1, tTMEM_LOADVrS);
scale = ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
scale = (tTMEM_LOADVrS(kIdxOldRowMax) == tTMEM_LOADVrS(kIdxNewRowMax)) ? 1.0f : ::exp2f(params.scale_softmax_log2 * (tTMEM_LOADVrS(kIdxOldRowMax) - tTMEM_LOADVrS(kIdxNewRowMax)));
pipeline_o.consumer_wait(pipeline_o_consumer_state);
correction_rescale(scale, uint32_t(TmemAllocation::O1));
warp_do_correction = __any_sync(0xFFFFFFFF, scale != 1.0f);
if (warp_do_correction) {
correction_rescale(scale, uint32_t(TmemAllocation::O1));
}
pipeline_s0_c.consumer_release(pipeline_s0_c_consumer_state);
++pipeline_s0_c_consumer_state;
@@ -1178,10 +1186,10 @@ struct Sm100MlaFwdMainloopTmaWarpspecialized {
auto tOgO = thr_copy.partition_D(sO);
auto tOrO = make_tensor<ElementOut>(shape(tOgO(_,_,_,_0{})));
clear(tOrO);
copy(tiled_copy, tOrO, tOgO(_,_,_,_0{}));
#endif
if (epilogue.params.ptr_LSE != nullptr) {
int row_idx = thread_idx + get<0>(TileShape{}) * get<0>(blk_coord);
@@ -1039,10 +1039,6 @@ struct Sm100FmhaMlaKernelTmaWarpspecialized {
auto pipeline_commit_state = pipeline_acquire_state;
int pipeline_offset = 0;
for (int i = 0; i < StagesPV; i++) {
cutlass::arch::cp_async_fence();
}
auto load_stage = [&](auto fn) {
pipeline_load.producer_acquire(pipeline_acquire_state);
fn(pipeline_acquire_state.index());
@@ -1132,6 +1128,13 @@ struct Sm100FmhaMlaKernelTmaWarpspecialized {
pipeline_page_table.consumer_release(pipeline_pt_release_state);
++pipeline_pt_release_state;
// Extra async fence if the pipeline_offset can't meet the StagesPV
int extra_offset = 0;
while (pipeline_offset + extra_offset < StagesPV - 1) {
extra_offset++;
cutlass::arch::cp_async_fence();
}
while (pipeline_offset > 0) {
cutlass::arch::cp_async_fence();
@@ -2097,7 +2100,7 @@ struct Sm100FmhaMlaKernelTmaWarpspecialized {
cutlass::arch::NamedBarrier(
(kNumComputeWarps + kNumLoadWarps) * NumThreadsPerWarp,
kNamedBarrierEpilogue
).arrive();
).arrive_and_wait();
return;
}
@@ -329,6 +329,20 @@ void fmha_bwd_reference_dQ(
dim3 grid(size<0>(mDQ), size<2>(mDQ), 1);
dim3 block(256);
int shared_mem = size<0>(mK) * sizeof(typename TensorDQ::value_type);
cudaError_t result;
if (shared_mem >= (48 << 10)) {
result = cudaFuncSetAttribute(
&fmha_bwd_reference_dQ_kernel<ProblemShape, TensorQ, TensorK, TensorV,
TensorO, TensorLSE, TensorDO, TensorDQ, Fusion>,
cudaFuncAttributeMaxDynamicSharedMemorySize,
shared_mem);
if (cudaSuccess != result) {
cudaGetLastError(); // Clear the error state
throw std::runtime_error("Failed to allocate " +
std::to_string(shared_mem >> 10) + " KB dynamic smem for dQ tensor in ref. check - " +
"please try reducing seq_len or skipping ref. check");
}
}
fmha_bwd_reference_dQ_kernel<<<grid, block, shared_mem>>>(problem_shape, mQ, mK, mV, mO, mLSE, mDO, mDQ, fusion);
}
@@ -356,6 +370,20 @@ void fmha_bwd_reference_dK(
dim3 grid(K, H_K * B, 1);
dim3 block(std::max(D, 256));
int shared_mem = size<0>(mDO) * sizeof(typename TensorDK::value_type);
cudaError_t result;
if (shared_mem >= (48 << 10)) {
result = cudaFuncSetAttribute(
&fmha_bwd_reference_dK_kernel<ProblemShape, TensorQ, TensorK, TensorV,
TensorO, TensorLSE, TensorDO, TensorDK, Fusion>,
cudaFuncAttributeMaxDynamicSharedMemorySize,
shared_mem);
if (cudaSuccess != result) {
cudaGetLastError(); // Clear the error state
throw std::runtime_error("Failed to allocate " +
std::to_string(shared_mem >> 10) + " KB dynamic smem for dO tensor in ref. check - " +
"please try reducing seq_len or skipping ref. check");
}
}
fmha_bwd_reference_dK_kernel<<<grid, block, shared_mem>>>(problem_shape, mQ, mK, mV, mO, mLSE, mDO, mDK, fusion);
}
@@ -383,6 +411,20 @@ void fmha_bwd_reference_dV(
dim3 grid(K, H_K * B, 1);
dim3 block(std::max(D_VO, 256));
int shared_mem = size<0>(mDO) * sizeof(typename TensorDV::value_type);
cudaError_t result;
if (shared_mem >= (48 << 10)) {
result = cudaFuncSetAttribute(
&fmha_bwd_reference_dV_kernel<ProblemShape, TensorQ, TensorK, TensorV,
TensorO, TensorLSE, TensorDO, TensorDV, Fusion>,
cudaFuncAttributeMaxDynamicSharedMemorySize,
shared_mem);
if (cudaSuccess != result) {
cudaGetLastError(); // Clear the error state
throw std::runtime_error("Failed to allocate " +
std::to_string(shared_mem >> 10) + " KB dynamic smem for dO tensor in ref. check - " +
"please try reducing seq_len or skipping ref. check");
}
}
fmha_bwd_reference_dV_kernel<<<grid, block, shared_mem>>>(problem_shape, mQ, mK, mV, mO, mLSE, mDO, mDV, fusion);
}
@@ -189,6 +189,19 @@ void fmha_reference(
dim3 grid(size<0>(mO), size<2>(mO), 1);
dim3 block(256);
int shared_mem = size<0>(mK) * int(sizeof(typename TensorLSE::value_type));
cudaError_t result;
if (shared_mem >= (48 << 10)) {
result = cudaFuncSetAttribute(
&fmha_reference_kernel<ProblemShapeIn, TensorQ, TensorK, TensorV, TensorO, TensorLSE, Mask>,
cudaFuncAttributeMaxDynamicSharedMemorySize,
shared_mem);
if (cudaSuccess != result) {
cudaGetLastError(); // Clear the error state
throw std::runtime_error("Failed to allocate " +
std::to_string(shared_mem >> 10) + " KB dynamic smem for S/P tensor in ref. check - " +
"please try reducing seq_len or skipping ref. check");
}
}
fmha_reference_kernel<<<grid, block, shared_mem>>>(problem_shape_in, mQ, mK, mV, mO, mLSE, mask);
}
@@ -185,9 +185,11 @@ void fmha_mla_reference(
cudaFuncAttributeMaxDynamicSharedMemorySize,
shared_mem);
if (cudaSuccess != result) {
result = cudaGetLastError(); // to clear the error bit
throw std::runtime_error("couldn't perform smem optin");
}
cudaGetLastError(); // Clear the error state
throw std::runtime_error("Failed to allocate " +
std::to_string(shared_mem >> 10) + " KB dynamic smem for S/P tensor in ref. check - " +
"please try reducing seq_len or skipping ref. check");
}
}
fmha_mla_reference_kernel<<<grid, block, shared_mem>>>(
problem_shape, mSeq, mPT, mQL, mQR, mCL, mKR, mO, mLSE, scale);