Clover Git
OpenCL 1.1 software implementation
|
CPU device. More...
#include <device.h>
Public Member Functions | |
CPUDevice () | |
~CPUDevice () | |
void | init () |
Initialize the CPU device. | |
cl_int | info (cl_device_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) const |
Retrieve information about the device. | |
DeviceBuffer * | createDeviceBuffer (MemObject *buffer, cl_int *rs) |
Create a Coal::DeviceBuffer object for this device. | |
DeviceProgram * | createDeviceProgram (Program *program) |
Create a Coal::DeviceProgram object for this device. | |
DeviceKernel * | createDeviceKernel (Kernel *kernel, llvm::Function *function) |
Create a Coal::DeviceKernel object for this device. | |
cl_int | initEventDeviceData (Event *event) |
Initialize device-specific event data. | |
void | freeEventDeviceData (Event *event) |
Free device-specific event data. | |
void | pushEvent (Event *event) |
Push an event on the device. | |
Event * | getEvent (bool &stop) |
unsigned int | numCPUs () const |
Number of logical CPU cores on the system. | |
float | cpuMhz () const |
Speed of the CPU in Mhz. | |
Private Attributes | |
unsigned int | p_cores |
unsigned int | p_num_events |
float | p_cpu_mhz |
pthread_t * | p_workers |
std::list< Event * > | p_events |
pthread_cond_t | p_events_cond |
pthread_mutex_t | p_events_mutex |
bool | p_stop |
bool | p_initialized |
CPU device.
This class is the base of all the CPU-accelerated OpenCL processing. It creates and manages subclasses such as Coal::DeviceBuffer
, Coal::DeviceProgram
and Coal::DeviceKernel
.
This class and the aforementioned ones work together to compile and run kernels using the LLVM JIT, manage buffers, provide built-in functions and do all of this in a multithreaded fashion using worker threads.
CPUDevice::CPUDevice | ( | ) |
Definition at line 58 of file device.cpp.
CPUDevice::~CPUDevice | ( | ) |
Definition at line 109 of file device.cpp.
References numCPUs(), p_events_cond, p_events_mutex, p_initialized, p_stop, and p_workers.
float CPUDevice::cpuMhz | ( | ) | const |
Speed of the CPU in Mhz.
Definition at line 285 of file device.cpp.
References p_cpu_mhz.
Referenced by info().
DeviceBuffer * CPUDevice::createDeviceBuffer | ( | MemObject * | buffer, |
cl_int * | rs | ||
) | [virtual] |
Create a Coal::DeviceBuffer
object for this device.
buffer | Memory object for which the buffer has to be created |
rs | Error code (CL_SUCCESS if no error) |
Coal::DeviceBuffer
object, undefined if there is an error Implements Coal::DeviceInterface.
Definition at line 133 of file device.cpp.
DeviceKernel * CPUDevice::createDeviceKernel | ( | Kernel * | kernel, |
llvm::Function * | function | ||
) | [virtual] |
Create a Coal::DeviceKernel
object for this device.
kernel | Coal::Kernel containing the device-independent kernel data |
function | device-specific llvm::Function to be used |
Coal::DeviceKernel
object Implements Coal::DeviceInterface.
Definition at line 143 of file device.cpp.
DeviceProgram * CPUDevice::createDeviceProgram | ( | Program * | program | ) | [virtual] |
Create a Coal::DeviceProgram
object for this device.
program | Coal::Program containing the device-independent program data |
Coal::DeviceProgram
object Implements Coal::DeviceInterface.
Definition at line 138 of file device.cpp.
void CPUDevice::freeEventDeviceData | ( | Event * | event | ) | [virtual] |
Free device-specific event data.
This function is called just before event
gets deleted. It allows a device to free device-specific data of this event, if any.
event | the event that will be destroyed |
Implements Coal::DeviceInterface.
Definition at line 212 of file device.cpp.
References Coal::Event::deviceData(), Coal::Event::NDRangeKernel, Coal::Event::TaskKernel, and Coal::Event::type().
Event * CPUDevice::getEvent | ( | bool & | stop | ) |
Definition at line 241 of file device.cpp.
References Coal::Event::NDRangeKernel, p_events, p_events_cond, p_events_mutex, p_num_events, p_stop, Coal::CPUKernelEvent::reserve(), and Coal::Event::TaskKernel.
Referenced by worker().
cl_int CPUDevice::info | ( | cl_device_info | param_name, |
size_t | param_value_size, | ||
void * | param_value, | ||
size_t * | param_value_size_ret | ||
) | const [virtual] |
Retrieve information about the device.
This function is used to retrieve information about an object. Sometimes, the size of the data retrieved is unknown (for example, a string). The application can call this function twice, the first time to get the size, then it allocates a buffer, and finally get the data.
const char *string = 0; size_t len; object->info(FOO_PROPERTY_STRING, 0, 0, &len); string = std::malloc(len); object->info(FOO_PROPERTY_STRING, len, string, 0);
param_name | Name of the property to retrieve |
param_value_size | Size of the application-allocated buffer in which to put the value. |
param_value | Pointer to an application-allocated buffer where the property data will be stored. Ignored if NULL. |
param_value_size_ret | Size of the value retrieved, ignored if NULL. |
Implements Coal::DeviceInterface.
Definition at line 303 of file device.cpp.
References cpuMhz(), numCPUs(), SIMPLE_ASSIGN, STRING_ASSIGN, and TYPE_MAX.
void CPUDevice::init | ( | ) |
Initialize the CPU device.
This function creates the worker threads and get information about the host system for the numCPUs()
and cpuMhz
functions.
Definition at line 65 of file device.cpp.
References numCPUs(), p_cores, p_cpu_mhz, p_events_cond, p_events_mutex, p_initialized, p_workers, and worker().
Referenced by clGetDeviceIDs().
cl_int CPUDevice::initEventDeviceData | ( | Event * | event | ) | [virtual] |
Initialize device-specific event data.
This call allows a device to initialize device-specific event data, by using Coal::Event::setDeviceData()
. For instance, an hardware-accelerated device can associate a device command to an event, and use it to manage the event when it gets pushed.
Coal::MapBufferEvent::setPtr()
and Coal::MapImageEvent::setPtr()
(and other function described in its documentation)event | the event for which data can be set |
Implements Coal::DeviceInterface.
Definition at line 149 of file device.cpp.
References Coal::BufferEvent::buffer(), Coal::CPUBuffer::data(), Coal::MemObject::deviceBuffer(), Coal::Program::deviceDependentProgram(), imageData(), Coal::CPUProgram::initJIT(), Coal::KernelEvent::kernel(), Coal::Event::MapBuffer, Coal::Event::MapImage, Coal::Event::NDRangeKernel, Coal::MapBufferEvent::offset(), Coal::MapImageEvent::origin(), Coal::Object::parent(), Coal::Image2D::pixel_size(), Coal::Image2D::row_pitch(), Coal::Event::setDeviceData(), Coal::MapImageEvent::setPtr(), Coal::MapBufferEvent::setPtr(), Coal::MapImageEvent::setRowPitch(), Coal::MapImageEvent::setSlicePitch(), Coal::Image2D::slice_pitch(), Coal::Event::TaskKernel, Coal::Event::type(), and Coal::Event::UnmapMemObject.
unsigned int CPUDevice::numCPUs | ( | ) | const |
Number of logical CPU cores on the system.
Definition at line 280 of file device.cpp.
References p_cores.
Referenced by Coal::CPUKernel::guessWorkGroupSize(), info(), init(), and ~CPUDevice().
void CPUDevice::pushEvent | ( | Event * | event | ) | [virtual] |
Push an event on the device.
event | the event to be pushed |
Implements Coal::DeviceInterface.
Definition at line 229 of file device.cpp.
References p_events, p_events_cond, p_events_mutex, and p_num_events.
unsigned int Coal::CPUDevice::p_cores [private] |
float Coal::CPUDevice::p_cpu_mhz [private] |
std::list<Event *> Coal::CPUDevice::p_events [private] |
Definition at line 100 of file device.h.
Referenced by getEvent(), and pushEvent().
pthread_cond_t Coal::CPUDevice::p_events_cond [private] |
Definition at line 101 of file device.h.
Referenced by getEvent(), init(), pushEvent(), and ~CPUDevice().
pthread_mutex_t Coal::CPUDevice::p_events_mutex [private] |
Definition at line 102 of file device.h.
Referenced by getEvent(), init(), pushEvent(), and ~CPUDevice().
bool Coal::CPUDevice::p_initialized [private] |
Definition at line 103 of file device.h.
Referenced by init(), and ~CPUDevice().
unsigned int Coal::CPUDevice::p_num_events [private] |
Definition at line 96 of file device.h.
Referenced by getEvent(), and pushEvent().
bool Coal::CPUDevice::p_stop [private] |
Definition at line 103 of file device.h.
Referenced by getEvent(), and ~CPUDevice().
pthread_t* Coal::CPUDevice::p_workers [private] |
Definition at line 98 of file device.h.
Referenced by init(), and ~CPUDevice().