v4.4 update. (#2979)
This commit is contained in:
@@ -0,0 +1,259 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2025 - 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../collective/sm100_ssd_epilogue.hpp"
|
||||
#include "../collective/sm100_ssd_gemm_tma_warpspecialized.hpp"
|
||||
#include "../kernel/sm100_ssd_kernel_tma_warpspecialized.hpp"
|
||||
#include "../kernel/sm100_ssd_tile_scheduler.hpp"
|
||||
|
||||
#include "cutlass/cutlass.h"
|
||||
#include "cutlass/epilogue/collective/collective_builder.hpp"
|
||||
|
||||
namespace cutlass::ssd::kernel::detail {
|
||||
|
||||
template<
|
||||
class ElementA,
|
||||
class ElementB,
|
||||
class ElementAccumulator,
|
||||
class TileShape_MNK,
|
||||
class ClusterShape_MNK,
|
||||
UMMA::Major UmmaMajorA,
|
||||
UMMA::Major UmmaMajorB
|
||||
>
|
||||
constexpr auto
|
||||
sm100_make_ts_tiled_mma() {
|
||||
return cutlass::gemm::collective::detail::sm100_make_1sm_ts_trivial_tiled_mma<
|
||||
ElementA, ElementB, ElementAccumulator,
|
||||
TileShape_MNK, ClusterShape_MNK, UmmaMajorA, UmmaMajorB>();
|
||||
}
|
||||
|
||||
template<
|
||||
class ElementA,
|
||||
class ElementB,
|
||||
class ElementAccumulator,
|
||||
class TileShape_MNK,
|
||||
class ClusterShape_MNK,
|
||||
UMMA::Major UmmaMajorA,
|
||||
UMMA::Major UmmaMajorB
|
||||
>
|
||||
constexpr auto
|
||||
sm100_make_ss_tiled_mma() {
|
||||
return cutlass::gemm::collective::detail::sm100_make_1sm_trivial_tiled_mma<
|
||||
ElementA, ElementB, ElementAccumulator,
|
||||
TileShape_MNK, ClusterShape_MNK, UmmaMajorA, UmmaMajorB>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace cutlass::ssd::kernel {
|
||||
|
||||
template<
|
||||
class Element_,
|
||||
class ElementDA_,
|
||||
class ElementAcc_,
|
||||
class ElementY_,
|
||||
class TileShape_,
|
||||
bool HAS_D_,
|
||||
bool D_HAS_HDIM_
|
||||
>
|
||||
struct Sm100SsdBuilder {
|
||||
|
||||
using Element = Element_;
|
||||
using ElementDA = ElementDA_;
|
||||
using ElementAcc = ElementAcc_;
|
||||
using ElementY = ElementY_;
|
||||
using TileShape = TileShape_;
|
||||
using ArchTag = cutlass::arch::Sm100;
|
||||
|
||||
// hard-code
|
||||
using ClusterShape = Shape<_1,_1,_1>;
|
||||
|
||||
static constexpr int StagesInput = 2;
|
||||
static constexpr int StagesOutput = 2;
|
||||
|
||||
using TileShapeIntraBMM1 = decltype(make_shape(get<0>(TileShape{}), get<0>(TileShape{}), get<2>(TileShape{}))); // (L,L,N)
|
||||
using TileShapeIntraBMM2 = decltype(make_shape(get<0>(TileShape{}), get<1>(TileShape{}), get<0>(TileShape{}))); // (L,D,L)
|
||||
using TileShapeInterBMM1 = decltype(make_shape(get<2>(TileShape{}), get<1>(TileShape{}), get<0>(TileShape{}))); // (N,D,L)
|
||||
using TileShapeInterBMM2 = decltype(make_shape(get<0>(TileShape{}), get<1>(TileShape{}), get<2>(TileShape{}))); // (L,D,N)
|
||||
|
||||
// LxLxN, NT
|
||||
using TiledMmaIntra1 = decltype(detail::sm100_make_ss_tiled_mma<Element, Element, ElementAcc,
|
||||
TileShapeIntraBMM1, ClusterShape,
|
||||
cute::UMMA::Major::MN, cute::UMMA::Major::MN>());
|
||||
// LxNxL, TN
|
||||
using TiledMmaIntra2 = decltype(detail::sm100_make_ts_tiled_mma<Element, Element, ElementAcc,
|
||||
TileShapeIntraBMM2, ClusterShape,
|
||||
cute::UMMA::Major::K, cute::UMMA::Major::K>());
|
||||
// NxDxL, TN
|
||||
using TiledMmaInter1 = decltype(detail::sm100_make_ts_tiled_mma<Element, Element, ElementAcc,
|
||||
TileShapeInterBMM1, ClusterShape,
|
||||
cute::UMMA::Major::K, cute::UMMA::Major::K>());
|
||||
// LxDxN, NN
|
||||
using TiledMmaInter2 = decltype(detail::sm100_make_ss_tiled_mma<Element, Element, ElementAcc,
|
||||
TileShapeInterBMM2, ClusterShape,
|
||||
cute::UMMA::Major::MN, cute::UMMA::Major::K>());
|
||||
|
||||
// ((MMA_TILE_M,MMA_TILE_K), MMA_M, MMA_K)
|
||||
using MmaShapeC_MK = decltype(partition_shape_A(TiledMmaIntra1{}, make_shape(cute::size<0>(TileShapeIntraBMM1{}),
|
||||
cute::size<2>(TileShapeIntraBMM1{}))));
|
||||
using MmaShapeB_NK = decltype(partition_shape_B(TiledMmaIntra1{}, make_shape(cute::size<1>(TileShapeIntraBMM1{}),
|
||||
cute::size<2>(TileShapeIntraBMM1{}))));
|
||||
using MmaShapeQ_MK = decltype(partition_shape_A(TiledMmaIntra2{}, make_shape(cute::size<0>(TileShapeIntraBMM2{}),
|
||||
cute::size<2>(TileShapeIntraBMM2{}))));
|
||||
using MmaShapeX_NK = decltype(partition_shape_B(TiledMmaIntra2{}, make_shape(cute::size<1>(TileShapeIntraBMM2{}),
|
||||
cute::size<2>(TileShapeIntraBMM2{}))));
|
||||
|
||||
using MmaShapeB_MK = decltype(partition_shape_A(TiledMmaInter1{}, make_shape(cute::size<0>(TileShapeInterBMM1{}),
|
||||
cute::size<2>(TileShapeInterBMM1{}))));
|
||||
using MmaShapeP_NK = decltype(partition_shape_B(TiledMmaInter2{}, make_shape(cute::size<1>(TileShapeInterBMM2{}),
|
||||
cute::size<2>(TileShapeInterBMM2{}))));
|
||||
|
||||
using GmemTiledCopyX = cute::SM90_TMA_LOAD;
|
||||
using GmemTiledCopyB = cute::SM90_TMA_LOAD;
|
||||
using GmemTiledCopyC = cute::SM90_TMA_LOAD;
|
||||
|
||||
using BlockTileX_N = decltype(cute::size<0,0>(MmaShapeX_NK{}) * cute::size<1>(MmaShapeX_NK{}));
|
||||
using BlockTileX_K = decltype(cute::size<0,1>(MmaShapeX_NK{}) * cute::size<2>(MmaShapeX_NK{}));
|
||||
using SmemLayoutAtomX = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::K, Element, BlockTileX_N, BlockTileX_K>());
|
||||
|
||||
using BlockTileB_N = decltype(cute::size<0,0>(MmaShapeB_NK{}) * cute::size<1>(MmaShapeB_NK{}));
|
||||
using BlockTileB_K = decltype(cute::size<0,1>(MmaShapeB_NK{}) * cute::size<2>(MmaShapeB_NK{}));
|
||||
using SmemLayoutAtomB = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::MN, Element, BlockTileB_N, BlockTileB_K>());
|
||||
|
||||
using BlockTileBT_M = decltype(cute::size<0,0>(MmaShapeB_MK{}) * cute::size<1>(MmaShapeB_MK{}));
|
||||
using BlockTileBT_K = decltype(cute::size<0,1>(MmaShapeB_MK{}) * cute::size<2>(MmaShapeB_MK{}));
|
||||
using SmemLayoutAtomBT = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::K, Element, BlockTileBT_M, BlockTileBT_K>());
|
||||
using TmemLayoutAtomB = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::K, Element, BlockTileBT_M, BlockTileBT_K>());
|
||||
|
||||
using BlockTileC_M = decltype(cute::size<0,0>(MmaShapeC_MK{}) * cute::size<1>(MmaShapeC_MK{}));
|
||||
using BlockTileC_K = decltype(cute::size<0,1>(MmaShapeC_MK{}) * cute::size<2>(MmaShapeC_MK{}));
|
||||
using SmemLayoutAtomC = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::MN, Element, BlockTileC_M, BlockTileC_K>());
|
||||
|
||||
using BlockTileP_N = decltype(cute::size<0,0>(MmaShapeP_NK{}) * cute::size<1>(MmaShapeP_NK{}));
|
||||
using BlockTileP_K = decltype(cute::size<0,1>(MmaShapeP_NK{}) * cute::size<2>(MmaShapeP_NK{}));
|
||||
using SmemLayoutAtomP = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::K, Element, BlockTileP_N, BlockTileP_K>());
|
||||
|
||||
using SmemLayoutAtomPT = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::MN, Element, BlockTileP_K, BlockTileP_N>());
|
||||
|
||||
using BlockTileQ_M = decltype(cute::size<0,0>(MmaShapeQ_MK{}) * cute::size<1>(MmaShapeQ_MK{}));
|
||||
using BlockTileQ_K = decltype(cute::size<0,1>(MmaShapeQ_MK{}) * cute::size<2>(MmaShapeQ_MK{}));
|
||||
using SmemLayoutAtomQ = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::K, Element, BlockTileP_N, BlockTileP_K>());
|
||||
using TmemLayoutAtomQ = decltype(cutlass::gemm::collective::detail::sm100_smem_selector<
|
||||
cute::UMMA::Major::K, Element, BlockTileQ_M, BlockTileQ_K>());
|
||||
|
||||
using SmemLayoutX = decltype(UMMA::tile_to_mma_shape(
|
||||
SmemLayoutAtomX{},
|
||||
append(MmaShapeX_NK{}, Int<StagesInput>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
using SmemLayoutB = decltype(UMMA::tile_to_mma_shape(
|
||||
SmemLayoutAtomB{},
|
||||
append(MmaShapeB_NK{}, Int<StagesInput>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
// Be consistent with SmemLayoutB
|
||||
using SmemLayoutBT = decltype(UMMA::tile_to_mma_shape(
|
||||
SmemLayoutAtomBT{},
|
||||
append(MmaShapeB_MK{}, Int<StagesInput>{}),
|
||||
Step<_1,_2,_3>{}));
|
||||
using TmemLayoutB = decltype(UMMA::tile_to_mma_shape(
|
||||
TmemLayoutAtomB{},
|
||||
append(MmaShapeB_MK{}, Int<1>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
using SmemLayoutC = decltype(UMMA::tile_to_mma_shape(
|
||||
SmemLayoutAtomC{},
|
||||
append(MmaShapeC_MK{}, Int<StagesInput>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
// P only need 1 stage in this case
|
||||
using SmemLayoutPT = decltype(tile_to_shape(
|
||||
SmemLayoutAtomPT{},
|
||||
append(make_shape(get<2>(TileShape{}), get<1>(TileShape{})), Int<1>{})));
|
||||
using SmemLayoutP = decltype(UMMA::tile_to_mma_shape(
|
||||
SmemLayoutAtomP{},
|
||||
append(MmaShapeP_NK{}, Int<1>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
using TmemLayoutQ = decltype(UMMA::tile_to_mma_shape(
|
||||
TmemLayoutAtomQ{},
|
||||
append(MmaShapeQ_MK{}, Int<1>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
using SmemLayoutQ = decltype(UMMA::tile_to_mma_shape(
|
||||
SmemLayoutAtomQ{},
|
||||
append(MmaShapeQ_MK{}, Int<2>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
|
||||
using SmemLayoutAtomXT = decltype(cutlass::gemm::collective::detail::ss_smem_selector<
|
||||
cute::GMMA::Major::MN, Element, decltype(get<0>(TileShape{})), decltype(get<1>(TileShape{}))>());
|
||||
using SmemLayoutXT = decltype(tile_to_shape(
|
||||
SmemLayoutAtomXT{},
|
||||
make_shape(size<0>(TileShape{}), size<1>(TileShape{}), Int<StagesInput>{}),
|
||||
Step<_1,_2,_3>{}));
|
||||
|
||||
using EpilogueTileType = cutlass::epilogue::collective::EpilogueTileAuto;
|
||||
using Schedule = cutlass::epilogue::TmaWarpSpecialized;
|
||||
using EpilogueTile = Shape<Int<128>, Int<32>>;
|
||||
|
||||
using SmemLayoutAtomY = decltype(cutlass::gemm::collective::detail::ss_smem_selector<
|
||||
cute::GMMA::Major::MN, ElementY, decltype(get<0>(EpilogueTile{})), decltype(get<1>(EpilogueTile{}))>());
|
||||
using SmemLayoutY = decltype(tile_to_shape(
|
||||
SmemLayoutAtomY{},
|
||||
make_shape(size<0>(EpilogueTile{}), size<1>(EpilogueTile{}), Int<StagesOutput>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
using SmemLayoutStoreP = decltype(tile_to_shape(
|
||||
SmemLayoutAtomP{},
|
||||
append(make_shape(get<1>(TileShape{}), get<2>(TileShape{})), Int<1>{}),
|
||||
Step<_2,_1,_3>{}));
|
||||
|
||||
using CollectiveMainloop = cutlass::ssd::collective::SsdMainloopTmaWarpSpecialized<
|
||||
Element, ElementDA, ElementAcc, ElementY, TileShape,
|
||||
StagesInput, StagesOutput,
|
||||
TiledMmaIntra1, TiledMmaIntra2,
|
||||
TiledMmaInter1, TiledMmaInter2,
|
||||
SmemLayoutX, SmemLayoutB, SmemLayoutC, SmemLayoutP,
|
||||
SmemLayoutBT, SmemLayoutPT, SmemLayoutQ,
|
||||
TmemLayoutB, TmemLayoutQ>;
|
||||
using CollectiveEpilogue = cutlass::ssd::collective::SsdEpilogue<
|
||||
ElementAcc, Element, ElementDA, TileShape,
|
||||
EpilogueTile, SmemLayoutY, SmemLayoutStoreP, SmemLayoutXT, StagesInput, StagesOutput,
|
||||
HAS_D_, D_HAS_HDIM_>;
|
||||
using TileScheduler = cutlass::ssd::kernel::PersistentTileScheduler;
|
||||
using Kernel = cutlass::ssd::kernel::SsdKernelTmaWarpSpecialized<CollectiveMainloop, CollectiveEpilogue, TileScheduler>;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,519 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2025 - 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cutlass/cutlass.h"
|
||||
#include "cutlass/arch/reg_reconfig.h"
|
||||
#include "cutlass/pipeline/pipeline.hpp"
|
||||
#include "cutlass/arch/arch.h"
|
||||
|
||||
namespace cutlass::ssd::kernel {
|
||||
|
||||
using namespace cute;
|
||||
|
||||
template<
|
||||
class CollectiveMainloop_,
|
||||
class CollectiveEpilogue_,
|
||||
class TileScheduler_
|
||||
>
|
||||
struct SsdKernelTmaWarpSpecialized {
|
||||
|
||||
using CollectiveMainloop = CollectiveMainloop_;
|
||||
using CollectiveEpilogue = CollectiveEpilogue_;
|
||||
using TileScheduler = TileScheduler_;
|
||||
|
||||
// TileShape: LDN
|
||||
using TileShape = typename CollectiveMainloop::TileShape;
|
||||
// Force to use 1x1x1
|
||||
using ClusterShape = typename CollectiveMainloop::ClusterShape;
|
||||
using ArchTag = cutlass::arch::Sm100;
|
||||
|
||||
static constexpr uint32_t NumMmaThreads = NumThreadsPerWarp; // 1 warp
|
||||
static constexpr uint32_t NumEpilogueThreads = CollectiveEpilogue::ThreadCount;
|
||||
static constexpr uint32_t NumEpilogueWarps = NumEpilogueThreads / NumThreadsPerWarp;
|
||||
|
||||
// Pipeline for Tensor X
|
||||
using MainloopPipelineX = typename CollectiveMainloop::MainloopPipelineX;
|
||||
using PipelineStateX = typename cutlass::PipelineState<MainloopPipelineX::Stages>;
|
||||
using PipelineParamsX = typename MainloopPipelineX::Params;
|
||||
|
||||
// Pipeline for Tensor Delta && DeltaA
|
||||
using MainloopPipelineDelta = typename CollectiveMainloop::MainloopPipelineDelta;
|
||||
using PipelineStateDelta = typename cutlass::PipelineState<MainloopPipelineDelta::Stages>;
|
||||
using PipelineParamsDelta = typename MainloopPipelineDelta::Params;
|
||||
|
||||
// Pipeline for Tensor X
|
||||
using MainloopPipelineB = typename CollectiveMainloop::MainloopPipelineB;
|
||||
using PipelineStateB = typename cutlass::PipelineState<MainloopPipelineB::Stages>;
|
||||
using PipelineParamsB = typename MainloopPipelineB::Params;
|
||||
|
||||
// Pipeline for Tensor X
|
||||
using MainloopPipelineC = typename CollectiveMainloop::MainloopPipelineC;
|
||||
using PipelineStateC = typename cutlass::PipelineState<MainloopPipelineC::Stages>;
|
||||
using PipelineParamsC = typename MainloopPipelineC::Params;
|
||||
|
||||
// Pipeline for Intra Fusion
|
||||
using MainloopPipelineIntra = typename CollectiveMainloop::MainloopPipelineIntra;
|
||||
using PipelineStateIntra = typename cutlass::PipelineState<MainloopPipelineIntra::Stages>;
|
||||
using PipelineParamsIntra = typename MainloopPipelineIntra::Params;
|
||||
|
||||
// Pipeline for Inter Fusion
|
||||
using MainloopPipelineInter = typename CollectiveMainloop::MainloopPipelineInter;
|
||||
using PipelineStateInter = typename cutlass::PipelineState<MainloopPipelineInter::Stages>;
|
||||
using PipelineParamsInter = typename MainloopPipelineInter::Params;
|
||||
|
||||
// Pipeline for Accumulator
|
||||
using AccumulatorPipeline = typename CollectiveMainloop::AccumulatorPipeline;
|
||||
using AccumulatorPipelineState = typename CollectiveMainloop::AccumulatorPipelineState;
|
||||
using PipelineParamsAcc = typename AccumulatorPipeline::Params;
|
||||
|
||||
// Pipeline for Epilgoue store
|
||||
using EpiStorePipeline = typename CollectiveEpilogue::StorePipeline;
|
||||
using EpiStorePipelineState = typename CollectiveEpilogue::StorePipelineState;
|
||||
|
||||
// Pipeline for Epilgoue load D
|
||||
using EpiloadPipelineD = typename CollectiveEpilogue::EpiloadPipelineD;
|
||||
using PipelineParamsD = typename EpiloadPipelineD::Params;
|
||||
using PipelineStateD = typename cutlass::PipelineState<EpiloadPipelineD::Stages>;
|
||||
using TmemAllocator = typename cute::TMEM::Allocator1Sm;
|
||||
|
||||
struct SharedStorage {
|
||||
struct PipelineStorage : cute::aligned_struct<16, _1> {
|
||||
using PipelineStorageX = typename MainloopPipelineX::SharedStorage;
|
||||
using PipelineStorageDelta = typename MainloopPipelineDelta::SharedStorage;
|
||||
using PipelineStorageB = typename MainloopPipelineB::SharedStorage;
|
||||
using PipelineStorageC = typename MainloopPipelineC::SharedStorage;
|
||||
using PipelineStorageIntra = typename MainloopPipelineIntra::SharedStorage;
|
||||
using PipelineStorageInter = typename MainloopPipelineInter::SharedStorage;
|
||||
using PipelineStorageAcc = typename AccumulatorPipeline::SharedStorage;
|
||||
using PipelineStorageD = typename EpiloadPipelineD::SharedStorage;
|
||||
alignas(16) PipelineStorageX pipeline_storage_x;
|
||||
alignas(16) PipelineStorageDelta pipeline_storage_delta;
|
||||
alignas(16) PipelineStorageB pipeline_storage_b;
|
||||
alignas(16) PipelineStorageC pipeline_storage_c;
|
||||
alignas(16) PipelineStorageD pipeline_storage_d;
|
||||
alignas(16) PipelineStorageIntra pipeline_storage_intra;
|
||||
alignas(16) PipelineStorageInter pipeline_storage_inter;
|
||||
alignas(16) PipelineStorageAcc pipeline_storage_acc;
|
||||
} pipelines;
|
||||
|
||||
uint32_t tmem_base_ptr;
|
||||
|
||||
struct TensorStorage : cute::aligned_struct<128, _1> {
|
||||
using EpilogueTensorStorage = typename CollectiveEpilogue::TensorStorage;
|
||||
using MainloopTensorStorage = typename CollectiveMainloop::TensorStorage;
|
||||
|
||||
EpilogueTensorStorage epilogue;
|
||||
MainloopTensorStorage mainloop;
|
||||
} tensors;
|
||||
};
|
||||
|
||||
static constexpr int SharedStorageSize = sizeof(SharedStorage);
|
||||
// [G, B, EH, C, L, D, N]
|
||||
using ProblemShape = cute::tuple<int, int, int, int, int, int, int>;
|
||||
|
||||
struct Arguments {
|
||||
ProblemShape problem_size;
|
||||
typename CollectiveMainloop::Arguments mainloop;
|
||||
typename CollectiveEpilogue::Arguments epilogue;
|
||||
KernelHardwareInfo hw_info;
|
||||
};
|
||||
|
||||
struct Params {
|
||||
ProblemShape problem_size;
|
||||
typename CollectiveMainloop::Params mainloop;
|
||||
typename CollectiveEpilogue::Params epilogue;
|
||||
typename TileScheduler::Params tile_scheduler;
|
||||
};
|
||||
|
||||
static const int MinBlocksPerMultiprocessor = 1;
|
||||
static const int MaxThreadsPerBlock = 384;
|
||||
|
||||
static size_t get_workspace_size(Arguments const& args) { return 0; }
|
||||
static cutlass::Status initialize_workspace(Arguments const&, void*, cudaStream_t) {
|
||||
return cutlass::Status::kSuccess;
|
||||
}
|
||||
|
||||
static bool can_implement(Arguments const& args) {
|
||||
return CollectiveMainloop::can_implement(args.problem_size, args.mainloop);
|
||||
}
|
||||
|
||||
static dim3 get_grid_shape(Params const& params) {
|
||||
return TileScheduler::get_grid_shape(params.tile_scheduler);
|
||||
}
|
||||
|
||||
static dim3 get_block_shape() {
|
||||
dim3 block(MaxThreadsPerBlock, 1, 1);
|
||||
return block;
|
||||
}
|
||||
|
||||
static Params to_underlying_arguments(Arguments const& args, void* workspace) {
|
||||
return Params{
|
||||
args.problem_size,
|
||||
CollectiveMainloop::to_underlying_arguments(args.problem_size, args.mainloop, workspace),
|
||||
CollectiveEpilogue::to_underlying_arguments(args.problem_size, args.epilogue, workspace),
|
||||
TileScheduler::to_underlying_arguments(args.problem_size, args.hw_info, ClusterShape{}, TileShape{})
|
||||
};
|
||||
}
|
||||
|
||||
CUTLASS_DEVICE void operator()(const Params ¶ms, char* smem) {
|
||||
|
||||
using namespace cute;
|
||||
using X = Underscore;
|
||||
|
||||
// TBD
|
||||
enum class WarpCategory : int32_t {
|
||||
MMAInter = 0,
|
||||
MMAIntra = 1,
|
||||
DMA0 = 2, // Delta, X
|
||||
DMA1 = 3, // B, C
|
||||
PreInter = 4,
|
||||
PreIntra = 8
|
||||
};
|
||||
|
||||
// Parameters
|
||||
// [G, B, EH, C, L, D, N]
|
||||
auto C = get<3>(params.problem_size);
|
||||
|
||||
// Shared memory.
|
||||
auto& storage = *reinterpret_cast<SharedStorage*>(smem);
|
||||
|
||||
int lane_predicate = cute::elect_one_sync();
|
||||
int lane_idx = cutlass::canonical_lane_idx();
|
||||
int warp_idx = cutlass::canonical_warp_idx_sync();
|
||||
auto warp_category = (WarpCategory(warp_idx) < WarpCategory::PreInter) ?
|
||||
WarpCategory(warp_idx) :
|
||||
(WarpCategory(warp_idx) < WarpCategory::PreIntra) ?
|
||||
WarpCategory::PreInter : WarpCategory::PreIntra;
|
||||
|
||||
// Issue Tma Descriptor Prefetch from a single thread
|
||||
if ((warp_idx == 0) && lane_predicate) {
|
||||
CollectiveMainloop::prefetch_tma_descriptors(params.mainloop);
|
||||
}
|
||||
|
||||
// Pipeline (TBD)
|
||||
PipelineParamsX pipeline_params_x;
|
||||
pipeline_params_x.transaction_bytes = CollectiveMainloop::kXLoadBytes;
|
||||
pipeline_params_x.is_leader = lane_predicate && (warp_category == WarpCategory::DMA0);
|
||||
pipeline_params_x.num_consumers = 1 + 1 + cutlass::NumThreadsPerWarpGroup; // MMA0 + MMA1 + PreInter
|
||||
pipeline_params_x.initializing_warp = 4;
|
||||
|
||||
PipelineParamsDelta pipeline_params_delta;
|
||||
pipeline_params_delta.transaction_bytes = CollectiveMainloop::kDeltaLoadBytes + CollectiveMainloop::kDeltaALoadBytes;
|
||||
pipeline_params_delta.is_leader = lane_predicate && (warp_category == WarpCategory::DMA0);
|
||||
pipeline_params_delta.num_consumers = cutlass::NumThreadsPerWarpGroup + cutlass::NumThreadsPerWarpGroup; // PreInter + PreIntra
|
||||
pipeline_params_delta.initializing_warp = 5;
|
||||
|
||||
PipelineParamsB pipeline_params_b;
|
||||
pipeline_params_b.transaction_bytes = CollectiveMainloop::kBLoadBytes;
|
||||
pipeline_params_b.is_leader = lane_predicate && (warp_category == WarpCategory::DMA1);
|
||||
pipeline_params_b.num_consumers = 1 + cutlass::NumThreadsPerWarpGroup;
|
||||
pipeline_params_b.initializing_warp = 6;
|
||||
|
||||
PipelineParamsC pipeline_params_c;
|
||||
pipeline_params_c.transaction_bytes = CollectiveMainloop::kCLoadBytes;
|
||||
pipeline_params_c.is_leader = lane_predicate && (warp_category == WarpCategory::DMA1);
|
||||
pipeline_params_c.num_consumers = 1 + 1;
|
||||
pipeline_params_c.initializing_warp = 7;
|
||||
|
||||
PipelineParamsIntra pipeline_params_intra;
|
||||
pipeline_params_intra.producer_arv_count = 1;
|
||||
pipeline_params_intra.consumer_arv_count = cutlass::NumThreadsPerWarpGroup;
|
||||
pipeline_params_intra.initializing_warp = 8;
|
||||
|
||||
PipelineParamsIntra pipeline_params_inter;
|
||||
pipeline_params_inter.producer_arv_count = 1;
|
||||
pipeline_params_inter.consumer_arv_count = cutlass::NumThreadsPerWarpGroup;
|
||||
pipeline_params_inter.initializing_warp = 9;
|
||||
|
||||
PipelineParamsAcc pipeline_params_acc;
|
||||
pipeline_params_acc.producer_arv_count = 1;
|
||||
pipeline_params_acc.consumer_arv_count = cutlass::NumThreadsPerWarpGroup;
|
||||
pipeline_params_acc.initializing_warp = 10;
|
||||
|
||||
PipelineParamsD pipeline_params_d;
|
||||
pipeline_params_d.transaction_bytes = CollectiveEpilogue::kEpiloadDBytes;
|
||||
pipeline_params_d.is_leader = lane_predicate && (warp_category == WarpCategory::DMA0);
|
||||
pipeline_params_d.num_consumers = cutlass::NumThreadsPerWarpGroup;
|
||||
pipeline_params_d.initializing_warp = 11;
|
||||
|
||||
|
||||
if (warp_category == WarpCategory::DMA0) {
|
||||
pipeline_params_x.role = MainloopPipelineX::ThreadCategory::Producer;
|
||||
pipeline_params_delta.role = MainloopPipelineDelta::ThreadCategory::Producer;
|
||||
pipeline_params_d.role = EpiloadPipelineD::ThreadCategory::Producer;
|
||||
}
|
||||
if (warp_category == WarpCategory::DMA1) {
|
||||
pipeline_params_b.role = MainloopPipelineB::ThreadCategory::Producer;
|
||||
pipeline_params_c.role = MainloopPipelineC::ThreadCategory::Producer;
|
||||
}
|
||||
// TBD
|
||||
if (warp_category == WarpCategory::MMAInter) {
|
||||
pipeline_params_x.role = MainloopPipelineX::ThreadCategory::Consumer;
|
||||
// pipeline_params_b.role = MainloopPipelineB::ThreadCategory::Consumer;
|
||||
pipeline_params_c.role = MainloopPipelineC::ThreadCategory::Consumer;
|
||||
pipeline_params_inter.role = MainloopPipelineInter::ThreadCategory::Producer;
|
||||
pipeline_params_acc.role = AccumulatorPipeline::ThreadCategory::Producer;
|
||||
}
|
||||
if (warp_category == WarpCategory::MMAIntra) {
|
||||
pipeline_params_x.role = MainloopPipelineX::ThreadCategory::Consumer;
|
||||
pipeline_params_b.role = MainloopPipelineB::ThreadCategory::Consumer;
|
||||
pipeline_params_c.role = MainloopPipelineC::ThreadCategory::Consumer;
|
||||
pipeline_params_intra.role = MainloopPipelineIntra::ThreadCategory::Producer;
|
||||
}
|
||||
if (warp_category == WarpCategory::PreInter) {
|
||||
pipeline_params_b.role = MainloopPipelineB::ThreadCategory::Consumer;
|
||||
pipeline_params_delta.role = MainloopPipelineDelta::ThreadCategory::Consumer;
|
||||
pipeline_params_inter.role = MainloopPipelineInter::ThreadCategory::Consumer;
|
||||
}
|
||||
if (warp_category == WarpCategory::PreIntra) {
|
||||
pipeline_params_x.role = MainloopPipelineX::ThreadCategory::Consumer;
|
||||
pipeline_params_delta.role = MainloopPipelineDelta::ThreadCategory::Consumer;
|
||||
pipeline_params_acc.role = AccumulatorPipeline::ThreadCategory::Consumer;
|
||||
pipeline_params_intra.role = MainloopPipelineIntra::ThreadCategory::Consumer;
|
||||
pipeline_params_d.role = EpiloadPipelineD::ThreadCategory::Consumer;
|
||||
}
|
||||
|
||||
MainloopPipelineX pipeline_x(storage.pipelines.pipeline_storage_x, pipeline_params_x, Shape<_1,_1,_1>{});
|
||||
PipelineStateX mainloop_pipe_x_consumer;
|
||||
PipelineStateX mainloop_pipe_x_producer = cutlass::make_producer_start_state<MainloopPipelineX>();
|
||||
|
||||
MainloopPipelineDelta pipeline_delta(storage.pipelines.pipeline_storage_delta, pipeline_params_delta, Shape<_1,_1,_1>{});
|
||||
PipelineStateDelta mainloop_pipe_delta_consumer;
|
||||
PipelineStateDelta mainloop_pipe_delta_producer = cutlass::make_producer_start_state<MainloopPipelineDelta>();
|
||||
|
||||
MainloopPipelineB pipeline_b(storage.pipelines.pipeline_storage_b, pipeline_params_b, Shape<_1,_1,_1>{});
|
||||
PipelineStateB mainloop_pipe_b_consumer;
|
||||
PipelineStateB mainloop_pipe_b_producer = cutlass::make_producer_start_state<MainloopPipelineB>();
|
||||
|
||||
MainloopPipelineC pipeline_c(storage.pipelines.pipeline_storage_c, pipeline_params_c, Shape<_1,_1,_1>{});
|
||||
PipelineStateC mainloop_pipe_c_consumer;
|
||||
PipelineStateC mainloop_pipe_c_producer = cutlass::make_producer_start_state<MainloopPipelineC>();
|
||||
|
||||
EpiloadPipelineD pipeline_d(storage.pipelines.pipeline_storage_d, pipeline_params_d, Shape<_1,_1,_1>{});
|
||||
PipelineStateD epi_load_pipe_d_consumer;
|
||||
PipelineStateD epi_load_pipe_d_producer = cutlass::make_producer_start_state<EpiloadPipelineD>();
|
||||
|
||||
MainloopPipelineIntra pipeline_intra(storage.pipelines.pipeline_storage_intra, pipeline_params_intra, Shape<_1,_1,_1>{});
|
||||
PipelineStateIntra mainloop_pipe_intra_consumer;
|
||||
PipelineStateIntra mainloop_pipe_intra_producer = cutlass::make_producer_start_state<MainloopPipelineIntra>();
|
||||
|
||||
MainloopPipelineInter pipeline_inter(storage.pipelines.pipeline_storage_inter, pipeline_params_inter, Shape<_1,_1,_1>{});
|
||||
// Opposite pipeline state
|
||||
PipelineStateInter mainloop_pipe_inter_consumer = cutlass::make_producer_start_state<MainloopPipelineIntra>();
|
||||
PipelineStateInter mainloop_pipe_inter_producer;
|
||||
|
||||
AccumulatorPipeline pipeline_acc(storage.pipelines.pipeline_storage_acc, pipeline_params_acc, Shape<_1,_1,_1>{});
|
||||
AccumulatorPipelineState mainloop_pipe_acc_consumer;
|
||||
AccumulatorPipelineState mainloop_pipe_acc_producer = cutlass::make_producer_start_state<AccumulatorPipeline>();
|
||||
|
||||
// Epilogue Store pipeline
|
||||
using EpiStorePipeline = typename CollectiveEpilogue::StorePipeline;
|
||||
typename EpiStorePipeline::Params epi_store_pipeline_params;
|
||||
epi_store_pipeline_params.always_wait = true;
|
||||
EpiStorePipeline epi_store_pipeline(epi_store_pipeline_params);
|
||||
|
||||
PipelineState epi_store_pipe_producer_state = cutlass::make_producer_start_state<EpiStorePipeline>();
|
||||
|
||||
// Epilogue Store P pipeline
|
||||
using EpiStorePPipeline = typename CollectiveEpilogue::StorePPipeline;
|
||||
typename EpiStorePPipeline::Params epi_store_p_pipeline_params;
|
||||
epi_store_p_pipeline_params.always_wait = true;
|
||||
EpiStorePPipeline epi_store_p_pipeline(epi_store_p_pipeline_params);
|
||||
|
||||
PipelineState epi_store_p_pipe_producer_state = cutlass::make_producer_start_state<EpiStorePPipeline>();
|
||||
|
||||
// Tmem allocator
|
||||
TmemAllocator tmem_allocator{};
|
||||
// We need this to guarantee that the Pipeline init is visible
|
||||
// To all producers and consumer blocks in the Cluster
|
||||
// and to finish smem init
|
||||
if constexpr (size(ClusterShape{}) > 1) {
|
||||
cute::cluster_arrive_relaxed();
|
||||
cute::cluster_wait();
|
||||
}
|
||||
else {
|
||||
__syncthreads();
|
||||
}
|
||||
|
||||
// ignore the tmem alloc
|
||||
arch::NamedBarrier tmem_allocation_result_barrier(NumMmaThreads + NumMmaThreads + NumEpilogueThreads + NumEpilogueThreads,
|
||||
cutlass::arch::ReservedNamedBarriers::TmemAllocBarrier);
|
||||
if (warp_category == WarpCategory::MMAIntra) {
|
||||
tmem_allocator.allocate(TmemAllocator::Sm100TmemCapacityColumns, &storage.tmem_base_ptr);
|
||||
__syncwarp();
|
||||
tmem_allocation_result_barrier.arrive();
|
||||
}
|
||||
if (warp_category == WarpCategory::MMAInter || warp_category == WarpCategory::PreIntra || warp_category == WarpCategory::PreInter) {
|
||||
tmem_allocation_result_barrier.arrive_and_wait();
|
||||
}
|
||||
|
||||
// Kernel implement(TBD)
|
||||
|
||||
CollectiveMainloop collective_mainloop;
|
||||
CollectiveEpilogue collective_epilogue;
|
||||
TileScheduler tile_scheduler{params.tile_scheduler};
|
||||
|
||||
auto mma_output_intra = collective_mainloop.get_mma_intra_acc();
|
||||
auto mma_output_inter = collective_mainloop.get_mma_inter_acc();
|
||||
|
||||
if (warp_category == WarpCategory::DMA0) {
|
||||
auto load_input = collective_mainloop.load_x_init(params.mainloop, params.problem_size);
|
||||
for (; tile_scheduler.is_valid(); ++tile_scheduler) {
|
||||
auto blk_coord = tile_scheduler.get_block_coord();
|
||||
auto blk_coord_eh = tile_scheduler.get_block_coord_eh();
|
||||
// Load D
|
||||
collective_epilogue.load_d(
|
||||
blk_coord_eh, params.epilogue, params.problem_size,
|
||||
pipeline_d, epi_load_pipe_d_producer,
|
||||
storage.tensors.mainloop
|
||||
);
|
||||
// Load X
|
||||
// Load Delta
|
||||
// Load DeltaA
|
||||
collective_mainloop.load_x_delta(
|
||||
blk_coord, params.mainloop, params.problem_size,
|
||||
pipeline_x, mainloop_pipe_x_producer,
|
||||
pipeline_delta, mainloop_pipe_delta_producer,
|
||||
load_input,
|
||||
storage.tensors.mainloop
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (warp_category == WarpCategory::DMA1) {
|
||||
auto load_input_b = collective_mainloop.load_b_init(params.mainloop, params.problem_size);
|
||||
auto load_input_c = collective_mainloop.load_c_init(params.mainloop, params.problem_size);
|
||||
for (; tile_scheduler.is_valid(); ++tile_scheduler) {
|
||||
auto blk_coord = tile_scheduler.get_block_coord_b();
|
||||
// Load B
|
||||
// Load C
|
||||
collective_mainloop.load_b_c(
|
||||
blk_coord, params.mainloop, params.problem_size,
|
||||
pipeline_b, mainloop_pipe_b_producer,
|
||||
pipeline_c, mainloop_pipe_c_producer,
|
||||
load_input_b, load_input_c,
|
||||
storage.tensors.mainloop
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (warp_category == WarpCategory::MMAIntra) {
|
||||
auto [mma_inputs_1, mma_inputs_2] = collective_mainloop.mma_intra_init(storage.tensors.mainloop);
|
||||
for (; tile_scheduler.is_valid(); ++tile_scheduler) {
|
||||
for (int chunk = 0; chunk < C; ++chunk) {
|
||||
collective_mainloop.mma_intra(
|
||||
pipeline_b, mainloop_pipe_b_consumer,
|
||||
pipeline_c, mainloop_pipe_c_consumer,
|
||||
pipeline_x, mainloop_pipe_x_consumer,
|
||||
pipeline_intra, mainloop_pipe_intra_producer,
|
||||
mma_inputs_1, mma_inputs_2,
|
||||
mma_output_intra
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (warp_category == WarpCategory::MMAInter) {
|
||||
auto [mma_inputs_1, mma_inputs_2] = collective_mainloop.mma_inter_init(storage.tensors.mainloop);
|
||||
for (; tile_scheduler.is_valid(); ++tile_scheduler) {
|
||||
for (int chunk = 0; chunk < C; ++chunk) {
|
||||
collective_mainloop.mma_inter(
|
||||
pipeline_c, mainloop_pipe_c_consumer,
|
||||
pipeline_x, mainloop_pipe_x_consumer,
|
||||
pipeline_inter, mainloop_pipe_inter_producer,
|
||||
pipeline_acc, mainloop_pipe_acc_producer,
|
||||
mma_inputs_1, mma_inputs_2,
|
||||
mma_output_inter
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (warp_category == WarpCategory::PreIntra) {
|
||||
for (; tile_scheduler.is_valid(); ++tile_scheduler) {
|
||||
auto blk_coord = tile_scheduler.get_block_coord();
|
||||
auto blk_coord_eh = tile_scheduler.get_block_coord_eh();
|
||||
bool is_first_iteration = true;
|
||||
for (int chunk = 0; chunk < C; ++chunk) {
|
||||
collective_mainloop.pre_intra(
|
||||
pipeline_delta, mainloop_pipe_delta_consumer,
|
||||
pipeline_intra, mainloop_pipe_intra_consumer,
|
||||
mma_output_intra,
|
||||
storage.tensors.mainloop
|
||||
);
|
||||
collective_epilogue.store(
|
||||
chunk, blk_coord, blk_coord_eh, params.epilogue, params.problem_size,
|
||||
pipeline_intra, mainloop_pipe_intra_consumer,
|
||||
pipeline_acc, mainloop_pipe_acc_consumer,
|
||||
pipeline_delta, mainloop_pipe_delta_consumer,
|
||||
pipeline_x, mainloop_pipe_x_consumer,
|
||||
pipeline_d, epi_load_pipe_d_consumer,
|
||||
epi_store_pipeline, epi_store_pipe_producer_state,
|
||||
mma_output_intra,
|
||||
mma_output_inter,
|
||||
storage.tensors.mainloop, storage.tensors.epilogue,
|
||||
is_first_iteration
|
||||
);
|
||||
is_first_iteration = false;
|
||||
}
|
||||
if constexpr (CollectiveEpilogue::HasBlockScaleD) {
|
||||
// update the barrier
|
||||
pipeline_d.consumer_release(epi_load_pipe_d_consumer);
|
||||
++epi_load_pipe_d_consumer;
|
||||
}
|
||||
}
|
||||
uint32_t free_stage_ptr = storage.tmem_base_ptr;
|
||||
tmem_allocator.free(free_stage_ptr, TmemAllocator::Sm100TmemCapacityColumns);
|
||||
}
|
||||
else if (warp_category == WarpCategory::PreInter) {
|
||||
for (; tile_scheduler.is_valid(); ++tile_scheduler) {
|
||||
auto [tState] = collective_mainloop.state_init(mma_output_inter, storage.tensors.mainloop);
|
||||
for (int chunk = 0; chunk < C; ++chunk) {
|
||||
collective_mainloop.pre_inter(
|
||||
pipeline_b, mainloop_pipe_b_consumer,
|
||||
pipeline_delta, mainloop_pipe_delta_consumer,
|
||||
pipeline_inter, mainloop_pipe_inter_consumer,
|
||||
mma_output_inter,
|
||||
tState,
|
||||
storage.tensors.mainloop
|
||||
);
|
||||
}
|
||||
auto blk_coord = tile_scheduler.get_block_coord();
|
||||
// Epilogue Fstate store
|
||||
collective_epilogue.store_p(
|
||||
blk_coord, params.epilogue, params.problem_size,
|
||||
epi_store_p_pipeline, epi_store_p_pipe_producer_state,
|
||||
storage.tensors.mainloop
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace cutlass::ssd::kernel
|
||||
@@ -0,0 +1,132 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2025 - 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from
|
||||
* this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**************************************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "cutlass/cutlass.h"
|
||||
#include "cutlass/fast_math.h"
|
||||
#include "cutlass/kernel_hardware_info.h"
|
||||
|
||||
namespace cutlass::ssd::kernel {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
struct PersistentTileScheduler {
|
||||
|
||||
struct Params {
|
||||
int num_blocks;
|
||||
int num_groups;
|
||||
FastDivmod divmod_eh;
|
||||
FastDivmod divmod_ngroup_ratio;
|
||||
|
||||
KernelHardwareInfo hw_info;
|
||||
};
|
||||
|
||||
int block_idx = 0;
|
||||
Params params;
|
||||
|
||||
CUTLASS_DEVICE
|
||||
PersistentTileScheduler(Params const& params) : block_idx(blockIdx.x), params(params) {}
|
||||
|
||||
template<class ProblemSize, class ClusterShape, class TileShape>
|
||||
static Params to_underlying_arguments(
|
||||
ProblemSize const& problem_size, KernelHardwareInfo hw_info,
|
||||
ClusterShape const& cluster_shape, TileShape const& tile_shape)
|
||||
{
|
||||
using namespace cute;
|
||||
auto [G, B, EH, C, L, D, N] = problem_size;
|
||||
|
||||
// Get SM count if needed, otherwise use user supplied SM count
|
||||
int sm_count = hw_info.sm_count;
|
||||
if (sm_count <= 0) {
|
||||
CUTLASS_TRACE_HOST(" WARNING: Arguments do not include a valid SM count.\n"
|
||||
" For optimal performance, populate the arguments KernelHardwareInfo struct with the SM count.");
|
||||
sm_count = KernelHardwareInfo::query_device_multiprocessor_count(hw_info.device_id);
|
||||
}
|
||||
|
||||
CUTLASS_TRACE_HOST("to_underlying_arguments(): Setting persistent grid SM count to " << sm_count);
|
||||
hw_info.sm_count = sm_count;
|
||||
|
||||
int num_blocks = B * EH;
|
||||
int ngroup_ratio = EH / G;
|
||||
|
||||
return Params {
|
||||
num_blocks,
|
||||
G,
|
||||
{EH},
|
||||
{ngroup_ratio},
|
||||
hw_info
|
||||
};
|
||||
}
|
||||
|
||||
static dim3 get_grid_shape(Params const& params) {
|
||||
dim3 grid(std::min(params.num_blocks, params.hw_info.sm_count), 1, 1);
|
||||
return grid;
|
||||
}
|
||||
|
||||
CUTLASS_DEVICE
|
||||
bool is_valid() {
|
||||
return block_idx < params.num_blocks;
|
||||
}
|
||||
|
||||
CUTLASS_DEVICE
|
||||
auto get_block_coord() {
|
||||
return block_idx;
|
||||
}
|
||||
|
||||
CUTLASS_DEVICE
|
||||
auto get_block_coord_b() {
|
||||
using namespace cute;
|
||||
int eh_idx, b_idx;
|
||||
int g_idx, rest_idx;
|
||||
params.divmod_eh(b_idx, eh_idx, block_idx);
|
||||
params.divmod_ngroup_ratio(g_idx, rest_idx, eh_idx);
|
||||
return (params.num_groups * b_idx + g_idx);
|
||||
}
|
||||
|
||||
CUTLASS_DEVICE
|
||||
auto get_block_coord_eh() {
|
||||
using namespace cute;
|
||||
int eh_idx, b_idx;
|
||||
params.divmod_eh(b_idx, eh_idx, block_idx);
|
||||
return eh_idx;
|
||||
}
|
||||
|
||||
CUTLASS_DEVICE
|
||||
PersistentTileScheduler& operator++() {
|
||||
block_idx += gridDim.x;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
} // namespace cutlass::ssd::kernel
|
||||
Reference in New Issue
Block a user