From cfdb10c8080f8cd7bc2b1be8b760821bcf2d67ef Mon Sep 17 00:00:00 2001 From: Kyle Lutz Date: Mon, 29 Dec 2014 17:22:25 -0800 Subject: [PATCH] Move is_device_iterator to the public API --- doc/reference.qbk | 1 + include/boost/compute/algorithm/copy.hpp | 12 +++--- .../algorithm/detail/copy_on_device.hpp | 1 + include/boost/compute/algorithm/sort.hpp | 1 + include/boost/compute/detail/device_ptr.hpp | 21 ++++------ .../compute/detail/is_device_iterator.hpp | 29 -------------- .../boost/compute/detail/iterator_traits.hpp | 2 +- .../compute/iterator/buffer_iterator.hpp | 19 +++------ .../iterator/constant_buffer_iterator.hpp | 18 +++------ .../compute/iterator/constant_iterator.hpp | 20 ++-------- .../compute/iterator/counting_iterator.hpp | 20 ++-------- .../iterator/detail/pixel_input_iterator.hpp | 19 +++------ .../iterator/detail/swizzle_iterator.hpp | 22 +++-------- .../compute/iterator/discard_iterator.hpp | 9 ++--- .../iterator/function_input_iterator.hpp | 20 ++-------- .../compute/iterator/permutation_iterator.hpp | 20 ++-------- .../compute/iterator/transform_iterator.hpp | 22 +++-------- .../boost/compute/iterator/zip_iterator.hpp | 22 ++++------- include/boost/compute/memory/svm_ptr.hpp | 19 ++------- include/boost/compute/type_traits.hpp | 1 + .../type_traits/is_device_iterator.hpp | 39 +++++++++++++++++++ test/test_buffer_iterator.cpp | 2 +- test/test_permutation_iterator.cpp | 13 +++++++ test/test_transform_iterator.cpp | 12 ++++++ test/test_type_traits.cpp | 9 +++-- 25 files changed, 146 insertions(+), 227 deletions(-) delete mode 100644 include/boost/compute/detail/is_device_iterator.hpp create mode 100644 include/boost/compute/type_traits/is_device_iterator.hpp diff --git a/doc/reference.qbk b/doc/reference.qbk index 6afee1e2..4f573d38 100644 --- a/doc/reference.qbk +++ b/doc/reference.qbk @@ -194,6 +194,7 @@ Header: `` Header: `` +* [classref boost::compute::is_device_iterator is_device_iterator] * [classref boost::compute::is_fundamental is_fundamental] * [classref boost::compute::is_vector_type is_vector_type] * [classref boost::compute::make_vector_type make_vector_type] diff --git a/include/boost/compute/algorithm/copy.hpp b/include/boost/compute/algorithm/copy.hpp index 54b326cd..8db0151e 100644 --- a/include/boost/compute/algorithm/copy.hpp +++ b/include/boost/compute/algorithm/copy.hpp @@ -22,14 +22,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include namespace boost { namespace compute { diff --git a/include/boost/compute/algorithm/detail/copy_on_device.hpp b/include/boost/compute/algorithm/detail/copy_on_device.hpp index 6971d818..c746a2e8 100644 --- a/include/boost/compute/algorithm/detail/copy_on_device.hpp +++ b/include/boost/compute/algorithm/detail/copy_on_device.hpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include diff --git a/include/boost/compute/algorithm/sort.hpp b/include/boost/compute/algorithm/sort.hpp index 9f2c3794..bb6ae3db 100644 --- a/include/boost/compute/algorithm/sort.hpp +++ b/include/boost/compute/algorithm/sort.hpp @@ -23,6 +23,7 @@ #include #include #include +#include namespace boost { namespace compute { diff --git a/include/boost/compute/detail/device_ptr.hpp b/include/boost/compute/detail/device_ptr.hpp index e8636bd4..cf8340a8 100644 --- a/include/boost/compute/detail/device_ptr.hpp +++ b/include/boost/compute/detail/device_ptr.hpp @@ -17,8 +17,8 @@ #include #include #include -#include #include +#include namespace boost { namespace compute { @@ -191,7 +191,7 @@ private: size_t m_index; }; -// is_buffer_iterator specialization for buffer_iterator +// is_buffer_iterator specialization for device_ptr template struct is_buffer_iterator< Iterator, @@ -203,19 +203,12 @@ struct is_buffer_iterator< >::type > : public boost::true_type {}; -// is_device_iterator specialization for buffer_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - device_ptr, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - } // end detail namespace + +// is_device_iterator specialization for device_ptr +template +struct is_device_iterator > : boost::true_type {}; + } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/detail/is_device_iterator.hpp b/include/boost/compute/detail/is_device_iterator.hpp deleted file mode 100644 index 204bc4ff..00000000 --- a/include/boost/compute/detail/is_device_iterator.hpp +++ /dev/null @@ -1,29 +0,0 @@ -//---------------------------------------------------------------------------// -// Copyright (c) 2013 Kyle Lutz -// -// Distributed under the Boost Software License, Version 1.0 -// See accompanying file LICENSE_1_0.txt or copy at -// http://www.boost.org/LICENSE_1_0.txt -// -// See http://kylelutz.github.com/compute for more information. -//---------------------------------------------------------------------------// - -#ifndef BOOST_COMPUTE_DETAIL_IS_DEVICE_ITERATOR_HPP -#define BOOST_COMPUTE_DETAIL_IS_DEVICE_ITERATOR_HPP - -#include -#include -#include - -namespace boost { -namespace compute { -namespace detail { - -template -struct is_device_iterator : public boost::false_type {}; - -} // end detail namespace -} // end compute namespace -} // end boost namespace - -#endif // BOOST_COMPUTE_DETAIL_IS_DEVICE_ITERATOR_HPP diff --git a/include/boost/compute/detail/iterator_traits.hpp b/include/boost/compute/detail/iterator_traits.hpp index 9f9935d0..154a58fc 100644 --- a/include/boost/compute/detail/iterator_traits.hpp +++ b/include/boost/compute/detail/iterator_traits.hpp @@ -13,8 +13,8 @@ #include -#include #include +#include namespace boost { namespace compute { diff --git a/include/boost/compute/iterator/buffer_iterator.hpp b/include/boost/compute/iterator/buffer_iterator.hpp index 6b78857d..16ca504a 100644 --- a/include/boost/compute/iterator/buffer_iterator.hpp +++ b/include/boost/compute/iterator/buffer_iterator.hpp @@ -23,9 +23,9 @@ #include #include #include -#include #include #include +#include namespace boost { namespace compute { @@ -255,6 +255,10 @@ make_buffer_iterator(const buffer &buffer, size_t index = 0) return buffer_iterator(buffer, index); } +/// \internal_ (is_device_iterator specialization for buffer_iterator) +template +struct is_device_iterator > : boost::true_type {}; + namespace detail { // is_buffer_iterator specialization for buffer_iterator @@ -269,20 +273,7 @@ struct is_buffer_iterator< >::type > : public boost::true_type {}; -// is_device_iterator specialization for buffer_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - buffer_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - } // end detail namespace - } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/constant_buffer_iterator.hpp b/include/boost/compute/iterator/constant_buffer_iterator.hpp index 748c53c2..1347c4a4 100644 --- a/include/boost/compute/iterator/constant_buffer_iterator.hpp +++ b/include/boost/compute/iterator/constant_buffer_iterator.hpp @@ -18,6 +18,7 @@ #include #include +#include namespace boost { namespace compute { @@ -183,6 +184,10 @@ make_constant_buffer_iterator(const buffer &buffer, size_t index = 0) return constant_buffer_iterator(buffer, index); } +/// \internal_ (is_device_iterator specialization for constant_buffer_iterator) +template +struct is_device_iterator > : boost::true_type {}; + namespace detail { // is_buffer_iterator specialization for constant_buffer_iterator @@ -197,20 +202,7 @@ struct is_buffer_iterator< >::type > : public boost::true_type {}; -// is_device_iterator specialization for constant_buffer_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - constant_buffer_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - } // end detail namespace - } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/constant_iterator.hpp b/include/boost/compute/iterator/constant_iterator.hpp index 15eefe04..643d6b37 100644 --- a/include/boost/compute/iterator/constant_iterator.hpp +++ b/include/boost/compute/iterator/constant_iterator.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include namespace boost { namespace compute { @@ -161,21 +161,9 @@ make_constant_iterator(const T &value, size_t index = 0) return constant_iterator(value, index); } -namespace detail { - -// is_device_iterator specialization for constant_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - constant_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - -} // end detail namespace +/// \internal_ (is_device_iterator specialization for constant_iterator) +template +struct is_device_iterator > : boost::true_type {}; } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/counting_iterator.hpp b/include/boost/compute/iterator/counting_iterator.hpp index bf929f3b..53e12536 100644 --- a/include/boost/compute/iterator/counting_iterator.hpp +++ b/include/boost/compute/iterator/counting_iterator.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include namespace boost { namespace compute { @@ -175,21 +175,9 @@ inline counting_iterator make_counting_iterator(const T &init) return counting_iterator(init); } -namespace detail { - -// is_device_iterator specialization for counting_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - counting_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - -} // end detail namespace +/// \internal_ (is_device_iterator specialization for counting_iterator) +template +struct is_device_iterator > : boost::true_type {}; } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/detail/pixel_input_iterator.hpp b/include/boost/compute/iterator/detail/pixel_input_iterator.hpp index c20f0ad4..d4f60a9e 100644 --- a/include/boost/compute/iterator/detail/pixel_input_iterator.hpp +++ b/include/boost/compute/iterator/detail/pixel_input_iterator.hpp @@ -23,8 +23,8 @@ #include #include #include +#include #include -#include namespace boost { namespace compute { @@ -193,19 +193,12 @@ make_pixel_input_iterator(const image2d &image, size_t index = 0) return pixel_input_iterator(image, index); } -// is_device_iterator specialization for pixel_input_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - pixel_input_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - } // end detail namespace + +// is_device_iterator specialization for pixel_input_iterator +template +struct is_device_iterator > : boost::true_type {}; + } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/detail/swizzle_iterator.hpp b/include/boost/compute/iterator/detail/swizzle_iterator.hpp index 222fc523..51d516a9 100644 --- a/include/boost/compute/iterator/detail/swizzle_iterator.hpp +++ b/include/boost/compute/iterator/detail/swizzle_iterator.hpp @@ -22,9 +22,9 @@ #include #include #include -#include #include #include +#include namespace boost { namespace compute { @@ -176,22 +176,12 @@ make_swizzle_iterator(InputIterator iterator, const std::string &components) return swizzle_iterator(iterator, components); } -// is_device_iterator specialization for swizzle_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - swizzle_iterator< - typename Iterator::base_type, - Iterator::vector_size - >, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - } // end detail namespace + +// is_device_iterator specialization for swizzle_iterator +template +struct is_device_iterator > : boost::true_type {}; + } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/discard_iterator.hpp b/include/boost/compute/iterator/discard_iterator.hpp index 6db64119..4c7b7629 100644 --- a/include/boost/compute/iterator/discard_iterator.hpp +++ b/include/boost/compute/iterator/discard_iterator.hpp @@ -19,7 +19,7 @@ #include #include -#include +#include namespace boost { namespace compute { @@ -160,13 +160,10 @@ inline discard_iterator make_discard_iterator(size_t index = 0) return discard_iterator(index); } -namespace detail { - -// is_device_iterator specialization for discard_iterator +/// internal_ (is_device_iterator specialization for discard_iterator) template<> -struct is_device_iterator : public boost::true_type {}; +struct is_device_iterator : boost::true_type {}; -} // end detail namespace } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/function_input_iterator.hpp b/include/boost/compute/iterator/function_input_iterator.hpp index 8f6b3909..440b4e94 100644 --- a/include/boost/compute/iterator/function_input_iterator.hpp +++ b/include/boost/compute/iterator/function_input_iterator.hpp @@ -18,7 +18,7 @@ #include #include -#include +#include #include namespace boost { @@ -176,21 +176,9 @@ make_function_input_iterator(const Function &function, size_t index = 0) return function_input_iterator(function, index); } -namespace detail { - -// is_device_iterator specialization for function_input_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - function_input_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - -} // end detail namespace +/// \internal_ (is_device_iterator specialization for function_input_iterator) +template +struct is_device_iterator > : boost::true_type {}; } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/permutation_iterator.hpp b/include/boost/compute/iterator/permutation_iterator.hpp index f4933269..26b0e3f7 100644 --- a/include/boost/compute/iterator/permutation_iterator.hpp +++ b/include/boost/compute/iterator/permutation_iterator.hpp @@ -21,9 +21,9 @@ #include #include #include -#include #include #include +#include namespace boost { namespace compute { @@ -181,22 +181,10 @@ make_permutation_iterator(ElementIterator e, IndexIterator i) return permutation_iterator(e, i); } -namespace detail { - -// is_device_iterator specialization for permutation_iterator -template +/// \internal_ (is_device_iterator specialization for permutation_iterator) +template struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - permutation_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - -} // end detail namespace + permutation_iterator > : boost::true_type {}; } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/transform_iterator.hpp b/include/boost/compute/iterator/transform_iterator.hpp index a4457097..bd359700 100644 --- a/include/boost/compute/iterator/transform_iterator.hpp +++ b/include/boost/compute/iterator/transform_iterator.hpp @@ -20,9 +20,9 @@ #include #include #include -#include #include #include +#include #include namespace boost { @@ -106,8 +106,7 @@ inline meta_kernel& operator<<(meta_kernel &kernel, /// \see buffer_iterator, make_transform_iterator() template class transform_iterator : - public detail::transform_iterator_base::type + public detail::transform_iterator_base::type { public: typedef typename @@ -217,22 +216,11 @@ make_transform_iterator(InputIterator iterator, UnaryFunction transform) UnaryFunction>(iterator, transform); } -namespace detail { - -// is_device_iterator specialization for transform_iterator -template +/// \internal_ (is_device_iterator specialization for transform_iterator) +template struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - transform_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; + transform_iterator > : boost::true_type {}; -} // end detail namespace } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/iterator/zip_iterator.hpp b/include/boost/compute/iterator/zip_iterator.hpp index 864295cf..2ab81e81 100644 --- a/include/boost/compute/iterator/zip_iterator.hpp +++ b/include/boost/compute/iterator/zip_iterator.hpp @@ -26,11 +26,11 @@ #include #include -#include -#include #include -#include #include +#include +#include +#include namespace boost { namespace compute { @@ -278,19 +278,11 @@ make_zip_iterator(IteratorTuple iterators) return zip_iterator(iterators); } -namespace detail { +/// \internal_ (is_device_iterator specialization for zip_iterator) +template +struct is_device_iterator > : boost::true_type {}; -// is_device_iterator specialization for zip_iterator -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - zip_iterator, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; +namespace detail { // get() specialization for zip_iterator /// \internal_ diff --git a/include/boost/compute/memory/svm_ptr.hpp b/include/boost/compute/memory/svm_ptr.hpp index 80d176c1..318e6ed2 100644 --- a/include/boost/compute/memory/svm_ptr.hpp +++ b/include/boost/compute/memory/svm_ptr.hpp @@ -12,7 +12,7 @@ #define BOOST_COMPUTE_MEMORY_SVM_PTR_HPP #include -#include +#include namespace boost { namespace compute { @@ -70,21 +70,10 @@ private: T *m_ptr; }; -namespace detail { +/// \internal_ (is_device_iterator specialization for svm_ptr) +template +struct is_device_iterator > : boost::true_type {}; -// is_device_iterator specialization for svm_ptr -template -struct is_device_iterator< - Iterator, - typename boost::enable_if< - boost::is_same< - svm_ptr, - typename boost::remove_const::type - > - >::type -> : public boost::true_type {}; - -} // end detail namespace } // end compute namespace } // end boost namespace diff --git a/include/boost/compute/type_traits.hpp b/include/boost/compute/type_traits.hpp index 5cc2fac4..58d8f649 100644 --- a/include/boost/compute/type_traits.hpp +++ b/include/boost/compute/type_traits.hpp @@ -12,6 +12,7 @@ #define BOOST_COMPUTE_TYPE_TRAITS_HPP #include +#include #include #include #include diff --git a/include/boost/compute/type_traits/is_device_iterator.hpp b/include/boost/compute/type_traits/is_device_iterator.hpp new file mode 100644 index 00000000..9847ba19 --- /dev/null +++ b/include/boost/compute/type_traits/is_device_iterator.hpp @@ -0,0 +1,39 @@ +//---------------------------------------------------------------------------// +// Copyright (c) 2013-2014 Kyle Lutz +// +// Distributed under the Boost Software License, Version 1.0 +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt +// +// See http://kylelutz.github.com/compute for more information. +//---------------------------------------------------------------------------// + +#ifndef BOOST_COMPUTE_TYPE_TRAITS_IS_DEVICE_ITERATOR_HPP +#define BOOST_COMPUTE_TYPE_TRAITS_IS_DEVICE_ITERATOR_HPP + +#include + +namespace boost { +namespace compute { + +/// Meta-function returning \c true if \c Iterator is a device-iterator. +/// +/// By default, this function returns false. Device iterator types (such as +/// buffer_iterator) should specialize this trait and return \c true. +/// +/// For example: +/// \code +/// is_device_iterator>::value == true +/// is_device_iterator::iterator>::value == false +/// \endcode +template +struct is_device_iterator : boost::false_type {}; + +/// \internal_ +template +struct is_device_iterator : is_device_iterator {}; + +} // end compute namespace +} // end boost namespace + +#endif // BOOST_COMPUTE_TYPE_TRAITS_IS_DEVICE_ITERATOR_HPP diff --git a/test/test_buffer_iterator.cpp b/test/test_buffer_iterator.cpp index bb43f675..0b6d747f 100644 --- a/test/test_buffer_iterator.cpp +++ b/test/test_buffer_iterator.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include "check_macros.hpp" #include "context_setup.hpp" diff --git a/test/test_permutation_iterator.cpp b/test/test_permutation_iterator.cpp index e51b2e78..794d1c39 100644 --- a/test/test_permutation_iterator.cpp +++ b/test/test_permutation_iterator.cpp @@ -49,6 +49,19 @@ BOOST_AUTO_TEST_CASE(value_type) )); } +BOOST_AUTO_TEST_CASE(base_type) +{ + BOOST_STATIC_ASSERT(( + boost::is_same< + boost::compute::permutation_iterator< + boost::compute::buffer_iterator, + boost::compute::buffer_iterator + >::base_type, + boost::compute::buffer_iterator + >::value + )); +} + BOOST_AUTO_TEST_CASE(copy) { int input_data[] = { 3, 4, 2, 1, 5 }; diff --git a/test/test_transform_iterator.cpp b/test/test_transform_iterator.cpp index 3ef55651..c7ec881e 100644 --- a/test/test_transform_iterator.cpp +++ b/test/test_transform_iterator.cpp @@ -50,6 +50,18 @@ BOOST_AUTO_TEST_CASE(value_type) )); } +BOOST_AUTO_TEST_CASE(base_type) +{ + BOOST_STATIC_ASSERT(( + boost::is_same< + boost::compute::transform_iterator< + boost::compute::buffer_iterator, boost::compute::abs + >::base_type, + boost::compute::buffer_iterator + >::value + )); +} + BOOST_AUTO_TEST_CASE(copy) { int data[] = { 1, -2, 3, -4, 5 }; diff --git a/test/test_type_traits.cpp b/test/test_type_traits.cpp index 8b547062..a74e4d36 100644 --- a/test/test_type_traits.cpp +++ b/test/test_type_traits.cpp @@ -24,7 +24,6 @@ #include #include #include -#include namespace bc = boost::compute; @@ -119,10 +118,14 @@ BOOST_AUTO_TEST_CASE(is_buffer_iterator) BOOST_AUTO_TEST_CASE(is_device_iterator) { - using boost::compute::detail::is_device_iterator; + using boost::compute::is_device_iterator; BOOST_STATIC_ASSERT(is_device_iterator >::value == true); + BOOST_STATIC_ASSERT(is_device_iterator >::value == true); BOOST_STATIC_ASSERT(is_device_iterator >::value == true); - BOOST_STATIC_ASSERT(is_device_iterator::iterator>::value == false); + BOOST_STATIC_ASSERT(is_device_iterator >::value == true); BOOST_STATIC_ASSERT(is_device_iterator::value == false); + BOOST_STATIC_ASSERT(is_device_iterator::value == false); + BOOST_STATIC_ASSERT(is_device_iterator::iterator>::value == false); + BOOST_STATIC_ASSERT(is_device_iterator::iterator>::value == false); }