11 #include <unordered_map>
16 namespace groupallocator {
18 static std::mutex groupMapMutex;
19 static std::unordered_map<int, std::shared_ptr<GroupAllocator>> allocator;
48 void allocate(T **ptr,
size_t s,
const Context ctx,
int group = -1,
bool forceAligned128 =
false) {
50 std::shared_ptr <GroupAllocator> g = allocator[group];
52 g = std::make_shared<GroupAllocator>(group, ctx.
page_size);
55 groupMapMutex.unlock();
57 g->allocate<T>(ptr, s, forceAligned128);
67 void free(T *p,
int group = -1) {
69 std::shared_ptr <GroupAllocator> g = allocator[group];
70 groupMapMutex.unlock();
82 for (std::pair<
const int, std::shared_ptr < groupallocator::GroupAllocator>>
84 elm.second->freeall();
86 groupMapMutex.unlock();
95 inline void moveToGPU(
int group = -1,
int gpuID = 0, cudaStream_t stream = cudaStreamDefault){
97 std::shared_ptr <GroupAllocator> g = allocator[group];
98 groupMapMutex.unlock();
102 g->moveToDevice(gpuID, stream);
111 inline void moveToCPU(
int group = -1, cudaStream_t stream = cudaStreamDefault){
112 groupMapMutex.lock();
113 std::shared_ptr <GroupAllocator> g = allocator[group];
114 groupMapMutex.unlock();
117 g->moveToDevice(cudaCpuDeviceId, stream);