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