Drmike
February 25, 2010, 4:38pm
1
I’d like to build a list of subroutines of the form
[codebox]
device psi_000(…)
device psi_001(…)
:
:
__device__psi_968(…)
[/codebox]
and have different threads call specific subroutines based on their block number and thread ID. In C I’d just do this:
[codebox]double (*function_table[969])(double, double, double)={NULL};
void Init_function_table()
{
function_table[0] = &psi_000;
function_table[1] = &psi_001;
function_table[2] = &psi_002;
:
:
function_table[968] = &psi_968;
}
[/codebox]
How do I do the same thing with a kernel? Can nvcc build the list of addresses so I can put it in either global or constant memory before invoking the kernel?
Thanks for any ideas.
RoBiK
February 25, 2010, 5:01pm
2
I’d like to build a list of subroutines of the form
[codebox]
device psi_000(…)
device psi_001(…)
:
:
__device__psi_968(…)
[/codebox]
and have different threads call specific subroutines based on their block number and thread ID. In C I’d just do this:
[codebox]double (*function_table[969])(double, double, double)={NULL};
void Init_function_table()
{
function_table[0] = &psi_000;
function_table[1] = &psi_001;
function_table[2] = &psi_002;
:
:
function_table[968] = &psi_968;
}
[/codebox]
How do I do the same thing with a kernel? Can nvcc build the list of addresses so I can put it in either global or constant memory before invoking the kernel?
Thanks for any ideas.
that’s not possible. there is no way of calling a function in the current PTX ISA, all the device functions get inlined during compilation anyway… the only thing you can do is to use a switch statement to execute different functions based on index.
Drmike
February 25, 2010, 5:20pm
3
OK, glad I asked!
I will have to think about alternative ways to skin this cat.