Commit a19235d4 authored by Ville Pietilä's avatar Ville Pietilä
Browse files

Fixed cleaning up pinned host memory after deallocate.

parent 578fd2d7
...@@ -5,13 +5,18 @@ ...@@ -5,13 +5,18 @@
#include <hip/hip_runtime.h> #include <hip/hip_runtime.h>
#include "ck/host_utility/hip_check_error.hpp" #include "ck/host_utility/hip_check_error.hpp"
#include "ck/utility/env.hpp"
#include <map> #include <map>
#include <queue> #include <queue>
#include <mutex> #include <mutex>
#include <cstddef> #include <cstddef>
#include <limits> #include <limits>
#include <type_traits>
#include "unistd.h" #include "unistd.h"
CK_DECLARE_ENV_VAR_BOOL(CK_USE_DYNAMIC_MEM_POOL)
CK_DECLARE_ENV_VAR_BOOL(CK_PREFER_NEW_PINNED_MEM_ALLOCATION)
namespace ck { namespace ck {
namespace memory { namespace memory {
...@@ -296,7 +301,15 @@ namespace memory { ...@@ -296,7 +301,15 @@ namespace memory {
return static_cast<T*>(memory_pool.allocate(sizeInBytes)); return static_cast<T*>(memory_pool.allocate(sizeInBytes));
} }
void deallocate(T* p, std::size_t n) { void deallocate(T* p, std::size_t n)
{
if constexpr (std::is_destructible_v<T>)
{
for (size_t i = 0; i < n; ++i) {
p[i].~T();
}
}
auto& memory_pool = get_memory_pool(); auto& memory_pool = get_memory_pool();
const size_t sizeInBytes = n * sizeof(T); const size_t sizeInBytes = n * sizeof(T);
memory_pool.deallocate(p, sizeInBytes); memory_pool.deallocate(p, sizeInBytes);
......
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