thrust_resize.hpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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 <boost/range.hpp>
  16. #include <thrust/device_vector.h>
  17. #include <thrust/host_vector.h>
  18. #include <thrust/distance.h>
  19. #include <boost/numeric/odeint/util/resize.hpp>
  20. #include <boost/numeric/odeint/util/same_size.hpp>
  21. #include <boost/numeric/odeint/util/copy.hpp>
  22. namespace boost {
  23. namespace numeric {
  24. namespace odeint {
  25. // some macros that define the necessary utilities
  26. #define ODEINT_THRUST_VECTOR_IS_RESIZEABLE( THRUST_VECTOR ) \
  27. template< class T , class A > \
  28. struct is_resizeable< THRUST_VECTOR<T,A> > \
  29. { \
  30. struct type : public boost::true_type { }; \
  31. const static bool value = type::value; \
  32. }; \
  33. #define ODEINT_TRHUST_VECTOR_RESIZE_IMPL( THRUST_VECTOR ) \
  34. template< class T, class A > \
  35. struct resize_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
  36. { \
  37. static void resize( THRUST_VECTOR<T,A> &x , \
  38. const THRUST_VECTOR<T,A> &y ) \
  39. { \
  40. x.resize( y.size() ); \
  41. } \
  42. }; \
  43. template< class T, class A, typename Range > \
  44. struct resize_impl< THRUST_VECTOR<T,A> , Range > \
  45. { \
  46. static void resize( THRUST_VECTOR<T,A> &x , \
  47. const Range &y ) \
  48. { \
  49. x.resize( thrust::distance(boost::begin(y), \
  50. boost::end(y))); \
  51. } \
  52. }; \
  53. #define ODEINT_THRUST_SAME_SIZE_IMPL( THRUST_VECTOR ) \
  54. template< class T , class A > \
  55. struct same_size_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
  56. { \
  57. static bool same_size( const THRUST_VECTOR<T,A> &x , \
  58. const THRUST_VECTOR<T,A> &y ) \
  59. { \
  60. return x.size() == y.size(); \
  61. } \
  62. }; \
  63. template< class T , class A, typename Range > \
  64. struct same_size_impl< THRUST_VECTOR<T,A> , Range > \
  65. { \
  66. static bool same_size( const THRUST_VECTOR<T,A> &x , \
  67. const Range &y ) \
  68. { \
  69. return x.size() == thrust::distance(boost::begin(y), \
  70. boost::end(y)); \
  71. } \
  72. }; \
  73. #define ODEINT_THRUST_COPY_IMPL( THRUST_VECTOR ) \
  74. template< class Container1 , class T , class A > \
  75. struct copy_impl< Container1 , THRUST_VECTOR<T,A> > \
  76. { \
  77. static void copy( const Container1 &from , THRUST_VECTOR<T,A> &to ) \
  78. { \
  79. thrust::copy( boost::begin( from ) , boost::end( from ) , \
  80. boost::begin( to ) ); \
  81. } \
  82. }; \
  83. \
  84. template< class T , class A , class Container2 > \
  85. struct copy_impl< THRUST_VECTOR<T,A> , Container2 > \
  86. { \
  87. static void copy( const THRUST_VECTOR<T,A> &from , Container2 &to ) \
  88. { \
  89. thrust::copy( boost::begin( from ) , boost::end( from ) , \
  90. boost::begin( to ) ); \
  91. } \
  92. }; \
  93. \
  94. template< class T , class A > \
  95. struct copy_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
  96. { \
  97. static void copy( const THRUST_VECTOR<T,A> &from , \
  98. THRUST_VECTOR<T,A> &to ) \
  99. { \
  100. thrust::copy( boost::begin( from ) , boost::end( from ) , \
  101. boost::begin( to ) ); \
  102. } \
  103. }; \
  104. // add support for the standard thrust containers
  105. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::device_vector )
  106. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::device_vector )
  107. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::device_vector )
  108. ODEINT_THRUST_COPY_IMPL( thrust::device_vector )
  109. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::host_vector )
  110. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::host_vector )
  111. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::host_vector )
  112. ODEINT_THRUST_COPY_IMPL( thrust::host_vector )
  113. } // odeint
  114. } // numeric
  115. } // boost
  116. // add support for thrust backend vectors, if available
  117. #include <thrust/version.h>
  118. #if THRUST_VERSION >= 100600
  119. #include <thrust/system/cpp/vector.h>
  120. namespace boost { namespace numeric { namespace odeint {
  121. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cpp::vector )
  122. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cpp::vector )
  123. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cpp::vector )
  124. ODEINT_THRUST_COPY_IMPL( thrust::cpp::vector )
  125. } } }
  126. #ifdef _OPENMP
  127. #include <thrust/system/omp/vector.h>
  128. namespace boost { namespace numeric { namespace odeint {
  129. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::omp::vector )
  130. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::omp::vector )
  131. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::omp::vector )
  132. ODEINT_THRUST_COPY_IMPL( thrust::omp::vector )
  133. } } }
  134. #endif // _OPENMP
  135. #ifdef TBB_VERSION_MAJOR
  136. #include <thrust/system/tbb/vector.h>
  137. namespace boost { namespace numeric { namespace odeint {
  138. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::tbb::vector )
  139. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::tbb::vector )
  140. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::tbb::vector )
  141. ODEINT_THRUST_COPY_IMPL( thrust::tbb::vector )
  142. } } }
  143. #endif // TBB_VERSION_MAJOR
  144. #ifdef __CUDACC__
  145. #include <thrust/system/cuda/vector.h>
  146. namespace boost { namespace numeric { namespace odeint {
  147. ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cuda::vector )
  148. ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cuda::vector )
  149. ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cuda::vector )
  150. ODEINT_THRUST_COPY_IMPL( thrust::cuda::vector )
  151. } } }
  152. #endif // __CUDACC__
  153. #endif // THRUST_VERSION >= 100600
  154. #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED