mgcpp
A C++ Math Library Based on CUDA
allocator.hpp
Go to the documentation of this file.
1 #ifndef MGCPP_ALLOCATOR_HPP
2 #define MGCPP_ALLOCATOR_HPP
3 
5 
6 namespace mgcpp {
7 
8 class memory_resource;
9 class device_memory_resource;
10 
11 template <typename Type>
12 class allocator {
13  memory_resource* m_host_resource;
14  device_memory_resource* m_device_resource;
15 
16  public:
17  using host_value_type = Type;
20 
24 
25  template <typename NewType>
27 
28  allocator();
30 
31  template <class U>
32  allocator(const allocator<U>& other);
33 
34  host_pointer allocate_host(size_t n);
35  void deallocate_host(host_pointer p, size_t n);
36 
38  void deallocate_device(device_pointer p, size_t n);
39 
40  void copy_from_host(device_pointer device,
42  size_t n) const;
43 
44  void copy_to_host(device_pointer host,
45  device_const_pointer device,
46  size_t n) const;
47 
48  // Return a default-constructed instance of this class
50 
51  memory_resource* host_resource() const noexcept;
52  device_memory_resource* device_resource() const noexcept;
53  size_t device_id() const noexcept;
54 };
55 
56 template <typename T1, typename T2>
57 bool operator==(allocator<T1> const& a, allocator<T2> const& b);
58 
59 template <typename T1, typename T2>
60 bool operator!=(allocator<T1> const& a, allocator<T2> const& b);
61 
62 } // namespace mgcpp
63 
64 #include <mgcpp/allocators/allocator.tpp>
65 #endif // MGCPP_ALLOCATOR_HPP
typename device_value_type< Type >::type device_value_type
Definition: allocator.hpp:21
Definition: adapter_base.hpp:12
device_pointer allocate_device(size_t n)
void copy_to_host(device_pointer host, device_const_pointer device, size_t n) const
memory_resource * host_resource() const noexcept
device_memory_resource * device_resource() const noexcept
Definition: device_memory_resource.hpp:8
host_value_type const * host_const_pointer
Definition: allocator.hpp:19
Definition: memory_resource.hpp:12
host_pointer allocate_host(size_t n)
void deallocate_device(device_pointer p, size_t n)
size_t device_id() const noexcept
void deallocate_host(host_pointer p, size_t n)
Type host_value_type
Definition: allocator.hpp:17
Definition: allocator.hpp:12
allocator select_on_container_copy_construction() const
device_value_type const * device_const_pointer
Definition: allocator.hpp:23
Type type
Definition: device_value_type.hpp:20
host_value_type * host_pointer
Definition: allocator.hpp:18
void copy_from_host(device_pointer device, device_const_pointer host, size_t n) const
device_value_type * device_pointer
Definition: allocator.hpp:22