CUTLASS 3.2.1 (#1113)
* Updates for 3.2.1 release. * Minor fix in gemm op profiler for raster order. * Add scheduler mapping for raster order in the kernels.
This commit is contained in:
@@ -387,8 +387,7 @@ abs(ScaledBasis<T,N> const& e) {
|
||||
}
|
||||
|
||||
// Multiplication
|
||||
template <class A, int N, class T,
|
||||
__CUTE_REQUIRES(cute::is_integral<A>::value)>
|
||||
template <class A, int N, class T>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
auto
|
||||
operator*(A const& a, ScaledBasis<T,N> const& e) {
|
||||
@@ -396,8 +395,7 @@ operator*(A const& a, ScaledBasis<T,N> const& e) {
|
||||
return ScaledBasis<decltype(r),N>{r};
|
||||
}
|
||||
|
||||
template <int N, class T, class B,
|
||||
__CUTE_REQUIRES(cute::is_integral<B>::value)>
|
||||
template <int N, class T, class B>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
auto
|
||||
operator*(ScaledBasis<T,N> const& e, B const& b) {
|
||||
|
||||
@@ -30,97 +30,19 @@
|
||||
**************************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <cute/util/type_traits.hpp>
|
||||
|
||||
//#if defined(__CUDA_ARCH__)
|
||||
//# include <cuda/std/complex>
|
||||
//#else
|
||||
//# include <complex>
|
||||
//#endif
|
||||
|
||||
// Suppress warnings for code in Thrust headers.
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
// We check for MSVC first, because MSVC also defines __GNUC__.
|
||||
// It's common for non-GCC compilers that emulate GCC's behavior
|
||||
// to define __GNUC__.
|
||||
//
|
||||
// thrust/complex.h triggers MSVC's warning on conversion
|
||||
// from double to float (or const float) ("possible loss of data").
|
||||
// MSVC treats this as an error by default (at least with
|
||||
// CUTLASS's default CMake configuration).
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable : 4244 )
|
||||
#elif defined(__GNUC__)
|
||||
// With GCC + CUDA 11.4, builds show spurious "-Wconversion"
|
||||
// warnings on line 656 of thrust/detail/type_traits.h.
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
#endif
|
||||
|
||||
#if defined(__CUDACC_RTC__)
|
||||
#include <cuda/std/complex>
|
||||
#else
|
||||
#include <thrust/complex.h>
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning( pop )
|
||||
#elif defined(__GNUC__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include <cute/config.hpp>
|
||||
#include <cute/util/type_traits.hpp>
|
||||
#include <cutlass/complex.h>
|
||||
|
||||
namespace cute
|
||||
{
|
||||
|
||||
//#if defined(__CUDA_ARCH__)
|
||||
//template <class T>
|
||||
//using complex = cuda::std::complex<T>;
|
||||
//#else
|
||||
//template <class T>
|
||||
//using complex = std::complex<T>;
|
||||
//#endif
|
||||
|
||||
//template <class T>
|
||||
//using complex = thrust::complex<T>;
|
||||
|
||||
#if defined(__CUDACC_RTC__)
|
||||
using cuda::std::complex;
|
||||
#else
|
||||
using thrust::complex;
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
CUTE_HOST_DEVICE
|
||||
T real(complex<T> const& z) {
|
||||
return z.real();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
CUTE_HOST_DEVICE
|
||||
T imag(complex<T> const& z) {
|
||||
return z.imag();
|
||||
}
|
||||
|
||||
template <class T>
|
||||
CUTE_HOST_DEVICE
|
||||
complex<T> conj(complex<T> const& z) {
|
||||
return complex<T>(real(z), -imag(z));
|
||||
}
|
||||
|
||||
// cute::conj forwards scalars
|
||||
template <class T>
|
||||
CUTE_HOST_DEVICE
|
||||
T conj(T z) {
|
||||
return z;
|
||||
}
|
||||
|
||||
//CUTE_HOST_DEVICE constexpr
|
||||
//float conj(float z) { return z; }
|
||||
//CUTE_HOST_DEVICE constexpr
|
||||
//double conj(double z) { return z; }
|
||||
using cutlass::complex;
|
||||
using cutlass::is_complex;
|
||||
using cutlass::RealType;
|
||||
using cutlass::real;
|
||||
using cutlass::imag;
|
||||
using cutlass::conj;
|
||||
|
||||
/// Fused multiply-add for complex numbers
|
||||
template <class T>
|
||||
@@ -131,10 +53,10 @@ fma(complex<T> & d,
|
||||
complex<T> const& b,
|
||||
complex<T> const& c)
|
||||
{
|
||||
d.real(c.real() + a.real() * b.real());
|
||||
d.imag(c.imag() + a.real() * b.imag());
|
||||
d.real(d.real() - a.imag() * b.imag());
|
||||
d.imag(d.imag() + a.imag() * b.real());
|
||||
d.real(fma( a.real(), b.real(), c.real()));
|
||||
d.imag(fma( a.real(), b.imag(), c.imag()));
|
||||
d.real(fma(-a.imag(), b.imag(), d.real()));
|
||||
d.imag(fma( a.imag(), b.real(), d.imag()));
|
||||
}
|
||||
|
||||
/// Fused multiply-add for triplets
|
||||
@@ -148,46 +70,4 @@ fma(complex<T> const& a,
|
||||
return fma(c, a, b, c);
|
||||
}
|
||||
|
||||
/// Used to determine the real-valued underlying type of a numeric type T
|
||||
template <class T>
|
||||
struct RealType {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
/// Partial specialization for complex-valued type
|
||||
template <class T>
|
||||
struct RealType<complex<T>> {
|
||||
using Type = T;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class T>
|
||||
struct is_complex {
|
||||
static bool const value = false;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct is_complex<complex<T>> {
|
||||
static bool const value = true;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Display utilities
|
||||
|
||||
#if !defined(__CUDACC_RTC__)
|
||||
template <class T>
|
||||
CUTE_HOST std::ostream& operator<<(std::ostream& os, complex<T> const& z)
|
||||
{
|
||||
T _r = z.real();
|
||||
T _i = z.imag();
|
||||
|
||||
if (bool(_i)) {
|
||||
return os << _r << "+i" << _i;
|
||||
} else {
|
||||
return os << _r;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace cute
|
||||
|
||||
@@ -30,15 +30,14 @@
|
||||
**************************************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include <cute/config.hpp>
|
||||
|
||||
#include <cute/util/type_traits.hpp>
|
||||
#include <cute/numeric/math.hpp>
|
||||
#include "cute/util/print.hpp"
|
||||
#include "cute/util/type_traits.hpp"
|
||||
#include "cute/numeric/math.hpp"
|
||||
|
||||
namespace cute
|
||||
{
|
||||
|
||||
// Short name for fast compilation
|
||||
// A constant value: short name and type-deduction for fast compilation
|
||||
template <auto v>
|
||||
struct C {
|
||||
using type = C<v>;
|
||||
@@ -48,29 +47,40 @@ struct C {
|
||||
CUTE_HOST_DEVICE constexpr value_type operator()() const noexcept { return value; }
|
||||
};
|
||||
|
||||
// Deprecate
|
||||
template <class T, T v>
|
||||
using constant = C<v>;
|
||||
|
||||
template <class T, T v>
|
||||
using integral_constant = C<v>;
|
||||
|
||||
template <bool b>
|
||||
using bool_constant = C<b>;
|
||||
|
||||
using true_type = bool_constant<true>;
|
||||
using false_type = bool_constant<false>;
|
||||
|
||||
// A more std:: conforming integral_constant that enforces type but interops with C<v>
|
||||
template <class T, T v>
|
||||
struct integral_constant : C<v> {
|
||||
using type = integral_constant<T,v>;
|
||||
static constexpr T value = v;
|
||||
using value_type = T;
|
||||
// Disambiguate C<v>::operator value_type()
|
||||
//CUTE_HOST_DEVICE constexpr operator value_type() const noexcept { return value; }
|
||||
CUTE_HOST_DEVICE constexpr value_type operator()() const noexcept { return value; }
|
||||
};
|
||||
|
||||
//
|
||||
// Traits
|
||||
//
|
||||
|
||||
// Use cute::is_std_integral<T> to match built-in integral types (int, int64_t, unsigned, etc)
|
||||
// Use cute::is_integral<T> to match both built-in integral types AND constant<T,t>
|
||||
// Use cute::is_integral<T> to match both built-in integral types AND static integral types.
|
||||
|
||||
template <class T>
|
||||
struct is_integral : bool_constant<is_std_integral<T>::value> {};
|
||||
template <auto v>
|
||||
struct is_integral<C<v>> : true_type {};
|
||||
struct is_integral<C<v> > : true_type {};
|
||||
template <class T, T v>
|
||||
struct is_integral<integral_constant<T,v>> : true_type {};
|
||||
|
||||
// is_static detects if an (abstract) value is defined completely by it's type (no members)
|
||||
|
||||
@@ -80,20 +90,22 @@ struct is_static : bool_constant<is_empty<T>::value> {};
|
||||
template <class T>
|
||||
constexpr bool is_static_v = is_static<T>::value;
|
||||
|
||||
// is_constant detects if a type is a constant<T,v> and if v is equal to a value
|
||||
// is_constant detects if a type is a static integral type and if v is equal to a value
|
||||
|
||||
template <auto n, class T>
|
||||
struct is_constant : false_type {};
|
||||
template <auto n, class T>
|
||||
struct is_constant<n, T const > : is_constant<n,T> {};
|
||||
template <auto n, class T>
|
||||
struct is_constant<n, T const&> : is_constant<n,T> {};
|
||||
template <auto n, class T>
|
||||
struct is_constant<n, T &> : is_constant<n,T> {};
|
||||
template <auto n, class T>
|
||||
struct is_constant<n, T &&> : is_constant<n,T> {};
|
||||
template <auto n, auto v>
|
||||
struct is_constant<n, C<v> > : bool_constant<v == n> {};
|
||||
template <auto n, auto v>
|
||||
struct is_constant<n, C<v> const > : bool_constant<v == n> {};
|
||||
template <auto n, auto v>
|
||||
struct is_constant<n, C<v> const&> : bool_constant<v == n> {};
|
||||
template <auto n, auto v>
|
||||
struct is_constant<n, C<v> &> : bool_constant<v == n> {};
|
||||
template <auto n, auto v>
|
||||
struct is_constant<n, C<v> &&> : bool_constant<v == n> {};
|
||||
struct is_constant<n, C<v> > : bool_constant<v == n> {};
|
||||
template <auto n, class T, T v>
|
||||
struct is_constant<n, integral_constant<T,v>> : bool_constant<v == n> {};
|
||||
|
||||
//
|
||||
// Specializations
|
||||
@@ -403,9 +415,10 @@ conditional_return(TrueType const& t, FalseType const& f) {
|
||||
// Display utilities
|
||||
//
|
||||
|
||||
template <auto t>
|
||||
CUTE_HOST_DEVICE void print(C<t> const&) {
|
||||
printf("_%d", int(t));
|
||||
template <auto Value>
|
||||
CUTE_HOST_DEVICE void print(C<Value>) {
|
||||
printf("_");
|
||||
::cute::print(Value);
|
||||
}
|
||||
|
||||
#if !defined(__CUDACC_RTC__)
|
||||
|
||||
175
include/cute/numeric/integral_ratio.hpp
Normal file
175
include/cute/numeric/integral_ratio.hpp
Normal file
@@ -0,0 +1,175 @@
|
||||
/***************************************************************************************************
|
||||
* Copyright (c) 2023 - 2023 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/numeric/math.hpp>
|
||||
#include <cute/numeric/integral_constant.hpp>
|
||||
|
||||
namespace cute
|
||||
{
|
||||
|
||||
/** Compile-time rational arithmetic type.
|
||||
* Like cute::C for std::integral_constant, cute::R for std::ratio has a short name
|
||||
* for error messages and compile times.
|
||||
* The static data members @a num and @a den represent the reduced numerator and denominator
|
||||
* of the rational value. Thus, two cute::R types with different @a n or @a d are distinct types
|
||||
* even if they represent the same rational value. A cute::R exposes the reduced canonical type
|
||||
* via its type member. That is, cute::R<3,6>::type is cute::R<1,2> and cute::R<6,3>::type is cute::C<2>
|
||||
*/
|
||||
template <auto n, auto d>
|
||||
class R {
|
||||
static_assert(d != 0);
|
||||
static constexpr auto an = abs(n);
|
||||
static constexpr auto ad = abs(d);
|
||||
static constexpr auto g = gcd(an, ad);
|
||||
|
||||
public:
|
||||
static constexpr auto num = signum(n) * signum(d) * an / g;
|
||||
static constexpr auto den = ad / g;
|
||||
// RI: den >= 1 && gcd(abs(num),den) == 1
|
||||
using type = typename conditional<num == 0 || den == 1, C<num>, R<num,den>>::type;
|
||||
};
|
||||
|
||||
template <auto a, auto b>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a,b>::type
|
||||
ratio(C<a>, C<b>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto a, auto b, auto x, auto y>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a*x,b*y>::type
|
||||
operator*(R<a,b>, R<x,y>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto a, auto b, auto c>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a*c,b>::type
|
||||
operator*(R<a,b>, C<c>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto c, auto a, auto b>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a*c,b>::type
|
||||
operator*(C<c>, R<a,b>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
// Product with dynamic type needs to produce an integer...
|
||||
template <class C, auto a, auto b,
|
||||
__CUTE_REQUIRES(cute::is_std_integral<C>::value)>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
auto
|
||||
operator*(C const& c, R<a,b>) {
|
||||
return c * R<a,b>::num / R<a,b>::den;
|
||||
}
|
||||
|
||||
// Product with dynamic type needs to produce an integer...
|
||||
template <auto a, auto b, class C,
|
||||
__CUTE_REQUIRES(cute::is_std_integral<C>::value)>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
auto
|
||||
operator*(R<a,b>, C const& c) {
|
||||
return c * R<a,b>::num / R<a,b>::den;
|
||||
}
|
||||
|
||||
template <auto a, auto b, auto x, auto y>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a*y+b*x, b*y>::type
|
||||
operator+(R<a,b>, R<x,y>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto a, auto b, auto c>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a+c*b,b>::type
|
||||
operator+(R<a,b>, C<c>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto c, auto a, auto b>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<a+c*b,b>::type
|
||||
operator+(C<c>, R<a,b>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto a, auto b, auto x, auto y>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
bool_constant<R<a,b>::num == R<x,y>::num && R<a,b>::den == R<x,y>::den>
|
||||
operator==(R<a,b>, R<x,y>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto a, auto b, auto c>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
bool_constant<R<a,b>::num == c && R<a,b>::den == 1>
|
||||
operator==(R<a,b>, C<c>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto c, auto a, auto b>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
bool_constant<R<a,b>::num == c && R<a,b>::den == 1>
|
||||
operator==(C<c>, R<a,b>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
template <auto a, auto b>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
typename R<abs(a),abs(b)>::type
|
||||
abs(R<a,b>) {
|
||||
return {};
|
||||
}
|
||||
|
||||
//
|
||||
// Display utilities
|
||||
//
|
||||
|
||||
template <auto a, auto b>
|
||||
CUTE_HOST_DEVICE void print(R<a,b>) {
|
||||
print(C<a>{}); print("/"); print(C<b>{});
|
||||
}
|
||||
|
||||
#if !defined(__CUDACC_RTC__)
|
||||
template <auto a, auto b>
|
||||
CUTE_HOST std::ostream& operator<<(std::ostream& os, R<a,b>) {
|
||||
return os << "_" << C<a>{} << "/" << C<b>{};
|
||||
}
|
||||
#endif
|
||||
|
||||
} // end namespace cute
|
||||
@@ -73,11 +73,26 @@ abs(T const& t) {
|
||||
CUTE_GCC_UNREACHABLE;
|
||||
}
|
||||
|
||||
// Returns 1 if x > 0, -1 if x < 0, and 0 if x is zero.
|
||||
template <class T,
|
||||
__CUTE_REQUIRES(is_arithmetic<T>::value)>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
int
|
||||
signum(T const& x) {
|
||||
if constexpr (is_signed<T>::value) {
|
||||
return (T(0) < x) - (x < T(0));
|
||||
} else {
|
||||
return T(0) < x;
|
||||
}
|
||||
|
||||
CUTE_GCC_UNREACHABLE;
|
||||
}
|
||||
|
||||
//
|
||||
// C++17 <numeric> operations
|
||||
//
|
||||
|
||||
// Greatest common divisor of two integers
|
||||
// Greatest common divisor of two positive integers
|
||||
template <class T, class U,
|
||||
__CUTE_REQUIRES(is_std_integral<T>::value &&
|
||||
is_std_integral<U>::value)>
|
||||
@@ -92,7 +107,7 @@ gcd(T t, U u) {
|
||||
}
|
||||
}
|
||||
|
||||
// Least common multiple of two integers
|
||||
// Least common multiple of two positive integers
|
||||
template <class T, class U,
|
||||
__CUTE_REQUIRES(is_std_integral<T>::value &&
|
||||
is_std_integral<U>::value)>
|
||||
@@ -280,23 +295,6 @@ shiftr(T x, int s) {
|
||||
return s >= 0 ? (x >> s) : (x << -s);
|
||||
}
|
||||
|
||||
// Returns 1 if x > 0, -1 if x < 0, and 0 if x is zero.
|
||||
template <class T,
|
||||
__CUTE_REQUIRES(is_unsigned<T>::value)>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
int
|
||||
signum(T const& x) {
|
||||
return T(0) < x;
|
||||
}
|
||||
|
||||
template <class T,
|
||||
__CUTE_REQUIRES(not is_unsigned<T>::value)>
|
||||
CUTE_HOST_DEVICE constexpr
|
||||
int
|
||||
signum(T const& x) {
|
||||
return (T(0) < x) - (x < T(0));
|
||||
}
|
||||
|
||||
// Safe divide
|
||||
// @pre t % u == 0
|
||||
// @result t / u
|
||||
|
||||
Reference in New Issue
Block a user