난 다음 호스트 코드 디바이스 버전이 필요) __global__ 커널.장치 기능 포인터
은 내가 NVIDIA 지포스 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 : 잘못되었습니다 - 함수 포인터가 Fermi에서 지원됩니다 – talonmies
CUDA SDK에 포함 된 함수 포인터 샘플이 있습니다.이 질문은 [이 게시물의 CUDA 개발자 포럼에서 매우 유사합니다 ] (http://forums.nvidia.com/index.php?showtopic=156792&view=findpost&p=1201985). – talonmies