Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
Files changed (50)
- lib/python3.12/site-packages/deep_gemm/__init__.pyAdded+13
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/axpby.hppAdded+95
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/clear.hppAdded+64
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/cooperative_copy.hppAdded+339
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/cooperative_gemm.hppAdded+553
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/copy.hppAdded+527
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/fill.hppAdded+87
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/functional.hppAdded+290
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/gemm.hppAdded+500
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/prefer.hppAdded+46
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/prefetch.hppAdded+145
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/tensor_algorithms.hppAdded+166
- lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/tuple_algorithms.hppAdded+1073
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/cluster_sm100.hppAdded+108
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/cluster_sm90.hppAdded+245
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/config.hppAdded+111
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy.hppAdded+107
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm100.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm100_tma.hppAdded+664
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm50.hppAdded+98
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm75.hppAdded+236
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm80.hppAdded+198
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm90.hppAdded+219
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm90_desc.hppAdded+475
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm90_tma.hppAdded+1496
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma.hppAdded+64
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm100.hppAdded+42
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm100_desc.hppAdded+651
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm100_umma.hppAdded+1616
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm120.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm120_sparse.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm61.hppAdded+87
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm70.hppAdded+329
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm75.hppAdded+120
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm80.hppAdded+2241
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm89.hppAdded+180
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_desc.hppAdded+151
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma_ext.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma_sparse.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma_sparse_ext.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/simd_sm100.hppAdded+96
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/tmem_allocator_sm100.hppAdded+168
- lib/python3.12/site-packages/deep_gemm/include/cute/arch/util.hppAdded+320
- lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_atom.hppAdded+765
- lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits.hppAdded+162
- lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits_sm100.hppAdded
- lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits_sm100_im2col.hppAdded+488
- lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits_sm100_tma.hppAdded+487
12345678910111213import torch
from . import jitfrom .jit_kernels import ( gemm_fp8_fp8_bf16_nt, m_grouped_gemm_fp8_fp8_bf16_nt_contiguous, m_grouped_gemm_fp8_fp8_bf16_nt_masked, ceil_div, set_num_sms, get_num_sms, get_col_major_tma_aligned_tensor, get_m_alignment_for_contiguous_layout)from .utils import bench, bench_kineto, calc_diff1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/tensor_impl.hpp>#include <cute/tensor_predicate.hpp>
namespace cute{
//// Accept mutable temporaries//template <class Alpha, class XEngine, class XLayout, class Beta, class YEngine, class YLayout, class PrdTensor = TrivialPredTensor>CUTE_HOST_DEVICEvoidaxpby(Alpha const& alpha, Tensor<XEngine, XLayout> const& x, Beta const& beta, Tensor<YEngine, YLayout> && y, PrdTensor const& p = {}){ return axpby(alpha, x, beta, y, p);}
//// AXPBY//template <class Alpha, class XEngine, class XLayout, class Beta, class YEngine, class YLayout, class PrdTensor = TrivialPredTensor>CUTE_HOST_DEVICEvoidaxpby(Alpha const& alpha, Tensor<XEngine, XLayout> const& x, Beta const& beta, Tensor<YEngine, YLayout> & y, PrdTensor const& p = {}){ auto isBetaZero = [&] () { if constexpr (is_complex<Beta>::value) { return beta.real() == Int<0>{} && beta.imag() == Int<0>{}; } else { return beta == Int<0>{}; }
CUTE_GCC_UNREACHABLE; } ();
CUTE_UNROLL for (int i = 0; i < size(x); ++i) { if (p(i)) { y(i) = (isBetaZero ? alpha * x(i) : alpha * x(i) + beta * y(i)); } }}
} // end namespace cute12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/tensor_impl.hpp> // cute::Tensor#include <cute/algorithm/fill.hpp> // cute::fill
namespace cute{
//// Accept mutable temporaries//template <class Engine, class Layout>CUTE_HOST_DEVICEvoidclear(Tensor<Engine, Layout>&& tensor){ return clear(tensor);}
//// Set elements to zero//template <class Engine, class Layout>CUTE_HOST_DEVICEvoidclear(Tensor<Engine, Layout>& tensor){ using T = typename Tensor<Engine,Layout>::value_type;
fill(tensor, T{});}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339/**************************************************************************************************** Copyright (c) 2017 - 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/config.hpp>#include <cute/layout.hpp>#include <cute/layout_composed.hpp> // cute::logical_divide#include <cute/swizzle.hpp> // cute::Swizzle#include <cute/swizzle_layout.hpp> // cute::get_nonswizzle_portion#include <cute/tensor_impl.hpp> // cute::Tensor#include <cute/tensor_predicate.hpp>#include <cute/algorithm/copy.hpp>#include <cute/atom/copy_atom.hpp>
namespace cute{
template <uint32_t NumThreads, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICE voidnaive_cooperative_copy(uint32_t const& tid, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ auto N = size(dst); auto R = N % Int<NumThreads>{}; if (R > 0 && tid < R) { // Likely static condition && Residue in-bounds dst[tid] = src[tid]; } CUTE_UNROLL for (uint32_t i = uint32_t(R); i < uint32_t(N); i += NumThreads) { // All in-bounds dst[tid + i] = src[tid + i]; }}
// Accept mutable temporariestemplate <uint32_t NumThreads, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICE voidnaive_cooperative_copy(uint32_t const& tid, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst){ return naive_cooperative_copy(tid, src, dst);}
// A heuristic to determine a "good" permutation of two tensors for later vectorization and thr-assignmenttemplate <class AEngine, class ALayout, class BEngine, class BLayout>CUTE_HOST_DEVICE constexprautoheuristic_permutation(Tensor<AEngine, ALayout> const& a, Tensor<BEngine, BLayout> const& b){ constexpr bool swizzleA = get_swizzle_t<AEngine>::num_bits != 0 or get_swizzle_t<ALayout>::num_bits != 0; constexpr bool swizzleB = get_swizzle_t<BEngine>::num_bits != 0 or get_swizzle_t<BLayout>::num_bits != 0; auto a_inv = right_inverse(get_nonswizzle_portion(a.layout())); auto b_inv = right_inverse(get_nonswizzle_portion(b.layout()));
constexpr uint8_t scoreA = (uint8_t(swizzleA) << 2) | (uint8_t(is_smem<AEngine>::value) << 1) | (uint8_t(size(a_inv) > size(b_inv)) << 0);
constexpr uint8_t scoreB = (uint8_t(swizzleB) << 2) | (uint8_t(is_smem<BEngine>::value) << 1) | (uint8_t(size(b_inv) > size(a_inv)) << 0);
if constexpr (scoreA >= scoreB) { return a_inv; } else { return b_inv; }}
// cooperative_copy<NumThreads, MaxVecBits>(thr_idx, src, dst)// Use NumThreads to copy Tensor src to Tensor dst with element-wise vectorization up to MaxVecBits.// @pre 0 <= @a tid < NumThreads// @pre Tensors @a src and @a dst are aligned up to MaxVecBits.// That is, pointers and dynamic strides are assumed to be aligned up to MaxVecBits.//template <uint32_t NumThreads, uint32_t MaxVecBits, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout, class CopyPolicy = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_copy(uint32_t const& tid, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst, CopyPolicy const& cpy = {}){ // Assumes the shapes are static, can generalize/fallback CUTE_STATIC_ASSERT_V(is_static<decltype(shape(src))>{} && is_static<decltype(shape(dst))>{}); CUTE_STATIC_ASSERT_V(size(src) == size(dst)); // Assumes the types are the same, can generalize/fallback static_assert(cute::is_same<typename SrcEngine::value_type, typename DstEngine::value_type>::value); static_assert(MaxVecBits == sizeof_bits_v<typename SrcEngine::value_type> || MaxVecBits == 8 || MaxVecBits == 16 || MaxVecBits == 32 || MaxVecBits == 64 || MaxVecBits == 128, "Expected MaxVecBits to be value size or 8 or 16 or 32 or 64 or 128 for alignment and performance."); // Check that the tensors are likely shared across threads: either gmem or smem static_assert((is_gmem<SrcEngine>::value || is_smem<SrcEngine>::value), "cooperative_copy expects shared gmem or smem source tensor."); static_assert((is_gmem<DstEngine>::value || is_smem<DstEngine>::value), "cooperative_copy expects shared gmem or smem destination tensor."); // Precondition on tid in DEBUG assert(tid < NumThreads); // Precondition on pointer alignment in DEBUG assert(is_byte_aligned<ceil_div(MaxVecBits,8u)>(raw_pointer_cast(src.data()))); assert(is_byte_aligned<ceil_div(MaxVecBits,8u)>(raw_pointer_cast(dst.data())));
#if 0 if (thread0()) { print(" "); print("cooperative_copy\n"); print(" "); print("NumThreads: "); print(NumThreads); print("\n"); print(" "); print("MaxVecBits: "); print(MaxVecBits); print("\n"); print(" "); print("src: "); print(src); print("\n"); print(" "); print("dst: "); print(dst); print("\n"); }#ifdef __CUDA_ARCH__ __syncthreads();#endif#endif
// The common layout of the two tensors that can be vectorized over elements and threads // vidx -> coord auto common_layout = heuristic_permutation(src, dst);
// Apply // (V, rest) Tensor src_a = coalesce(logical_divide(src, common_layout), Shape<_1,_1>{}); Tensor dst_a = coalesce(logical_divide(dst, common_layout), Shape<_1,_1>{});
// // Determine vectorization of elems and thrs based on src/dst size and number of threads // NOTE: This heuristic promotes parallelization over vectorization //
// The number of elements and number of bits constexpr int elem_bits = sizeof_bits_v<typename SrcEngine::value_type>; constexpr int total_elem = size(SrcLayout{});
// The number of elements that can be vectorized in values constexpr int common_elem = decltype(max_common_vector(src_a, dst_a))::value;
#if 0 if (thread0()) { print(" "); print("common_layout: "); print(common_layout); print("\n"); print(" "); print("src_a: "); print(src_a); print("\n"); print(" "); print("dst_a: "); print(dst_a); print("\n"); }#ifdef __CUDA_ARCH__ __syncthreads();#endif#endif
// if constexpr (total_elem % NumThreads != 0) { // Not attempting to find a partitioning pattern, fallback to dynamically indexed slowpath
if constexpr (common_elem > 1 && MaxVecBits > elem_bits) { // If the vectorization is non-trivial and divides the maximum vectorizations, then vectorize constexpr auto max_align_src = elem_bits * decltype(max_alignment(src_a.layout()))::value; constexpr auto max_align_dst = elem_bits * decltype(max_alignment(dst_a.layout()))::value; constexpr auto vec_bits = gcd(max_align_src, max_align_dst, MaxVecBits); using VecType = uint_bit_t<vec_bits>;
static_assert(vec_bits % elem_bits == 0, "Expected divisibility"); static_assert((vec_bits >= 8), "No support for subbyte copying");
Tensor src_v = recast<VecType const>(src_a); Tensor dst_v = recast<VecType >(dst_a);
#if 0 if (thread0()) { print(" "); print("cooperative_copy -- naive\n"); print(" "); print("src_v: "); print(src_v); print("\n"); print(" "); print("dst_v: "); print(dst_v); print("\n"); }#ifdef __CUDA_ARCH__ __syncthreads();#endif#endif
naive_cooperative_copy<NumThreads>(tid, src_v, dst_v); } else { naive_cooperative_copy<NumThreads>(tid, src_a, dst_a); } } else { // If the tensors can be equally partitioned by the threads, // compute vectorization widths in elements and threads.
// If there are too many threads to allow a full vectorized copy, trunc the vectorization constexpr int total_bits = total_elem * elem_bits; constexpr int max_bits_per_thr = total_bits / NumThreads; // At least elem_bits, at most common_bits constexpr int common_bits = common_elem * elem_bits; constexpr int vec_bits = cute::max(elem_bits, cute::gcd(common_bits, int(MaxVecBits), max_bits_per_thr));
// Should account for vec_bits < 8 and/or vec_elem <= 1 // And also account for subbyte types, which could cause race conditions // Want to ENFORCE sufficient vectorization in those cases static_assert(vec_bits % elem_bits == 0, "Expected divisibility"); static_assert(vec_bits >= 8, "No support for subbyte copying");
using VecType = uint_bit_t<vec_bits>; constexpr int vec_elem = vec_bits / elem_bits;
constexpr int vec_thrs = cute::min(int(NumThreads), total_elem / vec_elem);
// // Determine the partitioning patterns for the vec_elems and vec_thrs //
// Distribute the rest of the V*T to some consistent portion outside of the common_layout, if needed auto common_domain_src = domain_distribute(shape(src_a), Int<vec_elem*vec_thrs>{}); auto common_domain_dst = domain_distribute(shape(dst_a), Int<vec_elem*vec_thrs>{});
// Make sure for now, could fall back here instead CUTE_STATIC_ASSERT_V(size(common_domain_src) == Int<vec_elem*vec_thrs>{}); CUTE_STATIC_ASSERT_V(compatible(common_domain_src, common_domain_dst) || compatible(common_domain_dst, common_domain_src)); // Use the "more specific" domain for the extra elements of V*T auto common_domain = conditional_return(compatible(common_domain_src, common_domain_dst), common_domain_dst, common_domain_src);
// Construct the tiler auto tiler_vt = common_domain.with_shape(Int<vec_elem>{}, Int<vec_thrs>{});
// Apply and slice Tensor src_v = logical_divide(src_a, tiler_vt)(make_coord(_,tid),_); Tensor dst_v = logical_divide(dst_a, tiler_vt)(make_coord(_,tid),_);
#if 0 if (thread0()) { print(" "); print("cooperative_copy -- vec\n"); print(" "); print("Used vector: "); print(vec_elem); print("\n"); print(" "); print("Used threads: "); print(vec_thrs); print("\n"); print(" "); print("tiler_vt: "); print(tiler_vt); print("\n"); print(" "); print("src_v: "); print(src_v); print("\n"); print(" "); print("dst_v: "); print(dst_v); print("\n"); print(" "); print("recast<VecType const>(src_v): "); print(recast<VecType const>(src_v)); print("\n"); print(" "); print("recast<VecType >(dst_v): "); print(recast<VecType >(dst_v)); print("\n"); }#ifdef __CUDA_ARCH__ __syncthreads();#endif#endif
// If we're using all threads (static) or the tid is in-range (dynamic) if (vec_thrs == NumThreads or tid < vec_thrs) { auto src_c = recast<VecType const>(src_v); auto dst_c = recast<VecType>(dst_v); return copy(cpy, src_c, dst_c); } }}
// Default max-vectorization size to value_type sizetemplate <uint32_t NumThreads, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout, class CopyPolicy = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_copy(uint32_t const& tid, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst, CopyPolicy const& cpy = {}){ constexpr uint32_t MaxVecBits = sizeof_bits_v<typename SrcEngine::value_type>; return cooperative_copy<NumThreads, MaxVecBits>(tid, src, dst, cpy);}
//// Accept mutable temporaries//
template <uint32_t NumThreads, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout, class CopyPolicy = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_copy(uint32_t const& tid, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst, CopyPolicy const& cpy = {}){ return cooperative_copy<NumThreads>(tid, src, dst, cpy);}
template <uint32_t NumThreads, uint32_t MaxVecBits, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout, class CopyPolicy = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_copy(uint32_t const& tid, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst, CopyPolicy const& cpy = {}){ return cooperative_copy<NumThreads, MaxVecBits>(tid, src, dst, cpy);}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553/*************************************************************************************************** * Copyright (c) 2017 - 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/config.hpp>#include <cute/util/type_traits.hpp>
#include <cute/atom/mma_atom.hpp>
#include <cute/algorithm/axpby.hpp>#include <cute/algorithm/functional.hpp>#include <cute/algorithm/gemm.hpp>
#include <cute/tensor_impl.hpp>
namespace cute{
//// Cooperative Shared-Memory GEMMs//
namespace detail {
// Slow fallback path:template<typename ... Args, typename Alpha, typename TRC, typename RCLayout, typename Beta, class TSC, typename CLayout, typename SCLayout, typename CLoadTransformOp, typename CStoreTransformOp>CUTE_HOST_DEVICEvoidepilogue_predication(ThrMMA<Args...> const& thr_mma, Alpha const& alpha, Tensor<TRC, RCLayout> & tCrC, Beta const& beta, Tensor<TSC, CLayout> & sC, Tensor<TSC, SCLayout> & tCsC, CLoadTransformOp const& sC_load_op, // transforms C values before use in GEMM CStoreTransformOp const& sC_store_op) // transforms results before they are stored to C{ using InputTypeC = typename TSC::value_type; using ComputeTypeC = typename ThrMMA<Args...>::ValTypeC; CUTE_STATIC_ASSERT(CUTE_STL_NAMESPACE::is_same_v<ComputeTypeC, typename TRC::value_type>);
// Create coordinate tensors for the problem Tensor cC = make_identity_tensor(shape(sC)); // (M,N) -> (m,n) // Repeat partitioning with thr_mma Tensor tCcC = thr_mma.partition_C(cC); // (MMA,MMA_M,MMA_N) -> (m,n)
const bool isBetaZero = [&] () { if constexpr (is_complex<Beta>::value) { return beta.real() == Int<0>{} && beta.imag() == Int<0>{}; } else { return beta == Int<0>{}; } CUTE_GCC_UNREACHABLE; } ();
// Custom axpby_if for now CUTE_UNROLL for (int i = 0; i < size(tCrC); ++i) { if (elem_less(tCcC(i), shape(sC))) { tCsC(i) = sC_store_op(isBetaZero ? alpha * tCrC(i) : alpha * tCrC(i) + beta * static_cast<ComputeTypeC>(sC_load_op(tCsC(i)))); } }}
template<class ... Args, class Alpha, class TRC, class RCLayout, class Beta, class TSC, class SCLayout, class CLoadTransformOp, class CStoreTransformOp, class SmemCopyLdOpC, class SmemCopyStOpC>CUTE_HOST_DEVICEvoidepilogue_no_predication(uint32_t thread_idx, ThrMMA<Args...> const& thr_mma, Alpha const& alpha, Tensor<TRC, RCLayout> & tCrC, Beta const& beta, Tensor<TSC, SCLayout> & sC, CLoadTransformOp const& sC_load_op, // transforms C values before use in GEMM CStoreTransformOp const& sC_store_op, // transforms results before they are stored to C SmemCopyLdOpC const& sC_copy_ld_op, SmemCopyStOpC const& sC_copy_st_op){ using InputTypeC = typename TSC::value_type; using ComputeTypeC = typename TRC::value_type;
const bool isBetaZero = [&] () { if constexpr (is_complex<Beta>::value) { return beta.real() == Int<0>{} && beta.imag() == Int<0>{}; } else { return beta == Int<0>{}; } CUTE_GCC_UNREACHABLE; } ();
Tensor tCrD = make_fragment_like(tCrC); Tensor tCrDi = make_fragment_like<InputTypeC>(tCrD);
if(!isBetaZero) { auto smem_tiled_copy_C = make_tiled_copy_C(Copy_Atom<SmemCopyLdOpC, InputTypeC>{}, thr_mma); auto smem_thr_copy_C = smem_tiled_copy_C.get_thread_slice(thread_idx); Tensor tCsC = smem_thr_copy_C.partition_S(sC); Tensor tCrDi_copy_view = smem_thr_copy_C.retile_D(tCrDi); CUTE_STATIC_ASSERT_V(size<1>(tCsC) == size<1>(tCrDi_copy_view)); // CPY_M CUTE_STATIC_ASSERT_V(size<2>(tCsC) == size<2>(tCrDi_copy_view)); // CPY_N copy(smem_tiled_copy_C, tCsC, tCrDi_copy_view);
// Transform C on/after load cute::transform(tCrDi, tCrD, sC_load_op); } // C = alpha * (A * B) + beta * C axpby(alpha, tCrC, beta, tCrD); // Transform C before/on store cute::transform(tCrD, tCrDi, sC_store_op);
auto smem_tiled_copy_C = make_tiled_copy_C(Copy_Atom<SmemCopyStOpC, InputTypeC>{}, thr_mma); auto smem_thr_copy_C = smem_tiled_copy_C.get_thread_slice(thread_idx); Tensor tCsC = smem_thr_copy_C.partition_D(sC); Tensor tCrDi_copy_view = smem_thr_copy_C.retile_S(tCrDi); CUTE_STATIC_ASSERT_V(size<1>(tCsC) == size<1>(tCrDi_copy_view)); // CPY_M CUTE_STATIC_ASSERT_V(size<2>(tCsC) == size<2>(tCrDi_copy_view)); // CPY_N copy(smem_tiled_copy_C, tCrDi_copy_view, tCsC);}
// Predicated Cooperative GEMMtemplate <class... Args, class TA, class ALayout, class TB, class BLayout, class TC, class RCLayout, class ALoadTransformOp, class BLoadTransformOp>CUTE_HOST_DEVICEvoidcooperative_gemm_predication(ThrMMA<Args...> const& thr_mma, Tensor<TA, ALayout> const& sA, Tensor<TB, BLayout> const& sB, Tensor<TC, RCLayout> & tCrC, ALoadTransformOp const& sA_load_op, // transforms A values before use in GEMM BLoadTransformOp const& sB_load_op) // transforms B values before use in GEMM{ using InputTypeA = typename TA::value_type; using InputTypeB = typename TB::value_type; using InputTypeC = typename TC::value_type; using ComputeTypeA = typename ThrMMA<Args...>::ValTypeA; using ComputeTypeB = typename ThrMMA<Args...>::ValTypeB; using ComputeTypeC = typename ThrMMA<Args...>::ValTypeC;
// // MMA Partitioning //
// Partition the sA, sB, and sC tiles across the threads for the MMA Tensor tCsA = thr_mma.partition_A(sA); // (MMA,MMA_M,MMA_K) Tensor tCsB = thr_mma.partition_B(sB); // (MMA,MMA_N,MMA_K)
// Create register tensors for the MMA to operate on Tensor tCrA = thr_mma.make_fragment_A(tCsA); // (MMA,MMA_M,MMA_K) Tensor tCrB = thr_mma.make_fragment_B(tCsB); // (MMA,MMA_N,MMA_K) // // PREDICATION //
// Create coordinate tensors for the problem Tensor cA = make_identity_tensor(shape(sA)); // (M,K) -> (m,k) Tensor cB = make_identity_tensor(shape(sB)); // (N,K) -> (n,k)
// Repeat partitioning with thr_mma Tensor tCcA = thr_mma.partition_A(cA); // (MMA,MMA_M,MMA_K) -> (m,k) Tensor tCcB = thr_mma.partition_B(cB); // (MMA,MMA_N,MMA_K) -> (n,k)
// Allocate the preds for MMA- and MMA_MN-modes Tensor tCpA = make_tensor<bool>(make_shape(size<0>(tCsA), size<1>(tCsA))); Tensor tCpB = make_tensor<bool>(make_shape(size<0>(tCsB), size<1>(tCsB))); // Populate the predicates on M and N CUTE_UNROLL for (int i = 0; i < size(tCpA); ++i) { tCpA(i) = elem_less(get<0>(tCcA(_,_,Int<0>{})(i)), shape<0>(sA)); } CUTE_UNROLL for (int i = 0; i < size(tCpB); ++i) { tCpB(i) = elem_less(get<0>(tCcB(_,_,Int<0>{})(i)), shape<0>(sB)); } // // PREFETCH k_block = 0 // Condition the k-predication on (static) k_block == K_BLOCK_MAX-1, the last k_block // Assumes the MMA-tiling in K is trivial //
constexpr int K_BLOCK_MAX = size<2>(tCrA);
CUTE_UNROLL for (int m = 0; m < size<1>(tCrA); ++m) { // Copy MMA_M CUTE_UNROLL for (int i = 0; i < size<0>(tCrA); ++i) { // Copy MMA_I tCrA(i,m,0) = (tCpA(i,m) && (0 < K_BLOCK_MAX-1 || elem_less(get<1>(tCcA(i,m,0)), shape<1>(sA)))) ? static_cast<ComputeTypeA>(sA_load_op(tCsA(i,m,0))) : ComputeTypeA{}; } } CUTE_UNROLL for (int n = 0; n < size<1>(tCrB); ++n) { // Copy MMA_N CUTE_UNROLL for (int i = 0; i < size<0>(tCrB); ++i) { // Copy MMA_I tCrB(i,n,0) = (tCpB(i,n) && (0 < K_BLOCK_MAX-1 || elem_less(get<1>(tCcB(i,n,0)), shape<1>(sB)))) ? static_cast<ComputeTypeB>(sB_load_op(tCsB(i,n,0))) : ComputeTypeB{}; } } // // MAINLOOP //
CUTE_UNROLL for (int k_block = 0; k_block < K_BLOCK_MAX; ++k_block) { if (k_block < K_BLOCK_MAX-1) // static-if not the last k_block { int k_next = k_block + 1; // Load k_next block
// Condition the k-predication on (static) k_block == K_BLOCK_MAX-1, the last k_block // Assumes the MMA-tiling in K is trivial
CUTE_UNROLL for (int m = 0; m < size<1>(tCrA); ++m) { // Copy MMA_M CUTE_UNROLL for (int i = 0; i < size<0>(tCrA); ++i) { // Copy MMA_I tCrA(i,m,k_next) = (tCpA(i,m) && (k_next < K_BLOCK_MAX-1 || elem_less(get<1>(tCcA(i,m,k_next)), shape<1>(sA)))) ? static_cast<ComputeTypeA>(sA_load_op(tCsA(i,m,k_next))) : ComputeTypeA{}; } } CUTE_UNROLL for (int n = 0; n < size<1>(tCrB); ++n) { // Copy MMA_N CUTE_UNROLL for (int i = 0; i < size<0>(tCrB); ++i) { // Copy MMA_I tCrB(i,n,k_next) = (tCpB(i,n) && (k_next < K_BLOCK_MAX-1 || elem_less(get<1>(tCcB(i,n,k_next)), shape<1>(sB)))) ? static_cast<ComputeTypeB>(sB_load_op(tCsB(i,n,k_next))) : ComputeTypeB{}; } } } // GEMM on k_block in registers gemm(thr_mma, tCrA(_,_,k_block), tCrB(_,_,k_block), tCrC); }}
// Unpredicated Cooperative GEMMtemplate <class... Args, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, class ALoadTransformOp, class BLoadTransformOp, class SmemCopyOpA, class SmemCopyOpB>CUTE_HOST_DEVICEvoidcooperative_gemm_no_predication(uint32_t thread_idx, ThrMMA<Args...> const& thr_mma, Tensor<TA, ALayout> const& sA, Tensor<TB, BLayout> const& sB, Tensor<TC, CLayout> & tCrC, ALoadTransformOp const& sA_load_op, // transforms A values before use in GEMM BLoadTransformOp const& sB_load_op, // transforms B values before use in GEMM SmemCopyOpA const& sA_copy_op, SmemCopyOpB const& sB_copy_op){ using InputTypeA = typename TA::value_type; using InputTypeB = typename TB::value_type; using InputTypeC = typename TC::value_type; using ComputeTypeA = typename ThrMMA<Args...>::ValTypeA; using ComputeTypeB = typename ThrMMA<Args...>::ValTypeB; using ComputeTypeC = typename ThrMMA<Args...>::ValTypeC;
// // MMA Partitioning //
// Create register tensors for the MMA to operate on Tensor tCrA = thr_mma.partition_fragment_A(sA); // (MMA,MMA_M,MMA_K) Tensor tCrAi = make_fragment_like<InputTypeA>(tCrA); Tensor tCrB = thr_mma.partition_fragment_B(sB); // (MMA,MMA_N,MMA_K) Tensor tCrBi = make_fragment_like<InputTypeB>(tCrB);
using CopyOpAType = SmemCopyOpA; using CopyOpBType = SmemCopyOpB;
auto smem_tiled_copy_A = make_tiled_copy_A(Copy_Atom<CopyOpAType, InputTypeA>{}, thr_mma); auto smem_thr_copy_A = smem_tiled_copy_A.get_thread_slice(thread_idx); Tensor tCsA = smem_thr_copy_A.partition_S(sA); Tensor tCrAi_copy_view = smem_thr_copy_A.retile_D(tCrAi); CUTE_STATIC_ASSERT_V(size<1>(tCsA) == size<1>(tCrAi_copy_view)); // CPY_M CUTE_STATIC_ASSERT_V(size<2>(tCsA) == size<2>(tCrAi_copy_view)); // CPY_K
auto smem_tiled_copy_B = make_tiled_copy_B(Copy_Atom<CopyOpBType, InputTypeB>{}, thr_mma); auto smem_thr_copy_B = smem_tiled_copy_B.get_thread_slice(thread_idx); Tensor tCsB = smem_thr_copy_B.partition_S(sB); Tensor tCrBi_copy_view = smem_thr_copy_B.retile_D(tCrBi); CUTE_STATIC_ASSERT_V(size<1>(tCsB) == size<1>(tCrBi_copy_view)); // CPY_N CUTE_STATIC_ASSERT_V(size<2>(tCsB) == size<2>(tCrBi_copy_view)); // CPY_K // // PREFETCH //
copy(smem_tiled_copy_A, tCsA(_,_,Int<0>{}), tCrAi_copy_view(_,_,Int<0>{})); copy(smem_tiled_copy_B, tCsB(_,_,Int<0>{}), tCrBi_copy_view(_,_,Int<0>{})); // // MAINLOOP //
constexpr int K_BLOCK_MAX = size<2>(tCrA);
CUTE_UNROLL for (int k_block = 0; k_block < K_BLOCK_MAX; ++k_block) { // static-if load the next k_block. No k-predication required on these loads. if (k_block < K_BLOCK_MAX-1) { // Load the next k_block int k_next = k_block + 1; // statically unrolled copy(smem_tiled_copy_A, tCsA(_,_,k_next), tCrAi_copy_view(_,_,k_next)); copy(smem_tiled_copy_B, tCsB(_,_,k_next), tCrBi_copy_view(_,_,k_next)); }
// Transform A and B, relying on the compiler to remove in case of identity ops cute::transform(tCrAi(_,_,k_block), tCrA(_,_,k_block), sA_load_op); cute::transform(tCrBi(_,_,k_block), tCrB(_,_,k_block), sB_load_op);
// GEMM on k_block in registers gemm(thr_mma, tCrA(_,_,k_block), tCrB(_,_,k_block), tCrC); }}
} // end namespace detail
// C passed as a shared memory tensor// Epilogue includedtemplate <class... Args, class Alpha, class TA, class ALayout, class TB, class BLayout, class Beta, class TC, class CLayout, class ALoadTransformOp = cute::identity, class BLoadTransformOp = cute::identity, class CLoadTransformOp = cute::identity, class CStoreTransformOp = cute::identity, class SmemCopyOpA = DefaultCopy, class SmemCopyOpB = DefaultCopy, class SmemCopyLdOpC = DefaultCopy, class SmemCopyStOpC = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_gemm(uint32_t thread_idx, TiledMMA<Args...> const& tiled_mma, Alpha const& alpha, Tensor<TA, ALayout> const& sA, Tensor<TB, BLayout> const& sB, Beta const& beta, Tensor<TC, CLayout> & sC, ALoadTransformOp const& sA_load_op = {}, // transforms A values before use in GEMM BLoadTransformOp const& sB_load_op = {}, // transforms B values before use in GEMM CLoadTransformOp const& sC_load_op = {}, // transforms C values before use in GEMM CStoreTransformOp const& sC_store_op = {}, // transforms results before they are stored to C SmemCopyOpA const& sA_copy_op = {}, SmemCopyOpB const& sB_copy_op = {}, SmemCopyLdOpC const& sC_copy_ld_op = {}, SmemCopyStOpC const& sC_copy_st_op = {}){ CUTE_STATIC_ASSERT_V(rank(sA) == Int<2>{}); CUTE_STATIC_ASSERT_V(rank(sB) == Int<2>{}); CUTE_STATIC_ASSERT_V(rank(sC) == Int<2>{});
CUTE_STATIC_ASSERT_V(size<0>(sA) == size<0>(sC)); // AM == CM CUTE_STATIC_ASSERT_V(size<0>(sB) == size<1>(sC)); // BN == CN CUTE_STATIC_ASSERT_V(size<1>(sA) == size<1>(sB)); // AK == BK
using InputTypeA = typename TA::value_type; using InputTypeB = typename TB::value_type; using InputTypeC = typename TC::value_type; using ComputeTypeA = typename TiledMMA<Args...>::ValTypeA; using ComputeTypeB = typename TiledMMA<Args...>::ValTypeB; using ComputeTypeC = typename TiledMMA<Args...>::ValTypeC;
auto compat = evenly_divides(make_shape(size<0>(sA), size<0>(sB), size<1>(sA)), tile_shape(TiledMMA<Args...>{}));
// ThrMMA auto thr_mma = tiled_mma.get_thread_slice(thread_idx); Tensor tCsC = thr_mma.partition_C(sC); // (MMA,MMA_M,MMA_N) :: InputTypeC Tensor tCrC = thr_mma.make_fragment_C(tCsC); // (MMA,MMA_M,MMA_N) :: ComputeTypeC
// Clear accumulators clear(tCrC); if constexpr (is_constant<true, decltype(compat)>::value) { detail::cooperative_gemm_no_predication( thread_idx, thr_mma, sA, sB, tCrC, sA_load_op, sB_load_op, sA_copy_op, sB_copy_op ); detail::epilogue_no_predication( thread_idx, thr_mma,alpha, tCrC, beta, sC, sC_load_op, sC_store_op, sC_copy_ld_op, sC_copy_st_op ); } else { detail::cooperative_gemm_predication( thr_mma, sA, sB, tCrC, sA_load_op, sB_load_op ); detail::epilogue_predication( thr_mma, alpha, tCrC, beta, sC, tCsC, sC_load_op, sC_store_op ); }}
// C already partitioned into registers on input// It can be passed non-empty// Epilogue not includedtemplate <class... Args, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, class ALoadTransformOp = cute::identity, class BLoadTransformOp = cute::identity, class SmemCopyOpA = DefaultCopy, class SmemCopyOpB = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_gemm(uint32_t thread_idx, TiledMMA<Args...> const& tiled_mma, Tensor<TA, ALayout> const& sA, Tensor<TB, BLayout> const& sB, Tensor<TC, CLayout> & tCrC, ALoadTransformOp const& sA_load_op = {}, // transforms A values before use in GEMM BLoadTransformOp const& sB_load_op = {}, // transforms B values before use in GEMM SmemCopyOpA const& sA_copy_op = {}, SmemCopyOpB const& sB_copy_op = {}){ CUTE_STATIC_ASSERT_V(rank(sA) == Int<2>{}); CUTE_STATIC_ASSERT_V(rank(sB) == Int<2>{});
CUTE_STATIC_ASSERT_V(size<1>(sA) == size<1>(sB)); // AK == BK
using InputTypeA = typename TA::value_type; using InputTypeB = typename TB::value_type; using InputTypeC = typename TC::value_type; using ComputeTypeA = typename TiledMMA<Args...>::ValTypeA; using ComputeTypeB = typename TiledMMA<Args...>::ValTypeB; using ComputeTypeC = typename TiledMMA<Args...>::ValTypeC;
// Check if input C fragment is compatible with thr_mma and problem size using ref_c_frag = decltype(partition_shape_C(tiled_mma, make_shape(size<0>(sA), size<0>(sB)))); CUTE_STATIC_ASSERT_V(compatible(shape(ref_c_frag{}), shape(tCrC)));
auto compat = evenly_divides(make_shape(size<0>(sA), size<0>(sB), size<1>(sA)), tile_shape(TiledMMA<Args...>{}));
// ThrMMA auto thr_mma = tiled_mma.get_thread_slice(thread_idx);
if constexpr (is_constant<true, decltype(compat)>::value) { detail::cooperative_gemm_no_predication( thread_idx, thr_mma, sA, sB, tCrC, sA_load_op, sB_load_op, sA_copy_op, sB_copy_op ); } else { detail::cooperative_gemm_predication( thr_mma, sA, sB, tCrC, sA_load_op, sB_load_op ); }}
// Accept mutable temporariestemplate <class... Args, class Alpha, class TA, class ALayout, class TB, class BLayout, class Beta, class TC, class CLayout, class ALoadTransformOp = cute::identity, class BLoadTransformOp = cute::identity, class CLoadTransformOp = cute::identity, class CStoreTransformOp = cute::identity, class SmemCopyOpA = DefaultCopy, class SmemCopyOpB = DefaultCopy, class SmemCopyLdOpC = DefaultCopy, class SmemCopyStOpC = DefaultCopy>CUTE_HOST_DEVICEvoidcooperative_gemm(uint32_t thread_idx, TiledMMA<Args...> const& tiled_mma, Alpha const& alpha, Tensor<TA, ALayout> const& sA, Tensor<TB, BLayout> const& sB, Beta const& beta, Tensor<TC, CLayout> && sC, ALoadTransformOp const& sA_load_op = {}, // transforms A values before use in GEMM BLoadTransformOp const& sB_load_op = {}, // transforms B values before use in GEMM CLoadTransformOp const& sC_load_op = {}, // transforms C values before use in GEMM CStoreTransformOp const& sC_store_op = {}, // transforms results before they are stored to C SmemCopyOpA const& sA_copy_op = {}, SmemCopyOpB const& sB_copy_op = {}, SmemCopyLdOpC const& sC_copy_ld_op = {}, SmemCopyStOpC const& sC_copy_st_op = {}){ cooperative_gemm(thread_idx, tiled_mma, alpha, sA, sB, beta, sC, sA_load_op, sB_load_op, sC_load_op, sC_store_op, sA_copy_op, sB_copy_op, sC_copy_ld_op, sC_copy_st_op);}
// Legacy overload of cute::gemm for backwards-compatibilitytemplate <class... Args, class Alpha, class TA, class ALayout, class TB, class BLayout, class Beta, class TC, class CLayout, class ALoadTransformOp = cute::identity, class BLoadTransformOp = cute::identity, class CLoadTransformOp = cute::identity, class CStoreTransformOp = cute::identity>CUTE_HOST_DEVICEvoidgemm(ThrMMA<Args...> const& thr_mma, Alpha const& alpha, Tensor<TA, ALayout> const& sA, Tensor<TB, BLayout> const& sB, Beta const& beta, Tensor<TC, CLayout> & sC, ALoadTransformOp const& sA_load_op = {}, // transforms A values before use in GEMM BLoadTransformOp const& sB_load_op = {}, // transforms B values before use in GEMM CLoadTransformOp const& sC_load_op = {}, // transforms C values before use in GEMM CStoreTransformOp const& sC_store_op = {}) // transforms results before they are stored to C{ CUTE_STATIC_ASSERT_V(rank(sA) == Int<2>{}); CUTE_STATIC_ASSERT_V(rank(sB) == Int<2>{}); CUTE_STATIC_ASSERT_V(rank(sC) == Int<2>{});
CUTE_STATIC_ASSERT_V(size<0>(sA) == size<0>(sC)); // AM == CM CUTE_STATIC_ASSERT_V(size<0>(sB) == size<1>(sC)); // BN == CN CUTE_STATIC_ASSERT_V(size<1>(sA) == size<1>(sB)); // AK == BK
Tensor tCsC = thr_mma.partition_C(sC); // (MMA,MMA_M,MMA_N) Tensor tCrC = thr_mma.make_fragment_C(tCsC); // (MMA,MMA_M,MMA_N)
// Goes directly to the slow path to avoid getting thread_idx from thr_mma detail::cooperative_gemm_predication( thr_mma, sA, sB, sC, sA_load_op, sB_load_op );
detail::epilogue_predication( thr_mma, alpha, tCrC, beta, sC, tCsC, sC_load_op, sC_store_op );}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/tensor_impl.hpp> // cute::Tensor#include <cute/tensor_predicate.hpp> // cute::TrivialPredTensor#include <cute/atom/copy_atom.hpp> // cute::Copy_Atom
namespace cute{
//// copy_if -- Predicated Copy//
template <class PrdTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(PrdTensor const& pred, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ using SrcType = typename SrcEngine::value_type; using DstType = typename DstEngine::value_type;
CUTE_UNROLL for (int i = 0; i < size(dst); ++i) { if (pred(i)) { dst(i) = static_cast<DstType>(static_cast<SrcType>(src(i))); } }}
//// copy_if -- Predicated CopyAtom//
template <class... CopyArgs, class PredTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(Copy_Atom<CopyArgs...> const& copy_atom, PredTensor const& pred, // (Rest...) Tensor<SrcEngine, SrcLayout> const& src, // (V,Rest...) Tensor<DstEngine, DstLayout> & dst) // (V,Rest...){ static_assert(SrcLayout::rank == DstLayout::rank, "CopyAtom rank-mismatch."); auto has_with_bool = cute::is_valid([](auto t)->void_t<decltype(declval<typename decltype(t)::Traits>().with(true))>{}, copy_atom);
if constexpr (SrcLayout::rank == 1) { // Dispatch the copy if constexpr (has_with_bool) { copy_atom.with(pred()).call(src, dst); } else { if (pred()) { copy_atom.call(src, dst); } } } else { // Loop over all but the first mode constexpr int R = SrcLayout::rank; Tensor src_v = group_modes<1,R>(src); Tensor dst_v = group_modes<1,R>(dst); CUTE_UNROLL for (int i = 0; i < size<1>(dst_v); ++i) { if constexpr (has_with_bool) { copy_atom.with(pred(i)).call(src_v(_,i), dst_v(_,i)); } else { if (pred(i)) { copy_atom.call(src_v(_,i), dst_v(_,i)); } } } }}
//// copy_if -- AutoCopyAsync//template <class PrdTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(AutoCopyAsync const& cpy, PrdTensor const& pred, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ using SrcElemWithConst = remove_reference_t<typename SrcEngine::reference>; using SrcType = typename SrcEngine::value_type; using DstType = typename DstEngine::value_type;
auto copy_op = []() {#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) if constexpr (is_gmem<SrcEngine>::value && is_smem<DstEngine>::value && sizeof(SrcType) == sizeof(DstType)) { if constexpr (is_const_v<SrcElemWithConst> && sizeof(SrcType) == 16) { return SM80_CP_ASYNC_CACHEGLOBAL<SrcType,DstType>{}; } else if constexpr (sizeof(SrcType) == 4 || sizeof(SrcType) == 8 || sizeof(SrcType) == 16) { return SM80_CP_ASYNC_CACHEALWAYS<SrcType,DstType>{}; } else { return UniversalCopy<SrcType,DstType>{}; } } else { return UniversalCopy<SrcType,DstType>{}; }
CUTE_GCC_UNREACHABLE;#else return UniversalCopy<SrcType,DstType>{};#endif }();
CUTE_UNROLL for (int i = 0; i < size(dst); ++i) { if (pred(i)) { copy_op.copy(src(i), dst(i)); } }}
//// copy -- AutoCopyAsync//
template <class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(AutoCopyAsync const& cpy, Tensor<SrcEngine, SrcLayout> const& src, // (V,Rest...) Tensor<DstEngine, DstLayout> & dst) // (V,Rest...){ copy_if(cpy, TrivialPredTensor{}, src, dst);}
//// copy -- CopyAtom//
template <class... CopyArgs, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(Copy_Atom<CopyArgs...> const& copy_atom, Tensor<SrcEngine, SrcLayout> const& src, // (V,Rest...) Tensor<DstEngine, DstLayout> & dst) // (V,Rest...){ static_assert(SrcLayout::rank == DstLayout::rank, "CopyAtom rank-mismatch.");
if constexpr (SrcLayout::rank == 1) { // Dispatch the copy copy_atom.call(src, dst); } else { // Loop over all but the first mode constexpr int R = SrcLayout::rank; Tensor src_v = group_modes<1,R>(src); Tensor dst_v = group_modes<1,R>(dst);
if constexpr (is_static<decltype(shape(src_v))>::value && is_static<decltype(shape(dst_v))>::value) { CUTE_STATIC_ASSERT_V(size<1>(src_v) == size<1>(dst_v));
// AutoFilter on the Rest-mode auto dst_null = nullspace(layout<1>(dst_v));
Tensor dst_n = zipped_divide(dst_v, make_tile(shape<0>(dst_v), dst_null)); // ((V, NLL), (_1, Rest)) Tensor src_n = zipped_divide(src_v, make_tile(shape<0>(src_v), dst_null)); // ((V, NLL), (_1, Rest))
CUTE_STATIC_ASSERT_V(size<1>(src_n) == size<1>(dst_n)); CUTE_STATIC_ASSERT_V((cosize<0,1>(dst_n.layout()) == Int<1>{}), "Nullspace definition error"); CUTE_STATIC_ASSERT_V((cosize<0,1>(src_n.layout()) == Int<1>{}), "Error: Ambiguous scatter detected in copy"); CUTE_STATIC_ASSERT_V((size<1,0>(dst_n) == Int<1>{})); CUTE_STATIC_ASSERT_V((size<1,0>(src_n) == Int<1>{}));
Tensor dst_c = dst_n(make_coord(_,Int<0>{}),make_coord(Int<0>{},_)); // (V, Rest) Tensor src_c = src_n(make_coord(_,Int<0>{}),make_coord(Int<0>{},_)); // (V, Rest)
CUTE_STATIC_ASSERT_V(size<1>(src_c) == size<1>(dst_c)); CUTE_STATIC_ASSERT_V(shape<0>(dst_c) == shape<0>(dst)); CUTE_STATIC_ASSERT_V(shape<0>(src_c) == shape<0>(src));
CUTE_UNROLL for (int i = 0; i < size<1>(dst_c); ++i) { copy_atom.call(src_c(_,i), dst_c(_,i)); } } else { CUTE_UNROLL for (int i = 0; i < size<1>(dst_v); ++i) { copy_atom.call(src_v(_,i), dst_v(_,i)); } } }}
////////////////////////////////////////////////////////// Special Auto-Vectorizing, Auto-Filtering Overloads //////////////////////////////////////////////////////////
// Specialization for AutoVectorizingCopyAssumedAlignment<MaxVecBits>template <int MaxVecBits, class... Args, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(AutoVectorizingCopyWithAssumedAlignment<MaxVecBits> const&, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ constexpr int common_elem = CUTE_STATIC_V(max_common_vector(src, dst)); constexpr int align_bits = CUTE_STATIC_V(gcd(max_alignment(src), max_alignment(dst), Int<MaxVecBits>{})); static_assert(is_integral<decltype(Int<common_elem>{} * sizeof_bits_v<typename SrcEngine::value_type>)>::value, "Error: Attempting a subbit copy!"); constexpr int vec_bits = gcd(common_elem * sizeof_bits_v<typename SrcEngine::value_type>, align_bits);
if constexpr (common_elem > 1 && ((vec_bits % 8) == 0)) { // If more than one element vectorizes to 8bits or more, then recast and copy using VecType = uint_bit_t<vec_bits>; // Preserve volatility using SrcVecType = conditional_t<is_volatile_v<typename SrcEngine::element_type>, VecType const volatile, VecType const>; using DstVecType = conditional_t<is_volatile_v<typename DstEngine::element_type>, VecType volatile, VecType >;
// Recast Tensor src_v = recast<SrcVecType>(src); Tensor dst_v = recast<DstVecType>(dst); return copy_if(TrivialPredTensor{}, src_v, dst_v); } else { return copy_if(TrivialPredTensor{}, src, dst); }}
template <class Base>struct AutoFilter { Base const& base; CUTE_HOST_DEVICE AutoFilter(Base const& b) : base(b) {}};
// Specialization for AutoFiltertemplate <class CopyOp, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(AutoFilter<CopyOp> const& copy_op, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ if constexpr (is_constant<true, decltype(size(src) == size(dst))>::value) { auto dst_null = nullspace(dst.layout());
Tensor dst_n = zipped_divide(dst, dst_null); Tensor src_n = zipped_divide(src, dst_null);
CUTE_STATIC_ASSERT_V(cosize<0>(dst_n.layout()) == Int<1>{}, "Nullspace definition error"); CUTE_STATIC_ASSERT_V(cosize<0>(src_n.layout()) == Int<1>{}, "Error: Ambiguous scatter detected in copy");
copy(copy_op.base, src_n(Int<0>{},_), dst_n(Int<0>{},_)); } else { copy(copy_op.base, src, dst); }}
// Auto-vectorizing copy for static layoutstemplate <class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ if constexpr (is_static<SrcLayout>::value && is_static<DstLayout>::value) { // Assume Tensors with static layouts (e.g. registers) have pointers that are 128b aligned return copy(AutoFilter(AutoVectorizingCopyWithAssumedAlignment<128>{}), src, dst); } else if constexpr (is_static<decltype(shape(src))>::value && is_static<decltype(shape(dst))>::value) { // Tensors with static shapes can be filtered, but do not assume that dynamic layouts are aligned. return copy(AutoFilter(AutoVectorizingCopyWithAssumedAlignment<8>{}), src, dst); } else { // Do not assume that dynamic layouts are aligned. return copy(AutoVectorizingCopyWithAssumedAlignment<8>{}, src, dst); }}
// Auto-vectorizing copy with assumed alignment up to 128bit.template <class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_aligned(Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ if constexpr (is_static<decltype(shape(src))>::value && is_static<decltype(shape(dst))>::value) { // Tensors with static shapes can be filtered return copy(AutoFilter(AutoVectorizingCopyWithAssumedAlignment<128>{}), src, dst); } else { return copy(AutoVectorizingCopyWithAssumedAlignment<128>{}, src, dst); }}
// Specializaton for Atom AutoVectorizingCopyAssumedAlignmenttemplate <int MaxVecBits, class... Args, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(Copy_Atom<AutoVectorizingCopyWithAssumedAlignment<MaxVecBits>, Args...> const&, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ return copy(AutoVectorizingCopyWithAssumedAlignment<MaxVecBits>{}, src, dst);}
#if defined(CUTE_COPY_ATOM_TMA_SM90_ENABLED)template <class... CT_Args, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(Copy_Traits<SM90_BULK_COPY_AUTO, CT_Args...> const& atom, // Copy_Traits may or may not have the memory barrier in it already Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ using SrcType = typename SrcEngine::value_type; using DstType = typename DstEngine::value_type; static_assert(cute::is_same<SrcType, DstType>::value); static_assert((is_gmem<SrcEngine>::value && is_smem<DstEngine>::value) || (is_smem<SrcEngine>::value && is_gmem<DstEngine>::value), "Bulk Copy only supports gmem -> smem or smem -> gmem movement."); // G2S or S2G dispatch using BULK_COPY_OP = conditional_t<is_gmem<SrcEngine>::value, SM90_BULK_COPY_G2S, SM90_BULK_COPY_S2G>;
// Find the common subtensor of src and dst auto tiler = max_common_layout(src, dst); constexpr int vec_elem = decltype(size(tiler))::value; constexpr int vec_bits = vec_elem * sizeof_bits_v<SrcType>; static_assert(vec_bits >= 128, "Expected at least 128-bits for BLKCP");
// Construct a new concrete Atom of the vector size using BulkAtom = Copy_Atom<Copy_Traits<BULK_COPY_OP, Int<vec_bits>, CT_Args...>, SrcType>; auto bulk_atom = apply(atom.opargs_, [](auto const&... args) { return BulkAtom{args...}; }); return copy(bulk_atom, logical_divide(src, tiler), logical_divide(dst, tiler));}
// Backwards-compat. Throw out any extra Copy_Atom args.template <class... CT_Args, class... CA_Args, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(Copy_Atom<Copy_Traits<SM90_BULK_COPY_AUTO, CT_Args...>, CA_Args...> const& atom, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ return copy(static_cast<Copy_Traits<SM90_BULK_COPY_AUTO, CT_Args...> const&>(atom), src, dst);}#endif // #if defined(CUTE_COPY_ATOM_TMA_SM90_ENABLED)
//// Decay TiledCopy to CopyAtom//
template <class CopyAtom, class TV, class Tiler, class PrdTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(TiledCopy<CopyAtom, TV, Tiler> const& tiled_copy, PrdTensor const& pred, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ return copy_if(static_cast<CopyAtom const&>(tiled_copy), pred, src, dst);}
template <class CopyAtom, class TV, class Tiler, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(TiledCopy<CopyAtom, TV, Tiler> const& tiled_copy, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ return copy(static_cast<CopyAtom const&>(tiled_copy), src, dst);}
template <class TiledCopy, class ThrIdx, class PrdTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(ThrCopy<TiledCopy, ThrIdx> const& thr_copy, PrdTensor const& pred, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst) = delete;
template <class TiledCopy, class ThrIdx, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(ThrCopy<TiledCopy, ThrIdx> const& thr_copy, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst) = delete;
//// Catch uncaught policies//
template <class CopyPolicy, class PredTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(CopyPolicy const& cpy, PredTensor const& prd, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ static_assert(dependent_false<CopyPolicy>, "Unrecognized CopyPolicy.");}
template <class CopyPolicy, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(CopyPolicy const& cpy, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> & dst){ static_assert(dependent_false<CopyPolicy>, "Unrecognized CopyPolicy.");}
//// Accept mutable temporaries//
template <class PrdTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(PrdTensor const& pred, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst){ return copy_if(pred, src, dst);}
template <class CopyPolicy, class PrdTensor, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_if(CopyPolicy const& copy_policy, PrdTensor const& pred, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst){ return copy_if(copy_policy, pred, src, dst);}
template <class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst){ return copy(src, dst);}
template <class CopyPolicy, class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy(CopyPolicy const& copy_policy, Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst){ return copy(copy_policy, src, dst);}
template <class SrcEngine, class SrcLayout, class DstEngine, class DstLayout>CUTE_HOST_DEVICEvoidcopy_aligned(Tensor<SrcEngine, SrcLayout> const& src, Tensor<DstEngine, DstLayout> && dst){ return copy_aligned(src, dst);}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/tensor_impl.hpp>#include <cute/algorithm/prefer.hpp>
namespace cute{
//// Accept mutable temporaries//template <class Engine, class Layout, class T>CUTE_HOST_DEVICEvoidfill(Tensor<Engine, Layout>&& tensor, T const& value){ return fill(tensor, value);}
namespace detail{
// Prefer fill(tensor.data(), value), if possibletemplate <class Engine, class Layout, class T>CUTE_HOST_DEVICEautofill(Tensor<Engine, Layout>& tensor, T const& value, prefer<1>) -> decltype(fill(tensor.data(), value)){ fill(tensor.data(), value);}
// Default implementationtemplate <class Engine, class Layout, class T>CUTE_HOST_DEVICEvoidfill(Tensor<Engine, Layout>& tensor, T const& value, prefer<0>){ CUTE_UNROLL for (int i = 0; i < size(tensor); ++i) { tensor(i) = value; }}
} // end namespace detail
template <class Engine, class Layout, class T>CUTE_HOST_DEVICEvoidfill(Tensor<Engine, Layout>& tensor, T const& value){ return detail::fill(tensor, value, prefer<1>{});}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/numeric/math.hpp> // cute::max, cute::min#include <cute/numeric/complex.hpp> // cute::conj
/** C++14 <functional> extensions */
namespace cute {
/**************//** Identity **//**************/
struct identity { template <class T> CUTE_HOST_DEVICE constexpr decltype(auto) operator()(T&& arg) const { return static_cast<T&&>(arg); }};
template <class R>struct constant_fn { template <class... T> CUTE_HOST_DEVICE constexpr decltype(auto) operator()(T&&...) const { return r_; } R r_;};
/***********//** Unary **//***********/
#define CUTE_LEFT_UNARY_OP(NAME,OP) \ struct NAME { \ template <class T> \ CUTE_HOST_DEVICE constexpr \ decltype(auto) operator()(T&& arg) const { \ return OP static_cast<T&&>(arg); \ } \ }#define CUTE_RIGHT_UNARY_OP(NAME,OP) \ struct NAME { \ template <class T> \ CUTE_HOST_DEVICE constexpr \ decltype(auto) operator()(T&& arg) const { \ return static_cast<T&&>(arg) OP ; \ } \ }#define CUTE_NAMED_UNARY_OP(NAME,OP) \ struct NAME { \ template <class T> \ CUTE_HOST_DEVICE constexpr \ decltype(auto) operator()(T&& arg) const { \ return OP (static_cast<T&&>(arg)); \ } \ }
CUTE_LEFT_UNARY_OP(unary_plus, +);CUTE_LEFT_UNARY_OP(negate, -);CUTE_LEFT_UNARY_OP(bit_not, ~);CUTE_LEFT_UNARY_OP(logical_not, !);CUTE_LEFT_UNARY_OP(dereference, *);CUTE_LEFT_UNARY_OP(address_of, &);CUTE_LEFT_UNARY_OP(pre_increment, ++);CUTE_LEFT_UNARY_OP(pre_decrement, --);
CUTE_RIGHT_UNARY_OP(post_increment, ++);CUTE_RIGHT_UNARY_OP(post_decrement, --);
CUTE_NAMED_UNARY_OP(abs_fn, abs);CUTE_NAMED_UNARY_OP(conjugate, cute::conj);
#undef CUTE_LEFT_UNARY_OP#undef CUTE_RIGHT_UNARY_OP#undef CUTE_NAMED_UNARY_OP
template <int Shift_>struct shift_right_const { static constexpr int Shift = Shift_;
template <class T> CUTE_HOST_DEVICE constexpr decltype(auto) operator()(T&& arg) const { return static_cast<T&&>(arg) >> Shift; }};
template <int Shift_>struct shift_left_const { static constexpr int Shift = Shift_;
template <class T> CUTE_HOST_DEVICE constexpr decltype(auto) operator()(T&& arg) const { return static_cast<T&&>(arg) << Shift; }};
/************//** Binary **//************/
#define CUTE_BINARY_OP(NAME,OP) \ struct NAME { \ template <class T, class U> \ CUTE_HOST_DEVICE constexpr \ decltype(auto) operator()(T&& lhs, U&& rhs) const { \ return static_cast<T&&>(lhs) OP static_cast<U&&>(rhs); \ } \ }#define CUTE_NAMED_BINARY_OP(NAME,OP) \ struct NAME { \ template <class T, class U> \ CUTE_HOST_DEVICE constexpr \ decltype(auto) operator()(T&& lhs, U&& rhs) const { \ return OP (static_cast<T&&>(lhs), static_cast<U&&>(rhs)); \ } \ }
CUTE_BINARY_OP(plus, +);CUTE_BINARY_OP(minus, -);CUTE_BINARY_OP(multiplies, *);CUTE_BINARY_OP(divides, /);CUTE_BINARY_OP(modulus, %);
CUTE_BINARY_OP(plus_assign, +=);CUTE_BINARY_OP(minus_assign, -=);CUTE_BINARY_OP(multiplies_assign, *=);CUTE_BINARY_OP(divides_assign, /=);CUTE_BINARY_OP(modulus_assign, %=);
CUTE_BINARY_OP(bit_and, &);CUTE_BINARY_OP(bit_or, |);CUTE_BINARY_OP(bit_xor, ^);CUTE_BINARY_OP(left_shift, <<);CUTE_BINARY_OP(right_shift, >>);
CUTE_BINARY_OP(bit_and_assign, &=);CUTE_BINARY_OP(bit_or_assign, |=);CUTE_BINARY_OP(bit_xor_assign, ^=);CUTE_BINARY_OP(left_shift_assign, <<=);CUTE_BINARY_OP(right_shift_assign, >>=);
CUTE_BINARY_OP(logical_and, &&);CUTE_BINARY_OP(logical_or, ||);
CUTE_BINARY_OP(equal_to, ==);CUTE_BINARY_OP(not_equal_to, !=);CUTE_BINARY_OP(greater, >);CUTE_BINARY_OP(less, <);CUTE_BINARY_OP(greater_equal, >=);CUTE_BINARY_OP(less_equal, <=);
CUTE_NAMED_BINARY_OP(max_fn, cute::max);CUTE_NAMED_BINARY_OP(min_fn, cute::min);
#undef CUTE_BINARY_OP#undef CUTE_NAMED_BINARY_OP
/**********//** Fold **//**********/
#define CUTE_FOLD_OP(NAME,OP) \ struct NAME##_unary_rfold { \ template <class... T> \ CUTE_HOST_DEVICE constexpr \ auto operator()(T&&... t) const { \ return (t OP ...); \ } \ }; \ struct NAME##_unary_lfold { \ template <class... T> \ CUTE_HOST_DEVICE constexpr \ auto operator()(T&&... t) const { \ return (... OP t); \ } \ }; \ struct NAME##_binary_rfold { \ template <class U, class... T> \ CUTE_HOST_DEVICE constexpr \ auto operator()(U&& u, T&&... t) const { \ return (t OP ... OP u); \ } \ }; \ struct NAME##_binary_lfold { \ template <class U, class... T> \ CUTE_HOST_DEVICE constexpr \ auto operator()(U&& u, T&&... t) const { \ return (u OP ... OP t); \ } \ }
CUTE_FOLD_OP(plus, +);CUTE_FOLD_OP(minus, -);CUTE_FOLD_OP(multiplies, *);CUTE_FOLD_OP(divides, /);CUTE_FOLD_OP(modulus, %);
CUTE_FOLD_OP(plus_assign, +=);CUTE_FOLD_OP(minus_assign, -=);CUTE_FOLD_OP(multiplies_assign, *=);CUTE_FOLD_OP(divides_assign, /=);CUTE_FOLD_OP(modulus_assign, %=);
CUTE_FOLD_OP(bit_and, &);CUTE_FOLD_OP(bit_or, |);CUTE_FOLD_OP(bit_xor, ^);CUTE_FOLD_OP(left_shift, <<);CUTE_FOLD_OP(right_shift, >>);
CUTE_FOLD_OP(bit_and_assign, &=);CUTE_FOLD_OP(bit_or_assign, |=);CUTE_FOLD_OP(bit_xor_assign, ^=);CUTE_FOLD_OP(left_shift_assign, <<=);CUTE_FOLD_OP(right_shift_assign, >>=);
CUTE_FOLD_OP(logical_and, &&);CUTE_FOLD_OP(logical_or, ||);
CUTE_FOLD_OP(equal_to, ==);CUTE_FOLD_OP(not_equal_to, !=);CUTE_FOLD_OP(greater, >);CUTE_FOLD_OP(less, <);CUTE_FOLD_OP(greater_equal, >=);CUTE_FOLD_OP(less_equal, <=);
#undef CUTE_FOLD_OP
/**********//** Meta **//**********/
template <class Fn, class Arg>struct bound_fn {
template <class T> CUTE_HOST_DEVICE constexpr decltype(auto) operator()(T&& arg) { return fn_(arg_, static_cast<T&&>(arg)); }
Fn fn_; Arg arg_;};
template <class Fn, class Arg>CUTE_HOST_DEVICE constexprautobind(Fn const& fn, Arg const& arg) { return bound_fn<Fn,Arg>{fn, arg};}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/util/type_traits.hpp>#include <cute/algorithm/functional.hpp>
#include <cute/tensor_impl.hpp>
#include <cute/atom/mma_atom.hpp>
/** The gemm algorithm takes four (or three) tensors and computes * D = A * B + C * It dispatches based on the number of modes each tensor has: * * 1. `(V) x (V) => (V)`. * The element-wise product of vectors. Dispatches to FMA or MMA. * 2. `(M) x (N) => (M,N)`. * The outer product of vectors. Dispatches to [3] with new mode K=(1). * 3. `(M,K) x (N,K) => (M,N)`. * The product of matrices. Dispatches to [5] with MMA vector-mode V. * 4. `(V,M) x (V,N) => (V,M,N)`. * The batched outer product of vectors. Accounts for register reuse and dispatches to [1] for each (m,n). * 5. `(V,M,K) x (V,N,K) => (V,M,N)`. * The batched product of matrices. Dispatches to [4] for each (k). */
namespace cute{
//// Three arguments to four//
template <class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> & C){ return gemm(C, A, B, C);}
template <class MMA, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> & C){ return gemm(mma, C, A, B, C);}
//// Accept mutable temporaries//
template <class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> && C){ return gemm(C, A, B, C);}
template <class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(Tensor<TD, DLayout> && D, Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> const& C){ return gemm(D, A, B, C);}
template <class MMA, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> && C){ return gemm(mma, C, A, B, C);}
template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> && D, Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> const& C){ return gemm(mma, D, A, B, C);}
//// Default MMA is UniversalFMA//
template <class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout>CUTE_HOST_DEVICEvoidgemm(Tensor<TD, DLayout> & D, Tensor<TA, ALayout> const& A, Tensor<TB, BLayout> const& B, Tensor<TC, CLayout> const& C){ using MMA = MMA_Atom<UniversalFMA<typename Tensor<TD,DLayout>::value_type, typename Tensor<TA,ALayout>::value_type, typename Tensor<TB,BLayout>::value_type, typename Tensor<TC,CLayout>::value_type>>;
return gemm(MMA{}, D, A, B, C);}
//// Thread-Local Register-Memory GEMMs//
// Dispatch [1]: (V) x (V) => (V)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 1 && is_rmem<TD>::value && ALayout::rank == 1 && is_rmem<TA>::value && BLayout::rank == 1 && is_rmem<TB>::value && CLayout::rank == 1 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (V) Logical data Tensor<TA, ALayout> const& A, // (V) Logical data Tensor<TB, BLayout> const& B, // (V) Logical data Tensor<TC, CLayout> const& C) // (V) Logical data{ // No static assertions on (V), MMA checks compatibility mma.call(D, A, B, C);}
// Dispatch [2]: (M) x (N) => (M,N)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 2 && is_rmem<TD>::value && ALayout::rank == 1 && is_rmem<TA>::value && BLayout::rank == 1 && is_rmem<TB>::value && CLayout::rank == 2 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (M,N) Logical data Tensor<TA, ALayout> const& A, // (M) Logical data Tensor<TB, BLayout> const& B, // (N) Logical data Tensor<TC, CLayout> const& C) // (M,N) Logical data{ CUTE_STATIC_ASSERT_V(size<0>(A) == size<0>(C)); // AM == CM CUTE_STATIC_ASSERT_V(size<0>(B) == size<1>(C)); // BN == CN CUTE_STATIC_ASSERT_V(size<0>(C) == size<0>(D) && size<1>(C) == size<1>(D)); gemm(mma, D, // (M,N) make_tensor(A.data(), append<2>(A.layout())), // (M,1) make_tensor(B.data(), append<2>(B.layout())), // (N,1) C); // (M,N)}
// Dispatch [3]: (M,K) x (N,K) => (M,N)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 2 && is_rmem<TD>::value && ALayout::rank == 2 && is_rmem<TA>::value && BLayout::rank == 2 && is_rmem<TB>::value && CLayout::rank == 2 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (M,N) Logical data Tensor<TA, ALayout> const& A, // (M,K) Logical data Tensor<TB, BLayout> const& B, // (N,K) Logical data Tensor<TC, CLayout> const& C) // (M,N) Logical data{ CUTE_STATIC_ASSERT_V(size<0>(A) == size<0>(C)); // AM == CM CUTE_STATIC_ASSERT_V(size<0>(B) == size<1>(C)); // BN == CN CUTE_STATIC_ASSERT_V(size<1>(A) == size<1>(B)); // AK == BK CUTE_STATIC_ASSERT_V(size<0>(C) == size<0>(D) && size<1>(C) == size<1>(D));
// Assert this is a 1-value MMA CUTE_STATIC_ASSERT_V(size<1>(typename MMA_Atom<MMA>::LayoutC_TV{}) == Int<1>{}); CUTE_STATIC_ASSERT_V(size<1>(typename MMA_Atom<MMA>::LayoutA_TV{}) == Int<1>{}); CUTE_STATIC_ASSERT_V(size<1>(typename MMA_Atom<MMA>::LayoutB_TV{}) == Int<1>{});
gemm(mma, make_tensor(D.data(), prepend<3>(D.layout())), // (1,M,N) make_tensor(A.data(), prepend<3>(A.layout())), // (1,M,K) make_tensor(B.data(), prepend<3>(B.layout())), // (1,N,K) make_tensor(C.data(), prepend<3>(C.layout()))); // (1,M,N)}
// Dispatch [4]: (V,M) x (V,N) => (V,M,N)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 3 && is_rmem<TD>::value && ALayout::rank == 2 && is_rmem<TA>::value && BLayout::rank == 2 && is_rmem<TB>::value && CLayout::rank == 3 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (V,M,N) Logical data Tensor<TA, ALayout> const& A, // (V,M) Logical data Tensor<TB, BLayout> const& B, // (V,N) Logical data Tensor<TC, CLayout> const& C) // (V,M,N) Logical data{ CUTE_STATIC_ASSERT_V(size<1>(A) == size<1>(C)); // AM == CM CUTE_STATIC_ASSERT_V(size<1>(B) == size<2>(C)); // BN == CN CUTE_STATIC_ASSERT_V(size<0>(C) == size<0>(D) && size<1>(C) == size<1>(D) && size<2>(C) == size<2>(D)); auto M = size<1>(A); auto N = size<1>(B); // REGISTER .reuse OPTIMIZATIONS // 64-bit traversal specialization -- serpentine path if constexpr (decltype(size<0>(A))::value * sizeof(typename TA::value_type) == 8 && decltype(size<0>(B))::value * sizeof(typename TB::value_type) == 8) {#if 1 // NOTE: Row- vs Col- major could depend on the C-matrix order... (which we can test) // Row-major serpentine iteration CUTE_UNROLL for (int m = 0; m < M; ++m) { CUTE_UNROLL for (int n = 0; n < N; ++n) { int ns = (m & 1) ? N-1-n : n; // Serpentine coordinate gemm(mma, D(_,m,ns), A(_,m), B(_,ns), C(_,m,ns)); } }#else // Col-major serpentine iteration CUTE_UNROLL for (int n = 0; n < N; ++n) { CUTE_UNROLL for (int m = 0; m < M; ++m) { int ms = (n & 1) ? M-1-m : m; // Serpentine coordinate gemm(mma, D(_,ms,n), A(_,ms), B(_,n), C(_,ms,n)); } }#endif } else // 32-bit traversal specialization -- kinked serpentine path if constexpr (decltype(size<0>(A))::value * sizeof(typename TA::value_type) == 4 && decltype(size<0>(B))::value * sizeof(typename TB::value_type) == 4) {#if 1 // NOTE: Row- vs Col- major could depend on the C-matrix order... (which we can test) // Row-major kinked serpentine iteration CUTE_UNROLL for (int m = 0; m < M; m += 2) { CUTE_UNROLL for (int n = 0; n < N; ++n) { int ns = (m & 2) ? N-1-n : n; gemm(mma, D(_,m+0,ns), A(_,m+0), B(_,ns), C(_,m+0,ns));
if (m+1 < M) { gemm(mma, D(_,m+1,ns), A(_,m+1), B(_,ns), C(_,m+1,ns)); } } }#else // Col-major kinked serpentine iteration CUTE_UNROLL for (int n = 0; n < N; n += 2) { CUTE_UNROLL for (int m = 0; m < M; ++m) { // Kinked serpentine traversal for maximum register reuse int ms = (n & 2) ? M-1-m : m; gemm(mma, D(_,ms,n+0), A(_,ms), B(_,n+0), C(_,ms,n+0));
if (n+1 < N) { gemm(mma, D(_,ms,n+1), A(_,ms), B(_,n+1), C(_,ms,n+1)); } } }#endif } else // 64-bit + 32-bit traversal order -- keep A (64-bit) in the outer loop and serpentine B if constexpr (decltype(size<0>(A))::value * sizeof(typename TA::value_type) == 8 && decltype(size<0>(B))::value * sizeof(typename TB::value_type) == 4) { // Row-major serpentine iteration CUTE_UNROLL for (int m = 0; m < M; ++m) { CUTE_UNROLL for (int n = 0; n < N; ++n) { int ns = (m & 1) ? N-1-n : n; // Serpentine coordinate gemm(mma, D(_,m,ns), A(_,m), B(_,ns), C(_,m,ns)); } } } else // 32-bit + 64-bit traversal order -- keep B (64-bit) in the outer loop and serpentine A if constexpr (decltype(size<0>(A))::value * sizeof(typename TA::value_type) == 4 && decltype(size<0>(B))::value * sizeof(typename TB::value_type) == 8) { // Col-major serpentine iteration CUTE_UNROLL for (int n = 0; n < N; ++n) { CUTE_UNROLL for (int m = 0; m < M; ++m) { int ms = (n & 1) ? M-1-m : m; // Serpentine coordinate gemm(mma, D(_,ms,n), A(_,ms), B(_,n), C(_,ms,n)); } } } else // Fallback to serpentine loop { // Col-major serpentine iteration CUTE_UNROLL for (int n = 0; n < N; ++n) { CUTE_UNROLL for (int m = 0; m < M; ++m) { int ms = (n & 1) ? M-1-m : m; // Serpentine coordinate gemm(mma, D(_,ms,n), A(_,ms), B(_,n), C(_,ms,n)); } } }}
// Dispatch [5]: (V,M,K) x (V,N,K) => (V,M,N)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 3 && is_rmem<TD>::value && ALayout::rank == 3 && is_rmem<TA>::value && BLayout::rank == 3 && is_rmem<TB>::value && CLayout::rank == 3 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (V,M,N) Logical data Tensor<TA, ALayout> const& A, // (V,M,K) Logical data Tensor<TB, BLayout> const& B, // (V,N,K) Logical data Tensor<TC, CLayout> const& C) // (V,M,N) Logical data{ CUTE_STATIC_ASSERT_V(size<1>(A) == size<1>(C)); // AM == CM CUTE_STATIC_ASSERT_V(size<1>(B) == size<2>(C)); // BN == CN CUTE_STATIC_ASSERT_V(size<2>(A) == size<2>(B)); // AK == BK CUTE_STATIC_ASSERT_V(size<0>(C) == size<0>(D) && size<1>(C) == size<1>(D) && size<2>(C) == size<2>(D)); auto K = size<2>(A);
CUTE_UNROLL for (int k = 0; k < K; ++k) { gemm(mma, D, A(_,_,k), B(_,_,k), C); }}
//// Thread-Local Shared-Memory GEMMs//
// Dispatch [1]: (V) x (V) => (V)// Dispatch [2]: (M) x (N) => (M,N)// Dispatch [3]: (M,K) x (N,K) => (M,N)// Dispatch [4]: (V,M) x (V,N) => (V,M,N)// Dispatch [5]: (V,M,K) x (V,N,K) => (V,M,N)// Dispatch [3]: (M,K) x (N,K) => (M,N)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 2 && is_rmem<TD>::value && ALayout::rank == 2 && is_smem<TA>::value && BLayout::rank == 2 && is_smem<TB>::value && CLayout::rank == 2 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (M,N) Logical data Tensor<TA, ALayout> const& A, // (M,K) Logical data Tensor<TB, BLayout> const& B, // (N,K) Logical data Tensor<TC, CLayout> const& C) // (M,N) Logical data{ CUTE_STATIC_ASSERT_V(size<0>(A) == size<0>(C)); // AM == CM CUTE_STATIC_ASSERT_V(size<0>(B) == size<1>(C)); // BN == CN CUTE_STATIC_ASSERT_V(size<1>(A) == size<1>(B)); // AK == BK CUTE_STATIC_ASSERT_V(size<0>(C) == size<0>(D) && size<1>(C) == size<1>(D));
// Assert this is a 1-value MMA CUTE_STATIC_ASSERT_V(size<1>(typename MMA_Atom<MMA>::LayoutC_TV{}) == Int<1>{}); CUTE_STATIC_ASSERT_V(size<1>(typename MMA_Atom<MMA>::LayoutA_TV{}) == Int<1>{}); CUTE_STATIC_ASSERT_V(size<1>(typename MMA_Atom<MMA>::LayoutB_TV{}) == Int<1>{});
gemm(mma, make_tensor(D.data(), prepend<3>(D.layout())), // (1,M,N) make_tensor(A.data(), prepend<3>(A.layout())), // (1,M,K) make_tensor(B.data(), prepend<3>(B.layout())), // (1,N,K) make_tensor(C.data(), prepend<3>(C.layout()))); // (1,M,N)}
// Dispatch [5]: (V,M,K) x (V,N,K) => (V,M,N)template <class MMA, class TD, class DLayout, class TA, class ALayout, class TB, class BLayout, class TC, class CLayout, __CUTE_REQUIRES(DLayout::rank == 3 && is_rmem<TD>::value && ALayout::rank == 3 && is_smem<TA>::value && BLayout::rank == 3 && is_smem<TB>::value && CLayout::rank == 3 && is_rmem<TC>::value)>CUTE_HOST_DEVICEvoidgemm(MMA_Atom<MMA> const& mma, Tensor<TD, DLayout> & D, // (V,M,N) Logical data Tensor<TA, ALayout> const& A, // (V,M,K) Logical data Tensor<TB, BLayout> const& B, // (V,N,K) Logical data Tensor<TC, CLayout> const& C) // (V,M,N) Logical data{ CUTE_STATIC_ASSERT_V(size<1>(A) == size<1>(C)); // AM == CM CUTE_STATIC_ASSERT_V(size<1>(B) == size<2>(C)); // BN == CN CUTE_STATIC_ASSERT_V(size<2>(A) == size<2>(B)); // AK == BK CUTE_STATIC_ASSERT_V(size<0>(C) == size<0>(D) && size<1>(C) == size<1>(D) && size<2>(C) == size<2>(D));
auto rA = MMA_Atom<MMA>::make_fragment_A(A); auto rB = MMA_Atom<MMA>::make_fragment_B(B);
auto K = size<2>(A);
CUTE_UNROLL for (int k = 0; k < K; ++k) { copy(A(_,_,k), rA(_,_,k)); copy(B(_,_,k), rB(_,_,k)); // Thread-level register gemm for k gemm(mma, D, rA(_,_,k), rB(_,_,k), C); }}
} // end namespace cute12345678910111213141516171819202122232425262728293031323334353637383940414243444546/*************************************************************************************************** * Copyright (c) 2023 - 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
namespace cute{
// Infinite types that inherit from each othertemplate <size_t N>struct prefer : prefer<N-1> {};
template <>struct prefer<0> {};
// Can be used to preferencially overload implementations// Higher N in prefer<N> have higher priority.
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145/*************************************************************************************************** * Copyright (c) 2024 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/tensor_impl.hpp> // cute::Tensor#include <cute/atom/copy_atom.hpp> // cute::Copy_Atom
namespace cute{
//// Prefetch global tensors into L2//
template <uint32_t NumThreads, uint32_t FetchBytes = 64, class GEngine, class GLayout>CUTE_HOST_DEVICEvoidcooperative_prefetch(uint32_t const& tid, Tensor<GEngine, GLayout> const& src){ static_assert(is_gmem<GEngine>::value, "Expected global tensor for prefetch");
constexpr int V = decltype(max_common_vector(src, src))::value;
if constexpr (V > 1) { // L2 sector is 32B, default fetch granularity is 64B using VecType = conditional_t<(V * sizeof_bits_v<typename GEngine::value_type>) < (FetchBytes * 8), ArrayEngine<typename GEngine::value_type, V>, uint8_t[FetchBytes] >;
Tensor src_v = recast<VecType const>(src); CUTE_UNROLL for (int i = tid; i < size(src_v); i += NumThreads) { prefetch(raw_pointer_cast(&src_v(i))); } } else { CUTE_UNROLL for (int i = tid; i < size(src); i += NumThreads) { prefetch(raw_pointer_cast(&src(i))); } }}
template <class GEngine, class GLayout>CUTE_HOST_DEVICEvoidprefetch(Tensor<GEngine, GLayout> const& src){ return cooperative_prefetch<1>(0, src);}
// Prefetch with copy atomnamespace detail {
template <class CopyOp, class = void>constexpr bool has_prefetch = false;
template <class CopyOp>constexpr bool has_prefetch<CopyOp, void_t<typename CopyOp::PREFETCH>> = true;
} // end namespace detail
template <class CopyOp, class... CT_Args, class... CA_Args, class GEngine, class GLayout>CUTE_HOST_DEVICEvoidprefetch(Copy_Atom<Copy_Traits<CopyOp, CT_Args...>, CA_Args...> const& atom, Tensor<GEngine, GLayout> const& src){ if constexpr (detail::has_prefetch<CopyOp>) { using Prefetch_Traits = Copy_Traits<typename CopyOp::PREFETCH, CT_Args...>; using Prefetch_Atom = Copy_Atom<Prefetch_Traits, CA_Args...>; Prefetch_Atom prefetch_atom{atom}; auto& dst = const_cast<Tensor<GEngine, GLayout>&>(src); // dst is ignored for prefetch atoms return copy(prefetch_atom, src, dst); } else { return prefetch(src); }}
#if defined(CUTE_COPY_ATOM_TMA_SM90_ENABLED)template <class... CT_Args, class SrcEngine, class SrcLayout>CUTE_HOST_DEVICEvoidprefetch(Copy_Traits<SM90_BULK_COPY_AUTO, CT_Args...> const& atom, Tensor<SrcEngine, SrcLayout> const& src){ using SrcType = typename SrcEngine::value_type; static_assert(is_gmem<SrcEngine>::value, "Expected global tensor for L2 prefetch");
auto tiler = max_common_layout(src, src); constexpr int vec_elem = decltype(size(tiler))::value; constexpr int vec_bits = vec_elem * sizeof_bits_v<SrcType>; static_assert(vec_bits >= 128, "Expected at least 128-bits for BLKCP");
// Construct a new concrete Atom of the vector size auto bulk_atom = Copy_Atom<Copy_Traits<SM90_BULK_COPY_G2S, Int<vec_bits>>, SrcType>{};
return prefetch(bulk_atom, logical_divide(src, tiler));}
// Backwards-compat. Throw out any extra Copy_Atom args.template <class... CT_Args, class... CA_Args, class SrcEngine, class SrcLayout>CUTE_HOST_DEVICEvoidprefetch(Copy_Atom<Copy_Traits<SM90_BULK_COPY_AUTO, CT_Args...>, CA_Args...> const& atom, Tensor<SrcEngine, SrcLayout> const& src){ return prefetch(static_cast<Copy_Traits<SM90_BULK_COPY_AUTO, CT_Args...> const&>(atom), src);}#endif // #if defined(CUTE_COPY_ATOM_TMA_SM90_ENABLED)
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166/*************************************************************************************************** * Copyright (c) 2023 - 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. * **************************************************************************************************//** Common algorithms on (hierarchical) tensors */
#pragma once
#include <cute/config.hpp>#include <cute/tensor_impl.hpp>
namespace cute{
//// for_each//
template <class Engine, class Layout, class UnaryOp>CUTE_HOST_DEVICE constexprvoidfor_each(Tensor<Engine,Layout> const& tensor, UnaryOp&& op){ CUTE_UNROLL for (int i = 0; i < size(tensor); ++i) { op(tensor(i)); }}
template <class Engine, class Layout, class UnaryOp>CUTE_HOST_DEVICE constexprvoidfor_each(Tensor<Engine,Layout>& tensor, UnaryOp&& op){ CUTE_UNROLL for (int i = 0; i < size(tensor); ++i) { op(tensor(i)); }}
// Accept mutable temporariestemplate <class Engine, class Layout, class UnaryOp>CUTE_HOST_DEVICE constexprvoidfor_each(Tensor<Engine,Layout>&& tensor, UnaryOp&& op){ return for_each(tensor, op);}
//// transform//
// Similar to std::transform but does not return number of elements affectedtemplate <class Engine, class Layout, class UnaryOp>CUTE_HOST_DEVICE constexprvoidtransform(Tensor<Engine,Layout>& tensor, UnaryOp&& op){ CUTE_UNROLL for (int i = 0; i < size(tensor); ++i) { tensor(i) = op(tensor(i)); }}
// Accept mutable temporariestemplate <class Engine, class Layout, class UnaryOp>CUTE_HOST_DEVICE constexprvoidtransform(Tensor<Engine,Layout>&& tensor, UnaryOp&& op){ return transform(tensor, op);}
// Similar to std::transform transforms one tensors and assigns it to anothertemplate <class EngineIn, class LayoutIn, class EngineOut, class LayoutOut, class UnaryOp>CUTE_HOST_DEVICE constexprvoidtransform(Tensor<EngineIn, LayoutIn > const& tensor_in, Tensor<EngineOut,LayoutOut> & tensor_out, UnaryOp&& op){ CUTE_UNROLL for (int i = 0; i < size(tensor_in); ++i) { tensor_out(i) = op(tensor_in(i)); }}
// Accept mutable temporariestemplate <class EngineIn, class LayoutIn, class EngineOut, class LayoutOut, class UnaryOp>CUTE_HOST_DEVICE constexprvoidtransform(Tensor<EngineIn, LayoutIn > const& tensor_in, Tensor<EngineOut,LayoutOut> && tensor_out, UnaryOp&& op){ return transform(tensor_in, tensor_out, op);}
// Similar to std::transform with a binary operation// Takes two tensors as input and one tensor as output.// Applies the binary_op to tensor_in1 and tensor_in2 and// assigns it to tensor_outtemplate <class EngineIn1, class LayoutIn1, class EngineIn2, class LayoutIn2, class EngineOut, class LayoutOut, class BinaryOp>CUTE_HOST_DEVICE constexprvoidtransform(Tensor<EngineIn1,LayoutIn1> const& tensor_in1, Tensor<EngineIn2,LayoutIn2> const& tensor_in2, Tensor<EngineOut,LayoutOut> & tensor_out, BinaryOp&& op){ CUTE_UNROLL for (int i = 0; i < size(tensor_in1); ++i) { tensor_out(i) = op(tensor_in1(i), tensor_in2(i)); }}
// Accept mutable temporariestemplate <class EngineIn1, class LayoutIn1, class EngineIn2, class LayoutIn2, class EngineOut, class LayoutOut, class BinaryOp>CUTE_HOST_DEVICE constexprvoidtransform(Tensor<EngineIn1,LayoutIn1> const& tensor_in1, Tensor<EngineIn2,LayoutIn2> const& tensor_in2, Tensor<EngineOut,LayoutOut> && tensor_out, BinaryOp&& op){ return transform(tensor_in1, tensor_in2, tensor_out, op);}
} // end namespace cute12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/util/type_traits.hpp>#include <cute/container/tuple.hpp>#include <cute/algorithm/functional.hpp>#include <cute/numeric/integer_sequence.hpp>#include <cute/numeric/integral_constant.hpp>
/// @file tuple_algorithms.hpp/// @brief Common algorithms on (hierarchical) tuples////// Code guidelines and style preferences:////// For perfect forwarding, don't use std::forward, because it may not/// be defined in device code when compiling with NVRTC. Instead, use/// `static_cast<ParameterType&&>(parameter_name)`.////// CuTe generally does not bother forwarding functions, as/// reference-qualified member functions are rare in this code base.////// Throughout CUTLASS, cute::make_tuple always needs to be called/// namespace-qualified, EVEN If inside the cute namespace and/or in/// scope of a "using namespace cute" declaration. Otherwise, the/// compiler may select std::make_tuple instead of cute::make_tuple,/// due to argument-dependent lookup.
namespace cute{
//// Apply (Unpack)// (t, f) => f(t_0,t_1,...,t_n)//
namespace detail {
template <class T, class F, int... I>CUTE_HOST_DEVICE constexprautoapply(T&& t, F&& f, seq<I...>){ return f(get<I>(static_cast<T&&>(t))...);}
} // end namespace detail
template <class T, class F>CUTE_HOST_DEVICE constexprautoapply(T&& t, F&& f){ return detail::apply(static_cast<T&&>(t), f, tuple_seq<T>{});}
//// Transform Apply// (t, f, g) => g(f(t_0),f(t_1),...)//
namespace detail {
template <class T, class F, class G, int... I>CUTE_HOST_DEVICE constexprautotapply(T&& t, F&& f, G&& g, seq<I...>){ return g(f(get<I>(static_cast<T&&>(t)))...);}
template <class T0, class T1, class F, class G, int... I>CUTE_HOST_DEVICE constexprautotapply(T0&& t0, T1&& t1, F&& f, G&& g, seq<I...>){ return g(f(get<I>(static_cast<T0&&>(t0)), get<I>(static_cast<T1&&>(t1)))...);}
template <class T0, class T1, class T2, class F, class G, int... I>CUTE_HOST_DEVICE constexprautotapply(T0&& t0, T1&& t1, T2&& t2, F&& f, G&& g, seq<I...>){ return g(f(get<I>(static_cast<T0&&>(t0)), get<I>(static_cast<T1&&>(t1)), get<I>(static_cast<T2&&>(t2)))...);}
} // end namespace detail
template <class T, class F, class G>CUTE_HOST_DEVICE constexprautotransform_apply(T&& t, F&& f, G&& g){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { return detail::tapply(static_cast<T&&>(t), f, g, tuple_seq<T>{}); } else { return g(f(static_cast<T&&>(t))); }
CUTE_GCC_UNREACHABLE;}
template <class T0, class T1, class F, class G>CUTE_HOST_DEVICE constexprautotransform_apply(T0&& t0, T1&& t1, F&& f, G&& g){ if constexpr (is_tuple<remove_cvref_t<T0>>::value) { return detail::tapply(static_cast<T0&&>(t0), static_cast<T1&&>(t1), f, g, tuple_seq<T0>{}); } else { return g(f(static_cast<T0&&>(t0), static_cast<T1&&>(t1))); }
CUTE_GCC_UNREACHABLE;}
template <class T0, class T1, class T2, class F, class G>CUTE_HOST_DEVICE constexprautotransform_apply(T0&& t0, T1&& t1, T2&& t2, F&& f, G&& g){ if constexpr (is_tuple<remove_cvref_t<T0>>::value) { return detail::tapply(static_cast<T0&&>(t0), static_cast<T1&&>(t1), static_cast<T2&&>(t2), f, g, tuple_seq<T0>{}); } else { return g(f(static_cast<T0&&>(t0), static_cast<T1&&>(t1), static_cast<T2&&>(t2))); }
CUTE_GCC_UNREACHABLE;}
//// For Each// (t, f) => f(t_0),f(t_1),...,f(t_n)//
template <class T, class F>CUTE_HOST_DEVICE constexprvoidfor_each(T&& t, F&& f){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { return detail::apply(t, [&](auto&&... a) { (f(static_cast<decltype(a)&&>(a)), ...); }, tuple_seq<T>{}); } else { return f(static_cast<T&&>(t)); }
CUTE_GCC_UNREACHABLE;}
template <class T, class F>CUTE_HOST_DEVICE constexprautofor_each_leaf(T&& t, F&& f){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { return detail::apply(static_cast<T&&>(t), [&](auto&&... a){ return (for_each_leaf(static_cast<decltype(a)&&>(a), f), ...); }, tuple_seq<T>{}); } else { return f(static_cast<T&&>(t)); }
CUTE_GCC_UNREACHABLE;}
//// Transform// (t, f) => (f(t_0),f(t_1),...,f(t_n))//
template <class T, class F>CUTE_HOST_DEVICE constexprautotransform(T const& t, F&& f){ if constexpr (is_tuple<T>::value) { return detail::tapply(t, f, [](auto const&... a){ return cute::make_tuple(a...); }, tuple_seq<T>{}); } else { return f(t); }
CUTE_GCC_UNREACHABLE;}
template <class T0, class T1, class F>CUTE_HOST_DEVICE constexprautotransform(T0 const& t0, T1 const& t1, F&& f){ if constexpr (is_tuple<T0>::value) { static_assert(tuple_size<T0>::value == tuple_size<T1>::value, "Mismatched tuple_size"); return detail::tapply(t0, t1, f, [](auto const&... a){ return cute::make_tuple(a...); }, tuple_seq<T0>{}); } else { return f(t0, t1); }
CUTE_GCC_UNREACHABLE;}
template <class T0, class T1, class T2, class F>CUTE_HOST_DEVICE constexprautotransform(T0 const& t0, T1 const& t1, T2 const& t2, F&& f){ if constexpr (is_tuple<T0>::value) { static_assert(tuple_size<T0>::value == tuple_size<T1>::value, "Mismatched tuple_size"); static_assert(tuple_size<T0>::value == tuple_size<T2>::value, "Mismatched tuple_size"); return detail::tapply(t0, t1, t2, f, [](auto const&... a){ return cute::make_tuple(a...); }, tuple_seq<T0>{}); } else { return f(t0, t1, t2); }
CUTE_GCC_UNREACHABLE;}
template <class T, class F>CUTE_HOST_DEVICE constexprautotransform_leaf(T const& t, F&& f){ if constexpr (is_tuple<T>::value) { return transform(t, [&](auto const& a) { return transform_leaf(a, f); }); } else { return f(t); }
CUTE_GCC_UNREACHABLE;}
template <class T0, class T1, class F>CUTE_HOST_DEVICE constexprautotransform_leaf(T0 const& t0, T1 const& t1, F&& f){ if constexpr (is_tuple<T0>::value) { return transform(t0, t1, [&](auto const& a, auto const& b) { return transform_leaf(a, b, f); }); } else { return f(t0, t1); }
CUTE_GCC_UNREACHABLE;}
//// find and find_if//
namespace detail {
template <class T, class F, int I, int... Is>CUTE_HOST_DEVICE constexprautofind_if(T const& t, F&& f, seq<I,Is...>){ if constexpr (decltype(f(get<I>(t)))::value) { return cute::C<I>{}; } else if constexpr (sizeof...(Is) == 0) { return cute::C<I+1>{}; } else { return find_if(t, f, seq<Is...>{}); }
CUTE_GCC_UNREACHABLE;}
} // end namespace detail
template <class T, class F>CUTE_HOST_DEVICE constexprautofind_if(T const& t, F&& f){ if constexpr (is_tuple<T>::value) { return detail::find_if(t, f, tuple_seq<T>{}); } else { return cute::C<decltype(f(t))::value ? 0 : 1>{}; }
CUTE_GCC_UNREACHABLE;}
template <class T, class X>CUTE_HOST_DEVICE constexprautofind(T const& t, X const& x){ return find_if(t, [&](auto const& v) { return v == x; }); // This should always return a static true/false}
template <class T, class F>CUTE_HOST_DEVICE constexprautoany_of(T const& t, F&& f){ if constexpr (is_tuple<T>::value) { return detail::apply(cute::transform(t, f), [&] (auto const&... a) { return (false_type{} || ... || a); }, tuple_seq<T>{}); } else { return f(t); }
CUTE_GCC_UNREACHABLE;}
template <class T, class F>CUTE_HOST_DEVICE constexprautoall_of(T const& t, F&& f){ if constexpr (is_tuple<T>::value) { return detail::apply(cute::transform(t, f), [&] (auto const&... a) { return (true_type{} && ... && a); }, tuple_seq<T>{}); } else { return f(t); }
CUTE_GCC_UNREACHABLE;}
template <class T, class F>CUTE_HOST_DEVICE constexprautonone_of(T const& t, F&& f){ return not any_of(t, f);}
//// Filter// (t, f) => <f(t_0),f(t_1),...,f(t_n)>//
template <class T, class F>CUTE_HOST_DEVICE constexprautofilter_tuple(T const& t, F&& f){ return transform_apply(t, f, [](auto const&... a) { return cute::tuple_cat(a...); });}
template <class T0, class T1, class F>CUTE_HOST_DEVICE constexprautofilter_tuple(T0 const& t0, T1 const& t1, F&& f){ return transform_apply(t0, t1, f, [](auto const&... a) { return cute::tuple_cat(a...); });}
template <class T0, class T1, class T2, class F>CUTE_HOST_DEVICE constexprautofilter_tuple(T0 const& t0, T1 const& t1, T2 const& t2, F&& f){ return transform_apply(t0, t1, t2, f, [](auto const&... a) { return cute::tuple_cat(a...); });}
//// Fold (Reduce, Accumulate)// (t, v, f) => f(...f(f(v,t_0),t_1),...,t_n)//
namespace detail {
template <class Fn, class Val>struct FoldAdaptor { template <class X> CUTE_HOST_DEVICE constexpr auto operator|(X&& x) { auto r = fn_(val_, static_cast<X&&>(x)); return FoldAdaptor<Fn, decltype(r)>{fn_, r}; } Fn fn_; Val val_;};
template <class T, class V, class F, int... Is>CUTE_HOST_DEVICE constexprautofold(T&& t, V const& v, F&& f, seq<Is...>){ return (FoldAdaptor<F,V>{f,v} | ... | get<Is>(static_cast<T&&>(t))).val_;}
} // end namespace detail
template <class T, class V, class F>CUTE_HOST_DEVICE constexprautofold(T&& t, V const& v, F&& f){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { return detail::fold(static_cast<T&&>(t), v, f, tuple_seq<T>{}); } else { return f(v, static_cast<T&&>(t)); }
CUTE_GCC_UNREACHABLE;}
template <class T, class F>CUTE_HOST_DEVICE constexprautofold_first(T&& t, F&& f){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { return detail::fold(static_cast<T&&>(t), get<0>(t), f, make_range<1,tuple_size<remove_cvref_t<T>>::value>{}); } else { return t; }
CUTE_GCC_UNREACHABLE;}
//// front, back, take, select, unwrap//
// Get the first non-tuple element in a hierarchical tupletemplate <class T>CUTE_HOST_DEVICE constexprdecltype(auto)front(T&& t){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { return front(get<0>(static_cast<T&&>(t))); } else { return static_cast<T&&>(t); }
CUTE_GCC_UNREACHABLE;}
// Get the last non-tuple element in a hierarchical tupletemplate <class T>CUTE_HOST_DEVICE constexprdecltype(auto)back(T&& t){ if constexpr (is_tuple<remove_cvref_t<T>>::value) { constexpr int N = tuple_size<remove_cvref_t<T>>::value;
// MSVC needs a bit of extra help here deducing return types. // We help it by peeling off the nonrecursive case a level "early." if constexpr (! is_tuple<remove_cvref_t<decltype(get<N - 1>(static_cast<T&&>(t)))>>::value) { return get<N - 1>(static_cast<T&&>(t)); } else { return back(get<N - 1>(static_cast<T&&>(t))); } } else { return static_cast<T&&>(t); }
CUTE_GCC_UNREACHABLE;}
// Takes the elements in the range [B,E)template <int B, int E, class T>CUTE_HOST_DEVICE constexprautotake(T const& t){ if constexpr (E == -1) { if constexpr (is_tuple<T>::value) { return take<B,tuple_size<T>::value>(t); } else { return take<B,1>(t); } } else if constexpr (B <= E) { return detail::apply(t, [](auto const&... a) { return cute::make_tuple(a...); }, make_range<B,E>{}); } else { static_assert(B <= E); }
CUTE_GCC_UNREACHABLE;}
// Select tuple elements with given indices.template <int... I, class T>CUTE_HOST_DEVICE constexprautoselect(T const& t){ return cute::make_tuple(get<I>(t)...);}
// Wrap non-tuples into rank-1 tuples or forwardtemplate <class T>CUTE_HOST_DEVICE constexprautowrap(T const& t){ if constexpr (is_tuple<T>::value) { return t; } else { return cute::make_tuple(t); }
CUTE_GCC_UNREACHABLE;}
// Unwrap rank-1 tuples until we're left with a rank>1 tuple or a non-tupletemplate <class T>CUTE_HOST_DEVICE constexprautounwrap(T const& t){ if constexpr (is_tuple<T>::value) { if constexpr (tuple_size<T>::value == 1) { return unwrap(get<0>(t)); } else { return t; } } else { return t; }
CUTE_GCC_UNREACHABLE;}
//// Flatten and Unflatten//
template <class T>struct is_flat : true_type {};
template <class... Ts>struct is_flat<tuple<Ts...>> : bool_constant<(true && ... && (not is_tuple<Ts>::value))> {};
// Flatten a hierarchical tuple to a tuple of depth one// and wrap non-tuples into a rank-1 tuple.template <class T>CUTE_HOST_DEVICE constexprautoflatten_to_tuple(T const& t){ if constexpr (is_tuple<T>::value) { if constexpr (is_flat<T>::value) { // Shortcut for perf return t; } else { return filter_tuple(t, [](auto const& a) { return flatten_to_tuple(a); }); } } else { return cute::make_tuple(t); }
CUTE_GCC_UNREACHABLE;}
// Flatten a hierarchical tuple to a tuple of depth one// and leave non-tuple untouched.template <class T>CUTE_HOST_DEVICE constexprautoflatten(T const& t){ if constexpr (is_tuple<T>::value) { if constexpr (is_flat<T>::value) { // Shortcut for perf return t; } else { return filter_tuple(t, [](auto const& a) { return flatten_to_tuple(a); }); } } else { return t; }
CUTE_GCC_UNREACHABLE;}
namespace detail {
template <class FlatTuple, class TargetProfile>CUTE_HOST_DEVICE constexprautounflatten_impl(FlatTuple const& flat_tuple, TargetProfile const& target_profile){ if constexpr (is_tuple<TargetProfile>::value) { return fold(target_profile, cute::make_tuple(cute::make_tuple(), flat_tuple), [](auto const& v, auto const& t) { auto [result, remaining_tuple] = v; auto [sub_result, sub_tuple] = unflatten_impl(remaining_tuple, t); return cute::make_tuple(append(result, sub_result), sub_tuple); }); } else { return cute::make_tuple(get<0>(flat_tuple), take<1, decltype(rank(flat_tuple))::value>(flat_tuple)); }
CUTE_GCC_UNREACHABLE;}
} // end namespace detail
// Unflatten a flat tuple into a hierarchical tuple// @pre flatten(@a flat_tuple) == @a flat_tuple// @pre rank(flatten(@a target_profile)) == rank(@a flat_tuple)// @post congruent(@a result, @a target_profile)// @post flatten(@a result) == @a flat_tupletemplate <class FlatTuple, class TargetProfile>CUTE_HOST_DEVICE constexprautounflatten(FlatTuple const& flat_tuple, TargetProfile const& target_profile){ auto [unflatten_tuple, flat_remainder] = detail::unflatten_impl(flat_tuple, target_profile); CUTE_STATIC_ASSERT_V(rank(flat_remainder) == Int<0>{}); return unflatten_tuple;}
//// insert and remove and replace//
namespace detail {
// Shortcut around cute::tuple_cat for common insert/remove/repeat casestemplate <class T, class X, int... I, int... J, int... K>CUTE_HOST_DEVICE constexprautoconstruct(T const& t, X const& x, seq<I...>, seq<J...>, seq<K...>){ return cute::make_tuple(get<I>(t)..., (void(J),x)..., get<K>(t)...);}
} // end namespace detail
// Insert x into the Nth position of the tupletemplate <int N, class T, class X>CUTE_HOST_DEVICE constexprautoinsert(T const& t, X const& x){ return detail::construct(t, x, make_seq<N>{}, seq<0>{}, make_range<N,tuple_size<T>::value>{});}
// Remove the Nth element of the tupletemplate <int N, class T>CUTE_HOST_DEVICE constexprautoremove(T const& t){ return detail::construct(t, 0, make_seq<N>{}, seq<>{}, make_range<N+1,tuple_size<T>::value>{});}
// Replace the Nth element of the tuple with xtemplate <int N, class T, class X>CUTE_HOST_DEVICE constexprautoreplace(T const& t, X const& x){ if constexpr (is_tuple<T>::value) { return detail::construct(t, x, make_seq<N>{}, seq<0>{}, make_range<N+1,tuple_size<T>::value>{}); } else { static_assert(N == 0); return x; }
CUTE_GCC_UNREACHABLE;}
// Replace the first element of the tuple with xtemplate <class T, class X>CUTE_HOST_DEVICE constexprautoreplace_front(T const& t, X const& x){ if constexpr (is_tuple<T>::value) { return detail::construct(t, x, seq<>{}, seq<0>{}, make_range<1,tuple_size<T>::value>{}); } else { return x; }
CUTE_GCC_UNREACHABLE;}
// Replace the last element of the tuple with xtemplate <class T, class X>CUTE_HOST_DEVICE constexprautoreplace_back(T const& t, X const& x){ if constexpr (is_tuple<T>::value) { return detail::construct(t, x, make_seq<tuple_size<T>::value-1>{}, seq<0>{}, seq<>{}); } else { return x; }
CUTE_GCC_UNREACHABLE;}
//// Make a tuple of Xs of tuple_size N//
template <int N, class X>CUTE_HOST_DEVICE constexprautotuple_repeat(X const& x){ return detail::construct(0, x, seq<>{}, make_seq<N>{}, seq<>{});}
//// Make repeated Xs of rank N//
template <int N, class X>CUTE_HOST_DEVICE constexprautorepeat(X const& x){ if constexpr (N == 1) { return x; } else { return detail::construct(0, x, seq<>{}, make_seq<N>{}, seq<>{}); }
CUTE_GCC_UNREACHABLE;}
//// Make a tuple of Xs the same profile as tuple T//
template <class T, class X>CUTE_HOST_DEVICE constexprautorepeat_like(T const& t, X const& x){ if constexpr (is_tuple<T>::value) { return transform(t, [&](auto const& a) { return repeat_like(a,x); }); } else { return x; }
CUTE_GCC_UNREACHABLE;}
// Group the elements [B,E) of a T into a single element// e.g. group<2,4>(T<_1,_2,_3,_4,_5,_6>{})// => T<_1,_2,T<_3,_4>,_5,_6>{}template <int B, int E, class T>CUTE_HOST_DEVICE constexprautogroup(T const& t){ if constexpr (not is_tuple<T>::value) { if constexpr (E == -1) { return group<B,1>(t); } else { return detail::construct(t, take<B,E>(t), make_seq<B>{}, make_seq<(B < E)>{}, make_range<E,1>{}); } } else if constexpr (E == -1) { return group<B,tuple_size<T>::value>(t); } else if constexpr (B <= E) { return detail::construct(t, take<B,E>(t), make_seq<B>{}, make_seq<(B < E)>{}, make_range<E,tuple_size<T>::value>{}); } else { static_assert(B <= E); }
CUTE_GCC_UNREACHABLE;}
//// Extend a T to rank N by appending/prepending an element//
template <int N, class T, class X>CUTE_HOST_DEVICE constexprautoappend(T const& a, X const& x){ if constexpr (is_tuple<T>::value) { if constexpr (N == tuple_size<T>::value) { return a; } else { static_assert(N > tuple_size<T>::value); return detail::construct(a, x, make_seq<tuple_size<T>::value>{}, make_seq<N-tuple_size<T>::value>{}, seq<>{}); } } else { if constexpr (N == 1) { return a; } else { return detail::construct(cute::make_tuple(a), x, seq<0>{}, make_seq<N-1>{}, seq<>{}); } }
CUTE_GCC_UNREACHABLE;}
template <class T, class X>CUTE_HOST_DEVICE constexprautoappend(T const& a, X const& x){ if constexpr (is_tuple<T>::value) { return detail::construct(a, x, make_seq<tuple_size<T>::value>{}, seq<0>{}, seq<>{}); } else { return cute::make_tuple(a, x); }
CUTE_GCC_UNREACHABLE;}
template <int N, class T, class X>CUTE_HOST_DEVICE constexprautoprepend(T const& a, X const& x){ if constexpr (is_tuple<T>::value) { if constexpr (N == tuple_size<T>::value) { return a; } else { static_assert(N > tuple_size<T>::value); return detail::construct(a, x, seq<>{}, make_seq<N-tuple_size<T>::value>{}, make_seq<tuple_size<T>::value>{}); } } else { if constexpr (N == 1) { return a; } else { static_assert(N > 1); return detail::construct(cute::make_tuple(a), x, seq<>{}, make_seq<N-1>{}, seq<0>{}); } }
CUTE_GCC_UNREACHABLE;}
template <class T, class X>CUTE_HOST_DEVICE constexprautoprepend(T const& a, X const& x){ if constexpr (is_tuple<T>::value) { return detail::construct(a, x, seq<>{}, seq<0>{}, make_seq<tuple_size<T>::value>{}); } else { return cute::make_tuple(x, a); }
CUTE_GCC_UNREACHABLE;}
//// Inclusive scan (prefix sum)//
namespace detail {
template <class T, class V, class F, int I, int... Is>CUTE_HOST_DEVICE constexprautoiscan(T const& t, V const& v, F&& f, seq<I,Is...>){ // Apply the function to v and the element at I auto v_next = f(v, get<I>(t)); // Replace I with v_next auto t_next = replace<I>(t, v_next);
#if 0 std::cout << "ISCAN i" << I << std::endl; std::cout << " t " << t << std::endl; std::cout << " i " << v << std::endl; std::cout << " f(i,t) " << v_next << std::endl; std::cout << " t_n " << t_next << std::endl;#endif
if constexpr (sizeof...(Is) == 0) { return t_next; } else { return iscan(t_next, v_next, f, seq<Is...>{}); }
CUTE_GCC_UNREACHABLE;}
} // end namespace detail
template <class T, class V, class F>CUTE_HOST_DEVICE constexprautoiscan(T const& t, V const& v, F&& f){ return detail::iscan(t, v, f, tuple_seq<T>{});}
//// Exclusive scan (prefix sum)//
namespace detail {
template <class T, class V, class F, int I, int... Is>CUTE_HOST_DEVICE constexprautoescan(T const& t, V const& v, F&& f, seq<I,Is...>){ if constexpr (sizeof...(Is) == 0) { // Replace I with v return replace<I>(t, v); } else { // Apply the function to v and the element at I auto v_next = f(v, get<I>(t)); // Replace I with v auto t_next = replace<I>(t, v);
#if 0 std::cout << "ESCAN i" << I << std::endl; std::cout << " t " << t << std::endl; std::cout << " i " << v << std::endl; std::cout << " f(i,t) " << v_next << std::endl; std::cout << " t_n " << t_next << std::endl;#endif
// Recurse return escan(t_next, v_next, f, seq<Is...>{}); }
CUTE_GCC_UNREACHABLE;}
} // end namespace detail
template <class T, class V, class F>CUTE_HOST_DEVICE constexprautoescan(T const& t, V const& v, F&& f){ return detail::escan(t, v, f, tuple_seq<T>{});}
//// Zip (Transpose)//
// Take ((a,b,c,...),(x,y,z,...),...) rank-R0 x rank-R1 input// to produce ((a,x,...),(b,y,...),(c,z,...),...) rank-R1 x rank-R0 output
namespace detail {
template <int J, class... Ts>CUTE_HOST_DEVICE constexprautozip_(Ts const&... ts){ return cute::make_tuple(get<J>(ts)...);}
template <class T, int... Is, int... Js>CUTE_HOST_DEVICE constexprautozip(T const& t, seq<Is...>, seq<Js...>){ static_assert(conjunction<bool_constant<tuple_size<tuple_element_t<0,T>>::value == tuple_size<tuple_element_t<Is,T>>::value>...>::value, "Mismatched Ranks"); return cute::make_tuple(zip_<Js>(get<Is>(t)...)...);}
} // end namespace detail
template <class T>CUTE_HOST_DEVICE constexprautozip(T const& t){ if constexpr (is_tuple<T>::value) { if constexpr (is_tuple<tuple_element_t<0,T>>::value) { return detail::zip(t, tuple_seq<T>{}, tuple_seq<tuple_element_t<0,T>>{}); } else { return cute::make_tuple(t); } } else { return t; }
CUTE_GCC_UNREACHABLE;}
// Convenient to pass them in separatelytemplate <class T0, class T1, class... Ts>CUTE_HOST_DEVICE constexprautozip(T0 const& t0, T1 const& t1, Ts const&... ts){ return zip(cute::make_tuple(t0, t1, ts...));}
//// zip2_by -- A guided zip for rank-2 tuples// Take a tuple like ((A,a),((B,b),(C,c)),d)// and produce a tuple ((A,(B,C)),(a,(b,c),d))// where the rank-2 modes are selected by the terminals of the guide (X,(X,X))//
namespace detail {
template <class T, class TG, int... Is, int... Js>CUTE_HOST_DEVICE constexprautozip2_by(T const& t, TG const& guide, seq<Is...>, seq<Js...>){ // zip2_by produces the modes like ((A,a),(B,b),...) auto split = cute::make_tuple(zip2_by(get<Is>(t), get<Is>(guide))...);
// Rearrange and append missing modes from t to make ((A,B,...),(a,b,...,x,y)) return cute::make_tuple(cute::make_tuple(get<0>(get<Is>(split))...), cute::make_tuple(get<1>(get<Is>(split))..., get<Js>(t)...));}
} // end namespace detail
template <class T, class TG>CUTE_HOST_DEVICE constexprautozip2_by(T const& t, TG const& guide){ if constexpr (is_tuple<TG>::value) { constexpr int TR = tuple_size<T>::value; constexpr int GR = tuple_size<TG>::value; static_assert(TR >= GR, "Mismatched ranks"); return detail::zip2_by(t, guide, make_range< 0, GR>{}, make_range<GR, TR>{}); } else { static_assert(tuple_size<T>::value == 2, "Mismatched ranks"); return t; }
CUTE_GCC_UNREACHABLE;}
/// @return A tuple of the elements of @c t in reverse order.template <class T>CUTE_HOST_DEVICE constexprautoreverse(T const& t){ if constexpr (is_tuple<T>::value) { return detail::apply(t, [](auto const&... a){ return cute::make_tuple(a...); }, tuple_rseq<T>{}); } else { return t; }}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
namespace cute {
//// Cluster launch utility//CUTE_HOSTboolinitialize_preferred_cluster_launch(void const* const kernel_function, dim3 const& grid_dims, dim3 const& cluster_dims_preferred, dim3 const& cluster_dims_fallback){ // // Validate cluster_dims //
// Total number of cluster cannot be greater than 32 (hardware requirement) if (cluster_dims_preferred.x * cluster_dims_preferred.y * cluster_dims_preferred.z <= 0 || cluster_dims_preferred.x * cluster_dims_preferred.y * cluster_dims_preferred.z > 32) { std::cout << "Invalid preferred cluster dimensions: Attempting to init preferred cluster (" << cluster_dims_preferred.x << "," << cluster_dims_preferred.y << "," << cluster_dims_preferred.z << ") [" << (cluster_dims_preferred.x * cluster_dims_preferred.y * cluster_dims_preferred.z) << "] which must be within (0,32]." << std::endl; return false; }
// Total number of cluster cannot be greater than 32 (hardware requirement) if (cluster_dims_fallback.x * cluster_dims_fallback.y * cluster_dims_fallback.z <= 0 || cluster_dims_fallback.x * cluster_dims_fallback.y * cluster_dims_fallback.z > 32) { std::cout << "Invalid cluster dimensions: Attempting to init fallback cluster (" << cluster_dims_fallback.x << "," << cluster_dims_fallback.y << "," << cluster_dims_fallback.z << ") [" << (cluster_dims_fallback.x * cluster_dims_fallback.y * cluster_dims_fallback.z) << "] which must be within (0,32]." << std::endl; return false; }
// Total grid dimensions must be within (2^32, 2^16, 2^16) if (grid_dims.y > (1 << 16) || grid_dims.z > (1 << 16)) { std::cout << "Invalid grid dimensions: Attempting to init grid dimensions (" << grid_dims.x << "," << grid_dims.y << "," << grid_dims.z << ") which must be within (2^32, 2^16, 2^16)." << std::endl; return false; }
// grid_dims should be divisible by cluster_dims_preferred if (grid_dims.x % cluster_dims_preferred.x != 0 || grid_dims.y % cluster_dims_preferred.y != 0 || grid_dims.z % cluster_dims_preferred.z != 0) { std::cout << "Invalid grid dimensions: Preferred cluster (" << cluster_dims_preferred.x << "," << cluster_dims_preferred.y << "," << cluster_dims_preferred.z << ") does not divide Grid (" << grid_dims.x << "," << grid_dims.y << "," << grid_dims.z << ")." << std::endl; return false; }
// cluster_dims_preferred should be divisible by cluster_dims_fallback if (cluster_dims_preferred.x % cluster_dims_fallback.x != 0 || cluster_dims_preferred.y % cluster_dims_fallback.y != 0 || cluster_dims_preferred.z % cluster_dims_fallback.z != 0) { std::cout << "Invalid cluster dimensions: Fallback cluster (" << cluster_dims_fallback.x << "," << cluster_dims_fallback.y << "," << cluster_dims_fallback.z << ") does not divide Preferred cluster (" << cluster_dims_preferred.x << "," << cluster_dims_preferred.y << "," << cluster_dims_preferred.z << ")." << std::endl; return false; }
// Both cluster dimenions should have the same depth if (cluster_dims_preferred.z != cluster_dims_fallback.z) { std::cout << "Invalid cluster dimensions: Fallback cluster (" << cluster_dims_fallback.x << "," << cluster_dims_fallback.y << "," << cluster_dims_fallback.z << ") and Preferred cluster (" << cluster_dims_preferred.x << "," << cluster_dims_preferred.y << "," << cluster_dims_preferred.z << ") does not have the same depth." << std::endl; return false; }
return true;}} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
// Config#if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && \ ((__CUDACC_VER_MAJOR__ >= 12) || ((__CUDACC_VER_MAJOR__ == 11) && (__CUDACC_VER_MINOR__ >= 8))))# define CUTE_ARCH_CLUSTER_SM90_ENABLED#endif
#if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 900) && (__CUDACC_VER_MAJOR__ >= 12))# define CUTE_ARCH_ELECT_ONE_SM90_ENABLED#endif
namespace cute {
CUTE_DEVICE void cluster_arrive_relaxed(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) asm volatile("barrier.cluster.arrive.relaxed.aligned;\n" : : );#else CUTE_INVALID_CONTROL_PATH("CUTE_ARCH_CLUSTER_SM90_ENABLED is not defined");#endif}
CUTE_DEVICE void cluster_arrive(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) asm volatile("barrier.cluster.arrive.aligned;\n" : : );#else CUTE_INVALID_CONTROL_PATH("CUTE_ARCH_CLUSTER_SM90_ENABLED is not defined");#endif}
CUTE_DEVICE void cluster_wait(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) asm volatile("barrier.cluster.wait.aligned;\n" : : );#else CUTE_INVALID_CONTROL_PATH("CUTE_ARCH_CLUSTER_SM90_ENABLED is not defined");#endif}
CUTE_DEVICE void cluster_sync(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) cluster_arrive(); cluster_wait();#else CUTE_INVALID_CONTROL_PATH("CUTE_ARCH_CLUSTER_SM90_ENABLED is not defined");#endif}
// Returns the dim3 grid size in terms of number of clusters.CUTE_DEVICE dim3 cluster_grid_dims(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t x, y, z; asm volatile("mov.u32 %0, %%nclusterid.x;\n" : "=r"(x) : ); asm volatile("mov.u32 %0, %%nclusterid.y;\n" : "=r"(y) : ); asm volatile("mov.u32 %0, %%nclusterid.z;\n" : "=r"(z) : ); return {x, y, z};#elif defined(__CUDA_ARCH__) // MSVC requires protecting use of gridDim with __CUDA_ARCH__. return gridDim;#elif defined(_MSC_VER) CUTE_INVALID_CONTROL_PATH("cluster_grid_dims() can only be called on device"); return {0, 0, 0};#else return {0, 0, 0};#endif}
// Returns the dim3 cluster rank in the grid.CUTE_DEVICE dim3 cluster_id_in_grid(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t x, y, z; asm volatile("mov.u32 %0, %%clusterid.x;\n" : "=r"(x) : ); asm volatile("mov.u32 %0, %%clusterid.y;\n" : "=r"(y) : ); asm volatile("mov.u32 %0, %%clusterid.z;\n" : "=r"(z) : ); return {x, y, z};#elif defined(__CUDA_ARCH__) // MSVC requires protecting use of blockIdx with __CUDA_ARCH__. return blockIdx;#elif defined(_MSC_VER) CUTE_INVALID_CONTROL_PATH("cluster_id_in_grid() can only be called on device"); return {0, 0, 0};#else return {0, 0, 0};#endif}
// Returns the relative dim3 block rank local to the cluster.CUTE_DEVICE dim3 block_id_in_cluster(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t x, y, z; asm volatile("mov.u32 %0, %%cluster_ctaid.x;\n" : "=r"(x) : ); asm volatile("mov.u32 %0, %%cluster_ctaid.y;\n" : "=r"(y) : ); asm volatile("mov.u32 %0, %%cluster_ctaid.z;\n" : "=r"(z) : ); return {x, y, z};#else return {0,0,0};#endif}
// Returns the dim3 cluster shape.CUTE_DEVICE dim3 cluster_shape(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t x, y, z; asm volatile("mov.u32 %0, %%cluster_nctaid.x;\n" : "=r"(x) : ); asm volatile("mov.u32 %0, %%cluster_nctaid.y;\n" : "=r"(y) : ); asm volatile("mov.u32 %0, %%cluster_nctaid.z;\n" : "=r"(z) : ); return {x, y, z};#else return {1,1,1};#endif}
// Get 1D ctaid in a cluster.CUTE_DEVICE uint32_t block_rank_in_cluster(){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t rank; asm volatile("mov.u32 %0, %%cluster_ctarank;\n" : "=r"(rank) :); return rank;#else return 0;#endif}
// Set the destination block-ID in cluster for a given SMEM AddressCUTE_DEVICE uint32_t set_block_rank(uint32_t smemAddr, uint32_t rank){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t result; asm volatile("mapa.shared::cluster.u32 %0, %1, %2;\n" : "=r"(result) : "r"(smemAddr), "r"(rank)); return result;#else return smemAddr;#endif}
// Elect one thread in the warp. The elected thread gets its predicate set to true, all others obtain false.CUTE_HOST_DEVICE uint32_t elect_one_sync(){#if defined(CUTE_ARCH_ELECT_ONE_SM90_ENABLED) uint32_t pred = 0; uint32_t laneid = 0; asm volatile( "{\n" ".reg .b32 %%rx;\n" ".reg .pred %%px;\n" " elect.sync %%rx|%%px, %2;\n" "@%%px mov.s32 %1, 1;\n" " mov.s32 %0, %%rx;\n" "}\n" : "+r"(laneid), "+r"(pred) : "r"(0xFFFFFFFF)); return pred;#elif defined(__CUDA_ARCH__) return (threadIdx.x % 32) == 0;#else return true;#endif}
struct ElectOneLaneIdReturnType { uint32_t is_leader; uint32_t leader_lane_id;};
CUTE_HOST_DEVICEElectOneLaneIdReturnTypeelect_one_leader_sync(){#if defined(CUTE_ARCH_ELECT_ONE_SM90_ENABLED) uint32_t pred = 0; uint32_t laneid = 0; asm volatile( "{\n" ".reg .b32 %%rx;\n" ".reg .pred %%px;\n" " elect.sync %%rx|%%px, %2;\n" "@%%px mov.s32 %1, 1;\n" " mov.s32 %0, %%rx;\n" "}\n" : "+r"(laneid), "+r"(pred) : "r"(0xFFFFFFFF)); return {pred, laneid};#elif defined(__CUDA_ARCH__) return {(threadIdx.x % 32) == 0, 0};#else return {true, 0};#endif}
// Store value to remote shared memory in the clusterCUTE_DEVICEvoidstore_shared_remote(uint32_t value, uint32_t smem_addr, uint32_t mbarrier_addr, uint32_t dst_cta_rank){#if defined(CUTE_ARCH_CLUSTER_SM90_ENABLED) uint32_t dsmem_addr = set_block_rank(smem_addr, dst_cta_rank); uint32_t remote_barrier_addr = set_block_rank(mbarrier_addr, dst_cta_rank); asm volatile("st.async.shared::cluster.mbarrier::complete_tx::bytes.u32 [%0], %1, [%2];" : : "r"(dsmem_addr), "r"(value), "r"(remote_barrier_addr));#endif}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111/*************************************************************************************************** * Copyright (c) 2024 - 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 <cutlass/arch/config.h> // CUTLASS_ARCH_MMA_SMxx_ENABLED
// MMA SM90A#if defined(CUTLASS_ARCH_MMA_SM90A_ENABLED)# define CUTE_ARCH_MMA_SM90A_ENABLED#endif
// TMA instructions#if defined(CUTLASS_ARCH_MMA_SM90_ENABLED)# define CUTE_ARCH_TMA_SM90_ENABLED#endif
#if defined(CUTLASS_ARCH_MMA_MODIFIABLE_TMA_SM90_ENABLED)# define CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED#endif
// STSM#if defined(CUTLASS_ARCH_MMA_SM90_ENABLED)# define CUTE_ARCH_STSM_SM90_ENABLED#endif
////////////////////////////////////////////////////////////////////////////////////////////////////
#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED) || defined(CUTLASS_ARCH_MMA_SM101A_ENABLED) ||\ defined(CUTLASS_ARCH_MMA_SM120A_ENABLED))# define CUTE_ARCH_TMA_SM90_ENABLED# define CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED# define CUTE_ARCH_STSM_SM90_ENABLED#endif
#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED) || defined(CUTLASS_ARCH_MMA_SM101A_ENABLED))# define CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED# define CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED# define CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED# define CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED# define CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED#endif
#if defined(CUTLASS_ARCH_MMA_SM100A_ENABLED)# define CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED#endif
#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED) || defined(CUTLASS_ARCH_MMA_SM101A_ENABLED))# define CUTE_ARCH_TCGEN05_S8_MMA_ENABLED#endif
#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED) || defined(CUTLASS_ARCH_MMA_SM101A_ENABLED) ||\ defined(CUTLASS_ARCH_MMA_SM120A_ENABLED))# define CUTE_ARCH_LDSM_SM100A_ENABLED# define CUTE_ARCH_STSM_SM100A_ENABLED#endif
#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED) || defined(CUTLASS_ARCH_MMA_SM101A_ENABLED))# define CUTE_ARCH_TCGEN05_TMEM_ENABLED#endif
#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED) || defined(CUTLASS_ARCH_MMA_SM101A_ENABLED))# define CUTE_ARCH_TMA_SM100_ENABLED#endif
// {add, mul, fma}.f32x2 PTX#if (defined(CUTLASS_ARCH_MMA_SM100A_ENABLED)) #define CUTE_ARCH_FLOAT2_MATH_ENABLED#endif
#if defined(CUTLASS_ARCH_MMA_SM120_ENABLED) || defined(CUTLASS_ARCH_MMA_SM120A_ENABLED)# define CUTE_ARCH_MMA_SM120_ENABLED# define CUTE_ARCH_TMA_SM120_ENABLED#endif
#if defined(CUTLASS_ARCH_MMA_SM120_ENABLED) || defined(CUTLASS_ARCH_MMA_SM120A_ENABLED)# if (__CUDACC_VER_MAJOR__ > 12 || (__CUDACC_VER_MAJOR__ == 12 && __CUDACC_VER_MINOR__ >= 8))# define CUTE_ARCH_F8F6F4_MMA_ENABLED# define CUTE_ARCH_MXF8F6F4_MMA_ENABLED# define CUTE_ARCH_MXF4NVF4_2X_UE8M0_MMA_ENABLED# define CUTE_ARCH_MXF4NVF4_4X_UE4M3_MMA_ENABLED# endif#endif
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/util.hpp>#include <cute/numeric/numeric_types.hpp>
namespace cute{
//// Direct Copy for any specific types//
template <class S, class D = S>struct UniversalCopy{ using SRegisters = S[1]; using DRegisters = D[1];
// Sanity static_assert(sizeof_bits_v<S> >= 8); static_assert(sizeof_bits_v<D> >= 8);
CUTE_HOST_DEVICE static constexpr void copy(S const& src, D & dst) { dst = src; }};
//// Placeholder for the copy algorithm's stronger auto-vectorizing behavior// that assumes alignment of pointers and dynamic layouts up to MaxVecBits//
template <int MaxVecBits = 128>struct AutoVectorizingCopyWithAssumedAlignment : UniversalCopy<uint_bit_t<MaxVecBits>>{ static_assert(MaxVecBits == 8 || MaxVecBits == 16 || MaxVecBits == 32 || MaxVecBits == 64 || MaxVecBits == 128, "Expected MaxVecBits to be 8 or 16 or 32 or 64 or 128 for alignment and performance.");};
//// AutoVectorizingCopy alias assumes maximal alignment of pointers and dynamic strides.// If this is not the case then AutoVectorizingCopyWithAssumedAlignment should be used instead//
using AutoVectorizingCopy = AutoVectorizingCopyWithAssumedAlignment<128>;
//// DefaultCopy alias does not assume alignment of pointers or dynamic strides.//
using DefaultCopy = AutoVectorizingCopyWithAssumedAlignment<8>;
//// Copy policy automatically selecting between// UniversalCopy and cp.async , based on type and memory space.//struct AutoCopyAsync {};
//// Global memory prefetch into L2//
CUTE_HOST_DEVICE static voidprefetch(void const* gmem_ptr){#if defined(__CUDA_ARCH__) asm volatile("prefetch.global.L2 [%0];\n" : : "l"(gmem_ptr) : "memory");#endif}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664/*************************************************************************************************** * Copyright (c) 2020 - 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/config.hpp>
#include <cute/arch/copy.hpp>#include <cute/arch/copy_sm90.hpp>namespace cute{
constexpr uint32_t Sm100MmaPeerBitMask = 0xFEFFFFFF;constexpr uint64_t Sm100MemDescDefault = uint64_t(0x1000000000000000);
/////////////////////////////////////////////////////////////////////////////////////////////////////// UTMA_LOAD : Initiates a TMA copy from global memory to shared memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_1D{ CUTE_HOST_DEVICE static void copy([[maybe_unused]] void const* desc_ptr, [[maybe_unused]] uint64_t* mbar_ptr, [[maybe_unused]] uint64_t cache_hint, [[maybe_unused]] void * smem_ptr, [[maybe_unused]] int32_t const& crd0) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.1d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3}], [%2], %4;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_2D{ CUTE_HOST_DEVICE static void copy([[maybe_unused]] void const* desc_ptr, [[maybe_unused]] uint64_t* mbar_ptr, [[maybe_unused]] uint64_t cache_hint, [[maybe_unused]] void * smem_ptr, [[maybe_unused]] int32_t const& crd0, int32_t const& crd1) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.2d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4}], [%2], %5;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_3D{ CUTE_HOST_DEVICE static void copy([[maybe_unused]] void const* desc_ptr, [[maybe_unused]] uint64_t* mbar_ptr, [[maybe_unused]] uint64_t cache_hint, [[maybe_unused]] void * smem_ptr, [[maybe_unused]] int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.3d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5}], [%2], %6;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.4d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6}], [%2], %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.5d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], %8;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) { return SM100_TMA_2SM_LOAD_1D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) { return SM100_TMA_2SM_LOAD_2D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM100_TMA_2SM_LOAD_3D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM100_TMA_2SM_LOAD_4D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM100_TMA_2SM_LOAD_5D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1, crd2, crd3, crd4); }
using PREFETCH = typename SM90_TMA_LOAD::PREFETCH;};
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD_MULTICAST: Initiates a TMA copy from global memory to shared memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_MULTICAST_1D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.1d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4}], [%2], %3, %5;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_MULTICAST_2D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.2d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5}], [%2], %3, %6;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_MULTICAST_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED)uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.3d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5, %6}], [%2], %3, %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "r"(crd2), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_MULTICAST_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.4d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5, %6, %7}], [%2], %3, %8;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_MULTICAST_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.5d.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5, %6, %7, %8}], [%2], %3, %9;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM0_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_MULTICAST{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) { return SM100_TMA_2SM_LOAD_MULTICAST_1D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) { return SM100_TMA_2SM_LOAD_MULTICAST_2D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM100_TMA_2SM_LOAD_MULTICAST_3D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM100_TMA_2SM_LOAD_MULTICAST_4D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM100_TMA_2SM_LOAD_MULTICAST_5D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1, crd2, crd3, crd4); }
using PREFETCH = typename SM90_TMA_LOAD::PREFETCH;};////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_IM2COL_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.3d.im2col.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5}], [%2], {%6}, %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_n), "h"(offset_w), "l"(Sm100MemDescDefault) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_IM2COL_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.4d.im2col.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6}], [%2], {%7, %8}, %9;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w), "h"(offset_h), "l"(Sm100MemDescDefault) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_IM2COL_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.5d.im2col.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], {%8, %9, %10}, %11;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_d), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(offset_d), "l"(Sm100MemDescDefault) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_IM2COL{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) { return SM100_TMA_2SM_LOAD_IM2COL_3D::copy(desc_ptr, mbar_ptr, smem_ptr, coord_c, coord_w, coord_n, offset_w); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) { return SM100_TMA_2SM_LOAD_IM2COL_4D::copy(desc_ptr, mbar_ptr, smem_ptr, coord_c, coord_w, coord_h, coord_n, offset_w, offset_h); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) { return SM100_TMA_2SM_LOAD_IM2COL_5D::copy(desc_ptr, mbar_ptr, smem_ptr, coord_c, coord_w, coord_h, coord_d, coord_n, offset_w, offset_h, offset_d); }
using PREFETCH = typename SM90_TMA_LOAD_IM2COL::PREFETCH;};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.3d.im2col.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%3, %4, %5}], [%2], {%6}, %7, %8;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_n), "h"(offset_w), "h"(multicast_mask), "l"(Sm100MemDescDefault) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.4d.im2col.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6}], [%2], {%7, %8}, %9, %10;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(multicast_mask), "l"(Sm100MemDescDefault) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) {#if defined(CUTE_ARCH_TMA_SM100_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Executed by both CTAs. Set peer bit to 0 so that the // transaction bytes will update CTA0's barrier. uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr) & Sm100MmaPeerBitMask; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile ( "cp.async.bulk.tensor.5d.im2col.cta_group::2.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], {%8, %9, %10}, %11, %12;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_d), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(offset_d), "h"(multicast_mask), "l"(Sm100MemDescDefault) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM100_ENABLED.");#endif }};
struct SM100_TMA_2SM_LOAD_IM2COL_MULTICAST{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) { return SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_3D::copy(desc_ptr, mbar_ptr, multicast_mask, smem_ptr, coord_c, coord_w, coord_n, offset_w); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) { return SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_4D::copy(desc_ptr, mbar_ptr, multicast_mask, smem_ptr, coord_c, coord_w, coord_h, coord_n, offset_w, offset_h); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) { return SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_5D::copy(desc_ptr, mbar_ptr, multicast_mask, smem_ptr, coord_c, coord_w, coord_h, coord_d, coord_n, offset_w, offset_h, offset_d); }
using PREFETCH = typename SM90_TMA_LOAD_IM2COL::PREFETCH;};
////////////////////////////////////////////////////////////////////////////////////////////////////
} // end namespace cute1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798/*************************************************************************************************** * Copyright (c) 2024 - 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/config.hpp>
#include <cute/arch/copy.hpp>
#if defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 500 #define CUTE_ARCH_WARP_SHUFFLE_ENABLED 1#endif
namespace cute{// Shuffle data between thread pair (0, 1), (2, 3), etc.struct SM50_Shuffle_U32_2x2Trans_XOR1{ using SRegisters = uint32_t[2]; using DRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void copy(uint32_t const& src0, uint32_t const& src1, uint32_t& dst0, uint32_t& dst1) {#if defined(CUTE_ARCH_WARP_SHUFFLE_ENABLED) uint32_t x0 = src0; uint32_t y0 = __shfl_xor_sync(0xffffffff, x0, 1);
uint32_t x1 = src1; uint32_t y1 = __shfl_xor_sync(0xffffffff, x1, 1);
if (threadIdx.x % 2 == 0) { dst1 = y0; } else { dst0 = y1; }#else CUTE_INVALID_CONTROL_PATH("Trying to use __shfl_xor_sync without CUTE_ARCH_WARP_SHUFFLE_ENABLED.");#endif }};
// Shuffle data between thread pair (0, 4), (1, 5), etc.struct SM50_Shuffle_U32_2x2Trans_XOR4{ using SRegisters = uint32_t[2]; using DRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void copy(uint32_t const& src0, uint32_t const& src1, uint32_t& dst0, uint32_t& dst1) {#if defined(CUTE_ARCH_WARP_SHUFFLE_ENABLED) uint32_t x0 = threadIdx.x & 4 ? src0 : src1; uint32_t y0 = __shfl_xor_sync(0xffffffff, x0, 4);
// Replace detination register with shuffle result. if (threadIdx.x & 0x4) { dst0 = y0; } else { dst1 = y0; }#else CUTE_INVALID_CONTROL_PATH("Trying to use __shfl_xor_sync without CUTE_ARCH_WARP_SHUFFLE_ENABLED.");#endif }};
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/copy.hpp>
// Config#if defined(__clang__) && defined(__CUDA__) // ldmatrix PTX instructions added in Clang 14: https://reviews.llvm.org/D107046 // ... but will not work until Clang 15: // * https://reviews.llvm.org/D121666 // * https://reviews.llvm.org/D126846 #define CUTE_ARCH_CLANG_SUPPORTS_LDSM_SM75 (__clang_major__ >= 15)#endif
#if defined(__NVCC__) || defined(__CUDACC_RTC__) // ldmatrix PTX instruction added in CUDA 10.2+ #define CUTE_ARCH_NVCC_SUPPORTS_LDSM_SM75 ((__CUDACC_VER_MAJOR__ == 10 && __CUDACC_VER_MINOR__ >= 2) || __CUDACC_VER_MAJOR__ >= 11)#endif
#if ! defined(CUTE_ARCH_LDSM_SM75_SUPPORTED) #define CUTE_ARCH_LDSM_SM75_SUPPORTED (CUTE_ARCH_NVCC_SUPPORTS_LDSM_SM75 || CUTE_ARCH_CLANG_SUPPORTS_LDSM_SM75)#endif
#if ! defined(CUTE_ARCH_LDSM_SM75_ENABLED) #define CUTE_ARCH_LDSM_SM75_ENABLED (CUTE_ARCH_LDSM_SM75_SUPPORTED)#endif
#if (CUTE_ARCH_LDSM_SM75_ENABLED) && defined(__CUDA_ARCH__) && __CUDA_ARCH__ >= 750 #define CUTE_ARCH_LDSM_SM75_ACTIVATED 1#endif
namespace cute{
struct SM75_U32x1_LDSM_N{ using SRegisters = uint128_t[1]; using DRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void copy(uint128_t const& smem_src, uint32_t& dst) {#if defined(CUTE_ARCH_LDSM_SM75_ACTIVATED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_src); asm volatile ("ldmatrix.sync.aligned.x1.m8n8.shared.b16 {%0}, [%1];\n" : "=r"(dst) : "r"(smem_int_ptr));#else CUTE_INVALID_CONTROL_PATH("Trying to use ldmatrix without CUTE_ARCH_LDSM_SM75_ACTIVATED.");#endif }};
struct SM75_U32x2_LDSM_N{ using SRegisters = uint128_t[1]; using DRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void copy(uint128_t const& smem_src, uint32_t& dst0, uint32_t& dst1) {#if defined(CUTE_ARCH_LDSM_SM75_ACTIVATED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_src); asm volatile ("ldmatrix.sync.aligned.x2.m8n8.shared.b16 {%0, %1}, [%2];\n" : "=r"(dst0), "=r"(dst1) : "r"(smem_int_ptr));#else CUTE_INVALID_CONTROL_PATH("Trying to use ldmatrix without CUTE_ARCH_LDSM_SM75_ACTIVATED.");#endif }};
struct SM75_U32x4_LDSM_N{ using SRegisters = uint128_t[1]; using DRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void copy(uint128_t const& smem_src, uint32_t& dst0, uint32_t& dst1, uint32_t& dst2, uint32_t& dst3) {#if defined(CUTE_ARCH_LDSM_SM75_ACTIVATED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_src); asm volatile ("ldmatrix.sync.aligned.x4.m8n8.shared.b16 {%0, %1, %2, %3}, [%4];\n" : "=r"(dst0), "=r"(dst1), "=r"(dst2), "=r"(dst3) : "r"(smem_int_ptr));#else CUTE_INVALID_CONTROL_PATH("Trying to use ldmatrix without CUTE_ARCH_LDSM_SM75_ACTIVATED.");#endif }};
struct SM75_U16x2_LDSM_T{ using SRegisters = uint128_t[1]; using DRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void copy(uint128_t const& smem_src, uint32_t& dst) {#if defined(CUTE_ARCH_LDSM_SM75_ACTIVATED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_src); asm volatile ("ldmatrix.sync.aligned.x1.trans.m8n8.shared.b16 {%0}, [%1];\n" : "=r"(dst) : "r"(smem_int_ptr));#else CUTE_INVALID_CONTROL_PATH("Trying to use ldmatrix without CUTE_ARCH_LDSM_SM75_ACTIVATED.");#endif }};
struct SM75_U16x4_LDSM_T{ using SRegisters = uint128_t[1]; using DRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void copy(uint128_t const& smem_src, uint32_t& dst0, uint32_t& dst1) {#if defined(CUTE_ARCH_LDSM_SM75_ACTIVATED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_src); asm volatile ("ldmatrix.sync.aligned.x2.trans.m8n8.shared.b16 {%0, %1}, [%2];\n" : "=r"(dst0), "=r"(dst1) : "r"(smem_int_ptr));#else CUTE_INVALID_CONTROL_PATH("Trying to use ldmatrix without CUTE_ARCH_LDSM_SM75_ACTIVATED.");#endif }};
struct SM75_U16x8_LDSM_T{ using SRegisters = uint128_t[1]; using DRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void copy(uint128_t const& smem_src, uint32_t& dst0, uint32_t& dst1, uint32_t& dst2, uint32_t& dst3) {#if defined(CUTE_ARCH_LDSM_SM75_ACTIVATED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_src); asm volatile ("ldmatrix.sync.aligned.x4.trans.m8n8.shared.b16 {%0, %1, %2, %3}, [%4];\n" : "=r"(dst0), "=r"(dst1), "=r"(dst2), "=r"(dst3) : "r"(smem_int_ptr));#else CUTE_INVALID_CONTROL_PATH("Trying to use ldmatrix without CUTE_ARCH_LDSM_SM75_ACTIVATED.");#endif }};
//// Legacy LDSM interfaces that aren't very useful//
template <class T>CUTE_HOST_DEVICEvoidcopy_ldsm(uint128_t const* const smem_ptr, T* rmem_ptr){ uint32_t* reg_ptr = reinterpret_cast<uint32_t*>(rmem_ptr);
// if constexpr if (sizeof(T) == 4) { SM75_U32x1_LDSM_N::copy(smem_ptr[0], reg_ptr[0]); } else if (sizeof(T) == 8) { SM75_U32x2_LDSM_N::copy(smem_ptr[0], reg_ptr[0], reg_ptr[1]); } else if (sizeof(T) == 16) { SM75_U32x4_LDSM_N::copy(smem_ptr[0], reg_ptr[0], reg_ptr[1], reg_ptr[2], reg_ptr[3]); } else { static_assert(sizeof(T) == 4 || sizeof(T) == 8 || sizeof(T) == 16, "sizeof(T) is not supported"); }}
template <class T>CUTE_HOST_DEVICEvoidcopy_ldsm_trans(uint128_t const* const smem_ptr, T* rmem_ptr){ uint32_t* reg_ptr = reinterpret_cast<uint32_t*>(rmem_ptr);
// if constexpr if (sizeof(T) == 4) { SM75_U16x2_LDSM_T::copy(smem_ptr[0], reg_ptr[0]); } else if (sizeof(T) == 8) { SM75_U16x4_LDSM_T::copy(smem_ptr[0], reg_ptr[0], reg_ptr[1]); } else if (sizeof(T) == 16) { SM75_U16x8_LDSM_T::copy(smem_ptr[0], reg_ptr[0], reg_ptr[1], reg_ptr[2], reg_ptr[3]); } else { static_assert(sizeof(T) == 4 || sizeof(T) == 8 || sizeof(T) == 16, "sizeof(T) is not supported"); }}
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/copy.hpp>
// Config#if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 800))# define CUTE_ARCH_CP_ASYNC_SM80_ENABLED#endif
namespace cute{
/// Copy via cp.async with caching at all levelstemplate <class TS, class TD = TS>struct SM80_CP_ASYNC_CACHEALWAYS{ using SRegisters = TS[1]; using DRegisters = TD[1];
static_assert(sizeof(TS) == sizeof(TD), "cp.async requires sizeof(src_value_type) == sizeof(dst_value_type)"); static_assert(sizeof(TS) == 4 || sizeof(TS) == 8 || sizeof(TS) == 16, "cp.async sizeof(TS) is not supported");
CUTE_HOST_DEVICE static void copy(TS const& gmem_src, TD & smem_dst) {#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) TS const* gmem_ptr = &gmem_src; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile("cp.async.ca.shared.global.L2::128B [%0], [%1], %2;\n" :: "r"(smem_int_ptr), "l"(gmem_ptr), "n"(sizeof(TS)));#else CUTE_INVALID_CONTROL_PATH("Support for cp.async instructions has not been enabled");#endif }};
/// Copy via cp.async with caching at global leveltemplate <class TS, class TD = TS>struct SM80_CP_ASYNC_CACHEGLOBAL{ using SRegisters = TS[1]; using DRegisters = TD[1];
static_assert(sizeof(TS) == sizeof(TD), "cp.async requires sizeof(src_value_type) == sizeof(dst_value_type)"); static_assert(sizeof(TS) == 16, "cp.async sizeof(TS) is not supported");
CUTE_HOST_DEVICE static void copy(TS const& gmem_src, TD & smem_dst) {#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) TS const* gmem_ptr = &gmem_src; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile("cp.async.cg.shared.global.L2::128B [%0], [%1], %2;\n" :: "r"(smem_int_ptr), "l"(gmem_ptr), "n"(sizeof(TS)));#else CUTE_INVALID_CONTROL_PATH("Support for cp.async instructions has not been enabled");#endif }};
/// Copy via cp.async with caching at all levelstemplate <class TS, class TD = TS>struct SM80_CP_ASYNC_CACHEALWAYS_ZFILL{ using SRegisters = TS[1]; using DRegisters = TD[1];
static_assert(sizeof(TS) == sizeof(TD), "cp.async requires sizeof(src_value_type) == sizeof(dst_value_type)"); static_assert(sizeof(TS) == 4 || sizeof(TS) == 8 || sizeof(TS) == 16, "cp.async sizeof(TS) is not supported");
CUTE_HOST_DEVICE static void copy(TS const& gmem_src, TD & smem_dst, bool pred) {#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) TS const* gmem_ptr = &gmem_src; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); int src_size = pred ? sizeof(TS) : 0; asm volatile("cp.async.ca.shared.global.L2::128B [%0], [%1], %2, %3;\n" :: "r"(smem_int_ptr), "l"(gmem_ptr), "n"(sizeof(TS)), "r"(src_size));#else CUTE_INVALID_CONTROL_PATH("Support for cp.async instructions has not been enabled");#endif }};
/// Copy via cp.async with caching at global leveltemplate <class TS, class TD = TS>struct SM80_CP_ASYNC_CACHEGLOBAL_ZFILL{ using SRegisters = TS[1]; using DRegisters = TD[1];
static_assert(sizeof(TS) == sizeof(TD), "cp.async requires sizeof(src_value_type) == sizeof(dst_value_type)"); static_assert(sizeof(TS) == 16, "cp.async sizeof(TS) is not supported");
CUTE_HOST_DEVICE static void copy(TS const& gmem_src, TD & smem_dst, bool pred) {#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) TS const* gmem_ptr = &gmem_src; uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); int src_size = pred ? sizeof(TS) : 0; asm volatile("cp.async.cg.shared.global.L2::128B [%0], [%1], %2, %3;\n" :: "r"(smem_int_ptr), "l"(gmem_ptr), "n"(sizeof(TS)), "r"(src_size));#else CUTE_INVALID_CONTROL_PATH("Support for cp.async instructions has not been enabled");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Establishes an ordering w.r.t previously issued cp.async instructions. Does not block.CUTE_HOST_DEVICEvoidcp_async_fence(){#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) asm volatile("cp.async.commit_group;\n" ::);#endif}
////////////////////////////////////////////////////////////////////////////////////////////////////
/// Blocks until all but N previous cp.async.commit_group operations have committed.template <int N>CUTE_HOST_DEVICEvoidcp_async_wait(){#if defined(CUTE_ARCH_CP_ASYNC_SM80_ENABLED) if constexpr (N == 0) { asm volatile("cp.async.wait_all;\n" ::); } else { asm volatile("cp.async.wait_group %0;\n" :: "n"(N)); }#endif}
template <int N>CUTE_HOST_DEVICEvoidcp_async_wait(Int<N>){ return cp_async_wait<N>();}
/////////////////////////////////////////////////////////////////////////////////////////////////
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/arch/config.hpp> // CUTE_ARCH_TMA_SMxx_ENABLED#include <cute/arch/copy.hpp>
namespace cute{
struct SM90_U32x1_STSM_N{ using SRegisters = uint32_t[1]; using DRegisters = uint128_t[1];
CUTE_HOST_DEVICE static void copy(uint32_t const& src, uint128_t & smem_dst) {#if defined(CUTE_ARCH_STSM_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile ("stmatrix.sync.aligned.x1.m8n8.shared.b16 [%0], {%1};\n" :: "r"(smem_int_ptr), "r"(src));#else CUTE_INVALID_CONTROL_PATH("Trying to use stmatrix without CUTE_ARCH_STSM_SM90_ENABLED.");#endif }};
struct SM90_U32x2_STSM_N{ using SRegisters = uint32_t[2]; using DRegisters = uint128_t[1];
CUTE_HOST_DEVICE static void copy(uint32_t const& src0, uint32_t const& src1, uint128_t& smem_dst) {#if defined(CUTE_ARCH_STSM_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile ("stmatrix.sync.aligned.x2.m8n8.shared.b16 [%0], {%1, %2};\n" :: "r"(smem_int_ptr), "r"(src0), "r"(src1));#else CUTE_INVALID_CONTROL_PATH("Trying to use stmatrix without CUTE_ARCH_STSM_SM90_ENABLED.");#endif }};
struct SM90_U32x4_STSM_N{ using SRegisters = uint32_t[4]; using DRegisters = uint128_t[1];
CUTE_HOST_DEVICE static void copy(uint32_t const& src0, uint32_t const& src1, uint32_t const& src2, uint32_t const& src3, uint128_t& smem_dst) {#if defined(CUTE_ARCH_STSM_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile ("stmatrix.sync.aligned.x4.m8n8.shared.b16 [%0], {%1, %2, %3, %4};\n" :: "r"(smem_int_ptr), "r"(src0), "r"(src1), "r"(src2), "r"(src3));#else CUTE_INVALID_CONTROL_PATH("Trying to use stmatrix without CUTE_ARCH_STSM_SM90_ENABLED.");#endif }};
struct SM90_U16x2_STSM_T{ using SRegisters = uint32_t[1]; using DRegisters = uint128_t[1];
CUTE_HOST_DEVICE static void copy(uint32_t const& src, uint128_t& smem_dst) {#if defined(CUTE_ARCH_STSM_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile ("stmatrix.sync.aligned.x1.trans.m8n8.shared.b16 [%0], {%1};\n" :: "r"(smem_int_ptr), "r"(src));#else CUTE_INVALID_CONTROL_PATH("Trying to use stmatrix without CUTE_ARCH_STSM_SM90_ENABLED.");#endif }};
struct SM90_U16x4_STSM_T{ using SRegisters = uint32_t[2]; using DRegisters = uint128_t[1];
CUTE_HOST_DEVICE static void copy(uint32_t const& src0, uint32_t const& src1, uint128_t& smem_dst) {#if defined(CUTE_ARCH_STSM_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile ("stmatrix.sync.aligned.x2.trans.m8n8.shared.b16 [%0], {%1, %2};\n" :: "r"(smem_int_ptr), "r"(src0), "r"(src1));#else CUTE_INVALID_CONTROL_PATH("Trying to use stmatrix without CUTE_ARCH_STSM_SM90_ENABLED.");#endif }};
struct SM90_U16x8_STSM_T{ using SRegisters = uint32_t[4]; using DRegisters = uint128_t[1];
CUTE_HOST_DEVICE static void copy(uint32_t const& src0, uint32_t const& src1, uint32_t const& src2, uint32_t const& src3, uint128_t& smem_dst) {#if defined(CUTE_ARCH_STSM_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_dst); asm volatile ("stmatrix.sync.aligned.x4.trans.m8n8.shared.b16 [%0], {%1, %2, %3, %4};\n" :: "r"(smem_int_ptr), "r"(src0), "r"(src1), "r"(src2), "r"(src3));#else CUTE_INVALID_CONTROL_PATH("Trying to use stmatrix without CUTE_ARCH_STSM_SM90_ENABLED.");#endif }};
//// Legacy STSM interfaces that aren't very useful//
template <class T>CUTE_HOST_DEVICEvoidcopy_stsm(T const* const rmem_ptr, uint128_t* const smem_ptr){ uint32_t const* reg_ptr = reinterpret_cast<uint32_t const*>(rmem_ptr);
// if constexpr if (sizeof(T) == 4) { SM90_U32x1_STSM_N::copy(reg_ptr[0], smem_ptr[0]); } else if (sizeof(T) == 8) { SM90_U32x2_STSM_N::copy(reg_ptr[0], reg_ptr[1], smem_ptr[0]); } else if (sizeof(T) == 16) { SM90_U32x4_STSM_N::copy(reg_ptr[0], reg_ptr[1], reg_ptr[2], reg_ptr[3], smem_ptr[0]); } else { static_assert(sizeof(T) == 4 || sizeof(T) == 8 || sizeof(T) == 16, "sizeof(T) is not supported"); }}
template <class T>CUTE_HOST_DEVICEvoidcopy_stsm_trans(T const* const rmem_ptr, uint128_t* const smem_ptr){ uint32_t const* reg_ptr = reinterpret_cast<uint32_t const*>(rmem_ptr);
// if constexpr if (sizeof(T) == 4) { SM90_U16x2_STSM_T::copy(reg_ptr[0], smem_ptr[0]); } else if (sizeof(T) == 8) { SM90_U16x4_STSM_T::copy(reg_ptr[0], reg_ptr[1], smem_ptr[0]); } else if (sizeof(T) == 16) { SM90_U16x8_STSM_T::copy(reg_ptr[0], reg_ptr[1], reg_ptr[2], reg_ptr[3], smem_ptr[0]); } else { static_assert(sizeof(T) == 4 || sizeof(T) == 8 || sizeof(T) == 16, "sizeof(T) is not supported"); }}
////////////////////////////////////////////////////////////////////////////////////////////////////
} // end namespace cute
////////////////////////////////////////////////////////////////////////////////////////////////////
#include <cute/arch/copy_sm90_desc.hpp>#include <cute/arch/copy_sm90_tma.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475/*************************************************************************************************** * Copyright (c) 2023 - 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 "cutlass/numeric_types.h"
#if !defined(__CUDACC_RTC__)#include <cuda.h>#include <cinttypes>#endif
#include <cute/config.hpp>
#include <cute/arch/util.hpp> // cute::cast_smem_ptr_to_uint#include <cute/arch/config.hpp> // CUTE_ARCH_TMA_SMxx_ENABLED#include <cute/arch/copy.hpp>#include <cute/arch/copy_sm90.hpp>
#include <cute/container/alignment.hpp>#include <cute/container/bit_field.hpp>#include <cute/container/array.hpp>#include <cute/numeric/numeric_types.hpp>
namespace cute{
///////////////////////////////////////////////////////////////////////////////////////////////////////// Barriers are 64-bit of user-managed information used in broadly two types syncronization patterns/// 1) arrive/wait on threads (usage: cp.async and warp-specialized kernels)/// 2) transaction-based (usage: TMA transaction where a CTA issues one transaction)//////////////////////////////////////////////////////////////////////////////////////////////////////
// Initialize barrier present in shared memoryCUTE_HOST_DEVICEvoidinitialize_barrier(uint64_t& smem_barrier, // 64 bits user-manged barrier in smem int thread_count = 1) // Thread count expected to arrive/wait on this barrier{#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_barrier); asm volatile ("mbarrier.init.shared::cta.b64 [%0], %1;\n" :: "r"(smem_int_ptr), "r"(thread_count));#endif}
// Set the number of bytes transfered per transaction and perform an arrive operation as wellCUTE_HOST_DEVICEvoidset_barrier_transaction_bytes(uint64_t& smem_barrier, // 64 bits user-manged barrier in smem uint32_t bytes) // Number of bytes transfered by per TMA transaction{#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_barrier); asm volatile ("mbarrier.arrive.expect_tx.shared::cta.b64 _, [%0], %1;\n" :: "r"(smem_int_ptr), "r"(bytes));#endif}
// Barrier waitCUTE_HOST_DEVICEvoidwait_barrier(uint64_t& smem_barrier, // 64 bits user-manged barrier in smem int phase_bit) // Current phase bit the barrier waiting to flip{#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_barrier); asm volatile( "{\n" ".reg .pred P1;\n" "LAB_WAIT:\n" "mbarrier.try_wait.parity.shared::cta.b64 P1, [%0], %1;\n" "@P1 bra DONE;\n" "bra LAB_WAIT;\n" "DONE:\n" "}\n" :: "r"(smem_int_ptr), "r"(phase_bit));
#endif}
// Barrier arriveCUTE_HOST_DEVICEvoidarrive_barrier(uint64_t& smem_barrier) // 64 bits user-manged barrier in smem{#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(&smem_barrier); asm volatile( "{\n" ".reg .b64 state; \n" "mbarrier.arrive.shared::cta.b64 state, [%0];\n" "}\n" :: "r"(smem_int_ptr));#endif}
////////////////////////////////////////////////////////////////////////////////////////////////////// TMA Descriptor and utilities////////////////////////////////////////////////////////////////////////////////////////////////////
namespace TMA {
enum class SmemSwizzleBits : uint8_t { DISABLE = 0, B32 = 1, B64 = 2, B128 = 3,};
enum class SmemSwizzleBase : uint8_t { SWIZZLE_BASE_16B = 0, SWIZZLE_BASE_32B = 1, SWIZZLE_BASE_32B_FLIP_8B = 2, SWIZZLE_BASE_64B = 3, };
enum class OOBFill : uint8_t { ZERO = 0, CONSTANT = 1,};
CUTE_HOST_DEVICE char const* to_string(OOBFill const& t) { switch (t) { case OOBFill::ZERO: return "ZERO"; case OOBFill::CONSTANT: return "CONSTANT"; } return nullptr;}
enum class L2Promotion : uint8_t { DISABLE = 0, B64 = 1, B128 = 2, B256 = 3,};
CUTE_HOST_DEVICE char const* to_string(L2Promotion const& t) { switch (t) { case L2Promotion::DISABLE: return "DISABLE"; case L2Promotion::B64: return "B64"; case L2Promotion::B128: return "B128"; case L2Promotion::B256: return "B256"; } return nullptr;}
// Aux parameters which are independent with the problem sizestruct DescriptorAuxParams { OOBFill oobfill_ = OOBFill::ZERO; L2Promotion l2promo_ = L2Promotion::DISABLE;};
enum class CacheHintSm90 : uint64_t { EVICT_NORMAL = 0x1000000000000000, EVICT_FIRST = 0x12F0000000000000, EVICT_LAST = 0x14F0000000000000,};
enum class CacheHintSm100 : uint64_t { EVICT_NORMAL = 0x1000000000000000, EVICT_FIRST = 0x12F0000000000000, EVICT_LAST = 0x14F0000000000000,};
#if (__CUDACC_VER_MAJOR__ >= 12)
#if !defined(__CUDACC_RTC__)/// @return The TMA descriptor datatype enum corresponding to T.template <class T>inline CUtensorMapDataTypeto_CUtensorMapDataType() { if constexpr (is_same_v<T, int8_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT8; } else if constexpr (is_same_v<T, uint8_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT8; } else if constexpr (is_same_v<T, float_e4m3_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT8; } else if constexpr (is_same_v<T, float_e5m2_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT8; } else if constexpr (is_same_v<T, float_ue8m0_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT8; } else if constexpr (is_same_v<T, type_erased_dynamic_float8_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT8;} else if constexpr (is_same_v<T, uint16_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT16; } else if constexpr (is_same_v<T, uint32_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT32; } else if constexpr (is_same_v<T, uint64_t>) { return CU_TENSOR_MAP_DATA_TYPE_UINT64; } else if constexpr (is_same_v<T, int32_t>) { return CU_TENSOR_MAP_DATA_TYPE_INT32; } else if constexpr (is_same_v<T, int64_t>) { return CU_TENSOR_MAP_DATA_TYPE_INT64; } else if constexpr (is_same_v<T, half_t>) { return CU_TENSOR_MAP_DATA_TYPE_FLOAT16; } else if constexpr (is_same_v<T, float>) { return CU_TENSOR_MAP_DATA_TYPE_FLOAT32; } else if constexpr (is_same_v<T, double>) { return CU_TENSOR_MAP_DATA_TYPE_FLOAT64; } else if constexpr (is_same_v<T, bfloat16_t>) { return CU_TENSOR_MAP_DATA_TYPE_BFLOAT16; } else if constexpr (is_same_v<T, tfloat32_t>) { return CU_TENSOR_MAP_DATA_TYPE_TFLOAT32; } else #if ((__CUDACC_VER_MAJOR__ > 12) || ((__CUDACC_VER_MAJOR__ == 12) && (__CUDACC_VER_MINOR__ > 6))) if constexpr (is_same_v<T, float_e2m1_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U4_ALIGN8B; } else if constexpr (is_same_v<T, float_e2m3_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U6_ALIGN16B; } else if constexpr (is_same_v<T, float_e3m2_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U6_ALIGN16B; } else if constexpr (is_same_v<T, type_erased_dynamic_float4_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U4_ALIGN8B; } else if constexpr (is_same_v<T, type_erased_dynamic_float6_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U6_ALIGN16B; } else if constexpr (is_same_v<T, detail::float_e2m1_unpacksmem_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U4_ALIGN16B; } else if constexpr (is_same_v<T, detail::float_e2m3_unpacksmem_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U6_ALIGN16B; } else if constexpr (is_same_v<T, detail::float_e3m2_unpacksmem_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U6_ALIGN16B; } else if constexpr (is_same_v<T, detail::type_erased_dynamic_float4_unpacksmem_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U4_ALIGN16B; } else if constexpr (is_same_v<T, detail::type_erased_dynamic_float6_unpacksmem_t>) { return CU_TENSOR_MAP_DATA_TYPE_16U6_ALIGN16B; } else #endif
{ static_assert(sizeof(T) < 0, "Unknown TMA Format!"); }}
inline CUtensorMapSwizzleto_CUtensorMapSwizzle(SmemSwizzleBits const& t, SmemSwizzleBase const& b) { switch (t) { default: assert(false && "Unsupported pair of SmemSwizzleBits and SmemSwizzleBase!"); case SmemSwizzleBits::DISABLE: assert((b == SmemSwizzleBase::SWIZZLE_BASE_16B) && "Expected 16B swizzle base for 0B swizzle bits."); return CU_TENSOR_MAP_SWIZZLE_NONE; case SmemSwizzleBits::B32: assert((b == SmemSwizzleBase::SWIZZLE_BASE_16B) && "Expected 16B swizzle base for 32B swizzle bits."); return CU_TENSOR_MAP_SWIZZLE_32B; case SmemSwizzleBits::B64: assert((b == SmemSwizzleBase::SWIZZLE_BASE_16B) && "Expected 16B swizzle base for 64B swizzle bits."); return CU_TENSOR_MAP_SWIZZLE_64B; case SmemSwizzleBits::B128: switch (b) { default: assert(false && "Unsupported pair of SmemSwizzleBits and SmemSwizzleBase!"); case SmemSwizzleBase::SWIZZLE_BASE_16B: return CU_TENSOR_MAP_SWIZZLE_128B; #if ((__CUDACC_VER_MAJOR__ > 12) || ((__CUDACC_VER_MAJOR__ == 12) && (__CUDACC_VER_MINOR__ > 6))) case SmemSwizzleBase::SWIZZLE_BASE_32B: return CU_TENSOR_MAP_SWIZZLE_128B_ATOM_32B; case SmemSwizzleBase::SWIZZLE_BASE_64B: return CU_TENSOR_MAP_SWIZZLE_128B_ATOM_64B; #endif } }}
inline CUtensorMapFloatOOBfillto_CUtensorMapFloatOOBfill(OOBFill const& t) { switch(t) { default: assert(false && "Unknown OOBFill!"); case OOBFill::ZERO: return CU_TENSOR_MAP_FLOAT_OOB_FILL_NONE; case OOBFill::CONSTANT: return CU_TENSOR_MAP_FLOAT_OOB_FILL_NAN_REQUEST_ZERO_FMA; }}
inline CUtensorMapL2promotionto_CUtensorMapL2promotion(L2Promotion const& t) { switch(t) { default: assert(false && "Unknown L2Promotion!"); case L2Promotion::DISABLE: return CU_TENSOR_MAP_L2_PROMOTION_NONE; case L2Promotion::B64: return CU_TENSOR_MAP_L2_PROMOTION_L2_64B; case L2Promotion::B128: return CU_TENSOR_MAP_L2_PROMOTION_L2_128B; case L2Promotion::B256: return CU_TENSOR_MAP_L2_PROMOTION_L2_256B; }}
#endif // !defined(__CUDACC_RTC__)
#endif // (__CUDACC_VER_MAJOR__ >= 12)
} // end namespace TMA
#if (__CUDACC_VER_MAJOR__ >= 12) && !defined(__CUDACC_RTC__) using TmaDescriptor = CUtensorMap; using Im2ColTmaDescriptor = CUtensorMap;#else using TmaDescriptor = struct alignas(64) { char bytes[128]; }; using Im2ColTmaDescriptor = struct alignas(64) { char bytes[128]; };#endif/////////////////////////////////////////////////////////////////////////////////////////////////////// Initiates a TensorMap Prefetch////////////////////////////////////////////////////////////////////////////////////////////////////
CUTE_HOST_DEVICEvoidprefetch_tma_descriptor(TmaDescriptor const* desc_ptr){#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); // Prefetch TMA Descriptor using generic addressing (i.e. no specific state space: const or param) asm volatile ( "prefetch.tensormap [%0];" : : "l"(gmem_int_desc) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use TMA Descriptor Prefetch without CUTE_ARCH_TMA_SM90_ENABLED.");#endif}
/////////////////////////////////////////////////////////////////////////////////////////////////////// Perform a TensorMap modification (by each field)////////////////////////////////////////////////////////////////////////////////////////////////////
// Replace tensor pointer directly in GMEMCUTE_HOST_DEVICEvoidtma_descriptor_replace_addr_in_global_mem(TmaDescriptor const* desc_ptr, void const* const new_tensor_ptr){#if defined(CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint64_t const new_desc_addr = reinterpret_cast<uint64_t>(new_tensor_ptr); asm volatile ( "tensormap.replace.tile.global_address.global.b1024.b64 [%0], %1;" :: "l"(gmem_int_desc), "l"(new_desc_addr));#else CUTE_INVALID_CONTROL_PATH("Using TMA Descriptor modification without CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED and CUDA 12.3");#endif}
// Replace tensor pointer by bringing the tensormap from GMEM into the shared memoryCUTE_HOST_DEVICEvoidtma_descriptor_replace_addr_in_shared_mem(TmaDescriptor& smem_desc, void const* const new_tensor_ptr){#if defined(CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED) uint32_t smem_int_desc = cast_smem_ptr_to_uint(&smem_desc); uint64_t const new_desc_addr = reinterpret_cast<uint64_t>(new_tensor_ptr); asm volatile ( "tensormap.replace.tile.global_address.shared::cta.b1024.b64 [%0], %1;" :: "r"(smem_int_desc), "l"(new_desc_addr));#else CUTE_INVALID_CONTROL_PATH("Using TMA Descriptor modification without CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED and CUDA 12.3");#endif}
// Replace tensor dims and strides for GEMMs by bringing the tensormap from GMEM into the shared memoryCUTE_HOST_DEVICEvoidtma_descriptor_replace_dims_strides_in_shared_mem(TmaDescriptor & smem_desc, cute::array<uint32_t, 5> const& prob_shape, cute::array<uint64_t, 5> const& prob_stride){#if defined(CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED) uint32_t smem_int_desc = cast_smem_ptr_to_uint(&smem_desc); uint64_t const smem_int64_desc = 0; asm volatile ( "cvt.u64.u32 %0, %1;" :: "l"(smem_int64_desc), "r"(smem_int_desc)); asm volatile ( "tensormap.replace.tile.global_dim.shared::cta.b1024.b32 [%0], 0, %1;" :: "l"(smem_int64_desc), "r"(prob_shape[0])); asm volatile ( "tensormap.replace.tile.global_dim.shared::cta.b1024.b32 [%0], 1, %1;" :: "l"(smem_int64_desc), "r"(prob_shape[1])); asm volatile ( "tensormap.replace.tile.global_dim.shared::cta.b1024.b32 [%0], 2, %1;" :: "l"(smem_int64_desc), "r"(prob_shape[2])); asm volatile ( "tensormap.replace.tile.global_dim.shared::cta.b1024.b32 [%0], 3, %1;" :: "l"(smem_int64_desc), "r"(prob_shape[3])); asm volatile ( "tensormap.replace.tile.global_dim.shared::cta.b1024.b32 [%0], 4, %1;" :: "l"(smem_int64_desc), "r"(prob_shape[4])); // Strides must be a multiple of 16. Also, stride for the intermost dimension is implicitly 1 #if ((__CUDACC_VER_MAJOR__ > 12) || ((__CUDACC_VER_MAJOR__ == 12) && (__CUDACC_VER_MINOR__ >= 5))) asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 0, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[1])); asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 1, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[2])); asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 2, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[3])); asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 3, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[4])); #else // 4 LSBs are not included asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 0, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[1] >> 4)); asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 1, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[2] >> 4)); asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 2, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[3] >> 4)); asm volatile ( "tensormap.replace.tile.global_stride.shared::cta.b1024.b64 [%0], 3, %1;" :: "l"(smem_int64_desc), "l"(prob_stride[4] >> 4)); #endif#else CUTE_INVALID_CONTROL_PATH("Using TMA Descriptor modification without CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED and CUDA 12.3");#endif}
/////////////////////////////////////////////////////////////////////////////////////////////////////// Perform a fused copy and fence operation (needed when modifying tensormap in shared memory)////////////////////////////////////////////////////////////////////////////////////////////////////
CUTE_HOST_DEVICEvoidtma_descriptor_cp_fence_release(TmaDescriptor const* gmem_desc_ptr, TmaDescriptor& smem_desc){#if defined(CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(gmem_desc_ptr); uint32_t smem_int_desc = cast_smem_ptr_to_uint(&smem_desc); asm volatile ( "tensormap.cp_fenceproxy.global.shared::cta.tensormap::generic.release.gpu.sync.aligned [%0], [%1], 128;" :: "l"(gmem_int_desc), "r"(smem_int_desc));#else CUTE_INVALID_CONTROL_PATH("Using TMA Descriptor modification without CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED and CUDA 12.3");#endif}
/////////////////////////////////////////////////////////////////////////////////////////////////////// Perform a release fence operation (needed when modifying tensormap directly in GMEM)////////////////////////////////////////////////////////////////////////////////////////////////////
CUTE_HOST_DEVICEvoidtma_descriptor_fence_release(){#if defined(CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED) asm volatile ("fence.proxy.tensormap::generic.release.gpu;");#else CUTE_INVALID_CONTROL_PATH("Using TMA Descriptor modification without CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED and CUDA 12.3");#endif}
/////////////////////////////////////////////////////////////////////////////////////////////////////// Perform a acquire fence operation////////////////////////////////////////////////////////////////////////////////////////////////////
CUTE_HOST_DEVICEvoidtma_descriptor_fence_acquire(TmaDescriptor const* desc_ptr){#if defined(CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "fence.proxy.tensormap::generic.acquire.gpu [%0], 128;" : : "l"(gmem_int_desc) : "memory");#else CUTE_INVALID_CONTROL_PATH("Using TMA Descriptor modification without CUTE_ARCH_DEVICE_MODIFIABLE_TMA_SM90_ENABLED and CUDA 12.3");#endif}
///////////////////////////////////////////////////////////////////////////////
} // end namespace cute12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/config.hpp> // CUTE_ARCH_TMA_SMxx_ENABLED#include <cute/arch/copy.hpp>#include <cute/arch/copy_sm90.hpp>#include "cutlass/arch/synclog.hpp"
namespace cute{
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD : Initiates a TMA copy from global memory to shared memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_LOAD_1D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr);#if defined(CUTE_ARCH_TMA_SM120_ENABLED) asm volatile ( "cp.async.bulk.tensor.1d.shared::cta.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3}], [%2], %4;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "l"(cache_hint) : "memory");#else asm volatile ( "cp.async.bulk.tensor.1d.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3}], [%2], %4;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "l"(cache_hint) : "memory");#endif#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.1d.L2.global" " [%0, {%1}];" : : "l"(gmem_int_desc), "r"(crd0) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_2D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr);#if defined(CUTE_ARCH_TMA_SM120_ENABLED) asm volatile ( "cp.async.bulk.tensor.2d.shared::cta.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4}], [%2], %5;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "l"(cache_hint) : "memory");#else asm volatile ( "cp.async.bulk.tensor.2d.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4}], [%2], %5;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "l"(cache_hint) : "memory");#endif#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.2d.L2.global" " [%0, {%1, %2}];" : : "l"(gmem_int_desc), "r"(crd0), "r"(crd1) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr);#if defined(CUTE_ARCH_TMA_SM120_ENABLED) asm volatile ( "cp.async.bulk.tensor.3d.shared::cta.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5}], [%2], %6;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "l"(cache_hint) : "memory");#else asm volatile ( "cp.async.bulk.tensor.3d.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5}], [%2], %6;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "l"(cache_hint) : "memory");#endif#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.3d.L2.global" " [%0, {%1, %2, %3}];" : : "l"(gmem_int_desc), "r"(crd0), "r"(crd1), "r"(crd2) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr);#if defined(CUTE_ARCH_TMA_SM120_ENABLED) asm volatile ( "cp.async.bulk.tensor.4d.shared::cta.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6}], [%2], %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "l"(cache_hint) : "memory");#else asm volatile ( "cp.async.bulk.tensor.4d.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6}], [%2], %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "l"(cache_hint) : "memory");#endif#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.4d.L2.global" " [%0, {%1, %2, %3, %4}];" : : "l"(gmem_int_desc), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr);#if defined(CUTE_ARCH_TMA_SM120_ENABLED) asm volatile ( "cp.async.bulk.tensor.5d.shared::cta.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], %8;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4), "l"(cache_hint) : "memory");#else asm volatile ( "cp.async.bulk.tensor.5d.shared::cluster.global.mbarrier::complete_tx::bytes.L2::cache_hint" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], %8;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4), "l"(cache_hint) : "memory");#endif#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.5d.L2.global" " [%0, {%1, %2, %3, %4, %5}];" : : "l"(gmem_int_desc), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) { return SM90_TMA_LOAD_1D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) { return SM90_TMA_LOAD_2D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM90_TMA_LOAD_3D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM90_TMA_LOAD_4D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM90_TMA_LOAD_5D::copy(desc_ptr, mbar_ptr, cache_hint, smem_ptr, crd0, crd1, crd2, crd3, crd4); }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0) { return SM90_TMA_LOAD_1D::PREFETCH::copy(desc_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1) { return SM90_TMA_LOAD_2D::PREFETCH::copy(desc_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM90_TMA_LOAD_3D::PREFETCH::copy(desc_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM90_TMA_LOAD_4D::PREFETCH::copy(desc_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM90_TMA_LOAD_5D::PREFETCH::copy(desc_ptr, crd0, crd1, crd2, crd3, crd4); } };};
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD im2col: Initiates a TMA copy, in im2col mode, from global memory to shared memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_LOAD_IM2COL_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); // Copy from global to shared::cluster. asm volatile ( "cp.async.bulk.tensor.3d.shared::cluster.global.im2col.mbarrier::complete_tx::bytes" " [%0], [%1, {%3, %4, %5}], [%2], {%6};" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_n), "h"(offset_w) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.3d.L2.global.im2col" " [%0, {%1, %2, %3}], {%4};" : : "l"(gmem_int_desc), "r"(coord_c), "r"(coord_w), "r"(coord_n), "h"(offset_w) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_IM2COL_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); // Copy from global to shared::cluster. asm volatile ( "cp.async.bulk.tensor.4d.shared::cluster.global.im2col.mbarrier::complete_tx::bytes" " [%0], [%1, {%3, %4, %5, %6}], [%2], {%7, %8};" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w), "h"(offset_h) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.4d.L2.global.im2col" " [%0, {%1, %2, %3, %4}], {%5, %6};" : : "l"(gmem_int_desc), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w), "h"(offset_h) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_IM2COL_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); // Copy from global to shared::cluster. asm volatile ( "cp.async.bulk.tensor.5d.shared::cluster.global.im2col.mbarrier::complete_tx::bytes" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], {%8, %9, %10};" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_d), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(offset_d) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); asm volatile ( "cp.async.bulk.prefetch.tensor.5d.L2.global.im2col" " [%0, {%1, %2, %3, %4, %5}], {%6, %7, %8};" : : "l"(gmem_int_desc), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_d), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(offset_d) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_TMA_LOAD_IM2COL{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) { return SM90_TMA_LOAD_IM2COL_3D::copy(desc_ptr, mbar_ptr, smem_ptr, coord_c, coord_w, coord_n, offset_w); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) { return SM90_TMA_LOAD_IM2COL_4D::copy(desc_ptr, mbar_ptr, smem_ptr, coord_c, coord_w, coord_h, coord_n, offset_w, offset_h); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) { return SM90_TMA_LOAD_IM2COL_5D::copy(desc_ptr, mbar_ptr, smem_ptr, coord_c, coord_w, coord_h, coord_d, coord_n, offset_w, offset_h, offset_d); }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) { return SM90_TMA_LOAD_IM2COL_3D::PREFETCH::copy(desc_ptr, coord_c, coord_w, coord_n, offset_w); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) { return SM90_TMA_LOAD_IM2COL_4D::PREFETCH::copy(desc_ptr, coord_c, coord_w, coord_h, coord_n, offset_w, offset_h); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) { return SM90_TMA_LOAD_IM2COL_5D::PREFETCH::copy(desc_ptr, coord_c, coord_w, coord_h, coord_d, coord_n, offset_w, offset_h, offset_d); } };};
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD_MULTICAST: Initiates a TMA copy from global memory to shared memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_LOAD_MULTICAST_1D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.1d.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4}], [%2], %3, %5;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_MULTICAST_2D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.2d.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5}], [%2], %3, %6;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_MULTICAST_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.3d.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5, %6}], [%2], %3, %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "r"(crd2), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_MULTICAST_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.4d.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5, %6, %7}], [%2], %3, %8;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_MULTICAST_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.5d.shared::cluster.global.mbarrier::complete_tx::bytes.multicast::cluster.L2::cache_hint" " [%0], [%1, {%4, %5, %6, %7, %8}], [%2], %3, %9;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "h"(multicast_mask), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4), "l"(cache_hint) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_MULTICAST{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0) { return SM90_TMA_LOAD_MULTICAST_1D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1) { return SM90_TMA_LOAD_MULTICAST_2D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM90_TMA_LOAD_MULTICAST_3D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM90_TMA_LOAD_MULTICAST_4D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, uint64_t cache_hint, void * smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM90_TMA_LOAD_MULTICAST_5D::copy(desc_ptr, mbar_ptr, multicast_mask, cache_hint, smem_ptr, crd0, crd1, crd2, crd3, crd4); }
using PREFETCH = typename SM90_TMA_LOAD::PREFETCH;};
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD_MULTICAST im2col: Initiates a TMA copy, in im2col mode, from global memory to shared memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_LOAD_IM2COL_MULTICAST_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); // Copy from global to shared::cluster. asm volatile ( "cp.async.bulk.tensor.3d.shared::cluster.global.im2col.mbarrier::complete_tx::bytes.multicast::cluster" " [%0], [%1, {%3, %4, %5}], [%2], {%6}, %7;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_n), "h"(offset_w), "h"(multicast_mask) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_IM2COL_MULTICAST_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); // Copy from global to shared::cluster. asm volatile ( "cp.async.bulk.tensor.4d.shared::cluster.global.im2col.mbarrier::complete_tx::bytes.multicast::cluster" " [%0], [%1, {%3, %4, %5, %6}], [%2], {%7, %8}, %9;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(multicast_mask) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_IM2COL_MULTICAST_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED)#if defined(CUTE_ARCH_TMA_SM120_ENABLED) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_load(__LINE__, gmem_int_desc, smem_int_mbar, smem_int_ptr); // Copy from global to shared::cluster. asm volatile ( "cp.async.bulk.tensor.5d.shared::cluster.global.im2col.mbarrier::complete_tx::bytes.multicast::cluster" " [%0], [%1, {%3, %4, %5, %6, %7}], [%2], {%8, %9, %10}, %11;" : : "r"(smem_int_ptr), "l"(gmem_int_desc), "r"(smem_int_mbar), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_d), "r"(coord_n), "h"(offset_w), "h"(offset_h), "h"(offset_d), "h"(multicast_mask) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_LOAD_IM2COL_MULTICAST{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n, uint16_t const& offset_w) { return SM90_TMA_LOAD_IM2COL_MULTICAST_3D::copy(desc_ptr, mbar_ptr, multicast_mask, smem_ptr, coord_c, coord_w, coord_n, offset_w); }
CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h) { return SM90_TMA_LOAD_IM2COL_MULTICAST_4D::copy(desc_ptr, mbar_ptr, multicast_mask, smem_ptr, coord_c, coord_w, coord_h, coord_n, offset_w, offset_h); }
CUTE_HOST_DEVICE static void copy(void const* desc_ptr, uint64_t* mbar_ptr, uint16_t multicast_mask, void * smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n, uint16_t const& offset_w, uint16_t const& offset_h, uint16_t const& offset_d) { return SM90_TMA_LOAD_IM2COL_MULTICAST_5D::copy(desc_ptr, mbar_ptr, multicast_mask, smem_ptr, coord_c, coord_w, coord_h, coord_d, coord_n, offset_w, offset_h, offset_d); }
using PREFETCH = typename SM90_TMA_LOAD_IM2COL::PREFETCH;};
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_STORE : Initiates a TMA copy from shared memory to global memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_STORE_1D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.1d.global.shared::cta.bulk_group [%0, {%2}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_2D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.2d.global.shared::cta.bulk_group [%0, {%2, %3}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.3d.global.shared::cta.bulk_group [%0, {%2, %3, %4}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1), "r"(crd2) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.4d.global.shared::cta.bulk_group [%0, {%2, %3, %4, %5}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.5d.global.shared::cta.bulk_group [%0, {%2, %3, %4, %5, %6}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0) { return SM90_TMA_STORE_1D::copy(desc_ptr, smem_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1) { return SM90_TMA_STORE_2D::copy(desc_ptr, smem_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM90_TMA_STORE_3D::copy(desc_ptr, smem_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM90_TMA_STORE_4D::copy(desc_ptr, smem_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM90_TMA_STORE_5D::copy(desc_ptr, smem_ptr, crd0, crd1, crd2, crd3, crd4); }};
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_STORE im2col: Initiates a TMA copy, in im2col mode, from shared memory to global memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_STORE_IM2COL_3D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.3d.global.shared::cta.im2col_no_offs.bulk_group" " [%0, {%2, %3, %4}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(coord_c), "r"(coord_w), "r"(coord_n) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_IM2COL_4D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.4d.global.shared::cta.im2col_no_offs.bulk_group" " [%0, {%2, %3, %4, %5}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_n) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_IM2COL_5D{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.async.bulk.tensor.5d.global.shared::cta.im2col_no_offs.bulk_group" " [%0, {%2, %3, %4, %5, %6}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(coord_c), "r"(coord_w), "r"(coord_h), "r"(coord_d), "r"(coord_n) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_STORE_IM2COL{ CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_n) { return SM90_TMA_STORE_IM2COL_3D::copy(desc_ptr, smem_ptr, coord_c, coord_w, coord_n); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_n) { return SM90_TMA_STORE_IM2COL_4D::copy(desc_ptr, smem_ptr, coord_c, coord_w, coord_h, coord_n); } CUTE_HOST_DEVICE static void copy(void const* desc_ptr, void const* smem_ptr, int32_t const& coord_c, int32_t const& coord_w, int32_t const& coord_h, int32_t const& coord_d, int32_t const& coord_n) { return SM90_TMA_STORE_IM2COL_5D::copy(desc_ptr, smem_ptr, coord_c, coord_w, coord_h, coord_d, coord_n); }};
// Fence for smem stores for subsequent TMA_STORECUTE_HOST_DEVICE static voidtma_store_fence() {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) cutlass::arch::synclog_emit_fence_view_async_shared(__LINE__); asm volatile ("fence.proxy.async.shared::cta;");#elif defined(__CUDA_ARCH__) CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif}
// Indicate arrival of warp issuing TMA_STORECUTE_HOST_DEVICE static voidtma_store_arrive() {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) cutlass::arch::synclog_emit_tma_store_arrive(__LINE__); asm volatile("cp.async.bulk.commit_group;");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif}
CUTE_HOST_DEVICE static voidtma_desc_commit_group() {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) asm volatile("cp.async.bulk.commit_group;");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif}
// Wait until at most Count committed TMA_STOREs are pending and all prior commits are completetemplate <int Count>CUTE_HOST_DEVICE static voidtma_store_wait() {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) asm volatile( "cp.async.bulk.wait_group.read %0;" : : "n"(Count) : "memory"); cutlass::arch::synclog_emit_tma_store_wait(__LINE__, Count);#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif}
// Wait until all TMA descriptor previously issued are safe to be modified after tma_desc_commit_group()CUTE_HOST_DEVICE static voidtma_desc_wait_group() {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) asm volatile( "cp.async.bulk.wait_group.read %0;" : : "n"(0) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif}
/////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_REDUCE_ADD : Initiates a TMA reduce-add from shared memory to global memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_TMA_REDUCE_ADD_1D{ CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.reduce.async.bulk.tensor.1d.global.shared::cta.add.bulk_group [%0, {%2}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_REDUCE_ADD_2D{ CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.reduce.async.bulk.tensor.2d.global.shared::cta.add.bulk_group [%0, {%2, %3}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_REDUCE_ADD_3D{ CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.reduce.async.bulk.tensor.3d.global.shared::cta.add.bulk_group [%0, {%2, %3, %4}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1), "r"(crd2) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_REDUCE_ADD_4D{ CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.reduce.async.bulk.tensor.4d.global.shared::cta.add.bulk_group [%0, {%2, %3, %4, %5}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_REDUCE_ADD_5D{ CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint64_t gmem_int_desc = reinterpret_cast<uint64_t>(desc_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); cutlass::arch::synclog_emit_tma_store(__LINE__, gmem_int_desc, smem_int_ptr); asm volatile ( "cp.reduce.async.bulk.tensor.5d.global.shared::cta.add.bulk_group [%0, {%2, %3, %4, %5, %6}], [%1];" : : "l"(gmem_int_desc), "r"(smem_int_ptr), "r"(crd0), "r"(crd1), "r"(crd2), "r"(crd3), "r"(crd4) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use tma without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_TMA_REDUCE_ADD{ CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0) { return SM90_TMA_REDUCE_ADD_1D::copy(desc_ptr, smem_ptr, crd0); } CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1) { return SM90_TMA_REDUCE_ADD_2D::copy(desc_ptr, smem_ptr, crd0, crd1); } CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2) { return SM90_TMA_REDUCE_ADD_3D::copy(desc_ptr, smem_ptr, crd0, crd1, crd2); } CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3) { return SM90_TMA_REDUCE_ADD_4D::copy(desc_ptr, smem_ptr, crd0, crd1, crd2, crd3); } CUTE_HOST_DEVICE static void copy(void const* const desc_ptr, void const* const smem_ptr, int32_t const& crd0, int32_t const& crd1, int32_t const& crd2, int32_t const& crd3, int32_t const& crd4) { return SM90_TMA_REDUCE_ADD_5D::copy(desc_ptr, smem_ptr, crd0, crd1, crd2, crd3, crd4); }};
/////////////////////////////////////////////////////////////////////////////////////////////////////// BULK_COPY : Copy a bulk of memory between shared memory and global memory////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM90_BULK_COPY_G2S{ CUTE_HOST_DEVICE static void copy(void const* gmem_ptr, uint64_t* mbar_ptr, void * smem_ptr, int32_t load_bytes) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint32_t smem_int_mbar = cast_smem_ptr_to_uint(mbar_ptr); uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile("cp.async.bulk.shared::cluster.global.mbarrier::complete_tx::bytes [%0], [%1], %2, [%3];\n" : : "r"(smem_int_ptr), "l"(gmem_ptr), "r"(load_bytes), "r"(smem_int_mbar) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use BULK_COPY without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }
struct PREFETCH { CUTE_HOST_DEVICE static void copy(void const* gmem_ptr, int32_t load_bytes) { #if defined(CUTE_ARCH_TMA_SM90_ENABLED) asm volatile("cp.async.bulk.prefetch.L2.global [%0], %1;\n" : : "l"(gmem_ptr), "r"(load_bytes) : "memory"); #else CUTE_INVALID_CONTROL_PATH("Trying to use BULK_COPY without CUTE_ARCH_TMA_SM90_ENABLED."); #endif } };};
struct SM90_BULK_COPY_S2G{ CUTE_HOST_DEVICE static void copy(void const* smem_ptr, void * gmem_ptr, int32_t store_bytes) {#if defined(CUTE_ARCH_TMA_SM90_ENABLED) uint32_t smem_int_ptr = cast_smem_ptr_to_uint(smem_ptr); asm volatile("cp.async.bulk.global.shared::cta.bulk_group [%0], [%1], %2;\n" : : "l"(gmem_ptr), "r"(smem_int_ptr), "r"(store_bytes) : "memory");#else CUTE_INVALID_CONTROL_PATH("Trying to use BULK_COPY without CUTE_ARCH_TMA_SM90_ENABLED.");#endif }};
struct SM90_BULK_COPY_AUTO {};
////////////////////////////////////////////////////////////////////////////////////////////////////
} // end namespace cute12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/numeric/complex.hpp> // cute::fma#include <cute/numeric/real.hpp> // cute::fma
namespace cute{
//// Direct FMA for any type//
template <class D, class A = D, class B = A, class C = D>struct UniversalFMA{ using DRegisters = D[1]; using ARegisters = A[1]; using BRegisters = B[1]; using CRegisters = C[1];
CUTE_HOST_DEVICE static constexpr void fma(D & d, A const& a, B const& b, C const& c) { // Forward to an ADL/cute free function for these types using cute::fma; fma(d, a, b, c); }};
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/arch/mma.hpp>
namespace cute {
} // namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651/*************************************************************************************************** * Copyright (c) 2023 - 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
#if !defined(__CUDACC_RTC__)#include <cinttypes>#endif
#include <cute/arch/config.hpp>
#include <cute/arch/mma.hpp>
#include <cute/container/bit_field.hpp>#include <cute/container/array.hpp> // cute::array
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace cute {
////////////////////////////////////////////////////////////////////////////////////////////////////// UMMA Descriptor and utilities
// UMMA enums and utilitiesnamespace UMMA{
enum class Major : uint8_t { K = 0, MN = 1};
enum class ScaleIn : uint8_t { One = 0, Neg = 1};
enum class ScaleOut : uint8_t { Zero = 0, One = 1};
enum class Saturate : uint8_t { False = 0, True = 1};
enum class LayoutType : uint8_t { SWIZZLE_NONE = 0, SWIZZLE_128B_BASE32B = 1, SWIZZLE_128B = 2, SWIZZLE_64B = 4, SWIZZLE_32B = 6};
CUTE_HOST_DEVICE char const* to_string(LayoutType const& t) { switch (t) { case LayoutType::SWIZZLE_NONE: return "SWIZZLE_NONE"; case LayoutType::SWIZZLE_128B_BASE32B: return "SWIZZLE_128B_BASE32B"; case LayoutType::SWIZZLE_128B: return "SWIZZLE_128B"; case LayoutType::SWIZZLE_64B: return "SWIZZLE_64B"; case LayoutType::SWIZZLE_32B: return "SWIZZLE_32B"; } return nullptr;}
union SmemDescriptor{ uint64_t desc_ = 0; // Bitfield implementation avoids the need for shifts in assignment struct { // start_address, bit [0,14), 4LSB not included uint16_t start_address_ : 14, : 2; // 14 bits [0,14), 2 bits unused // leading dimension byte offset, bit [16,30), 4LSB not included uint16_t leading_byte_offset_ : 14, : 2; // 14 bits [0,14), 2 bits unused // stride dimension byte offset, bit [32,46), 4LSB not included uint16_t stride_byte_offset_ : 14, version_ : 2; // 14 bits [0,14), 2 bits [14,16) // base_offset, bit [49,52). leading_byte_offset_mode, bit [52,53). uint8_t : 1, base_offset_ : 3, lbo_mode_ : 1, : 3; // 1 bit unused, 3 bits [1,4), 1 bit [4,5), 3 bits unused // layout type, bit [61,64), SWIZZLE_NONE matrix descriptor = 0, SWIZZLE_128B matrix descriptor = 2, SWIZZLE_64B descriptor = 4, SWIZZLE_32B descriptor = 6, SWIZZLE_128B_BASE32B = 1, N/A = 3, N/A = 5, N/A = 7 uint8_t : 5, layout_type_ : 3; // 6 bits unused, 3 bits [5,8) }; // Seperate the field, as we may only update one part of desc struct { uint32_t lo; uint32_t hi; };
// Decay to a uint64_t CUTE_HOST_DEVICE constexpr operator uint64_t() const noexcept { return desc_; }};
enum class F16F32Format : uint8_t { F16 = 0, BF16 = 1, TF32 = 2,};
CUTE_HOST_DEVICE char const* to_string(F16F32Format const& t) { switch (t) { case F16F32Format::F16: return "F16"; case F16F32Format::BF16: return "BF16"; case F16F32Format::TF32: return "TF32"; } return nullptr;}
template <class T>CUTE_HOST_DEVICE constexpr F16F32Format to_F16F32Format() { if constexpr (is_same_v<T, half_t>) { return F16F32Format::F16; } else if constexpr (is_same_v<T, bfloat16_t>) { return F16F32Format::BF16; } else if constexpr (is_same_v<T, tfloat32_t>) { return F16F32Format::TF32; } else { static_assert(sizeof(T) == 0, "Unknown type for F16F32Format"); }}
enum class S8Format : uint8_t { UINT8 = 0, INT8 = 1,};
CUTE_HOST_DEVICE char const* to_string(S8Format const& t) { switch (t) { case S8Format::UINT8: return "UINT8"; case S8Format::INT8: return "INT8"; } return nullptr;}
template <class T>CUTE_HOST_DEVICE constexpr S8Format to_S8Format() { if constexpr (is_same_v<T, uint8_t>) { return S8Format::UINT8; } else if constexpr (is_same_v<T, int8_t>) { return S8Format::INT8; } else { static_assert(sizeof(T) == 0, "Unknown type for S8Format"); }}
enum class MXF8F6F4Format : uint8_t { E4M3 = 0, E5M2 = 1, E2M3 = 3, E3M2 = 4, E2M1 = 5, INVALID = 7 // an invalid datatype for runtime proxy type};
CUTE_HOST_DEVICE char const* to_string(MXF8F6F4Format const& t) { switch (t) { case MXF8F6F4Format::E4M3: return "E4M3"; case MXF8F6F4Format::E5M2: return "E5M2"; case MXF8F6F4Format::E2M3: return "E2M3"; case MXF8F6F4Format::E3M2: return "E3M2"; case MXF8F6F4Format::E2M1: return "E2M1"; case MXF8F6F4Format::INVALID: return "INVALID"; } return nullptr;}
template <class T>CUTE_HOST_DEVICE constexpr MXF8F6F4Format to_MXF8F6F4Format() { if constexpr (is_same_v<T, float_e4m3_t>) { return MXF8F6F4Format::E4M3; } else if constexpr (is_same_v<T, float_e5m2_t>) { return MXF8F6F4Format::E5M2; } else if constexpr (is_same_v<T, detail::float_e2m3_unpacksmem_t>) { return MXF8F6F4Format::E2M3; } else if constexpr (is_same_v<T, detail::float_e3m2_unpacksmem_t>) { return MXF8F6F4Format::E3M2; } else if constexpr (is_same_v<T, detail::float_e2m1_unpacksmem_t>) { return MXF8F6F4Format::E2M1; } else { static_assert(sizeof(T) == 0, "Unknown type for MXF8F6F4Format"); }}
enum class MXF4Format : uint8_t { E2M1 = 1,};
CUTE_HOST_DEVICE char const* to_string(MXF4Format const& t) { switch (t) { case MXF4Format::E2M1: return "E2M1"; } return nullptr;}
template <class T>CUTE_HOST_DEVICE constexpr MXF4Format to_MXF4Format() { if constexpr (is_same_v<T, float_e2m1_t>) { return MXF4Format::E2M1; } else { static_assert(sizeof(T) == 0, "Unknown type for MXF4Format"); }}
enum class ScaleFormat : uint8_t { UE4M3 = 0, UE8M0 = 1,};
CUTE_HOST_DEVICE char const* to_string(ScaleFormat const& t) { switch (t) { case ScaleFormat::UE4M3: return "UE4M3"; case ScaleFormat::UE8M0: return "UE8M0"; } return nullptr;}
template <class T>CUTE_HOST_DEVICE constexpr ScaleFormat to_ScaleFormat() { if constexpr (is_same_v<T, float_ue4m3_t>) { return ScaleFormat::UE4M3; } else if constexpr (is_same_v<T, float_ue8m0_t>) { return ScaleFormat::UE8M0; } else { static_assert(sizeof(T) == 0, "Unknown type for ScaleFormat"); }}
enum class CFormat : uint8_t { F16 = 0, F32 = 1, S32 = 2,};
CUTE_HOST_DEVICE char const* to_string(CFormat const& t) { switch (t) { case CFormat::F16: return "F16"; case CFormat::F32: return "F32"; case CFormat::S32: return "S32"; } return nullptr;}
enum class MaxShift : uint8_t { NoShift = 0, MaxShift8 = 1, MaxShift16 = 2, MaxShift32 = 3};
enum class BMatrixBufferId : uint8_t { Zero = 0u, One = 1u, Two = 2u, Three = 3u};
enum class BMatrixBufferReuse : uint8_t { Keep = 1u, Reuse = 2u, ReuseAndKeep = 3u};
// using MaskAndShiftB = uint32_t[2];union MaskAndShiftB{ uint32_t uri[2];
struct { // Bitfield implementation avoids the need for shifts in assignment uint8_t start_count_ [4]; // bit [ 0:32) : 8 bits each. Specifies the start count for mask generation. uint32_t first_span_ : 4, // bit [32:36) : 1 bit each. 0 = start where B is used. 1 = start with where B is skipped(0 value is used). : 3, // nzm_ : 1, // bit [39:40) : 0 = Enable the mask. 1 = Disable the mask. skip_span_ : 8, // bit [40:48) : Count-1 (zero encoded in this field specifies use span of 1) of consecutive columns where 0 value is used. use_span_ : 8, // bit [48:55) : Count-1 (zero encoded in this field specifies use span of 1) of consecutive columns where B matrix data is used. shift_ : 6, // bit [56:62) : Shift value for B matrix data. : 2; };};
template <typename ShapeType, int FLT_S, int CTA_M, int CTA_N>CUTE_HOST_DEVICE constexpr automake_column_zero_mask(ShapeType conv_q, int32_t cta_coord_q, int32_t num_pixels_skip_left) {
static_assert(cute::is_same_v<ShapeType, cutlass::FastDivmod> || cute::is_integral<ShapeType>::value);
cute::array<MaskAndShiftB, FLT_S> column_zero_masks{};
static_assert(FLT_S == 3, "Filter size not supported."); constexpr int MAX_USE_SPAN_COUNT = 256; constexpr int MAX_SKIP_SPAN_COUNT = 256;
// conv_q_int used for non-divmod case (add/minus/..) // conv_q used for divmod case (div/mod/...) int32_t conv_q_int = int(conv_q); auto [_, cta_q] = divmod(cta_coord_q * CTA_N, conv_q);
int step_q = CTA_M == 128 ? CTA_N / 1 : CTA_M == 64 ? CTA_N / 2 : CTA_M == 32 ? CTA_N / 4 : 0;
for (int mask_iter = 0; mask_iter < int(CTA_N / step_q); ++mask_iter) {
for (int s_iter = 0; s_iter < FLT_S; s_iter += 1) {
int32_t skip_span{0}, use_span{0}, nzm{1}, first_span{0}, start_count{0}, shift{0};
shift = s_iter;
// Examples for CZM setting // CASE0: (skip_span_ < 0) // | padding |<- conv_q ->| // |skip_span_|<- use_span ->|skip_span_| // -skip_span 0 ^cta_q conv_q-1 // 0 ^index // // CASE1: (skip_span_ > 0) // |<- conv_q ->| // |skip_span_|<- use_span ->|skip_span_| // 0 ^cta_q conv_q-1 // 0 ^index // // line 0 an input vector from 0 to conv_q with the padding // line 1 shows the different spans we need to skip or load // lines 2-3 show the different coordinates of different boundaries. // CTQ_q is the coordinate of the present cta.
int32_t skip_span_ = num_pixels_skip_left - shift; int32_t index{0}; if (skip_span_ > 0) { auto [_, index_mod] = divmod(cta_q, conv_q); index = index_mod; } else if (skip_span_ < 0) { auto [_, index_mod] = divmod((cta_q - skip_span_), conv_q); index = index_mod; } else { nzm = 0; } skip_span = cute::max(cute::abs(skip_span_), 1); use_span = cute::min(conv_q_int - static_cast<int32_t>(skip_span), MAX_USE_SPAN_COUNT); if (use_span > 0) { first_span = index >= skip_span ? 0 : 1; if ((first_span == 0) && (index + CTA_N < conv_q_int + skip_span)) { nzm = 0; } else { start_count = first_span == 0 ? (use_span - (conv_q_int - index)) : index; } } else { skip_span = MAX_SKIP_SPAN_COUNT; use_span = 1; first_span = 1; start_count = 0; }
column_zero_masks[s_iter].start_count_[mask_iter] = start_count; column_zero_masks[s_iter].first_span_ |= first_span << mask_iter; column_zero_masks[s_iter].nzm_ |= nzm; column_zero_masks[s_iter].skip_span_ = skip_span - 1; column_zero_masks[s_iter].use_span_ = use_span - 1; column_zero_masks[s_iter].shift_ = shift;
}
cta_q += step_q; }
return column_zero_masks;}
template <class T>CUTE_HOST_DEVICE constexpr auto to_UMMAFormat() { if constexpr (is_same_v<T, half_t>) { return F16F32Format::F16; } else if constexpr (is_same_v<T, bfloat16_t>) { return F16F32Format::BF16; } else if constexpr (is_same_v<T, tfloat32_t>) { return F16F32Format::TF32; } else if constexpr (is_same_v<T, uint8_t>) { return S8Format::UINT8; } else if constexpr (is_same_v<T, int8_t>) { return S8Format::INT8; } else if constexpr (is_same_v<T, type_erased_dynamic_float8_t>) {return MXF8F6F4Format::INVALID; } else if constexpr (is_same_v<T, type_erased_dynamic_float6_t>) {return MXF8F6F4Format::INVALID; } else if constexpr (is_same_v<T, type_erased_dynamic_float4_t>) {return MXF8F6F4Format::INVALID; } else if constexpr (is_same_v<T, detail::type_erased_dynamic_float4_unpacksmem_t>) {return MXF8F6F4Format::INVALID; } else if constexpr (is_same_v<T, float_e4m3_t>) { return MXF8F6F4Format::E4M3; } else if constexpr (is_same_v<T, float_e5m2_t>) { return MXF8F6F4Format::E5M2; } else if constexpr (is_same_v<T, detail::type_erased_dynamic_float6_unpacksmem_t>) {return MXF8F6F4Format::INVALID; } else if constexpr (is_same_v<T, detail::float_e2m3_unpacksmem_t>) { return MXF8F6F4Format::E2M3; } else if constexpr (is_same_v<T, detail::float_e3m2_unpacksmem_t>) { return MXF8F6F4Format::E3M2; } else if constexpr (is_same_v<T, float_e2m3_t>) { return MXF8F6F4Format::E2M3; } else if constexpr (is_same_v<T, float_e3m2_t>) { return MXF8F6F4Format::E3M2; } else if constexpr (is_same_v<T, detail::float_e2m1_unpacksmem_t>) { return MXF8F6F4Format::E2M1; } else if constexpr (is_same_v<T, float_e2m1_t>) { return MXF4Format::E2M1; } else { static_assert(sizeof(T) == 0, "Unknown type for UMMAFormat"); }}
template <class T>CUTE_HOST_DEVICE constexpr CFormat to_CFormat() { if constexpr (is_same_v<T, half_t>) { return CFormat::F16; } else if constexpr (is_same_v<T, float>) { return CFormat::F32; } else if constexpr (is_same_v<T, int32_t>) { return CFormat::S32; } else { static_assert(sizeof(T) == 0, "Unknown type for CFormat"); }}
union InstrDescriptor{ uint32_t desc_;
struct { // Bitfield implementation avoids the need for shifts in assignment uint16_t sparse_id2_ : 2, // bit [ 0, 2) : Sparse meta data id2 sparse_flag_ : 1, // bit [ 2, 3) : 0 = dense. 1 = sparse. 1 value valid only for F32F16/S8/MXF8F6F4 saturate_ : 1, // bit [ 3, 4) : 0 = no saturate. 1 = saturate. 1 value valid only for S8 c_format_ : 2, // bit [ 4, 6) : 0 = F16. 1 = F32, 2 = S32 : 1, // a_format_ : 3, // bit [ 7,10) : MXF8F6F4Format:0 = E4M3, 1 = E5M2, 3 = E2M3, 4 = E3M2, 5 = E2M1. F32F16Format: 0 = F16, 1 = BF16, 2 = TF32. S8: 0 unsigned 8 bit, 1 signed 8 bit. Boolean MMA: 0 Boolean b_format_ : 3, // bit [10,13) : MXF8F6F4Format:0 = E4M3, 1 = E5M2, 3 = E2M3, 4 = E3M2, 5 = E2M1. F32F16Format: 0 = F16, 1 = BF16, 2 = TF32. S8: 0 unsigned 8 bit, 1 signed 8 bit. Boolean MMA: 0 Boolean a_negate_ : 1, // bit [13,14) : 0 = no negate. 1 = negate. 1 value valid only for F32F16Format and MXF8F6F4Format b_negate_ : 1, // bit [14,15) : 0 = no negate. 1 = negate. 1 value valid only for F32F16Format and MXF8F6F4Format a_major_ : 1; // bit [15,16) : 0 = K-major. 1 = MN-major. Major value of 1 is only valid for E4M3, E5M2, INT8 (signed and unsigned), F16, BF16 and TF32 source formats uint16_t b_major_ : 1, // bit [16,17) : 0 = K-major. 1 = MN-major. Major value of 1 is only valid for E4M3, E5M2, INT8 (signed and unsigned), F16, BF16 and TF32 source formats n_dim_ : 6, // bit [17,23) : 3 LSBs not included. Valid values range from 1 (N=8) to 32 (N=256). All values are not valid for all instruction formats : 1, // m_dim_ : 5, // bit [24,29) : 4 LSBs not included. Valid values are: 4 (M=64), 8 (M=128), 16 (M=256) : 1, // max_shift_ : 2; // bit [30,32) : Maximum shift for WS instruction. Encoded as follows: 0 = no shift, 1 = maximum shift of 8, 2 = maximum shift of 16, 3 = maximum shift of 32. };
// Decay to a uint32_t CUTE_HOST_DEVICE constexpr explicit operator uint32_t() const noexcept { return desc_; }};
union InstrDescriptorBlockScaled{ uint32_t desc_;
struct { // Bitfield implementation avoids the need for shifts in assignment uint16_t sparse_id2_ : 2, // bit [ 0, 2) : Sparse meta data id2 sparse_flag_ : 1, // bit [ 2, 3) : 0 = dense. 1 = sparse. 1 value valid only for F32F16/S8/MXF8F6F4 : 1, // b_sf_id_ : 2, // bit [ 4, 6) : Matrix B Scale Factor ID : 1, // a_format_ : 3, // bit [ 7, 9) : MXF8F6F4Format:0 = E4M3, 1 = E5M2, 3 = E2M3, 4 = E3M2, 5 = E2M1. F32F16Format: 0 = F16, 1 = BF16, 2 = TF32. S8: 0 unsigned 8 bit, 1 signed 8 bit. BMMA: 0 Boolean b_format_ : 3, // bit [10,12) : MXF8F6F4Format:0 = E4M3, 1 = E5M2, 3 = E2M3, 4 = E3M2, 5 = E2M1. F32F16Format: 0 = F16, 1 = BF16, 2 = TF32. S8: 0 unsigned 8 bit, 1 signed 8 bit. BMMA: 0 Boolean a_negate_ : 1, // bit [13,14) : 0 = no negate. 1 = negate. 1 value valid only for F32F16Format and MXF8F6F4Format b_negate_ : 1, // bit [14,15) : 0 = no negate. 1 = negate. 1 value valid only for F32F16Format and MXF8F6F4Format a_major_ : 1; // bit [15,16) : 0 = K-major. 1 = MN-major. Major value of 1 is only valid for E4M3, E5M2, INT8 (signed and unsigned), F16, BF16 and TF32 source formats uint16_t b_major_ : 1, // bit [16,17) : 0 = K-major. 1 = MN-major. Major value of 1 is only valid for E4M3, E5M2, INT8 (signed and unsigned), F16, BF16 and TF32 source formats n_dim_ : 6, // bit [17,23) : 3 LSBs not included. Valid values range from 1 (N=8) to 32 (N=256). All values are not valid for all instruction formats scale_format_ : 1, // bit [23,24) : 0=E4M3, 1=E8M0 m_dim_ : 5, // bit [24,29) : 4 LSBs not included. Valid values are: 4 (M=64), 8 (M=128), 16 (M=256) a_sf_id_ : 2, // bit [29,31) : Matrix A Scale Factor ID : 1; // };
// Decay to a uint32_t CUTE_HOST_DEVICE constexpr operator uint32_t() const noexcept { return desc_; }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False, bool is_sparse = false, UMMA::MaxShift max_shift = UMMA::MaxShift::NoShift>CUTE_HOST_DEVICE constexprUMMA::InstrDescriptormake_instr_desc(){ UMMA::InstrDescriptor desc_i = {};
desc_i.a_format_ = uint8_t(UMMA::to_UMMAFormat<a_type>()); desc_i.b_format_ = uint8_t(UMMA::to_UMMAFormat<b_type>()); desc_i.c_format_ = uint8_t(UMMA::to_CFormat<c_type>());
desc_i.m_dim_ = (M >> 4); desc_i.n_dim_ = (N >> 3);
desc_i.a_major_ = uint8_t(a_major); desc_i.b_major_ = uint8_t(b_major);
desc_i.a_negate_ = uint8_t(a_neg); desc_i.b_negate_ = uint8_t(b_neg); desc_i.saturate_ = uint8_t(c_sat);
desc_i.sparse_flag_ = is_sparse; // 1 = Sparse desc_i.sparse_id2_ = 0;
desc_i.max_shift_ = uint8_t(max_shift);
return desc_i;}
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False, bool is_sparse = false, UMMA::MaxShift max_shift = UMMA::MaxShift::NoShift>CUTE_HOST_DEVICEconstexpr uint64_tmake_runtime_instr_desc(uint16_t sparse_id2 = 0u, uint32_t tmem_e = 0u) { UMMA::InstrDescriptor desc_i = UMMA::make_instr_desc< a_type, b_type, c_type, M, N, a_major, b_major, a_neg, b_neg, c_sat, is_sparse, max_shift>();
if constexpr (is_sparse) { desc_i.sparse_id2_ = sparse_id2; } else { assert(sparse_id2 == 0u); } // In current compiler exposure, idescE is a uint64_t. It should contain: // - Lower 32b URe: Specifies the tmem address that stores the sparse metadata. // Only needed for Sparse MMA instructions. Otherwise, ignored. // - Upper 32b URh: Specifies the instruction descriptor. uint64_t idescE = (static_cast<uint64_t>(static_cast<uint32_t>(desc_i)) << 32);
return idescE;}
template <bool is_sparse = false>CUTE_HOST_DEVICEconstexpr uint64_tmake_runtime_instr_desc(UMMA::InstrDescriptor desc_i, uint16_t sparse_id2 = 0u, uint32_t tmem_e = 0u){ if constexpr (is_sparse) { desc_i.sparse_id2_ = sparse_id2; } else { assert(sparse_id2 == 0u); } // In current compiler exposure, idescE is a uint64_t. It should contain: // - Lower 32b URe: Specifies the tmem address that stores the sparse metadata. // Only needed for Sparse MMA instructions. Otherwise, ignored. // - Upper 32b URh: Specifies the instruction descriptor. uint64_t idescE = (static_cast<uint64_t>(static_cast<uint32_t>(desc_i)) << 32);
return idescE;}
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, bool is_sparse = false >CUTE_HOST_DEVICE constexprUMMA::InstrDescriptorBlockScaledmake_instr_desc_block_scaled(){ UMMA::InstrDescriptorBlockScaled desc_i = {};
desc_i.a_format_ = uint8_t(UMMA::to_UMMAFormat<a_type>()); desc_i.b_format_ = uint8_t(UMMA::to_UMMAFormat<b_type>());
desc_i.scale_format_ = uint8_t(UMMA::to_ScaleFormat<sf_type>()); desc_i.a_sf_id_ = 0; desc_i.b_sf_id_ = 0;
desc_i.m_dim_ = (M >> 4); desc_i.n_dim_ = (N >> 3);
desc_i.a_major_ = uint8_t(a_major); desc_i.b_major_ = uint8_t(b_major);
desc_i.a_negate_ = uint8_t(a_neg); desc_i.b_negate_ = uint8_t(b_neg); desc_i.sparse_flag_ = is_sparse; // 1 = Sparse desc_i.sparse_id2_ = 0;
// Below would bring some warnings.#if defined(__GNUC__)# pragma GCC diagnostic ignored "-Wconversion"#endif return desc_i;}
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, bool is_sparse = false>CUTE_HOST_DEVICEconstexpr uint64_tmake_runtime_instr_desc_block_scaled(uint32_t const tmem_sfa_addr, uint32_t const tmem_sfb_addr, uint16_t const sparse_id2 = 0u, uint32_t const tmem_e = 0u){ UMMA::InstrDescriptorBlockScaled desc_i = UMMA::make_instr_desc_block_scaled< a_type, b_type, c_type, sf_type, M, N, a_major, b_major, a_neg, b_neg, is_sparse>();
// The first 2-bits of TMEM address includes byte address. desc_i.a_sf_id_ = (tmem_sfa_addr & 0xC0000000) >> 30; desc_i.b_sf_id_ = (tmem_sfb_addr & 0xC0000000) >> 30;
if constexpr (is_sparse) { desc_i.sparse_id2_ = sparse_id2; } else { assert(sparse_id2 == 0u); }
// In current compiler exposure, idescE is a uint64_t. It should contain: // - Lower 32b URe: Specifies the tmem address that stores the sparse metadata. // Only needed for Sparse MMA instructions. Otherwise, ignored. // - Upper 32b URh: Specifies the instruction descriptor. uint64_t idescE = (static_cast<uint64_t>(static_cast<uint32_t>(desc_i)) << 32);
return idescE;}
template <bool is_sparse = false>CUTE_HOST_DEVICEconstexpr uint64_tmake_runtime_instr_desc_block_scaled(UMMA::InstrDescriptorBlockScaled desc_i, uint32_t const tmem_sfa_addr, uint32_t const tmem_sfb_addr, uint16_t const sparse_id2 = 0u, uint32_t const tmem_e = 0u){ // The first 2-bits of TMEM address includes byte address. desc_i.a_sf_id_ = (tmem_sfa_addr & 0xC0000000) >> 30; desc_i.b_sf_id_ = (tmem_sfb_addr & 0xC0000000) >> 30;
if constexpr (is_sparse) { desc_i.sparse_id2_ = sparse_id2; } else { assert(sparse_id2 == 0u); }
// In current compiler exposure, idescE is a uint64_t. It should contain: // - Lower 32b URe: Specifies the tmem address that stores the sparse metadata. // Only needed for Sparse MMA instructions. Otherwise, ignored. // - Upper 32b URh: Specifies the instruction descriptor. uint64_t idescE = (static_cast<uint64_t>(static_cast<uint32_t>(desc_i)) << 32);
return idescE;}
} // end namespace UMMA} // namespace cute12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/arch/mma.hpp>#include <cute/arch/mma_sm100.hpp>#include <cute/arch/mma_sm100_desc.hpp>#include <cute/arch/cluster_sm90.hpp>
namespace cute{
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_TF32_SS{ static_assert(M == 64 || M == 128, "SM100_MMA_TF32 M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_TF32 N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::tf32 [%0], %1, %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_TF32_SS without CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F16BF16_SS{ static_assert(M == 64 || M == 128, "SM100_MMA_F16BF16 M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F16BF16 N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::f16 [%0], %1, %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_SS without CUTE_ARCH_MMA_SM100A_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_TF32_TS{ static_assert(M == 64 || M == 128, "SM100_MMA_TF32 M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_TF32 N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_TF32 A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED) uint32_t mask[4] = {0, 0, 0, 0}; if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::tf32 [%0], [%1], %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_TF32_TS without CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_F16BF16_TS{ static_assert(M == 64 || M == 128, "SM100_MMA_F16BF16 M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F16BF16 N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_F16BF16 A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED) uint32_t mask[4] = {0, 0, 0, 0}; if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::f16 [%0], [%1], %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_TS without CUTE_ARCH_MMA_SM100A_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, uint32_t ScaleC, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F16BF16_SS_SCALED{ static_assert(M == 64 || M == 128, "SM100_MMA_F16BF16_SS_SCALED M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F16BF16_SS_SCALED N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& accumulate, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED) if (cute::elect_one_sync()) { // ScaleC input should be a literal or compile time constant uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::f16 [%0], %1, %2, %3, {%5, %6, %7, %8}, p, %9; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(accumulate), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "n"(ScaleC)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_SS without CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, uint32_t ScaleC, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_F16BF16_TS_SCALED{ static_assert(M == 64 || M == 128, "SM100_MMA_F16BF16_TS_SCALED M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F16BF16_TS_SCALED N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_F16BF16_TS_SCALED A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& accumulate, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED) if (cute::elect_one_sync()) { // ScaleC input should be a literal or compile time constant uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::f16 [%0], [%1], %2, %3, {%5, %6, %7, %8}, p, %9; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(accumulate), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "n"(ScaleC)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_TS_SCALED without CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_TF32_SS_SPARSE{ static_assert(M == 64 || M == 128, "SM100_MMA_TF32_SS_SPARSE M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_TF32_SS_SPARSE N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::tf32 [%0], %1, %2, [%9], %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_TF32_SS_SPARSE without CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F16BF16_SS_SPARSE{ static_assert(M == 64 || M == 128, "SM100_MMA_F16BF16_SS_SPARSE M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F16BF16_SS_SPARSE N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::f16 [%0], %1, %2, [%9], %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_SS_SPARSE without CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_TF32_2x1SM_SS{ static_assert(M == 128 || M == 256, "SM100_MMA_TF32_2x1SM_SS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_TF32_2x1SM_SS N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::tf32 [%0], %1, %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_TF32_2x1SM_SS without CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F16BF16_2x1SM_SS{ static_assert(M == 128 || M == 256, "SM100_MMA_F16BF16_2x1SM_SS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F16BF16_2x1SM_SS N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::f16 [%0], %1, %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_2x1SM_SS without CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_TF32_2x1SM_TS{ static_assert(M == 128 || M == 256, "SM100_MMA_TF32_2x1SM_TS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_TF32_2x1SM_TS N-mode size should be a multiple of 32 between 32 and 256."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_TF32_2x1SM_TS A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::tf32 [%0], [%1], %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_TF32_2x1SM_TS without CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_F16BF16_2x1SM_TS{ static_assert(M == 128 || M == 256, "SM100_MMA_F16BF16_2x1SM_TS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F16BF16_2x1SM_TS N-mode size should be a multiple of 32 between 32 and 256."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_F16BF16_2x1SM_TS A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::f16 [%0], [%1], %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_2x1SM_TS without CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, uint32_t ScaleC, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F16BF16_2x1SM_SS_SCALED{ static_assert(M == 128 || M == 256, "SM100_MMA_F16BF16_2x1SM_SS_SCALED M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F16BF16_2x1SM_SS_SCALED N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& accumulate, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED) if (cute::elect_one_sync()) { // ScaleC input should be a literal or compile time constant uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::f16 [%0], %1, %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p, %13; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(accumulate), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7]), "n"(ScaleC)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_2x1SM_SS_SCALED without CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, uint32_t ScaleC, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_F16BF16_2x1SM_TS_SCALED{ static_assert(M == 128 || M == 256, "SM100_MMA_F16BF16_2x1SM_TS_SCALED M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F16BF16_2x1SM_TS_SCALED N-mode size should be a multiple of 32 between 32 and 256."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_F16BF16_2x1SM_TS_SCALED A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& accumulate, uint64_t idescE) {#if defined(CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED) if (cute::elect_one_sync()) { // ScaleC input should be a literal or compile time constant uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::f16 [%0], [%1], %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p, %13; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(accumulate), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7]), "n"(ScaleC)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_2x1SM_TS_SCALED without CUTE_ARCH_TCGEN05_F16BF16_MMA_SCALED_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_TF32_2x1SM_SS_SPARSE{ static_assert(M == 128 || M == 256, "SM100_MMA_TF32_2x1SM_SS_SPARSE M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_TF32_2x1SM_SS_SPARSE N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::tf32 [%0], %1, %2, [%13], %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_TF32_2x1SM_SS_SPARSE without CUTE_ARCH_TCGEN05_TF32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F16BF16_2x1SM_SS_SPARSE{ static_assert(M == 128 || M == 256, "SM100_MMA_F16BF16_2x1SM_SS_SPARSE M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F16BF16_2x1SM_SS_SPARSE N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::f16 [%0], %1, %2, [%13], %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F16BF16_2x1SM_SS_SPARSE without CUTE_ARCH_TCGEN05_F16F32_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_S8_SS{ static_assert(is_same_v<c_type, int32_t>, "SM100_MMA_S8_SS result type can only be int32_t."); static_assert(M == 64 || M == 128, "SM100_MMA_S8_SS M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert(N == 8 || ((N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_S8_SS N-mode size should be 8 or a multiple of 16 between 16 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_S8_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::i8 [%0], %1, %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_S8_SS without CUTE_ARCH_TCGEN05_S8_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_S8_TS{ static_assert(M == 64 || M == 128, "SM100_MMA_S8_TS M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert(N == 8 || ((N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_S8_TS N-mode size should be 8 or a multiple of 16 between 16 and 256."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_S8_TS A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_S8_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::i8 [%0], [%1], %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_S8_TS without CUTE_ARCH_TCGEN05_S8_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_S8_SS_SPARSE{ static_assert(is_same_v<c_type, int32_t>, "SM100_MMA_S8_SS_SPARSE result type can only be int32_t."); static_assert(M == 64 || M == 128, "SM100_MMA_S8_SS_SPARSE M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert(N == 8 || ((N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_S8_SS_SPARSE N-mode size should be 8 or a multiple of 16 between 16 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_S8_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::i8 [%0], %1, %2, [%9], %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_S8_SS_SPARSE without CUTE_ARCH_TCGEN05_S8_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_S8_2x1SM_SS{ static_assert(M == 128 || M == 256, "SM100_MMA_S8_2x1SM_SS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_S8_2x1SM_SS N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_S8_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::i8 [%0], %1, %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_S8_2x1SM_SS without CUTE_ARCH_TCGEN05_S8_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_S8_2x1SM_TS{ static_assert(M == 128 || M == 256, "SM100_MMA_S8_2x1SM_TS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_S8_2x1SM_TS N-mode size should be a multiple of 32 between 32 and 256."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_S8_2x1SM_TS A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_S8_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::i8 [%0], [%1], %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_S8_2x1SM_TS without CUTE_ARCH_TCGEN05_S8_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_S8_2x1SM_SS_SPARSE{ static_assert(M == 128 || M == 256, "SM100_MMA_S8 M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_S8 N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_S8_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::i8 [%0], %1, %2, [%13], %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_S8_2x1SM_SS_SPARSE without CUTE_ARCH_TCGEN05_S8_MMA_ENABLED");#endif }};
struct SM100_MMA_F8F6F4_SS{ using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::f8f6f4 [%0], %1, %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_SS without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF8F6F4_SS{ static_assert(M == 128, "SM100_MMA_MXF8F6F4_SS M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((N % 8 == 0) && (8 <= N) && (N <= 256), "SM100_MMA_MXF8F6F4_SS N-mode size should be a multiple of 8 between 8 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1]; using SFARegisters = uint32_t[1]; using SFBRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::mxf8f6f4.block_scale [%0], %1, %2, %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_SS without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_F8F6F4_TS{ static_assert(M == 64 || M == 128, "SM100_MMA_F8F6F4_TS M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F8F6F4_TS N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_F8F6F4_TS A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::f8f6f4 [%0], [%1], %2, %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_TS without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One, UMMA::Saturate c_sat = UMMA::Saturate::False>struct SM100_MMA_F8F6F4_2x1SM_TS{ static_assert(M == 128 || M == 256, "SM100_MMA_F8F6F4_2x1SM_TS M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F8F6F4_2x1SM_TS N-mode size should be a multiple of 32 between 32 and 256."); static_assert(a_major == UMMA::Major::K, "SM100_MMA_F8F6F4_2x1SM_TS A from TMEM can't be transposed");
using DRegisters = void; using ARegisters = uint32_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint32_t const& tmem_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::f8f6f4 [%0], [%1], %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "r"(tmem_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_TS without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F8F6F4_SS_SPARSE{ static_assert(M == 64 || M == 128, "SM100_MMA_F8F6F4_SS_SPARSE M-mode size should be 64 or 128 for 1 CTA cluster MMA."); static_assert((M == 64 && (N % 8 == 0) && (8 <= N) && (N <= 256)) || (M == 128 && (N % 16 == 0) && (16 <= N) && (N <= 256)), "SM100_MMA_F8F6F4_SS_SPARSE N-mode size should be a multiple of 8 between 8 and 256 for M=64,\ or a multiple of 16 between 16 and 256 for M=128.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[4] = {0, 0, 0, 0}; // %5, %6, %7, %8 asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::f8f6f4 [%0], %1, %2, [%9], %3, {%5, %6, %7, %8}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_SS_SPARSE without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF8F6F4_SS_SPARSE{ static_assert(M == 128, "SM100_MMA_MXF8F6F4_SS_SPARSE M-mode size should be 128 for 1 CTA cluster MMA."); static_assert((N % 8 == 0) && (8 <= N) && (N <= 256), "SM100_MMA_MXF8F6F4_SS_SPARSE N-mode size should be a multiple of 8 between 8 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1]; using SFARegisters = uint32_t[1]; using SFBRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::mxf8f6f4.block_scale [%0], %1, %2, [%7], %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF8F6F4_SS_SPARSE without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
struct SM100_MMA_F8F6F4_2x1SM_SS{ using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::f8f6f4 [%0], %1, %2, %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7])); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_2x1SM_SS without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF8F6F4_2x1SM_SS_SPARSE{ static_assert(M == 256, "SM100_MMA_MXF8F6F4_2x1SM_SS_SPARSE M-mode size should be 256 for 2 CTA cluster MMA."); static_assert((N % 16 == 0) && (16 <= N) && (N <= 256), "SM100_MMA_MXF8F6F4_2x1SM_SS_SPARSE N-mode size should be a multiple of 16 between 16 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::mxf8f6f4.block_scale [%0], %1, %2, [%7], %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF8F6F4_2x1SM_SS_SPARSE without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF8F6F4_2x1SM_SS{ static_assert(M == 256, "SM100_MMA_MXF8F6F4_2x1SM_SS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 16 == 0) && (16 <= N) && (N <= 256), "SM100_MMA_MXF8F6F4_2x1SM_SS N-mode size should be a multiple of 16 between 16 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::mxf8f6f4.block_scale [%0], %1, %2, %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF8F6F4_2x1SM_SS without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, int M, int N, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_F8F6F4_2x1SM_SS_SPARSE{ static_assert(M == 128 || M == 256, "SM100_MMA_F8F6F4_2x1SM_SS_SPARSE M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 32 == 0) && (32 <= N) && (N <= 256), "SM100_MMA_F8F6F4_2x1SM_SS_SPARSE N-mode size should be a multiple of 32 between 32 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tmem_e) {#if defined(CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED) if (cute::elect_one_sync()) { uint32_t mask[8] = {0, 0, 0, 0, 0, 0, 0, 0}; asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::f8f6f4 [%0], %1, %2, [%13], %3, {%5, %6, %7, %8, %9, %10, %11, %12}, p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(mask[0]), "r"(mask[1]), "r"(mask[2]), "r"(mask[3]), "r"(mask[4]), "r"(mask[5]), "r"(mask[6]), "r"(mask[7]), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_F8F6F4_2x1SM_SS_SPARSE without CUTE_ARCH_TCGEN05_MXF8F6F4_MMA_ENABLED");#endif }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, int VS, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF4_SS{ static_assert(M == 128, "SM100_MMA_MXF4_SS M-mode size should be 128 for 1 CTA cluster MMA."); static_assert((N % 8 == 0) && (8 <= N) && (N <= 256), "SM100_MMA_MXF4_SS N-mode size should be a multiple of 8 between 8 and 256."); static_assert((VS == 16) || (VS == 32), "SM100_MMA_MXF4_SS Vector size can only be 16 or 32.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1]; using SFARegisters = uint32_t[1]; using SFBRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr) { if constexpr (VS == 16) {#if defined(CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::mxf4nvf4.block_scale.scale_vec::4X [%0], %1, %2, %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4_SS (VS = 16) without CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED");#endif } if constexpr (VS == 32) {#if defined(CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::1.kind::mxf4.block_scale.scale_vec::2X [%0], %1, %2, %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4_SS (VS = 32) without CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED");#endif } }
};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, int VS, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF4NVF4_SS_SPARSE{ static_assert(M == 128, "SM100_MMA_MXF4NVF4_SS_SPARSE M-mode size should be 128 for 1 CTA cluster MMA."); static_assert((N % 8 == 0) && (8 <= N) && (N <= 256), "SM100_MMA_MXF4NVF4_SS_SPARSE N-mode size should be a multiple of 8 between 8 and 256.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1]; using SFARegisters = uint32_t[1]; using SFBRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr, uint32_t const& tmem_e) { if constexpr (VS == 32) {#if defined(CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::mxf4nvf4.block_scale.scale_vec::4X [%0], %1, %2, [%7], %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4NVF4_SS_SPARSE (VS = 32) without CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED");#endif }
if constexpr (VS == 64) {#if defined(CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::1.kind::mxf4.block_scale.scale_vec::2X [%0], %1, %2, [%7], %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4NVF4_SS_SPARSE (VS = 64) without CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED");#endif } }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, int VS, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF4_2x1SM_SS{ static_assert(M == 128 || M == 256, "SM100_MMA_MXF4_2x1SM_SS M-mode size should be 128 or 256 for 2 CTA cluster MMA."); static_assert((N % 16 == 0) && (16 <= N) && (N <= 256), "SM100_MMA_MXF4_2x1SM_SS N-mode size should be a multiple of 16 between 16 and 256."); static_assert((VS == 16) || (VS == 32), "SM100_MMA_MXF4_2x1SM_SS Vector size can only be 16 or 32.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1]; using SFARegisters = uint32_t[1]; using SFBRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr) { if constexpr (VS == 16) {#if defined(CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::mxf4nvf4.block_scale.scale_vec::4X [%0], %1, %2, %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4_2x1SM_SS (VS = 16) without CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED");#endif } if constexpr (VS == 32) {#if defined(CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.cta_group::2.kind::mxf4.block_scale.scale_vec::2X [%0], %1, %2, %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4_2x1SM_SS (VS = 32) without CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED");#endif } }};
template <class a_type, class b_type, class c_type, class sf_type, int M, int N, int VS, UMMA::Major a_major, UMMA::Major b_major, UMMA::ScaleIn a_neg = UMMA::ScaleIn::One, UMMA::ScaleIn b_neg = UMMA::ScaleIn::One>struct SM100_MMA_MXF4NVF4_2x1SM_SS_SPARSE{ static_assert((N % 16 == 0) && (16 <= N) && (N <= 256), "SM100_MMA_MXF4NVF4_2x1SM_SS_SPARSE N-mode size should be a multiple of 16 between 16 and 256."); static_assert((VS == 32) || (VS == 64), "SM100_MMA_MXF4NVF4_2x1SM_SS_SPARSE Vector size can only be 32 or 64.");
using DRegisters = void; using ARegisters = uint64_t[1]; using BRegisters = uint64_t[1]; using CRegisters = uint32_t[1]; using SFARegisters = uint32_t[1]; using SFBRegisters = uint32_t[1];
CUTE_HOST_DEVICE static void fma(uint64_t const& desc_a, uint64_t const& desc_b, uint32_t const& tmem_c, uint32_t const& scaleC, uint64_t const& idescE, uint32_t const& tsfa_addr, uint32_t const& tsfb_addr, uint32_t const& tmem_e) { if constexpr (VS == 32) {#if defined(CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::mxf4nvf4.block_scale.scale_vec::4X [%0], %1, %2, [%7], %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4NVF4_2x1SM_SS_SPARSE (VS = 32) without CUTE_ARCH_TCGEN05_MXF4NVF4_MMA_ENABLED");#endif }
if constexpr (VS == 64) {#if defined(CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED) if (cute::elect_one_sync()) { asm volatile( "{\n\t" ".reg .pred p;\n\t" "setp.ne.b32 p, %4, 0;\n\t" "tcgen05.mma.sp.cta_group::2.kind::mxf4.block_scale.scale_vec::2X [%0], %1, %2, [%7], %3, [%5], [%6], p; \n\t" "}\n" : : "r"(tmem_c), "l"(desc_a), "l"(desc_b), "r"(uint32_t(idescE>>32)), "r"(scaleC), "r"(tsfa_addr), "r"(tsfb_addr), "r"(tmem_e)); }#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM100_MMA_MXF4NVF4_2x1SM_SS_SPARSE (VS = 64) without CUTE_ARCH_TCGEN05_MXF4_MMA_ENABLED");#endif } }};
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/arch/mma.hpp>
// Config#if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 610))# define CUTE_ARCH_MMA_SM61_ENABLED#endif
namespace cute{
struct SM61_DP4A{ using DRegisters = int32_t[1]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = int32_t[1];
// Register asm fma CUTE_HOST_DEVICE static void fma(int32_t& d, uint32_t const& a, uint32_t const& b, int32_t const& c) {#if defined(CUTE_ARCH_MMA_SM61_ENABLED) asm volatile("dp4a.s32.s32 %0, %1, %2, %3;" : "=r"(d) : "r"(a), "r"(b), "r"(c));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM61_DP4A without CUTE_ARCH_MMA_SM61_ENABLED");#endif }};
struct SM61_DP2A{ using DRegisters = int32_t[1]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = int32_t[1];
// Register asm fma CUTE_HOST_DEVICE static void fma(int32_t& d, uint32_t const& a, uint32_t const& b, int32_t const& c) {#if defined(CUTE_ARCH_MMA_SM61_ENABLED) asm volatile("dp2a.s32.s32 %0, %1, %2, %3;" : "=r"(d) : "r"(a), "r"(b), "r"(c));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM61_DP2A without CUTE_ARCH_MMA_SM61_ENABLED");#endif }};
} // namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/mma.hpp>
// Config#if ((__CUDACC_VER_MAJOR__ > 10) || (__CUDACC_VER_MAJOR__ == 10 && __CUDACC_VER_MINOR__ >= 1))# define CUTE_ARCH_MMA_SM70_SUPPORTED# if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 700))# define CUTE_ARCH_MMA_SM70_ENABLED# endif#endif
namespace cute{
//// SM70 MMA 884 F16F16F16//
struct SM70_8x8x4_F16F16F16F16_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
// Register asm fma CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.row.col.f16.f16.f16.f16" "{%0, %1, %2, %3}," "{%4, %5}," "{%6, %7}," "{%8, %9, %10, %11};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F16F16F16F16_TN without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM70_8x8x4_F16F16F16F16_NT{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
// Register asm fma CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.col.row.f16.f16.f16.f16" "{%0, %1, %2, %3}," "{%4, %5}," "{%6, %7}," "{%8, %9, %10, %11};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F16F16F16F16_NT without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM70_8x8x4_F16F16F16F16_NN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
// Register asm fma CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.col.col.f16.f16.f16.f16" "{%0, %1, %2, %3}," "{%4, %5}," "{%6, %7}," "{%8, %9, %10, %11};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F16F16F16F16_NN without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM70_8x8x4_F16F16F16F16_TT{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
// Register asm fma CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.row.row.f16.f16.f16.f16" "{%0, %1, %2, %3}," "{%4, %5}," "{%6, %7}," "{%8, %9, %10, %11};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F16F16F16F16_TT without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
//// SM70 MMA 884 F16F16F32//
struct SM70_8x8x4_F32F16F16F32_TN{ using DRegisters = float[8]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = float[8];
// Register asm fma CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, float & d4, float & d5, float & d6, float & d7, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3, float const& c4, float const& c5, float const& c6, float const& c7) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.row.col.f32.f16.f16.f32" "{%0, %1, %2, %3, %4, %5, %6, %7}," "{%8, %9}," "{%10, %11}," "{%12, %13, %14, %15, %16, %17, %18, %19};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3), "=f"(d4), "=f"(d5), "=f"(d6), "=f"(d7) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3), "f"(c4), "f"(c5), "f"(c6), "f"(c7));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F32F16F16F32_TN without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM70_8x8x4_F32F16F16F32_NT{ using DRegisters = float[8]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = float[8];
// Register asm fma CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, float & d4, float & d5, float & d6, float & d7, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3, float const& c4, float const& c5, float const& c6, float const& c7) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.col.row.f32.f16.f16.f32" "{%0, %1, %2, %3, %4, %5, %6, %7}," "{%8, %9}," "{%10, %11}," "{%12, %13, %14, %15, %16, %17, %18, %19};" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3), "=f"(d4), "=f"(d5), "=f"(d6), "=f"(d7) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3), "f"(c4), "f"(c5), "f"(c6), "f"(c7));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F32F16F16F32_NT without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM70_8x8x4_F32F16F16F32_NN{ using DRegisters = float[8]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = float[8];
// Register asm fma CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, float & d4, float & d5, float & d6, float & d7, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3, float const& c4, float const& c5, float const& c6, float const& c7) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.col.col.f32.f16.f16.f32" "{%0, %1, %2, %3, %4, %5, %6, %7}," "{%8, %9}," "{%10, %11}," "{%12, %13, %14, %15, %16, %17, %18, %19};" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3), "=f"(d4), "=f"(d5), "=f"(d6), "=f"(d7) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3), "f"(c4), "f"(c5), "f"(c6), "f"(c7));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F32F16F16F32_NN without CUTE_ARCH_MMA_SM70_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM70_8x8x4_F32F16F16F32_TT{ using DRegisters = float[8]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[2]; using CRegisters = float[8];
// Register asm fma CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, float & d4, float & d5, float & d6, float & d7, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3, float const& c4, float const& c5, float const& c6, float const& c7) {#if defined(CUTE_ARCH_MMA_SM70_ENABLED) asm volatile("mma.sync.aligned.m8n8k4.row.row.f32.f16.f16.f32" "{%0, %1, %2, %3, %4, %5, %6, %7}," "{%8, %9}," "{%10, %11}," "{%12, %13, %14, %15, %16, %17, %18, %19};" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3), "=f"(d4), "=f"(d5), "=f"(d6), "=f"(d7) : "r"(a0), "r"(a1), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3), "f"(c4), "f"(c5), "f"(c6), "f"(c7));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM70_8x8x4_F32F16F16F32_TT without CUTE_ARCH_MMA_SM70_ENABLED");#endif }
};
////////////////////////////////////////////////////////////////////////////////////////////////////
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/mma.hpp>
// Config#if ((__CUDACC_VER_MAJOR__ > 10) || (__CUDACC_VER_MAJOR__ == 10 && __CUDACC_VER_MINOR__ >= 2))# define CUTE_ARCH_MMA_SM75_SUPPORTED# if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 750))# define CUTE_ARCH_MMA_SM75_ENABLED# endif#endif
namespace cute{
//// SM75 MMA 1688 F16F16F32//
struct SM75_16x8x8_F32F16F16F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = float[4];
// Register asm fma CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, float const& c0, float const& c1, float const& c2, float const& c3) {#if defined(CUTE_ARCH_MMA_SM75_ENABLED) asm volatile("mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32" "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(b0), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM75_16x8x8_F32F16F16F32_TN without CUTE_ARCH_MMA_SM75_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
//// SM75 MMA 8816 S8S8S32//
struct SM75_8x8x16_S32S8S8S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
// Register asm fma CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM75_ENABLED) asm volatile("mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32" "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM75_8x8x16_S32S8S8S32_TN without CUTE_ARCH_MMA_SM75_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/arch/mma.hpp>#include <cute/numeric/complex.hpp>
// Config#if (defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 800))# define CUTE_ARCH_MMA_SM80_ENABLED
#if (__CUDA_ARCH__ <= 900)#define CUTE_ARCH_MMA_B1_AND_SM80_ENABLED#endif
#if (__CUDA_ARCH__ <= 890)#define CUTE_ARCH_MMA_B1_XOR_SM80_ENABLED#endif
#endif
namespace cute {
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x8 TNstruct SM80_16x8x8_F16F16F16F16_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k8.row.col.f16.f16.f16.f16 " "{%0, %1}," "{%2, %3}," "{%4}," "{%5, %6};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x8_F16F16F16F16_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_F16F16F16F16_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.f16.f16.f16.f16 " "{%0, %1}," "{%2, %3, %4, %5}," "{%6, %7}," "{%8, %9};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_F16F16F16F16_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x8 TNstruct SM80_16x8x8_F32F16F16F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, float const & c0, float const & c1, float const & c2, float const & c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k8.row.col.f32.f16.f16.f32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(b0), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x8_F32F16F16F32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_F32F16F16F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const & c0, float const & c1, float const & c2, float const & c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.f32.f16.f16.f32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_F32F16F16F32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x8 TNstruct SM80_16x8x8_F32BF16BF16F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, float const & c0, float const & c1, float const & c2, float const & c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k8.row.col.f32.bf16.bf16.f32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(b0), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x8_F32BF16BF16F32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_F32BF16BF16F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const & c0, float const & c1, float const & c2, float const & c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_F32BF16BF16F32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x4 TNstruct SM80_16x8x4_F32TF32TF32F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, float const & c0, float const & c1, float const & c2, float const & c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k4.row.col.f32.tf32.tf32.f32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(b0), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x4_F32TF32TF32F32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x8 TNstruct SM80_16x8x8_F32TF32TF32F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const & c0, float const & c1, float const & c2, float const & c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k8.row.col.f32.tf32.tf32.f32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x8_F32TF32TF32F32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x4 TNstruct SM80_8x8x4_F64F64F64F64_TN{ using DRegisters = double[2]; using ARegisters = double[1]; using BRegisters = double[1]; using CRegisters = double[2];
CUTE_HOST_DEVICE static void fma(double & d0, double & d1, double const& a0, double const& b0, double const& c0, double const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k4.row.col.f64.f64.f64.f64 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=d"(d0), "=d"(d1) : "d"(a0), "d"(b0), "d"(c0), "d"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x4_F64F64F64F64_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
// MMA 8x8x4 TN with Planar Complex multiplicationstruct SM80_8x8x4_C64C64C64C64_TN{ using DRegisters = complex<double>[2]; using ARegisters = complex<double>[1]; using BRegisters = complex<double>[1]; using CRegisters = complex<double>[2];
CUTE_HOST_DEVICE static void fma(complex<double> & d0, complex<double> & d1, complex<double> const& a0, complex<double> const& b0, complex<double> const& c0, complex<double> const& c1) { // Because thrust::complex does not provide a mutable ref double& rd0 = reinterpret_cast<double(&)[2]>(d0)[0]; double& id0 = reinterpret_cast<double(&)[2]>(d0)[1]; double& rd1 = reinterpret_cast<double(&)[2]>(d1)[0]; double& id1 = reinterpret_cast<double(&)[2]>(d1)[1];
// d.real() = a.real() * b.real() + c.real(); SM80_8x8x4_F64F64F64F64_TN::fma( rd0, rd1, a0.real(), b0.real(), c0.real(), c1.real());
// d.imag() = a.imag() * b.real() + c.imag(); SM80_8x8x4_F64F64F64F64_TN::fma( id0, id1, a0.imag(), b0.real(), c0.imag(), c1.imag());
// d.real() = -a.imag() * b.imag() + d.real(); SM80_8x8x4_F64F64F64F64_TN::fma( rd0, rd1, -a0.imag(), b0.imag(), d0.real(), d1.real());
// d.imag() = a.real() * b.imag() + d.imag(); SM80_8x8x4_F64F64F64F64_TN::fma( id0, id1, a0.real(), b0.imag(), d0.imag(), d1.imag()); }};
// MMA 8x8x4 TN with Gaussian Complex multiplication:// (a + bi)*(c + di)// yields// t0 += a*c// t1 += b*d// t2 += (a+b)*(c+d)// then// re = t0 - t1// im = t2 - t0 - t1struct SM80_8x8x4_GC64C64C64GC64_TN{ struct GaussComplex { double t0, t1, t2;
CUTE_HOST_DEVICE //constexpr operator complex<double>() const { return complex<double>(t0 - t1, t2 - t0 - t1); }
CUTE_HOST_DEVICE friend //constexpr complex<double> operator*(GaussComplex const& a, complex<double> const& b) { return static_cast<complex<double>>(a) * b; } CUTE_HOST_DEVICE friend //constexpr complex<double> operator*(complex<double> const& a, GaussComplex const& b) { return b * a; }
CUTE_HOST_DEVICE friend //constexpr complex<double> operator+(GaussComplex const& a, complex<double> const& b) { return static_cast<complex<double>>(a) + b; } CUTE_HOST_DEVICE friend //constexpr complex<double> operator+(complex<double> const& a, GaussComplex const& b) { return b + a; } };
using DRegisters = GaussComplex[2]; using ARegisters = complex<double>[1]; using BRegisters = complex<double>[1]; using CRegisters = GaussComplex[2];
CUTE_HOST_DEVICE static void fma(GaussComplex & d0, GaussComplex & d1, complex<double> const& a0, complex<double> const& b0, GaussComplex const& c0, GaussComplex const& c1) { SM80_8x8x4_F64F64F64F64_TN::fma(d0.t0, d1.t0, a0.real(), b0.real(), c0.t0, c1.t0); SM80_8x8x4_F64F64F64F64_TN::fma(d0.t1, d1.t1, a0.imag(), b0.imag(), c0.t1, c1.t1); SM80_8x8x4_F64F64F64F64_TN::fma(d0.t2, d1.t2, a0.real() + a0.imag(), b0.real() + b0.imag(), c0.t2, c1.t2); }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32S8S8S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32S8S8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32S8S8S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.s8.s8.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32S8S8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32S8S8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.s8.s8.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32S8S8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32S8S8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.s8.s8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32S8S8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S8S8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s8.s8.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S8S8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S8S8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s8.s8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S8S8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32S8U8S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.s8.u8.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32S8U8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32S8U8S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.s8.u8.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32S8U8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32S8U8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.s8.u8.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32S8U8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32S8U8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.s8.u8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32S8U8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S8U8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s8.u8.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S8U8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S8U8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s8.u8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S8U8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32U8S8S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.u8.s8.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32U8S8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32U8S8S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.u8.s8.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32U8S8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32U8S8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.u8.s8.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32U8S8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32U8S8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.u8.s8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32U8S8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U8S8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u8.s8.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U8S8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U8S8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u8.s8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U8S8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32U8U8S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.u8.u8.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32U8U8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x16 TNstruct SM80_8x8x16_S32U8U8S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k16.row.col.s32.u8.u8.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x16_S32U8U8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32U8U8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.u8.u8.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32U8U8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x16 TNstruct SM80_16x8x16_S32U8U8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k16.row.col.s32.u8.u8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x16_S32U8U8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U8U8S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u8.u8.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U8U8S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U8U8S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u8.u8.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U8U8S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32S4S4S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.s4.s4.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32S4S4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32S4S4S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.s4.s4.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32S4S4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S4S4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s4.s4.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S4S4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S4S4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s4.s4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S4S4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32S4S4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.s4.s4.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32S4S4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32S4S4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.s4.s4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32S4S4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32S4U4S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.s4.u4.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32S4U4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32S4U4S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.s4.u4.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32S4U4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S4U4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s4.u4.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S4U4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32S4U4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.s4.u4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32S4U4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32S4U4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.s4.u4.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32S4U4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32S4U4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.s4.u4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32S4U4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32U4S4S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.u4.s4.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32U4S4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32U4S4S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.u4.s4.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32U4S4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U4S4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u4.s4.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U4S4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U4S4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u4.s4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U4S4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32U4S4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.u4.s4.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32U4S4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32U4S4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.u4.s4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32U4S4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32U4U4S32_TN{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.u4.u4.s32 " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32U4U4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x32 TNstruct SM80_8x8x32_S32U4U4S32_TN_SATURATE{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k32.row.col.s32.u4.u4.s32.satfinite " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x32_S32U4U4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U4U4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u4.u4.s32 " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U4U4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x32 TNstruct SM80_16x8x32_S32U4U4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k32.row.col.s32.u4.u4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x32_S32U4U4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32U4U4S32_TN{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.u4.u4.s32 " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32U4U4S32_TN without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x64 TNstruct SM80_16x8x64_S32U4U4S32_TN_SATURATE{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k64.row.col.s32.u4.u4.s32.satfinite " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x64_S32U4U4S32_TN_SATURATE without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x128 TNstruct SM80_8x8x128_S32U1U1S32_TN_ANDPOPC{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k128.row.col.s32.b1.b1.s32.and.popc " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x128_S32U1U1S32_TN_ANDPOPC without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x128 TNstruct SM80_16x8x128_S32U1U1S32_TN_ANDPOPC{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k128.row.col.s32.b1.b1.s32.and.popc " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x128_S32U1U1S32_TN_ANDPOPC without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x256 TNstruct SM80_16x8x256_S32U1U1S32_TN_ANDPOPC{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_B1_AND_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k256.row.col.s32.b1.b1.s32.and.popc " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x256_S32U1U1S32_TN_ANDPOPC without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 8x8x128 TNstruct SM80_8x8x128_S32U1U1S32_TN_XORPOPC{ using DRegisters = uint32_t[2]; using ARegisters = uint32_t[1]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[2];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t const& a0, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1) {#if defined(CUTE_ARCH_MMA_B1_XOR_SM80_ENABLED) asm volatile( "mma.sync.aligned.m8n8k128.row.col.s32.b1.b1.s32.xor.popc " "{%0, %1}," "{%2}," "{%3}," "{%4, %5};\n" : "=r"(d0), "=r"(d1) : "r"(a0), "r"(b0), "r"(c0), "r"(c1));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_8x8x128_S32U1U1S32_TN_XORPOPC without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x128 TNstruct SM80_16x8x128_S32U1U1S32_TN_XORPOPC{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[2]; using BRegisters = uint32_t[1]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& b0, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_B1_XOR_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k128.row.col.s32.b1.b1.s32.xor.popc " "{%0, %1, %2, %3}," "{%4, %5}," "{%6}," "{%7, %8, %9, %10};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(b0), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x128_S32U1U1S32_TN_XORPOPC without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
// MMA 16x8x256 TNstruct SM80_16x8x256_S32U1U1S32_TN_XORPOPC{ using DRegisters = uint32_t[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = uint32_t[4];
CUTE_HOST_DEVICE static void fma(uint32_t & d0, uint32_t & d1, uint32_t & d2, uint32_t & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, uint32_t const& c0, uint32_t const& c1, uint32_t const& c2, uint32_t const& c3) {#if defined(CUTE_ARCH_MMA_B1_XOR_SM80_ENABLED) asm volatile( "mma.sync.aligned.m16n8k256.row.col.s32.b1.b1.s32.xor.popc " "{%0, %1, %2, %3}," "{%4, %5, %6, %7}," "{%8, %9}," "{%10, %11, %12, %13};\n" : "=r"(d0), "=r"(d1), "=r"(d2), "=r"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "r"(c0), "r"(c1), "r"(c2), "r"(c3));#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM80_16x8x256_S32U1U1S32_TN_XORPOPC without CUTE_ARCH_MMA_SM80_ENABLED");#endif }};
////////////////////////////////////////////////////////////////////////////////////////////////////
} // namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/arch/mma.hpp>
////////////////////////////////////////////////////////////////////////////////
#if (__CUDACC_VER_MAJOR__ > 12) || (__CUDACC_VER_MAJOR__ == 12 && __CUDACC_VER_MINOR__ >= 4)# define CUTE_ARCH_MMA_F32_SM89_SUPPORTED#endif
#if (__CUDACC_VER_MAJOR__ > 12) || (__CUDACC_VER_MAJOR__ == 12 && __CUDACC_VER_MINOR__ >= 8)# define CUTE_ARCH_MMA_F16_SM89_SUPPORTED#endif
#if defined(__CUDA_ARCH__) && (__CUDA_ARCH__ >= 890)# if defined(CUTE_ARCH_MMA_F32_SM89_SUPPORTED)# define CUTE_ARCH_MMA_F32_SM89_ENABLED# endif
# if defined(CUTE_ARCH_MMA_F16_SM89_SUPPORTED)# define CUTE_ARCH_MMA_F16_SM89_ENABLED# endif#endif
////////////////////////////////////////////////////////////////////////////////
namespace cute {// MMA 16x8x32 TNstruct SM89_16x8x32_F32E4M3E4M3F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3) {#if defined(CUTE_ARCH_MMA_F32_SM89_ENABLED) asm( "mma.sync.aligned.m16n8k32.row.col.f32.e4m3.e4m3.f32 " "{%0,%1,%2,%3}, {%4,%5,%6,%7}, {%8,%9}, {%10,%11,%12,%13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3) );#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM89_16x8x32_F32E4M3E4M3F32_TN without CUTE_ARCH_MMA_F32_SM89_ENABLED");#endif }};
struct SM89_16x8x32_F32E4M3E5M2F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3) {#if defined(CUTE_ARCH_MMA_F32_SM89_ENABLED) asm( "mma.sync.aligned.m16n8k32.row.col.f32.e4m3.e5m2.f32 " "{%0,%1,%2,%3}, {%4,%5,%6,%7}, {%8,%9}, {%10,%11,%12,%13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3) );#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM89_16x8x32_F32E4M3E5M2F32_TN without CUTE_ARCH_MMA_F32_SM89_ENABLED");#endif }};
struct SM89_16x8x32_F32E5M2E5M2F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3) {#if defined(CUTE_ARCH_MMA_F32_SM89_ENABLED) asm( "mma.sync.aligned.m16n8k32.row.col.f32.e5m2.e5m2.f32 " "{%0,%1,%2,%3}, {%4,%5,%6,%7}, {%8,%9}, {%10,%11,%12,%13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3) );#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM89_16x8x32_F32E5M2E5M2F32_TN without CUTE_ARCH_MMA_F32_SM89_ENABLED");#endif }};
struct SM89_16x8x32_F32E5M2E4M3F32_TN{ using DRegisters = float[4]; using ARegisters = uint32_t[4]; using BRegisters = uint32_t[2]; using CRegisters = float[4];
CUTE_HOST_DEVICE static void fma(float & d0, float & d1, float & d2, float & d3, uint32_t const& a0, uint32_t const& a1, uint32_t const& a2, uint32_t const& a3, uint32_t const& b0, uint32_t const& b1, float const& c0, float const& c1, float const& c2, float const& c3) {#if defined(CUTE_ARCH_MMA_F32_SM89_ENABLED) asm( "mma.sync.aligned.m16n8k32.row.col.f32.e5m2.e4m3.f32 " "{%0,%1,%2,%3}, {%4,%5,%6,%7}, {%8,%9}, {%10,%11,%12,%13};\n" : "=f"(d0), "=f"(d1), "=f"(d2), "=f"(d3) : "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(b0), "r"(b1), "f"(c0), "f"(c1), "f"(c2), "f"(c3) );#else CUTE_INVALID_CONTROL_PATH("Attempting to use SM89_16x8x32_F32E5M2E4M3F32_TN without CUTE_ARCH_MMA_F32_SM89_ENABLED");#endif }};
} // namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>
#include <cute/arch/mma.hpp>
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace cute {
////////////////////////////////////////////////////////////////////////////////////////////////////// GMMA Descriptor and utilities
// GMMA enums and utilitiesnamespace SM90::GMMA {
enum class LayoutType : uint8_t { INTERLEAVE = 0, B128 = 1, B64 = 2, B32 = 3,};
CUTE_HOST_DEVICE char const* to_string(LayoutType const& t) { switch (t) { case LayoutType::INTERLEAVE: return "INTERLEAVE"; case LayoutType::B128: return "B128"; case LayoutType::B64: return "B64"; case LayoutType::B32: return "B32"; } return nullptr;}
#if !defined(__CUDACC_RTC__)// Output operator for all enums in this namespaceCUTE_HOST std::ostream& operator<<(std::ostream& os, LayoutType const& t) { char const* s = to_string(t); if (s) { std::operator<<(os, s); // Explicit call to avoid ambiguity } else { os.setstate(std::ios_base::failbit); } return os;}#endif // !defined(__CUDACC_RTC__)
} // end namespace SM90::GMMA
union GmmaDescriptor{ CUTE_HOST_DEVICE constexpr GmmaDescriptor() noexcept : desc_(0) {} CUTE_HOST_DEVICE constexpr GmmaDescriptor(uint64_t desc) noexcept : desc_(desc) {} CUTE_HOST_DEVICE constexpr GmmaDescriptor(GmmaDescriptor const& t) noexcept : desc_(t.desc_) {} CUTE_HOST_DEVICE constexpr GmmaDescriptor(GmmaDescriptor && t) noexcept : desc_(t.desc_) {}
CUTE_HOST_DEVICE constexpr GmmaDescriptor& operator=(GmmaDescriptor const& t) noexcept { desc_ = t.desc_; return *this; }
CUTE_HOST_DEVICE constexpr GmmaDescriptor& operator=(GmmaDescriptor && t) noexcept { desc_ = t.desc_; return *this; }
uint64_t desc_; uint32_t reg32_[2]; uint16_t reg16_[4];
// Bitfield implementation avoids the need for shifts in assignment struct { // start_address, bit [0,14), 4LSB not included uint16_t start_address_ : 14, : 2; // 14 bits [0,14), 2 bits unused // leading dimension byte offset, bit [16,30), 4LSB not included // For N: This is the stride from the first col to the second col of the 8x2 brick in INTERLEAVED // Unused for all SWIZZLE_* layouts (and assumed to be 1) // For T: This is the stride from the first 8 rows to the next 8 rows. uint16_t leading_byte_offset_ : 14, : 2; // 14 bits [0,14), 2 bits unused // stride dimension byte offset, bit [32,46), 4LSB not included // For N: This is the stride from the first 8 rows to the next 8 rows. // For T: This is the stride fro mthe first 8 cols to the next 8 cols. uint16_t stride_byte_offset_ : 14, : 2; // 14 bits [0,14), 2 bits unused // base_offset, bit [49,52) // Valid only for SWIZZLE_128B and SWIZZLE_64B uint8_t : 1, base_offset_ : 3, : 4; // 1 bit unused, 3 bits [1,4), 4 bits unused // layout type, bit [62,64) // SWIZZLE_NONE = 0, SWIZZLE_32B = 3, SWIZZLE_64B = 2, SWIZZLE_128B = 1 uint8_t : 6, layout_type_ : 2; // 6 bits unused, 2 bits [6,8) } bitfield;
// Decay to a uint64_t CUTE_HOST_DEVICE constexpr operator uint64_t() const noexcept { return desc_; }};
// PrinterCUTE_HOST_DEVICE voidprint(GmmaDescriptor const& t){#if !defined(__CUDACC_RTC__) printf("GmmaDescriptor: 0x%016llx\n", static_cast<unsigned long long>(t.desc_)); printf(" start_addr : 0x%04x\n", t.bitfield.start_address_); printf(" leading_off: 0x%04x (%d)\n", t.bitfield.leading_byte_offset_, t.bitfield.leading_byte_offset_); printf(" stride_off : 0x%04x (%d)\n", t.bitfield.stride_byte_offset_, t.bitfield.stride_byte_offset_); printf(" base_offset: 0x%01x\n", t.bitfield.base_offset_); printf(" layout_type: 0x%01x (%s)\n", t.bitfield.layout_type_, to_string(static_cast<SM90::GMMA::LayoutType>(t.bitfield.layout_type_)));#endif // !defined(__CUDACC_RTC__)}
////////////////////////////////////////////////////////////////////////////////////////////////////
} // namespace cute
////////////////////////////////////////////////////////////////////////////////////////////////////123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596/*************************************************************************************************** * Copyright (c) 2024 - 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/config.hpp>#include <cute/arch/config.hpp>#include <cute/numeric/real.hpp>
namespace cute {
CUTE_HOST_DEVICEvoid add(float2 & c, float2 const& a, float2 const& b) {#if defined(CUTE_ARCH_FLOAT2_MATH_ENABLED) asm volatile("add.f32x2 %0, %1, %2;\n" : "=l"(reinterpret_cast<uint64_t &>(c)) : "l"(reinterpret_cast<uint64_t const&>(a)), "l"(reinterpret_cast<uint64_t const&>(b)));#else add(c.x, a.x, b.x); add(c.y, a.y, b.y);#endif}
CUTE_HOST_DEVICEvoid mul(float2 & c, float2 const& a, float2 const& b) {#if defined(CUTE_ARCH_FLOAT2_MATH_ENABLED) asm volatile("mul.f32x2 %0, %1, %2;\n" : "=l"(reinterpret_cast<uint64_t &>(c)) : "l"(reinterpret_cast<uint64_t const&>(a)), "l"(reinterpret_cast<uint64_t const&>(b)));#else mul(c.x, a.x, b.x); mul(c.y, a.y, b.y);#endif}
CUTE_HOST_DEVICEvoid fma(float2 & d, float2 const& a, float2 const& b, float2 const& c) {#if defined(CUTE_ARCH_FLOAT2_MATH_ENABLED) asm volatile("fma.rn.f32x2 %0, %1, %2, %3;\n" : "=l"(reinterpret_cast<uint64_t &>(d)) : "l"(reinterpret_cast<uint64_t const&>(a)), "l"(reinterpret_cast<uint64_t const&>(b)), "l"(reinterpret_cast<uint64_t const&>(c)));#else fma(d.x, a.x, b.x, c.x); fma(d.y, a.y, b.y, c.y);#endif}
} // namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/arch/cluster_sm90.hpp>#include <cute/atom/copy_traits_sm100.hpp>
#include <cutlass/pipeline/sm90_pipeline.hpp>
namespace cute::TMEM {
// All operations of this class require that only a single warp uniformly participatesclass Allocator1Sm {public: static constexpr int ColumnsPerAllocationSlice = 32; static constexpr int Sm100TmemCapacityColumns = 512;
__device__ Allocator1Sm() { }
/** * Performs a non-blocking allocation of TMEM. * @param num_columns Number of columns being freed. Must be 32 <= num_columns <= 512 and power of 2. * @param dst_ptr Pointer to shared memory to which to write the result tmem pointer to. * @pre Must be issued by a single fully active warp of the CTA. * @pre Must never be issued by more than one warp at the same time. * @pre For repeated allocations, the same warp must be used to issue all allocations. **/ CUTE_HOST_DEVICE void allocate(int num_columns, uint32_t* dst_ptr) { #if defined(CUTE_ARCH_TCGEN05_TMEM_ENABLED) uint32_t dst_intptr = cute::cast_smem_ptr_to_uint(dst_ptr); asm volatile( "tcgen05.alloc.cta_group::1.sync.aligned.shared::cta.b32 [%0], %1;" : : "r"(dst_intptr), "r"(num_columns)); #else CUTE_INVALID_CONTROL_PATH("Attempting to use TMEM allocation PTX without CUTE_ARCH_TCGEN05_TMEM_ENABLED"); #endif }
__device__ void free(uint32_t tmem_ptr, int num_columns) { #if defined(CUTE_ARCH_TCGEN05_TMEM_ENABLED) asm volatile( "{\n\t" "tcgen05.dealloc.cta_group::1.sync.aligned.b32 %0, %1; \n\t" "}" : : "r"(tmem_ptr), "r"(num_columns)); #else CUTE_INVALID_CONTROL_PATH("Attempting to use TMEM allocation PTX without CUTE_ARCH_TCGEN05_TMEM_ENABLED"); #endif }
__device__ void release_allocation_lock() { #if defined(CUTE_ARCH_TCGEN05_TMEM_ENABLED) asm volatile("tcgen05.relinquish_alloc_permit.cta_group::1.sync.aligned;" ::); #else CUTE_INVALID_CONTROL_PATH("Attempting to use TMEM allocation PTX without CUTE_ARCH_TCGEN05_TMEM_ENABLED"); #endif }};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Allocator2Sm {public: static constexpr int ColumnsPerAllocationSlice = 32; static constexpr int Sm100TmemCapacityColumns = 512;
__device__ Allocator2Sm() { }
/** * Performs a non-blocking allocation of TMEM. * @param num_columns Number of columns being freed. Must be 32 <= num_columns <= 512 and power of 2. * @param dst_ptr Pointer to shared memory to which to write the result tmem pointer to. * Both CTAs _must_ provide the exact same dst_ptr for correctness. * @pre Must be issued by a single fully active warp of the CTA. * @pre Must never be issued by more than one warp at the same time. * @pre For repeated allocations, the same warp must be used to issue all allocations. * @pre The 2 warps from participating CTAs have the same logical warp ID. **/ CUTE_HOST_DEVICE void allocate(int num_columns, uint32_t* dst_ptr) { #if defined(CUTE_ARCH_TCGEN05_TMEM_ENABLED) uint32_t dst_intptr = cute::cast_smem_ptr_to_uint(dst_ptr); asm volatile( "tcgen05.alloc.cta_group::2.sync.aligned.shared::cta.b32 [%0], %1;" : : "r"(dst_intptr), "r"(num_columns)); #else CUTE_INVALID_CONTROL_PATH("Attempting to use TMEM allocation PTX without CUTE_ARCH_TCGEN05_TMEM_ENABLED"); #endif }
/** * Frees the TMEM corresponding to the pointer and slice count provided. * Release the TMEM after checking that the CTA issuing the free does indeed own the corresponding slices. * @param tmem_ptr Base address of the TMEM address space being freed. * @param num_columns Number of columns being freed. Must be 32 <= num_columns <= 512 and power of 2. * @pre Must be issued by a single fully active warp of the CTA. * @pre Must never be issued by more than one warp at the same time. * @pre The 2 warps from participating CTAs have the same logical warp ID. * @returns true **/ __device__ void free(uint32_t tmem_ptr, int num_columns) { #if defined(CUTE_ARCH_TCGEN05_TMEM_ENABLED) asm volatile( "{\n\t" "tcgen05.dealloc.cta_group::2.sync.aligned.b32 %0, %1; \n\t" "}" : : "r"(tmem_ptr), "r"(num_columns)); #else CUTE_INVALID_CONTROL_PATH("Attempting to use TMEM allocation PTX without CUTE_ARCH_TCGEN05_TMEM_ENABLED"); #endif }
__device__ void release_allocation_lock() { #if defined(CUTE_ARCH_TCGEN05_TMEM_ENABLED) asm volatile("tcgen05.relinquish_alloc_permit.cta_group::2.sync.aligned;" ::); #else CUTE_INVALID_CONTROL_PATH("Attempting to use TMEM allocation PTX without CUTE_ARCH_TCGEN05_TMEM_ENABLED"); #endif }};
} // namespace cute::TMEM123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp>#include <cute/numeric/integer_sequence.hpp>
#if defined(__clang__) && defined(__CUDA__) // __cvta_generic_to_shared was added in Clang 14: https://reviews.llvm.org/D111665 #if __clang_major__ >= 14 #define CUTE_CLANG_SUPPORTS_CVTA_GENERIC_TO_SHARED 1 #endif
// __nvvm_get_smem_pointer added in Clang 14: https://reviews.llvm.org/D111665 // ... but will not work on Windows until Clang 15: https://reviews.llvm.org/D122897 #if (!defined(_WIN32) && __clang_major__ >= 14) || __clang_major__ >= 15 #define CUTE_CLANG_SUPPORTS_NVVM_GET_SMEM_POINTER 1 #endif#endif
#if defined(__NVCC__) || defined(__CUDACC_RTC__) // __cvta_generic_to_shared added in CUDA 11+ #if __CUDACC_VER_MAJOR__ >= 11 #define CUTE_NVCC_SUPPORTS_CVTA_GENERIC_TO_SHARED 1 #endif
// __nvvm_get_smem_pointer added in CUDA 10.2 #if __CUDACC_VER_MAJOR__ == 10 && __CUDACC_VER_MINOR__ >= 2 #define CUTE_NVCC_SUPPORTS_NVVM_GET_SMEM_POINTER 1 #endif#endif
#if CUTE_NVCC_SUPPORTS_CVTA_GENERIC_TO_SHARED || CUTE_CLANG_SUPPORTS_CVTA_GENERIC_TO_SHARED #define CUTE_CVTA_GENERIC_TO_SHARED_SUPPORTED 1#endif
#if !defined(CUTE_CVTA_GENERIC_TO_SHARED_ACTIVATED) && CUTE_CVTA_GENERIC_TO_SHARED_SUPPORTED && defined(__CUDA_ARCH__) #define CUTE_CVTA_GENERIC_TO_SHARED_ACTIVATED 1#endif
#if CUTE_NVCC_SUPPORTS_NVVM_GET_SMEM_POINTER || CUTE_CLANG_SUPPORTS_NVVM_GET_SMEM_POINTER #define CUTE_NVVM_GET_SMEM_POINTER_SUPPORTED 1#endif
#if !defined(CUTE_NVVM_GET_SMEM_POINTER_ACTIVATED) && CUTE_NVVM_GET_SMEM_POINTER_SUPPORTED && defined(__CUDA_ARCH__) #define CUTE_NVVM_GET_SMEM_POINTER_ACTIVATED 1#endif
// Clang 14+ provides a declaration of __nvvm_get_smem_pointer, so we only need// to provide one for NVCC#if CUTE_NVCC_SUPPORTS_NVVM_GET_SMEM_POINTER extern "C" { // This NVVM intrinsic is subject to change in future versions of CUDA. // Clients should not call it directly. CUTE_DEVICE uint32_t __nvvm_get_smem_pointer(void*); }#endif
namespace cute{
/// CUTE helper to cast SMEM pointer to unsignedCUTE_HOST_DEVICEuint32_tcast_smem_ptr_to_uint(void const* const ptr){// We prefer to use the new CVTA intrinsics if they are available, otherwise we will fall back to// the previous internal intrinsics if they are available.#if CUTE_CVTA_GENERIC_TO_SHARED_ACTIVATED // // This NVVM intrinsic converts an address in shared memory to a plain // unsigned integer. This is necessary to pass to shared memory instructions // in inline PTX. // // In CUDA 11 and beyond, this replaces __nvvm_get_smem_pointer() [only available in 10.2]. // //__device__ size_t __cvta_generic_to_shared(void* ptr);
/// CUTE helper to get SMEM pointer return static_cast<uint32_t>(__cvta_generic_to_shared(ptr));
#elif CUTE_NVVM_GET_SMEM_POINTER_ACTIVATED
return __nvvm_get_smem_pointer(ptr);
#elif defined(__CUDA_ARCH__)
uint32_t smem_ptr;
asm( "{ .reg .u64 smem_ptr; cvta.to.shared.u64 smem_ptr, %1; cvt.u32.u64 %0, smem_ptr; }\n" : "=r"(smem_ptr) : "l"(ptr));
return smem_ptr;
#else
(void) ptr; printf("ERROR: cast_smem_ptr_to_uint not supported but used.\n"); return 0;
#endif}
namespace detail {
//// Wrapper for MMAOp::fma//
template <class MmaOp>struct CallFMA { template <class... Args> CUTE_HOST_DEVICE constexpr void operator()(Args&&... args) const { return MmaOp::fma(static_cast<Args&&>(args)...); }};
//// Wrapper for CopyOp::copy//
template <class CopyOp>struct CallCOPY { template <class... Args> CUTE_HOST_DEVICE constexpr void operator()(Args&&... args) const { return CopyOp::copy(static_cast<Args&&>(args)...); }};
//// Utility for exploding pointers/arrays/tensors into functions//
template <class Fn, class PtrA, int... I>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrA&& a, int_sequence<I...>){ return fn(a[I]...);}
template <class Fn, class PtrS, int... Is, class PtrD, int... Id>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrS&& s, int_sequence<Is...>, PtrD&& d, int_sequence<Id...>){ return fn(s[Is]..., d[Id]...);}
template <class Fn, class PtrA, int... Ia, class PtrB, int... Ib, class PtrC, int... Ic>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrA&& a, int_sequence<Ia...>, PtrB&& b, int_sequence<Ib...>, PtrC&& c, int_sequence<Ic...>){ return fn(a[Ia]..., b[Ib]..., c[Ic]...);}
template <class Fn, class PtrD, int... Id, class PtrA, int... Ia, class PtrB, int... Ib, class PtrC, int... Ic>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrD&& d, int_sequence<Id...>, PtrA&& a, int_sequence<Ia...>, PtrB&& b, int_sequence<Ib...>, PtrC&& c, int_sequence<Ic...>){ return fn(d[Id]..., a[Ia]..., b[Ib]..., c[Ic]...);}
template <class Fn, class PtrD, int... Id, class PtrA, int... Ia, class PtrB, int... Ib, class PtrC, int... Ic, class PtrE, int... Ie>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrD&& d, int_sequence<Id...>, PtrA&& a, int_sequence<Ia...>, PtrB&& b, int_sequence<Ib...>, PtrC&& c, int_sequence<Ic...>, PtrE&& e, int_sequence<Ie...>){ return fn(d[Id]..., a[Ia]..., b[Ib]..., c[Ic]..., e[Ie]...);}
template <class Fn, class PtrD, int... Id, class PtrA, int... Ia, class PtrB, int... Ib, class PtrC, int... Ic, class PtrE, int... Ie, class PtrF, int... If>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrD&& d, int_sequence<Id...>, PtrA&& a, int_sequence<Ia...>, PtrB&& b, int_sequence<Ib...>, PtrC&& c, int_sequence<Ic...>, PtrE&& e, int_sequence<Ie...>, PtrF&& f, int_sequence<If...>){ return fn(d[Id]..., a[Ia]..., b[Ib]..., c[Ic]..., e[Ie]..., f[If]...);}
template <class Fn, class PtrD, int... Id, class PtrA, int... Ia, class PtrB, int... Ib, class PtrC, int... Ic, class PtrE, int... Ie, class PtrF, int... If, class PtrG, int... Ig>CUTE_HOST_DEVICE constexprvoidexplode(Fn fn, PtrD&& d, int_sequence<Id...>, PtrA&& a, int_sequence<Ia...>, PtrB&& b, int_sequence<Ib...>, PtrC&& c, int_sequence<Ic...>, PtrE&& e, int_sequence<Ie...>, PtrF&& f, int_sequence<If...>, PtrG&& g, int_sequence<Ig...>){ return fn(d[Id]..., a[Ia]..., b[Ib]..., c[Ic]..., e[Ie]..., f[If]..., g[Ig]...);}
//// Utility for exploding tuples into functions//
template <class Fn, class TupleA, int... I>CUTE_HOST_DEVICE constexprvoidexplode_tuple(Fn fn, TupleA&& a, int_sequence<I...>){ return fn(get<I>(a)...);}
template <class Fn, class TupleA, int... Ia, class TupleB, int... Ib>CUTE_HOST_DEVICE constexprvoidexplode_tuple(Fn fn, TupleA&& a, int_sequence<Ia...>, TupleB&& b, int_sequence<Ib...>){ return fn(get<Ia>(a)..., get<Ib>(b)...);}
template <class Fn, class TupleA, int... Ia, class TupleB, int... Ib, class TupleC, int... Ic>CUTE_HOST_DEVICE constexprvoidexplode_tuple(Fn fn, TupleA&& a, int_sequence<Ia...>, TupleB&& b, int_sequence<Ib...>, TupleC&& c, int_sequence<Ic...>){ return fn(get<Ia>(a)..., get<Ib>(b)..., get<Ic>(c)...);}
} // end namespace detail
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765/*************************************************************************************************** * Copyright (c) 2023 - 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/config.hpp> // CUTE_HOST_DEVICE#include <cute/tensor_impl.hpp> // cute::Tensor#include <cute/util/type_traits.hpp> // cute::__CUTE_REQUIRES#include <cute/container/tuple.hpp> // cute::is_tuple#include <cute/numeric/integral_constant.hpp> // cute::is_constant, cute::is_integral#include <cute/atom/copy_traits.hpp> // cute::Copy_Traits#include <cute/atom/mma_atom.hpp> // cute::TiledMMA
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...>;
// Bit and Thr layouts from the Copy_Traits 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{});
// Additional Trait parameters/transformations 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}; }
// // Tensor call interfaces //
// Check and call instruction, or recurse 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) { // Dispatch to unpack to execute instruction 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) { // If the size of the src/dst doesn't match the instruction, // recurse this rank-1 layout by peeling off the mode // ((A,B,C,...)) -> (A,B,C,...) 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."); } }
// Accept mutable temporaries 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); }};
//// A tiling of copy atoms//
template <class TiledCopy, class ThrIdx>struct ThrCopy;
template <class Copy_Atom, class LayoutCopy_TV, // (tid,vid) -> coord [Need not be 2D...] class ShapeTiler_MN> // coord spacestruct TiledCopy : Copy_Atom{ // Layout information from the CopyAtom using AtomThrID = typename Copy_Atom::ThrID; // thrid -> thr_idx using AtomLayoutSrc = typename Copy_Atom::ValLayoutSrc; // (thr,val) -> offset using AtomLayoutDst = typename Copy_Atom::ValLayoutDst; // (thr,val) -> offset using AtomLayoutRef = typename Copy_Atom::ValLayoutRef; // (thr,val) -> offset
using AtomNumThr = decltype(size<0>(AtomLayoutRef{})); using AtomNumVal = decltype(size<1>(AtomLayoutRef{}));
// Layout information for the TiledCopy 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");
// Tile a tensor or a layout from shape // (M,N,...) // to shape // ((ThrV,ThrX),FrgV,(RestM,RestN,...)) // where // ThrV: The threads local to a COPY_ATOM Src. // ThrX: The threads tiled across COPY_ATOMs Src. // FrgV: The values local to a COPY_ATOM Src. // RestM: The values tiled in M. // RestN: The values tiled in N. 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.");
// Tile the stensor and compute the (src-thr, src-val) -> (ref-thr, ref-val) layout return tile2thrfrg(zipped_divide(stensor,Tiler_MN{}), right_inverse(AtomLayoutRef{}).compose(AtomLayoutSrc{})); }
// Tile a tensor or a layout from shape // (M,N,...) // to shape // ((ThrV,ThrX),FrgV,(RestM,RestN,...)) // where // ThrV: The threads local to a COPY_ATOM Dst. // ThrX: The threads tiled across COPY_ATOMs Dst. // FrgV: The values local to a COPY_ATOM Dst. // RestM: The values tiled in M. // RestN: The values tiled in N. 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.");
// Tile the dtensor and compute the (dst-thr, dst-val) -> (ref-thr, ref-val) layout return tile2thrfrg(zipped_divide(dtensor,Tiler_MN{}), right_inverse(AtomLayoutRef{}).compose(AtomLayoutDst{})); }
// Tile a tensor or a layout from shape // ((TileM,TileN,...), (RestM,RestN,...)) // to shape // ((ThrV,ThrX),FrgV,(RestM,RestN,...)) template <class Tensor, class Ref2TrgLayout> CUTE_HOST_DEVICE constexpr static auto tile2thrfrg(Tensor&& tensor, Ref2TrgLayout const& ref2trg) { // Take the thrs/vals that the atom is interested in // NOTE: Assumes the AtomNumThr are contiguous and identity within TiledThrID auto atom_layout_TV = zipped_divide(TiledLayout_TV{}, make_shape(AtomNumThr{}, AtomNumVal{})); // ((atom_tid,atom_val),(rest_tid,rest_val)) -> (m,n)
// Transform to the trg layout auto trg_layout_TV = atom_layout_TV.compose(ref2trg, _); // ((trg_tid,trg_val),(rest_tid,rest_val)) -> (m,n)
// Transform the thrs mode from thrid to thr_idx // NOTE: Assumes the AtomNumThr are contiguous and identity within TiledThrID auto thrval2mn = coalesce(zip(trg_layout_TV), Shape<_1,Shape<_1,_1>>{}); // ((trg_tid,rest_tid),(trg_val,rest_val)) -> (m,n)
/// ==================
// Transform the tile mode auto tv_tensor = tensor.compose(thrval2mn, _); // ((thrid,val),(RestM,RestN,...))
// Unfold and return return tv_tensor(make_coord(_,_), _); }
// retile_S and retile_D assume they are working with the reference layout -- they are the same template <class Tensor> CUTE_HOST_DEVICE constexpr static auto retile(Tensor&& tensor) { constexpr int R = remove_cvref_t<Tensor>::rank; // Assert that AtomLayoutSrc|Dst is identity so we can skip the Ref transformation
// Assume the first size<0>(tensor) elements are the first val_ids in TiledLayout_TV. // Then, we only need the shape+layout of those size<0>(tensor) elements in TiledLayout_TV // and that shape is what we gather from the other modes of tensor
auto V = size<0>(tensor);
auto frg_layout_mn = upcast<TiledNumThr{} * V>(right_inverse(TiledLayout_TV{}).with_shape(shape(Tiler_MN{}))); // (m,n) -> v_idx -- The shape and order of the V inside of TiledLayout_TV
auto frg_layout_v = zipped_divide(logical_product(make_layout(V), right_inverse(frg_layout_mn)), make_layout(AtomNumVal{})); // (atom_vals,rest_vals) -> (v,m,n)
/// =======
// Tile the tensor for TileFrg auto t_tensor = zipped_divide(tensor, prepend(product_each(shape(frg_layout_mn)), V)); // ((TileV,TileM,TileN,...),(1,RestM,RestN,...))
// Transform the tile mode auto v_tensor = t_tensor.compose(frg_layout_v, _); // ((atom_vals,rest_vals),(1,RM,RN,...))
// Unfold and return return v_tensor(_, append<R>(Int<0>{},_)); }
CUTE_HOST_DEVICE constexpr static auto get_layoutS_TV() { // (M,N) -> (M,N) auto ref_S = make_layout(make_shape(shape(Tiler_MN{}), Int<1>{})); // (thr_idx,val_idx) -> (M,N) return tile2thrfrg(ref_S, right_inverse(AtomLayoutRef{}).compose(AtomLayoutSrc{}))(_,_,Int<0>{}); }
CUTE_HOST_DEVICE constexpr static auto get_layoutS_MN() { // (thr_idx,val_idx) -> (M,N) auto layoutS_TV = get_layoutS_TV(); // (M,K) -> (thr_idx,val_idx) auto layoutS_MK = right_inverse(layoutS_TV).with_shape(shape(Tiler_MN{}));
// athrid = (v,m,k) -> thr_idx 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() { // (M,N) -> (M,N) auto ref_D = make_layout(make_shape(shape(Tiler_MN{}), Int<1>{})); // (thr_idx,val_idx) -> (M,N) return tile2thrfrg(ref_D, right_inverse(AtomLayoutRef{}).compose(AtomLayoutDst{}))(_,_,Int<0>{}); }
CUTE_HOST_DEVICE constexpr static auto get_layoutD_MN() { // (thr_idx,val_idx) -> (M,N) auto layoutD_TV = get_layoutD_TV(); // (M,K) -> (thr_idx,val_idx) auto layoutD_MK = right_inverse(layoutD_TV).with_shape(shape(Tiler_MN{}));
// athrid = (v,m,k) -> thr_idx 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 { //static_assert(sizeof(typename remove_cvref_t<STensor>::value_type) == sizeof(typename TiledCopy::ValType), // "Expected ValType for tiling SrcTensor."); 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 { //static_assert(sizeof(typename remove_cvref_t<DTensor>::value_type) == sizeof(typename TiledCopy::ValType), // "Expected ValType for tiling DstTensor."); 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) { // static_assert(sizeof(typename remove_cvref_t<STensor>::value_type) == sizeof(typename TiledCopy::ValType), // "Expected ValType for tiling SrcTensor."); return make_tensor(static_cast<STensor&&>(stensor).data(), TiledCopy::retile(stensor.layout())); }
template <class DTensor> CUTE_HOST_DEVICE static auto retile_D(DTensor&& dtensor) { // static_assert(sizeof(typename remove_cvref_t<DTensor>::value_type) == sizeof(typename TiledCopy::ValType), // "Expected ValType for tiling DstTensor."); return make_tensor(static_cast<DTensor&&>(dtensor).data(), TiledCopy::retile(dtensor.layout())); }};
template <class... Args, class LayoutCopy_TV, class Tiler>CUTE_HOST_DEVICEautomake_tiled_copy_impl(Copy_Atom<Args...> const& atom, LayoutCopy_TV const&, Tiler const&){ return TiledCopy<Copy_Atom<Args...>, LayoutCopy_TV, Tiler>{atom};}
//// These tile the Copy_Atom as a whole//
template <class... CArgs, class... MArgs>CUTE_HOST_DEVICEautomake_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_DEVICEautomake_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_DEVICEautomake_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)));}
// returns the smallest tiled copy that can retile LayoutC_TV// for use with pipelined epilogues with subtiled storestemplate <class... CArgs, class... MArgs>CUTE_HOST_DEVICEautomake_tiled_copy_C_atom(Copy_Atom<CArgs...> const& copy_atom, TiledMMA<MArgs...> const& mma){ // Truncate the V-layout to just the Copy_Atom, keep the V-order 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)));
// Recompute tiler and restride the TV layout for the new tiler
// Tiler -- Find the active elements in the MMA tensor and generate a tiler to extract them // Convert to the awkward by-mode tiler to preserve the modes of the tiled MMA 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)); });
// Layout_TV -- Find the (tid,vid) -> tile coord transformation // Apply the tiler to a reference and transform the codomain // tile_coord -> mma_coord auto tile2mma = composition(make_layout(mma_tiler), tiler);
// (tid,vid) -> tile_coord auto layout_tv = composition(left_inverse(tile2mma), layout_TV);
return make_tiled_copy_impl(copy_atom, layout_tv, tiler);}
/** Produce a TiledCopy from logical thread and values layouts. * The thread and value layouts map coordinates to thr_idx and val_idx. * The product of these layouts is taken to produce the TV layout and the Tiler. * Useful when threads and values need very specific mappings onto coordinates * in the target tensors. */template <class... Args, class ThrLayout, class ValLayout = Layout<_1>>CUTE_HOST_DEVICEautomake_tiled_copy(Copy_Atom<Args...> const& copy_atom, ThrLayout const& thr_layout = {}, // (m,n) -> thr_idx ValLayout const& val_layout = {}) // (m,n) -> val_idx{ // Take the raked_products to compute the Layout_MN // (M,N) -> (thr_idx, val_idx) auto layout_mn = raked_product(thr_layout, val_layout); // (thr_idx, val_idx) -> (M,N) auto layout_tv = right_inverse(layout_mn).with_shape(make_shape(size(thr_layout), size(val_layout))); // Tiler for extracting relevant elements // (M,N) -> tensor coord 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);}
/** Produce a TiledCopy from thread and value offset maps. * The TV Layout maps threads and values to the codomain of the data_layout. * It is verified that the intended codomain is valid within data_layout. * Useful when threads and values don't care about owning specific coordinates, but * care more about the vector-width and offsets between them. */template <class... Args, class AtomTVLayout, class DataLayout>CUTE_HOST_DEVICE constexprautomake_cotiled_copy(Copy_Atom<Args...> const& copy_atom, AtomTVLayout const& atom_tv_layout, // atom (thr,val) -> data addr DataLayout const& data_layout) // coord -> data addr The target layout{ static_assert(is_static<AtomTVLayout>::value); static_assert(is_static<DataLayout>::value);
// data addr -> data coord Append 1:0 so off-the-ends get the stride-0 auto inv_data_layout = make_layout(left_inverse(data_layout), Layout<_1,_0>{});
// (tid,vid) -> data_coord auto layout_tv_data = composition(inv_data_layout, atom_tv_layout);
// Check validity 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."); // // Tiler -- Find the active elements in the DATA tensor and generate a tiler to extract them //
// Convert to the awkward by-mode tiler to preserve the modes of the tiled DATA 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)); });
// // Layout_TV -- Find the (tid,vid) -> tile coord transformation //
// Apply the tiler to a reference and transform the codomain // tile_coord -> data_coord auto tile2data = composition(make_layout(flat_data_shape), tiler);
// (tid,vid) -> tile_coord auto layout_tv = composition(left_inverse(tile2data), layout_tv_data); return make_tiled_copy_impl(copy_atom, layout_tv, tiler);}
// Make a TiledCopy out of the copy_atom that matches the Src-Layout of tiled_copytemplate <class... Args, class TiledCopy>CUTE_HOST_DEVICEautomake_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{});}
// Make a TiledCopy out of the copy_atom that matches the Dst-Layout of tiled_copytemplate <class... Args, class TiledCopy>CUTE_HOST_DEVICEautomake_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{});}
//// Size//
// The logical size of a TileCopytemplate <int... I, class... Args>CUTE_HOST_DEVICE constexprautotile_size(TiledCopy<Args...> const&){ return size<I...>(typename TiledCopy<Args...>::Tiler_MN{});}
// The number of threads involved in a TiledCopytemplate <class... Args>CUTE_HOST_DEVICE constexprautosize(TiledCopy<Args...> const&){ return typename TiledCopy<Args...>::TiledNumThr{};}
//// Display utilities//
template <class... Args, class T>CUTE_HOST_DEVICEvoidprint(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_DEVICEvoidprint(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_DEVICEvoidprint(ThrCopy<TiledCopy, ThrIdx> const& thr_copy){ print("ThrCopy\n"); print(" ThrIdx: "); print(thr_copy.thr_idx_); print("\n"); print(TiledCopy{});}
// TiledCopy to LaTeX TikZtemplate <class... Args, class TikzColorFn = TikzColor_TV>CUTE_HOST_DEVICEautoprint_latex(TiledCopy<Args...> const& copy, TikzColorFn color = {}) // lambda(thr_idx,val_idx) -> tikz color string{ 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);}
// MNK Copy Layout to LaTeX TikZtemplate <class LayoutS, class ThrIDS, class LayoutD, class ThrIDD, class TikzColorFn = TikzColor_TV>CUTE_HOST_DEVICEvoidprint_latex_copy(LayoutS const& S, ThrIDS const& TS, // (m,n) -> (tid,vid) and tid -> thr_idx LayoutD const& D, ThrIDD const& TD, // (m,n) -> (tid,vid) and tid -> thr_idx TikzColorFn color = {}) // lambda(thr_idx,val_idx) -> tikz color string{ 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));
// Commented prints 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");
// Header 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");
// S starting at 0,0 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); } } // Grid 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))); // S Labels 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); }
// D starting at 0,size<1>(S)+3 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); } } // Grid 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)); // D Labels 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); }
// Footer printf("\\end{tikzpicture}\n" "\\end{document}\n");}
} // end namespace cute
////////////////////////////////////////////////////////////////////////////////////////////////////
#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>
// Config#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
////////////////////////////////////////////////////////////////////////////////////////////////////123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162/*************************************************************************************************** * Copyright (c) 2023 - 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/copy.hpp>
#include <cute/tensor_impl.hpp>
namespace cute{
/** * concept Copy_Traits * { * using ThrID = // Logical thread id (tid) -> tidx * * using SrcLayout = // (Logical src thread id (tid), Logical src value id (vid)) -> bit * using DstLayout = // (Logical dst thread id (tid), Logical dst value id (vid)) -> bit * using RefLayout = // (Logical ref thread id (tid), Logical ref value id (vid)) -> bit * }; * * The abstract bit ordering of the Copy_Traits (the codomain of SrcLayout, DstLayout, and RefLayout) * is arbitrary and only used to construct maps * (ref-tid,ref-vid) -> (src-tid,src-vid) * (ref-tid,ref-vid) -> (dst-tid,dst-vid) * in TiledCopy. The Layout_TV in TiledCopy is in accordance with the RefLayout of a Traits, then mapped to * the Src or Dst (tid,vid) representation on demand. * */
template <class CopyOperation, class... CopyOpArgs>struct Copy_Traits{ static_assert(dependent_false<CopyOperation>, "Copy_Traits not implemented for this CopyOperation.");};
template <class S, class D>struct Copy_Traits<UniversalCopy<S,D>>{ // Logical thread id to thread idx (one-thread) using ThrID = Layout<_1>;
// Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_1,Int<sizeof_bits<S>::value>>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_1,Int<sizeof_bits<D>::value>>>;
// Reference map from (thr,val) to bit using RefLayout = SrcLayout;};
template <int MaxVecBits>struct Copy_Traits<AutoVectorizingCopyWithAssumedAlignment<MaxVecBits>>{ // Logical thread id to thread idx (one-thread) using ThrID = Layout<_1>;
// Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_1,_1>, Stride<_0,_0>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_1,_1>, Stride<_0,_0>>;
// Reference map from (thr,val) to bit using RefLayout = SrcLayout;};
// Extract a CPY_Op from a CPY_Traitstemplate <class CPY_Traits>struct CPY_Op {};
template <class CPY_Op_Arg, class... Args>struct CPY_Op<Copy_Traits<CPY_Op_Arg, Args...>> { using type = CPY_Op_Arg;}; //// Generic copy_unpack for common argument-based Copy_Traits//
template <class AnyCPYTraits, class SEngine, class SLayout, class DEngine, class DLayout>CUTE_HOST_DEVICE constexprvoidcopy_unpack(AnyCPYTraits const&, Tensor<SEngine,SLayout> const& src, Tensor<DEngine,DLayout> & dst){ using CopyOp = typename CPY_Op<AnyCPYTraits>::type; using RegistersSrc = typename CopyOp::SRegisters; using RegistersDst = typename CopyOp::DRegisters; using RegTypeSrc = typename remove_extent<RegistersSrc>::type; using RegTypeDst = typename remove_extent<RegistersDst>::type; constexpr int RegNumSrc = extent<RegistersSrc>::value; constexpr int RegNumDst = extent<RegistersDst>::value;
Tensor rS = recast<RegTypeSrc>(src); Tensor rD = recast<RegTypeDst>(dst);
CUTE_STATIC_ASSERT_V(size(rS) == Int<RegNumSrc>{}, "Copy_Traits: src failed to vectorize into registers. Layout is incompatible with this CopyOp."); CUTE_STATIC_ASSERT_V(size(rD) == Int<RegNumDst>{}, "Copy_Traits: dst failed to vectorize into registers. Layout is incompatible with this CopyOp.");
detail::explode(detail::CallCOPY<CopyOp>{}, rS, make_int_sequence<RegNumSrc>{}, rD, make_int_sequence<RegNumDst>{});}
// Accept mutable temporariestemplate <class AnyCPYTraits, class SEngine, class SLayout, class DEngine, class DLayout>CUTE_HOST_DEVICE constexprvoidcopy_unpack(AnyCPYTraits const& traits, Tensor<SEngine,SLayout> const& src, Tensor<DEngine,DLayout> && dst){ copy_unpack(traits, src, dst);}
namespace detail {
template <class CopyOp, class = void>constexpr bool is_prefetch = false;
template <class CopyOp>constexpr bool is_prefetch<CopyOp, void_t<typename CopyOp::PREFETCH>> = is_same_v<CopyOp, typename CopyOp::PREFETCH>;
} // end namespace detail
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488/*************************************************************************************************** * Copyright (c) 2023 - 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
/*! \file \brief im2col make_tma_copy */
#include "cute/arch/copy_sm90.hpp"#include "cute/arch/copy_sm90_desc.hpp"#include "cute/atom/copy_traits_sm90_im2col.hpp"#include "cute/tensor.hpp"
namespace cute {
struct SM100_TMA_2SM_LOAD_IM2COL_OP : SM100_TMA_2SM_LOAD_IM2COL {};
/// @brief Non-executable specialization of Copy_Traits for SM100/// im2col TMA load, with TMA descriptor but no barrier.////// Use `.with(memory_barrier)` to construct an executable version.template <class NumBitsPerTMA, class TMATensor>struct Copy_Traits<SM100_TMA_2SM_LOAD_IM2COL, NumBitsPerTMA, TMATensor>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
Im2ColTmaDescriptor tma_desc_; TMATensor tma_tensor_;
CUTE_HOST_DEVICE constexpr Im2ColTmaDescriptor const* get_tma_descriptor() const { return &tma_desc_; }
template <class GShape> CUTE_HOST_DEVICE constexpr TMATensor const get_tma_tensor(GShape const&) const { return tma_tensor_; }
/// @brief Get an executable specialization. /// /// Copy_Traits specializations with SM100_TMA_2SM_LOAD_IM2COL are not /// directly executable. Instead, call this "with" member function /// to get an executable specialization. "Executable" means that /// @c copy_unpack works. /// /// @param tma_mbar Memory barrier for synchronization /// /// @param multicast_mask Multicast mask (unused; only exists /// for consistency with the actual multicast Copy_Traits /// specialization) /// /// @return Executable specialization of @c Copy_Traits CUTE_HOST_DEVICE constexpr Copy_Traits<SM100_TMA_2SM_LOAD_IM2COL_OP, NumBitsPerTMA> with(uint64_t& tma_mbar, [[maybe_unused]] uint16_t const& multicast_mask = 0) const { return {{}, {&tma_desc_, &tma_mbar}}; }
// Copy_Traits specializations with SM100_TMA_2SM_LOAD_IM2COL // are not directly executable. Instead, call .with // to get an executable specialization. template <class TS, class SLayout, class TD, class DLayout> CUTE_HOST_DEVICE friend constexpr void copy_unpack(Copy_Traits const& traits, Tensor<TS,SLayout> const& src, Tensor<TD,DLayout> & dst) = delete;};
/// TMA load, with TMA descriptor and barrier.template <class NumBitsPerTMA>struct Copy_Traits<SM100_TMA_2SM_LOAD_IM2COL_OP, NumBitsPerTMA> : TMA_LOAD_IM2COL_Unpack<SM100_TMA_2SM_LOAD_IM2COL_OP>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
// SM100_TMA_2SM_LOAD_IM2COL arguments tuple< Im2ColTmaDescriptor const*, uint64_t* // smem mbarrier > const opargs_;};
/////////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD_MULTICAST ///////////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_OP : SM100_TMA_2SM_LOAD_IM2COL_MULTICAST {};
/// @brief Non-executable specialization of Copy_Traits for SM100/// im2col TMA load, with TMA descriptor but no barrier or multicast/// mask.////// Use `.with(memory_barrier)` to construct an executable version.template <class NumBitsPerTMA, class TMATensor>struct Copy_Traits<SM100_TMA_2SM_LOAD_IM2COL_MULTICAST, NumBitsPerTMA, TMATensor>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
Im2ColTmaDescriptor tma_desc_; TMATensor tma_tensor_;
CUTE_HOST_DEVICE constexpr Im2ColTmaDescriptor const* get_tma_descriptor() const { return &tma_desc_; }
template <class GShape> CUTE_HOST_DEVICE constexpr TMATensor const get_tma_tensor(GShape const&) const { return tma_tensor_; }
/// @brief Get an executable specialization. /// /// Copy_Traits specializations with SM100_TMA_2SM_LOAD_IM2COL_MULTICAST /// are not directly executable. Instead, call this "with" member /// function to get an executable specialization. "Executable" /// means that @c copy_unpack works. /// /// @param tma_mbar Memory barrier for synchronization /// /// @param multicast_mask Multicast mask (defaults to a single CTA) /// /// @return Executable specialization of @c Copy_Traits CUTE_HOST_DEVICE constexpr Copy_Traits<SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_OP, NumBitsPerTMA> with(uint64_t& tma_mbar, uint16_t const& multicast_mask) const { return {{}, {&tma_desc_, &tma_mbar, multicast_mask}}; }
// Copy_Traits specializations with SM100_TMA_LOAD_IM2COL_MULTICAST // are not directly executable. Instead, call .with to get an // executable specialization. template <class TS, class SLayout, class TD, class DLayout> CUTE_HOST_DEVICE friend constexpr void copy_unpack(Copy_Traits const& traits, Tensor<TS,SLayout> const& src, Tensor<TD,DLayout> & dst) = delete;};
/// @brief Executable specialization of Copy_Traits for SM100 multicast/// im2col TMA load, with TMA descriptor, barrier, and multicast mask.template <class NumBitsPerTMA>struct Copy_Traits<SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_OP, NumBitsPerTMA> : TMA_LOAD_IM2COL_Unpack<SM100_TMA_2SM_LOAD_IM2COL_MULTICAST_OP>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit. using SrcLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2, NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
// SM100_TMA_2SM_LOAD_IM2COL_MULTICAST arguments tuple< Im2ColTmaDescriptor const*, uint64_t*, // smem mbarrier uint16_t // multicast mask > const opargs_;};
////////////////////////////////////// Make TMA///////////////////////////////////
#if !defined(__CUDACC_RTC__)/** Make a CuTe CTA-collective TiledCopy for a TMA operation. * * @param CopyOp The target copy operation: SM100_TMA_2SM_LOAD * @param gtensor The GMEM Tensor to be involved in the TMA. * @param slayout The SMEM Layout to be involved in the TMA. * @param cluster_tile The Cluster-local tile that each Cluster will be tiling GMEM with. * This is often the cluster_tile_shape that is used to tile the GMEM: * local_tile(gtensor, cluster_tile_shape, cluster_coord) * -> Cluster-local tile of GMEM * @param mma The TiledMMA that defines the Cluster-Tile to Block-Tile partitioning. * * This code attempts to maximize the TMA box size. It does this by tracing * the SMEM "vector" -- the inverse of the smem layout -- to find the largest * contiguous array of smem that can be written to/from global memory given * the constraints that the TMA instruction imposes. * * This is accomplished by assigning "basis" strides to the GMEM to track which * modes of SMEM map to which modes of GMEM, then reordering the modes of GMEM according * to the SMEM vector, and then using those GMEM/SMEM modes to fill in the desc. * * Examples: */template <class CopyOp, class GEngine, class GLayout, class SLayout, class Cluster_Tile, class... Args, class LowerCornerStride, class UpperCornerStride, class LowerPaddingStride, class UpperPaddingStride, class TraversalStride, class LowerSRTStride, class DilationStride>CUTE_HOSTautomake_im2col_tma_copy_A_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (M,K,...) SLayout const& slayout, // (MMA, MMA_M, MMA_K) Cluster_Tile const& cluster_tile, // (TILE_M,TILE_N,TILE_K) TiledMMA<Args...> const& mma, LowerCornerStride const& lower_corner_whd, UpperCornerStride const& upper_corner_whd, LowerPaddingStride const& lower_padding_whd, UpperPaddingStride const& upper_padding_whd, TraversalStride const& stride_whd, LowerSRTStride const& lower_srt, DilationStride const& stride_srt, TMA::DescriptorAuxParams const& aux_params = {}){ constexpr int R = GLayout::rank; // Keep only MK modes from MNK auto cluster_tile_shape = append<R>(make_shape(get<0>(cluster_tile), get<2>(cluster_tile)), Int<1>{}); auto cluster_layout = make_identity_layout(cluster_tile_shape); // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_A(cluster_layout))(_, repeat<R>(_));
auto cta_t_vmnk_strides = [](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL_MULTICAST>) { return Stride<_0,_0,_1,_0>{}; // VMNK: Use only the N-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL>) { return Stride<_0,_0,_0,_0>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
auto cta_t_shape = shape(mma.get_thr_layout_vmnk()); // cta rank -> logical cta idx auto cta_t_map = make_layout(cta_t_shape, compact_col_major(cta_t_shape, cta_t_vmnk_strides));
return detail::make_tma_copy_im2col(copy_op, gtensor, slayout, cta_t_map, cta_v_tile, lower_corner_whd, upper_corner_whd, lower_padding_whd, upper_padding_whd, stride_whd, lower_srt, stride_srt, aux_params);}
template <class CopyOp, class GEngine, class GLayout, class SLayout, class Cluster_Tile, class... Args, class LowerCornerStride, class UpperCornerStride, class LowerPaddingStride, class UpperPaddingStride, class TraversalStride, class LowerSRTStride, class DilationStride>CUTE_HOSTautomake_im2col_tma_copy_B_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (N,K,...) SLayout const& slayout, // (MMA, MMA_N, MMA_K) Cluster_Tile const& cluster_tile, // (TILE_M,TILE_N,TILE_K) TiledMMA<Args...> const& mma, LowerCornerStride const& lower_corner_whd, UpperCornerStride const& upper_corner_whd, LowerPaddingStride const& lower_padding_whd, UpperPaddingStride const& upper_padding_whd, TraversalStride const& stride_whd, LowerSRTStride const& lower_srt, DilationStride const& stride_srt, TMA::DescriptorAuxParams const& aux_params = {}){ constexpr int R = GLayout::rank; // Keep only NK modes from MNK auto cluster_tile_shape = append<R>(make_shape(get<1>(cluster_tile), get<2>(cluster_tile)), Int<1>{}); auto cluster_layout = make_identity_layout(cluster_tile_shape); // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_B(cluster_layout))(_, repeat<R>(_));
auto cta_t_vmnk_strides = [](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL_MULTICAST>) { return Stride<_0,_1,_0,_0>{}; // VMNK: Use only the M-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL>) { return Stride<_0,_0,_0,_0>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
auto cta_t_shape = shape(mma.get_thr_layout_vmnk()); // cta rank -> logical cta idx auto cta_t_map = make_layout(cta_t_shape, compact_col_major(cta_t_shape, cta_t_vmnk_strides));
return detail::make_tma_copy_im2col(copy_op, gtensor, slayout, cta_t_map, cta_v_tile, lower_corner_whd, upper_corner_whd, lower_padding_whd, upper_padding_whd, stride_whd, lower_srt, stride_srt, aux_params);}
/////////////////////////////////////// Experimental Make Im2col TMA Atom/////////////////////////////////////
template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class MMA_Tiler, class... Args, class ClusterShapeVMNK, class LowerCornerStride, class UpperCornerStride, class LowerPaddingStride, class UpperPaddingStride, class TraversalStride, class LowerSRTStride, class DilationStride>CUTE_HOSTautomake_im2col_tma_atom_A_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (M, K, ...) SLayout const& slayout, // (MMA, MMA_M, MMA_K, ...) MMA_Tiler const& mma_tiler, // (TILE_M, TILE_N, TILE_K, ...) TiledMMA<Args...> const& mma, ClusterShapeVMNK const& cluster_shape, // (CTA_V, CTA_M, CTA_N, CTA_K) LowerCornerStride const& lower_corner_whd, UpperCornerStride const& upper_corner_whd, LowerPaddingStride const& lower_padding_whd, UpperPaddingStride const& upper_padding_whd, TraversalStride const& stride_whd, LowerSRTStride const& lower_srt, DilationStride const& stride_srt, TMA::DescriptorAuxParams const& aux_params = {}){ constexpr int R = GLayout::rank; // Keep only MK modes from MNK auto cluster_tile_shape = append<R>(make_shape(get<0>(mma_tiler), get<2>(mma_tiler)), Int<1>{}); auto cluster_layout = make_identity_layout(cluster_tile_shape); // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_A(cluster_layout))(_, repeat<R>(_));
// The size of the multicasting auto num_multicast = [&](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL_MULTICAST>) { return size<2>(cluster_shape); // VMNK: Use only the N-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL> || is_same_v<CopyOp, SM90_TMA_STORE_IM2COL> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL>) { return Int<1>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
return detail::make_tma_atom_im2col(copy_op, gtensor, slayout, num_multicast, cta_v_tile, lower_corner_whd, upper_corner_whd, lower_padding_whd, upper_padding_whd, stride_whd, lower_srt, stride_srt, aux_params);}
template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class MMA_Tiler, class... Args, class ClusterShapeVMNK, class LowerCornerStride, class UpperCornerStride, class LowerPaddingStride, class UpperPaddingStride, class TraversalStride, class LowerSRTStride, class DilationStride>CUTE_HOSTautomake_im2col_tma_atom_B_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (N, K, ...) SLayout const& slayout, // (MMA, MMA_N, MMA_K, ...) MMA_Tiler const& mma_tiler, // (TILE_M, TILE_N, TILE_K, ...) TiledMMA<Args...> const& mma, ClusterShapeVMNK const& cluster_shape, // (CTA_V, CTA_M, CTA_N, CTA_K) LowerCornerStride const& lower_corner_whd, UpperCornerStride const& upper_corner_whd, LowerPaddingStride const& lower_padding_whd, UpperPaddingStride const& upper_padding_whd, TraversalStride const& stride_whd, LowerSRTStride const& lower_srt, DilationStride const& stride_srt, TMA::DescriptorAuxParams const& aux_params = {}){ constexpr int R = GLayout::rank; // Keep only NK modes from MNK auto cluster_tile_shape = append<R>(make_shape(get<1>(mma_tiler), get<2>(mma_tiler)), Int<1>{}); auto cluster_layout = make_identity_layout(cluster_tile_shape); // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_B(cluster_layout))(_, repeat<R>(_));
// The size of the multicasting auto num_multicast = [&](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL_MULTICAST>) { return size<1>(cluster_shape); // VMNK: Use only the M-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_IM2COL> || is_same_v<CopyOp, SM90_TMA_STORE_IM2COL> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_IM2COL>) { return Int<1>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
return detail::make_tma_atom_im2col(copy_op, gtensor, slayout, num_multicast, cta_v_tile, lower_corner_whd, upper_corner_whd, lower_padding_whd, upper_padding_whd, stride_whd, lower_srt, stride_srt, aux_params);}#endif // !defined(__CUDACC_RTC__)
} // end namespace cute123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487/*************************************************************************************************** * Copyright (c) 2021 - 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
#if !defined(__CUDACC_RTC__)#include <cuda.h>#endif
#include <cute/tensor.hpp>#include <cute/atom/copy_traits_sm90_tma.hpp>#include <cute/arch/copy_sm100_tma.hpp>#include <cute/atom/copy_traits.hpp>
namespace cute{
//////////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_OP : SM100_TMA_2SM_LOAD {};
// The non-executable SM100_TMA_2SM_LOAD with tma_desc and no tma_mbar// Use .with(tma_mbar) to construct an executable versiontemplate <class NumBitsPerTMA, class AuxParams_>struct Copy_Traits<SM100_TMA_2SM_LOAD, NumBitsPerTMA, AuxParams_>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
// SM100_TMA_2SM_LOAD arguments TmaDescriptor tma_desc_; using AuxParams = AuxParams_; AuxParams aux_params_;
// Return TmaDescriptor/TensorMap CUTE_HOST_DEVICE constexpr TmaDescriptor const* get_tma_descriptor() const { return &tma_desc_; }
// Construct an executable SM100_TMA_2SM_LOAD with tma_mbar CUTE_HOST_DEVICE constexpr Copy_Traits<SM100_TMA_2SM_LOAD_OP, NumBitsPerTMA> with( uint64_t& tma_mbar, [[maybe_unused]] uint16_t const& multicast_mask = 0, TMA::CacheHintSm100 const& cache_hint = TMA::CacheHintSm100::EVICT_NORMAL) const { // We accept multicast_mask here to keep the API for both atoms consistent return {{}, {&tma_desc_, &tma_mbar, static_cast<uint64_t>(cache_hint)}}; }
// Construct an executable SM100_TMA_2SM_LOAD with tma_mbar (temp. overloaded for grouped gemm/ptr array gemm) CUTE_HOST_DEVICE constexpr Copy_Traits<SM100_TMA_2SM_LOAD_OP, NumBitsPerTMA> with( TmaDescriptor const* new_tma_desc, uint64_t& tma_mbar, [[maybe_unused]] uint16_t const& multicast_mask = 0, TMA::CacheHintSm100 const& cache_hint = TMA::CacheHintSm100::EVICT_NORMAL) const { // We accept multicast_mask here to keep the API for both atoms consistent return {{}, {new_tma_desc, &tma_mbar, static_cast<uint64_t>(cache_hint)}}; }
template <class GShape> CUTE_HOST_DEVICE constexpr auto get_tma_tensor(GShape const& g_shape) const { static_assert(is_congruent<decltype(g_shape), decltype(aux_params_.g_stride_)>::value); return make_counting_tensor(make_layout(g_shape, aux_params_.g_stride_)); }
// Don't try to execute a copy with SM100_TMA_2SM_LOAD before calling .with() template <class TS, class SLayout, class TD, class DLayout> CUTE_HOST_DEVICE friend constexpr void copy_unpack(Copy_Traits const& traits, Tensor<TS,SLayout> const& src, Tensor<TD,DLayout> & dst) = delete;};
// The executable SM100_TMA_2SM_LOAD with tma_desc and tma_mbartemplate <class NumBitsPerTMA>struct Copy_Traits<SM100_TMA_2SM_LOAD_OP, NumBitsPerTMA> : TMA_LOAD_Unpack<SM100_TMA_2SM_LOAD_OP, NumBitsPerTMA>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
// SM100_TMA_2SM_LOAD arguments tuple< TmaDescriptor const*, uint64_t*, // smem mbarrier uint64_t // cache hint > const opargs_;};
/////////////////////////////////////////////////////////////////////////////////////////////////////////// TMA_LOAD_MULTICAST ///////////////////////////////////////////////////////////////////////////////////////////////////////////
struct SM100_TMA_2SM_LOAD_MULTICAST_OP : SM100_TMA_2SM_LOAD_MULTICAST {};
template <class NumBitsPerTMA, class AuxParams_>struct Copy_Traits<SM100_TMA_2SM_LOAD_MULTICAST, NumBitsPerTMA, AuxParams_>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
// SM100_TMA_2SM_LOAD_MULTICAST_OP arguments TmaDescriptor tma_desc_; using AuxParams = AuxParams_; AuxParams aux_params_;
// Return TmaDescriptor/TensorMap CUTE_HOST_DEVICE constexpr TmaDescriptor const* get_tma_descriptor() const { return &tma_desc_; }
// Construct an executable SM100_TMA_2SM_LOAD_MULTICAST_OP with tma_mbar CUTE_HOST_DEVICE constexpr Copy_Traits<SM100_TMA_2SM_LOAD_MULTICAST_OP, NumBitsPerTMA> with( uint64_t& tma_load_mbar, uint16_t const& multicast_mask, TMA::CacheHintSm100 const& cache_hint = TMA::CacheHintSm100::EVICT_NORMAL) const { return {{}, {&tma_desc_, &tma_load_mbar, multicast_mask, static_cast<uint64_t>(cache_hint)}}; }
// Construct an executable SM100_TMA_2SM_LOAD_MULTICAST_OP with tma_mbar (temp. overloaded for grouped gemm/ptr array gemm) CUTE_HOST_DEVICE constexpr Copy_Traits<SM100_TMA_2SM_LOAD_MULTICAST_OP, NumBitsPerTMA> with( TmaDescriptor const* new_tma_desc, uint64_t& tma_load_mbar, uint16_t const& multicast_mask, TMA::CacheHintSm100 const& cache_hint = TMA::CacheHintSm100::EVICT_NORMAL) const { return {{}, {new_tma_desc, &tma_load_mbar, multicast_mask, static_cast<uint64_t>(cache_hint)}}; }
template <class GShape> CUTE_HOST_DEVICE constexpr auto get_tma_tensor(GShape const& g_shape) const { static_assert(is_congruent<decltype(g_shape), decltype(aux_params_.g_stride_)>::value); return make_counting_tensor(make_layout(g_shape, aux_params_.g_stride_)); }
// Don't try to execute a copy with SM100_TMA_2SM_LOAD_MULTICAST_OP before calling .with() template <class TS, class SLayout, class TD, class DLayout> CUTE_HOST_DEVICE friend constexpr void copy_unpack(Copy_Traits const& traits, Tensor<TS,SLayout> const& src, Tensor<TD,DLayout> & dst) = delete;};
template <class NumBitsPerTMA>struct Copy_Traits<SM100_TMA_2SM_LOAD_MULTICAST_OP, NumBitsPerTMA> : TMA_LOAD_Unpack<SM100_TMA_2SM_LOAD_MULTICAST_OP, NumBitsPerTMA>{ using ThrID = Layout<_2>; // Map from (src-thr,src-val) to bit using SrcLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Map from (dst-thr,dst-val) to bit using DstLayout = Layout<Shape<_2,NumBitsPerTMA>, Stride<NumBitsPerTMA,_1>>; // Reference map from (thr,val) to bit using RefLayout = SrcLayout;
// SM100_TMA_2SM_LOAD_MULTICAST_OP arguments tuple< TmaDescriptor const*, uint64_t*, // smem mbarrier uint16_t, // multicast mask uint64_t // cache hint > const opargs_;};
////////////////////////////////////// Make TMA///////////////////////////////////
#if !defined(__CUDACC_RTC__)/** Make a CuTe CTA-collective TiledCopy for a TMA operation. * * @param CopyOp The target copy operation: SM100_TMA_2SM_LOAD * @param gtensor The GMEM Tensor to be involved in the TMA. * @param slayout The SMEM Layout to be involved in the TMA. * @param cluster_tile The Cluster-local tile that each Cluster will be tiling GMEM with. * This is often the cluster_tile_shape that is used to tile the GMEM: * local_tile(gtensor, cluster_tile_shape, cluster_coord) * -> Cluster-local tile of GMEM * @param mma The TiledMMA that defines the Cluster-Tile to Block-Tile partitioning. * * This code attempts to maximize the TMA box size. It does this by tracing * the SMEM "vector" -- the inverse of the smem layout -- to find the largest * contiguous array of smem that can be written to/from global memory given * the constraints that the TMA instruction imposes. * * This is accomplished by assigning "basis" strides to the GMEM to track which * modes of SMEM map to which modes of GMEM, then reordering the modes of GMEM according * to the SMEM vector, and then using those GMEM/SMEM modes to fill in the desc. * * Examples: */template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class Cluster_Tiler, class... Args>CUTE_HOSTautomake_tma_copy_A_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (M, K, ...) SLayout const& slayout, // (MMA, MMA_M, MMA_K, ...) Cluster_Tiler const& cluster_tiler, // (TILER_M, TILER_N, TILER_K, ...) TiledMMA<Args...> const& mma){ // Keep only MK modes from MNK auto cluster_tiler_mk = remove<1>(cluster_tiler); // cluster tile coord -> gtensor coord auto g_tile = make_identity_layout(shape(gtensor)).compose(cluster_tiler_mk); // (TILE_M, TILE_K, ...) // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_A(g_tile))(_, repeat<rank(g_tile)>(_)); // (MMA, MMA_M, MMA_K, ...)
auto cta_t_vmnk_strides = [](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_MULTICAST>) { return Stride<_0,_0,_1,_0>{}; // VMNK: Use only the N-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD> || is_same_v<CopyOp, SM90_TMA_STORE> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD>) { return Stride<_0,_0,_0,_0>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
auto cta_t_shape = shape(mma.get_thr_layout_vmnk()); // cta rank -> logical cta idx auto cta_t_map = coalesce(make_layout(cta_t_shape, compact_col_major(cta_t_shape, cta_t_vmnk_strides)));
// Prefer TmaInternalType if specified. Fallback to GEngine::value_type using TmaType = conditional_t<is_same<void, TmaInternalType>::value, typename GEngine::value_type, TmaInternalType>; return detail::make_tma_copy_tiled<TmaType>(copy_op, gtensor, slayout, cta_t_map, cta_v_tile);}
template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class Cluster_Tiler, class... Args>CUTE_HOSTautomake_tma_copy_B_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (N, K, ...) SLayout const& slayout, // (MMA, MMA_N, MMA_K, ...) Cluster_Tiler const& cluster_tiler, // (TILE_M, TILE_N, TILE_K, ...) TiledMMA<Args...> const& mma){ // Keep only NK modes from MNK auto cluster_tiler_nk = remove<0>(cluster_tiler); // cluster tile coord -> gtensor coord auto g_tile = make_identity_layout(shape(gtensor)).compose(cluster_tiler_nk); // (TILE_N, TILE_K, ...) // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_B(g_tile))(_, repeat<rank(g_tile)>(_)); // (MMA, MMA_N, MMA_K, ...)
auto cta_t_vmnk_strides = [](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_MULTICAST>) { return Stride<_0,_1,_0,_0>{}; // VMNK: Use only the M-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD> || is_same_v<CopyOp, SM90_TMA_STORE> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD>) { return Stride<_0,_0,_0,_0>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
auto cta_t_shape = shape(mma.get_thr_layout_vmnk()); // cta rank -> logical cta idx auto cta_t_map = coalesce(make_layout(cta_t_shape, compact_col_major(cta_t_shape, cta_t_vmnk_strides)));
// Prefer TmaInternalType if specified. Fallback to GEngine::value_type using TmaType = conditional_t<is_same<void, TmaInternalType>::value, typename GEngine::value_type, TmaInternalType>; return detail::make_tma_copy_tiled<TmaType>(copy_op, gtensor, slayout, cta_t_map, cta_v_tile);}
template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class Cluster_Tiler, class... Args>CUTE_HOSTautomake_tma_copy_C_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (M, N, ...) SLayout const& slayout, // (MMA, MMA_M, MMA_N, ...) Cluster_Tiler const& cluster_tiler, // (TILE_M, TILE_N, TILE_K, ...) TiledMMA<Args...> const& mma){ // Keep only MN modes from MNK auto cluster_tiler_mn = remove<2>(cluster_tiler); // cluster tile coord -> gtensor coord auto g_tile = make_identity_layout(shape(gtensor)).compose(cluster_tiler_mn); // (TILE_M, TILE_N, ...) // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_C(g_tile))(_, repeat<rank(g_tile)>(_)); // (MMA, MMA_M, MMA_N, ...)
static_assert(is_same_v<CopyOp, SM90_TMA_LOAD> || is_same_v<CopyOp, SM90_TMA_STORE> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD>, "Unsupported TMA Op, expected a non-multicast TMA");
// No multicast, so only 1 CTA involved auto cta_t_map = Layout<_1,_0>{};
// Prefer TmaInternalType if specified. Fallback to GEngine::value_type using TmaType = conditional_t<is_same<void, TmaInternalType>::value, typename GEngine::value_type, TmaInternalType>; return detail::make_tma_copy_tiled<TmaType>(copy_op, gtensor, slayout, cta_t_map, cta_v_tile);}
////////////////////////////////////// Experimental Make TMA Atom///////////////////////////////////
template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class MMA_Tiler, class... Args, class ClusterShapeVMNK>CUTE_HOSTautomake_tma_atom_A_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (M, K, ...) SLayout const& slayout, // (MMA, MMA_M, MMA_K, ...) MMA_Tiler const& mma_tiler, // (TILE_M, TILE_N, TILE_K, ...) TiledMMA<Args...> const& mma, ClusterShapeVMNK const& cluster_shape) // (CTA_V, CTA_M, CTA_N, CTA_K){ // Keep only MK modes from MNK auto mma_tiler_mk = remove<1>(mma_tiler);
// cluster tile coord -> gtensor coord auto g_tile = make_identity_layout(shape(gtensor)).compose(mma_tiler_mk); // (TILE_M, TILE_K, ...)
// cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_A(g_tile))(_, repeat<rank(g_tile)>(_)); // (MMA, MMA_M, MMA_K, ...)
#if 0 print("(tma_a) slayout: "); print(slayout); print("\n"); print("(tma_a) mma_tiler_nk: "); print(mma_tiler_nk); print("\n"); print("(tma_a) g_tile: "); print(g_tile); print("\n"); print("(tma_a) mma_tiler: "); print(mma_tiler); print("\n"); print("(tma_a) cta_v_tile: "); print(cta_v_tile); print("\n");#endif
// The size of the multicasting auto num_multicast = [&](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_MULTICAST>) { return size<2>(cluster_shape); // VMNK: Use only the N-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD> || is_same_v<CopyOp, SM90_TMA_STORE> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD>) { return Int<1>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
// Prefer TmaInternalType if specified. Fallback to GEngine::value_type using TmaType = conditional_t<is_same<void, TmaInternalType>::value, typename GEngine::value_type, TmaInternalType>; return detail::make_tma_copy_atom<TmaType>(copy_op, gtensor, slayout, num_multicast, cta_v_tile);}
template <class TmaInternalType = void, class CopyOp, class GEngine, class GLayout, class SLayout, class MMA_Tiler, class... Args, class ClusterShapeVMNK>CUTE_HOSTautomake_tma_atom_B_sm100(CopyOp const& copy_op, Tensor<GEngine,GLayout> const& gtensor, // (N, K, ...) SLayout const& slayout, // (MMA, MMA_N, MMA_K, ...) MMA_Tiler const& mma_tiler, // (TILE_M, TILE_N, TILE_K, ...) TiledMMA<Args...> const& mma, ClusterShapeVMNK const& cluster_shape) // (CTA_V, CTA_M, CTA_N, CTA_K){ // Keep only NK modes from MNK auto mma_tiler_nk = remove<0>(mma_tiler); // cluster tile coord -> gtensor coord auto g_tile = make_identity_layout(shape(gtensor)).compose(mma_tiler_nk); // (TILE_N, TILE_K, ...) // cta val idx -> gmem mode auto cta_v_tile = layout<1>(mma.thrfrg_B(g_tile))(_, repeat<rank(g_tile)>(_)); // (MMA, MMA_N, MMA_K, ...)
#if 0 print("(tma_b) slayout: "); print(slayout); print("\n"); print("(tma_b) mma_tiler_nk: "); print(mma_tiler_nk); print("\n"); print("(tma_b) g_tile: "); print(g_tile); print("\n"); print("(tma_b) mma_tiler: "); print(mma_tiler); print("\n"); print("(tma_b) cta_v_tile: "); print(cta_v_tile); print("\n");#endif
// The size of the multicasting auto num_multicast = [&](){ if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD_MULTICAST> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD_MULTICAST>) { return size<1>(cluster_shape); // VMNK: Use only the M-CTAs in the Multicast } else if constexpr (is_same_v<CopyOp, SM90_TMA_LOAD> || is_same_v<CopyOp, SM90_TMA_STORE> || is_same_v<CopyOp, SM100_TMA_2SM_LOAD>) { return Int<1>{}; // VMNK: Use no CTAs in Non-Multicast } else { static_assert(dependent_false<CopyOp>, "Unsupported TMA"); } }();
// Prefer TmaInternalType if specified. Fallback to GEngine::value_type using TmaType = conditional_t<is_same<void, TmaInternalType>::value, typename GEngine::value_type, TmaInternalType>; return detail::make_tma_copy_atom<TmaType>(copy_op, gtensor, slayout, num_multicast, cta_v_tile);}
#endif // !defined(__CUDACC_RTC__)
} // end namespace cutelib/python3.12/site-packages/deep_gemm/__init__.pyAdded+13
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/axpby.hppAdded+95
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/clear.hppAdded+64
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/cooperative_copy.hppAdded+339
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/cooperative_gemm.hppAdded+553
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/copy.hppAdded+527
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/fill.hppAdded+87
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/functional.hppAdded+290
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/gemm.hppAdded+500
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/prefer.hppAdded+46
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/prefetch.hppAdded+145
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/tensor_algorithms.hppAdded+166
lib/python3.12/site-packages/deep_gemm/include/cute/algorithm/tuple_algorithms.hppAdded+1073
lib/python3.12/site-packages/deep_gemm/include/cute/arch/cluster_sm100.hppAdded+108
lib/python3.12/site-packages/deep_gemm/include/cute/arch/cluster_sm90.hppAdded+245
lib/python3.12/site-packages/deep_gemm/include/cute/arch/config.hppAdded+111
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy.hppAdded+107
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm100.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm100_tma.hppAdded+664
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm50.hppAdded+98
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm75.hppAdded+236
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm80.hppAdded+198
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm90.hppAdded+219
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm90_desc.hppAdded+475
lib/python3.12/site-packages/deep_gemm/include/cute/arch/copy_sm90_tma.hppAdded+1496
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma.hppAdded+64
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm100.hppAdded+42
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm100_desc.hppAdded+651
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm100_umma.hppAdded+1616
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm120.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm120_sparse.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm61.hppAdded+87
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm70.hppAdded+329
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm75.hppAdded+120
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm80.hppAdded+2241
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm89.hppAdded+180
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_desc.hppAdded+151
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma_ext.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma_sparse.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/mma_sm90_gmma_sparse_ext.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/arch/simd_sm100.hppAdded+96
lib/python3.12/site-packages/deep_gemm/include/cute/arch/tmem_allocator_sm100.hppAdded+168
lib/python3.12/site-packages/deep_gemm/include/cute/arch/util.hppAdded+320
lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_atom.hppAdded+765
lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits.hppAdded+162
lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits_sm100.hppAdded
lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits_sm100_im2col.hppAdded+488
lib/python3.12/site-packages/deep_gemm/include/cute/atom/copy_traits_sm100_tma.hppAdded+487