Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

memory: Add safe_host_allocator and deprecate safe_pinned_host_allocator #36

Merged
merged 1 commit into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 30 additions & 7 deletions src/stdgpu/impl/memory_detail.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ createHostArray(const stdgpu::index64_t count,
{
T* host_array = nullptr;

stdgpu::safe_pinned_host_allocator<T> host_allocator;
stdgpu::safe_host_allocator<T> host_allocator;
host_array = host_allocator.allocate(count);

if (host_array == nullptr)
Expand Down Expand Up @@ -258,7 +258,7 @@ destroyHostArray(T*& host_array)
stdgpu::detail::destroy_value<T>());
#endif

stdgpu::safe_pinned_host_allocator<T> host_allocator;
stdgpu::safe_host_allocator<T> host_allocator;
host_allocator.deallocate(host_array, stdgpu::size(host_array));

host_array = nullptr;
Expand Down Expand Up @@ -290,7 +290,7 @@ copyCreateDevice2HostArray(const T* device_array,
{
T* host_array = nullptr;

stdgpu::safe_pinned_host_allocator<T> host_allocator;
stdgpu::safe_host_allocator<T> host_allocator;
host_array = host_allocator.allocate(count);

if (host_array == nullptr)
Expand Down Expand Up @@ -336,7 +336,7 @@ copyCreateHost2HostArray(const T* host_array,
{
T* host_array_2 = nullptr;

stdgpu::safe_pinned_host_allocator<T> host_allocator;
stdgpu::safe_host_allocator<T> host_allocator;
host_array_2 = host_allocator.allocate(count);

if (host_array_2 == nullptr)
Expand Down Expand Up @@ -462,16 +462,16 @@ safe_device_allocator<T>::deallocate(T* p,

template <typename T>
STDGPU_NODISCARD T*
safe_pinned_host_allocator<T>::allocate(index64_t n)
safe_host_allocator<T>::allocate(index64_t n)
{
return static_cast<T*>(detail::allocate(n * sizeof(T), memory_type));
}


template <typename T>
void
safe_pinned_host_allocator<T>::deallocate(T* p,
index64_t n)
safe_host_allocator<T>::deallocate(T* p,
index64_t n)
{
detail::deallocate(static_cast<void*>(p), n * sizeof(T), memory_type);
}
Expand Down Expand Up @@ -536,6 +536,29 @@ size_bytes(T* array)
return size_bytes<void>(static_cast<void*>(const_cast<std::remove_cv_t<T>*>(array)));
}


// Deprecated classes and functions
template <typename T>
struct [[deprecated("Replaced by stdgpu::safe_host_allocator<T>")]] safe_pinned_host_allocator
{
using value_type = T;

constexpr static dynamic_memory_type memory_type = dynamic_memory_type::host;

STDGPU_NODISCARD T*
allocate(index64_t n)
{
return static_cast<T*>(detail::allocate(n * sizeof(T), memory_type));
}

void
deallocate(T* p,
index64_t n)
{
detail::deallocate(static_cast<void*>(p), n * sizeof(T), memory_type);
}
};

} // namespace stdgpu


Expand Down
13 changes: 11 additions & 2 deletions src/stdgpu/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,11 @@ struct safe_device_allocator


/**
* \brief An allocator for pinned host memory
* \brief An allocator for host memory
* \tparam T A type
*/
template <typename T>
struct safe_pinned_host_allocator
struct safe_host_allocator
{
using value_type = T; /**< T */

Expand Down Expand Up @@ -428,6 +428,15 @@ template <typename T>
index64_t
size_bytes(T* array);


// Deprecated classes and functions
/**
* \def safe_pinned_host_allocator
* \deprecated Replaced by stdgpu::safe_host_allocator<T>
* \brief An allocator for pinned host memory
* \tparam T A type
*/

} // namespace stdgpu


Expand Down