"python/ait_impl/generation/xx.cpp" did not exist on "b491ebf38480bc0d6cb329ba6825dee610c59097"
Commit d0a846c2 authored by Ville Pietilä's avatar Ville Pietilä
Browse files

Added more logging. Fix pinned host memory pool to be a real singleton.

parent af2a1bd8
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <map> #include <map>
#include <queue> #include <queue>
#include <mutex> #include <mutex>
#include "unistd.h"
namespace ck { namespace ck {
namespace memory { namespace memory {
...@@ -15,15 +16,27 @@ namespace memory { ...@@ -15,15 +16,27 @@ namespace memory {
class MemPool class MemPool
{ {
public: public:
MemPool() = default; MemPool() :
enableLogging_(ck::EnvIsEnabled(CK_ENV(CK_LOGGING))),
pid_(getpid())
{
if (enableLogging_)
std::cout << "[ MemPool ] Created memory pool for process " << pid_ << std::endl;
}
~MemPool() ~MemPool()
{ {
if (enableLogging_)
std::cout << "[ MemPool ] Deleting pool for process " << pid_ << "..."<< std::endl;
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
for (auto& [size, q] : memory_pool_) for (auto& [size, q] : memory_pool_)
{ {
clearMemoryPoolQueue(q); clearMemoryPoolQueue(q);
} }
if (enableLogging_)
std::cout << "[ MemPool ] Deleted pool for process " << pid_ << std::endl;
} }
void* allocate(std::size_t sizeInBytes) void* allocate(std::size_t sizeInBytes)
...@@ -78,10 +91,21 @@ namespace memory { ...@@ -78,10 +91,21 @@ namespace memory {
std::mutex mutex_; // Mutex to protect access to the memory pool. std::mutex mutex_; // Mutex to protect access to the memory pool.
std::map<size_t, std::queue<void*>> memory_pool_{}; std::map<size_t, std::queue<void*>> memory_pool_{};
size_t memPoolSizeInBytes_{0}; size_t memPoolSizeInBytes_{0};
bool enableLogging_{false};
int pid_{-1};
};
class PinnedHostMemoryAllocatorBase
{
protected:
static MemPool& get_memory_pool() {
static MemPool memory_pool;
return memory_pool;
}
}; };
template <typename T> template <typename T>
class PinnedHostMemoryAllocator class PinnedHostMemoryAllocator : public PinnedHostMemoryAllocatorBase
{ {
public: public:
using value_type = T; using value_type = T;
...@@ -124,11 +148,6 @@ namespace memory { ...@@ -124,11 +148,6 @@ namespace memory {
void destroy(U* p) noexcept { void destroy(U* p) noexcept {
p->~U(); p->~U();
} }
private:
static MemPool& get_memory_pool() {
static MemPool memory_pool;
return memory_pool;
}
}; };
template <typename T, typename U> template <typename T, typename U>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment