Skip to content

OpenCL Device Vector Performance Parameters

Jay edited this page Feb 26, 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>
#include <bolt/cl/control.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,
                     in_buffer.begin(),
                     in_buffer.end(),
                     in_buffer.begin(),
                     bolt::cl::plus<int>() );
...

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

#include <bolt/cl/transform.h>
#include <bolt/cl/device_vector.h>
#include <bolt/cl/control.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::MulticoreCpu);       // Choose TBB path
bolt::cl::transform( ctl,
                     in_buffer.begin(),
                     in_buffer.end(),
                     in_buffer.begin(),
                     bolt::cl::plus<int>() );
...

Clone this wiki locally