-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory_controller.hpp
More file actions
52 lines (41 loc) · 905 Bytes
/
memory_controller.hpp
File metadata and controls
52 lines (41 loc) · 905 Bytes
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
#ifndef MEMORY_CONTROLLER_HPP
#define MEMORY_CONTROLLER_HPP
#include <stdio.h>
#include <memory>
#include <glog/logging.h>
namespace fool{
inline void fool_memset(void* X, const int value, const size_t size){
memset(X, value, size);
}
// adapt CUDA
inline void FoolMallocHost(void** ptr, size_t size){
#ifndef CPU_ONLY
LOG(ERROR) << "Don't support GPU." ;
return;
#endif
*ptr = malloc(size);
}
inline void FoolFreeHost(void* ptr){
#ifndef CPU_ONLY
return;
#endif
free(ptr);
}
// Allocate memory when needed
class MemoryController{
public:
MemoryController();
explicit MemoryController(size_t size);
~MemoryController();
void to_cpu();
const void* cpu_data();
void set_cpu_data(void* data);
void* mutable_cpu_data();
size_t size() {return m_size;}
enum HandlerType{UNINITIALIZED, AT_CPU};
HandlerType m_handler;
void* m_cpu_ptr;
size_t m_size;
};
}
#endif // MENCONTROLLER_HPP