I am trying to create a mapped memory file, containing uint32_t
s, and then use that as zero-copy pinned memory as shown below for CUDA. I am getting the cudaErrorInvalidValue
when getting the device pointer, having allocated space and mapped the memory from file. I know the error message (from the API) means :
This indicates that one or more of the parameters passed to the API call is not within an acceptable range of values.
But I'm struggling to figure out why I'm having this problem.... Any ideas? Thanks in advance.
#include <stdio.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
…
int main(void)
{
struct stat buf;
…
uint32_t *data, *dev_data;
cudaDeviceProp cuda_prop;
cudaGetDeviceProperties(&cuda_prop, 0);
if (!cuda_prop.canMapHostMemory)
exit(EXIT_FAILURE);
cudaSetDeviceFlags(cudaDeviceMapHost);
int data_file = open(data_file_name, O_RDONLY);
int stat = fstat(sa_file, &buf);
int data_file_size = buf.st_size;
err = cudaHostAlloc((void**)&data, data_file_size, cudaHostAllocMapped);
if (err == cudaErrorMemoryAllocation) exit(EXIT_FAILURE);
data = (uint32_t*) mmap(0, data_file_size, PROT_READ, MAP_PRIVATE, data_file, 0);
err = cudaHostGetDevicePointer((void**)&dev_data, (void*)data, 0);
if (err == cudaErrorMemoryAllocation)
{
printf("cudaHostGetDevicePointer - Mem Alloc Err\n");
exit(EXIT_FAILURE);
}
else if (err == cudaErrorInvalidValue) //ERROR HERE.
{
printf("cudaHostGetDevicePointer - Invalid Val Err\n");
exit(EXIT_FAILURE);
}
…
}