| 1 | // -------------------------------------------------------------------------- |
| 2 | // |
| 3 | // Copyright |
| 4 | // Markus Wittmann, 2016-2017 |
| 5 | // RRZE, University of Erlangen-Nuremberg, Germany |
| 6 | // markus.wittmann -at- fau.de or hpc -at- rrze.fau.de |
| 7 | // |
| 8 | // Viktor Haag, 2016 |
| 9 | // LSS, University of Erlangen-Nuremberg, Germany |
| 10 | // |
| 11 | // Michael Hussnaetter, 2017-2018 |
| 12 | // University of Erlangen-Nuremberg, Germany |
| 13 | // michael.hussnaetter -at- fau.de |
| 14 | // |
| 15 | // This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels). |
| 16 | // |
| 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. |
| 21 | // |
| 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. |
| 26 | // |
| 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/>. |
| 29 | // |
| 30 | // -------------------------------------------------------------------------- |
| 31 | #ifndef __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__ |
| 32 | #define __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__ |
| 33 | |
| 34 | |
| 35 | #include "Kernel.h" |
| 36 | |
| 37 | #include <inttypes.h> |
| 38 | |
| 39 | #define N_D3Q19_IDX 18 |
| 40 | |
| 41 | typedef struct KernelDataList_ |
| 42 | { |
| 43 | KernelData kd; |
| 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. |
| 52 | } KernelDataList; |
| 53 | |
| 54 | |
| 55 | // Macro for casting KernelData * to KernelDataList *. |
| 56 | #define KDL(_x_) ((KernelDataList *)(_x_)) |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 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)) |
| 65 | |
| 66 | #ifndef DATA_LAYOUT_NAME |
| 67 | #error DATA_LAYOUT_NAME must be defined |
| 68 | #endif |
| 69 | |
| 70 | #ifndef PROP_MODEL_NAME |
| 71 | #error PROP_MODEL_NAME must be defined |
| 72 | #endif |
| 73 | |
| 74 | // ----------------------------------------------------------------------- |
| 75 | // Index function for accesssing PDF array for different data layouts. |
| 76 | |
| 77 | #define P_INDEX_3 FNAME(PINDEX3) |
| 78 | |
| 79 | static inline int FNAME(PINDEX3)(int nCells, int cellIndex, int d) |
| 80 | { |
| 81 | Assert(nCells > 0); |
| 82 | Assert(cellIndex >= 0); |
| 83 | Assert(cellIndex < nCells); |
| 84 | |
| 85 | Assert(d >= 0); |
| 86 | #ifdef D3Q19 |
| 87 | Assert(d < N_D3Q19); |
| 88 | #else |
| 89 | #error Not implemented for this discretization. |
| 90 | #endif |
| 91 | |
| 92 | #ifdef DATA_LAYOUT_SOA |
| 93 | return d * nCells + cellIndex; |
| 94 | #elif DATA_LAYOUT_AOS |
| 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); |
| 100 | #else |
| 101 | #error P_INDEX_3 function not implemented for chosen data layout. |
| 102 | #endif |
| 103 | } |
| 104 | |
| 105 | #define P_INDEX_5 FNAME(PINDEX5) |
| 106 | |
| 107 | static inline int FNAME(PINDEX5)(KernelDataList * kdl, int x, int y, int z, int d) |
| 108 | { |
| 109 | Assert(kdl != NULL); |
| 110 | #ifdef DEBUG |
| 111 | uint32_t * grid = kdl->Grid; |
| 112 | int * dims = kdl->kd.Dims; |
| 113 | |
| 114 | Assert(grid != NULL); |
| 115 | Assert(dims != NULL); |
| 116 | Assert(dims[0] > 0); |
| 117 | Assert(dims[1] > 0); |
| 118 | Assert(dims[2] > 0); |
| 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); |
| 123 | #endif |
| 124 | |
| 125 | return P_INDEX_3(kdl->nCells, kdl->Grid[L_INDEX_4(kdl->kd.Dims, x, y, z)], d); |
| 126 | } |
| 127 | |
| 128 | // ----------------------------------------------------------------------- |
| 129 | // Macros for accessing coord array |
| 130 | |
| 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) |
| 134 | |
| 135 | static inline int C_INDEX(int cellIndex, int xyz) |
| 136 | { |
| 137 | Assert(cellIndex >= 0); |
| 138 | Assert(xyz >= 0); |
| 139 | Assert(xyz < 3); |
| 140 | |
| 141 | return cellIndex * 3 + xyz; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | #endif // __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__ |