NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
thrust_view.h
Go to the documentation of this file.
1 /*
2  * nvbio
3  * Copyright (c) 2011-2014, 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 <nvbio/basic/types.h>
36 #include <thrust/host_vector.h>
37 #include <thrust/device_vector.h>
38 
39 namespace nvbio {
40 
41 template <typename T> struct device_view_subtype< thrust::device_vector<T> > { typedef vector_view<T*,uint64> type; };
42 template <typename T> struct plain_view_subtype< thrust::host_vector<T> > { typedef vector_view<T*,uint64> type; };
43 template <typename T> struct plain_view_subtype< thrust::device_vector<T> > { typedef vector_view<T*,uint64> type; };
44 template <typename T> struct plain_view_subtype< const thrust::host_vector<T> > { typedef vector_view<const T*,uint64> type; };
45 template <typename T> struct plain_view_subtype< const thrust::device_vector<T> > { typedef vector_view<const T*,uint64> type; };
46 
49 template <typename T>
50 vector_view<T*,uint64> device_view(thrust::device_vector<T>& vec) { return vector_view<T*,uint64>( vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL ); }
51 
54 template <typename T>
55 vector_view<const T*,uint64> device_view(const thrust::device_vector<T>& vec) { return vector_view<const T*,uint64>( vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL ); }
56 
59 template <typename T>
60 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 ); }
61 
64 template <typename T>
65 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 ); }
66 
69 template <typename T>
70 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 ); }
71 
74 template <typename T>
75 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 ); }
76 
79 template <typename T>
80 T* raw_pointer(thrust::device_vector<T>& vec) { return vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
81 
84 template <typename T>
85 const T* raw_pointer(const thrust::device_vector<T>& vec) { return vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
86 
89 template <typename T>
90 T* raw_pointer(thrust::host_vector<T>& vec) { return vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
91 
94 template <typename T>
95 const T* raw_pointer(const thrust::host_vector<T>& vec) { return vec.size(), vec.size() ? thrust::raw_pointer_cast( &vec.front() ) : NULL; }
96 
99 template <typename T>
100 typename thrust::device_vector<T>::iterator begin(thrust::device_vector<T>& vec) { return vec.begin; }
101 
104 template <typename T>
105 typename thrust::device_vector<T>::const_iterator begin(const thrust::device_vector<T>& vec) { return vec.begin; }
106 
109 template <typename T>
110 typename thrust::host_vector<T>::iterator begin(thrust::host_vector<T>& vec) { return vec.begin; }
111 
114 template <typename T>
115 typename thrust::host_vector<T>::const_iterator begin(const thrust::host_vector<T>& vec) { return vec.begin; }
116 
117 } // namespace nvbio