2
0
mirror of https://github.com/boostorg/compute.git synced 2026-01-27 18:52:15 +00:00
Files
compute/test/test_histogram.cpp
Denis Demidov 5d77bbebee Global setup for OpenCL context in tests
refs kylelutz/compute#9

device, context, and queue are initialized statically in `context_setup.hpp`.
With this change all tests are able to complete when an NVIDIA GPU is in
exclusive compute mode.

Side effect of the change:
Time for all tests to complete reduced from 15.71 to 13.03 sec Tesla C2075.
2013-04-19 14:53:59 +04:00

54 lines
2.0 KiB
C++

//---------------------------------------------------------------------------//
// 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://kylelutz.github.com/compute for more information.
//---------------------------------------------------------------------------//
#define BOOST_TEST_MODULE TestHistogram
#include <boost/test/unit_test.hpp>
#include <boost/compute/algorithm/fill.hpp>
#include <boost/compute/algorithm/detail/histogram.hpp>
#include <boost/compute/container/vector.hpp>
#include "context_setup.hpp"
BOOST_AUTO_TEST_CASE(histogram_uchar)
{
using boost::compute::uchar_;
using boost::compute::uint_;
uchar_ data[] = { 1, 2, 5, 6, 7, 8, 9, 1, 5, 2,
0, 9, 5, 9, 8, 3, 2, 3, 4, 1,
4, 6, 4, 2, 8, 5, 2, 9, 7, 1 };
boost::compute::vector<uchar_> input(data, data + 30);
boost::compute::vector<uint_> result(10);
boost::compute::fill(result.begin(), result.end(), uint_(0));
boost::compute::command_queue queue =
boost::compute::detail::default_queue_for_iterator(input.begin());
boost::compute::detail::histogram(input.begin(),
input.end(),
result.begin(),
queue);
queue.finish();
BOOST_CHECK_EQUAL(uint_(result[0]), uint_(1));
BOOST_CHECK_EQUAL(uint_(result[1]), uint_(4));
BOOST_CHECK_EQUAL(uint_(result[2]), uint_(5));
BOOST_CHECK_EQUAL(uint_(result[3]), uint_(2));
BOOST_CHECK_EQUAL(uint_(result[4]), uint_(3));
BOOST_CHECK_EQUAL(uint_(result[5]), uint_(4));
BOOST_CHECK_EQUAL(uint_(result[6]), uint_(2));
BOOST_CHECK_EQUAL(uint_(result[7]), uint_(2));
BOOST_CHECK_EQUAL(uint_(result[8]), uint_(3));
BOOST_CHECK_EQUAL(uint_(result[9]), uint_(4));
}
BOOST_AUTO_TEST_SUITE_END()