| 7 | #include "Context.h" |
| 8 | |
| 9 | CUMAT_NAMESPACE_BEGIN |
| 10 | |
| 11 | template <typename T> |
| 12 | class DevicePointer |
| 13 | { |
| 14 | private: |
| 15 | T* pointer_; |
| 16 | int* counter_; |
| 17 | CUMAT_NAMESPACE Context* context_; |
| 18 | friend class DevicePointer<typename std::remove_const<T>::type>; |
| 19 | |
| 20 | __host__ __device__ |
| 21 | void release() |
| 22 | { |
| 23 | #ifndef __CUDA_ARCH__ |
| 24 | //no decrement of the counter in CUDA-code, counter is in host-memory |
| 25 | assert(CUMAT_IMPLIES(counter_, (*counter_) > 0) && "Attempt to calling release() twice"); |
| 26 | if ((counter_) && (--(*counter_) == 0)) |
| 27 | { |
| 28 | delete counter_; |
| 29 | |
| 30 | //DEBUG |
| 31 | if (&Context::current() != context_) |
| 32 | { |
| 33 | CUMAT_LOG_WARNING( |
| 34 | "Freeing memory with a different context than the current context.\n" |
| 35 | "This will likely crash with an invalid-resource-handle error due to different Cub-Allocators"); |
| 36 | } |
| 37 | |
| 38 | context_->freeDevice(pointer_); |
| 39 | } |
| 40 | #endif |
| 41 | } |
| 42 | |
| 43 | public: |
| 44 | DevicePointer(size_t size, CUMAT_NAMESPACE Context& ctx) |
no test coverage detected