-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_simple_grid.py
More file actions
140 lines (113 loc) · 3.81 KB
/
Copy pathrun_simple_grid.py
File metadata and controls
140 lines (113 loc) · 3.81 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import argparse
import numpy as np
from os import path
from pathlib import Path
from icon4py.model.common.grid.grid_manager import ( # type: ignore [import-not-found]
GridManager,
IndexTransformation,
)
from icon4py.model.common.grid.vertical import VerticalGridSize # type: ignore [import-not-found]
from icon4py.model.common.dimension import E2C2VDim # type: ignore [import-not-found]
import icon_benchmark # type: ignore [import-not-found]
def init_grid_manager(fname, num_levels=65):
grid_manager = GridManager(
IndexTransformation(), fname, VerticalGridSize(num_levels)
)
grid_manager()
return grid_manager
def get_torus_grid(filename, num_levels):
grid_manager = init_grid_manager(filename, num_levels)
grid_manager()
simple_grid = grid_manager.get_grid()
return simple_grid
def parse_arguments():
parser = argparse.ArgumentParser()
parser.add_argument("grid", help="SimpleGrid netCDF4 file")
parser.add_argument("--klevels", type=int, default=65, help="Number of k levels")
parser.add_argument(
"--repetitions", type=int, default=101, help="Number of repetitions"
)
parser.add_argument(
"--dry-run", default=False, help="Do a dry run or not", action="store_true"
)
return parser.parse_args()
def run_benchmarks():
args = parse_arguments()
torus_grid = get_torus_grid(args.grid, args.klevels)
repetitions = args.repetitions
dry_runs = 1 if args.dry_run else 0
print(
"CellsDim: {} VertexDim: {} EdgeDim: {} KDim: {} E2C2VDim: {}".format(
torus_grid.num_cells,
torus_grid.num_vertices,
torus_grid.num_edges,
torus_grid.num_levels,
torus_grid.size[E2C2VDim],
)
)
unstructured_naive_runtimes = icon_benchmark.nabla4_benchmark_unstructured_naive(
torus_grid.get_offset_provider("E2C2V").table,
torus_grid.get_offset_provider("E2ECV").table,
torus_grid.num_cells,
torus_grid.num_vertices,
torus_grid.num_edges,
torus_grid.num_levels,
torus_grid.size[E2C2VDim],
repetitions,
dry_runs,
)
print(
"unstructured naive median runtime: {}".format(
np.median(unstructured_naive_runtimes)
)
)
structured_simple_naive_runtimes = (
icon_benchmark.nabla4_benchmark_structured_simple_naive(
torus_grid.num_cells,
torus_grid.num_vertices,
torus_grid.num_edges,
torus_grid.num_levels,
torus_grid.size[E2C2VDim],
repetitions,
dry_runs,
)
)
print(
"structured SimpleGrid naive median runtime: {}".format(
np.median(structured_simple_naive_runtimes)
)
)
structured_simple_cpu_ifirst_runtimes = (
icon_benchmark.nabla4_benchmark_structured_simple_cpu_ifirst(
torus_grid.num_cells,
torus_grid.num_vertices,
torus_grid.num_edges,
torus_grid.num_levels,
torus_grid.size[E2C2VDim],
repetitions,
dry_runs,
)
)
print(
"structured SimpleGrid cpu_ifirst median runtime: {}".format(
np.median(structured_simple_cpu_ifirst_runtimes)
)
)
structured_simple_cpu_kfirst_runtimes = (
icon_benchmark.nabla4_benchmark_structured_simple_cpu_kfirst(
torus_grid.num_cells,
torus_grid.num_vertices,
torus_grid.num_edges,
torus_grid.num_levels,
torus_grid.size[E2C2VDim],
repetitions,
dry_runs,
)
)
print(
"structured SimpleGrid cpu_kfirst median runtime: {}".format(
np.median(structured_simple_cpu_kfirst_runtimes)
)
)
if __name__ == "__main__":
run_benchmarks()