6 #include <boost/compute/algorithm/copy.hpp> 7 #include <boost/compute/command_queue.hpp> 8 #include <boost/compute/container/vector.hpp> 23 int main(
int argc,
char* argv[]) {
26 auto testcases = create_test_cases();
27 return jb::testing::microbenchmark_group_main<config>(argc, argv, testcases);
33 return static_cast<int>(sysconf(_SC_PAGESIZE));
37 int pagesize = get_page_size();
41 template <
bool upload>
45 boost::compute::context& context, boost::compute::command_queue& q,
47 : fixture(default_size(), context, q, aligned) {
50 int size, boost::compute::context& context,
51 boost::compute::command_queue& q,
bool aligned)
52 : dev(size /
sizeof(
int), context)
53 , host((size + get_page_size()) /
sizeof(
int))
56 , end(host.begin() + size /
sizeof(int)) {
57 int pagesize = get_page_size();
59 reinterpret_cast<std::intptr_t
>(boost::addressof(*start));
61 if (ptr % pagesize == 0) {
68 while (ptr % pagesize != 0 and ++start != host.end() and
69 ++end != host.end()) {
70 ptr =
reinterpret_cast<std::intptr_t
>(boost::addressof(*start));
72 if (ptr % pagesize != 0) {
73 throw std::runtime_error(
"Could not align buffer");
78 boost::compute::copy(start, end, dev.begin(), queue);
80 return static_cast<int>(dev.size());
84 boost::compute::vector<int> dev;
85 std::vector<int> host;
86 boost::compute::command_queue queue;
87 std::vector<int>::iterator start;
88 std::vector<int>::iterator end;
93 int fixture<false>::run() {
94 boost::compute::copy(dev.begin(), dev.end(), start, queue);
96 return static_cast<int>(dev.size());
99 template <
bool upload,
bool aligned>
100 std::function<void(config const&)> test_case() {
101 return [](config
const& cfg) {
103 boost::compute::context context(device);
104 boost::compute::command_queue queue(context, device);
106 benchmark bm(cfg.microbenchmark());
108 auto r = bm.
run(context, queue, aligned);
109 bm.typical_output(r);
115 {
"upload:aligned", test_case<true, true>()},
116 {
"upload:misaligned", test_case<true, false>()},
117 {
"download:aligned", test_case<false, true>()},
118 {
"download:misaligned", test_case<false, false>()},
boost::compute::device device_selector(config const &cfg)
Select an OpenCL device matching the current configuration.
The configuration shared by all OpenCL microbenchmarks.
results run(Args &&... args)
Run the microbenchmaark.
std::map< std::string, std::function< void(config const &cfg)> > microbenchmark_group
Define a representation for a group of microbenchmarks.
Run a micro-benchmark on a given class.
int main(int argc, char *argv[])