As mentioned in previous example, the calculation in OpenCL is performed by executing functions named kernels in OpenCL.
We also learned that kernels are collected in a program (OpenCL name for library of functions), typically stored as separate CL file.
Before we jump on the execution of kernels, we will have a look at one useful feature - detecting kernel names in a program.
In my older OpenCL examples, I did this by parsing CL file using ThinBASIC string functions, but there is more automatic way directly in OpenCL.
After building the program, you can use clGetKernelInfo to retrieve various kinds of information about each kernel, including the name.
The attached example examines this simple file:
__kernel void add(__global float *a,
__global float *b,
__global float *c) {
*c = *a + *b;
}
__kernel void sub(__global float *a,
__global float *b,
__global float *c) {
*c = *a - *b;
}
__kernel void mult(__global float *a,
__global float *b,
__global float *c) {
*c = *a * *b;
}
__kernel void div(__global float *a,
__global float *b,
__global float *c) {
*c = *a / *b;
}
You will need the latest ThinBASIC and OpenCL headers to run it + of course modern GPU or CPU.
Bookmarks