Brick Library 0.1
Performance-portable stencil datalayout & codegen
memfd.h
Go to the documentation of this file.
1
6#ifndef BRICK_MEMFD_H
7#define BRICK_MEMFD_H
8
9#include <iostream>
10#include <vector>
11#include <initializer_list>
12#include <set>
13#include <sys/mman.h>
14#include <stdio.h>
15#include <string.h>
16#include <errno.h>
17#include <unistd.h>
18
19class MEMFD {
20private:
21 size_t len;
22 int ring_fd;
23 long pagesize;
24 size_t offset;
25#ifndef USE_MEMFD
26 static std::string shm_prefix;
27 static int shm_cnt;
28 std::string shm_name;
29#endif
30public:
31 static uint8_t *mmap_end;
32 static std::set<void *> allocated;
33
34 static void setup_prefix(const std::string &prefix, int rank);
35
36 static void free(void *ptr, size_t length);
37
38 MEMFD(MEMFD* memfd): len(memfd->len), ring_fd(memfd->ring_fd), pagesize(memfd->pagesize), offset(0) {
39#ifndef USE_MEMFD
40 shm_name = memfd->shm_name;
41#endif
42 }
43
44 MEMFD(size_t length);
45
46 void *map_pointer(void *hint, size_t pos, size_t len);
47
48 void *packed_pointer(const std::vector<size_t> &packed);
49
50 void *packed_pointer(const std::initializer_list<size_t> &packed_init) {
51 std::vector<size_t> packed = packed_init;
52 return packed_pointer(packed);
53 }
54
55 MEMFD *duplicate(size_t offset);
56
57 void cleanup();
58};
59
60// TODO Record and free pointers
61
62#endif //BRICK_MEMFD_H
Definition: memfd.h:19
static void setup_prefix(const std::string &prefix, int rank)
Definition: memfd.cpp:18
void * map_pointer(void *hint, size_t pos, size_t len)
Definition: memfd.cpp:53
static uint8_t * mmap_end
Definition: memfd.h:31
static void free(void *ptr, size_t length)
Definition: memfd.cpp:24
void * packed_pointer(const std::initializer_list< size_t > &packed_init)
Definition: memfd.h:50
MEMFD * duplicate(size_t offset)
Definition: memfd.cpp:97
void * packed_pointer(const std::vector< size_t > &packed)
Definition: memfd.cpp:66
MEMFD(MEMFD *memfd)
Definition: memfd.h:38
static std::set< void * > allocated
Definition: memfd.h:32
void cleanup()
Definition: memfd.cpp:46