4

How do i define functions in OpenCL? I tried to build one program for each function. And it didn't worked.

float AddVectors(float a, float b)
{
    return a + b;
}

kernel void VectorAdd(
    global read_only float* a,
    global read_only float* b,
    global write_only float* c )
{
    int index = get_global_id(0);
    //c[index] = a[index] + b[index];
    c[index] = AddVectors(a[index], b[index]);
}
Kayhano
  • 457
  • 5
  • 11

1 Answers1

4

You don't need to create one program for each function, instead you create a program for a set of functions that are marked with __kernel (or kernel) and potentially auxiliary functions (like your AddVectors function) using for example clCreateProgramWithSource call.

Check out basic tutorials from Apple, AMD, NVIDIA..

elmattic
  • 12,046
  • 5
  • 43
  • 79
  • I just tested this. Did not receive any errors so It may be working. Also just found out that clBuildProgram is not threadsafe. So we are putting all programs in a single cl file for a reason. – huseyin tugrul buyukisik Jan 23 '14 at 14:17