thrust
device_ptr.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008-2013 NVIDIA Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 
22 #pragma once
23 
24 #include <thrust/detail/config.h>
25 #include <thrust/memory.h>
26 
27 namespace thrust
28 {
29 
36 // forward declarations
37 template<typename T> class device_reference;
38 
60 template<typename T>
61  class device_ptr
62  : public thrust::pointer<
63  T,
64  thrust::device_system_tag,
65  thrust::device_reference<T>,
66  thrust::device_ptr<T>
67  >
68 {
69  private:
70  typedef thrust::pointer<
71  T,
72  thrust::device_system_tag,
75  > super_t;
76 
77  public:
80  __host__ __device__
81  device_ptr() : super_t() {}
82 
83  #if THRUST_CPP_DIALECT >= 2011
84  // NOTE: This is needed so that Thrust smart pointers can be used in
85  // `std::unique_ptr`.
86  __host__ __device__
87  device_ptr(decltype(nullptr)) : super_t(nullptr) {}
88  #endif
89 
96  template<typename OtherT>
97  __host__ __device__
98  explicit device_ptr(OtherT *ptr) : super_t(ptr) {}
99 
103  template<typename OtherT>
104  __host__ __device__
105  device_ptr(const device_ptr<OtherT> &other) : super_t(other) {}
106 
111  template<typename OtherT>
112  __host__ __device__
113  device_ptr &operator=(const device_ptr<OtherT> &other)
114  {
115  super_t::operator=(other);
116  return *this;
117  }
118 
119  #if THRUST_CPP_DIALECT >= 2011
120  // NOTE: This is needed so that Thrust smart pointers can be used in
121  // `std::unique_ptr`.
122  __host__ __device__
123  device_ptr& operator=(decltype(nullptr))
124  {
125  super_t::operator=(nullptr);
126  return *this;
127  }
128  #endif
129 
130 // declare these members for the purpose of Doxygenating them
131 // they actually exist in a derived-from class
132 #if 0
133 
136  __host__ __device__
137  T *get(void) const;
138 #endif // end doxygen-only members
139 }; // end device_ptr
140 
141 // declare these methods for the purpose of Doxygenating them
142 // they actually are defined for a derived-from class
143 #if 0
144 
150 template<typename T, typename charT, typename traits>
151 std::basic_ostream<charT, traits> &
152 operator<<(std::basic_ostream<charT, traits> &os, const device_ptr<T> &p);
153 #endif
154 
171 template<typename T>
172 __host__ __device__
173 inline device_ptr<T> device_pointer_cast(T *ptr);
174 
181 template<typename T>
182 __host__ __device__
184 
188 } // end thrust
189 
190 #include <thrust/detail/device_ptr.inl>
191 #include <thrust/detail/raw_pointer_cast.h>
192 
Abstractions for Thrust&#39;s memory model.
__host__ __device__ device_ptr(OtherT *ptr)
Definition: device_ptr.h:98
__host__ __device__ device_ptr< T > device_pointer_cast(T *ptr)
thrust is the top-level namespace which contains all Thrust functions and types.
Definition: addressof.h:14
__host__ __device__ device_ptr & operator=(const device_ptr< OtherT > &other)
Definition: device_ptr.h:113
Definition: device_malloc_allocator.h:36
Definition: device_ptr.h:37
__host__ __device__ device_ptr(const device_ptr< OtherT > &other)
Definition: device_ptr.h:105
__host__ __device__ device_ptr()
Definition: device_ptr.h:81