DFT-EFE
 
Loading...
Searching...
No Matches
MemoryStorage.h
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2021. *
3 * The Regents of the University of Michigan and DFT-EFE developers. *
4 * *
5 * This file is part of the DFT-EFE code. *
6 * *
7 * DFT-EFE is free software: you can redistribute it and/or modify *
8 * it under the terms of the Lesser GNU General Public License as *
9 * published by the Free Software Foundation, either version 3 of *
10 * the License, or (at your option) any later version. *
11 * *
12 * DFT-EFE is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
15 * See the Lesser GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License at the top level of DFT-EFE distribution. If not, see *
19 * <https://www.gnu.org/licenses/>. *
20 ******************************************************************************/
21
22/*
23 * @author Ian C. Lin, Sambit Das.
24 */
25
26#ifndef dftefeMemoryStorage_h
27#define dftefeMemoryStorage_h
28
29#include <utils/MemoryManager.h>
30#include <utils/TypeConfig.h>
31#include <vector>
32namespace dftefe
33{
34 namespace utils
35 {
36 template <typename ValueType, dftefe::utils::MemorySpace memorySpace>
38 {
51 //
52 // typedefs
53 //
54 public:
55 typedef ValueType value_type;
56 typedef ValueType * pointer;
57 typedef ValueType & reference;
58 typedef const ValueType &const_reference;
59 typedef ValueType * iterator;
60 typedef const ValueType *const_iterator;
61
62 public:
63 MemoryStorage() = default;
64
70
75 MemoryStorage(MemoryStorage &&u) noexcept;
76
82 explicit MemoryStorage(size_type size, ValueType initVal = ValueType());
83
88
93 void
94 setValue(const ValueType val);
95
103 begin();
104
113 begin() const;
114
121 end();
122
130 end() const;
131
132
139 operator=(const MemoryStorage &rhs);
140
141
148 operator=(MemoryStorage &&rhs) noexcept;
149
150 // // This part does not work for GPU version, will work on this
151 // until
152 // // having cleaner solution.
153 // /**
154 // * @brief Operator to get a reference to a element of the Vector
155 // * @param[in] i is the index to the element of the Vector
156 // * @returns reference to the element of the Vector
157 // * @throws exception if i >= size of the Vector
158 // */
159 // reference
160 // operator[](size_type i);
161 //
162 // /**
163 // * @brief Operator to get a const reference to a element of the Vector
164 // * @param[in] i is the index to the element of the Vector
165 // * @returns const reference to the element of the Vector
166 // * @throws exception if i >= size of the Vector
167 // */
168 // const_reference
169 // operator[](size_type i) const;
170
177 void
178 resize(size_type size, ValueType initVal = ValueType());
179
185 size() const;
186
191 ValueType *
192 data() noexcept;
193
198 const ValueType *
199 data() const noexcept;
200
216 template <dftefe::utils::MemorySpace memorySpaceDst>
217 void
218 copyTo(MemoryStorage<ValueType, memorySpaceDst> &dstMemoryStorage) const;
219
246 template <dftefe::utils::MemorySpace memorySpaceDst>
247 void
248 copyTo(MemoryStorage<ValueType, memorySpaceDst> &dstMemoryStorage,
249 const size_type N,
250 const size_type srcOffset,
251 const size_type dstOffset) const;
252
267 template <dftefe::utils::MemorySpace memorySpaceSrc>
268 void
269 copyFrom(
270 const MemoryStorage<ValueType, memorySpaceSrc> &srcMemoryStorage);
271
297 template <dftefe::utils::MemorySpace memorySpaceSrc>
298 void
299 copyFrom(MemoryStorage<ValueType, memorySpaceSrc> &srcMemoryStorage,
300 const size_type N,
301 const size_type srcOffset,
302 const size_type dstOffset);
303
317 template <dftefe::utils::MemorySpace memorySpaceDst>
318 void
319 copyTo(ValueType *dst) const;
320
345 template <dftefe::utils::MemorySpace memorySpaceDst>
346 void
347 copyTo(ValueType * dst,
348 const size_type N,
349 const size_type srcOffset,
350 const size_type dstOffset) const;
351
365 template <dftefe::utils::MemorySpace memorySpaceSrc>
366 void
367 copyFrom(const ValueType *src);
368
392 template <dftefe::utils::MemorySpace memorySpaceSrc>
393 void
394 copyFrom(const ValueType *src,
395 const size_type N,
396 const size_type srcOffset,
397 const size_type dstOffset);
398
414 void
415 copyTo(std::vector<ValueType> &dst) const;
416
446 void
447 copyTo(std::vector<ValueType> &dst,
448 const size_type N,
449 const size_type srcOffset,
450 const size_type dstOffset) const;
451
464 void
465 copyFrom(const std::vector<ValueType> &src);
466
490 void
491 copyFrom(const std::vector<ValueType> &src,
492 const size_type N,
493 const size_type srcOffset,
494 const size_type dstOffset);
495
496
497 private:
498 ValueType *d_data = nullptr;
500 };
501
502 //
503 // helper functions
504 //
505
518 template <typename ValueType, utils::MemorySpace memorySpaceDst>
519 MemoryStorage<ValueType, memorySpaceDst>
520 memoryStorageFromSTL(const std::vector<ValueType> &src);
521
522 } // namespace utils
523} // end of namespace dftefe
524
525#include "MemoryStorage.t.cpp"
526
527#endif
Definition: MemoryStorage.h:38
const ValueType & const_reference
Definition: MemoryStorage.h:58
const ValueType * const_iterator
Definition: MemoryStorage.h:60
ValueType * data() noexcept
Return the raw pointer to the Vector.
Definition: MemoryStorage.t.cpp:198
size_type d_size
Definition: MemoryStorage.h:499
void resize(size_type size, ValueType initVal=ValueType())
Deallocates and then resizes Vector with new size and initial value arguments.
Definition: MemoryStorage.t.cpp:52
ValueType * iterator
Definition: MemoryStorage.h:59
iterator begin()
Return iterator pointing to the beginning of point data.
Definition: MemoryStorage.t.cpp:117
MemoryStorage & operator=(const MemoryStorage &rhs)
Copy assignment operator.
Definition: MemoryStorage.t.cpp:145
ValueType * pointer
Definition: MemoryStorage.h:56
void setValue(const ValueType val)
Set all the entries to a given value.
Definition: MemoryStorage.t.cpp:92
iterator end()
Return iterator pointing to the end of Vector data.
Definition: MemoryStorage.t.cpp:131
ValueType & reference
Definition: MemoryStorage.h:57
ValueType * d_data
Definition: MemoryStorage.h:498
size_type size() const
Returns the dimension of the Vector.
Definition: MemoryStorage.t.cpp:110
ValueType value_type
A class template to provide an interface that can act similar to STL vectors but with different Memor...
Definition: MemoryStorage.h:55
~MemoryStorage()
Destructor.
Definition: MemoryStorage.t.cpp:73
void copyFrom(const MemoryStorage< ValueType, memorySpaceSrc > &srcMemoryStorage)
Copies data from a MemoryStorage object in a different memory space. This provides a seamless interfa...
Definition: MemoryStorage.t.cpp:250
void copyTo(MemoryStorage< ValueType, memorySpaceDst > &dstMemoryStorage) const
Copies the data to a MemoryStorage object in a different memory space. This provides a seamless inter...
Definition: MemoryStorage.t.cpp:212
MemorySpace
Definition: MemorySpaceType.h:37
MemoryStorage< ValueType, memorySpaceDst > memoryStorageFromSTL(const std::vector< ValueType > &src)
Create a MemoryStorage object from an input C++ STL vector.
Definition: MemoryStorage.t.cpp:409
dealii includes
Definition: AtomFieldDataSpherical.cpp:31
unsigned int size_type
Definition: TypeConfig.h:8