v3.9 (#2185)
* v3.8 update x * fix blackwell gg * doc change * doc change * doc change --------- Co-authored-by: yuzhai <yuzhai@nvidia.com> Co-authored-by: Haicheng Wu <haichengw@nvidia.com> Co-authored-by: Haicheng Wu <57973641+hwu36@users.noreply.github.com>
This commit is contained in:
co-authored by
yuzhai
Haicheng Wu
Haicheng Wu
parent
8c4d1dc47d
commit
62750a2b75
@@ -626,7 +626,7 @@ make_tma_atom_im2col(CopyOp,
|
||||
auto tma_layout_trunc = take<0,smem_tma_rank>(tma_layout_full);
|
||||
|
||||
// Split according to the portion each multicast CTA will be responsible for
|
||||
auto tma_layout_vt = logical_divide(tma_layout_trunc, shape_div(size(tma_layout_trunc), num_multicast));
|
||||
auto tma_layout_vt = logical_divide(tma_layout_trunc, safe_div(size(tma_layout_trunc), num_multicast));
|
||||
|
||||
#if 0
|
||||
print("glayout_basis : "); print(glayout_basis); print("\n");
|
||||
@@ -748,7 +748,7 @@ make_tma_copy_im2col(CopyOp const& copy_op,
|
||||
// Scale that up to cover all of the smem_coords
|
||||
auto layout_V = tile_to_shape(make_layout(layout_v), size(cta_v_map));
|
||||
// CTA T -> smem idx
|
||||
auto layout_t = make_layout(cosize(cta_t_map), shape_div(num_elems_per_tma, cosize(cta_t_map)));
|
||||
auto layout_t = make_layout(cosize(cta_t_map), safe_div(num_elems_per_tma, cosize(cta_t_map)));
|
||||
// CTA TID -> smem coord
|
||||
auto layout_T = composition(inv_smem_layout, composition(layout_t, cta_t_map));
|
||||
// Combine with the T mapping
|
||||
|
||||
@@ -1165,7 +1165,7 @@ make_tma_copy_tiled(CopyOp const& copy_op,
|
||||
// Scale that up to cover all of the smem_coords
|
||||
auto layout_V = tile_to_shape(make_layout(layout_v), size(cta_v_map));
|
||||
// CTA T -> smem idx
|
||||
auto layout_t = make_layout(cosize(cta_t_map), shape_div(num_elems_per_tma, cosize(cta_t_map)));
|
||||
auto layout_t = make_layout(cosize(cta_t_map), safe_div(num_elems_per_tma, cosize(cta_t_map)));
|
||||
// CTA TID -> smem coord
|
||||
auto layout_T = composition(inv_smem_layout, composition(layout_t, cta_t_map));
|
||||
// Combine with the T mapping
|
||||
@@ -1400,16 +1400,19 @@ tma_partition(Copy_Atom<Args...> const& copy_atom,
|
||||
}
|
||||
|
||||
// TMA Multicast Masks Calculation
|
||||
template <int Mode, class CtaLayout, class CtaCoord>
|
||||
template <class CtaLayout, class CtaCoord>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
uint16_t
|
||||
create_tma_multicast_mask(CtaLayout const& cta_layout_vmnk,
|
||||
CtaCoord const& cta_coord_vmnk)
|
||||
{
|
||||
auto cta_coord_slicer = replace<Mode>(cta_coord_vmnk, _);
|
||||
auto [cta_layout, elected_cta] = slice_and_offset(cta_coord_slicer, cta_layout_vmnk);
|
||||
auto [cta_layout, elected_cta] = slice_and_offset(cta_coord_vmnk, cta_layout_vmnk);
|
||||
|
||||
uint16_t mcast_mask = 0;
|
||||
if constexpr (rank_v<decltype(cta_layout)> == 0) {
|
||||
// Trivial case with no additional ctas
|
||||
mcast_mask = uint16_t(1);
|
||||
} else
|
||||
if constexpr (rank_v<decltype(cta_layout)> == 1 and depth_v<decltype(cta_layout)> <= 1 and
|
||||
not is_static<decltype(cta_layout)>::value) {
|
||||
// Get the instruction code -- optimized for dynamic flat-rank-1 cta_layout
|
||||
@@ -1432,6 +1435,16 @@ create_tma_multicast_mask(CtaLayout const& cta_layout_vmnk,
|
||||
return mcast_mask;
|
||||
}
|
||||
|
||||
// Projections multicast mask
|
||||
template <int Mode, int... Modes, class CtaLayout, class CtaCoord>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
uint16_t
|
||||
create_tma_multicast_mask(CtaLayout const& cta_layout_vmnk,
|
||||
CtaCoord const& cta_coord_vmnk)
|
||||
{
|
||||
return create_tma_multicast_mask<Modes...>(cta_layout_vmnk, replace<Mode>(cta_coord_vmnk, _));
|
||||
}
|
||||
|
||||
////////////////////////////////////
|
||||
// Make TMA copy A/B/C
|
||||
///////////////////////////////////
|
||||
|
||||
@@ -154,9 +154,10 @@ struct MMA_Atom<MMA_Traits<MMAOperation, Args...>>
|
||||
if constexpr (has_dereference<FrgTypeA>::value) {
|
||||
// If the intended FrgTypeA is a view (of the current tensor), forward the whole
|
||||
static_assert(is_same<ValTypeA, typename remove_cvref_t<ATensor>::value_type>::value
|
||||
|
||||
|| (sizeof_bits_v<typename remove_cvref_t<ATensor>::value_type> == 8 &&
|
||||
(sizeof_bits_v<ValTypeA> == 8 || sizeof_bits_v<ValTypeA> == 6 || sizeof_bits_v<ValTypeA> == 4))
|
||||
|| (sizeof_bits_v<typename remove_cvref_t<ATensor>::value_type> == 4 &&
|
||||
(sizeof_bits_v<ValTypeA> == 4 || sizeof_bits_v<ValTypeA> == 3 || sizeof_bits_v<ValTypeA> == 2))
|
||||
, "Expecting ValTypeA type");
|
||||
return make_tensor<FrgTypeA>(static_cast<ATensor&&>(atensor));
|
||||
} else {
|
||||
@@ -1117,4 +1118,7 @@ print_svg(TiledMMA<Args...> const &mma) {
|
||||
#include <cute/atom/mma_traits_sm90.hpp>
|
||||
#include <cute/atom/mma_traits_sm90_gmma.hpp>
|
||||
#include <cute/atom/mma_traits_sm100.hpp>
|
||||
#include <cute/atom/mma_traits_sm120.hpp>
|
||||
#include <cute/atom/mma_traits_sm120_sparse.hpp>
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,262 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2025 - 2025 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 <cute/arch/mma_sm120.hpp>
|
||||
#include <cute/atom/mma_traits.hpp>
|
||||
#include <cute/atom/mma_traits_sm80.hpp>
|
||||
#include <cute/layout.hpp>
|
||||
#include <cute/numeric/numeric_types.hpp>
|
||||
|
||||
namespace cute
|
||||
{
|
||||
|
||||
namespace SM120::BLOCKSCALED {
|
||||
|
||||
template <class MMAOp,
|
||||
class TD, class DLayout,
|
||||
class TA, class ALayout,
|
||||
class TB, class BLayout,
|
||||
class TC, class CLayout>
|
||||
CUTE_HOST_DEVICE constexpr void
|
||||
mma_unpack(MMA_Traits<MMAOp> const& traits,
|
||||
Tensor<TD, DLayout> & D,
|
||||
Tensor<TA, ALayout> const& A_zipped,
|
||||
Tensor<TB, BLayout> const& B_zipped,
|
||||
Tensor<TC, CLayout> const& C)
|
||||
{
|
||||
static_assert(is_rmem<TD>::value, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem<TA>::value, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem<TB>::value, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem<TC>::value, "Expected registers in MMA_Atom::call");
|
||||
|
||||
// Register value types from the MMA_Operation register arrays
|
||||
using RegTypeD = typename remove_extent<typename MMAOp::DRegisters>::type;
|
||||
using RegTypeA = typename remove_extent<typename MMAOp::ARegisters>::type;
|
||||
using RegTypeB = typename remove_extent<typename MMAOp::BRegisters>::type;
|
||||
using RegTypeC = typename remove_extent<typename MMAOp::CRegisters>::type;
|
||||
using RegTypeSFA = typename remove_extent<typename MMAOp::SFARegisters>::type;
|
||||
using RegTypeSFB = typename remove_extent<typename MMAOp::SFBRegisters>::type;
|
||||
|
||||
constexpr int RegNumD = extent<typename MMAOp::DRegisters>::value;
|
||||
constexpr int RegNumA = extent<typename MMAOp::ARegisters>::value;
|
||||
constexpr int RegNumB = extent<typename MMAOp::BRegisters>::value;
|
||||
constexpr int RegNumC = extent<typename MMAOp::CRegisters>::value;
|
||||
constexpr int RegNumSFA = extent<typename MMAOp::SFARegisters>::value;
|
||||
constexpr int RegNumSFB = extent<typename MMAOp::SFBRegisters>::value;
|
||||
|
||||
auto [A, SFA] = unzip_tensor(A_zipped);
|
||||
auto [B, SFB] = unzip_tensor(B_zipped);
|
||||
|
||||
using Shape_MNK = typename MMA_Traits<MMAOp>::Shape_MNK;
|
||||
constexpr int SFVecSize = MMA_Traits<MMAOp>::SFVecSize;
|
||||
|
||||
// Assert logical size
|
||||
CUTE_STATIC_ASSERT_V(size(SFA) == size<2>(Shape_MNK{}));
|
||||
CUTE_STATIC_ASSERT_V(size(SFB) == size<2>(Shape_MNK{}));
|
||||
|
||||
// Assert physical size
|
||||
CUTE_STATIC_ASSERT(decltype(cosize(layout(SFA))){} == size<2>(Shape_MNK{}) / SFVecSize);
|
||||
CUTE_STATIC_ASSERT(decltype(cosize(layout(SFB))){} == size<2>(Shape_MNK{}) / SFVecSize);
|
||||
|
||||
Tensor rA = recast<RegTypeA>(A);
|
||||
Tensor rB = recast<RegTypeB>(B);
|
||||
CUTE_STATIC_ASSERT_V(size(rA) == Int<RegNumA>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rB) == Int<RegNumB>{});
|
||||
|
||||
Tensor rD = recast<RegTypeD>(D);
|
||||
Tensor rC = recast<RegTypeC>(C);
|
||||
CUTE_STATIC_ASSERT_V(size(rD) == Int<RegNumD>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rC) == Int<RegNumC>{});
|
||||
|
||||
Tensor rSFA = recast<RegTypeSFA>(filter_zeros(SFA));
|
||||
Tensor rSFB = recast<RegTypeSFB>(filter_zeros(SFB));
|
||||
|
||||
CUTE_STATIC_ASSERT_V(size(rSFA) == Int<RegNumSFA>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rSFB) == Int<RegNumSFB>{});
|
||||
|
||||
detail::explode(MMAOp::fma,
|
||||
rD, make_int_sequence<RegNumD>{},
|
||||
rA, make_int_sequence<RegNumA>{},
|
||||
rB, make_int_sequence<RegNumB>{},
|
||||
rC, make_int_sequence<RegNumC>{},
|
||||
rSFA, make_int_sequence<RegNumSFA>{},
|
||||
rSFB, make_int_sequence<RegNumSFB>{});
|
||||
}
|
||||
} // namespace SM120::BLOCKSCALED
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// MMA F8F6F4 16x8x32 TN
|
||||
template <class a_type, class b_type, class c_type>
|
||||
struct MMA_Traits<SM120_16x8x32_TN<a_type, b_type, c_type>>
|
||||
: MMA_Traits<SM80_16x8x32_S32S8S8S32_TN>
|
||||
{
|
||||
// The MMA accepts 8-bit inputs regardless of the types for A and B
|
||||
using ValTypeA = uint8_t;
|
||||
using ValTypeB = uint8_t;
|
||||
|
||||
using ValTypeD = c_type;
|
||||
using ValTypeC = c_type;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// MMA MXF8F6F4 16x8x64 TN
|
||||
template <class a_type, class b_type, class c_type, class sf_type, int VS>
|
||||
struct MMA_Traits<SM120::BLOCKSCALED::SM120_16x8x64_TN_VS<a_type, b_type, c_type, sf_type, VS>>
|
||||
{
|
||||
// The MMA accepts 4-bit inputs regardless of the types for A and B
|
||||
using ValTypeA = uint4_t;
|
||||
using ValTypeB = uint4_t;
|
||||
|
||||
using ValTypeD = c_type;
|
||||
using ValTypeC = c_type;
|
||||
|
||||
using ValTypeSF = sf_type;
|
||||
constexpr static int SFVecSize = VS;
|
||||
|
||||
using Shape_MNK = Shape<_16,_8,_64>;
|
||||
using ThrID = Layout<_32>;
|
||||
|
||||
// (T32,V32) -> (M16,K64)
|
||||
using ALayout = Layout<Shape <Shape < _4,_8>,Shape < _8,_2, _2>>,
|
||||
Stride<Stride<_128,_1>,Stride<_16,_8,_512>>>;
|
||||
// (T32,V16) -> (M16,K64)
|
||||
using BLayout = Layout<Shape <Shape < _4,_8>,Shape <_8, _2>>,
|
||||
Stride<Stride<_64,_1>,Stride<_8,_256>>>;
|
||||
// (T32,V64) -> (M16,K64)
|
||||
using SFALayout = Layout<Shape <Shape <_2,_2,_8>,_64>, // Effectively 16 threads due to the 2:0 mode
|
||||
Stride<Stride<_8,_0,_1>,_16>>;
|
||||
// (T32,V64) -> (N8,K64)
|
||||
using SFBLayout = Layout<Shape <Shape <_4,_8>,_64>, // Effectively 8 threads due to the 4:0 mode
|
||||
Stride<Stride<_0,_1>, _8>>;
|
||||
// (T32,V4) -> (M16,N8)
|
||||
using CLayout = SM80_16x8_Row;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// MMA MXF8F6F4 16x8x32 TN
|
||||
template <class a_type, class b_type, class c_type, class sf_type, int VS>
|
||||
struct MMA_Traits<SM120::BLOCKSCALED::SM120_16x8x32_TN_VS<a_type, b_type, c_type, sf_type, VS>>
|
||||
{
|
||||
using UnderlyingTraits = MMA_Traits<SM120_16x8x32_TN<a_type, b_type, c_type>>;
|
||||
|
||||
// The MMA accepts 8-bit inputs regardless of the types for A and B
|
||||
using ValTypeA = typename UnderlyingTraits::ValTypeA;
|
||||
using ValTypeB = typename UnderlyingTraits::ValTypeB;
|
||||
|
||||
using ValTypeD = typename UnderlyingTraits::ValTypeD;
|
||||
using ValTypeC = typename UnderlyingTraits::ValTypeC;
|
||||
|
||||
using Shape_MNK = typename UnderlyingTraits::Shape_MNK;
|
||||
using ThrID = typename UnderlyingTraits::ThrID;
|
||||
|
||||
using ALayout = typename UnderlyingTraits::ALayout;
|
||||
using BLayout = typename UnderlyingTraits::BLayout;
|
||||
using CLayout = typename UnderlyingTraits::CLayout;
|
||||
|
||||
// Scaling factor
|
||||
using ValTypeSF = sf_type;
|
||||
constexpr static int SFVecSize = VS;
|
||||
|
||||
// (T32,V32) -> (M16,K32)
|
||||
using SFALayout = Layout<Shape <Shape <_2,_2,_8>,_32>, // Effectively 16 threads due to the 2:0 mode
|
||||
Stride<Stride<_8,_0,_1>,_16>>;
|
||||
// (T32,V32) -> (N8,K32)
|
||||
using SFBLayout = Layout<Shape <Shape <_4,_8>,_32>, // Effectively 8 threads due to the 4:0 mode
|
||||
Stride<Stride<_0,_1>, _8>>;
|
||||
};
|
||||
|
||||
// Transform if needed
|
||||
template<class MMA_Op, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_A(MMA_Op const& op, Tensor&& tensor) {
|
||||
}
|
||||
template<class MMA_Op, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_B(MMA_Op const& op, Tensor&& tensor) {
|
||||
}
|
||||
|
||||
// For SM120 MMA F8F6F4 input fp4, the operand A/B are load from ld.matrix.
|
||||
// ld.matrix b4x16_p64 places FP4 data at the first four bits in each
|
||||
// eight-bit container, whereas MMA F8F6F4 expects the four-bit data to be in
|
||||
// the middle of the eight-bit container. Thus, e2m1 operands being fed
|
||||
// to MMA F8F6F4 must be shifted left by two bits.
|
||||
// 0b0000ABCD --> 0b00ABCD00
|
||||
// NOTE: Same transformation is NOT needed for FP6 and FP8.
|
||||
template<class AType, class BType, class... MMAArgs, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_A(SM120_16x8x32_TN<AType, BType, MMAArgs ...> const&, Tensor&& tensor) {
|
||||
using RegisterTypeA = typename remove_extent<typename
|
||||
SM120_16x8x32_TN<AType, BType, MMAArgs ...>::ARegisters>::type;
|
||||
if constexpr (cute::is_same_v<AType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeA>(tensor), [](RegisterTypeA& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
template<class AType, class BType, class... MMAArgs, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_B(SM120_16x8x32_TN<AType, BType, MMAArgs ...> const&, Tensor&& tensor) {
|
||||
using RegisterTypeB = typename remove_extent<typename
|
||||
SM120_16x8x32_TN<AType, BType, MMAArgs ...>::BRegisters>::type;
|
||||
if constexpr (cute::is_same_v<BType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeB>(tensor), [](RegisterTypeB& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
|
||||
namespace SM120::BLOCKSCALED {
|
||||
|
||||
// Template function with scale factor needs to enmuerate types one by one, as template
|
||||
// arguments contatins two variadic lists, which cannot be deduced in one shot.
|
||||
template<class AType, class BType, class CType, class SFType, int VS, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_A(SM120::BLOCKSCALED::SM120_16x8x32_TN_VS<AType, BType, CType, SFType, VS> const&, Tensor&& tensor) {
|
||||
using RegisterTypeA = typename remove_extent<typename
|
||||
SM120::BLOCKSCALED::SM120_16x8x32_TN_VS<AType, BType, CType, SFType, VS>::ARegisters>::type;
|
||||
if constexpr (cute::is_same_v<AType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeA>(tensor), [](RegisterTypeA& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
template<class AType, class BType, class CType, class SFType, int VS, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_B(SM120::BLOCKSCALED::SM120_16x8x32_TN_VS<AType, BType, CType, SFType, VS> const&, Tensor&& tensor) {
|
||||
using RegisterTypeB = typename remove_extent<typename
|
||||
SM120::BLOCKSCALED::SM120_16x8x32_TN_VS<AType, BType, CType, SFType, VS>::BRegisters>::type;
|
||||
if constexpr (cute::is_same_v<BType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeB>(tensor), [](RegisterTypeB& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // end namespace cute
|
||||
@@ -0,0 +1,326 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2025 - 2025 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 <cute/arch/mma_sm120.hpp>
|
||||
#include <cute/arch/mma_sm120_sparse.hpp>
|
||||
#include <cute/atom/mma_traits.hpp>
|
||||
#include <cute/layout.hpp>
|
||||
#include <cute/numeric/numeric_types.hpp>
|
||||
|
||||
namespace cute
|
||||
{
|
||||
|
||||
namespace {
|
||||
|
||||
// (T32,V4) -> (M16,N8)
|
||||
using SM120_16x8_Row = Layout<Shape <Shape < _4,_8>,Shape < _2,_2>>,
|
||||
Stride<Stride<_32,_1>,Stride<_16,_8>>>;
|
||||
|
||||
}
|
||||
|
||||
namespace SM120::BLOCKSCALED::SPARSE
|
||||
{
|
||||
|
||||
// Unpack explode/mma call with sparse and block scalaring inputs.
|
||||
template <class MMAOp,
|
||||
class TD, class DLayout,
|
||||
class TA, class ALayout,
|
||||
class TB, class BLayout,
|
||||
class TC, class CLayout>
|
||||
CUTE_HOST_DEVICE constexpr void
|
||||
mma_unpack(MMA_Traits<MMAOp> const&,
|
||||
Tensor<TD, DLayout> & D,
|
||||
Tensor<TA, ALayout> const& A,
|
||||
Tensor<TB, BLayout> const& B,
|
||||
Tensor<TC, CLayout> const& C)
|
||||
{
|
||||
static_assert(is_rmem_v<TD>, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem_v<TA>, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem_v<TB>, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem_v<TC>, "Expected registers in MMA_Atom::call");
|
||||
using DRegisters = typename MMAOp::DRegisters;
|
||||
using ARegisters = typename MMAOp::ARegisters;
|
||||
using ERegisters = typename MMAOp::ERegisters;
|
||||
using BRegisters = typename MMAOp::BRegisters;
|
||||
using CRegisters = typename MMAOp::CRegisters;
|
||||
using SFARegisters = typename MMAOp::SFARegisters;
|
||||
using SFBRegisters = typename MMAOp::SFBRegisters;
|
||||
// Register value types from the MMAOp register arrays
|
||||
using RegTypeD = typename remove_extent<DRegisters>::type;
|
||||
using RegTypeA = typename remove_extent<ARegisters>::type;
|
||||
using RegTypeE = typename remove_extent<ERegisters>::type;
|
||||
using RegTypeB = typename remove_extent<BRegisters>::type;
|
||||
using RegTypeC = typename remove_extent<CRegisters>::type;
|
||||
using RegTypeSFA = typename remove_extent<SFARegisters>::type;
|
||||
using RegTypeSFB = typename remove_extent<SFBRegisters>::type;
|
||||
constexpr int RegNumD = extent<DRegisters>::value;
|
||||
constexpr int RegNumA = extent<ARegisters>::value;
|
||||
constexpr int RegNumE = extent<ERegisters>::value;
|
||||
constexpr int RegNumB = extent<BRegisters>::value;
|
||||
constexpr int RegNumC = extent<CRegisters>::value;
|
||||
constexpr int RegNumSFA = extent<SFARegisters>::value;
|
||||
constexpr int RegNumSFB = extent<SFBRegisters>::value;
|
||||
|
||||
auto [tA, tSFA, tE] = unzip_tensor(A);
|
||||
auto [tB, tSFB ] = unzip_tensor(B);
|
||||
Tensor rA = recast<RegTypeA>(tA);
|
||||
Tensor rE = recast<RegTypeE>(tE);
|
||||
Tensor rB = recast<RegTypeB>(tB);
|
||||
Tensor rD = recast<RegTypeD>(D);
|
||||
Tensor rC = recast<RegTypeC>(C);
|
||||
Tensor rSFA = recast<RegTypeSFA>(tSFA);
|
||||
Tensor rSFB = recast<RegTypeSFB>(tSFB);
|
||||
|
||||
CUTE_STATIC_ASSERT_V(size(rA) == Int<RegNumA>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rE) == Int<RegNumE>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rB) == Int<RegNumB>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rD) == Int<RegNumD>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rC) == Int<RegNumC>{});
|
||||
CUTE_STATIC_ASSERT_V(size(filter_zeros(rSFA)) == Int<RegNumSFA>{});
|
||||
CUTE_STATIC_ASSERT_V(size(filter_zeros(rSFB)) == Int<RegNumSFB>{});
|
||||
|
||||
detail::explode(MMAOp::fma,
|
||||
rD, make_int_sequence<RegNumD>{},
|
||||
rA, make_int_sequence<RegNumA>{},
|
||||
rB, make_int_sequence<RegNumB>{},
|
||||
rC, make_int_sequence<RegNumC>{},
|
||||
rE, make_int_sequence<RegNumE>{},
|
||||
rSFA, make_int_sequence<RegNumSFA>{},
|
||||
rSFB, make_int_sequence<RegNumSFB>{});
|
||||
}
|
||||
|
||||
} // end namespace SM120::BLOCKSCALED::SPARSE
|
||||
|
||||
|
||||
namespace SM120::SPARSE
|
||||
{
|
||||
|
||||
template <class MMAOp,
|
||||
class TD, class DLayout,
|
||||
class TA, class ALayout,
|
||||
class TB, class BLayout,
|
||||
class TC, class CLayout>
|
||||
CUTE_HOST_DEVICE constexpr void
|
||||
mma_unpack(MMA_Traits<MMAOp> const&,
|
||||
Tensor<TD, DLayout> & D,
|
||||
Tensor<TA, ALayout> const& A,
|
||||
Tensor<TB, BLayout> const& B,
|
||||
Tensor<TC, CLayout> const& C)
|
||||
{
|
||||
static_assert(is_rmem_v<TD>, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem_v<TA>, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem_v<TB>, "Expected registers in MMA_Atom::call");
|
||||
static_assert(is_rmem_v<TC>, "Expected registers in MMA_Atom::call");
|
||||
using DRegisters = typename MMAOp::DRegisters;
|
||||
using ARegisters = typename MMAOp::ARegisters;
|
||||
using ERegisters = typename MMAOp::ERegisters;
|
||||
using BRegisters = typename MMAOp::BRegisters;
|
||||
using CRegisters = typename MMAOp::CRegisters;
|
||||
// Register value types from the MMAOp register arrays
|
||||
using RegTypeD = typename remove_extent<DRegisters>::type;
|
||||
using RegTypeA = typename remove_extent<ARegisters>::type;
|
||||
using RegTypeE = typename remove_extent<ERegisters>::type;
|
||||
using RegTypeB = typename remove_extent<BRegisters>::type;
|
||||
using RegTypeC = typename remove_extent<CRegisters>::type;
|
||||
constexpr int RegNumD = extent<DRegisters>::value;
|
||||
constexpr int RegNumA = extent<ARegisters>::value;
|
||||
constexpr int RegNumE = extent<ERegisters>::value;
|
||||
constexpr int RegNumB = extent<BRegisters>::value;
|
||||
constexpr int RegNumC = extent<CRegisters>::value;
|
||||
|
||||
auto [tA, tE] = unzip_tensor(A);
|
||||
Tensor rA = recast<RegTypeA>(tA);
|
||||
Tensor rE = recast<RegTypeE>(tE);
|
||||
Tensor rB = recast<RegTypeB>(B);
|
||||
Tensor rD = recast<RegTypeD>(D);
|
||||
Tensor rC = recast<RegTypeC>(C);
|
||||
CUTE_STATIC_ASSERT_V(size(rA) == Int<RegNumA>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rE) == Int<RegNumE>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rB) == Int<RegNumB>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rD) == Int<RegNumD>{});
|
||||
CUTE_STATIC_ASSERT_V(size(rC) == Int<RegNumC>{});
|
||||
|
||||
detail::explode(MMAOp::fma,
|
||||
rD, make_int_sequence<RegNumD>{},
|
||||
rA, make_int_sequence<RegNumA>{},
|
||||
rB, make_int_sequence<RegNumB>{},
|
||||
rC, make_int_sequence<RegNumC>{},
|
||||
rE, make_int_sequence<RegNumE>{});
|
||||
}
|
||||
|
||||
} // end namespace SM120::SPARSE
|
||||
|
||||
// sparse F8F6F4 without block-scaling
|
||||
template <class a_type, class b_type, class c_type>
|
||||
struct MMA_Traits<SM120::SPARSE::SM120_SPARSE_16x8x64_TN<a_type, b_type, c_type>>
|
||||
{
|
||||
using ValTypeA = sparse_elem<2, a_type>;
|
||||
using ValTypeE = sparse_elem<8, uint8_t>;
|
||||
using ValTypeB = uint8_t;
|
||||
using FrgTypeA = sparse_elem<2, uint8_t>;
|
||||
using FrgTypeE = sparse_elem<8, uint8_t>;
|
||||
|
||||
using ValTypeC = c_type;
|
||||
using ValTypeD = c_type;
|
||||
|
||||
using Shape_MNK = Shape<_16, _8, _64>;
|
||||
using ThrID = Layout<_32>;
|
||||
// (T32,V32) -> (M16,K64)
|
||||
using ALayout = Layout<Shape <Shape < _4,_8>,Shape < _8,_2, _2>>,
|
||||
Stride<Stride<_128,_1>,Stride<_16,_8,_512>>>;
|
||||
// (T32,V16) -> (N8,K64)
|
||||
using BLayout = Layout<Shape <Shape < _4,_8>,Shape <_4, _4>>,
|
||||
Stride<Stride<_32,_1>,Stride<_8,_128>>>;
|
||||
// (T32,V4) -> (M16,N8)
|
||||
using CLayout = SM120_16x8_Row;
|
||||
|
||||
// (T32, V32) -> (M16, K64)
|
||||
using ELayout = Layout<Shape <Shape <_2, _2,_8>, _32>,
|
||||
Stride<Stride<_8,_512,_1>,_16>>;
|
||||
};
|
||||
|
||||
// sparse MXF8F6F4 with block-scaling.
|
||||
template <class a_type, class b_type, class c_type, class sf_type, int VS>
|
||||
struct MMA_Traits<SM120::BLOCKSCALED::SPARSE::SM120_SPARSE_16x8x64_TN_VS<a_type, b_type, c_type, sf_type, VS>>
|
||||
: MMA_Traits<SM120::SPARSE::SM120_SPARSE_16x8x64_TN<a_type, b_type, c_type>>
|
||||
{
|
||||
using ValTypeA = sparse_elem<2, a_type>;
|
||||
using ValTypeE = sparse_elem<8, uint8_t>;
|
||||
using ValTypeB = uint8_t;
|
||||
using FrgTypeA = sparse_elem<2, uint8_t>;
|
||||
using FrgTypeE = sparse_elem<8, uint8_t>;
|
||||
|
||||
using ValTypeD = c_type;
|
||||
using ValTypeC = c_type;
|
||||
|
||||
using ValTypeSF = sf_type;
|
||||
constexpr static int SFVecSize = VS;
|
||||
|
||||
using UnderlyingSFTraits = MMA_Traits<SM120::BLOCKSCALED::SM120_16x8x64_TN_VS<a_type, b_type, c_type, sf_type, VS>>;
|
||||
using SFALayout = typename UnderlyingSFTraits::SFALayout;
|
||||
using SFBLayout = typename UnderlyingSFTraits::SFBLayout;
|
||||
};
|
||||
|
||||
template <class a_type, class b_type, class c_type, class sf_type, int VS>
|
||||
struct MMA_Traits<SM120::BLOCKSCALED::SPARSE::SM120_SPARSE_16x8x128_TN_VS<a_type, b_type, c_type, sf_type, VS>>
|
||||
{
|
||||
using ValTypeA = sparse_elem<4, uint8_t>;
|
||||
using ValTypeE = sparse_elem<16, uint8_t>;
|
||||
using ValTypeB = uint4_t;
|
||||
using FrgTypeA = sparse_elem<4, uint8_t>;
|
||||
using FrgTypeE = sparse_elem<16, uint8_t>;
|
||||
|
||||
using ValTypeC = c_type;
|
||||
using ValTypeD = c_type;
|
||||
|
||||
using ValTypeSF = sf_type;
|
||||
|
||||
constexpr static int SFVecSize = VS;
|
||||
|
||||
using Shape_MNK = Shape<_16, _8, _128>;
|
||||
using ThrID = Layout<_32>;
|
||||
// (T32,V64) -> (M16,K128)
|
||||
using ALayout = Layout<Shape <Shape < _4,_8>,Shape <_16,_2, _2>>,
|
||||
Stride<Stride<_256,_1>,Stride<_16,_8,_1024>>>;
|
||||
// (T32,V32) -> (N8,K128)
|
||||
using BLayout = Layout<Shape <Shape < _4,_8>,Shape <_8, _4>>,
|
||||
Stride<Stride<_64,_1>,Stride<_8,_256>>>;
|
||||
// (T32,V128) -> (M16,K128)
|
||||
using SFALayout = Layout<Shape <Shape <_2,_2,_8>,_128>,
|
||||
Stride<Stride<_8,_0,_1>, _16>>;
|
||||
// (T32,V128) -> (N8,K128)
|
||||
using SFBLayout = Layout<Shape <Shape <_4,_8>,_128>,
|
||||
Stride<Stride<_0,_1>, _8>>;
|
||||
// (T32,V4) -> (M16,N8)
|
||||
using CLayout = SM120_16x8_Row;
|
||||
// (T32, V64) -> (M16, K128)
|
||||
using ELayout = Layout<Shape <Shape <_2, _2,_8>, Shape< _64>>,
|
||||
Stride<Stride<_8,_1024,_1>,Stride<_16>>>;
|
||||
};
|
||||
|
||||
namespace SM120::SPARSE {
|
||||
|
||||
// For SM120 MMA F8F6F4 input fp4, the operand A/B are load from ld.matrix.
|
||||
// ld.matrix b4x16_p64 places FP4 data at the first four bits in each
|
||||
// eight-bit container, whereas MMA F8F6F4 expects the four-bit data to be in
|
||||
// the middle of the eight-bit container. Thus, e2m1 operands being fed
|
||||
// to MMA F8F6F4 must be shifted left by two bits.
|
||||
// 0b0000ABCD --> 0b00ABCD00
|
||||
// NOTE: Same transformation is NOT needed for FP6 and FP8.
|
||||
template<class AType, class BType, class... MMAArgs, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_A(SM120_SPARSE_16x8x64_TN<AType, BType, MMAArgs ...> const&, Tensor&& tensor) {
|
||||
using RegisterTypeA = typename remove_extent<typename
|
||||
SM120_SPARSE_16x8x64_TN<AType, BType, MMAArgs ...>::ARegisters>::type;
|
||||
if constexpr (cute::is_same_v<AType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeA>(tensor), [](RegisterTypeA& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
template<class AType, class BType, class... MMAArgs, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_B(SM120_SPARSE_16x8x64_TN<AType, BType, MMAArgs ...> const&, Tensor&& tensor) {
|
||||
using RegisterTypeB = typename remove_extent<typename
|
||||
SM120_SPARSE_16x8x64_TN<AType, BType, MMAArgs ...>::BRegisters>::type;
|
||||
if constexpr (cute::is_same_v<BType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeB>(tensor), [](RegisterTypeB& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace SM120::SPARSE
|
||||
|
||||
namespace SM120::BLOCKSCALED::SPARSE {
|
||||
|
||||
// Template function with scale factor needs to enmuerate types one by one, as template
|
||||
// arguments contatins two variadic lists, which cannot be deduced in one shot.
|
||||
template<class AType, class BType, class CType, class SFType, int VS, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_A(SM120_SPARSE_16x8x64_TN_VS<AType, BType, CType, SFType, VS> const&, Tensor&& tensor) {
|
||||
using RegisterTypeA = typename remove_extent<typename
|
||||
SM120_SPARSE_16x8x64_TN_VS<AType, BType, CType, SFType, VS>::ARegisters>::type;
|
||||
if constexpr (cute::is_same_v<AType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeA>(tensor), [](RegisterTypeA& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
template<class AType, class BType, class CType, class SFType, int VS, class Tensor>
|
||||
CUTLASS_DEVICE void
|
||||
fp4_shift_B(SM120_SPARSE_16x8x64_TN_VS<AType, BType, CType, SFType, VS> const&, Tensor&& tensor) {
|
||||
using RegisterTypeB = typename remove_extent<typename
|
||||
SM120_SPARSE_16x8x64_TN_VS<AType, BType, CType, SFType, VS>::BRegisters>::type;
|
||||
if constexpr (cute::is_same_v<BType, cutlass::float_e2m1_t>) {
|
||||
cute::transform(recast<RegisterTypeB>(tensor), [](RegisterTypeB& v){ return v << 2; });
|
||||
}
|
||||
}
|
||||
|
||||
} // end namespace SM120::BLOCKSCALED::SPARSE
|
||||
|
||||
} // end namespace cute
|
||||
@@ -239,11 +239,10 @@ make_gmma_desc(Tensor<TEngine,TLayout> const& tensor)
|
||||
"Not a canonical GMMA_MN Layout: Expected K-size 256/sizeof_bits<T> for dense or (128|512)/sizeof_bits<T> for sparse.");
|
||||
|
||||
// Construct the canonical GMMA T Layout with shape ((W,n),(8,2))
|
||||
Layout canonical_layout = logical_divide(layout(u128_tensor), make_tile(Layout<Int<W>,_1>{}, Layout<Int<8>,_1>{}));
|
||||
Layout canonical_layout = logical_divide(layout(u128_tensor), Tile<Layout<Int<W>,_1>,Layout<Int<8>,_1>>{});
|
||||
|
||||
// Check ranks of canonical
|
||||
CUTE_STATIC_ASSERT_V(rank<0>(canonical_layout) == Int<2>{}, "Not a canonical GMMA_MN Layout: No flat offset mode");
|
||||
CUTE_STATIC_ASSERT_V(rank<1>(canonical_layout) == Int<2>{}, "Not a canonical GMMA_MN Layout: No flat offset mode");
|
||||
// Check profile of canonical
|
||||
CUTE_STATIC_ASSERT_V(congruent(canonical_layout, Shape<Shape<_1,_1>,Shape<_1,_1>>{}), "Not a canonical GMMA_MN Layout: Expected profile failure.");
|
||||
// Check canonical mode strides
|
||||
constexpr uint32_t stride_00 = stride<0,0>(canonical_layout);
|
||||
constexpr uint32_t expected_stride_00 = LAYOUT_TYPE == LayoutType::INTERLEAVE ? stride<0,0>(canonical_layout) : 1;
|
||||
@@ -274,11 +273,10 @@ make_gmma_desc(Tensor<TEngine,TLayout> const& tensor)
|
||||
"Not a canonical GMMA_K Layout: Expected K-size 2 for dense or 4 for sparse (in units of uint128_t).");
|
||||
|
||||
// Construct the canonical GMMA N Layout with shape ((8,n),(2,1))
|
||||
Layout canonical_layout = logical_divide(layout(u128_tensor), make_tile(Layout<_8,_1>{}, Layout<_2,_1>{}));
|
||||
Layout canonical_layout = logical_divide(layout(u128_tensor), Tile<Layout<_8,_1>,Layout<_2,_1>>{});
|
||||
|
||||
// Check ranks of canonical
|
||||
CUTE_STATIC_ASSERT_V(rank<0>(canonical_layout) == Int<2>{}, "Not a canonical GMMA_K Layout: No flat offset mode");
|
||||
CUTE_STATIC_ASSERT_V(rank<1>(canonical_layout) == Int<2>{}, "Not a canonical GMMA_K Layout: No flat offset mode");
|
||||
// Check profile of canonical
|
||||
CUTE_STATIC_ASSERT_V(congruent(canonical_layout, Shape<Shape<_1,_1>,Shape<_1,_1>>{}), "Not a canonical GMMA_K Layout: Expected profile failure.");
|
||||
// Check canonical mode strides
|
||||
constexpr uint32_t stride_00 = stride<0,0>(canonical_layout);
|
||||
constexpr uint32_t expected_stride_00 = W;
|
||||
|
||||
Reference in New Issue
Block a user