JayBeams  0.1
Another project to have fun coding.
bm_launch_kernel.cpp
Go to the documentation of this file.
5 
6 #include <boost/compute/algorithm/copy.hpp>
7 #include <boost/compute/command_queue.hpp>
8 #include <boost/compute/utility/wait_list.hpp>
9 #include <iostream>
10 #include <stdexcept>
11 #include <string>
12 
13 namespace {
15 
16 char const source[] = R"""(
17 __kernel void empty() {
18 }
19 )""";
20 
21 class fixture {
22 public:
23  fixture(boost::compute::context& context, boost::compute::command_queue& q)
24  : fixture(1, context, q) {
25  }
26  fixture(
27  int size, boost::compute::context& context,
28  boost::compute::command_queue& q)
29  : chain_length(size)
30  , kernel(jb::opencl::build_simple_kernel(
31  context, context.get_device(), source, "empty"))
32  , queue(q) {
33  }
34 
35  int run() {
36  boost::compute::wait_list wait;
37  for (int i = 0; i != chain_length; ++i) {
38  auto event = queue.enqueue_task(kernel, wait);
39  wait = boost::compute::wait_list(event);
40  }
41  wait.wait();
42  return chain_length;
43  }
44 
45 private:
46  int chain_length;
47  boost::compute::kernel kernel;
48  boost::compute::command_queue queue;
49 };
50 } // anonymous namespace
51 
52 int main(int argc, char* argv[]) try {
53  config cfg;
54  cfg.process_cmdline(argc, argv);
55  std::cerr << "Configuration for test\n" << cfg << std::endl;
56 
57  boost::compute::device device = jb::opencl::device_selector(cfg.opencl());
58  boost::compute::context context(device);
59  boost::compute::command_queue queue(context, device);
60  typedef jb::testing::microbenchmark<fixture> benchmark;
61  benchmark bm(cfg.microbenchmark());
62 
63  auto r = bm.run(context, queue);
64  bm.typical_output(r);
65 
66  return 0;
67 } catch (jb::usage const& ex) {
68  std::cerr << "usage: " << ex.what() << std::endl;
69  return ex.exit_status();
70 } catch (std::exception const& ex) {
71  std::cerr << "standard exception raised: " << ex.what() << std::endl;
72  return 1;
73 } catch (...) {
74  std::cerr << "unknown exception raised" << std::endl;
75  return 1;
76 }
int exit_status() const
Definition: usage.hpp:21
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.
boost::compute::kernel build_simple_kernel(boost::compute::context context, boost::compute::device device, char const *code, char const *kernel_name)
Build a simple program (one where everything is in a single string) and get a kernel from it...
A simple class to communicate the result of parsing the options.
Definition: usage.hpp:11
int main(int argc, char *argv[])
Run a micro-benchmark on a given class.
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7