Peano
Loading...
Searching...
No Matches
CellData.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 "tarch/la/Vector.h"
7#include "config.h"
9
10#include <functional>
11#include <string>
12
13namespace exahype2 {
77 template<typename inType=double, typename outType=double>
78 struct CellData {
83 inType** QIn;
86
87 double* t;
88 double* dt;
94 int* id;
95
100 const int numberOfCells;
101
107
112 const int targetDevice;
113
117 outType** QOut;
118
123
124
136 inType* QIn_,
137 const tarch::la::Vector<Dimensions,double>& cellCentre_,
139 double t_,
140 double dt_,
141 outType* QOut_,
144 );
145
147 int numberOfCells_,
150 );
151
152 CellData(const CellData<inType,outType>& copy) = delete;
153
155
156 std::string toString() const;
157
158 static int in(int index[Dimensions+2]);
159 static int out(int index[Dimensions+2]);
160 };
161
162// using CellData = CellData<double, double>;
163
186 template<typename inType=double, typename outType=double>
188 /*
189 See CellData for meaning of member variables.
190 The only change is changing QIn and QOut from 2D arrays to 1D.
191 */
192
193 inType* QIn;
196 double* t;
197 double* dt;
198 int* id;
199 const int numberOfCells;
201 const int targetDevice;
202 outType* QOut;
204
205 inType** QInHost;
206 outType** QOutHost;
208
216 const CellData<inType, outType>& cellData,
217 int inputPatchSize,
218 int outputPatchSize,
220 int currentPatchDevice = tarch::accelerator::Device::HostDevice
221 );
224
225 std::string toString() const;
226
229 };
230
231 template <typename inType=double, typename outType=double>
233 /*
234 See CellData for meaning of member variables.
235 The only change is changing QIn and QOut from 2D arrays to 1D.
236 */
237
238 // These fields must be represented in Python also
239 inType* QIn;
240 outType* QOut;
243 double* t;
244 double* dt;
246 const int64_t numberOfCells;
247
249 const CellData<inType, outType>& cellData,
250 int inputPatchSize,
251 int outputPatchSize
252 );
254
255 std::string toString() const;
256
259
260 inType** QInNested;
261 outType** QOutNested;
262 };
263
264 // MLIR memref descriptor struct definition
265 // Matches the LLVM struct layout: {T* allocated, T* aligned, i64 offset, i64 sizes[N], i64 strides[N]}
266
267 template<typename T, int Rank>
269 T* allocated; // Pointer to allocated memory
270 T* aligned; // Pointer to aligned data (usually same as allocated)
271 int64_t offset; // Offset in elements from aligned pointer
272 int64_t sizes[Rank]; // Size of each dimension
273 int64_t strides[Rank]; // Stride of each dimension
274
275 // Constructor for easy initialization
276 MemRefDescriptor() : allocated(nullptr), aligned(nullptr), offset(0) {
277 for (int i = 0; i < Rank; ++i) {
278 sizes[i] = 0;
279 strides[i] = 0;
280 }
281 }
282 };
283
284 // Convenience typedefs for common cases
285 // MemRefDescriptor represent 1 and two dimensions respectively using a flat 1D array, akin to double*
286 // In contrast, MemRefDescriptorNested uses a nested array, akin to double**
290
291 inline MemRefDescriptor1D createMemRefDescriptor1D(double* data, int64_t size) {
293 desc.allocated = data;
294 desc.aligned = data;
295 desc.offset = 0;
296 desc.sizes[0] = size;
297 desc.strides[0] = 1; // Stride between elements
298 return desc;
299 }
300
301 inline MemRefDescriptor2D createMemRefDescriptor2D(double** data, int64_t rows, int64_t cols) {
303 double* flattenedInput = new double[rows * cols];
304 for (int64_t i = 0; i < rows; ++i) {
305 std::memcpy(
306 flattenedInput + i * cols,
307 data[i],
308 static_cast<std::size_t>(cols) * sizeof(double)
309 );
310 }
311 desc.allocated = flattenedInput;
312 desc.aligned = flattenedInput;
313 desc.offset = 0;
314 desc.sizes[0] = rows;
315 desc.sizes[1] = cols;
316 desc.strides[0] = cols; // Stride between rows
317 desc.strides[1] = 1; // Stride between columns
318 return desc;
319 }
320
321 inline MemRefDescriptorNested createMemRefDescriptorNested(double** data, int64_t rows, int64_t cols) {
323 MemRefDescriptor1D* nestedInput = new MemRefDescriptor1D[rows];
324 for (int64_t i = 0; i < rows; ++i) {
325 nestedInput[i] = createMemRefDescriptor1D(data[i], cols);
326 }
327 desc.allocated = nestedInput;
328 desc.aligned = nestedInput;
329 desc.offset = 0;
330 desc.sizes[0] = rows;
331 desc.strides[0] = 1; // Stride between rows
332 return desc;
333 }
334
336 /*
337 See CellData for meaning of member variables.
338 The only change is changing QIn and QOut from 2D arrays to 1D.
339 */
340
341 // These fields must be represented in Python also
349 const int64_t numberOfCells;
350
352 const CellData<double, double>& cellData,
353 int inputPatchSize,
354 int outputPatchSize
355 );
357
358 std::string toString() const;
359
362
363 double** QInNested;
364 double** QOutNested;
365 };
366
368 /*
369 See CellData for meaning of member variables.
370 The only change is changing QIn and QOut from 2D arrays to 1D.
371 */
372
373 // These fields must be represented in Python also
381 const int64_t numberOfCells;
382
384 const CellData<double, double>& cellData,
385 int inputPatchSize,
386 int outputPatchSize
387 );
389
390 std::string toString() const;
391
394
395 double** QInNested;
396 double** QOutNested;
397 };
398
399}
400
401#include "CellData.cpph"
static constexpr int HostDevice
Accelerator devices (GPUs) are enumerated starting from 0.
Definition Device.h:48
This file is part of the ExaHyPE 2 project within Peano 4.
MemRefDescriptor< double, 2 > MemRefDescriptor2D
Definition CellData.h:288
MemRefDescriptor< MemRefDescriptor1D, 1 > MemRefDescriptorNested
Definition CellData.h:289
MemRefDescriptorNested createMemRefDescriptorNested(double **data, int64_t rows, int64_t cols)
Definition CellData.h:321
MemRefDescriptor< double, 1 > MemRefDescriptor1D
Definition CellData.h:287
MemRefDescriptor2D createMemRefDescriptor2D(double **data, int64_t rows, int64_t cols)
Definition CellData.h:301
MemRefDescriptor1D createMemRefDescriptor1D(double *data, int64_t size)
Definition CellData.h:291
MemoryLocation
Definition accelerator.h:58
@ Heap
Create data on the heap of the local device.
Definition accelerator.h:69
std::string toString() const
tarch::la::Vector< Dimensions, double > * cellSize
Definition CellData.h:242
CellDataFlattened(const CellData< inType, outType > &cellData, int inputPatchSize, int outputPatchSize)
const int64_t numberOfCells
Definition CellData.h:246
tarch::la::Vector< Dimensions, double > * cellCentre
Definition CellData.h:241
Representation of a number of cells which contains all information that's required to process the sto...
Definition CellData.h:78
outType ** QOut
Out values.
Definition CellData.h:117
const tarch::MemoryLocation memoryLocation
We might want to allocate data on the heap or an accelerator, therefore we save the target device id.
Definition CellData.h:106
static int out(int index[Dimensions+2])
inType ** QIn
QIn may not be const, as some kernels delete it straightaway once the input data has been handled.
Definition CellData.h:83
const int numberOfCells
As we store data as SoA, we have to know how big the actual arrays are.
Definition CellData.h:100
static int in(int index[Dimensions+2])
CellData(inType *QIn_, const tarch::la::Vector< Dimensions, double > &cellCentre_, const tarch::la::Vector< Dimensions, double > &cellSize_, double t_, double dt_, outType *QOut_, tarch::MemoryLocation memoryLocation_=tarch::MemoryLocation::Heap, int targetDevice_=tarch::accelerator::Device::HostDevice)
Construct patch data object for one single cell.
std::string toString() const
CellData(const CellData< inType, outType > &copy)=delete
int * id
Id of underlying task.
Definition CellData.h:94
const int targetDevice
We might want to allocate data on an accelerator, therefore we save the target device id.
Definition CellData.h:112
CellData(int numberOfCells_, tarch::MemoryLocation memoryLocation=tarch::MemoryLocation::Heap, int targetDevice=tarch::accelerator::Device::HostDevice)
double * maxEigenvalue
Out values.
Definition CellData.h:122
tarch::la::Vector< Dimensions, double > * cellCentre
Definition CellData.h:84
tarch::la::Vector< Dimensions, double > * cellSize
Definition CellData.h:85
const tarch::MemoryLocation memoryLocation
Definition CellData.h:200
tarch::la::Vector< Dimensions, double > * cellCentre
Definition CellData.h:194
tarch::la::Vector< Dimensions, double > * cellSize
Definition CellData.h:195
CopyCellDataGPU(const CellData< inType, outType > &cellData, int inputPatchSize, int outputPatchSize, int device=tarch::accelerator::Device::HostDevice, int currentPatchDevice=tarch::accelerator::Device::HostDevice)
Construct a copy object.
std::string toString() const
MemRefDescriptor1D maxEigenvalue
Definition CellData.h:348
MemRefDescriptor2D cellSize
Definition CellData.h:345
MLIRCellDataFlattened(const CellData< double, double > &cellData, int inputPatchSize, int outputPatchSize)
MemRefDescriptor2D QOut
Definition CellData.h:343
std::string toString() const
MemRefDescriptor2D cellCentre
Definition CellData.h:344
MLIRCellDataNested(const CellData< double, double > &cellData, int inputPatchSize, int outputPatchSize)
std::string toString() const
MemRefDescriptorNested QIn
Definition CellData.h:374
MemRefDescriptor1D t
Definition CellData.h:378
MemRefDescriptor1D maxEigenvalue
Definition CellData.h:380
MemRefDescriptor2D cellCentre
Definition CellData.h:376
MemRefDescriptor2D cellSize
Definition CellData.h:377
MemRefDescriptorNested QOut
Definition CellData.h:375
MemRefDescriptor1D dt
Definition CellData.h:379
const int64_t numberOfCells
Definition CellData.h:381
Simple vector class.
Definition Vector.h:159