Fermat
thrust_view.h
1 /*
2  * cugar
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of the NVIDIA CORPORATION nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
32 #pragma once
33 
34 #include <cugar/basic/types.h>
35 #include <cugar/basic/vector_view.h>
36 #include <thrust/host_vector.h>
37 #include <thrust/device_vector.h>
38 
39 namespace cugar {
40 
41 template <typename T> struct plain_view_subtype< thrust::host_vector<T> > { typedef vector_view<T*,uint64> type; };
42 template <typename T> struct plain_view_subtype< thrust::device_vector<T> > { typedef vector_view<T*,uint64> type; };
43 template <typename T> struct plain_view_subtype< const thrust::host_vector<T> > { typedef vector_view<const T*,uint64> type; };
44 template <typename T> struct plain_view_subtype< const thrust::device_vector<T> > { typedef vector_view<const T*,uint64> type; };
45 
48 template <typename T>
49 vector_view<T*,uint64> plain_view(thrust::device_vector<T>& vec) { return vector_view<T*,uint64>( vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL ); }
50 
53 template <typename T>
54 vector_view<const T*,uint64> plain_view(const thrust::device_vector<T>& vec) { return vector_view<const T*,uint64>( vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL ); }
55 
58 template <typename T>
59 vector_view<T*,uint64> plain_view(thrust::host_vector<T>& vec) { return vector_view<T*,uint64>( vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL ); }
60 
63 template <typename T>
64 vector_view<const T*,uint64> plain_view(const thrust::host_vector<T>& vec) { return vector_view<const T*,uint64>( vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL ); }
65 
68 template <typename T, typename Alloc>
69 T* raw_pointer(thrust::device_vector<T,Alloc>& vec) { return vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
70 
73 template <typename T, typename Alloc>
74 const T* raw_pointer(const thrust::device_vector<T,Alloc>& vec) { return vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
75 
78 template <typename T>
79 T* raw_pointer(thrust::host_vector<T>& vec) { return vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
80 
83 template <typename T>
84 const T* raw_pointer(const thrust::host_vector<T>& vec) { return vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
85 
88 template <typename T>
89 typename thrust::device_vector<T>::iterator begin(thrust::device_vector<T>& vec) { return vec.begin; }
90 
93 template <typename T>
94 typename thrust::device_vector<T>::const_iterator begin(const thrust::device_vector<T>& vec) { return vec.begin; }
95 
98 template <typename T>
99 typename thrust::host_vector<T>::iterator begin(thrust::host_vector<T>& vec) { return vec.begin; }
100 
103 template <typename T>
104 typename thrust::host_vector<T>::const_iterator begin(const thrust::host_vector<T>& vec) { return vec.begin; }
105 
106 } // namespace cugar
thrust::device_vector< T >::iterator begin(thrust::device_vector< T > &vec)
Definition: thrust_view.h:89
Definition: vector_view.h:87
Definition: vector.h:264
vector_view< T *, uint64 > plain_view(thrust::device_vector< T > &vec)
Definition: thrust_view.h:49
T * raw_pointer(thrust::device_vector< T, Alloc > &vec)
Definition: thrust_view.h:69
Definition: types.h:221
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: vector.h:224