123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- //---------------------------------------------------------------------------//
- // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
- //
- // 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://boostorg.github.com/compute for more information.
- //---------------------------------------------------------------------------//
- #define BOOST_TEST_MODULE TestInplaceReduce
- #include <boost/test/unit_test.hpp>
- #include <iostream>
- #include <boost/compute/system.hpp>
- #include <boost/compute/functional.hpp>
- #include <boost/compute/algorithm/iota.hpp>
- #include <boost/compute/algorithm/detail/inplace_reduce.hpp>
- #include <boost/compute/container/vector.hpp>
- #include "quirks.hpp"
- #include "context_setup.hpp"
- BOOST_AUTO_TEST_CASE(sum_int)
- {
- if(is_apple_cpu_device(device)) {
- std::cerr
- << "skipping all inplace_reduce tests due to Apple platform"
- << " behavior when local memory is used on a CPU device"
- << std::endl;
- return;
- }
- int data[] = { 1, 5, 3, 4, 9, 3, 5, 3 };
- boost::compute::vector<int> vector(data, data + 8, queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(33));
- vector.assign(data, data + 8);
- vector.push_back(3);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(36));
- }
- BOOST_AUTO_TEST_CASE(multiply_int)
- {
- if(is_apple_cpu_device(device)) {
- return;
- }
- int data[] = { 1, 5, 3, 4, 9, 3, 5, 3 };
- boost::compute::vector<int> vector(data, data + 8, queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::multiplies<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(24300));
- vector.assign(data, data + 8);
- vector.push_back(3);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::multiplies<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(72900));
- }
- BOOST_AUTO_TEST_CASE(reduce_iota)
- {
- if(is_apple_cpu_device(device)) {
- return;
- }
- // 1 value
- boost::compute::vector<int> vector(1, context);
- boost::compute::iota(vector.begin(), vector.end(), int(0), queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(0));
- // 1000 values
- vector.resize(1000);
- boost::compute::iota(vector.begin(), vector.end(), int(0), queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(499500));
- // 2499 values
- vector.resize(2499);
- boost::compute::iota(vector.begin(), vector.end(), int(0), queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(3121251));
- // 4096 values
- vector.resize(4096);
- boost::compute::iota(vector.begin(), vector.end(), int(0), queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(8386560));
- // 5000 values
- vector.resize(5000);
- boost::compute::iota(vector.begin(), vector.end(), int(0), queue);
- boost::compute::detail::inplace_reduce(vector.begin(),
- vector.end(),
- boost::compute::plus<int>(),
- queue);
- queue.finish();
- BOOST_CHECK_EQUAL(int(vector[0]), int(12497500));
- }
- BOOST_AUTO_TEST_SUITE_END()
|