How to define functions in OpenCL?

How to define functions in OpenCL? I tried to create one program for each function. And it didn’t work.

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]); } 
+4
source share
1 answer

You do not 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 (for example, your AddVectors function), using, for example, calling clCreateProgramWithSource .

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

+5
source

All Articles