8. cudaMallocManaged
CPU
CUDA Unified Memory
void sortfile(FILE *fp, int N) {
char *data;
data = (char *)malloc(N);
!
!
!
!
}
fread(data, 1, N, fp);
qsort(data, N, 1, compare);
use_data(data);
free(data);
void sortfile(FILE *fp, int N) {
char *data;
cudaMallocManaged(&data, N);
!
!
!
!
}
fread(data, 1, N, fp);
qsort<<<…>>>(data, N, 1, compare);
cudaDeviceSynchronize();
use_data(data);
cudaFree(data);
cudaMallocManagedで確保されたメモリ領域はホストデバイス両方で使える
New Features in CUDA 6 Make GPU Acceleration Easier