2
* Copyright 2008-2012 NVIDIA Corporation
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
8
* http://www.apache.org/licenses/LICENSE-2.0
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.
19
#include <thrust/detail/config.h>
20
#include <thrust/detail/execution_policy.h>
21
#include <thrust/pair.h>
22
#include <thrust/detail/pointer.h>
23
#include <thrust/detail/raw_pointer_cast.h>
24
#include <thrust/system/detail/generic/temporary_buffer.h>
25
#include <thrust/system/detail/adl/temporary_buffer.h>
31
namespace get_temporary_buffer_detail
35
template<typename T, typename DerivedPolicy, typename Pair>
36
thrust::pair<thrust::pointer<T,DerivedPolicy>, typename thrust::pointer<T,DerivedPolicy>::difference_type>
37
down_cast_pair(Pair p)
39
// XXX should use a hypothetical thrust::static_pointer_cast here
40
thrust::pointer<T,DerivedPolicy> ptr = thrust::pointer<T,DerivedPolicy>(static_cast<T*>(thrust::raw_pointer_cast(p.first)));
42
typedef thrust::pair<thrust::pointer<T,DerivedPolicy>, typename thrust::pointer<T,DerivedPolicy>::difference_type> result_type;
43
return result_type(ptr, p.second);
44
} // end down_cast_pair()
47
} // end get_temporary_buffer_detail
51
template<typename T, typename DerivedPolicy>
52
thrust::pair<thrust::pointer<T,DerivedPolicy>, typename thrust::pointer<T,DerivedPolicy>::difference_type>
53
get_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, typename thrust::pointer<T,DerivedPolicy>::difference_type n)
55
using thrust::system::detail::generic::get_temporary_buffer;
57
return thrust::detail::get_temporary_buffer_detail::down_cast_pair<T,DerivedPolicy>(get_temporary_buffer<T>(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), n));
58
} // end get_temporary_buffer()
61
template<typename DerivedPolicy, typename Pointer>
62
void return_temporary_buffer(const thrust::detail::execution_policy_base<DerivedPolicy> &exec, Pointer p)
64
using thrust::system::detail::generic::return_temporary_buffer;
66
return return_temporary_buffer(thrust::detail::derived_cast(thrust::detail::strip_const(exec)), p);
67
} // end return_temporary_buffer()