2011-09-21 3 views

답변

2

예, 다음의 프로그램을 보여줍니다 같이

#include <stdio.h> 

struct my_struct 
{ 
    int x; 
}; 

// foo receives its argument by pointer 
__device__ void foo(my_struct *a) 
{ 
    a->x = 13; 
} 

__global__ void kernel() 
{ 
    my_struct a; 
    a.x = 7; 

    // expect 7 in the printed output 
    printf("a.x before foo: %d\n", a.x); 

    foo(&a); 

    // expect 13 in the printed output 
    printf("a.x after foo: %d\n", a.x); 
} 

int main() 
{ 
    kernel<<<1,1>>>(); 
    cudaThreadSynchronize(); 
    return 0; 
} 

결과 :

$ nvcc -arch=sm_20 test.cu -run 
a.x before foo: 7 
a.x after foo: 13 
1

장치에 메모리를 할당하고 장치 내에서만 사용하는 경우 원하는 장치 기능으로 메모리를 전달할 수 있습니다.

기기의 호스트에서 주소를 사용하거나 호스트의 기기에서 주소를 사용하려는 경우에만 걱정할 필요가 있습니다. 이 경우 먼저 적절한 memcopy를 사용하고 새 장치 또는 호스트 특정 주소를 얻어야합니다.

관련 문제