-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgpm-helper.cuh
65 lines (60 loc) · 1.73 KB
/
gpm-helper.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef PMEM_HELPER
#define PMEM_HELPER
#include "libpmem.h"
#include <fstream>
#include <stdio.h>
#include <thread>
#define checkForCudaErrors(ans) { gpuAsserter((ans), __FILE__, __LINE__); }
inline void gpuAsserter(cudaError_t code, const char *file, int line, bool abort=true)
{
if (code != cudaSuccess)
{
fprintf(stderr,"GPUassert %d: %s %s %d\n", code, cudaGetErrorString(code), file, line);
if (abort) exit(code);
}
}
enum PMEM_FLAGS {
PMEM_NO_FUNCTIONAL = 1,
};
static cudaError_t create_gpm_file(const char *path, void **var, size_t size)
{
int is_pmem;
// Create a pmem file and memory map it
if ((*var = pmem_map_file(path, size,
PMEM_FILE_CREATE, 0666, &size, &is_pmem)) == NULL) {
perror("pmem_map_file");
exit(1);
}
#ifdef DEBUG
printf("Created pmem (%d) file at %s of size %ld\n", is_pmem, path, size);
#endif
// Map to GPU address space
return cudaHostRegister(*var, size, 0);
}
static cudaError_t open_gpm_file(const char *path, void **var, size_t &size)
{
int is_pmem;
// Open a pmem file and memory map it
if ((*var = pmem_map_file(path, size,
0, 0666, &size, &is_pmem)) == NULL) {
perror("pmem_map_file");
exit(1);
}
#ifdef DEBUG
printf("Opened pmem (%d) file at %s of size %ld\n", is_pmem, path, size);
#endif
// Map to GPU address space
return cudaHostRegister(*var, size, 0);
}
static cudaError_t close_gpm_file(void *var, size_t size)
{
cudaError_t err = cudaHostUnregister(var);
pmem_persist(var, size);
if(pmem_unmap(var, size)) {
printf("Error unmapping during file close (%s)\n", pmem_errormsg());
exit(1);
}
// Map to GPU address space
return err;
}
#endif