Peano
Loading...
Searching...
No Matches
LRFaceData.h
Go to the documentation of this file.
1// This file is part of the ExaHyPE2 project. For conditions of distribution and
2// use, please see the copyright notice at www.peano-framework.org
3#pragma once
4
5#include "peano4/utils/Globals.h"
6#include "tarch/accelerator/accelerator.h"
7#include "tarch/accelerator/MemoryManager.h"
8#include "tarch/la/Vector.h"
9
10#include <functional>
11#include <string>
12
13namespace exahype2 {
20 template <typename inType = double, typename outType = double> struct FaceData {
25 inType* (*QIn)[2];
26 tarch::la::Vector<DIMENSIONS, double>* faceCentre;
27 tarch::la::Vector<DIMENSIONS, double>* faceSize;
28
29 double* t;
30 double* dt;
31
37 int* id;
38
43 const int numberOfFaces;
44
49 const tarch::MemoryLocation memoryLocation;
50
55 const int targetDevice;
56
60 outType* (*QOut)[2];
61
73 inType* QIn_[2],
74 const tarch::la::Vector<DIMENSIONS, double>& faceCentre_,
75 const tarch::la::Vector<DIMENSIONS, double>& faceSize_,
76 double t_,
77 double dt_,
78 outType* QOut_[2],
79 tarch::MemoryLocation memoryLocation_ = tarch::MemoryLocation::Heap,
80 int targetDevice_ = tarch::accelerator::Device::DefaultDevice
81 );
82
84 int numberOfFaces_,
85 tarch::MemoryLocation memoryLocation_ = tarch::MemoryLocation::Heap,
86 int targetDevice_ = tarch::accelerator::Device::DefaultDevice
87 );
88
89 FaceData(const FaceData& copy) = delete;
90 FaceData& operator=(const FaceData&) = delete;
91
92 ~FaceData();
93
94 std::string toString() const;
95 };
96
97} // namespace exahype2
98
99template <typename inType, typename outType>
101 inType* QIn_[2],
102 const tarch::la::Vector<DIMENSIONS, double>& faceCentre_,
103 const tarch::la::Vector<DIMENSIONS, double>& faceSize_,
104 double t_,
105 double dt_,
106 outType* QOut_[2],
107 tarch::MemoryLocation memoryLocation_,
108 int targetDevice_
109):
110 FaceData(1, memoryLocation_, targetDevice_) {
111 QIn[0] = QIn_;
112 faceCentre[0] = faceCentre_;
113 faceSize[0] = faceSize_;
114 t[0] = t_;
115 dt[0] = dt_;
116 QOut[0] = QOut_;
117 id[0] = -1;
118}
119
120template <typename inType, typename outType>
122 FaceData(int numberOfFaces_, tarch::MemoryLocation memoryLocation_, int targetDevice_):
123 numberOfFaces(numberOfFaces_),
124 memoryLocation(memoryLocation_),
125 targetDevice(targetDevice_) {
126
127 QIn = tarch::accelerator::MemoryManager::getInstance().allocate<inType* [2]>(
128 numberOfFaces_,
129 memoryLocation_,
130 targetDevice_
131 );
132 faceCentre = tarch::accelerator::MemoryManager::getInstance().allocate<tarch::la::Vector<DIMENSIONS, double>>(
133 numberOfFaces_,
134 memoryLocation_,
135 targetDevice_
136 );
137 faceSize = tarch::accelerator::MemoryManager::getInstance().allocate<tarch::la::Vector<DIMENSIONS, double>>(
138 numberOfFaces_,
139 memoryLocation_,
140 targetDevice_
141 );
142 t = tarch::accelerator::MemoryManager::getInstance().allocate<double>(numberOfFaces_, memoryLocation_, targetDevice_);
143 dt = tarch::accelerator::MemoryManager::getInstance().allocate<double>(
144 numberOfFaces_,
145 memoryLocation_,
146 targetDevice_
147 );
148 id = tarch::accelerator::MemoryManager::getInstance().allocate<int>(numberOfFaces_, memoryLocation_, targetDevice_);
149 QOut = tarch::accelerator::MemoryManager::getInstance().allocate<outType* [2]>(
150 numberOfFaces_,
151 memoryLocation_,
152 targetDevice_
153 );
154}
155
156template <typename inType, typename outType> exahype2::FaceData<inType, outType>::~FaceData() {
157 // tarch::freeMemory(QIn, memoryLocation, targetDevice);
158 // tarch::freeMemory(faceCentre, memoryLocation, targetDevice);
159 // tarch::freeMemory(faceSize, memoryLocation, targetDevice);
160 // tarch::freeMemory(t, memoryLocation, targetDevice);
161 // tarch::freeMemory(dt, memoryLocation, targetDevice);
162 // tarch::freeMemory(QOut, memoryLocation, targetDevice);
163 // tarch::freeMemory(id, memoryLocation, targetDevice);
164
165 tarch::accelerator::MemoryManager::getInstance().free(QIn, targetDevice);
166 tarch::accelerator::MemoryManager::getInstance().free(faceCentre, targetDevice);
167 tarch::accelerator::MemoryManager::getInstance().free(faceSize, targetDevice);
168 tarch::accelerator::MemoryManager::getInstance().free(t, targetDevice);
169 tarch::accelerator::MemoryManager::getInstance().free(dt, targetDevice);
170 tarch::accelerator::MemoryManager::getInstance().free(QOut, targetDevice);
171 tarch::accelerator::MemoryManager::getInstance().free(id, targetDevice);
172}
173
174template <typename inType, typename outType> std::string exahype2::FaceData<inType, outType>::toString() const {
175 std::ostringstream msg;
176 msg << "[";
177 for (int i = 0; i < numberOfFaces; i++) {
178 msg << "(x=" << faceCentre[i] << ",h=" << faceSize[i] << ",t=" << t[i] << ",dt=" << dt[i] << ",id=" << id[i] << ")";
179 }
180 msg << "]";
181 return msg.str();
182}
FaceData(inType *QIn_[2], const tarch::la::Vector< DIMENSIONS, double > &faceCentre_, const tarch::la::Vector< DIMENSIONS, double > &faceSize_, double t_, double dt_, outType *QOut_[2], tarch::MemoryLocation memoryLocation_=tarch::MemoryLocation::Heap, int targetDevice_=tarch::accelerator::Device::DefaultDevice)
Construct patch data object for one single cell.
Definition LRFaceData.h:100
const int targetDevice
We might want to allocate data on an accelerator, therefore we save the target device id.
Definition LRFaceData.h:55
tarch::la::Vector< DIMENSIONS, double > * faceSize
Definition LRFaceData.h:27
inType *(* QIn)[2]
QIn may not be const, as some kernels delete it straightaway once the input data has been handled.
Definition LRFaceData.h:25
const tarch::MemoryLocation memoryLocation
We might want to allocate data on the heap or an accelerator, therefore we save the target device id.
Definition LRFaceData.h:49
int * id
Id of underlying task.
Definition LRFaceData.h:37
FaceData & operator=(const FaceData &)=delete
FaceData(const FaceData &copy)=delete
tarch::la::Vector< DIMENSIONS, double > * faceCentre
Definition LRFaceData.h:26
std::string toString() const
Definition LRFaceData.h:174
outType *(* QOut)[2]
Out values.
Definition LRFaceData.h:60
const int numberOfFaces
As we store data as SoA, we have to know how big the actual arrays are.
Definition LRFaceData.h:43