Skip to content

Commit 1bf4b53

Browse files
authored
Merge pull request boostorg#763 from lakshayg/static_assert
add static asserts for device iterators
2 parents e4ccfe3 + d833b22 commit 1bf4b53

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+412
-4
lines changed

include/boost/compute/algorithm/accumulate.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_ACCUMULATE_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_ACCUMULATE_HPP
1313

14+
#include <boost/static_assert.hpp>
1415
#include <boost/preprocessor/seq/for_each.hpp>
1516

1617
#include <boost/compute/system.hpp>
@@ -20,6 +21,7 @@
2021
#include <boost/compute/algorithm/detail/serial_accumulate.hpp>
2122
#include <boost/compute/container/array.hpp>
2223
#include <boost/compute/container/vector.hpp>
24+
#include <boost/compute/type_traits/is_device_iterator.hpp>
2325
#include <boost/compute/detail/iterator_range_size.hpp>
2426

2527
namespace boost {
@@ -167,6 +169,8 @@ inline T accumulate(InputIterator first,
167169
BinaryFunction function,
168170
command_queue &queue = system::default_queue())
169171
{
172+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
173+
170174
return detail::dispatch_accumulate(first, last, init, function, queue);
171175
}
172176

@@ -177,6 +181,7 @@ inline T accumulate(InputIterator first,
177181
T init,
178182
command_queue &queue = system::default_queue())
179183
{
184+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
180185
typedef typename std::iterator_traits<InputIterator>::value_type IT;
181186

182187
return detail::dispatch_accumulate(first, last, init, plus<IT>(), queue);

include/boost/compute/algorithm/adjacent_difference.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313

1414
#include <iterator>
1515

16+
#include <boost/static_assert.hpp>
17+
1618
#include <boost/compute/system.hpp>
1719
#include <boost/compute/command_queue.hpp>
1820
#include <boost/compute/detail/meta_kernel.hpp>
1921
#include <boost/compute/detail/iterator_range_size.hpp>
2022
#include <boost/compute/functional/operator.hpp>
2123
#include <boost/compute/container/vector.hpp>
24+
#include <boost/compute/type_traits/is_device_iterator.hpp>
2225

2326
namespace boost {
2427
namespace compute {
@@ -76,6 +79,8 @@ adjacent_difference(InputIterator first,
7679
BinaryFunction op,
7780
command_queue &queue = system::default_queue())
7881
{
82+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
83+
BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
7984
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
8085

8186
if(first == last) {
@@ -106,6 +111,8 @@ adjacent_difference(InputIterator first,
106111
OutputIterator result,
107112
command_queue &queue = system::default_queue())
108113
{
114+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
115+
BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
109116
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
110117

111118
return ::boost::compute::adjacent_difference(

include/boost/compute/algorithm/adjacent_find.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
#include <iterator>
1515

16+
#include <boost/static_assert.hpp>
17+
1618
#include <boost/compute/command_queue.hpp>
1719
#include <boost/compute/lambda.hpp>
1820
#include <boost/compute/system.hpp>
@@ -21,6 +23,7 @@
2123
#include <boost/compute/detail/meta_kernel.hpp>
2224
#include <boost/compute/functional/operator.hpp>
2325
#include <boost/compute/type_traits/vector_size.hpp>
26+
#include <boost/compute/type_traits/is_device_iterator.hpp>
2427

2528
namespace boost {
2629
namespace compute {
@@ -124,6 +127,7 @@ adjacent_find(InputIterator first,
124127
Compare compare,
125128
command_queue &queue = system::default_queue())
126129
{
130+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
127131
size_t count = detail::iterator_range_size(first, last);
128132
if(count < 32){
129133
return detail::serial_adjacent_find(first, last, compare, queue);
@@ -140,6 +144,7 @@ adjacent_find(InputIterator first,
140144
InputIterator last,
141145
command_queue &queue = system::default_queue())
142146
{
147+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
143148
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
144149

145150
using ::boost::compute::lambda::_1;

include/boost/compute/algorithm/all_of.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_ALL_OF_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/system.hpp>
1517
#include <boost/compute/algorithm/find_if_not.hpp>
18+
#include <boost/compute/type_traits/is_device_iterator.hpp>
1619

1720
namespace boost {
1821
namespace compute {
@@ -29,6 +32,7 @@ inline bool all_of(InputIterator first,
2932
UnaryPredicate predicate,
3033
command_queue &queue = system::default_queue())
3134
{
35+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
3236
return ::boost::compute::find_if_not(first, last, predicate, queue) == last;
3337
}
3438

include/boost/compute/algorithm/any_of.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_ANY_OF_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_ANY_OF_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/system.hpp>
1517
#include <boost/compute/algorithm/find_if.hpp>
18+
#include <boost/compute/type_traits/is_device_iterator.hpp>
1619

1720
namespace boost {
1821
namespace compute {
@@ -33,6 +36,7 @@ inline bool any_of(InputIterator first,
3336
UnaryPredicate predicate,
3437
command_queue &queue = system::default_queue())
3538
{
39+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
3640
return ::boost::compute::find_if(first, last, predicate, queue) != last;
3741
}
3842

include/boost/compute/algorithm/binary_search.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_BINARY_SEARCH_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_BINARY_SEARCH_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/system.hpp>
1517
#include <boost/compute/command_queue.hpp>
1618
#include <boost/compute/algorithm/lower_bound.hpp>
19+
#include <boost/compute/type_traits/is_device_iterator.hpp>
1720

1821
namespace boost {
1922
namespace compute {
@@ -28,6 +31,7 @@ inline bool binary_search(InputIterator first,
2831
const T &value,
2932
command_queue &queue = system::default_queue())
3033
{
34+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
3135
InputIterator position = lower_bound(first, last, value, queue);
3236

3337
return position != last && position.read(queue) == value;

include/boost/compute/algorithm/copy_if.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_COPY_IF_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/algorithm/transform_if.hpp>
1517
#include <boost/compute/functional/identity.hpp>
18+
#include <boost/compute/type_traits/is_device_iterator.hpp>
1619

1720
namespace boost {
1821
namespace compute {
@@ -27,6 +30,8 @@ inline OutputIterator copy_index_if(InputIterator first,
2730
Predicate predicate,
2831
command_queue &queue = system::default_queue())
2932
{
33+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
34+
BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
3035
typedef typename std::iterator_traits<InputIterator>::value_type T;
3136

3237
return detail::transform_if_impl(
@@ -47,6 +52,8 @@ inline OutputIterator copy_if(InputIterator first,
4752
Predicate predicate,
4853
command_queue &queue = system::default_queue())
4954
{
55+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
56+
BOOST_STATIC_ASSERT(is_device_iterator<OutputIterator>::value);
5057
typedef typename std::iterator_traits<InputIterator>::value_type T;
5158

5259
return ::boost::compute::transform_if(

include/boost/compute/algorithm/count.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_COUNT_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_COUNT_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/lambda.hpp>
1517
#include <boost/compute/system.hpp>
1618
#include <boost/compute/command_queue.hpp>
1719
#include <boost/compute/algorithm/count_if.hpp>
1820
#include <boost/compute/type_traits/vector_size.hpp>
21+
#include <boost/compute/type_traits/is_device_iterator.hpp>
1922

2023
namespace boost {
2124
namespace compute {
@@ -33,6 +36,7 @@ inline size_t count(InputIterator first,
3336
const T &value,
3437
command_queue &queue = system::default_queue())
3538
{
39+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
3640
typedef typename std::iterator_traits<InputIterator>::value_type value_type;
3741

3842
using ::boost::compute::_1;

include/boost/compute/algorithm/count_if.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_COUNT_IF_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/device.hpp>
1517
#include <boost/compute/system.hpp>
1618
#include <boost/compute/command_queue.hpp>
@@ -19,6 +21,7 @@
1921
#include <boost/compute/algorithm/detail/count_if_with_threads.hpp>
2022
#include <boost/compute/algorithm/detail/serial_count_if.hpp>
2123
#include <boost/compute/detail/iterator_range_size.hpp>
24+
#include <boost/compute/type_traits/is_device_iterator.hpp>
2225

2326
namespace boost {
2427
namespace compute {
@@ -34,6 +37,7 @@ inline size_t count_if(InputIterator first,
3437
Predicate predicate,
3538
command_queue &queue = system::default_queue())
3639
{
40+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator>::value);
3741
const device &device = queue.get_device();
3842

3943
size_t input_size = detail::iterator_range_size(first, last);

include/boost/compute/algorithm/equal.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,12 @@
1111
#ifndef BOOST_COMPUTE_ALGORITHM_EQUAL_HPP
1212
#define BOOST_COMPUTE_ALGORITHM_EQUAL_HPP
1313

14+
#include <boost/static_assert.hpp>
15+
1416
#include <boost/compute/system.hpp>
1517
#include <boost/compute/command_queue.hpp>
1618
#include <boost/compute/algorithm/mismatch.hpp>
19+
#include <boost/compute/type_traits/is_device_iterator.hpp>
1720

1821
namespace boost {
1922
namespace compute {
@@ -28,6 +31,8 @@ inline bool equal(InputIterator1 first1,
2831
InputIterator2 first2,
2932
command_queue &queue = system::default_queue())
3033
{
34+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
35+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
3136
return ::boost::compute::mismatch(first1,
3237
last1,
3338
first2,
@@ -42,6 +47,8 @@ inline bool equal(InputIterator1 first1,
4247
InputIterator2 last2,
4348
command_queue &queue = system::default_queue())
4449
{
50+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator1>::value);
51+
BOOST_STATIC_ASSERT(is_device_iterator<InputIterator2>::value);
4552
if(std::distance(first1, last1) != std::distance(first2, last2)){
4653
return false;
4754
}

0 commit comments

Comments
 (0)