summaryrefslogtreecommitdiff
path: root/tangle/benchmark-ldc.cu
blob: 18b30d14eeb9e38f1cd395e9e7741bb8002e27eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#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 T = float;
using DESCRIPTOR = descriptor::D3Q19;

void simulate(descriptor::Cuboid<DESCRIPTOR> cuboid, std::size_t nStep) {
  auto current = cuda::device::current::get();

  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);
  
  cuda::synchronize(current);

  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();
  }

  cuda::synchronize(current);

  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();
  }

  cuda::synchronize(current);

  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 (cuda::device::count() == 0) {
    std::cerr << "No CUDA devices on this system" << std::endl;
    return -1;
  }
  if (argc != 3) {
    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]);

  simulate({ n, n, n}, steps);

  return 0;
}