Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:29:56

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP
0012 #define BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP
0013 
0014 #include <boost/static_assert.hpp>
0015 
0016 #include <boost/compute/functional.hpp>
0017 #include <boost/compute/system.hpp>
0018 #include <boost/compute/command_queue.hpp>
0019 #include <boost/compute/algorithm/detail/scan.hpp>
0020 #include <boost/compute/type_traits/is_device_iterator.hpp>
0021 
0022 namespace boost {
0023 namespace compute {
0024 
0025 /// Performs an exclusive scan of the elements in the range [\p first, \p last)
0026 /// and stores the results in the range beginning at \p result.
0027 ///
0028 /// Each element in the output is assigned to the sum of all the previous
0029 /// values in the input.
0030 ///
0031 /// \param first first element in the range to scan
0032 /// \param last last element in the range to scan
0033 /// \param result first element in the result range
0034 /// \param init value used to initialize the scan sequence
0035 /// \param binary_op associative binary operator
0036 /// \param queue command queue to perform the operation
0037 ///
0038 /// \return \c OutputIterator to the end of the result range
0039 ///
0040 /// The default operation is to add the elements up.
0041 ///
0042 /// \snippet test/test_scan.cpp exclusive_scan_int
0043 ///
0044 /// But different associative operation can be specified as \p binary_op
0045 /// instead (e.g., multiplication, maximum, minimum). Also value used to
0046 /// initialized the scan sequence can be specified.
0047 ///
0048 /// \snippet test/test_scan.cpp exclusive_scan_int_multiplies
0049 ///
0050 /// Space complexity on GPUs: \Omega(n)<br>
0051 /// Space complexity on GPUs when \p first == \p result: \Omega(2n)<br>
0052 /// Space complexity on CPUs: \Omega(1)
0053 ///
0054 /// \see inclusive_scan()
0055 template<class InputIterator, class OutputIterator, class T, class BinaryOperator>
0056 inline OutputIterator
0057 exclusive_scan(InputIterator first,
0058                InputIterator last,
0059                OutputIterator result,
0060                T init,
0061                BinaryOperator binary_op,
0062                command_queue &queue = system::default_queue())
0063 {
0064     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0065     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0066     return detail::scan(first, last, result, true, init, binary_op, queue);
0067 }
0068 
0069 /// \overload
0070 template<class InputIterator, class OutputIterator, class T>
0071 inline OutputIterator
0072 exclusive_scan(InputIterator first,
0073                InputIterator last,
0074                OutputIterator result,
0075                T init,
0076                command_queue &queue = system::default_queue())
0077 {
0078     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0079     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0080     typedef typename
0081         std::iterator_traits<OutputIterator>::value_type output_type;
0082 
0083     return detail::scan(first, last, result, true,
0084                         init, boost::compute::plus<output_type>(),
0085                         queue);
0086 }
0087 
0088 /// \overload
0089 template<class InputIterator, class OutputIterator>
0090 inline OutputIterator
0091 exclusive_scan(InputIterator first,
0092                InputIterator last,
0093                OutputIterator result,
0094                command_queue &queue = system::default_queue())
0095 {
0096     BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
0097     BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
0098     typedef typename
0099         std::iterator_traits<OutputIterator>::value_type output_type;
0100 
0101     return detail::scan(first, last, result, true,
0102                         output_type(0), boost::compute::plus<output_type>(),
0103                         queue);
0104 }
0105 
0106 } // end compute namespace
0107 } // end boost namespace
0108 
0109 #endif // BOOST_COMPUTE_ALGORITHM_EXCLUSIVE_SCAN_HPP