1 // --------------------------------------------------------------------------
4 // Markus Wittmann, 2016-2017
5 // RRZE, University of Erlangen-Nuremberg, Germany
6 // markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
9 // LSS, University of Erlangen-Nuremberg, Germany
11 // Michael Hussnaetter, 2017-2018
12 // University of Erlangen-Nuremberg, Germany
13 // michael.hussnaetter -at- fau.de
15 // This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
17 // LbmBenchKernels is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
22 // LbmBenchKernels is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 // GNU General Public License for more details.
27 // You should have received a copy of the GNU General Public License
28 // along with LbmBenchKernels. If not, see <http://www.gnu.org/licenses/>.
30 // --------------------------------------------------------------------------
31 #ifndef __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__
32 #define __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__
39 #define N_D3Q19_IDX 18
41 typedef struct KernelDataList_
44 uint32_t * AdjList; // Stores PDF indices, which are the destination for propagation.
45 // Determine the destination for node index n and direction d via:
46 // (n * N_D3Q19_IDX) + d
47 uint32_t * Grid; // Stores the node indices; use L_INDEX_4 macro for access.
48 uint32_t * Coords; // Map node indices to coordiantes; use C_INDEX_* macro for access.
49 int nFluid; // Number of fluid nodes allocated, i.e. length of adjList * N_D3Q19_IDX.
50 int nCells; // Total number of nodes allocated, including nodes for padding!
51 int Iteration; // Current iteration, starts at 0.
55 // Macro for casting KernelData * to KernelDataList *.
56 #define KDL(_x_) ((KernelDataList *)(_x_))
61 // Build a function name extended by the propagation model name and the data layout.
62 // FNANEM(test) will be expanded to test_PushSoA if DATA_LAYOUT_NAME is defined
63 // as SoA and PROP_MODEL is defined as Push.
64 #define FNAME(functionName) JOIN(JOIN(functionName,_),JOIN(PROP_MODEL_NAME,DATA_LAYOUT_NAME))
66 #ifndef DATA_LAYOUT_NAME
67 #error DATA_LAYOUT_NAME must be defined
70 #ifndef PROP_MODEL_NAME
71 #error PROP_MODEL_NAME must be defined
74 // -----------------------------------------------------------------------
75 // Index function for accesssing PDF array for different data layouts.
77 #define P_INDEX_3 FNAME(PINDEX3)
79 static inline int FNAME(PINDEX3)(int nCells, int cellIndex, int d)
82 Assert(cellIndex >= 0);
83 Assert(cellIndex < nCells);
89 #error Not implemented for this discretization.
92 #ifdef DATA_LAYOUT_SOA
93 return d * nCells + cellIndex;
95 return cellIndex * N_D3Q19 + d;
96 #elif DATA_LAYOUT_AOSOA
97 return (cellIndex - (cellIndex % AOSOA_BLOCK_SIZE)) * N_D3Q19
98 + (d * AOSOA_BLOCK_SIZE)
99 + (cellIndex % AOSOA_BLOCK_SIZE);
101 #error P_INDEX_3 function not implemented for chosen data layout.
105 #define P_INDEX_5 FNAME(PINDEX5)
107 static inline int FNAME(PINDEX5)(KernelDataList * kdl, int x, int y, int z, int d)
111 uint32_t * grid = kdl->Grid;
112 int * dims = kdl->kd.Dims;
114 Assert(grid != NULL);
115 Assert(dims != NULL);
119 Assert(x >= 0 && x < dims[0]);
120 Assert(y >= 0 && y < dims[1]);
121 Assert(z >= 0 && z < dims[2]);
122 Assert(d >= 0 && d < N_D3Q19);
125 return P_INDEX_3(kdl->nCells, kdl->Grid[L_INDEX_4(kdl->kd.Dims, x, y, z)], d);
128 // -----------------------------------------------------------------------
129 // Macros for accessing coord array
131 #define C_INDEX_X(cellIndex) C_INDEX(cellIndex, 0)
132 #define C_INDEX_Y(cellIndex) C_INDEX(cellIndex, 1)
133 #define C_INDEX_Z(cellIndex) C_INDEX(cellIndex, 2)
135 static inline int C_INDEX(int cellIndex, int xyz)
137 Assert(cellIndex >= 0);
141 return cellIndex * 3 + xyz;
145 #endif // __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__