cancel
Showing results for 
Search instead for 
Did you mean: 

OpenCL

notooth
Journeyman III
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 Kudos
Reply
4 Replies
LeeHowes
Staff
Staff

Re: Convert string to function name

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
Grandmaster

Re: Convert string to function name

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 Kudos
Reply
notooth
Journeyman III
Journeyman III

Re: Convert string to function name

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

0 Kudos
Reply
himanshu_gautam
Grandmaster
Grandmaster

Re: Convert string to function name

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