mgcpp
A C++ Math Library Based on CUDA
cudamalloc_resource.hpp
Go to the documentation of this file.
1 #ifndef CUDA_RESOURCE_HPP
2 #define CUDA_RESOURCE_HPP
3 
5 #include <mgcpp/cuda/device.hpp>
6 #include <mgcpp/cuda/memory.hpp>
7 
8 namespace mgcpp {
9 
11  public:
12  static cudamalloc_resource* instance(size_t device_id);
13  size_t allocated_bytes() const noexcept;
14 
15  protected:
16  void* do_allocate(size_t bytes) override;
17 
18  void do_deallocate(void* p, size_t bytes) override;
19 
20  bool do_is_equal(const memory_resource& other) const noexcept override;
21 
22  private:
23  explicit cudamalloc_resource(size_t device_id);
24 
25  std::atomic<size_t> _allocated_bytes{0};
26 };
27 
28 } // namespace mgcpp
29 
30 #endif // CUDA_RESOURCE_HPP
Definition: adapter_base.hpp:12
static cudamalloc_resource * instance(size_t device_id)
void * do_allocate(size_t bytes) override
Definition: device_memory_resource.hpp:8
size_t allocated_bytes() const noexcept
bool do_is_equal(const memory_resource &other) const noexcept override
Definition: memory_resource.hpp:12
Definition: cudamalloc_resource.hpp:10
void do_deallocate(void *p, size_t bytes) override