3 boost/numeric/odeint/external/thrust/thrust_resize.hpp
6 Enable resizing for thrusts device and host_vector.
9 Copyright 2010-2014 Mario Mulansky
10 Copyright 2010-2011 Karsten Ahnert
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
18 #ifndef BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
19 #define BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED
21 #include <boost/range.hpp>
23 #include <thrust/device_vector.h>
24 #include <thrust/host_vector.h>
25 #include <thrust/distance.h>
27 #include <boost/numeric/odeint/util/resize.hpp>
28 #include <boost/numeric/odeint/util/same_size.hpp>
29 #include <boost/numeric/odeint/util/copy.hpp>
35 // some macros that define the necessary utilities
37 #define ODEINT_THRUST_VECTOR_IS_RESIZEABLE( THRUST_VECTOR ) \
38 template< class T , class A > \
39 struct is_resizeable< THRUST_VECTOR<T,A> > \
41 struct type : public boost::true_type { }; \
42 const static bool value = type::value; \
45 #define ODEINT_TRHUST_VECTOR_RESIZE_IMPL( THRUST_VECTOR ) \
46 template< class T, class A > \
47 struct resize_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
49 static void resize( THRUST_VECTOR<T,A> &x , \
50 const THRUST_VECTOR<T,A> &y ) \
52 x.resize( y.size() ); \
55 template< class T, class A, typename Range > \
56 struct resize_impl< THRUST_VECTOR<T,A> , Range > \
58 static void resize( THRUST_VECTOR<T,A> &x , \
61 x.resize( thrust::distance(boost::begin(y), \
67 #define ODEINT_THRUST_SAME_SIZE_IMPL( THRUST_VECTOR ) \
68 template< class T , class A > \
69 struct same_size_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
71 static bool same_size( const THRUST_VECTOR<T,A> &x , \
72 const THRUST_VECTOR<T,A> &y ) \
74 return x.size() == y.size(); \
77 template< class T , class A, typename Range > \
78 struct same_size_impl< THRUST_VECTOR<T,A> , Range > \
80 static bool same_size( const THRUST_VECTOR<T,A> &x , \
83 return x.size() == thrust::distance(boost::begin(y), \
89 #define ODEINT_THRUST_COPY_IMPL( THRUST_VECTOR ) \
90 template< class Container1 , class T , class A > \
91 struct copy_impl< Container1 , THRUST_VECTOR<T,A> > \
93 static void copy( const Container1 &from , THRUST_VECTOR<T,A> &to ) \
95 thrust::copy( boost::begin( from ) , boost::end( from ) , \
96 boost::begin( to ) ); \
100 template< class T , class A , class Container2 > \
101 struct copy_impl< THRUST_VECTOR<T,A> , Container2 > \
103 static void copy( const THRUST_VECTOR<T,A> &from , Container2 &to ) \
105 thrust::copy( boost::begin( from ) , boost::end( from ) , \
106 boost::begin( to ) ); \
110 template< class T , class A > \
111 struct copy_impl< THRUST_VECTOR<T,A> , THRUST_VECTOR<T,A> > \
113 static void copy( const THRUST_VECTOR<T,A> &from , \
114 THRUST_VECTOR<T,A> &to ) \
116 thrust::copy( boost::begin( from ) , boost::end( from ) , \
117 boost::begin( to ) ); \
121 // add support for the standard thrust containers
123 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::device_vector )
124 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::device_vector )
125 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::device_vector )
126 ODEINT_THRUST_COPY_IMPL( thrust::device_vector )
129 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::host_vector )
130 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::host_vector )
131 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::host_vector )
132 ODEINT_THRUST_COPY_IMPL( thrust::host_vector )
139 // add support for thrust backend vectors, if available
141 #include <thrust/version.h>
143 #if THRUST_VERSION >= 100600
145 #include <thrust/system/cpp/vector.h>
146 namespace boost { namespace numeric { namespace odeint {
147 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cpp::vector )
148 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cpp::vector )
149 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cpp::vector )
150 ODEINT_THRUST_COPY_IMPL( thrust::cpp::vector )
154 #include <thrust/system/omp/vector.h>
155 namespace boost { namespace numeric { namespace odeint {
156 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::omp::vector )
157 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::omp::vector )
158 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::omp::vector )
159 ODEINT_THRUST_COPY_IMPL( thrust::omp::vector )
163 #ifdef TBB_VERSION_MAJOR
164 #include <thrust/system/tbb/vector.h>
165 namespace boost { namespace numeric { namespace odeint {
166 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::tbb::vector )
167 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::tbb::vector )
168 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::tbb::vector )
169 ODEINT_THRUST_COPY_IMPL( thrust::tbb::vector )
171 #endif // TBB_VERSION_MAJOR
174 #include <thrust/system/cuda/vector.h>
175 namespace boost { namespace numeric { namespace odeint {
176 ODEINT_THRUST_VECTOR_IS_RESIZEABLE( thrust::cuda::vector )
177 ODEINT_TRHUST_VECTOR_RESIZE_IMPL( thrust::cuda::vector )
178 ODEINT_THRUST_SAME_SIZE_IMPL( thrust::cuda::vector )
179 ODEINT_THRUST_COPY_IMPL( thrust::cuda::vector )
183 #endif // THRUST_VERSION >= 100600
185 #endif // BOOST_NUMERIC_ODEINT_EXTERNAL_THRUST_THRUST_RESIZE_HPP_INCLUDED