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

Coal::CPUKernel Class Reference

CPU kernel. More...

#include <kernel.h>

Inheritance diagram for Coal::CPUKernel:
Collaboration diagram for Coal::CPUKernel:

List of all members.

Public Member Functions

 CPUKernel (CPUDevice *device, Kernel *kernel, llvm::Function *function)
 Constructor.
 ~CPUKernel ()
size_t workGroupSize () const
 Maximum work-group size of a kernel.
cl_ulong localMemSize () const
 Local memory used by the kernel.
cl_ulong privateMemSize () const
 Private memory used by the kernel.
size_t preferredWorkGroupSizeMultiple () const
 Preferred work-group size multiple.
size_t guessWorkGroupSize (cl_uint num_dims, cl_uint dim, size_t global_work_size) const
 Optimal work-group size.
Kernelkernel () const
 Coal::Kernel object this kernel will run
CPUDevicedevice () const
 device on which the kernel will be run
llvm::Function * function () const
 llvm::Function representing the kernel but not to be run
llvm::Function * callFunction ()
 stub function used to run the kernel, see Using Clang and LLVM to Launch Kernels

Static Public Member Functions

static size_t typeOffset (size_t &offset, size_t type_len)
 Calculate where to place a value in an array.

Private Attributes

CPUDevicep_device
Kernelp_kernel
llvm::Function * p_function
llvm::Function * p_call_function
pthread_mutex_t p_call_function_mutex

Detailed Description

CPU kernel.

This class holds passive information about a kernel (Coal::Kernel object and device on which it is run) and provides the callFunction() function.

This function is described at the end of Using Clang and LLVM to Launch Kernels .

See also:
Coal::CPUKernelWorkGroup

Definition at line 71 of file cpu/kernel.h.


Constructor & Destructor Documentation

CPUKernel::CPUKernel ( CPUDevice device,
Kernel kernel,
llvm::Function *  function 
)

Constructor.

Parameters:
devicedevice on which the kernel will be run
kernelCoal::Kernel object holding information about this kernel
functionllvm::Function to run

Definition at line 58 of file cpu/kernel.cpp.

References p_call_function_mutex.

CPUKernel::~CPUKernel ( )

Definition at line 65 of file cpu/kernel.cpp.

References p_call_function, and p_call_function_mutex.


Member Function Documentation

llvm::Function * CPUKernel::callFunction ( )
CPUDevice * CPUKernel::device ( ) const

device on which the kernel will be run

Definition at line 146 of file cpu/kernel.cpp.

References p_device.

Referenced by Coal::CPUKernelWorkGroup::callArgs(), Coal::CPUKernelWorkGroup::getImageData(), and Coal::CPUKernelWorkGroup::run().

llvm::Function * CPUKernel::function ( ) const

llvm::Function representing the kernel but not to be run

Definition at line 136 of file cpu/kernel.cpp.

References p_function.

Referenced by Coal::CPUKernelWorkGroup::barrier(), and Coal::CPUKernelWorkGroup::builtinNotFound().

size_t CPUKernel::guessWorkGroupSize ( cl_uint  num_dims,
cl_uint  dim,
size_t  global_work_size 
) const [virtual]

Optimal work-group size.

This function allows a device to calculate the optimal work-group size for this kernel, using it's memory usage, SIMD dimension, etc.

Coal::CPUDevice tries to split the kernel into a number of work-groups the closest possible to the number of CPU cores.

Parameters:
num_dimsNumber of working dimensions
dimDimension for which the multiple is being calculated
global_work_sizeTotal number of work-items to split into work-groups
Returns:
optimal size of a work-group, for the dim dimension.

Implements Coal::DeviceKernel.

Definition at line 106 of file cpu/kernel.cpp.

References k_exp(), Coal::CPUDevice::numCPUs(), and p_device.

Kernel * CPUKernel::kernel ( ) const

Coal::Kernel object this kernel will run

Definition at line 141 of file cpu/kernel.cpp.

References p_kernel.

Referenced by Coal::CPUKernelWorkGroup::callArgs(), and Coal::CPUKernelWorkGroup::run().

cl_ulong CPUKernel::localMemSize ( ) const [virtual]

Local memory used by the kernel.

Returns:
Local memory used by the kernel, in bytes

Implements Coal::DeviceKernel.

Definition at line 78 of file cpu/kernel.cpp.

size_t CPUKernel::preferredWorkGroupSizeMultiple ( ) const [virtual]

Preferred work-group size multiple.

Returns:
The size multiple a work-group can have to work the best and the fastest on the device

Implements Coal::DeviceKernel.

Definition at line 88 of file cpu/kernel.cpp.

cl_ulong CPUKernel::privateMemSize ( ) const [virtual]

Private memory used by the kernel.

Returns:
Private memory used by the kernel, in bytes

Implements Coal::DeviceKernel.

Definition at line 83 of file cpu/kernel.cpp.

size_t CPUKernel::typeOffset ( size_t &  offset,
size_t  type_len 
) [static]

Calculate where to place a value in an array.

This function is used to calculate where to place a value in an array given its size, properly aligning it.

This function is called repeatedly to obtain the aligned position of each value that must be place in the array

 size_t array_len = 0, array_offset = 0;
 void *array;

 // First, get the array size given alignment constraints
 typeOffset(array_len, sizeof(int));
 typeOffset(array_len, sizeof(float));
 typeOffset(array_len, sizeof(void *));

 // Then, allocate memory
 array = malloc(array_len)

 // Finally, place the arguments
 *(int *)((char *)array + typeOffset(array_offset, sizeof(int))) = 1337;
 *(float *)((char *)array + typeOffset(array_offset, sizeof(int))) = 3.1415f;
 *(void **)((char *)array + typeOffset(array_offset, sizeof(int))) = array;
Parameters:
offsetoffset at which the value will be placed. This variable gets incremented by type_len + padding.
type_lensize in bytes of the value that will be stored
Returns:
offset at which the value will be stored (equal to offset before incrementation.

Definition at line 162 of file cpu/kernel.cpp.

References next_power_of_two().

Referenced by Coal::CPUKernelWorkGroup::callArgs(), and callFunction().

size_t CPUKernel::workGroupSize ( ) const [virtual]

Maximum work-group size of a kernel.

Returns:
Maximum work-group size of the kernel based on device-specific data such as memory usage, register pressure, etc)

Implements Coal::DeviceKernel.

Definition at line 73 of file cpu/kernel.cpp.


Member Data Documentation

llvm::Function * Coal::CPUKernel::p_call_function [private]

Definition at line 135 of file cpu/kernel.h.

Referenced by callFunction(), and ~CPUKernel().

pthread_mutex_t Coal::CPUKernel::p_call_function_mutex [private]

Definition at line 136 of file cpu/kernel.h.

Referenced by callFunction(), CPUKernel(), and ~CPUKernel().

Definition at line 133 of file cpu/kernel.h.

Referenced by device(), and guessWorkGroupSize().

llvm::Function* Coal::CPUKernel::p_function [private]

Definition at line 135 of file cpu/kernel.h.

Referenced by callFunction(), and function().

Definition at line 134 of file cpu/kernel.h.

Referenced by callFunction(), and kernel().


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