OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CudaMgr_Namespace::DeviceMemoryAllocationMap Class Reference

#include <DeviceMemoryAllocationMap.h>

Classes

struct  Allocation
 

Public Types

using DevicePtr = uint64_t
 
using Map = std::map< DevicePtr, Allocation >
 
using MapChangedCBID = uint32_t
 
using MapChangedCB = std::function< void(const heavyai::UUID, const bool)>
 

Public Member Functions

 DeviceMemoryAllocationMap ()
 
 ~DeviceMemoryAllocationMap ()=default
 
const MapgetMap () const
 
const bool mapEmpty () const
 
void addAllocation (const DevicePtr device_ptr, const uint64_t size, const uint64_t handle, const heavyai::UUID uuid, const int device_num, const bool is_slab)
 
Allocation removeAllocation (const DevicePtr device_ptr)
 
std::pair< DevicePtr, AllocationgetAllocation (const DevicePtr device_ptr)
 
const MapChangedCBID registerMapChangedCB (MapChangedCB cb)
 
void unregisterMapChangedCB (const MapChangedCBID cbid)
 
void notifyMapChanged (const heavyai::UUID device_uuid, const bool is_slab) const
 

Private Attributes

Map map_
 
MapChangedCBID last_map_changed_cbid_
 
std::unordered_map
< MapChangedCBID, MapChangedCB
map_changed_cbs_
 

Detailed Description

Definition at line 28 of file DeviceMemoryAllocationMap.h.

Member Typedef Documentation

using CudaMgr_Namespace::DeviceMemoryAllocationMap::MapChangedCB = std::function<void(const heavyai::UUID, const bool)>

Definition at line 40 of file DeviceMemoryAllocationMap.h.

Constructor & Destructor Documentation

CudaMgr_Namespace::DeviceMemoryAllocationMap::DeviceMemoryAllocationMap ( )
CudaMgr_Namespace::DeviceMemoryAllocationMap::~DeviceMemoryAllocationMap ( )
default

Member Function Documentation

void CudaMgr_Namespace::DeviceMemoryAllocationMap::addAllocation ( const DevicePtr  device_ptr,
const uint64_t  size,
const uint64_t  handle,
const heavyai::UUID  uuid,
const int  device_num,
const bool  is_slab 
)

Definition at line 34 of file DeviceMemoryAllocationMap.cpp.

References CHECK, and map_.

39  {
40  Allocation allocation{size, handle, uuid, device_num, is_slab};
41  CHECK(map_.try_emplace(device_ptr, std::move(allocation)).second);
42 }
#define CHECK(condition)
Definition: Logger.h:291
std::pair< DeviceMemoryAllocationMap::DevicePtr, DeviceMemoryAllocationMap::Allocation > CudaMgr_Namespace::DeviceMemoryAllocationMap::getAllocation ( const DevicePtr  device_ptr)

Definition at line 58 of file DeviceMemoryAllocationMap.cpp.

References CHECK, and map_.

58  {
59  // find the map entry above this address
60  auto itr = map_.upper_bound(device_ptr);
61  CHECK(itr != map_.begin());
62  // return the previous entry
63  --itr;
64  return std::make_pair(itr->first, itr->second);
65 }
#define CHECK(condition)
Definition: Logger.h:291
const DeviceMemoryAllocationMap::Map & CudaMgr_Namespace::DeviceMemoryAllocationMap::getMap ( ) const

Definition at line 26 of file DeviceMemoryAllocationMap.cpp.

References map_.

const bool CudaMgr_Namespace::DeviceMemoryAllocationMap::mapEmpty ( ) const

Definition at line 30 of file DeviceMemoryAllocationMap.cpp.

References map_.

30  {
31  return map_.empty();
32 }
void CudaMgr_Namespace::DeviceMemoryAllocationMap::notifyMapChanged ( const heavyai::UUID  device_uuid,
const bool  is_slab 
) const

Definition at line 80 of file DeviceMemoryAllocationMap.cpp.

References map_changed_cbs_.

81  {
82  for (auto const& cb : map_changed_cbs_) {
83  cb.second(device_uuid, is_slab);
84  }
85 }
std::unordered_map< MapChangedCBID, MapChangedCB > map_changed_cbs_
const DeviceMemoryAllocationMap::MapChangedCBID CudaMgr_Namespace::DeviceMemoryAllocationMap::registerMapChangedCB ( MapChangedCB  cb)

Definition at line 68 of file DeviceMemoryAllocationMap.cpp.

References CHECK, last_map_changed_cbid_, and map_changed_cbs_.

68  {
69  auto const cbid = ++last_map_changed_cbid_;
70  CHECK(map_changed_cbs_.emplace(cbid, cb).second) << "Repeat registration";
71  return cbid;
72 }
std::unordered_map< MapChangedCBID, MapChangedCB > map_changed_cbs_
#define CHECK(condition)
Definition: Logger.h:291
DeviceMemoryAllocationMap::Allocation CudaMgr_Namespace::DeviceMemoryAllocationMap::removeAllocation ( const DevicePtr  device_ptr)

Definition at line 44 of file DeviceMemoryAllocationMap.cpp.

References CHECK, and map_.

45  {
46  // find the exact match
47  auto const itr = map_.find(device_ptr);
48  CHECK(itr != map_.end());
49  // copy out the allocation
50  Allocation allocation = itr->second;
51  // remove from map
52  map_.erase(itr);
53  // return the allocation that was
54  return allocation;
55 }
#define CHECK(condition)
Definition: Logger.h:291
void CudaMgr_Namespace::DeviceMemoryAllocationMap::unregisterMapChangedCB ( const MapChangedCBID  cbid)

Definition at line 74 of file DeviceMemoryAllocationMap.cpp.

References CHECK, and map_changed_cbs_.

74  {
75  auto itr = map_changed_cbs_.find(cbid);
76  CHECK(itr != map_changed_cbs_.end()) << "Failed to unregister";
77  map_changed_cbs_.erase(itr);
78 }
std::unordered_map< MapChangedCBID, MapChangedCB > map_changed_cbs_
#define CHECK(condition)
Definition: Logger.h:291

Member Data Documentation

MapChangedCBID CudaMgr_Namespace::DeviceMemoryAllocationMap::last_map_changed_cbid_
private

Definition at line 63 of file DeviceMemoryAllocationMap.h.

Referenced by registerMapChangedCB().

Map CudaMgr_Namespace::DeviceMemoryAllocationMap::map_
private
std::unordered_map<MapChangedCBID, MapChangedCB> CudaMgr_Namespace::DeviceMemoryAllocationMap::map_changed_cbs_
private

The documentation for this class was generated from the following files: