Initializing Boost Compute

Before you can use Boost Compute, we need to initialize a device, context, and a command queue. We will be passing the context and the command queue as mutable references to all our examples with Boost Compute.

The most simple way to initialize the context and the command queue is to use the system default device, like this:

#include <boost/compute.hpp> 
auto main() -> int { 
  // Initialize Boost Compute and OpenCL 
  namespace bc = boost::compute;  auto device = bc::system::default_device();    auto context = bc::context(device);  auto command_queue = bc::command_queue(context, device);
}

Get C++ High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.