Ginkgo Generated from branch based on main. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
 
Loading...
Searching...
No Matches
types.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_BASE_TYPES_HPP_
6#define GKO_PUBLIC_CORE_BASE_TYPES_HPP_
7
8
9#include <array>
10#include <cassert>
11#include <climits>
12#include <complex>
13#include <cstddef>
14#include <cstdint>
15#include <limits>
16#include <stdexcept>
17#include <string>
18#include <type_traits>
19
20#include <ginkgo/config.hpp>
21#include <ginkgo/core/base/half.hpp>
22
23
24#ifdef __HIPCC__
25#include <hip/hip_runtime.h>
26#endif // __HIPCC__
27
28
29// Macros for handling different compilers / architectures uniformly
30#if defined(__CUDACC__) || defined(__HIPCC__)
31#define GKO_ATTRIBUTES __host__ __device__
32#define GKO_INLINE __forceinline__
33#define GKO_RESTRICT __restrict__
34#else
35#define GKO_ATTRIBUTES
36#define GKO_INLINE inline
37#define GKO_RESTRICT
38#endif // defined(__CUDACC__) || defined(__HIPCC__)
39
40
41// Macros for handling different device error return types uniformly
42#if defined(__CUDACC__)
43#define GKO_DEVICE_ERROR_TYPE cudaError_t
44#define GKO_DEVICE_ERROR_INVALID cudaErrorInvalidValue
45#define GKO_DEVICE_NO_ERROR cudaSuccess
46#elif defined(__HIPCC__)
47#define GKO_DEVICE_ERROR_TYPE hipError_t
48#define GKO_DEVICE_ERROR_INVALID hipErrorInvalidValue
49#define GKO_DEVICE_NO_ERROR hipSuccess
50#else
51#define GKO_DEVICE_ERROR_TYPE int
52#define GKO_DEVICE_ERROR_INVALID 1
53#define GKO_DEVICE_NO_ERROR 0
54#endif
55
56
57#define GKO_ASSERT(condition) assert(condition)
58
59
60// Handle deprecated notices correctly on different systems
61// clang-format off
62#define GKO_DEPRECATED(_msg) [[deprecated(_msg)]]
63#ifdef __NVCOMPILER
64#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_suppress 1445")
65#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("diag_warning 1445")
66#elif defined(__GNUC__) || defined(__clang__)
67#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
68 _Pragma("GCC diagnostic push") \
69 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
70#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("GCC diagnostic pop")
71#elif defined(_MSC_VER)
72#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS \
73 _Pragma("warning(push)") \
74 _Pragma("warning(disable : 5211 4973 4974 4996)")
75#define GKO_END_DISABLE_DEPRECATION_WARNINGS _Pragma("warning(pop)")
76#else
77#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
78#define GKO_END_DISABLE_DEPRECATION_WARNINGS
79#endif
80// clang-format on
81
82
83namespace gko {
84
85
89using size_type = std::size_t;
90
91
95using int8 = std::int8_t;
96
100using int16 = std::int16_t;
101
102
106using int32 = std::int32_t;
107
108
112using int64 = std::int64_t;
113
114
118using uint8 = std::uint8_t;
119
123using uint16 = std::uint16_t;
124
125
129using uint32 = std::uint32_t;
130
131
135using uint64 = std::uint64_t;
136
137
141using uintptr = std::uintptr_t;
142
143
147using float16 = half;
148
149
153using float32 = float;
154
155
159using float64 = double;
160
161
165using full_precision = double;
166
167
171using default_precision = double;
172
173
177constexpr size_type byte_size = CHAR_BIT;
178
179
188template <typename... Args>
189struct are_all_integral : public std::true_type {};
190
191template <typename First, typename... Args>
192struct are_all_integral<First, Args...>
193 : public std::conditional<std::is_integral<std::decay_t<First>>::value,
194 are_all_integral<Args...>,
195 std::false_type>::type {};
196
197
239public:
244
245private:
246 static constexpr auto nonpreserving_bits = 4u;
247 static constexpr auto preserving_bits =
248 byte_size * sizeof(storage_type) - nonpreserving_bits;
249 static constexpr auto nonpreserving_mask =
250 storage_type{(0x1 << nonpreserving_bits) - 1};
251 static constexpr auto preserving_mask =
252 storage_type{(0x1 << preserving_bits) - 1} << nonpreserving_bits;
253
254public:
260 GKO_ATTRIBUTES constexpr precision_reduction() noexcept : data_{0x0} {}
261
269 GKO_ATTRIBUTES constexpr precision_reduction(
270 storage_type preserving, storage_type nonpreserving) noexcept
271 : data_((GKO_ASSERT(preserving < (0x1 << preserving_bits) - 1),
272 GKO_ASSERT(nonpreserving < (0x1 << nonpreserving_bits) - 1),
273 (preserving << nonpreserving_bits) | nonpreserving))
274 {}
275
281 GKO_ATTRIBUTES constexpr operator storage_type() const noexcept
282 {
283 return data_;
284 }
285
291 GKO_ATTRIBUTES constexpr storage_type get_preserving() const noexcept
292 {
293 return (data_ & preserving_mask) >> nonpreserving_bits;
294 }
295
301 GKO_ATTRIBUTES constexpr storage_type get_nonpreserving() const noexcept
302 {
303 return data_ & nonpreserving_mask;
304 }
305
313 GKO_ATTRIBUTES constexpr static precision_reduction autodetect() noexcept
314 {
315 return precision_reduction{preserving_mask | nonpreserving_mask};
316 }
317
329 GKO_ATTRIBUTES constexpr static precision_reduction common(
331 {
332 return precision_reduction(
333 min(x.data_ & preserving_mask, y.data_ & preserving_mask) |
334 min(x.data_ & nonpreserving_mask, y.data_ & nonpreserving_mask));
335 }
336
337private:
338 GKO_ATTRIBUTES constexpr precision_reduction(storage_type data)
339 : data_{data}
340 {}
341
342 GKO_ATTRIBUTES constexpr static storage_type min(storage_type x,
343 storage_type y) noexcept
344 {
345 return x < y ? x : y;
346 }
347
348 storage_type data_;
349};
350
351
360GKO_ATTRIBUTES constexpr bool operator==(precision_reduction x,
361 precision_reduction y) noexcept
362{
364 return static_cast<st>(x) == static_cast<st>(y);
365}
366
367
376GKO_ATTRIBUTES constexpr bool operator!=(precision_reduction x,
377 precision_reduction y) noexcept
378{
380 return static_cast<st>(x) != static_cast<st>(y);
381}
382
383
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)
401
402
403// cuda half operation is supported from arch 5.3
404#if GINKGO_ENABLE_HALF && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 530)
405#define GKO_ADAPT_HF(_macro) _macro
406#else
407#define GKO_ADAPT_HF(_macro) \
408 static_assert(true, \
409 "This assert is used to counter the false positive extra " \
410 "semi-colon warnings")
411#endif
412
413
422#if GINKGO_DPCPP_SINGLE_MODE
423#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro) \
424 template _macro(float); \
425 template <> \
426 _macro(double) GKO_NOT_IMPLEMENTED
427#else
428#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro) \
429 template _macro(float); \
430 template _macro(double)
431#endif
432
433#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE(_macro) \
434 GKO_ADAPT_HF(template _macro(half)); \
435 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro)
436
437
446#if GINKGO_DPCPP_SINGLE_MODE
447#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro) \
448 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro); \
449 template _macro(std::complex<float>); \
450 template <> \
451 _macro(std::complex<double>) GKO_NOT_IMPLEMENTED
452#else
453#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro) \
454 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro); \
455 template _macro(std::complex<float>); \
456 template _macro(std::complex<double>)
457#endif
458
459#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro) \
460 GKO_ADAPT_HF(template _macro(half)); \
461 GKO_ADAPT_HF(template _macro(std::complex<half>)); \
462 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro)
463
464
465// Helper macro to make Windows builds work
466// In MSVC, __VA_ARGS__ behave like one argument by default.
467// with this, we can expand the __VA_ARGS__ properly
468#define GKO_INDIRECT(...) __VA_ARGS__
469
470
481#if GINKGO_DPCPP_SINGLE_MODE
482#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
483 ...) \
484 template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \
485 template <> \
486 GKO_INDIRECT(_macro(double, __VA_ARGS__)) \
487 GKO_NOT_IMPLEMENTED
488#else
489#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
490 ...) \
491 template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \
492 template GKO_INDIRECT(_macro(double, __VA_ARGS__))
493#endif
494
495#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS(_macro, ...) \
496 GKO_INDIRECT(GKO_ADAPT_HF(template _macro(half, __VA_ARGS__))); \
497 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
498 __VA_ARGS__)
499
500
511#if GINKGO_DPCPP_SINGLE_MODE
512#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, ...) \
513 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
514 __VA_ARGS__); \
515 template GKO_INDIRECT(_macro(std::complex<float>, __VA_ARGS__)); \
516 template <> \
517 GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__)) \
518 GKO_NOT_IMPLEMENTED
519#else
520#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, ...) \
521 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
522 __VA_ARGS__); \
523 template GKO_INDIRECT(_macro(std::complex<float>, __VA_ARGS__)); \
524 template GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__))
525#endif
526
527#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, ...) \
528 GKO_INDIRECT(GKO_ADAPT_HF(template _macro(half, __VA_ARGS__))); \
529 GKO_INDIRECT( \
530 GKO_ADAPT_HF(template _macro(std::complex<half>, __VA_ARGS__))); \
531 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, __VA_ARGS__)
532
533
544#if GINKGO_DPCPP_SINGLE_MODE
545#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro) \
546 template _macro(float, float); \
547 template <> \
548 _macro(double, double) GKO_NOT_IMPLEMENTED; \
549 template _macro(std::complex<float>, std::complex<float>); \
550 template <> \
551 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
552 template _macro(std::complex<float>, float); \
553 template <> \
554 _macro(std::complex<double>, double) GKO_NOT_IMPLEMENTED;
555#else
556#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro) \
557 template _macro(float, float); \
558 template _macro(double, double); \
559 template _macro(std::complex<float>, std::complex<float>); \
560 template _macro(std::complex<double>, std::complex<double>); \
561 template _macro(std::complex<float>, float); \
562 template _macro(std::complex<double>, double)
563#endif
564
565#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE(_macro) \
566 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro); \
567 GKO_ADAPT_HF(template _macro(half, half)); \
568 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<half>)); \
569 GKO_ADAPT_HF(template _macro(std::complex<half>, half))
570
571
580#define GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) \
581 template _macro(int32); \
582 template _macro(int64)
583
584
594#if GINKGO_DPCPP_SINGLE_MODE
595#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro) \
596 template _macro(float, int32); \
597 template <> \
598 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
599 template _macro(float, int64); \
600 template <> \
601 _macro(double, int64) GKO_NOT_IMPLEMENTED
602#else
603#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro) \
604 template _macro(float, int32); \
605 template _macro(double, int32); \
606 template _macro(float, int64); \
607 template _macro(double, int64)
608#endif
609#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE(_macro) \
610 GKO_ADAPT_HF(template _macro(half, int32)); \
611 GKO_ADAPT_HF(template _macro(half, int64)); \
612 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro)
613
614#if GINKGO_DPCPP_SINGLE_MODE
615#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro) \
616 template _macro(float, int32); \
617 template <> \
618 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
619 template _macro(std::complex<float>, int32); \
620 template <> \
621 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED
622#else
623#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro) \
624 template _macro(float, int32); \
625 template _macro(double, int32); \
626 template _macro(std::complex<float>, int32); \
627 template _macro(std::complex<double>, int32)
628#endif
629
630#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE(_macro) \
631 GKO_ADAPT_HF(template _macro(half, int32)); \
632 GKO_ADAPT_HF(template _macro(std::complex<half>, int32)); \
633 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro)
634
635
644#if GINKGO_DPCPP_SINGLE_MODE
645#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE_BASE(_macro) \
646 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro); \
647 template _macro(std::complex<float>, int32); \
648 template <> \
649 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED; \
650 template _macro(std::complex<float>, int64); \
651 template <> \
652 _macro(std::complex<double>, int64) GKO_NOT_IMPLEMENTED
653#else
654#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE_BASE(_macro) \
655 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_INDEX_TYPE_BASE(_macro); \
656 template _macro(std::complex<float>, int32); \
657 template _macro(std::complex<double>, int32); \
658 template _macro(std::complex<float>, int64); \
659 template _macro(std::complex<double>, int64)
660#endif
661
662#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE(_macro) \
663 GKO_ADAPT_HF(template _macro(half, int32)); \
664 GKO_ADAPT_HF(template _macro(half, int64)); \
665 GKO_ADAPT_HF(template _macro(std::complex<half>, int32)); \
666 GKO_ADAPT_HF(template _macro(std::complex<half>, int64)); \
667 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INDEX_TYPE_BASE(_macro)
668
669
679#if GINKGO_DPCPP_SINGLE_MODE
680#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
681 _macro) \
682 template _macro(float, int32, int32); \
683 template _macro(float, int32, int64); \
684 template _macro(float, int64, int64); \
685 template <> \
686 _macro(double, int32, int32) GKO_NOT_IMPLEMENTED; \
687 template <> \
688 _macro(double, int32, int64) GKO_NOT_IMPLEMENTED; \
689 template <> \
690 _macro(double, int64, int64) GKO_NOT_IMPLEMENTED
691#else
692#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
693 _macro) \
694 template _macro(float, int32, int32); \
695 template _macro(float, int32, int64); \
696 template _macro(float, int64, int64); \
697 template _macro(double, int32, int32); \
698 template _macro(double, int32, int64); \
699 template _macro(double, int64, int64)
700#endif
701
702#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
703 _macro) \
704 GKO_ADAPT_HF(template _macro(half, int32, int32)); \
705 GKO_ADAPT_HF(template _macro(half, int32, int64)); \
706 GKO_ADAPT_HF(template _macro(half, int64, int64)); \
707 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
708 _macro)
709
710
719#if GINKGO_DPCPP_SINGLE_MODE
720#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
721 _macro) \
722 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
723 _macro); \
724 template _macro(std::complex<float>, int32, int32); \
725 template _macro(std::complex<float>, int32, int64); \
726 template _macro(std::complex<float>, int64, int64); \
727 template <> \
728 _macro(std::complex<double>, int32, int32) GKO_NOT_IMPLEMENTED; \
729 template <> \
730 _macro(std::complex<double>, int32, int64) GKO_NOT_IMPLEMENTED; \
731 template <> \
732 _macro(std::complex<double>, int64, int64) GKO_NOT_IMPLEMENTED
733#else
734#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
735 _macro) \
736 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
737 _macro); \
738 template _macro(std::complex<float>, int32, int32); \
739 template _macro(std::complex<float>, int32, int64); \
740 template _macro(std::complex<float>, int64, int64); \
741 template _macro(std::complex<double>, int32, int32); \
742 template _macro(std::complex<double>, int32, int64); \
743 template _macro(std::complex<double>, int64, int64)
744#endif
745
746#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
747 GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE(_macro); \
748 GKO_ADAPT_HF(template _macro(half, int32, int32)); \
749 GKO_ADAPT_HF(template _macro(half, int32, int64)); \
750 GKO_ADAPT_HF(template _macro(half, int64, int64)); \
751 GKO_ADAPT_HF(template _macro(std::complex<half>, int32, int32)); \
752 GKO_ADAPT_HF(template _macro(std::complex<half>, int32, int64)); \
753 GKO_ADAPT_HF(template _macro(std::complex<half>, int64, int64))
754
755
756#if GINKGO_DPCPP_SINGLE_MODE
757#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro) \
758 template <> \
759 _macro(float, double) GKO_NOT_IMPLEMENTED; \
760 template <> \
761 _macro(double, float) GKO_NOT_IMPLEMENTED; \
762 template <> \
763 _macro(std::complex<float>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
764 template <> \
765 _macro(std::complex<double>, std::complex<float>) GKO_NOT_IMPLEMENTED
766
767
768#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY_BASE(_macro) \
769 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro); \
770 template _macro(float, float); \
771 template <> \
772 _macro(double, double) GKO_NOT_IMPLEMENTED; \
773 template _macro(std::complex<float>, std::complex<float>); \
774 template <> \
775 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED
776#else
786#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro) \
787 template _macro(float, double); \
788 template _macro(double, float); \
789 template _macro(std::complex<float>, std::complex<double>); \
790 template _macro(std::complex<double>, std::complex<float>)
791
792
802#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY_BASE(_macro) \
803 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro); \
804 template _macro(float, float); \
805 template _macro(double, double); \
806 template _macro(std::complex<float>, std::complex<float>); \
807 template _macro(std::complex<double>, std::complex<double>)
808#endif
809
810#if GINKGO_DPCPP_SINGLE_MODE
811#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
812 GKO_ADAPT_HF(template <> _macro(half, double) GKO_NOT_IMPLEMENTED); \
813 GKO_ADAPT_HF(template <> _macro(double, half) GKO_NOT_IMPLEMENTED); \
814 GKO_ADAPT_HF(template _macro(float, half)); \
815 GKO_ADAPT_HF(template _macro(half, float)); \
816 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<float>)); \
817 GKO_ADAPT_HF(template <> _macro(std::complex<half>, std::complex<double>) \
818 GKO_NOT_IMPLEMENTED); \
819 GKO_ADAPT_HF(template _macro(std::complex<float>, std::complex<half>)); \
820 GKO_ADAPT_HF(template <> _macro(std::complex<double>, std::complex<half>) \
821 GKO_NOT_IMPLEMENTED); \
822 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro)
823#else
824#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro) \
825 GKO_ADAPT_HF(template _macro(half, double)); \
826 GKO_ADAPT_HF(template _macro(double, half)); \
827 GKO_ADAPT_HF(template _macro(float, half)); \
828 GKO_ADAPT_HF(template _macro(half, float)); \
829 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<float>)); \
830 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<double>)); \
831 GKO_ADAPT_HF(template _macro(std::complex<float>, std::complex<half>)); \
832 GKO_ADAPT_HF(template _macro(std::complex<double>, std::complex<half>)); \
833 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro)
834#endif
835
836#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_OR_COPY(_macro) \
837 GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION(_macro); \
838 GKO_ADAPT_HF(template _macro(half, half)); \
839 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<half>)); \
840 template _macro(float, float); \
841 template _macro(double, double); \
842 template _macro(std::complex<float>, std::complex<float>); \
843 template _macro(std::complex<double>, std::complex<double>)
844
853#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR_BASE(_macro) \
854 template _macro(float, float); \
855 template _macro(double, double); \
856 template _macro(std::complex<float>, float); \
857 template _macro(std::complex<double>, double); \
858 template _macro(std::complex<float>, std::complex<float>); \
859 template _macro(std::complex<double>, std::complex<double>)
860
861#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR(_macro) \
862 GKO_ADAPT_HF(template _macro(half, half)); \
863 GKO_ADAPT_HF(template _macro(std::complex<half>, half)); \
864 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<half>)); \
865 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR_BASE(_macro)
866
876#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE_BASE(_macro) \
877 template _macro(char, char); \
878 template _macro(int32, int32); \
879 template _macro(int64, int64); \
880 template _macro(unsigned int, unsigned int); \
881 template _macro(unsigned long, unsigned long); \
882 template _macro(float, float); \
883 template _macro(double, double); \
884 template _macro(long double, long double); \
885 template _macro(std::complex<float>, std::complex<float>); \
886 template _macro(std::complex<double>, std::complex<double>)
887
888#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE(_macro) \
889 GKO_ADAPT_HF(template _macro(half, half)); \
890 GKO_ADAPT_HF(template _macro(std::complex<half>, std::complex<half>)); \
891 GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE_BASE(_macro)
892
901#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE_BASE(_macro) \
902 template _macro(float); \
903 template _macro(double); \
904 template _macro(std::complex<float>); \
905 template _macro(std::complex<double>); \
906 template _macro(size_type); \
907 template _macro(bool); \
908 template _macro(int32); \
909 template _macro(int64)
910
911#define GKO_INSTANTIATE_FOR_EACH_POD_TYPE(_macro) \
912 GKO_ADAPT_HF(template _macro(half)); \
913 GKO_ADAPT_HF(template _macro(std::complex<half>)); \
914 GKO_INSTANTIATE_FOR_EACH_POD_TYPE_BASE(_macro)
915
924#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE_BASE(_macro) \
925 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_BASE(_macro); \
926 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
927 template _macro(gko::size_type)
928
929#define GKO_INSTANTIATE_FOR_EACH_TEMPLATE_TYPE(_macro) \
930 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE(_macro); \
931 GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro); \
932 template _macro(gko::size_type)
933
934
943#define GKO_INSTANTIATE_FOR_INT32_TYPE(_macro) template _macro(int32)
944
945
949template <typename IndexType>
950inline constexpr GKO_ATTRIBUTES IndexType invalid_index()
951{
952 static_assert(std::is_signed<IndexType>::value,
953 "IndexType needs to be signed");
954 return static_cast<IndexType>(-1);
955}
956
957
958namespace experimental {
959namespace distributed {
960
961
967using comm_index_type = int;
968
969
979#define GKO_INSTANTIATE_FOR_EACH_LOCAL_GLOBAL_INDEX_TYPE(_macro) \
980 template _macro(int32, int32); \
981 template _macro(int32, int64); \
982 template _macro(int64, int64)
983
984
985} // namespace distributed
986} // namespace experimental
987} // namespace gko
988
989
990#endif // GKO_PUBLIC_CORE_BASE_TYPES_HPP_
A class providing basic support for half precision floating point types.
Definition half.hpp:286
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:967
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:118
std::uint64_t uint64
64-bit unsigned integral type.
Definition types.hpp:135
std::int32_t int32
32-bit signed integral type.
Definition types.hpp:106
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:100
std::uintptr_t uintptr
Unsigned integer type capable of holding a pointer to void.
Definition types.hpp:141
std::uint32_t uint32
32-bit unsigned integral type.
Definition types.hpp:129
std::int8_t int8
8-bit signed integral type.
Definition types.hpp:95
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:112
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:89
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:123
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:950
Evaluates if all template arguments Args fulfill std::is_integral.
Definition types.hpp:189