|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once |
|
|
|
|
|
#include <cute/config.hpp> |
|
|
#include <cute/tensor_impl.hpp> |
|
|
#include <cute/util/type_traits.hpp> |
|
|
#include <cute/container/tuple.hpp> |
|
|
#include <cute/numeric/integral_constant.hpp> |
|
|
#include <cute/atom/copy_traits.hpp> |
|
|
#include <cute/atom/mma_atom.hpp> |
|
|
|
|
|
namespace cute |
|
|
{ |
|
|
|
|
|
template <class... Args> |
|
|
struct Copy_Atom; |
|
|
|
|
|
template <class CopyOperation, class CopyInternalType> |
|
|
struct Copy_Atom<CopyOperation, CopyInternalType> : Copy_Atom<Copy_Traits<CopyOperation>, CopyInternalType> |
|
|
{}; |
|
|
|
|
|
template <class... Args, class CopyInternalType> |
|
|
struct Copy_Atom<Copy_Traits<Args...>, CopyInternalType> |
|
|
: Copy_Traits<Args...> |
|
|
{ |
|
|
using Traits = Copy_Traits<Args...>; |
|
|
|
|
|
|
|
|
using ThrID = typename Traits::ThrID; |
|
|
using BitLayoutSrc = typename Traits::SrcLayout; |
|
|
using BitLayoutDst = typename Traits::DstLayout; |
|
|
using BitLayoutRef = typename Traits::RefLayout; |
|
|
|
|
|
using ValType = CopyInternalType; |
|
|
|
|
|
using ValLayoutSrc = decltype(recast_layout<uint1_t, ValType>(BitLayoutSrc{})); |
|
|
using ValLayoutDst = decltype(recast_layout<uint1_t, ValType>(BitLayoutDst{})); |
|
|
using ValLayoutRef = decltype(recast_layout<uint1_t, ValType>(BitLayoutRef{})); |
|
|
|
|
|
CUTE_STATIC_ASSERT_V(size<0>(ValLayoutSrc{}) == size(ThrID{}), "CopyOperation is not valid for Src of ValType."); |
|
|
CUTE_STATIC_ASSERT_V(size<0>(ValLayoutDst{}) == size(ThrID{}), "CopyOperation is not valid for Dst of ValType."); |
|
|
CUTE_STATIC_ASSERT_V(size<0>(ValLayoutRef{}) == size(ThrID{}), "CopyOperation is not valid for Ref of ValType."); |
|
|
|
|
|
static constexpr int NumValSrc = size<1>(ValLayoutSrc{}); |
|
|
static constexpr int NumValDst = size<1>(ValLayoutDst{}); |
|
|
|
|
|
|
|
|
template <class... TraitsArgs> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
with(TraitsArgs&&... args) const { |
|
|
auto traits = Traits::with(static_cast<TraitsArgs&&>(args)...); |
|
|
return Copy_Atom<decltype(traits), CopyInternalType>{traits}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class SEngine, class SLayout, |
|
|
class DEngine, class DLayout> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
call(Tensor<SEngine,SLayout> const& src, |
|
|
Tensor<DEngine,DLayout> & dst) const |
|
|
{ |
|
|
static_assert(SLayout::rank == 1, "Expected rank-1 src tensor"); |
|
|
static_assert(DLayout::rank == 1, "Expected rank-1 dst tensor"); |
|
|
|
|
|
if constexpr (is_constant<NumValSrc, decltype(size(src))>::value || |
|
|
is_constant<NumValDst, decltype(size(dst))>::value) { |
|
|
|
|
|
return copy_unpack(static_cast<Traits const&>(*this), src, dst); |
|
|
} else if constexpr (is_tuple<decltype(shape(src))>::value && |
|
|
is_tuple<decltype(shape(dst))>::value) { |
|
|
|
|
|
|
|
|
|
|
|
return copy(*this, tensor<0>(src), tensor<0>(dst)); |
|
|
} else { |
|
|
static_assert(dependent_false<SEngine>, |
|
|
"CopyAtom: Src/Dst partitioning does not match the instruction requirement."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template <class SEngine, class SLayout, |
|
|
class DEngine, class DLayout> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
call(Tensor<SEngine,SLayout> const& src, |
|
|
Tensor<DEngine,DLayout> && dst) const |
|
|
{ |
|
|
return call(src, dst); |
|
|
} |
|
|
|
|
|
|
|
|
template <class PEngine, class PLayout, |
|
|
class SEngine, class SLayout, |
|
|
class DEngine, class DLayout> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
call(Tensor<PEngine,PLayout> const& prd, |
|
|
Tensor<SEngine,SLayout> const& src, |
|
|
Tensor<DEngine,DLayout> & dst) const |
|
|
{ |
|
|
static_assert(PLayout::rank == 1, "Expected rank-1 prd tensor"); |
|
|
static_assert(SLayout::rank == 1, "Expected rank-1 src tensor"); |
|
|
static_assert(DLayout::rank == 1, "Expected rank-1 dst tensor"); |
|
|
|
|
|
if constexpr (is_constant<NumValSrc, decltype(size(src))>::value || |
|
|
is_constant<NumValDst, decltype(size(dst))>::value) { |
|
|
|
|
|
Traits const& traits = static_cast<Traits const&>(*this); |
|
|
auto has_with_bool = cute::is_valid([](auto t)->void_t<decltype(t.with(true))>{}, traits); |
|
|
if constexpr (has_with_bool) { |
|
|
copy_unpack(traits.with(prd(Int<0>{})), src, dst); |
|
|
} else { |
|
|
if (prd(Int<0>{})) { copy_unpack(traits, src, dst); } |
|
|
} |
|
|
} else if constexpr (is_tuple<decltype(shape(prd))>::value && |
|
|
is_tuple<decltype(shape(src))>::value && |
|
|
is_tuple<decltype(shape(dst))>::value) { |
|
|
|
|
|
|
|
|
|
|
|
return copy_if(*this, tensor<0>(prd), tensor<0>(src), tensor<0>(dst)); |
|
|
} else { |
|
|
static_assert(dependent_false<SEngine>, |
|
|
"CopyAtom: Src/Dst partitioning does not match the instruction requirement."); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
template <class PEngine, class PLayout, |
|
|
class SEngine, class SLayout, |
|
|
class DEngine, class DLayout> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
call(Tensor<PEngine,PLayout> const& prd, |
|
|
Tensor<SEngine,SLayout> const& src, |
|
|
Tensor<DEngine,DLayout> && dst) const |
|
|
{ |
|
|
return call(prd, src, dst); |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class TiledCopy, class ThrIdx> |
|
|
struct ThrCopy; |
|
|
|
|
|
template <class Copy_Atom, |
|
|
class LayoutCopy_TV, |
|
|
class ShapeTiler_MN> |
|
|
struct TiledCopy : Copy_Atom |
|
|
{ |
|
|
|
|
|
using AtomThrID = typename Copy_Atom::ThrID; |
|
|
using AtomLayoutSrc = typename Copy_Atom::ValLayoutSrc; |
|
|
using AtomLayoutDst = typename Copy_Atom::ValLayoutDst; |
|
|
using AtomLayoutRef = typename Copy_Atom::ValLayoutRef; |
|
|
|
|
|
using AtomNumThr = decltype(size<0>(AtomLayoutRef{})); |
|
|
using AtomNumVal = decltype(size<1>(AtomLayoutRef{})); |
|
|
|
|
|
|
|
|
using Tiler_MN = ShapeTiler_MN; |
|
|
using TiledLayout_TV = LayoutCopy_TV; |
|
|
using TiledNumThr = decltype(size<0>(TiledLayout_TV{})); |
|
|
using TiledNumVal = decltype(size<1>(TiledLayout_TV{})); |
|
|
|
|
|
CUTE_STATIC_ASSERT_V(TiledNumThr{} % AtomNumThr{} == Int<0>{}, "TiledCopy uses too few thrs for selected CopyAtom"); |
|
|
CUTE_STATIC_ASSERT_V(TiledNumVal{} % AtomNumVal{} == Int<0>{}, "TiledCopy uses too few vals for selected CopyAtom"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class STensor> |
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
tidfrg_S(STensor&& stensor) |
|
|
{ |
|
|
CUTE_STATIC_ASSERT_V(rank(stensor) >= rank(Tiler_MN{}), "Rank of tensor to be partitioned too small."); |
|
|
|
|
|
|
|
|
return tile2thrfrg(zipped_divide(stensor,Tiler_MN{}), right_inverse(AtomLayoutRef{}).compose(AtomLayoutSrc{})); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class DTensor> |
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
tidfrg_D(DTensor&& dtensor) |
|
|
{ |
|
|
CUTE_STATIC_ASSERT_V(rank(dtensor) >= rank(Tiler_MN{}), "Rank of tensor to be partitioned too small."); |
|
|
|
|
|
|
|
|
return tile2thrfrg(zipped_divide(dtensor,Tiler_MN{}), right_inverse(AtomLayoutRef{}).compose(AtomLayoutDst{})); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class Tensor, class Ref2TrgLayout> |
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
tile2thrfrg(Tensor&& tensor, Ref2TrgLayout const& ref2trg) |
|
|
{ |
|
|
|
|
|
|
|
|
auto atom_layout_TV = zipped_divide(TiledLayout_TV{}, make_shape(AtomNumThr{}, AtomNumVal{})); |
|
|
|
|
|
|
|
|
|
|
|
auto trg_layout_TV = atom_layout_TV.compose(ref2trg, _); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto thrval2mn = coalesce(zip(trg_layout_TV), Shape<_1,Shape<_1,_1>>{}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto tv_tensor = tensor.compose(thrval2mn, _); |
|
|
|
|
|
|
|
|
|
|
|
return tv_tensor(make_coord(_,_), _); |
|
|
} |
|
|
|
|
|
|
|
|
template <class Tensor> |
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
retile(Tensor&& tensor) |
|
|
{ |
|
|
constexpr int R = remove_cvref_t<Tensor>::rank; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto V = size<0>(tensor); |
|
|
|
|
|
auto frg_layout_mn = upcast<TiledNumThr{} * V>(right_inverse(TiledLayout_TV{}).with_shape(shape(Tiler_MN{}))); |
|
|
|
|
|
|
|
|
auto frg_layout_v = zipped_divide(logical_product(make_layout(V), right_inverse(frg_layout_mn)), make_layout(AtomNumVal{})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto t_tensor = zipped_divide(tensor, prepend(product_each(shape(frg_layout_mn)), V)); |
|
|
|
|
|
|
|
|
|
|
|
auto v_tensor = t_tensor.compose(frg_layout_v, _); |
|
|
|
|
|
|
|
|
|
|
|
return v_tensor(_, append<R>(Int<0>{},_)); |
|
|
} |
|
|
|
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
get_layoutS_TV() |
|
|
{ |
|
|
|
|
|
auto ref_S = make_layout(make_shape(shape(Tiler_MN{}), Int<1>{})); |
|
|
|
|
|
return tile2thrfrg(ref_S, right_inverse(AtomLayoutRef{}).compose(AtomLayoutSrc{}))(_,_,Int<0>{}); |
|
|
} |
|
|
|
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
get_layoutS_MN() |
|
|
{ |
|
|
|
|
|
auto layoutS_TV = get_layoutS_TV(); |
|
|
|
|
|
auto layoutS_MK = right_inverse(layoutS_TV).with_shape(shape(Tiler_MN{})); |
|
|
|
|
|
|
|
|
auto thrID_S = make_layout(size<0>(TiledLayout_TV{})); |
|
|
|
|
|
return cute::make_tuple(layoutS_MK, thrID_S); |
|
|
} |
|
|
|
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
get_layoutD_TV() |
|
|
{ |
|
|
|
|
|
auto ref_D = make_layout(make_shape(shape(Tiler_MN{}), Int<1>{})); |
|
|
|
|
|
return tile2thrfrg(ref_D, right_inverse(AtomLayoutRef{}).compose(AtomLayoutDst{}))(_,_,Int<0>{}); |
|
|
} |
|
|
|
|
|
CUTE_HOST_DEVICE constexpr static |
|
|
auto |
|
|
get_layoutD_MN() |
|
|
{ |
|
|
|
|
|
auto layoutD_TV = get_layoutD_TV(); |
|
|
|
|
|
auto layoutD_MK = right_inverse(layoutD_TV).with_shape(shape(Tiler_MN{})); |
|
|
|
|
|
|
|
|
auto thrID_D = make_layout(size<0>(TiledLayout_TV{})); |
|
|
|
|
|
return cute::make_tuple(layoutD_MK, thrID_D); |
|
|
} |
|
|
|
|
|
template <class ThrIdx, |
|
|
__CUTE_REQUIRES(is_integral<ThrIdx>::value)> |
|
|
CUTE_HOST_DEVICE static |
|
|
auto |
|
|
get_slice(ThrIdx const& thr_idx) |
|
|
{ |
|
|
return ThrCopy<TiledCopy, ThrIdx>(thr_idx); |
|
|
} |
|
|
|
|
|
template <class ThrIdx, |
|
|
__CUTE_REQUIRES(is_integral<ThrIdx>::value)> |
|
|
CUTE_HOST_DEVICE static |
|
|
auto |
|
|
get_thread_slice(ThrIdx const& thr_idx) |
|
|
{ |
|
|
return get_slice(thr_idx); |
|
|
} |
|
|
}; |
|
|
|
|
|
template <class TiledCopy, class ThrIdx> |
|
|
struct ThrCopy |
|
|
{ |
|
|
ThrIdx thr_idx_; |
|
|
|
|
|
CUTE_HOST_DEVICE |
|
|
ThrCopy(ThrIdx const& thr_idx) : thr_idx_(thr_idx) {} |
|
|
|
|
|
template <class STensor> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
partition_S(STensor&& stensor) const { |
|
|
|
|
|
|
|
|
auto thr_tensor = make_tensor(static_cast<STensor&&>(stensor).data(), TiledCopy::tidfrg_S(stensor.layout())); |
|
|
return thr_tensor(thr_idx_, _, repeat<rank_v<STensor>>(_)); |
|
|
} |
|
|
|
|
|
template <class DTensor> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
partition_D(DTensor&& dtensor) const { |
|
|
|
|
|
|
|
|
auto thr_tensor = make_tensor(static_cast<DTensor&&>(dtensor).data(), TiledCopy::tidfrg_D(dtensor.layout())); |
|
|
return thr_tensor(thr_idx_, _, repeat<rank_v<DTensor>>(_)); |
|
|
} |
|
|
|
|
|
template <class STensor> |
|
|
CUTE_HOST_DEVICE static |
|
|
auto |
|
|
retile_S(STensor&& stensor) { |
|
|
|
|
|
|
|
|
return make_tensor(static_cast<STensor&&>(stensor).data(), TiledCopy::retile(stensor.layout())); |
|
|
} |
|
|
|
|
|
template <class DTensor> |
|
|
CUTE_HOST_DEVICE static |
|
|
auto |
|
|
retile_D(DTensor&& dtensor) { |
|
|
|
|
|
|
|
|
return make_tensor(static_cast<DTensor&&>(dtensor).data(), TiledCopy::retile(dtensor.layout())); |
|
|
} |
|
|
}; |
|
|
|
|
|
|
|
|
template <class... Args, |
|
|
class LayoutCopy_TV, |
|
|
class Tiler> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_impl(Copy_Atom<Args...> const& atom, |
|
|
LayoutCopy_TV const&, |
|
|
Tiler const&) |
|
|
{ |
|
|
return TiledCopy<Copy_Atom<Args...>, LayoutCopy_TV, Tiler>{atom}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class... CArgs, class... MArgs> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_A(Copy_Atom<CArgs...> const& copy_atom, |
|
|
TiledMMA<MArgs...> const& mma) |
|
|
{ |
|
|
return make_tiled_copy_impl(copy_atom, mma.get_layoutA_TV(), make_shape(tile_size<0>(mma),tile_size<2>(mma))); |
|
|
} |
|
|
|
|
|
template <class... CArgs, class... MArgs> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_B(Copy_Atom<CArgs...> const& copy_atom, |
|
|
TiledMMA<MArgs...> const& mma) |
|
|
{ |
|
|
return make_tiled_copy_impl(copy_atom, mma.get_layoutB_TV(), make_shape(tile_size<1>(mma),tile_size<2>(mma))); |
|
|
} |
|
|
|
|
|
template <class... CArgs, class... MArgs> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_C(Copy_Atom<CArgs...> const& copy_atom, |
|
|
TiledMMA<MArgs...> const& mma) |
|
|
{ |
|
|
return make_tiled_copy_impl(copy_atom, mma.get_layoutC_TV(), make_shape(tile_size<0>(mma),tile_size<1>(mma))); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
template <class... CArgs, class... MArgs> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_C_atom(Copy_Atom<CArgs...> const& copy_atom, |
|
|
TiledMMA<MArgs...> const& mma) |
|
|
{ |
|
|
|
|
|
auto layoutC_TV = mma.get_layoutC_TV(); |
|
|
auto copy_V = Int<Copy_Atom<CArgs...>::NumValSrc>{}; |
|
|
CUTE_STATIC_ASSERT_V(copy_V <= size<1>(layoutC_TV)); |
|
|
auto layout_TV = composition(layoutC_TV, make_layout(make_shape(size<0>(layoutC_TV), copy_V))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto mma_tiler = make_shape(tile_size<0>(mma),tile_size<1>(mma)); |
|
|
auto mma_zeros = repeat_like(mma_tiler, Int<0>{}); |
|
|
|
|
|
auto tiler = transform(make_seq<rank(mma_tiler)>{}, [&](auto i) { |
|
|
return filter(composition(make_layout(mma_tiler, replace<i>(mma_zeros, Int<1>{})), layout_TV)); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto tile2mma = composition(make_layout(mma_tiler), tiler); |
|
|
|
|
|
|
|
|
auto layout_tv = composition(left_inverse(tile2mma), layout_TV); |
|
|
|
|
|
return make_tiled_copy_impl(copy_atom, layout_tv, tiler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class... Args, |
|
|
class ThrLayout, |
|
|
class ValLayout = Layout<_1>> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy(Copy_Atom<Args...> const& copy_atom, |
|
|
ThrLayout const& thr_layout = {}, |
|
|
ValLayout const& val_layout = {}) |
|
|
{ |
|
|
|
|
|
|
|
|
auto layout_mn = raked_product(thr_layout, val_layout); |
|
|
|
|
|
auto layout_tv = right_inverse(layout_mn).with_shape(make_shape(size(thr_layout), size(val_layout))); |
|
|
|
|
|
|
|
|
auto tiler = product_each(shape(layout_mn)); |
|
|
|
|
|
#if 0 |
|
|
print("thr_layout: "); print(thr_layout); print("\n"); |
|
|
print("val_layout: "); print(val_layout); print("\n"); |
|
|
print("layout_mn : "); print(layout_mn); print("\n"); |
|
|
print("layout_tv : "); print(layout_tv); print("\n"); |
|
|
print("tiler : "); print(tiler); print("\n"); |
|
|
#endif |
|
|
|
|
|
return make_tiled_copy_impl(copy_atom, layout_tv, tiler); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class... Args, class AtomTVLayout, class DataLayout> |
|
|
CUTE_HOST_DEVICE constexpr |
|
|
auto |
|
|
make_cotiled_copy(Copy_Atom<Args...> const& copy_atom, |
|
|
AtomTVLayout const& atom_tv_layout, |
|
|
DataLayout const& data_layout) |
|
|
{ |
|
|
static_assert(is_static<AtomTVLayout>::value); |
|
|
static_assert(is_static<DataLayout>::value); |
|
|
|
|
|
|
|
|
auto inv_data_layout = make_layout(left_inverse(data_layout), Layout<_1,_0>{}); |
|
|
|
|
|
|
|
|
auto layout_tv_data = composition(inv_data_layout, atom_tv_layout); |
|
|
|
|
|
|
|
|
CUTE_STATIC_ASSERT_V(coalesce(composition(data_layout, layout<1>(layout_tv_data))) == coalesce(layout<1>(atom_tv_layout)), |
|
|
"The memory pointed to by AtomTVLayout does not exist in the DataLayout."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto flat_data_shape = product_each(shape(data_layout)); |
|
|
auto flat_data_zeros = repeat<rank(flat_data_shape)>(Int<0>{}); |
|
|
|
|
|
auto tiler = transform(make_seq<rank(flat_data_shape)>{}, [&](auto i) { |
|
|
return filter(composition(make_layout(flat_data_shape, replace<i>(flat_data_zeros, Int<1>{})), layout_tv_data)); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto tile2data = composition(make_layout(flat_data_shape), tiler); |
|
|
|
|
|
|
|
|
auto layout_tv = composition(left_inverse(tile2data), layout_tv_data); |
|
|
return make_tiled_copy_impl(copy_atom, layout_tv, tiler); |
|
|
} |
|
|
|
|
|
|
|
|
template <class... Args, |
|
|
class TiledCopy> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_S(Copy_Atom<Args...> const& copy_atom, |
|
|
TiledCopy const& tiled_copy) |
|
|
{ |
|
|
return make_tiled_copy_impl(copy_atom, tiled_copy.get_layoutS_TV(), typename TiledCopy::Tiler_MN{}); |
|
|
} |
|
|
|
|
|
|
|
|
template <class... Args, |
|
|
class TiledCopy> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
make_tiled_copy_D(Copy_Atom<Args...> const& copy_atom, |
|
|
TiledCopy const& tiled_copy) |
|
|
{ |
|
|
return make_tiled_copy_impl(copy_atom, tiled_copy.get_layoutD_TV(), typename TiledCopy::Tiler_MN{}); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <int... I, class... Args> |
|
|
CUTE_HOST_DEVICE constexpr |
|
|
auto |
|
|
tile_size(TiledCopy<Args...> const&) |
|
|
{ |
|
|
return size<I...>(typename TiledCopy<Args...>::Tiler_MN{}); |
|
|
} |
|
|
|
|
|
|
|
|
template <class... Args> |
|
|
CUTE_HOST_DEVICE constexpr |
|
|
auto |
|
|
size(TiledCopy<Args...> const&) |
|
|
{ |
|
|
return typename TiledCopy<Args...>::TiledNumThr{}; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class... Args, class T> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
print(Copy_Atom<Copy_Traits<Args...>, T> const&) |
|
|
{ |
|
|
using Atom = Copy_Atom<Copy_Traits<Args...>, T>; |
|
|
print("Copy_Atom\n"); |
|
|
print(" ThrID: "); print(typename Atom::ThrID{}); print("\n"); |
|
|
print(" ValLayoutSrc: "); print(typename Atom::ValLayoutSrc{}); print("\n"); |
|
|
print(" ValLayoutDst: "); print(typename Atom::ValLayoutDst{}); print("\n"); |
|
|
print(" ValLayoutRef: "); print(typename Atom::ValLayoutRef{}); print("\n"); |
|
|
print(" ValueType: "); print(sizeof_bits<typename Atom::ValType>::value); print("b\n"); |
|
|
} |
|
|
|
|
|
template <class Atom, class... Args> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
print(TiledCopy<Atom, Args...> const& copy, char const* pad = "") |
|
|
{ |
|
|
using Copy = TiledCopy<Atom, Args...>; |
|
|
print("TiledCopy\n"); |
|
|
print(" Tiler_MN: "); print(typename Copy::Tiler_MN{}); print("\n"); |
|
|
print(" TiledLayout_TV: "); print(typename Copy::TiledLayout_TV{}); print("\n"); |
|
|
print(static_cast<Atom const&>(copy)); |
|
|
} |
|
|
|
|
|
template <class TiledCopy, class ThrIdx> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
print(ThrCopy<TiledCopy, ThrIdx> const& thr_copy) |
|
|
{ |
|
|
print("ThrCopy\n"); |
|
|
print(" ThrIdx: "); print(thr_copy.thr_idx_); print("\n"); |
|
|
print(TiledCopy{}); |
|
|
} |
|
|
|
|
|
|
|
|
template <class... Args, class TikzColorFn = TikzColor_TV> |
|
|
CUTE_HOST_DEVICE |
|
|
auto |
|
|
print_latex(TiledCopy<Args...> const& copy, |
|
|
TikzColorFn color = {}) |
|
|
{ |
|
|
auto [layoutS_MN, thrID_S] = copy.get_layoutS_MN(); |
|
|
auto [layoutD_MN, thrID_D] = copy.get_layoutD_MN(); |
|
|
|
|
|
print_latex_copy(layoutS_MN, thrID_S, |
|
|
layoutD_MN, thrID_D); |
|
|
} |
|
|
|
|
|
|
|
|
template <class LayoutS, class ThrIDS, |
|
|
class LayoutD, class ThrIDD, |
|
|
class TikzColorFn = TikzColor_TV> |
|
|
CUTE_HOST_DEVICE |
|
|
void |
|
|
print_latex_copy(LayoutS const& S, ThrIDS const& TS, |
|
|
LayoutD const& D, ThrIDD const& TD, |
|
|
TikzColorFn color = {}) |
|
|
{ |
|
|
CUTE_STATIC_ASSERT_V(rank(S) == Int<2>{}); |
|
|
CUTE_STATIC_ASSERT_V(rank(D) == Int<2>{}); |
|
|
|
|
|
assert(size<0>(S) == size<0>(D)); |
|
|
assert(size<1>(S) == size<1>(D)); |
|
|
|
|
|
|
|
|
printf("%% LayoutS: "); print(S); printf("\n"); |
|
|
printf("%% ThrIDS : "); print(TS); printf("\n"); |
|
|
printf("%% LayoutD: "); print(D); printf("\n"); |
|
|
printf("%% ThrIDD : "); print(TD); printf("\n\n"); |
|
|
|
|
|
|
|
|
printf("\\documentclass[convert]{standalone}\n" |
|
|
"\\usepackage{tikz}\n\n" |
|
|
"\\begin{document}\n" |
|
|
"\\begin{tikzpicture}[x={(0cm,-1cm)},y={(1cm,0cm)},every node/.style={minimum size=1cm, outer sep=0pt}]\n\n"); |
|
|
|
|
|
|
|
|
for (int i = 0; i < size<0>(S); ++i) { |
|
|
for (int j = 0; j < size<1>(S); ++j) { |
|
|
int thrid = S(i,j) % size(TS); |
|
|
int val_idx = S(i,j) / size(TS); |
|
|
int thr_idx = TS(thrid); |
|
|
|
|
|
printf("\\node[fill=%s] at (%d,%d) {\\shortstack{T%d \\\\ V%d}};\n", |
|
|
color(thr_idx, val_idx), |
|
|
i, j, |
|
|
thr_idx, val_idx); |
|
|
} |
|
|
} |
|
|
|
|
|
printf("\\draw[color=black,thick,shift={(-0.5,-0.5)}] (%d,%d) grid (%d,%d);\n\n", |
|
|
0, 0, int(size<0>(S)), int(size<1>(S))); |
|
|
|
|
|
for (int i = 0, j = -1; i < size<0>(S); ++i) { |
|
|
printf("\\node at (%d,%d) {\\Large{\\texttt{%d}}};\n", i, j, i); |
|
|
} |
|
|
for (int i = -1, j = 0; j < size<1>(S); ++j) { |
|
|
printf("\\node at (%d,%d) {\\Large{\\texttt{%d}}};\n", i, j, j); |
|
|
} |
|
|
|
|
|
|
|
|
for (int i = 0; i < size<0>(D); ++i) { |
|
|
for (int j = 0; j < size<1>(D); ++j) { |
|
|
int thrid = D(i,j) % size(TD); |
|
|
int val_idx = D(i,j) / size(TD); |
|
|
int thr_idx = TD(thrid); |
|
|
|
|
|
printf("\\node[fill=%s] at (%d,%d) {\\shortstack{T%d \\\\ V%d}};\n", |
|
|
color(thr_idx, val_idx), |
|
|
i, j + size<1>(S) + 3, |
|
|
thr_idx, val_idx); |
|
|
} |
|
|
} |
|
|
|
|
|
printf("\\draw[color=black,thick,shift={(-0.5,-0.5)}] (%d,%d) grid (%d,%d);\n\n", |
|
|
0, int(size<1>(S)+3), int(size<0>(D)), int(size<1>(D)+size<1>(S)+3)); |
|
|
|
|
|
for (int i = 0, j = size<1>(D); i < size<0>(D); ++i) { |
|
|
printf("\\node at (%d,%d) {\\Large{\\texttt{%d}}};\n", i, j + size<1>(S) + 3, i); |
|
|
} |
|
|
for (int i = -1, j = 0; j < size<1>(D); ++j) { |
|
|
printf("\\node at (%d,%d) {\\Large{\\texttt{%d}}};\n", i, j + size<1>(S) + 3, j); |
|
|
} |
|
|
|
|
|
|
|
|
printf("\\end{tikzpicture}\n" |
|
|
"\\end{document}\n"); |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#include <cute/atom/copy_traits_sm50.hpp> |
|
|
#include <cute/atom/copy_traits_sm75.hpp> |
|
|
#include <cute/atom/copy_traits_sm80.hpp> |
|
|
#include <cute/atom/copy_traits_sm90.hpp> |
|
|
#include <cute/atom/copy_traits_sm100.hpp> |
|
|
|
|
|
|
|
|
|
|
|
#if (__CUDACC_VER_MAJOR__ >= 12) |
|
|
# define CUTE_COPY_ATOM_TMA_SM90_ENABLED |
|
|
# define CUTE_COPY_ATOM_TMA_SM100_ENABLED |
|
|
#endif |
|
|
|
|
|
|
|
|
#if (!defined(CUTE_COPY_ATOM_TMA_SM90_ENABLED)) |
|
|
# define CUTE_COPY_ATOM_TMA_SM90_ENABLED |
|
|
#endif |
|
|
|
|
|
#if (!defined(CUTE_COPY_ATOM_TMA_SM100_ENABLED)) |
|
|
# define CUTE_COPY_ATOM_TMA_SM100_ENABLED |
|
|
#endif |
|
|
|
|
|
|
|
|
#if defined(CUTE_COPY_ATOM_TMA_SM90_ENABLED) |
|
|
#include <cute/atom/copy_traits_sm90_tma.hpp> |
|
|
#endif |
|
|
|
|
|
|
|
|
#if defined(CUTE_COPY_ATOM_TMA_SM100_ENABLED) |
|
|
#include <cute/atom/copy_traits_sm100_tma.hpp> |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|