Transforming the algorithm to Boost Compute

Let's see how the equivalent would be implemented using the GPU with Boost Compute. In order to implement it, we have to perform a few extra steps:

  • Inform Boost Compute of the content of the Circle struct
  • Implement an OpenCL equivalent of the circle_area_cpu() function
  • Copy the data back and forth to the GPU

Note that circle_area_gpu() and boost::compute::plus<float> are compiled by the OpenCL driver at runtime, although the binary can be stored for future use.

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.