test_malloc.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013 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 TestMalloc
  11. #include <boost/test/unit_test.hpp>
  12. #include <boost/compute/algorithm/copy.hpp>
  13. #include <boost/compute/experimental/malloc.hpp>
  14. #include "context_setup.hpp"
  15. namespace bc = boost::compute;
  16. BOOST_AUTO_TEST_CASE(malloc_int)
  17. {
  18. bc::experimental::device_ptr<int> ptr = bc::experimental::malloc<int>(5, context);
  19. int input_data[] = { 2, 5, 8, 3, 6 };
  20. bc::copy(input_data, input_data + 5, ptr, queue);
  21. int output_data[5];
  22. bc::copy(ptr, ptr + 5, output_data, queue);
  23. BOOST_CHECK_EQUAL(output_data[0], 2);
  24. BOOST_CHECK_EQUAL(output_data[1], 5);
  25. BOOST_CHECK_EQUAL(output_data[2], 8);
  26. BOOST_CHECK_EQUAL(output_data[3], 3);
  27. BOOST_CHECK_EQUAL(output_data[4], 6);
  28. bc::experimental::free(ptr);
  29. }
  30. BOOST_AUTO_TEST_SUITE_END()