5#ifndef GKO_PUBLIC_CORE_BASE_TYPES_HPP_
6#define GKO_PUBLIC_CORE_BASE_TYPES_HPP_
22#include <hip/hip_runtime.h>
27#if defined(__CUDACC__) || defined(__HIPCC__)
28#define GKO_ATTRIBUTES __host__ __device__
29#define GKO_INLINE __forceinline__
30#define GKO_RESTRICT __restrict__
33#define GKO_INLINE inline
38#if (defined(__CUDA_ARCH__) && defined(__APPLE__)) || \
39 defined(__HIP_DEVICE_COMPILE__)
42#define GKO_ASSERT(condition) ((void)0)
46#define GKO_ASSERT(condition) \
49 : ((void)printf("%s: %d: %s: Assertion `" #condition "' failed\n", \
50 __FILE__, __LINE__, __func__)))
57#define GKO_ASSERT(condition) assert(condition)
65#define GKO_DEPRECATED(_msg) [[deprecated(_msg)]]
67#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_suppress 1445")
68#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_warning 1445")
69#elif defined(__GNUC__) || defined(__clang__)
70#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
71 _Pragma("GCC diagnostic push") \
72 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
73#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
74#elif defined(_MSC_VER)
75#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
76 _Pragma("warning(push)") \
77 _Pragma("warning(disable : 5211 4973 4974 4996)")
78#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("warning(pop)")
80#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
81#define GKO_END_DISABLE_DEPRECATION_WARNINGS
194template <
typename...
Args>
197template <
typename First,
typename...
Args>
199 :
public std::conditional<std::is_integral<std::decay_t<First>>::value,
200 are_all_integral<Args...>,
201 std::false_type>::type {};
252 static constexpr auto nonpreserving_bits = 4u;
253 static constexpr auto preserving_bits =
255 static constexpr auto nonpreserving_mask =
257 static constexpr auto preserving_mask =
258 storage_type{(0x1 << preserving_bits) - 1} << nonpreserving_bits;
277 : data_((GKO_ASSERT(
preserving < (0x1 << preserving_bits) - 1),
299 return (data_ & preserving_mask) >> nonpreserving_bits;
309 return data_ & nonpreserving_mask;
339 min(x.data_ & preserving_mask, y.data_ & preserving_mask) |
340 min(x.data_ & nonpreserving_mask, y.data_ & nonpreserving_mask));
351 return x < y ? x : y;
370 return static_cast<st>(x) ==
static_cast<st>(y);
386 return static_cast<st>(x) !=
static_cast<st>(y);
402#define GKO_ENABLE_FOR_ALL_EXECUTORS(_enable_macro) \
403 _enable_macro(OmpExecutor, omp); \
404 _enable_macro(HipExecutor, hip); \
405 _enable_macro(DpcppExecutor, dpcpp); \
406 _enable_macro(CudaExecutor, cuda)
417#if GINKGO_DPCPP_SINGLE_MODE
418#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
419 template _macro(float); \
421 _macro(double) GKO_NOT_IMPLEMENTED
423#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
424 template _macro(float); \
425 template _macro(double)
437#if GINKGO_DPCPP_SINGLE_MODE
438#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
439 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro); \
440 template _macro(std::complex<float>); \
442 _macro(std::complex<double>) GKO_NOT_IMPLEMENTED
444#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
445 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro); \
446 template _macro(std::complex<float>); \
447 template _macro(std::complex<double>)
461#if GINKGO_DPCPP_SINGLE_MODE
462#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
463 template _macro(float, float); \
465 _macro(double, double) GKO_NOT_IMPLEMENTED; \
466 template _macro(std::complex<float>, std::complex<float>); \
468 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
469 template _macro(std::complex<float>, float); \
471 _macro(std::complex<double>, double) GKO_NOT_IMPLEMENTED;
473#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
474 template _macro(float, float); \
475 template _macro(double, double); \
476 template _macro(std::complex<float>, std::complex<float>); \
477 template _macro(std::complex<double>, std::complex<double>); \
478 template _macro(std::complex<float>, float); \
479 template _macro(std::complex<double>, double)
491#define GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) \
492 template _macro(int32); \
493 template _macro(int64)
505#if GINKGO_DPCPP_SINGLE_MODE
506#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
507 template _macro(float, int32); \
509 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
510 template _macro(float, int64); \
512 _macro(double, int64) GKO_NOT_IMPLEMENTED
514#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
515 template _macro(float, int32); \
516 template _macro(double, int32); \
517 template _macro(float, int64); \
518 template _macro(double, int64)
521#if GINKGO_DPCPP_SINGLE_MODE
522#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
523 template _macro(float, int32); \
525 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
526 template _macro(std::complex<float>, int32); \
528 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED
530#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
531 template _macro(float, int32); \
532 template _macro(double, int32); \
533 template _macro(std::complex<float>, int32); \
534 template _macro(std::complex<double>, int32)
546#if GINKGO_DPCPP_SINGLE_MODE
547#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
548 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro); \
549 template _macro(std::complex<float>, int32); \
551 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED; \
552 template _macro(std::complex<float>, int64); \
554 _macro(std::complex<double>, int64) GKO_NOT_IMPLEMENTED
556#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
557 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro); \
558 template _macro(std::complex<float>, int32); \
559 template _macro(std::complex<double>, int32); \
560 template _macro(std::complex<float>, int64); \
561 template _macro(std::complex<double>, int64)
574#if GINKGO_DPCPP_SINGLE_MODE
575#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
577 template _macro(float, int32, int32); \
578 template _macro(float, int32, int64); \
579 template _macro(float, int64, int64); \
581 _macro(double, int32, int32) GKO_NOT_IMPLEMENTED; \
583 _macro(double, int32, int64) GKO_NOT_IMPLEMENTED; \
585 _macro(double, int64, int64) GKO_NOT_IMPLEMENTED
587#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
589 template _macro(float, int32, int32); \
590 template _macro(float, int32, int64); \
591 template _macro(float, int64, int64); \
592 template _macro(double, int32, int32); \
593 template _macro(double, int32, int64); \
594 template _macro(double, int64, int64)
606#if GINKGO_DPCPP_SINGLE_MODE
607#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
608 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
610 template _macro(std::complex<float>, int32, int32); \
611 template _macro(std::complex<float>, int32, int64); \
612 template _macro(std::complex<float>, int64, int64); \
614 _macro(std::complex<double>, int32, int32) GKO_NOT_IMPLEMENTED; \
616 _macro(std::complex<double>, int32, int64) GKO_NOT_IMPLEMENTED; \
618 _macro(std::complex<double>, int64, int64) GKO_NOT_IMPLEMENTED
620#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
621 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
623 template _macro(std::complex<float>, int32, int32); \
624 template _macro(std::complex<float>, int32, int64); \
625 template _macro(std::complex<float>, int64, int64); \
626 template _macro(std::complex<double>, int32, int32); \
627 template _macro(std::complex<double>, int32, int64); \
628 template _macro(std::complex<double>, int64, int64)
632#if GINKGO_DPCPP_SINGLE_MODE
633#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
635 _macro(float, double) GKO_NOT_IMPLEMENTED; \
637 _macro(double, float) GKO_NOT_IMPLEMENTED; \
639 _macro(std::complex<float>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
641 _macro(std::complex<double>, std::complex<float>) GKO_NOT_IMPLEMENTED
644#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
645 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
646 template _macro(float, float); \
648 _macro(double, double) GKO_NOT_IMPLEMENTED; \
649 template _macro(std::complex<float>, std::complex<float>); \
651 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED
662#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
663 template _macro(float, double); \
664 template _macro(double, float); \
665 template _macro(std::complex<float>, std::complex<double>); \
666 template _macro(std::complex<double>, std::complex<float>)
678#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
679 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
680 template _macro(float, float); \
681 template _macro(double, double); \
682 template _macro(std::complex<float>, std::complex<float>); \
683 template _macro(std::complex<double>, std::complex<double>)
695#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR(_macro) \
696 template _macro(float, float); \
697 template _macro(double, double); \
698 template _macro(std::complex<float>, float); \
699 template _macro(std::complex<double>, double); \
700 template _macro(std::complex<float>, std::complex<float>); \
701 template _macro(std::complex<double>, std::complex<double>)
713#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE(_macro) \
714 template _macro(char, char); \
715 template _macro(int32, int32); \
716 template _macro(int64, int64); \
717 template _macro(unsigned int, unsigned int); \
718 template _macro(unsigned long, unsigned long); \
719 template _macro(float, float); \
720 template _macro(double, double); \
721 template _macro(long double, long double); \
722 template _macro(std::complex<float>, std::complex<float>); \
723 template _macro(std::complex<double>, std::complex<double>)
733#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE(_macro) \
734 template _macro(float); \
735 template _macro(double); \
736 template _macro(std::complex<float>); \
737 template _macro(std::complex<double>); \
738 template _macro(size_type); \
739 template _macro(bool); \
740 template _macro(int32); \
741 template _macro(int64)
752#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(_macro) \
753 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro); \
754 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
755 template _macro(gko::size_type)
761template <
typename IndexType>
764 static_assert(std::is_signed<IndexType>::value,
765 "IndexType needs to be signed");
766 return static_cast<IndexType
>(-1);
770namespace experimental {
771namespace distributed {
791#define GKO_INSTANTIATE_FOR_EACH_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
792 template _macro(int32, int32); \
793 template _macro(int32, int64); \
794 template _macro(int64, int64)
This class is used to encode storage precisions of low precision algorithms.
Definition types.hpp:244
uint8 storage_type
The underlying datatype used to store the encoding.
Definition types.hpp:249
constexpr precision_reduction() noexcept
Creates a default precision_reduction encoding.
Definition types.hpp:266
constexpr storage_type get_nonpreserving() const noexcept
Returns the number of non-preserving conversions in the encoding.
Definition types.hpp:307
static constexpr precision_reduction common(precision_reduction x, precision_reduction y) noexcept
Returns the common encoding of input encodings.
Definition types.hpp:335
static constexpr precision_reduction autodetect() noexcept
Returns a special encoding which instructs the algorithm to automatically detect the best precision.
Definition types.hpp:319
constexpr storage_type get_preserving() const noexcept
Returns the number of preserving conversions in the encoding.
Definition types.hpp:297
constexpr precision_reduction(storage_type preserving, storage_type nonpreserving) noexcept
Creates a precision_reduction encoding with the specified number of conversions.
Definition types.hpp:275
int comm_index_type
Index type for enumerating processes in a distributed application.
Definition types.hpp:779
The Ginkgo namespace.
Definition abstract_factory.hpp:20
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:775
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:121
std::uint64_t uint64
64-bit unsigned integral type.
Definition types.hpp:138
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:109
double full_precision
The most precise floating-point type.
Definition types.hpp:171
std::int16_t int16
16-bit signed integral type.
Definition types.hpp:103
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:144
std::uint32_t uint32
32-bit unsigned integral type.
Definition types.hpp:132
std::int8_t int8
8-bit signed integral type.
Definition types.hpp:98
double float64
Double precision floating point type.
Definition types.hpp:165
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:177
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:115
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:92
constexpr size_type byte_size
Number of bits in a byte.
Definition types.hpp:183
std::uint16_t uint16
16-bit unsigned integral type.
Definition types.hpp:126
float float32
Single precision floating point type.
Definition types.hpp:159
half float16
Half precision floating point type.
Definition types.hpp:153
constexpr IndexType invalid_index()
Value for an invalid signed index type.
Definition types.hpp:762
Evaluates if all template arguments Args fulfill std::is_integral.
Definition types.hpp:195