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

Coal::Kernel Class Reference

Kernel. More...

#include <kernel.h>

Inheritance diagram for Coal::Kernel:
Collaboration diagram for Coal::Kernel:

List of all members.

Classes

class  Arg
 Kernel argument. More...
struct  DeviceDependent

Public Member Functions

 Kernel (Program *program)
 Constructor.
 ~Kernel ()
cl_int addFunction (DeviceInterface *device, llvm::Function *function, llvm::Module *module)
 Add a llvm::Function to this kernel.
llvm::Function * function (DeviceInterface *device) const
 Get the LLVM function for a specified device.
cl_int setArg (cl_uint index, size_t size, const void *value)
 Set the value of an argument.
unsigned int numArgs () const
 Number of arguments of this kernel.
const Argarg (unsigned int index) const
 Arg at the given index
DeviceKerneldeviceDependentKernel (DeviceInterface *device) const
 Coal::DeviceKernel for the specified device
bool argsSpecified () const
 true if all the arguments have been set through setArg()
bool hasLocals () const
 true if one or more argument is in file Arg::Local
cl_int info (cl_kernel_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) const
 Get information about this kernel.
cl_int workGroupInfo (DeviceInterface *device, cl_kernel_work_group_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) const
 Get performance hints and device-specific data about this kernel.

Private Member Functions

const DeviceDependentdeviceDependent (DeviceInterface *device) const
DeviceDependentdeviceDependent (DeviceInterface *device)

Private Attributes

std::string p_name
bool p_has_locals
std::vector< DeviceDependentp_device_dependent
std::vector< Argp_args
DeviceDependent null_dep

Detailed Description

Kernel.

A kernel represents a LLVM function that can be run on a device. As Coal::Kernel objects are device-independent, they in fact represent only the name of a kernel and the arguments the application wants to pass to it, but it also contains a list of LLVM functions for each device for which its parent Coal::Program has been built

Definition at line 65 of file kernel.h.


Constructor & Destructor Documentation

Kernel::Kernel ( Program program)
Kernel::~Kernel ( )

Definition at line 62 of file kernel.cpp.

References Coal::Kernel::DeviceDependent::kernel, and p_device_dependent.


Member Function Documentation

cl_int Kernel::addFunction ( DeviceInterface device,
llvm::Function *  function,
llvm::Module *  module 
)

Add a llvm::Function to this kernel.

This function adds a llvm::Function to this kernel for the specified device. It also has the responsibility to find the Arg::Kind of each of the function's arguments.

LLVM provides a llvm::Type for each argument:

  • If it is a pointer, the kind of the argument is Arg::Buffer and its field is a simple cast from a LLVM addrspace to Arg::File.
  • If it is a pointer to a struct whose name is either %struct.image2d or %struct.image3d, kind is set to Arg::Image2D or Arg::Image3D, respectively.
  • If it is a vector, vec_dim is set to the vector size, and the rest of the computations are done on the element type
  • Then we translate the LLVM type to an Arg::Kind. For instance, i32 becomes Arg::Int32

Samplers aren't detected at this stage because they are plain i32 types on the LLVM side. They are detected in setArg() when the value being set to the argument appears to be a Coal::Sampler.

Parameters:
devicedevice for which the function is added
functionfunction to add
moduleLLVM module of this function

Definition at line 100 of file kernel.cpp.

References Coal::Kernel::Arg::Buffer, Coal::DeviceInterface::createDeviceKernel(), Coal::Kernel::DeviceDependent::device, Coal::Kernel::Arg::Double, Coal::Kernel::Arg::Float, function(), Coal::Kernel::DeviceDependent::function, Coal::Kernel::Arg::Global, Coal::Kernel::Arg::Image2D, Coal::Kernel::Arg::Image3D, Coal::Kernel::Arg::Int16, Coal::Kernel::Arg::Int32, Coal::Kernel::Arg::Int64, Coal::Kernel::Arg::Int8, Coal::Kernel::Arg::Invalid, Coal::Kernel::DeviceDependent::kernel, Coal::Kernel::Arg::Local, Coal::Kernel::DeviceDependent::module, p_args, p_device_dependent, p_has_locals, p_name, Coal::Object::p_type, and Coal::Kernel::Arg::Private.

Referenced by Coal::Program::createKernel().

const Kernel::Arg & Kernel::arg ( unsigned int  index) const

Arg at the given index

Definition at line 303 of file kernel.cpp.

References p_args.

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

bool Kernel::argsSpecified ( ) const

true if all the arguments have been set through setArg()

Definition at line 308 of file kernel.cpp.

References p_args.

Referenced by Coal::KernelEvent::KernelEvent().

const Kernel::DeviceDependent & Kernel::deviceDependent ( DeviceInterface device) const [private]
Kernel::DeviceDependent & Kernel::deviceDependent ( DeviceInterface device) [private]

Definition at line 87 of file kernel.cpp.

References Coal::Kernel::DeviceDependent::device, null_dep, and p_device_dependent.

DeviceKernel * Kernel::deviceDependentKernel ( DeviceInterface device) const

Coal::DeviceKernel for the specified device

Definition at line 324 of file kernel.cpp.

References deviceDependent(), and Coal::Kernel::DeviceDependent::kernel.

Referenced by Coal::KernelEvent::KernelEvent().

llvm::Function * Kernel::function ( DeviceInterface device) const

Get the LLVM function for a specified device.

Parameters:
devicethe device for which a LLVM function is needed
Returns:
the LLVM function for the given device

Definition at line 226 of file kernel.cpp.

References deviceDependent(), and Coal::Kernel::DeviceDependent::function.

Referenced by addFunction().

bool Kernel::hasLocals ( ) const

true if one or more argument is in file Arg::Local

Definition at line 319 of file kernel.cpp.

References p_has_locals.

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

cl_int Kernel::info ( cl_kernel_info  param_name,
size_t  param_value_size,
void *  param_value,
size_t *  param_value_size_ret 
) const

Get information about this kernel.

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.

Definition at line 331 of file kernel.cpp.

References MEM_ASSIGN, p_args, p_name, Coal::Object::parent(), Coal::Object::references(), and SIMPLE_ASSIGN.

Referenced by Coal::KernelEvent::KernelEvent().

unsigned int Kernel::numArgs ( ) const

Number of arguments of this kernel.

Definition at line 298 of file kernel.cpp.

References p_args.

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

cl_int Kernel::setArg ( cl_uint  index,
size_t  size,
const void *  value 
)

Set the value of an argument.

See the constructor's documentation for a note on the Coal::Sampler objects

Parameters:
indexindex of the argument
sizesize of the value being stored in the argument, must match Arg::valueSize() * Arg::vecDim()
valuepointer to the data that will be copied in the argument
Returns:
CL_SUCCESS if success, an error code otherwise

Definition at line 233 of file kernel.cpp.

References Coal::Kernel::Arg::alloc(), arg(), Coal::Kernel::Arg::Buffer, Coal::Kernel::Arg::file(), Coal::Kernel::Arg::Image2D, Coal::Kernel::Arg::Image3D, Coal::Object::isA(), Coal::Kernel::Arg::kind(), Coal::Kernel::Arg::loadData(), Coal::Kernel::Arg::Local, p_args, Coal::Kernel::Arg::refineKind(), Coal::Kernel::Arg::Sampler, Coal::Kernel::Arg::setAllocAtKernelRuntime(), Coal::Object::T_Sampler, and Coal::Kernel::Arg::valueSize().

cl_int Kernel::workGroupInfo ( DeviceInterface device,
cl_kernel_work_group_info  param_name,
size_t  param_value_size,
void *  param_value,
size_t *  param_value_size_ret 
) const

Get performance hints and device-specific data about this kernel.

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.
Parameters:
deviceCoal::DeviceInterface on which the kernel will be run

Definition at line 383 of file kernel.cpp.

References deviceDependent(), Coal::Kernel::DeviceDependent::kernel, Coal::DeviceKernel::localMemSize(), Coal::DeviceKernel::preferredWorkGroupSizeMultiple(), Coal::DeviceKernel::privateMemSize(), SIMPLE_ASSIGN, and Coal::DeviceKernel::workGroupSize().


Member Data Documentation

Definition at line 295 of file kernel.h.

Referenced by deviceDependent(), and Kernel().

std::vector<Arg> Coal::Kernel::p_args [private]

Definition at line 294 of file kernel.h.

Referenced by addFunction(), arg(), argsSpecified(), info(), numArgs(), and setArg().

Definition at line 293 of file kernel.h.

Referenced by addFunction(), deviceDependent(), and ~Kernel().

Definition at line 283 of file kernel.h.

Referenced by addFunction(), and hasLocals().

std::string Coal::Kernel::p_name [private]

Definition at line 282 of file kernel.h.

Referenced by addFunction(), and info().


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