Peano
Loading...
Searching...
No Matches
CellFaceData.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 CellFaceData {
25 inType* (*QIn)[2 * DIMENSIONS];
26 tarch::la::Vector<DIMENSIONS, double>* cellCentre;
27 tarch::la::Vector<DIMENSIONS, double>* cellSize;
28
29 double* t;
30 double* dt;
31
37 int* id;
38
43 const int numberOfCells;
44
49 const tarch::MemoryLocation memoryLocation;
50
55 const int targetDevice;
56
60 outType* (*QOut)[2 * DIMENSIONS];
61
73 inType* QIn_[2 * DIMENSIONS],
74 const tarch::la::Vector<DIMENSIONS, double>& cellCentre_,
75 const tarch::la::Vector<DIMENSIONS, double>& cellSize_,
76 double t_,
77 double dt_,
78 outType* QOut_[2 * DIMENSIONS],
79 tarch::MemoryLocation memoryLocation_ = tarch::MemoryLocation::Heap,
80 int targetDevice_ = tarch::accelerator::Device::DefaultDevice
81 );
82
84 int numberOfCells_,
85 tarch::MemoryLocation memoryLocation_ = tarch::MemoryLocation::Heap,
86 int targetDevice_ = tarch::accelerator::Device::DefaultDevice
87 );
88
89 CellFaceData(const CellFaceData& copy) = delete;
91
93
94 std::string toString() const;
95 };
96} // namespace exahype2
97
98template <typename inType, typename outType>
100 inType* QIn_[2 * DIMENSIONS],
101 const tarch::la::Vector<DIMENSIONS, double>& cellCentre_,
102 const tarch::la::Vector<DIMENSIONS, double>& cellSize_,
103 double t_,
104 double dt_,
105 outType* QOut_[2 * DIMENSIONS],
106 tarch::MemoryLocation memoryLocation_,
107 int targetDevice_
108):
109 CellFaceData(1, memoryLocation_, targetDevice_) {
110 QIn[0] = QIn_;
111 cellCentre[0] = cellCentre_;
112 cellSize[0] = cellSize_;
113 t[0] = t_;
114 dt[0] = dt_;
115 QOut[0] = QOut_;
116 id[0] = -1;
117}
118
119template <typename inType, typename outType>
121 CellFaceData(int numberOfCells_, tarch::MemoryLocation memoryLocation_, int targetDevice_):
122 numberOfCells(numberOfCells_),
123 memoryLocation(memoryLocation_),
124 targetDevice(targetDevice_) {
125
126 QIn = reinterpret_cast<inType* (*)[2 * DIMENSIONS]>(tarch::accelerator::MemoryManager::getInstance().allocate<inType*>(
127 2 * DIMENSIONS * numberOfCells_,
128 memoryLocation_,
129 targetDevice_
130 ));
131 cellCentre = tarch::accelerator::MemoryManager::getInstance().allocate<tarch::la::Vector<DIMENSIONS, double>>(
132 numberOfCells_,
133 memoryLocation_,
134 targetDevice_
135 );
136 cellSize = tarch::accelerator::MemoryManager::getInstance().allocate<tarch::la::Vector<DIMENSIONS, double>>(
137 numberOfCells_,
138 memoryLocation_,
139 targetDevice_
140 );
141 t = tarch::accelerator::MemoryManager::getInstance().allocate<double>(numberOfCells_, memoryLocation_, targetDevice_);
142 dt = tarch::accelerator::MemoryManager::getInstance().allocate<double>(
143 numberOfCells_,
144 memoryLocation_,
145 targetDevice_
146 );
147 id = tarch::accelerator::MemoryManager::getInstance().allocate<int>(numberOfCells_, memoryLocation_, targetDevice_);
148 QOut = reinterpret_cast<inType* (*)[2 * DIMENSIONS]>(tarch::accelerator::MemoryManager::getInstance().allocate<outType*>(
149 2 * DIMENSIONS * numberOfCells_,
150 memoryLocation_,
151 targetDevice_
152 ));
153}
154
155template <typename inType, typename outType> exahype2::CellFaceData<inType, outType>::~CellFaceData() {
156 // tarch::freeMemory(QIn, memoryLocation, targetDevice);
157 // tarch::freeMemory(cellCentre, memoryLocation, targetDevice);
158 // tarch::freeMemory(cellSize, memoryLocation, targetDevice);
159 // tarch::freeMemory(t, memoryLocation, targetDevice);
160 // tarch::freeMemory(dt, memoryLocation, targetDevice);
161 // tarch::freeMemory(QOut, memoryLocation, targetDevice);
162 // tarch::freeMemory(id, memoryLocation, targetDevice);
163
164 tarch::accelerator::MemoryManager::getInstance().free(QIn, targetDevice);
165 tarch::accelerator::MemoryManager::getInstance().free(cellCentre, targetDevice);
166 tarch::accelerator::MemoryManager::getInstance().free(cellSize, targetDevice);
167 tarch::accelerator::MemoryManager::getInstance().free(t, targetDevice);
168 tarch::accelerator::MemoryManager::getInstance().free(dt, targetDevice);
169 tarch::accelerator::MemoryManager::getInstance().free(QOut, targetDevice);
170 tarch::accelerator::MemoryManager::getInstance().free(id, targetDevice);
171}
172
173template <typename inType, typename outType> std::string exahype2::CellFaceData<inType, outType>::toString() const {
174 std::ostringstream msg;
175 msg << "[";
176 for (int i = 0; i < numberOfCells; i++) {
177 msg << "(x=" << cellCentre[i] << ",h=" << cellSize[i] << ",t=" << t[i] << ",dt=" << dt[i] << ",id=" << id[i] << ")";
178 }
179 msg << "]";
180 return msg.str();
181}
tarch::la::Vector< DIMENSIONS, double > * cellSize
tarch::la::Vector< DIMENSIONS, double > * cellCentre
CellFaceData(inType *QIn_[2 *DIMENSIONS], const tarch::la::Vector< DIMENSIONS, double > &cellCentre_, const tarch::la::Vector< DIMENSIONS, double > &cellSize_, double t_, double dt_, outType *QOut_[2 *DIMENSIONS], tarch::MemoryLocation memoryLocation_=tarch::MemoryLocation::Heap, int targetDevice_=tarch::accelerator::Device::DefaultDevice)
Construct patch data object for one single cell.
const int targetDevice
We might want to allocate data on an accelerator, therefore we save the target device id.
int * id
Id of underlying task.
outType *(* QOut)[2 *DIMENSIONS]
Out values.
const tarch::MemoryLocation memoryLocation
We might want to allocate data on the heap or an accelerator, therefore we save the target device id.
CellFaceData(const CellFaceData &copy)=delete
std::string toString() const
inType *(* QIn)[2 *DIMENSIONS]
QIn may not be const, as some kernels delete it straightaway once the input data has been handled.
CellFaceData & operator=(const CellFaceData &)=delete
const int numberOfCells
As we store data as SoA, we have to know how big the actual arrays are.