Skip to content

Commit

Permalink
reuse the macro from another pr
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Koch <[email protected]>
  • Loading branch information
yhmtsai and MarcelKoch committed Nov 13, 2024
1 parent d22eecc commit 3408b2b
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 41 deletions.
24 changes: 12 additions & 12 deletions core/base/batch_instantiation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 46 additions & 29 deletions include/ginkgo/core/base/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<float>, __VA_ARGS__); \
template <> \
_macro(std::complex<double>, __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<float>, __VA_ARGS__)); \
template <> \
GKO_INDIRECT(_macro(std::complex<double>, __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<float>, __VA_ARGS__); \
template _macro(std::complex<double>, __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<float>, __VA_ARGS__)); \
template GKO_INDIRECT(_macro(std::complex<double>, __VA_ARGS__))
#endif


Expand Down

0 comments on commit 3408b2b

Please sign in to comment.