cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

notooth
Journeyman III

Convert string to function name

Hello,

I have the code:

  char* string = "monday";

How can I execute the monday function without using if, case branching?

0 Likes
4 Replies
LeeHowes
Staff

Using if-case branching. Even if OpenCL C were a high-level language with string-based dispatch, the runtime would only end up doing that anyway. OpenCL C is slightly more limited even than C in this because the functions have to be able to be inlined, so even computed branches and a function pointer table doesn't really work.

himanshu_gautam
Grandmaster

Are you looking to launch an OpenCL Kernel with the name "monday" from host ?

OR

Are you looking to call an OpenCL Function with the name "monday" from within an OpenCL kernel?

0 Likes

I am looking to an OpenCL function call within an OpenCL kernel. But an OpenCL kernel execution from host is also appreciated.

0 Likes

For OpenCl function calls from inside an OpenCL kernel, As Lee indicated, you need to go with "if-else".

If outside, you can create an appropriate cl_kernel object using "clCreateKernel" and pass the cl_kernel as the argument to clEnqueueNDRange API