I've created a bubble sort code. The createProgram function is giving an error which I've attached as a png photo and also attached the host code.
My kernel looks like:
__kernel void sort_kernel(__global const float *a, __global const float *b)
const int n=100;
int gid = get_global_id(0);
for(j=0; j < n-gid; j++)
clbuildprogram is giving an error as per the runtime error. Please tell me what is the error in the user defined function createProgram or in the kernel code and how can I rectify it...?
Yeah, I had rectified b as just "global float" before itself, just forgot to delete it here, but then too I am having the same error. I've also commented the entire for loop, just "b[gid]=a[aid]" remains, even then I get the same error..! So this error might be in building the program itself... how do I rectify it..?
Few tips to help you out:
1. Make sure every OpenCL API you use on the host code spits out the error code in case it fails. Then check the meaning of this error code in cl.h file.
2. It looks your Bubble sort code is written wrongly. Bubble sort as i know is done in steps. In the first step, the largest elements is moved to the last place in the array. In the 2nd step 2nd largest element moves in second last sopt on array. Now these two steps cannot be done in parallel, but you are assigning this work to two work-items for the GPU which will run in parallel. IMHO bubble sort is not easily parallelizeable. Check out some other parallel sorting algorithms like radixsort.
3. Doing b[gid] = a[gid]; inside that kernel anyhow does not make sense. I guess you were just playing around in the kernel though. darkhmz pointed to specific issues in the kernels, so no point repeating them.
4. The png image attached seems to be reporting kernel compilation error, so now you need to find what API is throwing an error for you and what. Check OpenCL 1.2 spec for help on those errors. And you may want to check APP SDK Sample related to sorting.