You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
double* data = (double*) mr->allocate(bytes, alignment);
64
+
mr->deallocate(data, bytes, alignment);
65
+
```
66
+
67
+
### pluto::async_memory_resource
68
+
69
+
The `pluto::async_memory_resource` extends `pluto::memory_resource` with asynchronous allocation and deallocation features. The asynchronous argument is a `pluto::stream_view`, which implements a `cudaStream` or `hipStream`. \
The `pluto::allocator<T>` extends [`std::pmr::polymorphic_allocater`](https://en.cppreference.com/w/cpp/memory/polymorphic_allocator)
88
+
which implements all functions required of a C++ [Allocator](https://en.cppreference.com/w/cpp/named_req/Allocator) to be given to [AllocatorAwareContainers](https://en.cppreference.com/w/cpp/named_req/AllocatorAwareContainer) such as e.g. `std::vector`, `std::map`, `std::set`, `std::list`, `std::string`.
89
+
It internally uses a `pluto::memory_resource*` for allocation and deallocation.
90
+
The noteworthy functions are:
91
+
```c++
92
+
/// Constructor without arguments; a configurable default pluto::memory_resource will be used
93
+
/// This default can be set with `std::pmr::set_default_resource()` or `pluto::set_default_resource()`
94
+
pluto::allocator<T>();
95
+
96
+
/// Constructor using a given memory_resource. Note this is compatible with any third-party `std::pmr::memory_resource`
97
+
pluto::allocator<T>(pluto::memory_resource*);
98
+
99
+
/// Return an new allocated array with `size` number of elements. (Not bytes unlike pluto::memory_resource)
100
+
T* allocate(std::size_t size);
101
+
102
+
/// Deallocate a given array with `size` number of elements. (Not bytes unlike pluto::memory_resource)
103
+
void deallocate(T* ptr, std::size_t size);
104
+
105
+
/// Return an new allocated array with `size` number of elements. (Not bytes unlike pluto::memory_resource)
When `(de)allocate_async` is used with a `memory_resource` that does not derive from `pluto::async_memory_resource`, then `(de)allocate` will be used instead.
113
+
The functions `(de)allocate`, `(de)allocate_async` also have overrides with a first argument `std::string_view label`, that can be used for tracing memory (de)allocations if the used concrete memory resources supports it.
114
+
115
+
#### Examples:
116
+
117
+
- Use allocator to allocate array of 10 elements using pre-defined `pluto::host_resource()`\
Following C++ classes exist that extend `pluto::allocator<T>`:
170
+
```c++
171
+
pluto::host::allocator<T>
172
+
pluto::device::allocator<T>
173
+
```
174
+
The only difference with `pluto::allocator` is that the default constructor won't use `std::pmr::get_default_resource()`, \
175
+
but rather `pluto::{host,device}::get_default_resource()`.
176
+
177
+
In Fortran you would create allocators that use the memory space specific defaults via:
178
+
```fortran
179
+
type(pluto_allocator) :: host_alloc, device_alloc
180
+
host_alloc = pluto%host%make_allocator()
181
+
device_alloc = pluto%device%make_allocator()
182
+
```
183
+
184
+
The initial value returned by `pluto::{host,device}::get_default_resource()` is respectively `pluto::host_resource()` and `pluto::device_resource()` unless specified otherwise via environment variables:
0 commit comments