Skip to content

OpenCL Device Vector Performance Parameters

Jay edited this page Feb 25, 2014 · 13 revisions

This page discusses the performance of bolt::cl::device_vector in various situations

Device Vector is a container designed to encapsulate an OpenCL buffer on the GPU. The performance of device_vector varies depending on the type and location of the buffer. For instance, it's advisable not to use a CL_MEM_READ_WRITE buffer if the program eventually executes on the host.

#include <bolt/cl/transform.h>
#include <bolt/cl/device_vector.h>

...

bolt::cl::device_vector<int> in_buffer( h_vector.begin(), // Calls default device_vector constructor
                                        h_vector.end() ); // CL_MEM_READ_WRITE buffer
bolt::cl::control ctl;
ctl.setForceRunMode(bolt::cl::control::OpenCL); // Assuming a GPU device supporting OpenCL exists
bolt::cl::transform( ctl,
                     input_buffer.begin(),
                     input_buffer.end(),
                     input_buffer.begin(),
                     bolt::cl::plus<int>() );
...

The code snippet above, demonstrates the right usage of device_vector -- The buffer resides on the GPU and the code runs on the GPU.

Clone this wiki locally