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

Coal::Program Class Reference

Program object. More...

#include <program.h>

Inheritance diagram for Coal::Program:
Collaboration diagram for Coal::Program:

List of all members.

Classes

struct  DeviceDependent

Public Types

enum  Type { Invalid, Source, Binary }
 

Program type.

More...
enum  State { Empty, Loaded, Built, Failed }
 

Program state.

More...

Public Member Functions

 Program (Context *ctx)
 Constructor.
 ~Program ()
cl_int loadSources (cl_uint count, const char **strings, const size_t *lengths)
 Load sources into the program.
cl_int loadBinaries (const unsigned char **data, const size_t *lengths, cl_int *binary_status, cl_uint num_devices, DeviceInterface *const *device_list)
 Load binaries into the program.
cl_int build (const char *options, void(CL_CALLBACK *pfn_notify)(cl_program program, void *user_data), void *user_data, cl_uint num_devices, DeviceInterface *const *device_list)
 Build the program.
Type type () const
 Type of the program.
State state () const
 State of the program.
KernelcreateKernel (const std::string &name, cl_int *errcode_ret)
 Create a kernel given a name.
std::vector< Kernel * > createKernels (cl_int *errcode_ret)
 Create all the kernels of the program.
DeviceProgramdeviceDependentProgram (DeviceInterface *device) const
 Device-specific program.
cl_int info (cl_program_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) const
 Get information about this program.
cl_int buildInfo (DeviceInterface *device, cl_program_build_info param_name, size_t param_value_size, void *param_value, size_t *param_value_size_ret) const
 Get build info about this program (log, binaries, etc)

Private Member Functions

void setDevices (cl_uint num_devices, DeviceInterface *const *devices)
DeviceDependentdeviceDependent (DeviceInterface *device)
const DeviceDependentdeviceDependent (DeviceInterface *device) const
std::vector< llvm::Function * > kernelFunctions (DeviceDependent &dep)

Private Attributes

Type p_type
State p_state
std::string p_source
std::vector< DeviceDependentp_device_dependent
DeviceDependent p_null_device_dependent

Detailed Description

Program object.

This class compiles and links a source or binaries into LLVM modules for each Coal::DeviceInterface for which the program is built.

It then contains functions to get the list of kernels available in the program, using Coal::Kernel objects.

Definition at line 67 of file program.h.


Member Enumeration Documentation

Program state.

Enumerator:
Empty 

Just created

Loaded 

Source or binary loaded

Built 

Built

Failed 

Build failed

Definition at line 90 of file program.h.

Program type.

Enumerator:
Invalid 

Invalid or unknown, type of a program not already loaded

Source 

Program made of sources that must be compiled and linked

Binary 

Program made of pre-built binaries that only need to be linked

Reimplemented from Coal::Object.

Definition at line 80 of file program.h.


Constructor & Destructor Documentation

Program::Program ( Context ctx)
Program::~Program ( )

Member Function Documentation

cl_int Program::build ( const char *  options,
void(CL_CALLBACK *pfn_notify)(cl_program program,void *user_data)  ,
void *  user_data,
cl_uint  num_devices,
DeviceInterface *const *  device_list 
)

Build the program.

This function compiles the sources, if any, and then link the resulting binaries if the devices for which they are compiled asks Coal::Program to do so, using Coal::DeviceProgram::linkStdLib().

Parameters:
optionsoptions to pass to the compiler, see the OpenCL specification.
pfn_notifycallback function called at the end of the build
user_datauser data given to pfn_notify
num_devicesnumber of devices for which binaries are being built. If it's a source-based program, this can be 0.
device_listlist of devices for which the program will be built.
Returns:
CL_SUCCESS if success, an error code otherwise

Definition at line 317 of file program.cpp.

References Coal::Compiler::appendLog(), Coal::DeviceProgram::build(), Built, Coal::Compiler::compile(), Coal::Program::DeviceDependent::compiler, Coal::DeviceProgram::createOptimizationPasses(), deviceDependent(), Failed, kernelFunctions(), Coal::Program::DeviceDependent::linked_module, Coal::DeviceProgram::linkStdLib(), Coal::Compiler::log(), Coal::Compiler::module(), Coal::Compiler::optimize(), p_device_dependent, p_source, p_state, p_type, Coal::Program::DeviceDependent::program, setDevices(), Source, and Coal::Program::DeviceDependent::unlinked_binary.

cl_int Program::buildInfo ( DeviceInterface device,
cl_program_build_info  param_name,
size_t  param_value_size,
void *  param_value,
size_t *  param_value_size_ret 
) const

Get build info about this program (log, binaries, etc)

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 for which info is needed

Definition at line 564 of file program.cpp.

References Built, Coal::Program::DeviceDependent::compiler, deviceDependent(), Empty, Failed, Loaded, Coal::Compiler::log(), Coal::Compiler::options(), p_state, and SIMPLE_ASSIGN.

Kernel * Program::createKernel ( const std::string &  name,
cl_int *  errcode_ret 
)

Create a kernel given a name.

Parameters:
namename of the kernel to be created
errcode_retreturn code (CL_SUCCESS if success)
Returns:
a Coal::Kernel object corresponding to the given name

Definition at line 166 of file program.cpp.

References Coal::Kernel::addFunction(), Coal::Program::DeviceDependent::device, kernelFunctions(), Coal::Program::DeviceDependent::linked_module, and p_device_dependent.

Referenced by createKernels().

std::vector< Kernel * > Program::createKernels ( cl_int *  errcode_ret)

Create all the kernels of the program.

Parameters:
errcode_retreturn code (CL_SUCCESS if success)
Returns:
the list of Coal::Kernel objects of this program

Definition at line 205 of file program.cpp.

References createKernel(), kernelFunctions(), and p_device_dependent.

Program::DeviceDependent & Program::deviceDependent ( DeviceInterface device) [private]
const Program::DeviceDependent & Program::deviceDependent ( DeviceInterface device) const [private]
DeviceProgram * Program::deviceDependentProgram ( DeviceInterface device) const

Device-specific program.

Parameters:
devicedevice for which the device-specific program is needed
Returns:
the device-specific program requested, 0 if not found

Definition at line 133 of file program.cpp.

References deviceDependent(), and Coal::Program::DeviceDependent::program.

Referenced by Coal::CPUDevice::initEventDeviceData(), and Coal::CPUKernelWorkGroup::run().

cl_int Program::info ( cl_program_info  param_name,
size_t  param_value_size,
void *  param_value,
size_t *  param_value_size_ret 
) const

Get information about this program.

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 461 of file program.cpp.

References Coal::Program::DeviceDependent::device, MEM_ASSIGN, p_device_dependent, p_source, Coal::Object::parent(), Coal::Object::references(), SIMPLE_ASSIGN, and Coal::Program::DeviceDependent::unlinked_binary.

std::vector< llvm::Function * > Program::kernelFunctions ( DeviceDependent dep) [private]

Definition at line 140 of file program.cpp.

References Coal::Program::DeviceDependent::linked_module.

Referenced by build(), createKernel(), and createKernels().

cl_int Program::loadBinaries ( const unsigned char **  data,
const size_t *  lengths,
cl_int *  binary_status,
cl_uint  num_devices,
DeviceInterface *const *  device_list 
)

Load binaries into the program.

This function allows client application to load a source, retrieve binaries using buildInfo(), and then re-create the same program (after a restart for example) by giving it a precompiled binary.

This function loads the binaries for each device and parse them into LLVM modules, then sets the program type to Binary.

Parameters:
dataarray of pointers to binaries, one for each device
lengthslengths of the binaries pointed to by data
binary_statusarray that will be filled by this function with the status of each loaded binary (CL_SUCCESS if success)
num_devicesnumber of devices for which a binary is loaded
device_listlist of devices for which the binaries are loaded
Returns:
CL_SUCCESS if success, an error code otherwise

Definition at line 274 of file program.cpp.

References Binary, deviceDependent(), Coal::Program::DeviceDependent::linked_module, Loaded, p_state, p_type, setDevices(), and Coal::Program::DeviceDependent::unlinked_binary.

Referenced by clCreateProgramWithBinary().

cl_int Program::loadSources ( cl_uint  count,
const char **  strings,
const size_t *  lengths 
)

Load sources into the program.

This function loads the source-code given in strings into the program and sets its type to Source.

Parameters:
countnumber of strings in strings
stringsarray of pointers to strings, either null-terminated or of length given in lengths
lengthslengths of the strings. If a field is 0, the corresponding string is null-terminated. If lengths is 0, all the strings are null-terminated
Returns:
CL_SUCCESS if success, an error code otherwise

Definition at line 238 of file program.cpp.

References Loaded, p_source, p_state, p_type, and Source.

Referenced by clCreateProgramWithSource().

void Program::setDevices ( cl_uint  num_devices,
DeviceInterface *const *  devices 
) [private]
Program::State Program::state ( ) const

State of the program.

Definition at line 456 of file program.cpp.

References p_state.

Program::Type Program::type ( ) const

Type of the program.

Reimplemented from Coal::Object.

Definition at line 451 of file program.cpp.

References p_type.


Member Data Documentation

Definition at line 218 of file program.h.

Referenced by build(), createKernel(), createKernels(), deviceDependent(), info(), setDevices(), and ~Program().

Definition at line 219 of file program.h.

Referenced by deviceDependent(), and Program().

std::string Coal::Program::p_source [private]

Definition at line 207 of file program.h.

Referenced by build(), info(), and loadSources().

Definition at line 206 of file program.h.

Referenced by build(), buildInfo(), loadBinaries(), loadSources(), and state().

Reimplemented from Coal::Object.

Definition at line 205 of file program.h.

Referenced by build(), loadBinaries(), loadSources(), and type().


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