diff --git a/core/base/batch_instantiation.hpp b/core/base/batch_instantiation.hpp index a686e9838a7..e7f0153c849 100644 --- a/core/base/batch_instantiation.hpp +++ b/core/base/batch_instantiation.hpp @@ -28,18 +28,18 @@ namespace batch { * * @note the second and third arguments only accept the base type.s */ -#define GKO_INSTANTIATE_FOR_BATCH_VALUE_MATRIX_PRECONDITIONER(_macro) \ - GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS(_macro, gko::batch::matrix::Csr, \ - gko::batch::matrix::Identity); \ - GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS(_macro, gko::batch::matrix::Ell, \ - gko::batch::matrix::Identity); \ - GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS( \ - _macro, gko::batch::matrix::Dense, gko::batch::matrix::Identity); \ - GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS( \ - _macro, gko::batch::matrix::Csr, gko::batch::preconditioner::Jacobi); \ - GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS( \ - _macro, gko::batch::matrix::Ell, gko::batch::preconditioner::Jacobi); \ - GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS( \ +#define GKO_INSTANTIATE_FOR_BATCH_VALUE_MATRIX_PRECONDITIONER(_macro) \ + GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, gko::batch::matrix::Csr, \ + gko::batch::matrix::Identity); \ + GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, gko::batch::matrix::Ell, \ + gko::batch::matrix::Identity); \ + GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS( \ + _macro, gko::batch::matrix::Dense, gko::batch::matrix::Identity); \ + GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS( \ + _macro, gko::batch::matrix::Csr, gko::batch::preconditioner::Jacobi); \ + GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS( \ + _macro, gko::batch::matrix::Ell, gko::batch::preconditioner::Jacobi); \ + GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS( \ _macro, gko::batch::matrix::Dense, gko::batch::preconditioner::Jacobi) } // namespace batch diff --git a/include/ginkgo/core/base/types.hpp b/include/ginkgo/core/base/types.hpp index e1bd3485162..4b06b494707 100644 --- a/include/ginkgo/core/base/types.hpp +++ b/include/ginkgo/core/base/types.hpp @@ -419,23 +419,6 @@ GKO_ATTRIBUTES constexpr bool operator!=(precision_reduction x, template _macro(double) #endif -/** - * Instantiates a template with additional arguments for each non-complex value - * type compiled by Ginkgo. - * - * @see GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE - */ -#if GINKGO_DPCPP_SINGLE_MODE -#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_ARGS(_macro, ...) \ - template _macro(float, __VA_ARGS__); \ - template <> \ - _macro(double, __VA_ARGS__) GKO_NOT_IMPLEMENTED -#else -#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_ARGS(_macro, ...) \ - template _macro(float, __VA_ARGS__); \ - template _macro(double, __VA_ARGS__) -#endif - /** * Instantiates a template for each value type compiled by Ginkgo. @@ -459,23 +442,57 @@ GKO_ATTRIBUTES constexpr bool operator!=(precision_reduction x, #endif +// Helper macro to make Windows builds work +#define GKO_INDIRECT(...) __VA_ARGS__ + + +/** + * Instantiates a template for each non-complex value type compiled by Ginkgo. + * + * @param _macro A macro which expands the template instantiation + * (not including the leading `template` specifier). + * Should take at least two arguments, of which the first one + * is the value type. + * + * @note This won't be necessary after upgrading to C++20 + */ +#if GINKGO_DPCPP_SINGLE_MODE +#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS(_macro, ...) \ + template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \ + template <> \ + GKO_INDIRECT(_macro(double, __VA_ARGS__)) \ + GKO_NOT_IMPLEMENTED +#else +#define GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS(_macro, ...) \ + template GKO_INDIRECT(_macro(float, __VA_ARGS__)); \ + template GKO_INDIRECT(_macro(double, __VA_ARGS__)) +#endif + + /** - * Instantiates a template with additional arguments for each value type - * compiled by Ginkgo. + * Instantiates a template for each non-complex value type compiled by Ginkgo. + * + * @param _macro A macro which expands the template instantiation + * (not including the leading `template` specifier). + * Should take at least two arguments, of which the first one + * is the value type. * - * @see GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE + * @note This won't be necessary after upgrading to C++20 */ #if GINKGO_DPCPP_SINGLE_MODE -#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS(_macro, ...) \ - GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_ARGS(_macro, __VA_ARGS__); \ - template _macro(std::complex, __VA_ARGS__); \ - template <> \ - _macro(std::complex, __VA_ARGS__) GKO_NOT_IMPLEMENTED +#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, ...) \ + GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS(_macro, \ + __VA_ARGS__); \ + template GKO_INDIRECT(_macro(std::complex, __VA_ARGS__)); \ + template <> \ + GKO_INDIRECT(_macro(std::complex, __VA_ARGS__)) \ + GKO_NOT_IMPLEMENTED #else -#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_ARGS(_macro, ...) \ - GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_ARGS(_macro, __VA_ARGS__); \ - template _macro(std::complex, __VA_ARGS__); \ - template _macro(std::complex, __VA_ARGS__) +#define GKO_INSTANTIATE_FOR_EACH_VALUE_TYPE_VARGS(_macro, ...) \ + GKO_INSTANTIATE_FOR_EACH_NON_COMPLEX_VALUE_TYPE_VARGS(_macro, \ + __VA_ARGS__); \ + template GKO_INDIRECT(_macro(std::complex, __VA_ARGS__)); \ + template GKO_INDIRECT(_macro(std::complex, __VA_ARGS__)) #endif