nnlib
GPU-accelerated, C/C++ neural network library.
cache.h
Go to the documentation of this file.
1 
10 #ifndef NNLIB_CACHE_H
11 #define NNLIB_CACHE_H
12 
13 #include <cstdlib>
14 #include <stack>
15 #include <unordered_map>
16 
24 enum DataLocation { HOST, DEVICE };
25 
26 
27 class Cache {
28 private:
29  std::unordered_map<size_t, std::stack<float*>> hostCache;
30  std::unordered_map<size_t, std::stack<float*>> deviceCache;
31 
32  Cache();
33 
34 public:
35  static Cache& getInstance() {
36  static Cache instance;
37  return instance;
38  }
39 
40  float* get(size_t size, DataLocation location);
41 
42  void put(size_t size, float* ptr, DataLocation location);
43 
44  ~Cache();
45 
46  Cache(Cache const&) = delete;
47  void operator=(Cache const&) = delete;
48 };
49 
50 
51 #endif //NNLIB_CACHE_H
DataLocation
Enumerate to specify where data is located.
Definition: cache.h:24
Definition: cache.h:27