Clover Git
OpenCL 1.1 software implementation
Public Member Functions | Private Attributes

Coal::CPUDevice Class Reference

CPU device. More...

#include <device.h>

Inheritance diagram for Coal::CPUDevice:
Collaboration diagram for Coal::CPUDevice:

List of all members.

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.
DeviceBuffercreateDeviceBuffer (MemObject *buffer, cl_int *rs)
 Create a Coal::DeviceBuffer object for this device.
DeviceProgramcreateDeviceProgram (Program *program)
 Create a Coal::DeviceProgram object for this device.
DeviceKernelcreateDeviceKernel (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.
EventgetEvent (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

Detailed Description

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.

See also:
Command Queues, Events and Worker Threads

Definition at line 62 of file device.h.


Constructor & Destructor Documentation

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.


Member Function Documentation

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.

Parameters:
bufferMemory object for which the buffer has to be created
rsError code (CL_SUCCESS if no error)
Returns:
a 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.

Parameters:
kernelCoal::Kernel containing the device-independent kernel data
functiondevice-specific llvm::Function to be used
Returns:
a 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.

Parameters:
programCoal::Program containing the device-independent program data
Returns:
a 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.

Parameters:
eventthe 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)
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);
Parameters:
param_nameName of the property to retrieve
param_value_sizeSize of the application-allocated buffer in which to put the value.
param_valuePointer to an application-allocated buffer where the property data will be stored. Ignored if NULL.
param_value_size_retSize of the value retrieved, ignored if NULL.
Returns:
CL_SUCCESS in case of success, otherwise a CL error code.

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.

Note:
This function has one obligation: it must call Coal::MapBufferEvent::setPtr() and Coal::MapImageEvent::setPtr() (and other function described in its documentation)
Parameters:
eventthe event for which data can be set
Returns:
CL_SUCCESS in case of success

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.

See also:
the end of Command Queues, Events and Worker Threads
Parameters:
eventthe 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.


Member Data Documentation

unsigned int Coal::CPUDevice::p_cores [private]

Definition at line 96 of file device.h.

Referenced by init(), and numCPUs().

float Coal::CPUDevice::p_cpu_mhz [private]

Definition at line 97 of file device.h.

Referenced by cpuMhz(), and init().

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().

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().


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines