File indexing completed on 2025-12-17 09:53:58
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
0019 #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
0020
0021 #include <type_traits>
0022
0023 #include <boost/range.hpp>
0024
0025 #include <thrust/device_vector.h>
0026 #include <thrust/host_vector.h>
0027 #include <thrust/distance.h>
0028
0029 #include <boost/numeric/odeint/util/resize.hpp>
0030 #include <boost/numeric/odeint/util/same_size.hpp>
0031 #include <boost/numeric/odeint/util/copy.hpp>
0032
0033 namespace boost {
0034 namespace numeric {
0035 namespace odeint {
0036
0037
0038
0039 #define ODEINT_THRUST_VECTOR_IS_RESIZEABLE( THRUST_VECTOR ) \
0040 template< class T , class A > \
0041 struct is_resizeable< THRUST_VECTOR<T,A> > \
0042 { \
0043 struct type : public std::true_type { }; \
0044 const static bool value = type::value; \
0045 }; \
0046
0047 #define ODEINT_TRHUST_VECTOR_RESIZE_IMPL( THRUST_VECTOR ) \
0048 template< class T, class A > \
0049 struct resize_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
0050 { \
0051 static void resize( THRUST_VECTOR<T,A> &x , \
0052 const THRUST_VECTOR<T,A> &y ) \
0053 { \
0054 x.resize( y.size() ); \
0055 } \
0056 }; \
0057 template< class T, class A, typename Range > \
0058 struct resize_impl< THRUST_VECTOR<T,A> , Range > \
0059 { \
0060 static void resize( THRUST_VECTOR<T,A> &x , \
0061 const Range &y ) \
0062 { \
0063 x.resize( thrust::distance(boost::begin(y), \
0064 boost::end(y))); \
0065 } \
0066 }; \
0067
0068
0069 #define ODEINT_THRUST_SAME_SIZE_IMPL( THRUST_VECTOR ) \
0070 template< class T , class A > \
0071 struct same_size_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
0072 { \
0073 static bool same_size( const THRUST_VECTOR<T,A> &x , \
0074 const THRUST_VECTOR<T,A> &y ) \
0075 { \
0076 return x.size() == y.size(); \
0077 } \
0078 }; \
0079 template< class T , class A, typename Range > \
0080 struct same_size_impl< THRUST_VECTOR<T,A> , Range > \
0081 { \
0082 static bool same_size( const THRUST_VECTOR<T,A> &x , \
0083 const Range &y ) \
0084 { \
0085 return x.size() == thrust::distance(boost::begin(y), \
0086 boost::end(y)); \
0087 } \
0088 }; \
0089
0090
0091 #define ODEINT_THRUST_COPY_IMPL( THRUST_VECTOR ) \
0092 template< class Container1 , class T , class A > \
0093 struct copy_impl< Container1 , THRUST_VECTOR<T,A> > \
0094 { \
0095 static void copy( const Container1 &from , THRUST_VECTOR<T,A> &to ) \
0096 { \
0097 thrust::copy( boost::begin( from ) , boost::end( from ) , \
0098 boost::begin( to ) ); \
0099 } \
0100 }; \
0101 \
0102 template< class T , class A , class Container2 > \
0103 struct copy_impl< THRUST_VECTOR<T,A> , Container2 > \
0104 { \
0105 static void copy( const THRUST_VECTOR<T,A> &from , Container2 &to ) \
0106 { \
0107 thrust::copy( boost::begin( from ) , boost::end( from ) , \
0108 boost::begin( to ) ); \
0109 } \
0110 }; \
0111 \
0112 template< class T , class A > \
0113 struct copy_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
0114 { \
0115 static void copy( const THRUST_VECTOR<T,A> &from , \
0116 THRUST_VECTOR<T,A> &to ) \
0117 { \
0118 thrust::copy( boost::begin( from ) , boost::end( from ) , \
0119 boost::begin( to ) ); \
0120 } \
0121 }; \
0122
0123
0124
0125 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::device_vector )
0126 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::device_vector )
0127 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::device_vector )
0128 ODEINT_THRUST_COPY_IMPL( thrust::device_vector )
0129
0130
0131 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::host_vector )
0132 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::host_vector )
0133 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::host_vector )
0134 ODEINT_THRUST_COPY_IMPL( thrust::host_vector )
0135
0136
0137 }
0138 }
0139 }
0140
0141
0142
0143 #include <thrust/version.h>
0144
0145 #if THRUST_VERSION >= 101000
0146
0147 #include <thrust/detail/vector_base.h>
0148 namespace boost { namespace numeric { namespace odeint {
0149 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::detail::vector_base )
0150 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::detail::vector_base )
0151 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::detail::vector_base )
0152 ODEINT_THRUST_COPY_IMPL( thrust::detail::vector_base )
0153 } } }
0154
0155 #elif THRUST_VERSION >= 100600
0156
0157 #include <thrust/system/cpp/vector.h>
0158 namespace boost { namespace numeric { namespace odeint {
0159 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cpp::vector )
0160 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cpp::vector )
0161 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cpp::vector )
0162 ODEINT_THRUST_COPY_IMPL( thrust::cpp::vector )
0163 } } }
0164
0165 #ifdef _OPENMP
0166 #include <thrust/system/omp/vector.h>
0167 namespace boost { namespace numeric { namespace odeint {
0168 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::omp::vector )
0169 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::omp::vector )
0170 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::omp::vector )
0171 ODEINT_THRUST_COPY_IMPL( thrust::omp::vector )
0172 } } }
0173 #endif
0174
0175 #ifdef TBB_VERSION_MAJOR
0176 #include <thrust/system/tbb/vector.h>
0177 namespace boost { namespace numeric { namespace odeint {
0178 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::tbb::vector )
0179 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::tbb::vector )
0180 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::tbb::vector )
0181 ODEINT_THRUST_COPY_IMPL( thrust::tbb::vector )
0182 } } }
0183 #endif
0184
0185 #ifdef __CUDACC__
0186 #include <thrust/system/cuda/vector.h>
0187 namespace boost { namespace numeric { namespace odeint {
0188 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cuda::vector )
0189 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cuda::vector )
0190 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cuda::vector )
0191 ODEINT_THRUST_COPY_IMPL( thrust::cuda::vector )
0192 } } }
0193 #endif
0194
0195 #endif
0196
0197 #endif