forked from boostorg/compute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_functional_unpack.cpp
99 lines (83 loc) · 2.97 KB
/
test_functional_unpack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <[email protected]>
//
// 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 TestFunctionalUnpack
#include <boost/test/unit_test.hpp>
#include <boost/compute/system.hpp>
#include <boost/compute/algorithm/copy_n.hpp>
#include <boost/compute/algorithm/transform.hpp>
#include <boost/compute/container/vector.hpp>
#include <boost/compute/iterator/zip_iterator.hpp>
#include <boost/compute/functional/detail/unpack.hpp>
#include "check_macros.hpp"
#include "context_setup.hpp"
namespace compute = boost::compute;
BOOST_AUTO_TEST_CASE(plus_int)
{
int data1[] = { 1, 3, 5, 7 };
int data2[] = { 2, 4, 6, 8 };
compute::vector<int> input1(4, context);
compute::vector<int> input2(4, context);
compute::copy_n(data1, 4, input1.begin(), queue);
compute::copy_n(data2, 4, input2.begin(), queue);
compute::vector<int> output(4, context);
compute::transform(
compute::make_zip_iterator(
boost::make_tuple(input1.begin(), input2.begin())
),
compute::make_zip_iterator(
boost::make_tuple(input1.end(), input2.end())
),
output.begin(),
compute::detail::unpack(compute::plus<int>()),
queue
);
CHECK_RANGE_EQUAL(int, 4, output, (3, 7, 11, 15));
}
BOOST_AUTO_TEST_CASE(fma_float)
{
float data1[] = { 1, 3, 5, 7 };
float data2[] = { 2, 4, 6, 8 };
float data3[] = { 0, 9, 1, 2 };
compute::vector<float> input1(4, context);
compute::vector<float> input2(4, context);
compute::vector<float> input3(4, context);
compute::copy_n(data1, 4, input1.begin(), queue);
compute::copy_n(data2, 4, input2.begin(), queue);
compute::copy_n(data3, 4, input3.begin(), queue);
compute::vector<int> output(4, context);
compute::transform(
compute::make_zip_iterator(
boost::make_tuple(input1.begin(), input2.begin(), input3.begin())
),
compute::make_zip_iterator(
boost::make_tuple(input1.end(), input2.end(), input3.begin())
),
output.begin(),
compute::detail::unpack(compute::fma<float>()),
queue
);
}
BOOST_AUTO_TEST_CASE(subtract_int2)
{
using compute::int2_;
int data[] = { 4, 2, 5, 1, 6, 3, 7, 0 };
compute::vector<int2_> input(4, context);
compute::copy_n(reinterpret_cast<int2_ *>(data), 4, input.begin(), queue);
compute::vector<int> output(4, context);
compute::transform(
input.begin(),
input.end(),
output.begin(),
compute::detail::unpack(compute::minus<int>()),
queue
);
CHECK_RANGE_EQUAL(int, 4, output, (2, 4, 3, 7));
}
BOOST_AUTO_TEST_SUITE_END()