PSCF v1.4.0
DeviceMemory.h
1#ifndef PSCF_DEVICE_MEMORY_H
2#define PSCF_DEVICE_MEMORY_H
3
4/*
5* PSCF - Polymer Self-Consistent Field
6*
7* Copyright 2015 - 2025, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/misc/ReferenceCounter.h>
12
13// Forward declaration
14namespace Util { class CountedReference; }
15
16namespace Pscf {
17
18 using namespace Util;
19
29 {
30
31 public:
32
37
46
52 virtual ~DeviceMemory();
53
62 void allocate(int capacity);
63
69 void deallocate();
70
85 void resize(int capacity);
86
100 void addReference(CountedReference& reference);
101
105 void* cArray() const;
106
112 int capacity() const;
113
117 bool isAllocated() const;
118
119 private:
120
122 void* dataPtr_;
123
125 int capacity_;
126
128 ReferenceCounter refCounter_;
129
130 };
131
132 /*
133 * Return true if the array has been allocated, false otherwise.
134 */
135 inline
137 { return (bool)dataPtr_; }
138
139 /*
140 * Return allocated capacity.
141 */
142 inline
144 { return capacity_; }
145
146} // namespace Pscf
147#endif
virtual ~DeviceMemory()
Destructor.
void deallocate()
Dellocate the underlying C array, if any.
void addReference(CountedReference &reference)
Associate a reference with the reference counter.
bool isAllocated() const
Return true if the array has been allocated, false otherwise.
DeviceMemory()
Default constructor.
void * cArray() const
Return pointer to underlying C array.
void allocate(int capacity)
Allocate the underlying C array on the device.
int capacity() const
Return allocated capacity.
void resize(int capacity)
Re-allocate if necessary to increase capacity.
Reference to a shared resource.
Reference counter.
PSCF package top-level namespace.
Utility classes for scientific computation.