![]() |
Mali OpenCL SDK v1.1.0
|
A skeleton file that can be used as a starting point for OpenCL development.
Check-list for an OpenCL application:
template.cpp uses the common.cpp library to set up the environment.
Create a context
Create an OpenCL context on the first available platform:
Create a command-queue
Create a command-queue to queue operations on the device:
Create a program
Create an OpenCL program from a given file and compile it:
Create a kernel
Create a kernel object for the kernel function template():
Create memory buffers
Request memory buffers for any data that you need to access from the device. For more information have a look at the Hello World.
Initialise the input data
If you need to initialise the data from the CPU side, then you need to:
For more information have a look at the Hello World tutorial.
Set up kernel arguments
Pass the memory buffers and/or other variables to the kernel as arguments.
For more information have a look at the Hello World tutorial.
Define the number of kernel instances
The globalWorkSize
determines how many kernel instances are run.
For another example have a look at the Hello World tutorial or any of the other tutorials.
Enqueue the kernel
Enqueue the kernel for execution. To retrieve profiling information, we define a cl_event
and pass it to clEnqueueNDRangeKernel()
.
Wait for kernel execution
Wait until all the kernel instances have finished executing:
Note: This may not be required depending on the application.
Print profiling information
Print the profiling information for the event (queueing, waiting and running time):
Retrieve results
To access the results from the CPU side, you need to:
For more information have a look at the Hello World tutorial.
Release OpenCL objects
Release any OpenCL objects that have been created.
This sample does nothing apart from printing profiling information.
From a command prompt in the root of the SDK, run:
This compiles the template sample code and copies all the files it needs to run to the bin folder in the root directory of the SDK.
Navigate to the folder on the board and run the template binary:
You should see output similar to:
Find solutions for Common Issues.
For more information have a look at the code in template.cpp and template.cl.