generate_automake_test_programs.py 11.4 KB
Newer Older
Wenzhe Yu's avatar
Wenzhe Yu committed
1
#!/usr/bin/env python3
2
3
from itertools import product

4
language_flag = {
5
    "Fortran": "",
6
    "C": "_c_version",
Andreas Marek's avatar
Andreas Marek committed
7
8
}

9
domain_flag = {
10
11
    "real":    "-DTEST_REAL",
    "complex": "-DTEST_COMPLEX",
12
13
}
prec_flag = {
14
15
    "double": "-DTEST_DOUBLE",
    "single": "-DTEST_SINGLE",
16
17
}
solver_flag = {
18
19
20
21
    "1stage":         "-DTEST_SOLVER_1STAGE",
    "2stage":         "-DTEST_SOLVER_2STAGE",
    "scalapack_all":  "-DTEST_SCALAPACK_ALL",
    "scalapack_part": "-DTEST_SCALAPACK_PART",
22
23
}
gpu_flag = {
24
25
    0: "-DTEST_GPU=0",
    1: "-DTEST_GPU=1",
26
}
27
28
29
30
gpu_id_flag = {
    0: "-DTEST_GPU_SET_ID=0",
    1: "-DTEST_GPU_SET_ID=1",
}
31

Pavel Kus's avatar
Pavel Kus committed
32
matrix_flag = {
33
34
35
36
    "random":   "-DTEST_MATRIX_RANDOM",
    "analytic": "-DTEST_MATRIX_ANALYTIC",
    "toeplitz": "-DTEST_MATRIX_TOEPLITZ",
    "frank":    "-DTEST_MATRIX_FRANK",
Andreas Marek's avatar
Andreas Marek committed
37
38
39
}

qr_flag = {
40
41
    0: "-DTEST_QR_DECOMPOSITION=0",
    1: "-DTEST_QR_DECOMPOSITION=1",
Pavel Kus's avatar
Pavel Kus committed
42
}
43

44
test_type_flag = {
45
46
47
48
49
    "eigenvectors":       "-DTEST_EIGENVECTORS",
    "eigenvalues":        "-DTEST_EIGENVALUES",
    "solve_tridiagonal":  "-DTEST_SOLVE_TRIDIAGONAL",
    "cholesky":           "-DTEST_CHOLESKY",
    "hermitian_multiply": "-DTEST_HERMITIAN_MULTIPLY",
50
    "generalized":        "-DTEST_GENERALIZED_EIGENPROBLEM",
51
    "generalized_decomp": "-DTEST_GENERALIZED_DECOMP_EIGENPROBLEM",
52
53
}

54
layout_flag = {
55
56
    "all_layouts": "-DTEST_ALL_LAYOUTS",
    "square": ""
57
58
}

59
60
61
62
63
split_comm_flag = {
    "myself": "-DSPLIT_COMM_MYSELF",
    "by_elpa": ""
}

64
for lang, m, g, gid, q, t, p, d, s, lay, spl in product(sorted(language_flag.keys()),
65
66
                                                   sorted(matrix_flag.keys()),
                                                   sorted(gpu_flag.keys()),
67
                                                   sorted(gpu_id_flag.keys()),
68
69
70
71
72
73
74
                                                   sorted(qr_flag.keys()),
                                                   sorted(test_type_flag.keys()),
                                                   sorted(prec_flag.keys()),
                                                   sorted(domain_flag.keys()),
                                                   sorted(solver_flag.keys()),
                                                   sorted(layout_flag.keys()),
                                                   sorted(split_comm_flag.keys())):
75

76
77
78
    if gid == 1 and (g == 0 ):
        continue

Andreas Marek's avatar
Andreas Marek committed
79
    if lang == "C" and (m == "analytic" or m == "toeplitz" or m == "frank" or lay == "all_layouts"):
Andreas Marek's avatar
Andreas Marek committed
80
81
        continue

82
83
84
85
    # not implemented in the test.c file yet
    if lang == "C" and (t == "cholesky" or t == "hermitian_multiply" or q == 1):
        continue

Andreas Marek's avatar
Andreas Marek committed
86
87
88
    # exclude some test combinations

    # analytic tests only for "eigenvectors" and not on GPU
Pavel Kus's avatar
Pavel Kus committed
89
    if(m == "analytic" and (g == 1 or t != "eigenvectors")):
Pavel Kus's avatar
Pavel Kus committed
90
91
        continue

Andreas Marek's avatar
Andreas Marek committed
92
    # Frank tests only for "eigenvectors" and eigenvalues and real double precision case
93
    if(m == "frank" and ((t != "eigenvectors" or t != "eigenvalues") and (d != "real" or p != "double"))):
Andreas Marek's avatar
Andreas Marek committed
94
95
        continue

96
    if(s in ["scalapack_all", "scalapack_part"] and (g == 1 or t != "eigenvectors" or m != "analytic")):
Pavel Kus's avatar
Pavel Kus committed
97
98
        continue

99
    # do not test single-precision scalapack
100
    if(s in ["scalapack_all", "scalapack_part"] and (p == "single")):
101
102
        continue

Andreas Marek's avatar
Andreas Marek committed
103
    # solve tridiagonal only for real toeplitz matrix in 1stage
104
    if (t == "solve_tridiagonal" and (s != "1stage" or d != "real" or m != "toeplitz")):
105
106
        continue

107
108
109
110
    # solve generalized only for random matrix in 1stage
    if (t == "generalized" and (m != "random" or s == "2stage")):
        continue

111
112
113
114
115
    # solve generalized already decomposed only for random matrix in 1stage
    # maybe this test should be further restricted, maybe not so important...
    if (t == "generalized_decomp" and (m != "random" or s == "2stage")):
        continue

116
117
    # cholesky tests only 1stage and teoplitz or random matrix
    if (t == "cholesky" and ((not (m == "toeplitz" or m == "random")) or s == "2stage")):
Andreas Marek's avatar
Andreas Marek committed
118
119
120
        continue

    if (t == "eigenvalues" and (m == "random")):
121
122
        continue

123
124
125
    if (t == "hermitian_multiply" and (s == "2stage")):
        continue

Andreas Marek's avatar
Andreas Marek committed
126
127
128
129
130
    if (t == "hermitian_multiply" and (m == "toeplitz")):
        continue

    # qr only for 2stage real
    if (q == 1 and (s != "2stage" or d != "real" or t != "eigenvectors" or g == 1 or m != "random")):
131
132
        continue

133
    if(spl == "myself" and (d != "real" or p != "double" or q != 0 or m != "random" or (t != "eigenvectors" and t != "cholesky")  or lang != "Fortran" or lay != "square")):
134
135
        continue

136
137
138
    for kernel in ["all_kernels", "default_kernel"] if s == "2stage" else ["nokernel"]:
        endifs = 0
        extra_flags = []
139

140
141
142
        if(spl == "myself" and kernel == "all_kernels"):
            continue

143
144
145
146
        if(spl == "myself"):
            print("if WITH_MPI")
            endifs += 1

147
        if (t == "eigenvalues" and kernel == "all_kernels"):
148
            continue
149

Andreas Marek's avatar
Andreas Marek committed
150
151
152
        if (lang == "C" and kernel == "all_kernels"):
            continue

153
154
155
156
        if (lang == "C"):
            print("if ENABLE_C_TESTS")
            endifs += 1

157
158
159
        if (g == 1):
            print("if WITH_GPU_VERSION")
            endifs += 1
160

161
        if (lay == "all_layouts"):
162
163
164
            print("if WITH_MPI")
            endifs += 1

165
        if (s in ["scalapack_all", "scalapack_part"]):
166
167
168
            print("if WITH_SCALAPACK_TESTS")
            endifs += 1

169
170
171
172
        if kernel == "default_kernel":
            extra_flags.append("-DTEST_KERNEL=ELPA_2STAGE_{0}_DEFAULT".format(d.upper()))
        elif kernel == "all_kernels":
            extra_flags.append("-DTEST_ALL_KERNELS")
173

174
175
        if layout_flag[lay]:
            extra_flags.append(layout_flag[lay])
176

177
178
179
        if split_comm_flag[spl]:
            extra_flags.append(split_comm_flag[spl])

180
181
182
183
184
185
186
187
188
        if (p == "single"):
            if (d == "real"):
                print("if WANT_SINGLE_PRECISION_REAL")
            elif (d == "complex"):
                print("if WANT_SINGLE_PRECISION_COMPLEX")
            else:
                raise Exception("Oh no!")
            endifs += 1

189
        name = "validate{langsuffix}_{d}_{p}_{t}_{s}{kernelsuffix}_{gpusuffix}{gpuidsuffix}{qrsuffix}{m}{layoutsuffix}{spl}".format(
190
191
192
193
            langsuffix=language_flag[lang],
            d=d, p=p, t=t, s=s,
            kernelsuffix="" if kernel == "nokernel" else "_" + kernel,
            gpusuffix="gpu_" if g else "",
194
            gpuidsuffix="set_gpu_id_" if gid else "",
195
196
            qrsuffix="qr_" if q else "",
            m=m,
197
198
            layoutsuffix="_all_layouts" if lay == "all_layouts" else "",
            spl="_split_comm_myself" if spl == "myself" else "")
199
200
201
202
203
204
205

        print("if BUILD_KCOMPUTER")
        print("bin_PROGRAMS += " + name)
        print("else")
        print("noinst_PROGRAMS += " + name)
        print("endif")

206
        if lay == "square" or t == "generalized":
207
208
209
210
            if kernel == "all_kernels":
                print("check_SCRIPTS += " + name + "_extended.sh")
            else:
                print("check_SCRIPTS += " + name + "_default.sh")
211
        elif lay == "all_layouts":
212
213
214
215
            if kernel == "all_kernels":
                print("check_SCRIPTS += " + name + "_extended.sh")
            else:
                print("check_SCRIPTS += " + name + "_extended.sh")
216
217
        else:
            raise Exception("Unknown layout {0}".format(lay))
218
219

        if lang == "Fortran":
Andreas Marek's avatar
Andreas Marek committed
220
221
222
            print(name + "_SOURCES = test/Fortran/test.F90")
            print(name + "_LDADD = $(test_program_ldadd)")
            print(name + "_FCFLAGS = $(test_program_fcflags) \\")
223
224

        elif lang == "C":
Andreas Marek's avatar
Andreas Marek committed
225
226
            print(name + "_SOURCES = test/C/test.c")
            print(name + "_LDADD = $(test_program_ldadd) $(FCLIBS)")
227
            print(name + "_CFLAGS = $(test_program_cflags) \\")
228

229
230
231
        else:
            raise Exception("Unknown language")

232
233
234
235
236
237
238
        print("  -DTEST_CASE=\\\"{0}\\\" \\".format(name))
        print("  " + " \\\n  ".join([
            domain_flag[d],
            prec_flag[p],
            test_type_flag[t],
            solver_flag[s],
            gpu_flag[g],
239
            gpu_id_flag[gid],
240
241
242
243
            qr_flag[q],
            matrix_flag[m]] + extra_flags))

        print("endif\n" * endifs)
244

245

Andreas Marek's avatar
Andreas Marek committed
246
for lang, p, d in product(sorted(language_flag.keys()), sorted(prec_flag.keys()), sorted(domain_flag.keys())):
247
248
249
250
251
252
253
254
255
256
    endifs = 0
    if (p == "single"):
        if (d == "real"):
            print("if WANT_SINGLE_PRECISION_REAL")
        elif (d == "complex"):
            print("if WANT_SINGLE_PRECISION_COMPLEX")
        else:
            raise Exception("Oh no!")
        endifs += 1

257
    name = "validate_autotune{langsuffix}_{d}_{p}".format(langsuffix=language_flag[lang], d=d, p=p)
258

Andreas Marek's avatar
Andreas Marek committed
259
    print("if ENABLE_AUTOTUNING")
260
261
    if lang == "C":
        print("if ENABLE_C_TESTS")
262
    print("check_SCRIPTS += " + name + "_extended.sh")
263
    print("noinst_PROGRAMS += " + name)
264
    if lang == "Fortran":
Andreas Marek's avatar
Andreas Marek committed
265
266
267
268
269
270
271
        print(name + "_SOURCES = test/Fortran/test_autotune.F90")
        print(name + "_LDADD = $(test_program_ldadd)")
        print(name + "_FCFLAGS = $(test_program_fcflags) \\")

    elif lang == "C":
        print(name + "_SOURCES = test/C/test_autotune.c")
        print(name + "_LDADD = $(test_program_ldadd) $(FCLIBS)")
272
        print(name + "_CFLAGS = $(test_program_cflags) \\")
Andreas Marek's avatar
Andreas Marek committed
273

274
275
276
    else:
        raise Exception("Unknown language")

277
    print("  " + " \\\n  ".join([
278
279
        domain_flag[d],
        prec_flag[p]]))
280
    print("endif\n" * endifs)
281
282
    if lang == "C":
        print("endif")
Andreas Marek's avatar
Andreas Marek committed
283
    print("endif")
Pavel Kus's avatar
Pavel Kus committed
284

285
name = "validate_multiple_objs_real_double"
Pavel Kus's avatar
Pavel Kus committed
286
287
288
289
290
291
292
293
294
295
296
print("if ENABLE_AUTOTUNING")
print("check_SCRIPTS += " + name + "_extended.sh")
print("noinst_PROGRAMS += " + name)
print(name + "_SOURCES = test/Fortran/test_multiple_objs.F90")
print(name + "_LDADD = $(test_program_ldadd)")
print(name + "_FCFLAGS = $(test_program_fcflags) \\")
print("  " + " \\\n  ".join([
        domain_flag['real'],
        prec_flag['double']]))
print("endif")

Andreas Marek's avatar
Andreas Marek committed
297
name = "test_skewsymmetric_real_double"
Andreas Marek's avatar
Andreas Marek committed
298
print("check_SCRIPTS += " + name + "_extended.sh")
Andreas Marek's avatar
Andreas Marek committed
299
300
301
302
303
304
305
306
print("noinst_PROGRAMS += " + name)
print(name + "_SOURCES = test/Fortran/test_skewsymmetric.F90")
print(name + "_LDADD = $(test_program_ldadd)")
print(name + "_FCFLAGS = $(test_program_fcflags) \\")
print("  " + " \\\n  ".join([
        domain_flag['real'],
        prec_flag['double']]))

307
308
name = "test_skewsymmetric_real_single"
print("if WANT_SINGLE_PRECISION_REAL")
Andreas Marek's avatar
Andreas Marek committed
309
print("check_SCRIPTS += " + name + "_extended.sh")
310
311
312
313
314
315
316
317
318
319
320
print("noinst_PROGRAMS += " + name)
print(name + "_SOURCES = test/Fortran/test_skewsymmetric.F90")
print(name + "_LDADD = $(test_program_ldadd)")
print(name + "_FCFLAGS = $(test_program_fcflags) \\")
print("  " + " \\\n  ".join([
        domain_flag['real'],
        prec_flag['single']]))
print("endif")



321
name = "validate_multiple_objs_real_double_c_version"
322
print("if ENABLE_C_TESTS")
323
324
325
326
327
328
329
330
331
332
print("if ENABLE_AUTOTUNING")
print("check_SCRIPTS += " + name + "_extended.sh")
print("noinst_PROGRAMS += " + name)
print(name + "_SOURCES = test/C/test_multiple_objs.c")
print(name + "_LDADD = $(test_program_ldadd) $(FCLIBS)")
print(name + "_CFLAGS = $(test_program_cflags) \\")
print("  " + " \\\n  ".join([
        domain_flag['real'],
        prec_flag['double']]))
print("endif")
333
334
print("endif")

335

336
name = "validate_split_comm_real_double"
337
338
339
340
341
342
343
344
print("check_SCRIPTS += " + name + "_extended.sh")
print("noinst_PROGRAMS += " + name)
print(name + "_SOURCES = test/Fortran/test_split_comm.F90")
print(name + "_LDADD = $(test_program_ldadd)")
print(name + "_FCFLAGS = $(test_program_fcflags) \\")
print("  " + " \\\n  ".join([
        domain_flag['real'],
        prec_flag['double']]))