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/iterator/iterator_traits.h>
21
#include <thrust/functional.h>
22
#include <thrust/system/cuda/detail/block/inclusive_scan.h>
36
template<typename Context, typename RandomAccessIterator, typename T, typename BinaryFunction>
38
typename thrust::iterator_value<RandomAccessIterator>::type
39
inplace_exclusive_scan(Context &ctx, RandomAccessIterator first, T init, BinaryFunction op)
41
// perform an inclusive scan, then shift right
42
block::inplace_inclusive_scan(ctx, first, op);
44
typename thrust::iterator_value<RandomAccessIterator>::type carry = first[ctx.block_dimension() - 1];
48
typename thrust::iterator_value<RandomAccessIterator>::type left = (ctx.thread_index() == 0) ? init : first[ctx.thread_index() - 1];
52
first[ctx.thread_index()] = left;
60
template<typename Context, typename Iterator, typename T>
62
typename thrust::iterator_value<Iterator>::type
63
inplace_exclusive_scan(Context &ctx, Iterator first, T init)
65
return block::inplace_exclusive_scan(ctx, first, init, thrust::plus<typename thrust::iterator_value<Iterator>::type>());
69
} // end namespace block
70
} // end namespace detail
71
} // end namespace cuda
72
} // end namespace system
73
} // end namespace thrust