5#ifndef GKO_PUBLIC_CORE_BASE_TYPES_HPP_
6#define GKO_PUBLIC_CORE_BASE_TYPES_HPP_
20#include <ginkgo/config.hpp>
21#include <ginkgo/core/base/bfloat16.hpp>
22#include <ginkgo/core/base/half.hpp>
26#include <hip/hip_runtime.h>
31#if defined(__CUDACC__) || defined(__HIPCC__)
32#define GKO_ATTRIBUTES __host__ __device__
33#define GKO_INLINE __forceinline__
34#define GKO_RESTRICT __restrict__
37#define GKO_INLINE inline
43#if defined(__CUDACC__)
44#define GKO_DEVICE_ERROR_TYPE cudaError_t
45#define GKO_DEVICE_ERROR_INVALID cudaErrorInvalidValue
46#define GKO_DEVICE_NO_ERROR cudaSuccess
47#elif defined(__HIPCC__)
48#define GKO_DEVICE_ERROR_TYPE hipError_t
49#define GKO_DEVICE_ERROR_INVALID hipErrorInvalidValue
50#define GKO_DEVICE_NO_ERROR hipSuccess
52#define GKO_DEVICE_ERROR_TYPE int
53#define GKO_DEVICE_ERROR_INVALID 1
54#define GKO_DEVICE_NO_ERROR 0
58#define GKO_ASSERT(condition) assert(condition)
63#define GKO_DEPRECATED(_msg) [[deprecated(_msg)]]
65#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_suppress 1445")
66#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_warning 1445")
67#elif defined(__GNUC__) || defined(__clang__)
68#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
69 _Pragma("GCC diagnostic push") \
70 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
71#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
72#elif defined(_MSC_VER)
73#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
74 _Pragma("warning(push)") \
75 _Pragma("warning(disable : 5211 4973 4974 4996)")
76#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("warning(pop)")
78#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
79#define GKO_END_DISABLE_DEPRECATION_WARNINGS
189template <
typename... Args>
192template <
typename First,
typename... Args>
194 :
public std::conditional<std::is_integral<std::decay_t<First>>::value,
195 are_all_integral<Args...>,
196 std::false_type>::type {};
247 static constexpr auto nonpreserving_bits = 4u;
248 static constexpr auto preserving_bits =
250 static constexpr auto nonpreserving_mask =
252 static constexpr auto preserving_mask =
253 storage_type{(0x1 << preserving_bits) - 1} << nonpreserving_bits;
272 : data_((GKO_ASSERT(preserving < (0x1 << preserving_bits) - 1),
273 GKO_ASSERT(nonpreserving < (0x1 << nonpreserving_bits) - 1),
274 (preserving << nonpreserving_bits) | nonpreserving))
294 return (data_ & preserving_mask) >> nonpreserving_bits;
304 return data_ & nonpreserving_mask;
334 min(x.data_ & preserving_mask, y.data_ & preserving_mask) |
335 min(x.data_ & nonpreserving_mask, y.data_ & nonpreserving_mask));
346 return x < y ? x : y;
365 return static_cast<st
>(x) ==
static_cast<st
>(y);
381 return static_cast<st
>(x) !=
static_cast<st
>(y);
397#define GKO_ENABLE_FOR_ALL_EXECUTORS(_enable_macro) \
398 _enable_macro(OmpExecutor, omp); \
399 _enable_macro(HipExecutor, hip); \
400 _enable_macro(DpcppExecutor, dpcpp); \
401 _enable_macro(CudaExecutor, cuda)
405#if GINKGO_ENABLE_HALF && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 530)
406#define GKO_ADAPT_HF(_macro) _macro
408#define GKO_ADAPT_HF(_macro) \
409 static_assert(true, \
410 "This assert is used to counter the false positive extra " \
411 "semi-colon warnings")
416#if GINKGO_ENABLE_BFLOAT16 && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800)
417#define GKO_ADAPT_BF(_macro) _macro
419#define GKO_ADAPT_BF(_macro) \
420 static_assert(true, \
421 "This assert is used to counter the false positive extra " \
422 "semi-colon warnings")
433#if GINKGO_DPCPP_SINGLE_MODE
434#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro) \
435 template _macro(float); \
437 _macro(double) GKO_NOT_IMPLEMENTED
439#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro) \
440 template _macro(float); \
441 template _macro(double)
444#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
445 GKO_ADAPT_HF(template _macro(float16)); \
446 GKO_ADAPT_BF(template _macro(bfloat16)); \
447 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro)
458#if GINKGO_DPCPP_SINGLE_MODE
459#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro) \
460 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro); \
461 template _macro(std::complex<float>); \
463 _macro(std::complex<double>) GKO_NOT_IMPLEMENTED
465#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro) \
466 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro); \
467 template _macro(std::complex<float>); \
468 template _macro(std::complex<double>)
471#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
472 GKO_ADAPT_HF(template _macro(float16)); \
473 GKO_ADAPT_HF(template _macro(std::complex<float16>)); \
474 GKO_ADAPT_BF(template _macro(bfloat16)); \
475 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>)); \
476 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro)
482#define GKO_INDIRECT(...) __VA_ARGS__
495#if GINKGO_DPCPP_SINGLE_MODE
496#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
498 template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \
500 GKO_INDIRECT(_macro(double, __VA_ARGS__)) \
503#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
505 template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \
506 template GKO_INDIRECT(_macro(double, __VA_ARGS__))
509#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS(_macro, ...) \
510 GKO_INDIRECT(GKO_ADAPT_HF(template _macro(float16, __VA_ARGS__))); \
511 GKO_INDIRECT(GKO_ADAPT_BF(template _macro(bfloat16, __VA_ARGS__))); \
512 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
526#if GINKGO_DPCPP_SINGLE_MODE
527#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, ...) \
528 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
530 template GKO_INDIRECT(_macro(std::complex<float>, __VA_ARGS__)); \
532 GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__)) \
535#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, ...) \
536 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
538 template GKO_INDIRECT(_macro(std::complex<float>, __VA_ARGS__)); \
539 template GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__))
542#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, ...) \
543 GKO_INDIRECT(GKO_ADAPT_HF(template _macro(float16, __VA_ARGS__))); \
545 GKO_ADAPT_HF(template _macro(std::complex<float16>, __VA_ARGS__))); \
546 GKO_INDIRECT(GKO_ADAPT_BF(template _macro(bfloat16, __VA_ARGS__))); \
548 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, __VA_ARGS__))); \
549 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, __VA_ARGS__)
562#if GINKGO_DPCPP_SINGLE_MODE
563#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro) \
564 template _macro(float, float); \
566 _macro(double, double) GKO_NOT_IMPLEMENTED; \
567 template _macro(std::complex<float>, std::complex<float>); \
569 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
570 template _macro(std::complex<float>, float); \
572 _macro(std::complex<double>, double) GKO_NOT_IMPLEMENTED;
574#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro) \
575 template _macro(float, float); \
576 template _macro(double, double); \
577 template _macro(std::complex<float>, std::complex<float>); \
578 template _macro(std::complex<double>, std::complex<double>); \
579 template _macro(std::complex<float>, float); \
580 template _macro(std::complex<double>, double)
583#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
584 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro); \
585 GKO_ADAPT_HF(template _macro(float16, float16)); \
587 template _macro(std::complex<float16>, std::complex<float16>)); \
588 GKO_ADAPT_HF(template _macro(std::complex<float16>, float16)); \
589 GKO_ADAPT_BF(template _macro(bfloat16, bfloat16)); \
591 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
592 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, bfloat16))
603#define GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) \
604 template _macro(int32); \
605 template _macro(int64)
617#if GINKGO_DPCPP_SINGLE_MODE
618#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro) \
619 template _macro(float, int32); \
621 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
622 template _macro(float, int64); \
624 _macro(double, int64) GKO_NOT_IMPLEMENTED
626#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro) \
627 template _macro(float, int32); \
628 template _macro(double, int32); \
629 template _macro(float, int64); \
630 template _macro(double, int64)
632#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
633 GKO_ADAPT_HF(template _macro(float16, int32)); \
634 GKO_ADAPT_HF(template _macro(float16, int64)); \
635 GKO_ADAPT_BF(template _macro(bfloat16, int32)); \
636 GKO_ADAPT_BF(template _macro(bfloat16, int64)); \
637 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro)
639#if GINKGO_DPCPP_SINGLE_MODE
640#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro) \
641 template _macro(float, int32); \
643 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
644 template _macro(std::complex<float>, int32); \
646 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED
648#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro) \
649 template _macro(float, int32); \
650 template _macro(double, int32); \
651 template _macro(std::complex<float>, int32); \
652 template _macro(std::complex<double>, int32)
655#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
656 GKO_ADAPT_HF(template _macro(float16, int32)); \
657 GKO_ADAPT_HF(template _macro(std::complex<float16>, int32)); \
658 GKO_ADAPT_BF(template _macro(bfloat16, int32)); \
659 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, int32)); \
660 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro)
671#if GINKGO_DPCPP_SINGLE_MODE
672#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE_BASE(_macro) \
673 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro); \
674 template _macro(std::complex<float>, int32); \
676 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED; \
677 template _macro(std::complex<float>, int64); \
679 _macro(std::complex<double>, int64) GKO_NOT_IMPLEMENTED
681#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE_BASE(_macro) \
682 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro); \
683 template _macro(std::complex<float>, int32); \
684 template _macro(std::complex<double>, int32); \
685 template _macro(std::complex<float>, int64); \
686 template _macro(std::complex<double>, int64)
689#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
690 GKO_ADAPT_HF(template _macro(float16, int32)); \
691 GKO_ADAPT_HF(template _macro(float16, int64)); \
692 GKO_ADAPT_HF(template _macro(std::complex<float16>, int32)); \
693 GKO_ADAPT_HF(template _macro(std::complex<float16>, int64)); \
694 GKO_ADAPT_BF(template _macro(bfloat16, int32)); \
695 GKO_ADAPT_BF(template _macro(bfloat16, int64)); \
696 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, int32)); \
697 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, int64)); \
698 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE_BASE(_macro)
710#if GINKGO_DPCPP_SINGLE_MODE
711#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
713 template _macro(float, int32, int32); \
714 template _macro(float, int32, int64); \
715 template _macro(float, int64, int64); \
717 _macro(double, int32, int32) GKO_NOT_IMPLEMENTED; \
719 _macro(double, int32, int64) GKO_NOT_IMPLEMENTED; \
721 _macro(double, int64, int64) GKO_NOT_IMPLEMENTED
723#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
725 template _macro(float, int32, int32); \
726 template _macro(float, int32, int64); \
727 template _macro(float, int64, int64); \
728 template _macro(double, int32, int32); \
729 template _macro(double, int32, int64); \
730 template _macro(double, int64, int64)
733#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
735 GKO_ADAPT_HF(template _macro(float16, int32, int32)); \
736 GKO_ADAPT_HF(template _macro(float16, int32, int64)); \
737 GKO_ADAPT_HF(template _macro(float16, int64, int64)); \
738 GKO_ADAPT_BF(template _macro(bfloat16, int32, int32)); \
739 GKO_ADAPT_BF(template _macro(bfloat16, int32, int64)); \
740 GKO_ADAPT_BF(template _macro(bfloat16, int64, int64)); \
741 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
753#if GINKGO_DPCPP_SINGLE_MODE
754#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
756 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
758 template _macro(std::complex<float>, int32, int32); \
759 template _macro(std::complex<float>, int32, int64); \
760 template _macro(std::complex<float>, int64, int64); \
762 _macro(std::complex<double>, int32, int32) GKO_NOT_IMPLEMENTED; \
764 _macro(std::complex<double>, int32, int64) GKO_NOT_IMPLEMENTED; \
766 _macro(std::complex<double>, int64, int64) GKO_NOT_IMPLEMENTED
768#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
770 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
772 template _macro(std::complex<float>, int32, int32); \
773 template _macro(std::complex<float>, int32, int64); \
774 template _macro(std::complex<float>, int64, int64); \
775 template _macro(std::complex<double>, int32, int32); \
776 template _macro(std::complex<double>, int32, int64); \
777 template _macro(std::complex<double>, int64, int64)
780#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
781 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE(_macro); \
782 GKO_ADAPT_HF(template _macro(float16, int32, int32)); \
783 GKO_ADAPT_HF(template _macro(float16, int32, int64)); \
784 GKO_ADAPT_HF(template _macro(float16, int64, int64)); \
785 GKO_ADAPT_HF(template _macro(std::complex<float16>, int32, int32)); \
786 GKO_ADAPT_HF(template _macro(std::complex<float16>, int32, int64)); \
787 GKO_ADAPT_HF(template _macro(std::complex<float16>, int64, int64)); \
788 GKO_ADAPT_BF(template _macro(bfloat16, int32, int32)); \
789 GKO_ADAPT_BF(template _macro(bfloat16, int32, int64)); \
790 GKO_ADAPT_BF(template _macro(bfloat16, int64, int64)); \
791 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, int32, int32)); \
792 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, int32, int64)); \
793 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, int64, int64))
796#if GINKGO_DPCPP_SINGLE_MODE
797#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro) \
799 _macro(float, double) GKO_NOT_IMPLEMENTED; \
801 _macro(double, float) GKO_NOT_IMPLEMENTED; \
803 _macro(std::complex<float>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
805 _macro(std::complex<double>, std::complex<float>) GKO_NOT_IMPLEMENTED
808#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY_BASE(_macro) \
809 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro); \
810 template _macro(float, float); \
812 _macro(double, double) GKO_NOT_IMPLEMENTED; \
813 template _macro(std::complex<float>, std::complex<float>); \
815 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED
826#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro) \
827 template _macro(float, double); \
828 template _macro(double, float); \
829 template _macro(std::complex<float>, std::complex<double>); \
830 template _macro(std::complex<double>, std::complex<float>)
842#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY_BASE(_macro) \
843 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro); \
844 template _macro(float, float); \
845 template _macro(double, double); \
846 template _macro(std::complex<float>, std::complex<float>); \
847 template _macro(std::complex<double>, std::complex<double>)
850#if GINKGO_DPCPP_SINGLE_MODE
851#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
852 GKO_ADAPT_HF(template <> _macro(float16, double) GKO_NOT_IMPLEMENTED); \
853 GKO_ADAPT_HF(template <> _macro(double, float16) GKO_NOT_IMPLEMENTED); \
854 GKO_ADAPT_HF(template _macro(float, float16)); \
855 GKO_ADAPT_HF(template _macro(float16, float)); \
856 GKO_ADAPT_HF(template _macro(std::complex<float16>, std::complex<float>)); \
857 GKO_ADAPT_HF(template <> _macro( \
858 std::complex<float16>, std::complex<double>) GKO_NOT_IMPLEMENTED); \
859 GKO_ADAPT_HF(template _macro(std::complex<float>, std::complex<float16>)); \
860 GKO_ADAPT_HF(template <> _macro( \
861 std::complex<double>, std::complex<float16>) GKO_NOT_IMPLEMENTED); \
862 GKO_ADAPT_BF(template <> _macro(bfloat16, double) GKO_NOT_IMPLEMENTED); \
863 GKO_ADAPT_BF(template <> _macro(double, bfloat16) GKO_NOT_IMPLEMENTED); \
864 GKO_ADAPT_BF(template _macro(float, bfloat16)); \
865 GKO_ADAPT_BF(template _macro(bfloat16, float)); \
867 template _macro(std::complex<bfloat16>, std::complex<float>)); \
868 GKO_ADAPT_BF(template <> _macro( \
869 std::complex<bfloat16>, std::complex<double>) GKO_NOT_IMPLEMENTED); \
871 template _macro(std::complex<float>, std::complex<bfloat16>)); \
872 GKO_ADAPT_BF(template <> _macro( \
873 std::complex<double>, std::complex<bfloat16>) GKO_NOT_IMPLEMENTED); \
874 GKO_ADAPT_BF(GKO_ADAPT_HF(template _macro(bfloat16, float16))); \
875 GKO_ADAPT_HF(GKO_ADAPT_BF(template _macro(float16, bfloat16))); \
876 GKO_ADAPT_BF(GKO_ADAPT_HF( \
877 template _macro(std::complex<bfloat16>, std::complex<float16>))); \
878 GKO_ADAPT_HF(GKO_ADAPT_BF( \
879 template _macro(std::complex<float16>, std::complex<bfloat16>))); \
880 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro)
882#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
883 GKO_ADAPT_HF(template _macro(float16, double)); \
884 GKO_ADAPT_HF(template _macro(double, float16)); \
885 GKO_ADAPT_HF(template _macro(float, float16)); \
886 GKO_ADAPT_HF(template _macro(float16, float)); \
887 GKO_ADAPT_HF(template _macro(std::complex<float16>, std::complex<float>)); \
889 template _macro(std::complex<float16>, std::complex<double>)); \
890 GKO_ADAPT_HF(template _macro(std::complex<float>, std::complex<float16>)); \
892 template _macro(std::complex<double>, std::complex<float16>)); \
893 GKO_ADAPT_BF(template _macro(bfloat16, double)); \
894 GKO_ADAPT_BF(template _macro(double, bfloat16)); \
895 GKO_ADAPT_BF(template _macro(float, bfloat16)); \
896 GKO_ADAPT_BF(template _macro(bfloat16, float)); \
898 template _macro(std::complex<bfloat16>, std::complex<float>)); \
900 template _macro(std::complex<bfloat16>, std::complex<double>)); \
902 template _macro(std::complex<float>, std::complex<bfloat16>)); \
904 template _macro(std::complex<double>, std::complex<bfloat16>)); \
905 GKO_ADAPT_BF(GKO_ADAPT_HF(template _macro(bfloat16, float16))); \
906 GKO_ADAPT_HF(GKO_ADAPT_BF(template _macro(float16, bfloat16))); \
907 GKO_ADAPT_BF(GKO_ADAPT_HF( \
908 template _macro(std::complex<bfloat16>, std::complex<float16>))); \
909 GKO_ADAPT_HF(GKO_ADAPT_BF( \
910 template _macro(std::complex<float16>, std::complex<bfloat16>))); \
911 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro)
914#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
915 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
916 GKO_ADAPT_HF(template _macro(float16, float16)); \
918 template _macro(std::complex<float16>, std::complex<float16>)); \
919 GKO_ADAPT_BF(template _macro(bfloat16, bfloat16)); \
921 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
922 template _macro(float, float); \
923 template _macro(double, double); \
924 template _macro(std::complex<float>, std::complex<float>); \
925 template _macro(std::complex<double>, std::complex<double>)
935#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR_BASE(_macro) \
936 template _macro(float, float); \
937 template _macro(double, double); \
938 template _macro(std::complex<float>, float); \
939 template _macro(std::complex<double>, double); \
940 template _macro(std::complex<float>, std::complex<float>); \
941 template _macro(std::complex<double>, std::complex<double>)
943#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR(_macro) \
944 GKO_ADAPT_HF(template _macro(float16, float16)); \
945 GKO_ADAPT_HF(template _macro(std::complex<float16>, float16)); \
947 template _macro(std::complex<float16>, std::complex<float16>)); \
948 GKO_ADAPT_BF(template _macro(bfloat16, bfloat16)); \
949 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, bfloat16)); \
951 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
952 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR_BASE(_macro)
963#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE_BASE(_macro) \
964 template _macro(char, char); \
965 template _macro(int32, int32); \
966 template _macro(int64, int64); \
967 template _macro(unsigned int, unsigned int); \
968 template _macro(unsigned long, unsigned long); \
969 template _macro(float, float); \
970 template _macro(double, double); \
971 template _macro(long double, long double); \
972 template _macro(std::complex<float>, std::complex<float>); \
973 template _macro(std::complex<double>, std::complex<double>)
975#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE(_macro) \
976 GKO_ADAPT_HF(template _macro(float16, float16)); \
978 template _macro(std::complex<float16>, std::complex<float16>)); \
979 GKO_ADAPT_BF(template _macro(bfloat16, bfloat16)); \
981 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
982 GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE_BASE(_macro)
992#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE_BASE(_macro) \
993 template _macro(float); \
994 template _macro(double); \
995 template _macro(std::complex<float>); \
996 template _macro(std::complex<double>); \
997 template _macro(size_type); \
998 template _macro(bool); \
999 template _macro(int32); \
1000 template _macro(int64)
1002#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE(_macro) \
1003 GKO_ADAPT_HF(template _macro(float16)); \
1004 GKO_ADAPT_HF(template _macro(std::complex<float16>)); \
1005 GKO_ADAPT_BF(template _macro(bfloat16)); \
1006 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>)); \
1007 GKO_INSTANTIATE_FOR_EACH_POD_TYPE_BASE(_macro)
1017#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE_BASE(_macro) \
1018 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro); \
1019 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
1020 template _macro(gko::size_type)
1022#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(_macro) \
1023 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro); \
1024 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
1025 template _macro(gko::size_type)
1036#define GKO_INSTANTIATE_FOR_INT32_TYPE(_macro) template _macro(int32)
1042template <
typename IndexType>
1045 static_assert(std::is_signed<IndexType>::value,
1046 "IndexType needs to be signed");
1047 return static_cast<IndexType
>(-1);
1051namespace experimental {
1084#define GKO_INSTANTIATE_FOR_EACH_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
1085 template _macro(int32, int32); \
1086 template _macro(int32, int64); \
1087 template _macro(int64, int64)
A class providing basic support for half precision floating point types.
Definition half.hpp:288
This class is used to encode storage precisions of low precision algorithms.
Definition types.hpp:239
uint8 storage_type
The underlying datatype used to store the encoding.
Definition types.hpp:244
constexpr precision_reduction() noexcept
Creates a default precision_reduction encoding.
Definition types.hpp:261
constexpr storage_type get_nonpreserving() const noexcept
Returns the number of non-preserving conversions in the encoding.
Definition types.hpp:302
static constexpr precision_reduction common(precision_reduction x, precision_reduction y) noexcept
Returns the common encoding of input encodings.
Definition types.hpp:330
static constexpr precision_reduction autodetect() noexcept
Returns a special encoding which instructs the algorithm to automatically detect the best precision.
Definition types.hpp:314
constexpr storage_type get_preserving() const noexcept
Returns the number of preserving conversions in the encoding.
Definition types.hpp:292
constexpr precision_reduction(storage_type preserving, storage_type nonpreserving) noexcept
Creates a precision_reduction encoding with the specified number of conversions.
Definition types.hpp:270
The distributed namespace.
Definition polymorphic_object.hpp:19
int comm_index_type
Index type for enumerating processes in a distributed application.
Definition types.hpp:1060
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:119
std::uint64_t uint64
64-bit unsigned integral type.
Definition types.hpp:136
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:107
double full_precision
The most precise floating-point type.
Definition types.hpp:166
std::int16_t int16
16-bit signed integral type.
Definition types.hpp:101
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:142
std::uint32_t uint32
32-bit unsigned integral type.
Definition types.hpp:130
std::int8_t int8
8-bit signed integral type.
Definition types.hpp:96
double float64
Double precision floating point type.
Definition types.hpp:160
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:172
std::int64_t int64
64-bit signed integral type.
Definition types.hpp:113
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
constexpr size_type byte_size
Number of bits in a byte.
Definition types.hpp:178
std::uint16_t uint16
16-bit unsigned integral type.
Definition types.hpp:124
float float32
Single precision floating point type.
Definition types.hpp:154
half float16
16 bit floating point type.
Definition types.hpp:148
constexpr IndexType invalid_index()
Value for an invalid signed index type.
Definition types.hpp:1043
Evaluates if all template arguments Args fulfill std::is_integral.
Definition types.hpp:190