|
| 1 | +#define AOS_BOOST |
| 2 | + |
| 3 | +#include <memory> |
| 4 | + |
| 5 | +#include "benchmark.h" |
| 6 | +#include "boost/SoALayout.h" |
| 7 | +#include <Eigen/Core> |
| 8 | + |
| 9 | +GENERATE_SOA_LAYOUT(SoALayout, |
| 10 | + SOA_COLUMN(int, x0), |
| 11 | + SOA_COLUMN(int, x1)) |
| 12 | + |
| 13 | +using SoA = SoALayout<>; |
| 14 | +using AoS = SoA::AoSWrapper; |
| 15 | + |
| 16 | +GENERATE_SOA_LAYOUT(MediumSoALayout, |
| 17 | + SOA_COLUMN(float, x0), |
| 18 | + SOA_COLUMN(float, x1), |
| 19 | + SOA_COLUMN(double, x2), |
| 20 | + SOA_COLUMN(double, x3), |
| 21 | + SOA_COLUMN(int, x4), |
| 22 | + SOA_COLUMN(int, x5), |
| 23 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x6), |
| 24 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x7), |
| 25 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x8), |
| 26 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x9)) |
| 27 | + |
| 28 | +using MediumSoA = MediumSoALayout<>; |
| 29 | +using MediumAoS = MediumSoA::AoSWrapper; |
| 30 | + |
| 31 | +GENERATE_SOA_LAYOUT(ModerateSoALayout, |
| 32 | + SOA_COLUMN(float, x0), |
| 33 | + SOA_COLUMN(float, x1), |
| 34 | + SOA_COLUMN(float, x2), |
| 35 | + SOA_COLUMN(float, x3), |
| 36 | + SOA_COLUMN(float, x4), |
| 37 | + SOA_COLUMN(float, x5), |
| 38 | + SOA_COLUMN(float, x6), |
| 39 | + SOA_COLUMN(float, x7), |
| 40 | + SOA_COLUMN(float, x8), |
| 41 | + SOA_COLUMN(float, x9), |
| 42 | + SOA_COLUMN(float, x10), |
| 43 | + SOA_COLUMN(float, x11), |
| 44 | + SOA_COLUMN(float, x12), |
| 45 | + SOA_COLUMN(double, x13), |
| 46 | + SOA_COLUMN(double, x14), |
| 47 | + SOA_COLUMN(double, x15), |
| 48 | + SOA_COLUMN(double, x16), |
| 49 | + SOA_COLUMN(double, x17), |
| 50 | + SOA_COLUMN(double, x18), |
| 51 | + SOA_COLUMN(double, x19), |
| 52 | + SOA_COLUMN(double, x20), |
| 53 | + SOA_COLUMN(double, x21), |
| 54 | + SOA_COLUMN(double, x22), |
| 55 | + SOA_COLUMN(double, x23), |
| 56 | + SOA_COLUMN(double, x24), |
| 57 | + SOA_COLUMN(double, x25), |
| 58 | + SOA_COLUMN(int, x26), |
| 59 | + SOA_COLUMN(int, x27), |
| 60 | + SOA_COLUMN(int, x28), |
| 61 | + SOA_COLUMN(int, x29), |
| 62 | + SOA_COLUMN(int, x30), |
| 63 | + SOA_COLUMN(int, x31)) |
| 64 | + |
| 65 | +using ModerateSoA = ModerateSoALayout<>; |
| 66 | +using ModerateAoS = ModerateSoA::AoSWrapper; |
| 67 | + |
| 68 | +GENERATE_SOA_LAYOUT(BigSoALayout, |
| 69 | + SOA_COLUMN(float, x0), |
| 70 | + SOA_COLUMN(float, x1), |
| 71 | + SOA_COLUMN(float, x2), |
| 72 | + SOA_COLUMN(float, x3), |
| 73 | + SOA_COLUMN(float, x4), |
| 74 | + SOA_COLUMN(float, x5), |
| 75 | + SOA_COLUMN(float, x6), |
| 76 | + SOA_COLUMN(float, x7), |
| 77 | + SOA_COLUMN(float, x8), |
| 78 | + SOA_COLUMN(float, x9), |
| 79 | + SOA_COLUMN(float, x10), |
| 80 | + SOA_COLUMN(float, x11), |
| 81 | + SOA_COLUMN(float, x12), |
| 82 | + SOA_COLUMN(double, x13), |
| 83 | + SOA_COLUMN(double, x14), |
| 84 | + SOA_COLUMN(double, x15), |
| 85 | + SOA_COLUMN(double, x16), |
| 86 | + SOA_COLUMN(double, x17), |
| 87 | + SOA_COLUMN(double, x18), |
| 88 | + SOA_COLUMN(double, x19), |
| 89 | + SOA_COLUMN(double, x20), |
| 90 | + SOA_COLUMN(double, x21), |
| 91 | + SOA_COLUMN(double, x22), |
| 92 | + SOA_COLUMN(double, x23), |
| 93 | + SOA_COLUMN(double, x24), |
| 94 | + SOA_COLUMN(double, x25), |
| 95 | + SOA_COLUMN(int, x26), |
| 96 | + SOA_COLUMN(int, x27), |
| 97 | + SOA_COLUMN(int, x28), |
| 98 | + SOA_COLUMN(int, x29), |
| 99 | + SOA_COLUMN(int, x30), |
| 100 | + SOA_COLUMN(int, x31), |
| 101 | + SOA_COLUMN(int, x32), |
| 102 | + SOA_COLUMN(int, x33), |
| 103 | + SOA_COLUMN(int, x34), |
| 104 | + SOA_COLUMN(int, x35), |
| 105 | + SOA_COLUMN(int, x36), |
| 106 | + SOA_COLUMN(int, x37), |
| 107 | + SOA_COLUMN(int, x38), |
| 108 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x39), |
| 109 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x40), |
| 110 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x41), |
| 111 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x42), |
| 112 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x43), |
| 113 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x44), |
| 114 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x45), |
| 115 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x46), |
| 116 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x47), |
| 117 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x48), |
| 118 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x49), |
| 119 | + SOA_EIGEN_COLUMN(Eigen::Vector3d, x50), |
| 120 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x51), |
| 121 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x52), |
| 122 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x53), |
| 123 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x54), |
| 124 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x55), |
| 125 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x56), |
| 126 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x57), |
| 127 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x58), |
| 128 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x59), |
| 129 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x60), |
| 130 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x61), |
| 131 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x62), |
| 132 | + SOA_EIGEN_COLUMN(Eigen::Matrix3d, x63)) |
| 133 | + |
| 134 | +using BigSoA = BigSoALayout<>; |
| 135 | +using BigAoS = BigSoA::AoSWrapper; |
| 136 | + |
| 137 | +GENERATE_SOA_LAYOUT(SoANbodyLayout, |
| 138 | + SOA_COLUMN(float, x), |
| 139 | + SOA_COLUMN(float, y), |
| 140 | + SOA_COLUMN(float, z), |
| 141 | + SOA_COLUMN(float, vx), |
| 142 | + SOA_COLUMN(float, vy), |
| 143 | + SOA_COLUMN(float, vz)) |
| 144 | + |
| 145 | +using SoANbody = SoANbodyLayout<>; |
| 146 | +using NbodyAoS = SoANbody::AoSWrapper; |
| 147 | + |
| 148 | +GENERATE_SOA_LAYOUT(Stencil, |
| 149 | + SOA_COLUMN(double, src), |
| 150 | + SOA_COLUMN(double, dst), |
| 151 | + SOA_COLUMN(double, rhs)) |
| 152 | + |
| 153 | +using SoAStencil = Stencil<>; |
| 154 | +using StencilAoS = SoAStencil::AoSWrapper; |
| 155 | + |
| 156 | +GENERATE_SOA_LAYOUT(PxPyPzM, |
| 157 | + SOA_COLUMN(double, x), |
| 158 | + SOA_COLUMN(double, y), |
| 159 | + SOA_COLUMN(double, z), |
| 160 | + SOA_COLUMN(double, M)) |
| 161 | + |
| 162 | +using SoAPxPyPzM = PxPyPzM<>; |
| 163 | +using PxPyPzMAoS = SoAPxPyPzM::AoSWrapper; |
| 164 | + |
| 165 | +/// Register Benchmarks /// |
| 166 | +template <typename AoS, typename N> |
| 167 | +class Fixture1 : public benchmark::Fixture { |
| 168 | + public: |
| 169 | + std::byte *buffer; |
| 170 | + using AoSView = AoS::View; |
| 171 | + AoSView t; |
| 172 | + |
| 173 | + static constexpr auto n = N::value; |
| 174 | + |
| 175 | + void SetUp(::benchmark::State &state /* unused */) override |
| 176 | + { |
| 177 | + buffer = reinterpret_cast<std::byte *>(aligned_alloc(Alignment, AoS::computeDataSize(n))); |
| 178 | + AoS aos(buffer, n); |
| 179 | + t = AoSView{aos}; |
| 180 | + } |
| 181 | + |
| 182 | + void TearDown(::benchmark::State &state /* unused */) override { std::free(buffer); } |
| 183 | +}; |
| 184 | + |
| 185 | +INSTANTIATE_BENCHMARKS_F1(BM_CPUEasyRW, AoS, N_Large); |
| 186 | +INSTANTIATE_BENCHMARKS_F1(BM_CPUEasyCompute, AoS, N); |
| 187 | +INSTANTIATE_BENCHMARKS_F1(BM_CPURealRW, MediumAoS, N); |
| 188 | +INSTANTIATE_BENCHMARKS_F1(BM_CPUStrided, ModerateAoS, N_Large); |
| 189 | +INSTANTIATE_BENCHMARKS_F1(BM_CPUHardRW, BigAoS, N); |
| 190 | +INSTANTIATE_BENCHMARKS_F1(BM_nbody, NbodyAoS, N); |
| 191 | +INSTANTIATE_BENCHMARKS_F1(BM_stencil, StencilAoS, N_Large); |
| 192 | + |
| 193 | +template <typename AoS1, typename AoS2, typename N> |
| 194 | +class Fixture2 : public benchmark::Fixture { |
| 195 | + public: |
| 196 | + std::byte *buffer1, *buffer2; |
| 197 | + using AoSView1 = AoS1::View; |
| 198 | + using AoSView2 = AoS2::View; |
| 199 | + |
| 200 | + AoSView1 t1; |
| 201 | + AoSView2 t2; |
| 202 | + |
| 203 | + static constexpr auto n = N::value; |
| 204 | + |
| 205 | + void SetUp(::benchmark::State &state /* unused */) override |
| 206 | + { |
| 207 | + buffer1 = reinterpret_cast<std::byte *>(aligned_alloc(Alignment, AoS1::computeDataSize(n))); |
| 208 | + buffer2 = reinterpret_cast<std::byte *>(aligned_alloc(Alignment, AoS2::computeDataSize(n))); |
| 209 | + AoS1 aos1(buffer1, n); |
| 210 | + AoS2 aos2(buffer2, n); |
| 211 | + t1 = AoSView1{aos1}; |
| 212 | + t2 = AoSView2{aos2}; |
| 213 | + } |
| 214 | + |
| 215 | + void TearDown(::benchmark::State &state /* unused */) override |
| 216 | + { |
| 217 | + std::free(buffer1); |
| 218 | + std::free(buffer2); |
| 219 | + } |
| 220 | +}; |
| 221 | + |
| 222 | +INSTANTIATE_BENCHMARKS_F2(BM_InvariantMass, PxPyPzMAoS, PxPyPzMAoS, N_Large); |
| 223 | + |
| 224 | +BENCHMARK_MAIN(); |
0 commit comments