मैं निम्नलिखित मेजबान कोड का एक डिवाइस संस्करण की आवश्यकता) __global__ कर्नेल।डिवाइस समारोह संकेत
मैं एक NVIDIA GeForce GTS 450 (गणना क्षमता 2.1) अग्रिम में धन्यवाद मिशेल
======================= है =================================
एक काम कर समाधान
#define REAL double
typedef REAL (*func)(REAL x);
__host__ __device__ REAL func1(REAL x)
{
return x+1.0f;
}
__host__ __device__ REAL func2(REAL x)
{
return x+2.0f;
}
__host__ __device__ REAL func3(REAL x)
{
return x+3.0f;
}
__device__ func func_list_d[3];
func func_list_h[3];
__global__ void assign_kernel(void)
{
func_list_d[0]=func1;
func_list_d[1]=func2;
func_list_d[2]=func3;
}
void assign(void)
{
func_list_h[0]=func1;
func_list_h[1]=func2;
func_list_h[2]=func3;
}
__global__ void test_kernel(void)
{
REAL x;
for(int i=0;i<3;++i){
x=func_list_d[i](2.0);
printf("%g\n",x);
}
}
void test(void)
{
REAL x;
printf("=============\n");
for(int i=0;i<3;++i){
x=func_list_h[i](2.0);
printf("%g\n",x);
}
}
int main(void)
{
assign_kernel<<<1,1>>>();
test_kernel<<<1,1>>>();
cudaThreadSynchronize();
assign();
test();
return 0;
}
फ़ंक्शंस पॉइंटर्स डिवाइस कोड में असमर्थित हैं। – Yappie
@Yappie: यह गलत है - फ़ंक्शन पॉइंटर्स फर्मि – talonmies
पर समर्थित हैं, एक फ़ंक्शन पॉइंटर नमूना है जो CUDA SDK में जहाजों को भेजता है, और आप एक उदाहरण देख सकते हैं जो आपके प्रश्न के समान है [इस पोस्ट में CUDA डेवलपर फ़ोरम पर ] (http://forums.nvidia.com/index.php?showtopic=156792&view=findpost&p=1201985)। – talonmies