Clover Git
OpenCL 1.1 software implementation
|
CPU kernel. More...
#include <kernel.h>
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. | |
Kernel * | kernel () const |
Coal::Kernel object this kernel will run | |
CPUDevice * | device () 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 | |
CPUDevice * | p_device |
Kernel * | p_kernel |
llvm::Function * | p_function |
llvm::Function * | p_call_function |
pthread_mutex_t | p_call_function_mutex |
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 .
Definition at line 71 of file cpu/kernel.h.
Constructor.
device | device on which the kernel will be run |
kernel | Coal::Kernel object holding information about this kernel |
function | llvm::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.
llvm::Function * CPUKernel::callFunction | ( | ) |
stub function used to run the kernel, see Using Clang and LLVM to Launch Kernels
Definition at line 179 of file cpu/kernel.cpp.
References Coal::Kernel::arg(), p_call_function, p_call_function_mutex, p_function, p_kernel, typeOffset(), Coal::Kernel::Arg::valueSize(), and Coal::Kernel::Arg::vecDim().
Referenced by Coal::CPUKernelWorkGroup::run().
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.
num_dims | Number of working dimensions |
dim | Dimension for which the multiple is being calculated |
global_work_size | Total number of work-items to split into work-groups |
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.
Implements Coal::DeviceKernel.
Definition at line 78 of file cpu/kernel.cpp.
size_t CPUKernel::preferredWorkGroupSizeMultiple | ( | ) | const [virtual] |
Preferred work-group size multiple.
Implements Coal::DeviceKernel.
Definition at line 88 of file cpu/kernel.cpp.
cl_ulong CPUKernel::privateMemSize | ( | ) | const [virtual] |
Private memory used by the kernel.
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;
offset | offset at which the value will be placed. This variable gets incremented by type_len + padding . |
type_len | size in bytes of the value that will be stored |
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.
Implements Coal::DeviceKernel.
Definition at line 73 of file cpu/kernel.cpp.
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().
CPUDevice* Coal::CPUKernel::p_device [private] |
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().
Kernel* Coal::CPUKernel::p_kernel [private] |
Definition at line 134 of file cpu/kernel.h.
Referenced by callFunction(), and kernel().