| 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 | |
| 11 | #define BOOST_TEST_MODULE TestMalloc |
| 12 | #include <boost/test/unit_test.hpp> |
| 13 | |
| 14 | #include <boost/compute/algorithm/copy.hpp> |
| 15 | #include <boost/compute/experimental/malloc.hpp> |
| 16 | |
| 17 | #include "context_setup.hpp" |
| 18 | |
| 19 | namespace bc = boost::compute; |
| 20 | |
| 21 | BOOST_AUTO_TEST_CASE(malloc_int) |
| 22 | { |
| 23 | bc::experimental::device_ptr<int> ptr = bc::experimental::malloc<int>(5, context); |
| 24 | |
| 25 | int input_data[] = { 2, 5, 8, 3, 6 }; |
| 26 | bc::copy(first: input_data, last: input_data + 5, result: ptr, queue); |
| 27 | |
| 28 | int output_data[5]; |
| 29 | bc::copy(first: ptr, last: ptr + 5, result: output_data, queue); |
| 30 | |
| 31 | BOOST_CHECK_EQUAL(output_data[0], 2); |
| 32 | BOOST_CHECK_EQUAL(output_data[1], 5); |
| 33 | BOOST_CHECK_EQUAL(output_data[2], 8); |
| 34 | BOOST_CHECK_EQUAL(output_data[3], 3); |
| 35 | BOOST_CHECK_EQUAL(output_data[4], 6); |
| 36 | |
| 37 | bc::experimental::free(ptr); |
| 38 | } |
| 39 | |
| 40 | BOOST_AUTO_TEST_SUITE_END() |
| 41 | |