ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
ResourceCleanup::Attorney< deallocator > Class Template Reference

Attorney for a resource deallocator. More...

#include <ResourceCleanup.hpp>

Friends

class ResourceCleanup
 

Detailed Description

template<auto deallocator>
class ResourceCleanup::Attorney< deallocator >

Attorney for a resource deallocator.

Usage:

#include <thrust/device_free.h>
#include <thrust/device_malloc.h>
#include <memory>
class MyClass;
static std::shared_ptr<ResourceCleanup> resource_queue = nullptr;
static std::shared_ptr<MyClass> resource = nullptr;
class MyClass {
private:
thrust::device_ptr<float> data_dev;
void free_device_memory() { thrust::device_free(data_dev); }
friend Cleanup;
public:
MyClass(int n) { data_dev = thrust::device_malloc<float>(n); }
~MyClass() { free_device_memory(); }
template <class... Args>
static auto make_shared(Args ...args) {
auto obj = std::make_shared<MyClass>(args...);
// comment the next line of code to trigger the CUDA runtime error
// "device free failed: cudaErrorCudartUnloading: driver shutting down"
::resource_queue->push<MyClass::Cleanup>(obj);
return obj;
}
};
int main() {
::resource_queue = std::make_shared<ResourceCleanup>();
::resource = MyClass::make_shared(5);
// The CUDA primary context expires before normal program termination.
// Yet thrust vectors require a primary context to deallocate device
// memory. Force deallocation before normal program termination.
::resource_queue.reset();
}
Attorney for a resource deallocator.
int main()
Definition dummy.cpp:19
Template Parameters
deallocatorMember function that deallocates managed resources.

Definition at line 106 of file ResourceCleanup.hpp.

Friends And Related Symbol Documentation

◆ ResourceCleanup

template<auto deallocator>
friend class ResourceCleanup
friend

Definition at line 139 of file ResourceCleanup.hpp.


The documentation for this class was generated from the following file: