]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/compute/test/test_user_defined_types.cpp
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #define BOOST_TEST_MODULE TestUserDefinedTypes
12 #include <boost/test/unit_test.hpp>
16 #include <boost/compute/function.hpp>
17 #include <boost/compute/system.hpp>
18 #include <boost/compute/algorithm/sort.hpp>
19 #include <boost/compute/container/vector.hpp>
20 #include <boost/compute/types/struct.hpp>
22 namespace compute
= boost::compute
;
24 // user-defined data type containing two int's and a float
32 // make UDD available to OpenCL
33 BOOST_COMPUTE_ADAPT_STRUCT(UDD
, UDD
, (a
, b
, c
))
35 // comparison operator for UDD
36 bool operator==(const UDD
&lhs
, const UDD
&rhs
)
38 return lhs
.a
== rhs
.a
&& lhs
.b
== rhs
.b
&& lhs
.c
== rhs
.c
;
41 // output stream operator for UDD
42 std::ostream
& operator<<(std::ostream
&stream
, const UDD
&x
)
44 return stream
<< "(" << x
.a
<< ", " << x
.b
<< ", " << x
.c
<< ")";
47 // function to generate a random UDD on the host
53 udd
.c
= (float)(rand() % 100) / 1.3f
;
58 // function to compare two UDD's on the host by their first component
59 bool compare_UDD_host(const UDD
&lhs
, const UDD
&rhs
)
64 // function to compate two UDD's on the device by their first component
65 BOOST_COMPUTE_FUNCTION(bool, compare_UDD_device
, (UDD lhs
, UDD rhs
),
70 #include "check_macros.hpp"
71 #include "context_setup.hpp"
73 // see: issue #11 (https://github.com/boostorg/compute/issues/11)
74 BOOST_AUTO_TEST_CASE(issue_11
)
76 if(device
.vendor() == "NVIDIA" && device
.platform().name() == "Apple"){
77 // FIXME: this test currently segfaults on NVIDIA GPUs on Apple
78 std::cerr
<< "skipping issue test on NVIDIA GPU on Apple platform" << std::endl
;
82 // create vector of random values on the host
83 std::vector
<UDD
> host_vector(10);
84 std::generate(host_vector
.begin(), host_vector
.end(), rand_UDD
);
86 // transfer the values to the device
87 compute::vector
<UDD
> device_vector(host_vector
.size(), context
);
89 host_vector
.begin(), host_vector
.end(), device_vector
.begin(), queue
92 // sort values on the device
94 device_vector
.begin(),
100 // sort values on the host
107 // copy sorted device values back to the host
108 std::vector
<UDD
> tmp(10);
110 device_vector
.begin(),
116 // verify sorted values
117 for(size_t i
= 0; i
< host_vector
.size(); i
++){
118 BOOST_CHECK_EQUAL(tmp
[i
], host_vector
[i
]);
122 BOOST_AUTO_TEST_SUITE_END()