Ginkgo Generated from branch based on main. Ginkgo version 1.10.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
types.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 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/bfloat16.hpp>
22#include <ginkgo/core/base/half.hpp>
23
24
25#ifdef __HIPCC__
26#include <hip/hip_runtime.h>
27#endif // __HIPCC__
28
29
30// Macros for handling different compilers / architectures uniformly
31#if defined(__CUDACC__) || defined(__HIPCC__)
32#define GKO_ATTRIBUTES __host__ __device__
33#define GKO_INLINE __forceinline__
34#define GKO_RESTRICT __restrict__
35#else
36#define GKO_ATTRIBUTES
37#define GKO_INLINE inline
38#define GKO_RESTRICT
39#endif // defined(__CUDACC__) || defined(__HIPCC__)
40
41
42// Macros for handling different device error return types uniformly
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
51#else
52#define GKO_DEVICE_ERROR_TYPE int
53#define GKO_DEVICE_ERROR_INVALID 1
54#define GKO_DEVICE_NO_ERROR 0
55#endif
56
57
58#define GKO_ASSERT(condition) assert(condition)
59
60
61// Handle deprecated notices correctly on different systems
62// clang-format off
63#define GKO_DEPRECATED(_msg) [[deprecated(_msg)]]
64#ifdef __NVCOMPILER
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)")
77#else
78#define GKO_BEGIN_DISABLE_DEPRECATION_WARNINGS
79#define GKO_END_DISABLE_DEPRECATION_WARNINGS
80#endif
81// clang-format on
82
83
84namespace gko {
85
86
90using size_type = std::size_t;
91
92
96using int8 = std::int8_t;
97
101using int16 = std::int16_t;
102
103
107using int32 = std::int32_t;
108
109
113using int64 = std::int64_t;
114
115
119using uint8 = std::uint8_t;
120
124using uint16 = std::uint16_t;
125
126
130using uint32 = std::uint32_t;
131
132
136using uint64 = std::uint64_t;
137
138
142using uintptr = std::uintptr_t;
143
144
148using float16 = half;
149
150
154using float32 = float;
155
156
160using float64 = double;
161
162
166using full_precision = double;
167
168
172using default_precision = double;
173
174
178constexpr size_type byte_size = CHAR_BIT;
179
180
189template <typename... Args>
190struct are_all_integral : public std::true_type {};
191
192template <typename First, typename... Args>
193struct are_all_integral<First, Args...>
194 : public std::conditional<std::is_integral<std::decay_t<First>>::value,
195 are_all_integral<Args...>,
196 std::false_type>::type {};
197
198
240public:
245
246private:
247 static constexpr auto nonpreserving_bits = 4u;
248 static constexpr auto preserving_bits =
249 byte_size * sizeof(storage_type) - nonpreserving_bits;
250 static constexpr auto nonpreserving_mask =
251 storage_type{(0x1 << nonpreserving_bits) - 1};
252 static constexpr auto preserving_mask =
253 storage_type{(0x1 << preserving_bits) - 1} << nonpreserving_bits;
254
255public:
261 GKO_ATTRIBUTES constexpr precision_reduction() noexcept : data_{0x0} {}
262
270 GKO_ATTRIBUTES constexpr precision_reduction(
271 storage_type preserving, storage_type nonpreserving) noexcept
272 : data_((GKO_ASSERT(preserving < (0x1 << preserving_bits) - 1),
273 GKO_ASSERT(nonpreserving < (0x1 << nonpreserving_bits) - 1),
274 (preserving << nonpreserving_bits) | nonpreserving))
275 {}
276
282 GKO_ATTRIBUTES constexpr operator storage_type() const noexcept
283 {
284 return data_;
285 }
286
292 GKO_ATTRIBUTES constexpr storage_type get_preserving() const noexcept
293 {
294 return (data_ & preserving_mask) >> nonpreserving_bits;
295 }
296
302 GKO_ATTRIBUTES constexpr storage_type get_nonpreserving() const noexcept
303 {
304 return data_ & nonpreserving_mask;
305 }
306
314 GKO_ATTRIBUTES constexpr static precision_reduction autodetect() noexcept
315 {
316 return precision_reduction{preserving_mask | nonpreserving_mask};
317 }
318
330 GKO_ATTRIBUTES constexpr static precision_reduction common(
332 {
333 return precision_reduction(
334 min(x.data_ & preserving_mask, y.data_ & preserving_mask) |
335 min(x.data_ & nonpreserving_mask, y.data_ & nonpreserving_mask));
336 }
337
338private:
339 GKO_ATTRIBUTES constexpr precision_reduction(storage_type data)
340 : data_{data}
341 {}
342
343 GKO_ATTRIBUTES constexpr static storage_type min(storage_type x,
344 storage_type y) noexcept
345 {
346 return x < y ? x : y;
347 }
348
349 storage_type data_;
350};
351
352
361GKO_ATTRIBUTES constexpr bool operator==(precision_reduction x,
362 precision_reduction y) noexcept
363{
365 return static_cast<st>(x) == static_cast<st>(y);
366}
367
368
377GKO_ATTRIBUTES constexpr bool operator!=(precision_reduction x,
378 precision_reduction y) noexcept
379{
381 return static_cast<st>(x) != static_cast<st>(y);
382}
383
384
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)
402
403
404// cuda half operation is supported from arch 5.3
405#if GINKGO_ENABLE_HALF && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 530)
406#define GKO_ADAPT_HF(_macro) _macro
407#else
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")
412#endif
413
414
415// cuda bfloat16 arithmetic operation is supported from arch 8.0
416#if GINKGO_ENABLE_BFLOAT16 && (!defined(__CUDA_ARCH__) || __CUDA_ARCH__ >= 800)
417#define GKO_ADAPT_BF(_macro) _macro
418#else
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")
423#endif
424
433#if GINKGO_DPCPP_SINGLE_MODE
434#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro) \
435 template _macro(float); \
436 template <> \
437 _macro(double) GKO_NOT_IMPLEMENTED
438#else
439#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_BASE(_macro) \
440 template _macro(float); \
441 template _macro(double)
442#endif
443
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)
448
449
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>); \
462 template <> \
463 _macro(std::complex<double>) GKO_NOT_IMPLEMENTED
464#else
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>)
469#endif
470
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)
477
478
479// Helper macro to make Windows builds work
480// In MSVC, __VA_ARGS__ behave like one argument by default.
481// with this, we can expand the __VA_ARGS__ properly
482#define GKO_INDIRECT(...) __VA_ARGS__
483
484
495#if GINKGO_DPCPP_SINGLE_MODE
496#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
497 ...) \
498 template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \
499 template <> \
500 GKO_INDIRECT(_macro(double, __VA_ARGS__)) \
501 GKO_NOT_IMPLEMENTED
502#else
503#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
504 ...) \
505 template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \
506 template GKO_INDIRECT(_macro(double, __VA_ARGS__))
507#endif
508
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, \
513 __VA_ARGS__)
514
515
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, \
529 __VA_ARGS__); \
530 template GKO_INDIRECT(_macro(std::complex<float>, __VA_ARGS__)); \
531 template <> \
532 GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__)) \
533 GKO_NOT_IMPLEMENTED
534#else
535#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, ...) \
536 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS_BASE(_macro, \
537 __VA_ARGS__); \
538 template GKO_INDIRECT(_macro(std::complex<float>, __VA_ARGS__)); \
539 template GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__))
540#endif
541
542#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, ...) \
543 GKO_INDIRECT(GKO_ADAPT_HF(template _macro(float16, __VA_ARGS__))); \
544 GKO_INDIRECT( \
545 GKO_ADAPT_HF(template _macro(std::complex<float16>, __VA_ARGS__))); \
546 GKO_INDIRECT(GKO_ADAPT_BF(template _macro(bfloat16, __VA_ARGS__))); \
547 GKO_INDIRECT( \
548 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, __VA_ARGS__))); \
549 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS_BASE(_macro, __VA_ARGS__)
550
551
562#if GINKGO_DPCPP_SINGLE_MODE
563#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_SCALAR_TYPE_BASE(_macro) \
564 template _macro(float, float); \
565 template <> \
566 _macro(double, double) GKO_NOT_IMPLEMENTED; \
567 template _macro(std::complex<float>, std::complex<float>); \
568 template <> \
569 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
570 template _macro(std::complex<float>, float); \
571 template <> \
572 _macro(std::complex<double>, double) GKO_NOT_IMPLEMENTED;
573#else
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)
581#endif
582
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)); \
586 GKO_ADAPT_HF( \
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)); \
590 GKO_ADAPT_BF( \
591 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
592 GKO_ADAPT_BF(template _macro(std::complex<bfloat16>, bfloat16))
593
594
603#define GKO_INSTANTIATE_FOR_EACH_INDEX_TYPE(_macro) \
604 template _macro(int32); \
605 template _macro(int64)
606
607
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); \
620 template <> \
621 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
622 template _macro(float, int64); \
623 template <> \
624 _macro(double, int64) GKO_NOT_IMPLEMENTED
625#else
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)
631#endif
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)
638
639#if GINKGO_DPCPP_SINGLE_MODE
640#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_INT32_TYPE_BASE(_macro) \
641 template _macro(float, int32); \
642 template <> \
643 _macro(double, int32) GKO_NOT_IMPLEMENTED; \
644 template _macro(std::complex<float>, int32); \
645 template <> \
646 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED
647#else
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)
653#endif
654
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)
661
662
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); \
675 template <> \
676 _macro(std::complex<double>, int32) GKO_NOT_IMPLEMENTED; \
677 template _macro(std::complex<float>, int64); \
678 template <> \
679 _macro(std::complex<double>, int64) GKO_NOT_IMPLEMENTED
680#else
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)
687#endif
688
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)
699
700
710#if GINKGO_DPCPP_SINGLE_MODE
711#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
712 _macro) \
713 template _macro(float, int32, int32); \
714 template _macro(float, int32, int64); \
715 template _macro(float, int64, int64); \
716 template <> \
717 _macro(double, int32, int32) GKO_NOT_IMPLEMENTED; \
718 template <> \
719 _macro(double, int32, int64) GKO_NOT_IMPLEMENTED; \
720 template <> \
721 _macro(double, int64, int64) GKO_NOT_IMPLEMENTED
722#else
723#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
724 _macro) \
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)
731#endif
732
733#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE( \
734 _macro) \
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( \
742 _macro)
743
744
753#if GINKGO_DPCPP_SINGLE_MODE
754#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
755 _macro) \
756 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
757 _macro); \
758 template _macro(std::complex<float>, int32, int32); \
759 template _macro(std::complex<float>, int32, int64); \
760 template _macro(std::complex<float>, int64, int64); \
761 template <> \
762 _macro(std::complex<double>, int32, int32) GKO_NOT_IMPLEMENTED; \
763 template <> \
764 _macro(std::complex<double>, int32, int64) GKO_NOT_IMPLEMENTED; \
765 template <> \
766 _macro(std::complex<double>, int64, int64) GKO_NOT_IMPLEMENTED
767#else
768#define GKO_INSTANTIATE_FOR_EACH_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
769 _macro) \
770 GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_AND_LOCAL_GLOBAL_INDEX_TYPE_BASE( \
771 _macro); \
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)
778#endif
779
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))
794
795
796#if GINKGO_DPCPP_SINGLE_MODE
797#define GKO_INSTANTIATE_FOR_EACH_VALUE_CONVERSION_BASE(_macro) \
798 template <> \
799 _macro(float, double) GKO_NOT_IMPLEMENTED; \
800 template <> \
801 _macro(double, float) GKO_NOT_IMPLEMENTED; \
802 template <> \
803 _macro(std::complex<float>, std::complex<double>) GKO_NOT_IMPLEMENTED; \
804 template <> \
805 _macro(std::complex<double>, std::complex<float>) GKO_NOT_IMPLEMENTED
806
807
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); \
811 template <> \
812 _macro(double, double) GKO_NOT_IMPLEMENTED; \
813 template _macro(std::complex<float>, std::complex<float>); \
814 template <> \
815 _macro(std::complex<double>, std::complex<double>) GKO_NOT_IMPLEMENTED
816#else
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>)
831
832
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>)
848#endif
849
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)); \
866 GKO_ADAPT_BF( \
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); \
870 GKO_ADAPT_BF( \
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)
881#else
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>)); \
888 GKO_ADAPT_HF( \
889 template _macro(std::complex<float16>, std::complex<double>)); \
890 GKO_ADAPT_HF(template _macro(std::complex<float>, std::complex<float16>)); \
891 GKO_ADAPT_HF( \
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)); \
897 GKO_ADAPT_BF( \
898 template _macro(std::complex<bfloat16>, std::complex<float>)); \
899 GKO_ADAPT_BF( \
900 template _macro(std::complex<bfloat16>, std::complex<double>)); \
901 GKO_ADAPT_BF( \
902 template _macro(std::complex<float>, std::complex<bfloat16>)); \
903 GKO_ADAPT_BF( \
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)
912#endif
913
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)); \
917 GKO_ADAPT_HF( \
918 template _macro(std::complex<float16>, std::complex<float16>)); \
919 GKO_ADAPT_BF(template _macro(bfloat16, bfloat16)); \
920 GKO_ADAPT_BF( \
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>)
926
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>)
942
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)); \
946 GKO_ADAPT_HF( \
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)); \
950 GKO_ADAPT_BF( \
951 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
952 GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_PAIR_BASE(_macro)
953
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>)
974
975#define GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE(_macro) \
976 GKO_ADAPT_HF(template _macro(float16, float16)); \
977 GKO_ADAPT_HF( \
978 template _macro(std::complex<float16>, std::complex<float16>)); \
979 GKO_ADAPT_BF(template _macro(bfloat16, bfloat16)); \
980 GKO_ADAPT_BF( \
981 template _macro(std::complex<bfloat16>, std::complex<bfloat16>)); \
982 GKO_INSTANTIATE_FOR_EACH_COMBINED_VALUE_AND_INDEX_TYPE_BASE(_macro)
983
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)
1001
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)
1008
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)
1021
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)
1026
1027
1036#define GKO_INSTANTIATE_FOR_INT32_TYPE(_macro) template _macro(int32)
1037
1038
1042template <typename IndexType>
1043inline constexpr GKO_ATTRIBUTES IndexType invalid_index()
1044{
1045 static_assert(std::is_signed<IndexType>::value,
1046 "IndexType needs to be signed");
1047 return static_cast<IndexType>(-1);
1048}
1049
1050
1051namespace experimental {
1052namespace mpi {
1053
1054
1061
1062
1063} // namespace mpi
1064
1065
1066namespace distributed {
1067
1068
1073
1074
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)
1088
1089
1090} // namespace distributed
1091} // namespace experimental
1092} // namespace gko
1093
1094
1095#endif // GKO_PUBLIC_CORE_BASE_TYPES_HPP_
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