33#ifndef GKO_PUBLIC_CORE_BASE_TYPES_HPP_
34#define GKO_PUBLIC_CORE_BASE_TYPES_HPP_
50#include <hip/hip_runtime.h>
55#if defined(__CUDACC__) || defined(__HIPCC__)
56#define GKO_ATTRIBUTES __host__ __device__
57#define GKO_INLINE __forceinline__
58#define GKO_RESTRICT __restrict__
61#define GKO_INLINE inline
66#if (defined(__CUDA_ARCH__) && defined(__APPLE__)) || \
67 defined(__HIP_DEVICE_COMPILE__)
70#define GKO_ASSERT(condition) ((void)0)
74#define GKO_ASSERT(condition) \
77 : ((void)printf("%s: %d: %s: Assertion `" #condition "' failed\n", \
78 __FILE__, __LINE__, __func__)))
85#define GKO_ASSERT(condition) assert(condition)
93#define GKO_DEPRECATED(_msg) [[deprecated(_msg)]]
95#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_suppress 1445")
96#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_warning 1445")
97#elif defined(__GNUC__) || defined(__clang__)
98#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
99 _Pragma("GCC diagnostic push") \
100 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
101#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
102#elif defined(_MSC_VER)
103#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
104 _Pragma("warning(push)") \
105 _Pragma("warning(disable : 5211 4973 4974 4996)")
106#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("warning(pop)")
108#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
109#define GKO_END_DISABLE_DEPRECATION_WARNINGS
222template <
typename...
Args>
225template <
typename First,
typename...
Args>
227 :
public std::conditional<std::is_integral<std::decay_t<First>>::value,
228 are_all_integral<Args...>,
229 std::false_type>::type {};
280 static constexpr auto nonpreserving_bits = 4u;
281 static constexpr auto preserving_bits =
283 static constexpr auto nonpreserving_mask =
285 static constexpr auto preserving_mask =
286 storage_type{(0x1 << preserving_bits) - 1} << nonpreserving_bits;
305 : data_((GKO_ASSERT(
preserving < (0x1 << preserving_bits) - 1),
327 return (data_ & preserving_mask) >> nonpreserving_bits;
337 return data_ & nonpreserving_mask;
367 min(x.data_ & preserving_mask, y.data_ & preserving_mask) |
368 min(x.data_ & nonpreserving_mask, y.data_ & nonpreserving_mask));
379 return x < y ? x : y;
398 return static_cast<st>(x) ==
static_cast<st>(y);
414 return static_cast<st>(x) !=
static_cast<st>(y);
430#define GKO_ENABLE_FOR_ALL_EXECUTORS(_enable_macro) \
431 _enable_macro(OmpExecutor, omp); \
432 _enable_macro(HipExecutor, hip); \
433 _enable_macro(DpcppExecutor, dpcpp); \
434 _enable_macro(CudaExecutor, cuda)
445#if GINKGO_DPCPP_SINGLE_MODE
446#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
447 template _macro(float); \
449 _macro(double) GKO_NOT_IMPLEMENTED
451#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
452 template _macro(float); \
453 template _macro(double)
465#if GINKGO_DPCPP_SINGLE_MODE
466#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
467 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro); \
468 template _macro(std::complex<float>); \
470 _macro(std::complex<double>) GKO_NOT_IMPLEMENTED
472#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
473 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro); \
474 template _macro(std::complex<float>); \
475 template _macro(std::complex<double>)
489#if GINKGO_DPCPP_SINGLE_MODE
490#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
491 template _macro(float, float); \
493 _macro(double, double) GKO_NOT_IMPLEMENTED; \
494 template _macro(std::complex<float>, std::complex<float>); \
496 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
497 template _macro(std::complex<float>, float); \
499 _macro(std::complex<double>, double) GKO_NOT_IMPLEMENTED;
501#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
502 template _macro(float, float); \
503 template _macro(double, double); \
504 template _macro(std::complex<float>, std::complex<float>); \
505 template _macro(std::complex<double>, std::complex<double>); \
506 template _macro(std::complex<float>, float); \
507 template _macro(std::complex<double>, double)
519#define GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) \
520 template _macro(int32); \
521 template _macro(int64)
533#if GINKGO_DPCPP_SINGLE_MODE
534#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
535 template _macro(float, int32); \
537 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
538 template _macro(float, int64); \
540 _macro(double, int64) GKO_NOT_IMPLEMENTED
542#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
543 template _macro(float, int32); \
544 template _macro(double, int32); \
545 template _macro(float, int64); \
546 template _macro(double, int64)
549#if GINKGO_DPCPP_SINGLE_MODE
550#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
551 template _macro(float, int32); \
553 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
554 template _macro(std::complex<float>, int32); \
556 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED
558#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
559 template _macro(float, int32); \
560 template _macro(double, int32); \
561 template _macro(std::complex<float>, int32); \
562 template _macro(std::complex<double>, int32)
574#if GINKGO_DPCPP_SINGLE_MODE
575#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
576 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro); \
577 template _macro(std::complex<float>, int32); \
579 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED; \
580 template _macro(std::complex<float>, int64); \
582 _macro(std::complex<double>, int64) GKO_NOT_IMPLEMENTED
584#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
585 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro); \
586 template _macro(std::complex<float>, int32); \
587 template _macro(std::complex<double>, int32); \
588 template _macro(std::complex<float>, int64); \
589 template _macro(std::complex<double>, int64)
602#if GINKGO_DPCPP_SINGLE_MODE
603#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
605 template _macro(float, int32, int32); \
606 template _macro(float, int32, int64); \
607 template _macro(float, int64, int64); \
609 _macro(double, int32, int32) GKO_NOT_IMPLEMENTED; \
611 _macro(double, int32, int64) GKO_NOT_IMPLEMENTED; \
613 _macro(double, int64, int64) GKO_NOT_IMPLEMENTED
615#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
617 template _macro(float, int32, int32); \
618 template _macro(float, int32, int64); \
619 template _macro(float, int64, int64); \
620 template _macro(double, int32, int32); \
621 template _macro(double, int32, int64); \
622 template _macro(double, int64, int64)
634#if GINKGO_DPCPP_SINGLE_MODE
635#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
636 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
638 template _macro(std::complex<float>, int32, int32); \
639 template _macro(std::complex<float>, int32, int64); \
640 template _macro(std::complex<float>, int64, int64); \
642 _macro(std::complex<double>, int32, int32) GKO_NOT_IMPLEMENTED; \
644 _macro(std::complex<double>, int32, int64) GKO_NOT_IMPLEMENTED; \
646 _macro(std::complex<double>, int64, int64) GKO_NOT_IMPLEMENTED
648#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
649 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
651 template _macro(std::complex<float>, int32, int32); \
652 template _macro(std::complex<float>, int32, int64); \
653 template _macro(std::complex<float>, int64, int64); \
654 template _macro(std::complex<double>, int32, int32); \
655 template _macro(std::complex<double>, int32, int64); \
656 template _macro(std::complex<double>, int64, int64)
660#if GINKGO_DPCPP_SINGLE_MODE
661#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
663 _macro(float, double) GKO_NOT_IMPLEMENTED; \
665 _macro(double, float) GKO_NOT_IMPLEMENTED; \
667 _macro(std::complex<float>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
669 _macro(std::complex<double>, std::complex<float>) GKO_NOT_IMPLEMENTED
672#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
673 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
674 template _macro(float, float); \
676 _macro(double, double) GKO_NOT_IMPLEMENTED; \
677 template _macro(std::complex<float>, std::complex<float>); \
679 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED
690#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
691 template _macro(float, double); \
692 template _macro(double, float); \
693 template _macro(std::complex<float>, std::complex<double>); \
694 template _macro(std::complex<double>, std::complex<float>)
706#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
707 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
708 template _macro(float, float); \
709 template _macro(double, double); \
710 template _macro(std::complex<float>, std::complex<float>); \
711 template _macro(std::complex<double>, std::complex<double>)
723#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR(_macro) \
724 template _macro(float, float); \
725 template _macro(double, double); \
726 template _macro(std::complex<float>, float); \
727 template _macro(std::complex<double>, double); \
728 template _macro(std::complex<float>, std::complex<float>); \
729 template _macro(std::complex<double>, std::complex<double>)
741#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE(_macro) \
742 template _macro(char, char); \
743 template _macro(int32, int32); \
744 template _macro(int64, int64); \
745 template _macro(unsigned int, unsigned int); \
746 template _macro(unsigned long, unsigned long); \
747 template _macro(float, float); \
748 template _macro(double, double); \
749 template _macro(long double, long double); \
750 template _macro(std::complex<float>, std::complex<float>); \
751 template _macro(std::complex<double>, std::complex<double>)
761#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE(_macro) \
762 template _macro(float); \
763 template _macro(double); \
764 template _macro(std::complex<float>); \
765 template _macro(std::complex<double>); \
766 template _macro(size_type); \
767 template _macro(bool); \
768 template _macro(int32); \
769 template _macro(int64)
780#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(_macro) \
781 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro); \
782 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
783 template _macro(gko::size_type)
789template <
typename IndexType>
792 static_assert(std::is_signed<IndexType>::value,
793 "IndexType needs to be signed");
794 return static_cast<IndexType
>(-1);
798namespace experimental {
799namespace distributed {
819#define GKO_INSTANTIATE_FOR_EACH_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
820 template _macro(int32, int32); \
821 template _macro(int32, int64); \
822 template _macro(int64, int64)
This class is used to encode storage precisions of low precision algorithms.
Definition types.hpp:272
uint8 storage_type
The underlying datatype used to store the encoding.
Definition types.hpp:277
constexpr precision_reduction() noexcept
Creates a default precision_reduction encoding.
Definition types.hpp:294
constexpr storage_type get_nonpreserving() const noexcept
Returns the number of non-preserving conversions in the encoding.
Definition types.hpp:335
static constexpr precision_reduction common(precision_reduction x, precision_reduction y) noexcept
Returns the common encoding of input encodings.
Definition types.hpp:363
static constexpr precision_reduction autodetect() noexcept
Returns a special encoding which instructs the algorithm to automatically detect the best precision.
Definition types.hpp:347
constexpr storage_type get_preserving() const noexcept
Returns the number of preserving conversions in the encoding.
Definition types.hpp:325
constexpr precision_reduction(storage_type preserving, storage_type nonpreserving) noexcept
Creates a precision_reduction encoding with the specified number of conversions.
Definition types.hpp:303
int comm_index_type
Index type for enumerating processes in a distributed application.
Definition types.hpp:807
The Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:149
std::uint64_t uint64
64-bit unsigned integral type.
Definition types.hpp:166
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:137
double full_precision
The most precise floating-point type.
Definition types.hpp:199
std::int16_t int16
16-bit signed integral type.
Definition types.hpp:131
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:172
constexpr bool operator!=(const dim< Dimensionality, DimensionType > &x, const dim< Dimensionality, DimensionType > &y)
Checks if two dim objects are different.
Definition dim.hpp:258
std::uint32_t uint32
32-bit unsigned integral type.
Definition types.hpp:160
std::int8_t int8
8-bit signed integral type.
Definition types.hpp:126
double float64
Double precision floating point type.
Definition types.hpp:193
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:205
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:143
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
constexpr size_type byte_size
Number of bits in a byte.
Definition types.hpp:211
std::uint16_t uint16
16-bit unsigned integral type.
Definition types.hpp:154
float float32
Single precision floating point type.
Definition types.hpp:187
half float16
Half precision floating point type.
Definition types.hpp:181
constexpr IndexType invalid_index()
Value for an invalid signed index type.
Definition types.hpp:790
Evaluates if all template arguments Args fulfill std::is_integral.
Definition types.hpp:223