Hi I’ve done some experiments with mapped memory.
First I wated to map POSIX shared memory into CUDA mapped memory.
cudaHostAlloc((void**)&hostArray, size, cudaHostAllocMapped);
cudaHostGetDevicePointer((void**)&devArray, (void*)hostArray, 0);
int shm = shm_open(“SharedMem”, 0_RDWR | 0_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if(-1 != shrm)
{
if(-1 != ftruncate(shmPtr, arraySize * sizeof(int)))
{
int shmPtr = (int)mmap(hostArray, size, PROT_READ | PROT_WRITE, MAP_FIXED, shm, 0);
//run kernel
//do other operations with differen processes
}
}
Then I wanted to map files instead of shared memory.
int file = open(“/home/…”, R_OK);
if (file != -1)
{
struct stat status;
if(fstat(file, &status))
{
cudaHostAlloc((void**)&hostArray, status.st_size, cudaHostAllocMapped);
cudaHostGetDevicePointer((void**)&devArray, (void*)hostArray, 0);
char *ptr=(char*)mmap(hostArray, status.st_size, PROT_READ, MAP_FIXED, file, 0);
//run kernel
//do other operations with differen processes
}
}
Does anybody kow why this does’t run correctly?
Has aybody a idea, how I can do this?