~ubuntu-branches/ubuntu/utopic/libthrust/utopic

« back to all changes in this revision

Viewing changes to system/cuda/detail/block/exclusive_scan.h

  • Committer: Package Import Robot
  • Author(s): Andreas Beckmann
  • Date: 2013-07-10 12:57:33 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20130710125733-my19jic71sqsabaj
Tags: 1.7.0-1
* New upstream release.  (Closes: #715362)
* Update watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright 2008-2012 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
#pragma once
 
18
 
 
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>
 
23
 
 
24
namespace thrust
 
25
{
 
26
namespace system
 
27
{
 
28
namespace cuda
 
29
{
 
30
namespace detail
 
31
{
 
32
namespace block
 
33
{
 
34
 
 
35
 
 
36
template<typename Context, typename RandomAccessIterator, typename T, typename BinaryFunction>
 
37
inline __device__
 
38
typename thrust::iterator_value<RandomAccessIterator>::type
 
39
  inplace_exclusive_scan(Context &ctx, RandomAccessIterator first, T init, BinaryFunction op)
 
40
{
 
41
  // perform an inclusive scan, then shift right
 
42
  block::inplace_inclusive_scan(ctx, first, op);
 
43
 
 
44
  typename thrust::iterator_value<RandomAccessIterator>::type carry = first[ctx.block_dimension() - 1];
 
45
 
 
46
  ctx.barrier();
 
47
 
 
48
  typename thrust::iterator_value<RandomAccessIterator>::type left = (ctx.thread_index() == 0) ? init : first[ctx.thread_index() - 1];
 
49
 
 
50
  ctx.barrier();
 
51
 
 
52
  first[ctx.thread_index()] = left;
 
53
 
 
54
  ctx.barrier();
 
55
 
 
56
  return carry;
 
57
}
 
58
 
 
59
 
 
60
template<typename Context, typename Iterator, typename T>
 
61
inline __device__
 
62
  typename thrust::iterator_value<Iterator>::type
 
63
    inplace_exclusive_scan(Context &ctx, Iterator first, T init)
 
64
{
 
65
  return block::inplace_exclusive_scan(ctx, first, init, thrust::plus<typename thrust::iterator_value<Iterator>::type>());
 
66
}
 
67
 
 
68
 
 
69
} // end namespace block
 
70
} // end namespace detail
 
71
} // end namespace cuda
 
72
} // end namespace system
 
73
} // end namespace thrust
 
74