benchmark_cpu.py 3.35 KB
Newer Older
Markus Holzer's avatar
Markus Holzer committed
1
2
3
4
5
import os
import waLBerla as wlb
import pandas as pd

from waLBerla.tools.sqlitedb import sequenceValuesToScalars
Markus Holzer's avatar
Markus Holzer committed
6
from waLBerla.tools.config import block_decomposition
Markus Holzer's avatar
Markus Holzer committed
7
8
9
10
11

import sys


class Scenario:
Markus Holzer's avatar
Markus Holzer committed
12
13
    def __init__(self, time_step_strategy, cells_per_block=(256, 256, 256),
                 cuda_enabled_mpi=False):
Markus Holzer's avatar
Markus Holzer committed
14
        # output frequencies
Markus Holzer's avatar
Markus Holzer committed
15
        self.vtkWriteFrequency = 0
Markus Holzer's avatar
Markus Holzer committed
16
17

        # simulation parameters
Markus Holzer's avatar
Markus Holzer committed
18
19
20
        self.timesteps = 101
        self.cells_per_block = cells_per_block
        self.blocks = block_decomposition(wlb.mpi.numProcesses())
Markus Holzer's avatar
Markus Holzer committed
21
        self.periodic = (1, 1, 1)
Markus Holzer's avatar
Markus Holzer committed
22
23
24
        self.size = (self.cells_per_block[0] * self.blocks[0],
                     self.cells_per_block[1] * self.blocks[1],
                     self.cells_per_block[2] * self.blocks[2])
Markus Holzer's avatar
Markus Holzer committed
25

Markus Holzer's avatar
Markus Holzer committed
26
        self.timeStepStrategy = time_step_strategy
Markus Holzer's avatar
Markus Holzer committed
27
28
        self.warmupSteps = 10

Markus Holzer's avatar
Markus Holzer committed
29
30
        self.cudaEnabledMpi = cuda_enabled_mpi

Markus Holzer's avatar
Markus Holzer committed
31
32
33
34
35
36
        # bubble parameters
        self.bubbleRadius = min(self.size) // 4
        self.bubbleMidPoint = (self.size[0] / 2, self.size[1] / 2, self.size[2] / 2)

        self.config_dict = self.config()

Markus Holzer's avatar
Markus Holzer committed
37
        self.csv_file = "benchmark.csv"
Markus Holzer's avatar
Markus Holzer committed
38
39
40
41
42
43

    @wlb.member_callback
    def config(self):
        return {
            'DomainSetup': {
                'blocks': self.blocks,
Markus Holzer's avatar
Markus Holzer committed
44
                'cellsPerBlock': self.cells_per_block,
Markus Holzer's avatar
Markus Holzer committed
45
46
47
48
49
                'periodic': self.periodic,
            },
            'Parameters': {
                'timesteps': self.timesteps,
                'vtkWriteFrequency': self.vtkWriteFrequency,
Markus Holzer's avatar
Markus Holzer committed
50
                'remainingTimeLoggerFrequency': -1,
Markus Holzer's avatar
Markus Holzer committed
51
52
                'timeStepStrategy': self.timeStepStrategy,
                'warmupSteps': self.warmupSteps,
Markus Holzer's avatar
Markus Holzer committed
53
54
                'scenario': 1,
                'cudaEnabledMpi': self.cudaEnabledMpi
Markus Holzer's avatar
Markus Holzer committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
            },
            'Boundaries_GPU': {
                'Border': []
            },
            'Boundaries_CPU': {
                'Border': []
            },
            'Bubble': {
                'bubbleMidPoint': self.bubbleMidPoint,
                'bubbleRadius': self.bubbleRadius,
            },
        }

    @wlb.member_callback
    def results_callback(self, **kwargs):
        data = {}
        data.update(self.config_dict['Parameters'])
        data.update(self.config_dict['DomainSetup'])
        data.update(kwargs)
        data['executable'] = sys.argv[0]
        data['compile_flags'] = wlb.build_info.compiler_flags
        data['walberla_version'] = wlb.build_info.version
        data['build_machine'] = wlb.build_info.build_machine
        sequenceValuesToScalars(data)

        df = pd.DataFrame.from_records([data])
        if not os.path.isfile(self.csv_file):
            df.to_csv(self.csv_file, index=False)
        else:
            df.to_csv(self.csv_file, index=False, mode='a', header=False)


Markus Holzer's avatar
Markus Holzer committed
87
def benchmark():
Markus Holzer's avatar
Markus Holzer committed
88
    scenarios = wlb.ScenarioManager()
Markus Holzer's avatar
Markus Holzer committed
89
90
91
    block_size = (64, 64, 64)

    scenarios.add(Scenario(time_step_strategy='normal', cells_per_block=block_size))
Markus Holzer's avatar
Markus Holzer committed
92
93
94
95


def kernel_benchmark():
    scenarios = wlb.ScenarioManager()
Markus Holzer's avatar
Markus Holzer committed
96
    block_sizes = [(i, i, i) for i in (8, 16, 32, 64, 128)]
Markus Holzer's avatar
Markus Holzer committed
97

Markus Holzer's avatar
Markus Holzer committed
98
99
100
101
102
    for time_step_strategy in ['phase_only', 'hydro_only', 'kernel_only', 'normal']:
        for block_size in block_sizes:
            scenario = Scenario(time_step_strategy=time_step_strategy,
                                cells_per_block=block_size)
            scenarios.add(scenario)
Markus Holzer's avatar
Markus Holzer committed
103
104


Markus Holzer's avatar
Markus Holzer committed
105
# benchmark()
Markus Holzer's avatar
Markus Holzer committed
106
kernel_benchmark()