OSDN Git Service

CUDA
[eos/hostdependX86LINUX64.git] / util / X86LINUX64 / cuda-6.5 / include / thrust / system / cuda / detail / memory.inl
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 #include <thrust/detail/config.h>
18 #include <thrust/system/cuda/memory.h>
19 #include <thrust/system/cuda/detail/malloc_and_free.h>
20 #include <limits>
21
22 namespace thrust
23 {
24
25 // XXX WAR an issue with MSVC 2005 (cl v14.00) incorrectly implementing
26 //     pointer_raw_pointer for pointer by specializing it here
27 //     note that we specialize it here, before the use of raw_pointer_cast
28 //     below, which causes pointer_raw_pointer's instantiation
29 #if (THRUST_HOST_COMPILER == THRUST_HOST_COMPILER_MSVC) && (_MSC_VER <= 1400)
30 namespace detail
31 {
32
33 template<typename T>
34   struct pointer_raw_pointer< thrust::cuda::pointer<T> >
35 {
36   typedef typename thrust::cuda::pointer<T>::raw_pointer type;
37 }; // end pointer_raw_pointer
38
39 } // end detail
40 #endif
41
42 namespace system
43 {
44 namespace cuda
45 {
46
47
48 template<typename T>
49   template<typename OtherT>
50     reference<T> &
51       reference<T>
52         ::operator=(const reference<OtherT> &other)
53 {
54   return super_t::operator=(other);
55 } // end reference::operator=()
56
57 template<typename T>
58   reference<T> &
59     reference<T>
60       ::operator=(const value_type &x)
61 {
62   return super_t::operator=(x);
63 } // end reference::operator=()
64
65 template<typename T>
66 __host__ __device__
67 void swap(reference<T> a, reference<T> b)
68 {
69   a.swap(b);
70 } // end swap()
71
72 pointer<void> malloc(std::size_t n)
73 {
74   tag cuda_tag;
75   return pointer<void>(thrust::system::cuda::detail::malloc(cuda_tag, n));
76 } // end malloc()
77
78 template<typename T>
79 pointer<T> malloc(std::size_t n)
80 {
81   pointer<void> raw_ptr = thrust::system::cuda::malloc(sizeof(T) * n);
82   return pointer<T>(reinterpret_cast<T*>(raw_ptr.get()));
83 } // end malloc()
84
85 void free(pointer<void> ptr)
86 {
87   tag cuda_tag;
88   return thrust::system::cuda::detail::free(cuda_tag, ptr.get());
89 } // end free()
90
91 } // end cuda
92 } // end system
93 } // end thrust
94