Alsvinn  0.5.3
The fast FVM simulator with UQ support
CudaMemory.hpp
Go to the documentation of this file.
1 /* Copyright (c) 2018 ETH Zurich, Kjetil Olsen Lye
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  */
15 
16 #include "alsfvm/memory/Memory.hpp"
17 namespace alsfvm {
18 namespace cuda {
19 
20 template<class T>
21 class CudaMemory : public memory::Memory<T> {
22 public:
28  CudaMemory(size_t nx, size_t ny = 1, size_t nz = 1);
29 
30 
32  virtual std::shared_ptr<memory::Memory<T> > makeInstance() const override;
33 
34  // Note: Virtual distructor since we will inherit
35  // from this.
36  virtual ~CudaMemory();
37 
39  virtual void copyFrom(const memory::Memory<T>& other) override;
40 
47  virtual bool isOnHost() const;
48 
52  virtual T* getPointer() override;
53 
60  virtual const T* getPointer() const override;
61 
65  virtual void copyToHost(T* bufferPointer, size_t bufferLength) const override;
66 
67 
71  virtual void copyFromHost(const T* bufferPointer, size_t bufferLength) override;
72 
73 
74 
75 
80  virtual void operator+=(const memory::Memory<T>& other) override;
81 
86  virtual void operator*=(const memory::Memory<T>& other) override;
87 
92  virtual void operator-=(const memory::Memory<T>& other) override;
93 
98  virtual void operator/=(const memory::Memory<T>& other) override;
99 
100 
105  virtual void operator+=(real scalar) override;
106 
111  virtual void operator*=(real scalar) override;
112 
117  virtual void operator-=(real scalar) override;
118 
123  virtual void operator/=(real scalar) override;
124 
128  virtual void makeZero() override;
129 
130 
145  virtual void copyInternalCells(size_t startX, size_t endX,
146  size_t startY, size_t endY,
147  size_t startZ, size_t endZ,
148  T* output, size_t outputSize) override;
149 
154  virtual void addLinearCombination(T a1,
155  T a2, const memory::Memory<T>& v2,
156  T a3, const memory::Memory<T>& v3,
157  T a4, const memory::Memory<T>& v4,
158  T a5, const memory::Memory<T>& v5) override;
159 
160 
161 
168  virtual void addPower(const memory::Memory<T>& other, double power) override;
169 
176  virtual void addPower(const memory::Memory<T>& other, double power,
177  double factor) override;
178 
179 
186  virtual void subtractPower(const memory::Memory<T>& other,
187  double power) override;
188 
189 
190  std::shared_ptr<memory::Memory<T> > getHostMemory() override;
191 
192  const std::shared_ptr<const memory::Memory<T> > getHostMemory() const override;
193 
203  virtual real getTotalVariation(int p, const ivec3& start,
204  const ivec3& end) const override;
205 
216  virtual real getTotalVariation(int direction, int p, const ivec3& start,
217  const ivec3& end) const override;
218 
219 
220 private:
221  T* memoryPointer;
222 };
223 
224 }
225 }
std::shared_ptr< memory::Memory< T > > getHostMemory() override
Copies the data to host if it is on GPU, otherwise makes a copy.
Definition: CudaMemory.cpp:339
virtual void copyFrom(const memory::Memory< T > &other) override
Copies the contents of the other memory area into this one.
Definition: CudaMemory.cpp:98
Definition: CudaMemory.hpp:21
const size_t ny
Definition: Memory.hpp:341
virtual void operator+=(const memory::Memory< T > &other) override
Definition: CudaMemory.cpp:166
virtual void makeZero() override
Definition: CudaMemory.cpp:259
virtual void operator*=(const memory::Memory< T > &other) override
Definition: CudaMemory.cpp:181
virtual void subtractPower(const memory::Memory< T > &other, double power) override
Definition: CudaMemory.cpp:332
virtual bool isOnHost() const
Definition: CudaMemory.cpp:120
double real
Definition: types.hpp:65
virtual real getTotalVariation(int p, const ivec3 &start, const ivec3 &end) const override
Definition: CudaMemory.cpp:360
Definition: Memory.hpp:28
const size_t nx
Definition: Memory.hpp:340
virtual void operator-=(const memory::Memory< T > &other) override
Definition: CudaMemory.cpp:195
virtual T * getPointer() override
Definition: CudaMemory.cpp:128
virtual void copyInternalCells(size_t startX, size_t endX, size_t startY, size_t endY, size_t startZ, size_t endZ, T *output, size_t outputSize) override
copyInternalCells copies the internal cells into the memory area This is ideal for removing ghost cel...
Definition: CudaMemory.cpp:264
virtual void operator/=(const memory::Memory< T > &other) override
Definition: CudaMemory.cpp:209
const size_t nz
Definition: Memory.hpp:342
CudaMemory(size_t nx, size_t ny=1, size_t nz=1)
Definition: CudaMemory.cpp:44
virtual void copyFromHost(const T *bufferPointer, size_t bufferLength) override
Definition: CudaMemory.cpp:154
virtual void addPower(const memory::Memory< T > &other, double power) override
Definition: CudaMemory.cpp:318
Various utility functions to implement the tecno flux.
Definition: types.hpp:30
float p
Definition: sodshocktube.py:5
virtual std::shared_ptr< memory::Memory< T > > makeInstance() const override
Clones the memory area, but does not copy the content
Definition: CudaMemory.cpp:77
virtual ~CudaMemory()
Definition: CudaMemory.cpp:86
virtual void copyToHost(T *bufferPointer, size_t bufferLength) const override
Definition: CudaMemory.cpp:144
virtual void addLinearCombination(T a1, T a2, const memory::Memory< T > &v2, T a3, const memory::Memory< T > &v3, T a4, const memory::Memory< T > &v4, T a5, const memory::Memory< T > &v5) override
Definition: CudaMemory.cpp:293