저는 cudaHostRegister 및 cudaHostUnregister 함수로 작업 해 왔으며 후자가 매우 오래 걸리는 것으로 나타났습니다. 동일한 데이터에서 cudaMemcpy와 cudaHostUnregister를 비교하는 경우에도 memcpy에 페이지 잠금 메모리를 사용하지 않아도 매우 오랜 시간이 걸립니다.CUDA 4.0 - cudaHostUnregister가 느립니다.
나는 다음과 같은 쇼트 프로그램했습니다 :
#include <stdio.h>
#include <time.h>
#include <assert.h>
#include <stdlib.h>
static struct timespec tp;
static clockid_t clk = CLOCK_REALTIME;
static void tu_timer_start(void)
{
int res = clock_gettime(clk, &tp);
assert(!res);
}
static long long tu_timer_stop(void)
{
struct timespec tp_new;
long long elapsed;
int res = clock_gettime(clk, &tp_new);
assert(!res);
elapsed = 1000000000LL * (tp_new.tv_sec - tp.tv_sec) + tp_new.tv_nsec - tp.tv_nsec;
tp = tp_new;
return elapsed;
}
int main() {
const int length = 999424;
const int pagesize = 4096;
// Allocating page-aligned host data and filling it with zeroes.
int *paged, *locked;
posix_memalign((void**) &paged, pagesize, length * sizeof(int));
posix_memalign((void**) &locked, pagesize, length * sizeof(int));
memset(paged, 0, length * sizeof(int));
memset(locked, 0, length * sizeof(int));
// Allocating device data.
int *devPaged, *devLocked;
tu_timer_start();
printf("%20d\n", cudaMalloc(&devPaged, length * sizeof(int)));
printf("%20d\n", cudaMalloc(&devLocked, length * sizeof(int)));
printf("Initialization: %12lld ns\n", tu_timer_stop());
// Measure copy time with pageable data.
tu_timer_start();
printf("%20d\n", cudaMemcpy(devPaged, paged, length * sizeof(int), cudaMemcpyHostToDevice));
printf("Copy pageable: %12lld ns\n", tu_timer_stop());
// Measure time to page-lock host data.
tu_timer_start();
printf("%20d\n", cudaHostRegister(locked, length * sizeof(int), 0));
printf("Host register: %12lld ns\n", tu_timer_stop());
// Measure copy time with page-locked data.
tu_timer_start();
printf("%20d\n", cudaMemcpy(devLocked, locked, length * sizeof(int), cudaMemcpyHostToDevice));
printf("Copy page-locked: %12lld ns\n", tu_timer_stop());
// Measure time to release page-lock on host data.
tu_timer_start();
cudaHostUnregister(locked);
printf("Host unregister: %12lld ns\n", tu_timer_stop());
return 0;
}
이 인텔 I5 760 CUDA 리턴 코드와 테슬라 C2050 (와 (코어 당 2.80 GHz의)이 인쇄되지 쿼드 코어에 다음과 같은 출력을 제공을 여기) :
Initialization: 81027005 ns
Copy pageable: 1263236 ns
Host register: 436132 ns
Copy page-locked: 706051 ns
Host unregister: 2139736 ns
이것은 내 문제를 보여줍니다. 내 실제 프로그램에서 그것은 더 나쁘다. 나는 종종 cudaHostUnregister를 약 3460000 ns 측정한다. 이것은 천천히 진행되는 것 외에 동시 비동기식 memcopies 또는 커널 실행에서 잘 작동하지 않는다는 것을 암시합니다.
왜이 기능이 오래 걸리고 속도를 높이는 방법이 있습니까? 그리고 실제로 memcopies와 커널과 병렬로 작동하지 않습니까? 그렇다면 왜 그렇게하지 않습니까?
아니면 단순히 memcopies와 커널을 병렬 처리하는 더 좋은 방법이 있습니까?
http://forums.nvidia.com/index.php?showtopic=210296에서 교차 게시 됨. –