summaryrefslogtreecommitdiff
path: root/tangle/benchmark-ldc.cu
diff options
context:
space:
mode:
authorAdrian Kummerlaender2021-05-17 00:15:33 +0200
committerAdrian Kummerlaender2021-05-17 00:15:33 +0200
commit4ec94c97879aafef15f7663135745e4ba61e62cf (patch)
tree322ae3f003892513f529842ff0b3fd100573b680 /tangle/benchmark-ldc.cu
downloadLiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.tar
LiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.tar.gz
LiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.tar.bz2
LiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.tar.lz
LiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.tar.xz
LiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.tar.zst
LiterateLB-4ec94c97879aafef15f7663135745e4ba61e62cf.zip
Extract first public LiterateLB version
Diffstat (limited to 'tangle/benchmark-ldc.cu')
-rw-r--r--tangle/benchmark-ldc.cu95
1 files changed, 95 insertions, 0 deletions
diff --git a/tangle/benchmark-ldc.cu b/tangle/benchmark-ldc.cu
new file mode 100644
index 0000000..2443afe
--- /dev/null
+++ b/tangle/benchmark-ldc.cu
@@ -0,0 +1,95 @@
+#include <LLBM/base.h>
+
+#include <LLBM/kernel/collide.h>
+#include <LLBM/kernel/bounce_back.h>
+#include <LLBM/kernel/bounce_back_moving_wall.h>
+
+#include "util/timer.h"
+
+#include <iostream>
+
+using DESCRIPTOR = descriptor::D3Q19;
+
+template <typename T>
+void simulate(descriptor::Cuboid<DESCRIPTOR> cuboid, std::size_t nStep) {
+ cudaSetDevice(0);
+
+ Lattice<DESCRIPTOR,T> lattice(cuboid);
+
+ CellMaterials<DESCRIPTOR> materials(cuboid, [&cuboid](uint3 p) -> int {
+ if (p.x == 0 || p.x == cuboid.nX-1 || p.y == 0 || p.y == cuboid.nY-1 || p.z == 0) {
+ return 2; // boundary cell
+ } else if (p.z == cuboid.nZ-1) {
+ return 3; // lid cell
+ } else {
+ return 1; // bulk
+ }
+ });
+
+ auto bulk_mask = materials.mask_of_material(1);
+ auto box_mask = materials.mask_of_material(2);
+ auto lid_mask = materials.mask_of_material(3);
+
+ auto bulk_cells = materials.list_of_material(1);
+ auto box_cells = materials.list_of_material(2);
+ auto lid_cells = materials.list_of_material(3);
+
+ lattice.template apply<InitializeO>(bulk_cells);
+ lattice.template apply<InitializeO>(box_cells);
+ lattice.template apply<InitializeO>(lid_cells);
+
+ cudaDeviceSynchronize();
+
+ for (std::size_t iStep=0; iStep < 100; ++iStep) {
+ lattice.apply(Operator(BgkCollideO(), bulk_mask, 0.56),
+ Operator(BounceBackO(), box_mask),
+ Operator(BounceBackMovingWallO(), lid_mask, 0.05f, 0.f, 0.f));
+ lattice.stream();
+ }
+
+ cudaDeviceSynchronize();
+
+ auto start = timer::now();
+
+ for (std::size_t iStep=0; iStep < nStep; ++iStep) {
+ lattice.apply(Operator(BgkCollideO(), bulk_mask, 0.56),
+ Operator(BounceBackO(), box_mask),
+ Operator(BounceBackMovingWallO(), lid_mask, 0.05f, 0.f, 0.f));
+ lattice.stream();
+ }
+
+ cudaDeviceSynchronize();
+
+ auto mlups = timer::mlups(cuboid.volume, nStep, start);
+
+ std::cout << sizeof(T) << ", " << cuboid.nX << ", " << nStep << ", " << mlups << std::endl;
+}
+
+int main(int argc, char* argv[]) {
+ if (argc < 3 || argc > 4) {
+ std::cerr << "Invalid parameter count" << std::endl;
+ return -1;
+ }
+
+ const std::size_t n = atoi(argv[1]);
+ const std::size_t steps = atoi(argv[2]);
+
+ unsigned precision = 4;
+ if (argc == 4) {
+ precision = atoi(argv[3]);
+ }
+
+ switch (precision) {
+ case 4:
+ simulate<float>({ n, n, n}, steps);
+ break;
+ case 8:
+ simulate<double>({ n, n, n}, steps);
+ break;
+ default:
+ std::cerr << "Invalid precision" << std::endl;
+ return -1;
+ }
+
+ return 0;
+}