Mali OpenCL SDK v1.1.0
 All Classes Files Functions Variables Macros Pages
common.h File Reference

Functions to simplify the use of OpenCL API. More...

#include <CL/cl.h>
#include <string>

Go to the source code of this file.

Functions

bool printProfilingInfo (cl_event event)
 Print the profiling information associated with an OpenCL event.
 
bool printSupported2DImageFormats (cl_context context)
 Print a list of the 2D OpenCL image formats supported.
 
std::string imageChannelOrderToString (cl_channel_order channelOrder)
 Convert cl_channel_order values into their string form.
 
std::string imageChannelDataTypeToString (cl_channel_type channelDataType)
 Convert cl_channel_type values into their string form.
 
bool cleanUpOpenCL (cl_context context, cl_command_queue commandQueue, cl_program program, cl_kernel kernel, cl_mem *memoryObjects, int numberOfMemoryObjects)
 Release any OpenCL objects that have been created.
 
bool createContext (cl_context *context)
 Create an OpenCL context on a GPU on the first available platform.
 
bool createCommandQueue (cl_context context, cl_command_queue *commandQueue, cl_device_id *device)
 Create an OpenCL command queue for a given context.
 
bool createProgram (cl_context context, cl_device_id device, std::string filename, cl_program *program)
 Create an OpenCL program from a given file and compile it.
 
std::string errorNumberToString (cl_int errorNumber)
 Convert OpenCL error numbers to their string form.
 
bool checkSuccess (cl_int errorNumber)
 Check an OpenCL error number for errors.
 
bool isExtensionSupported (cl_device_id device, std::string extension)
 Query an OpenCL device to see if it supports an extension.
 

Detailed Description

Functions to simplify the use of OpenCL API.

Definition in file common.h.

Function Documentation

bool checkSuccess ( cl_int  errorNumber)
inline

Check an OpenCL error number for errors.

If errorNumber is not CL_SUCESS, the function will print the string form of the error number.

Parameters
[in]errorNumberThe error number returned from an OpenCL command.
Returns
False if errorNumber != CL_SUCCESS, true otherwise.

Definition at line 358 of file common.cpp.

bool cleanUpOpenCL ( cl_context  context,
cl_command_queue  commandQueue,
cl_program  program,
cl_kernel  kernel,
cl_mem *  memoryObjects,
int  numberOfMemoryObjects 
)

Release any OpenCL objects that have been created.

If any of the OpenCL objects passed in are not NULL, they will be freed using the appropriate OpenCL function.

Returns
False if an error occurred, otherwise true.

Definition at line 170 of file common.cpp.

bool createCommandQueue ( cl_context  context,
cl_command_queue *  commandQueue,
cl_device_id *  device 
)

Create an OpenCL command queue for a given context.

Parameters
[in]contextThe OpenCL context to use.
[out]commandQueueThe created OpenCL command queue.
[out]deviceThe device in which the command queue is created.
Returns
False if an error occurred, otherwise true.

Definition at line 255 of file common.cpp.

bool createContext ( cl_context *  context)

Create an OpenCL context on a GPU on the first available platform.

Parameters
[out]contextPointer to the created OpenCL context.
Returns
False if an error occurred, otherwise true.

Definition at line 224 of file common.cpp.

bool createProgram ( cl_context  context,
cl_device_id  device,
std::string  filename,
cl_program *  program 
)

Create an OpenCL program from a given file and compile it.

Parameters
[in]contextThe OpenCL context in use.
[in]deviceThe OpenCL device to compile the kernel for.
[in]filenameName of the file containing the OpenCL kernel code to load.
[out]programThe created OpenCL program object.
Returns
False if an error occurred, otherwise true.
std::string errorNumberToString ( cl_int  errorNumber)

Convert OpenCL error numbers to their string form.

Uses the error number definitions from cl.h.

Parameters
[in]errorNumberThe error number returned from an OpenCL command.
Returns
A name of the error.

Definition at line 368 of file common.cpp.

std::string imageChannelDataTypeToString ( cl_channel_type  channelDataType)

Convert cl_channel_type values into their string form.

Uses the channel data type definitions from cl.h.

Parameters
[in]channelDataTypeThe channel data type value to convert.
Returns
The string form of the channel data type.

Definition at line 131 of file common.cpp.

std::string imageChannelOrderToString ( cl_channel_order  channelOrder)

Convert cl_channel_order values into their string form.

Uses the channel order definitions from cl.h.

Parameters
[in]channelOrderThe channel order value to convert.
Returns
The string form of the channel order.

Definition at line 96 of file common.cpp.

bool isExtensionSupported ( cl_device_id  device,
std::string  extension 
)

Query an OpenCL device to see if it supports an extension.

Parameters
[in]deviceThe device to query.
[in]extensionThe string name of the extension to query for.
Returns
True if the extension is supported on the given device, false otherwise.
bool printProfilingInfo ( cl_event  event)

Print the profiling information associated with an OpenCL event.

Prints the time spent in the command queue, the time spent waiting before being submitted to a device, and the execution time.

Parameters
[in]eventThe event to get profiling information for.
Returns
False if an error occurred, otherwise true.

Definition at line 18 of file common.cpp.

bool printSupported2DImageFormats ( cl_context  context)

Print a list of the 2D OpenCL image formats supported.

Parameters
[in]contextThe OpenCL context to use.
Returns
False if an error occurred, otherwise true.

Definition at line 57 of file common.cpp.