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
39#if defined(__CUDACC__)
40#define GKO_DEVICE_ERROR_TYPE cudaError_t
41#define GKO_DEVICE_ERROR_INVALID cudaErrorInvalidValue
42#define GKO_DEVICE_NO_ERROR cudaSuccess
43#elif defined(__HIPCC__)
44#define GKO_DEVICE_ERROR_TYPE hipError_t
45#define GKO_DEVICE_ERROR_INVALID hipErrorInvalidValue
46#define GKO_DEVICE_NO_ERROR hipSuccess
48#define GKO_DEVICE_ERROR_TYPE int
49#define GKO_DEVICE_ERROR_INVALID 1
50#define GKO_DEVICE_NO_ERROR 0
54#define GKO_ASSERT(condition) assert(condition)
59#define GKO_DEPRECATED(_msg) [[deprecated(_msg)]]
61#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_suppress 1445")
62#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_warning 1445")
63#elif defined(__GNUC__) || defined(__clang__)
64#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
65 _Pragma("GCC diagnostic push") \
66 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
67#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
68#elif defined(_MSC_VER)
69#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
70 _Pragma("warning(push)") \
71 _Pragma("warning(disable : 5211 4973 4974 4996)")
72#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("warning(pop)")
74#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
75#define GKO_END_DISABLE_DEPRECATION_WARNINGS
188template <
typename... Args>
191template <
typename First,
typename... Args>
193 :
public std::conditional<std::is_integral<std::decay_t<First>>::value,
194 are_all_integral<Args...>,
195 std::false_type>::type {};
246 static constexpr auto nonpreserving_bits = 4u;
247 static constexpr auto preserving_bits =
249 static constexpr auto nonpreserving_mask =
251 static constexpr auto preserving_mask =
252 storage_type{(0x1 << preserving_bits) - 1} << nonpreserving_bits;
271 : data_((GKO_ASSERT(preserving < (0x1 << preserving_bits) - 1),
272 GKO_ASSERT(nonpreserving < (0x1 << nonpreserving_bits) - 1),
273 (preserving << nonpreserving_bits) | nonpreserving))
293 return (data_ & preserving_mask) >> nonpreserving_bits;
303 return data_ & nonpreserving_mask;
333 min(x.data_ & preserving_mask, y.data_ & preserving_mask) |
334 min(x.data_ & nonpreserving_mask, y.data_ & nonpreserving_mask));
345 return x < y ? x : y;
364 return static_cast<st
>(x) ==
static_cast<st
>(y);
380 return static_cast<st
>(x) !=
static_cast<st
>(y);
396#define GKO_ENABLE_FOR_ALL_EXECUTORS(_enable_macro) \
397 _enable_macro(OmpExecutor, omp); \
398 _enable_macro(HipExecutor, hip); \
399 _enable_macro(DpcppExecutor, dpcpp); \
400 _enable_macro(CudaExecutor, cuda)
411#if GINKGO_DPCPP_SINGLE_MODE
412#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
413 template _macro(float); \
415 _macro(double) GKO_NOT_IMPLEMENTED
417#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
418 template _macro(float); \
419 template _macro(double)
431#if GINKGO_DPCPP_SINGLE_MODE
432#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
433 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro); \
434 template _macro(std::complex<float>); \
436 _macro(std::complex<double>) GKO_NOT_IMPLEMENTED
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>); \
441 template _macro(std::complex<double>)
455#if GINKGO_DPCPP_SINGLE_MODE
456#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
457 template _macro(float, float); \
459 _macro(double, double) GKO_NOT_IMPLEMENTED; \
460 template _macro(std::complex<float>, std::complex<float>); \
462 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
463 template _macro(std::complex<float>, float); \
465 _macro(std::complex<double>, double) GKO_NOT_IMPLEMENTED;
467#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
468 template _macro(float, float); \
469 template _macro(double, double); \
470 template _macro(std::complex<float>, std::complex<float>); \
471 template _macro(std::complex<double>, std::complex<double>); \
472 template _macro(std::complex<float>, float); \
473 template _macro(std::complex<double>, double)
485#define GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) \
486 template _macro(int32); \
487 template _macro(int64)
499#if GINKGO_DPCPP_SINGLE_MODE
500#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
501 template _macro(float, int32); \
503 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
504 template _macro(float, int64); \
506 _macro(double, int64) GKO_NOT_IMPLEMENTED
508#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
509 template _macro(float, int32); \
510 template _macro(double, int32); \
511 template _macro(float, int64); \
512 template _macro(double, int64)
515#if GINKGO_DPCPP_SINGLE_MODE
516#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
517 template _macro(float, int32); \
519 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
520 template _macro(std::complex<float>, int32); \
522 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED
524#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
525 template _macro(float, int32); \
526 template _macro(double, int32); \
527 template _macro(std::complex<float>, int32); \
528 template _macro(std::complex<double>, int32)
540#if GINKGO_DPCPP_SINGLE_MODE
541#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
542 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro); \
543 template _macro(std::complex<float>, int32); \
545 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED; \
546 template _macro(std::complex<float>, int64); \
548 _macro(std::complex<double>, int64) GKO_NOT_IMPLEMENTED
550#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
551 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro); \
552 template _macro(std::complex<float>, int32); \
553 template _macro(std::complex<double>, int32); \
554 template _macro(std::complex<float>, int64); \
555 template _macro(std::complex<double>, int64)
568#if GINKGO_DPCPP_SINGLE_MODE
569#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
571 template _macro(float, int32, int32); \
572 template _macro(float, int32, int64); \
573 template _macro(float, int64, int64); \
575 _macro(double, int32, int32) GKO_NOT_IMPLEMENTED; \
577 _macro(double, int32, int64) GKO_NOT_IMPLEMENTED; \
579 _macro(double, int64, int64) GKO_NOT_IMPLEMENTED
581#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
583 template _macro(float, int32, int32); \
584 template _macro(float, int32, int64); \
585 template _macro(float, int64, int64); \
586 template _macro(double, int32, int32); \
587 template _macro(double, int32, int64); \
588 template _macro(double, int64, int64)
600#if GINKGO_DPCPP_SINGLE_MODE
601#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
602 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
604 template _macro(std::complex<float>, int32, int32); \
605 template _macro(std::complex<float>, int32, int64); \
606 template _macro(std::complex<float>, int64, int64); \
608 _macro(std::complex<double>, int32, int32) GKO_NOT_IMPLEMENTED; \
610 _macro(std::complex<double>, int32, int64) GKO_NOT_IMPLEMENTED; \
612 _macro(std::complex<double>, int64, int64) GKO_NOT_IMPLEMENTED
614#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
615 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
617 template _macro(std::complex<float>, int32, int32); \
618 template _macro(std::complex<float>, int32, int64); \
619 template _macro(std::complex<float>, int64, int64); \
620 template _macro(std::complex<double>, int32, int32); \
621 template _macro(std::complex<double>, int32, int64); \
622 template _macro(std::complex<double>, int64, int64)
626#if GINKGO_DPCPP_SINGLE_MODE
627#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
629 _macro(float, double) GKO_NOT_IMPLEMENTED; \
631 _macro(double, float) GKO_NOT_IMPLEMENTED; \
633 _macro(std::complex<float>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
635 _macro(std::complex<double>, std::complex<float>) GKO_NOT_IMPLEMENTED
638#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
639 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
640 template _macro(float, float); \
642 _macro(double, double) GKO_NOT_IMPLEMENTED; \
643 template _macro(std::complex<float>, std::complex<float>); \
645 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED
656#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
657 template _macro(float, double); \
658 template _macro(double, float); \
659 template _macro(std::complex<float>, std::complex<double>); \
660 template _macro(std::complex<double>, std::complex<float>)
672#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
673 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
674 template _macro(float, float); \
675 template _macro(double, double); \
676 template _macro(std::complex<float>, std::complex<float>); \
677 template _macro(std::complex<double>, std::complex<double>)
689#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR(_macro) \
690 template _macro(float, float); \
691 template _macro(double, double); \
692 template _macro(std::complex<float>, float); \
693 template _macro(std::complex<double>, double); \
694 template _macro(std::complex<float>, std::complex<float>); \
695 template _macro(std::complex<double>, std::complex<double>)
707#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE(_macro) \
708 template _macro(char, char); \
709 template _macro(int32, int32); \
710 template _macro(int64, int64); \
711 template _macro(unsigned int, unsigned int); \
712 template _macro(unsigned long, unsigned long); \
713 template _macro(float, float); \
714 template _macro(double, double); \
715 template _macro(long double, long double); \
716 template _macro(std::complex<float>, std::complex<float>); \
717 template _macro(std::complex<double>, std::complex<double>)
727#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE(_macro) \
728 template _macro(float); \
729 template _macro(double); \
730 template _macro(std::complex<float>); \
731 template _macro(std::complex<double>); \
732 template _macro(size_type); \
733 template _macro(bool); \
734 template _macro(int32); \
735 template _macro(int64)
746#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(_macro) \
747 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro); \
748 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
749 template _macro(gko::size_type)
760#define GKO_INSTANTIATE_FOR_INT32_TYPE(_macro) template _macro(int32)
766template <
typename IndexType>
769 static_assert(std::is_signed<IndexType>::value,
770 "IndexType needs to be signed");
771 return static_cast<IndexType
>(-1);
775namespace experimental {
776namespace distributed {
796#define GKO_INSTANTIATE_FOR_EACH_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
797 template _macro(int32, int32); \
798 template _macro(int32, int64); \
799 template _macro(int64, int64)
This class is used to encode storage precisions of low precision algorithms.
Definition types.hpp:238
uint8 storage_type
The underlying datatype used to store the encoding.
Definition types.hpp:243
constexpr precision_reduction() noexcept
Creates a default precision_reduction encoding.
Definition types.hpp:260
constexpr storage_type get_nonpreserving() const noexcept
Returns the number of non-preserving conversions in the encoding.
Definition types.hpp:301
static constexpr precision_reduction common(precision_reduction x, precision_reduction y) noexcept
Returns the common encoding of input encodings.
Definition types.hpp:329
static constexpr precision_reduction autodetect() noexcept
Returns a special encoding which instructs the algorithm to automatically detect the best precision.
Definition types.hpp:313
constexpr storage_type get_preserving() const noexcept
Returns the number of preserving conversions in the encoding.
Definition types.hpp:291
constexpr precision_reduction(storage_type preserving, storage_type nonpreserving) noexcept
Creates a precision_reduction encoding with the specified number of conversions.
Definition types.hpp:269
int comm_index_type
Index type for enumerating processes in a distributed application.
Definition types.hpp:784
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:115
std::uint64_t uint64
64-bit unsigned integral type.
Definition types.hpp:132
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:103
double full_precision
The most precise floating-point type.
Definition types.hpp:165
std::int16_t int16
16-bit signed integral type.
Definition types.hpp:97
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:138
std::uint32_t uint32
32-bit unsigned integral type.
Definition types.hpp:126
std::int8_t int8
8-bit signed integral type.
Definition types.hpp:92
double float64
Double precision floating point type.
Definition types.hpp:159
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:171
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:109
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:86
constexpr size_type byte_size
Number of bits in a byte.
Definition types.hpp:177
std::uint16_t uint16
16-bit unsigned integral type.
Definition types.hpp:120
float float32
Single precision floating point type.
Definition types.hpp:153
half float16
Half precision floating point type.
Definition types.hpp:147
constexpr IndexType invalid_index()
Value for an invalid signed index type.
Definition types.hpp:767
Evaluates if all template arguments Args fulfill std::is_integral.
Definition types.hpp:189