thrust_resize.hpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/external/thrust/thrust_resize.hpp
  4. [begin_description]
  5. Enable resizing for thrusts device and host_vector.
  6. [end_description]
  7. Copyright 2010-2014 Mario Mulansky
  8. Copyright 2010-2011 Karsten Ahnert
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
  15. #include <type_traits>
  16. #include <boost/range.hpp>
  17. #include <thrust/device_vector.h>
  18. #include <thrust/host_vector.h>
  19. #include <thrust/distance.h>
  20. #include <boost/numeric/odeint/util/resize.hpp>
  21. #include <boost/numeric/odeint/util/same_size.hpp>
  22. #include <boost/numeric/odeint/util/copy.hpp>
  23. namespace boost {
  24. namespace numeric {
  25. namespace odeint {
  26. // some macros that define the necessary utilities
  27. #define ODEINT_THRUST_VECTOR_IS_RESIZEABLE( THRUST_VECTOR ) \
  28. template< class T , class A > \
  29. struct is_resizeable< THRUST_VECTOR<T,A> > \
  30. { \
  31. struct type : public std::true_type { }; \
  32. const static bool value = type::value; \
  33. }; \
  34. #define ODEINT_TRHUST_VECTOR_RESIZE_IMPL( THRUST_VECTOR ) \
  35. template< class T, class A > \
  36. struct resize_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
  37. { \
  38. static void resize( THRUST_VECTOR<T,A> &x , \
  39. const THRUST_VECTOR<T,A> &y ) \
  40. { \
  41. x.resize( y.size() ); \
  42. } \
  43. }; \
  44. template< class T, class A, typename Range > \
  45. struct resize_impl< THRUST_VECTOR<T,A> , Range > \
  46. { \
  47. static void resize( THRUST_VECTOR<T,A> &x , \
  48. const Range &y ) \
  49. { \
  50. x.resize( thrust::distance(boost::begin(y), \
  51. boost::end(y))); \
  52. } \
  53. }; \
  54. #define ODEINT_THRUST_SAME_SIZE_IMPL( THRUST_VECTOR ) \
  55. template< class T , class A > \
  56. struct same_size_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
  57. { \
  58. static bool same_size( const THRUST_VECTOR<T,A> &x , \
  59. const THRUST_VECTOR<T,A> &y ) \
  60. { \
  61. return x.size() == y.size(); \
  62. } \
  63. }; \
  64. template< class T , class A, typename Range > \
  65. struct same_size_impl< THRUST_VECTOR<T,A> , Range > \
  66. { \
  67. static bool same_size( const THRUST_VECTOR<T,A> &x , \
  68. const Range &y ) \
  69. { \
  70. return x.size() == thrust::distance(boost::begin(y), \
  71. boost::end(y)); \
  72. } \
  73. }; \
  74. #define ODEINT_THRUST_COPY_IMPL( THRUST_VECTOR ) \
  75. template< class Container1 , class T , class A > \
  76. struct copy_impl< Container1 , THRUST_VECTOR<T,A> > \
  77. { \
  78. static void copy( const Container1 &from , THRUST_VECTOR<T,A> &to ) \
  79. { \
  80. thrust::copy( boost::begin( from ) , boost::end( from ) , \
  81. boost::begin( to ) ); \
  82. } \
  83. }; \
  84. \
  85. template< class T , class A , class Container2 > \
  86. struct copy_impl< THRUST_VECTOR<T,A> , Container2 > \
  87. { \
  88. static void copy( const THRUST_VECTOR<T,A> &from , Container2 &to ) \
  89. { \
  90. thrust::copy( boost::begin( from ) , boost::end( from ) , \
  91. boost::begin( to ) ); \
  92. } \
  93. }; \
  94. \
  95. template< class T , class A > \
  96. struct copy_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
  97. { \
  98. static void copy( const THRUST_VECTOR<T,A> &from , \
  99. THRUST_VECTOR<T,A> &to ) \
  100. { \
  101. thrust::copy( boost::begin( from ) , boost::end( from ) , \
  102. boost::begin( to ) ); \
  103. } \
  104. }; \
  105. // add support for the standard thrust containers
  106. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::device_vector )
  107. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::device_vector )
  108. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::device_vector )
  109. ODEINT_THRUST_COPY_IMPL( thrust::device_vector )
  110. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::host_vector )
  111. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::host_vector )
  112. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::host_vector )
  113. ODEINT_THRUST_COPY_IMPL( thrust::host_vector )
  114. } // odeint
  115. } // numeric
  116. } // boost
  117. // add support for thrust backend vectors, if available
  118. #include <thrust/version.h>
  119. #if THRUST_VERSION >= 101000
  120. #include <thrust/detail/vector_base.h>
  121. namespace boost { namespace numeric { namespace odeint {
  122. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::detail::vector_base )
  123. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::detail::vector_base )
  124. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::detail::vector_base )
  125. ODEINT_THRUST_COPY_IMPL( thrust::detail::vector_base )
  126. } } }
  127. #elif THRUST_VERSION >= 100600
  128. #include <thrust/system/cpp/vector.h>
  129. namespace boost { namespace numeric { namespace odeint {
  130. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cpp::vector )
  131. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cpp::vector )
  132. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cpp::vector )
  133. ODEINT_THRUST_COPY_IMPL( thrust::cpp::vector )
  134. } } }
  135. #ifdef _OPENMP
  136. #include <thrust/system/omp/vector.h>
  137. namespace boost { namespace numeric { namespace odeint {
  138. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::omp::vector )
  139. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::omp::vector )
  140. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::omp::vector )
  141. ODEINT_THRUST_COPY_IMPL( thrust::omp::vector )
  142. } } }
  143. #endif // _OPENMP
  144. #ifdef TBB_VERSION_MAJOR
  145. #include <thrust/system/tbb/vector.h>
  146. namespace boost { namespace numeric { namespace odeint {
  147. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::tbb::vector )
  148. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::tbb::vector )
  149. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::tbb::vector )
  150. ODEINT_THRUST_COPY_IMPL( thrust::tbb::vector )
  151. } } }
  152. #endif // TBB_VERSION_MAJOR
  153. #ifdef __CUDACC__
  154. #include <thrust/system/cuda/vector.h>
  155. namespace boost { namespace numeric { namespace odeint {
  156. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cuda::vector )
  157. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cuda::vector )
  158. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cuda::vector )
  159. ODEINT_THRUST_COPY_IMPL( thrust::cuda::vector )
  160. } } }
  161. #endif // __CUDACC__
  162. #endif // THRUST_VERSION >= 100600
  163. #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED