test_buffer_iterator.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #define BOOST_TEST_MODULE TestBufferIterator
  11. #include <boost/test/unit_test.hpp>
  12. #include <iterator>
  13. #include <boost/type_traits.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/compute/algorithm/copy.hpp>
  16. #include <boost/compute/algorithm/reverse.hpp>
  17. #include <boost/compute/container/vector.hpp>
  18. #include <boost/compute/iterator/buffer_iterator.hpp>
  19. #include "check_macros.hpp"
  20. #include "context_setup.hpp"
  21. namespace compute = boost::compute;
  22. BOOST_AUTO_TEST_CASE(value_type)
  23. {
  24. BOOST_STATIC_ASSERT((
  25. boost::is_same<
  26. compute::buffer_iterator<int>::value_type, int
  27. >::value
  28. ));
  29. BOOST_STATIC_ASSERT((
  30. boost::is_same<
  31. compute::buffer_iterator<float>::value_type, float
  32. >::value
  33. ));
  34. }
  35. BOOST_AUTO_TEST_CASE(reverse_external_buffer_doctest)
  36. {
  37. int data[] = { 1, 2, 3 };
  38. compute::buffer buffer(context, 3 * sizeof(int));
  39. queue.enqueue_write_buffer(buffer, 0, 3 * sizeof(int), data);
  40. cl_mem external_mem_obj = buffer.get();
  41. //! [reverse_external_buffer]
  42. // create a buffer object wrapping the cl_mem object
  43. boost::compute::buffer buf(external_mem_obj);
  44. // reverse the values in the buffer
  45. boost::compute::reverse(
  46. boost::compute::make_buffer_iterator<int>(buf, 0),
  47. boost::compute::make_buffer_iterator<int>(buf, 3),
  48. queue
  49. );
  50. //! [reverse_external_buffer]
  51. queue.enqueue_read_buffer(buf, 0, 3 * sizeof(int), data);
  52. BOOST_CHECK_EQUAL(data[0], 3);
  53. BOOST_CHECK_EQUAL(data[1], 2);
  54. BOOST_CHECK_EQUAL(data[2], 1);
  55. }
  56. BOOST_AUTO_TEST_SUITE_END()