generate_automake_test_programs.py 7.2 KB
Newer Older
1
2
3
4
#!/usr/bin/env python
from __future__ import print_function
from itertools import product

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

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

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

qr_flag = {
37
38
    0: "-DTEST_QR_DECOMPOSITION=0",
    1: "-DTEST_QR_DECOMPOSITION=1",
Pavel Kus's avatar
Pavel Kus committed
39
}
40

41
test_type_flag = {
42
43
44
45
46
    "eigenvectors":       "-DTEST_EIGENVECTORS",
    "eigenvalues":        "-DTEST_EIGENVALUES",
    "solve_tridiagonal":  "-DTEST_SOLVE_TRIDIAGONAL",
    "cholesky":           "-DTEST_CHOLESKY",
    "hermitian_multiply": "-DTEST_HERMITIAN_MULTIPLY",
47
48
}

49
layout_flag = {
50
51
    "all_layouts": "-DTEST_ALL_LAYOUTS",
    "square": ""
52
53
}

54
55
56
57
58
59
60
61
62
63
for lang, m, g, q, t, p, d, s, lay in product(sorted(language_flag.keys()),
                                              sorted(matrix_flag.keys()),
                                              sorted(gpu_flag.keys()),
                                              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())):

Andreas Marek's avatar
Andreas Marek committed
64
    if lang == "C" and (m == "analytic" or m == "toeplitz" or m == "frank" or lay == "all_layouts"):
Andreas Marek's avatar
Andreas Marek committed
65
66
        continue

67
68
69
70
    # 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
71
72
73
    # exclude some test combinations

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

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

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

84
85
86
87
    # do not test single-precision scalapack
    if(s in ["scalapack_all", "scalapack_part"] and ( p == "single")):
        continue

Andreas Marek's avatar
Andreas Marek committed
88
    # solve tridiagonal only for real toeplitz matrix in 1stage
89
    if (t == "solve_tridiagonal" and (s != "1stage" or d != "real" or m != "toeplitz")):
90
91
        continue

Andreas Marek's avatar
Andreas Marek committed
92
93
94
95
96
    # cholesky tests only 1stage and teoplitz matrix
    if (t == "cholesky" and (m != "toeplitz" or s == "2stage")):
        continue

    if (t == "eigenvalues" and (m == "random")):
97
98
        continue

99
100
101
    if (t == "hermitian_multiply" and (s == "2stage")):
        continue

Andreas Marek's avatar
Andreas Marek committed
102
103
104
105
106
    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")):
107
108
        continue

109
110
111
    for kernel in ["all_kernels", "default_kernel"] if s == "2stage" else ["nokernel"]:
        endifs = 0
        extra_flags = []
112
113

        if (t == "eigenvalues" and kernel == "all_kernels"):
114
            continue
115

Andreas Marek's avatar
Andreas Marek committed
116
117
118
        if (lang == "C" and kernel == "all_kernels"):
            continue

119
120
121
        if (g == 1):
            print("if WITH_GPU_VERSION")
            endifs += 1
122

123
        if (lay == "all_layouts"):
124
125
126
            print("if WITH_MPI")
            endifs += 1

127
        if (s in ["scalapack_all", "scalapack_part"]):
128
129
130
            print("if WITH_SCALAPACK_TESTS")
            endifs += 1

131
132
133
134
        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")
135

136
137
        if layout_flag[lay]:
            extra_flags.append(layout_flag[lay])
138

139
140
141
142
143
144
145
146
147
        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

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        name = "test{langsuffix}_{d}_{p}_{t}_{s}{kernelsuffix}_{gpusuffix}{qrsuffix}{m}{layoutsuffix}".format(
            langsuffix=language_flag[lang],
            d=d, p=p, t=t, s=s,
            kernelsuffix="" if kernel == "nokernel" else "_" + kernel,
            gpusuffix="gpu_" if g else "",
            qrsuffix="qr_" if q else "",
            m=m,
            layoutsuffix="_all_layouts" if lay == "all_layouts" else "")

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

163
164
165
166
167
168
        if lay == "square":
            print("check_SCRIPTS += " + name + "_default.sh")
        elif lay == "all_layouts":
            print("check_SCRIPTS += " + name + "_extended.sh")
        else:
            raise Exception("Unknown layout {0}".format(lay))
169
170

        if lang == "Fortran":
Andreas Marek's avatar
Andreas Marek committed
171
172
173
            print(name + "_SOURCES = test/Fortran/test.F90")
            print(name + "_LDADD = $(test_program_ldadd)")
            print(name + "_FCFLAGS = $(test_program_fcflags) \\")
174
175

        elif lang == "C":
Andreas Marek's avatar
Andreas Marek committed
176
177
            print(name + "_SOURCES = test/C/test.c")
            print(name + "_LDADD = $(test_program_ldadd) $(FCLIBS)")
178
            print(name + "_CFLAGS = $(test_program_cflags) \\")
179
180
181
182
183
184
185
186
187
188
189
190

        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],
            qr_flag[q],
            matrix_flag[m]] + extra_flags))

        print("endif\n" * endifs)
191

Andreas Marek's avatar
Andreas Marek committed
192
for lang, p, d in product(sorted(language_flag.keys()), sorted(prec_flag.keys()), sorted(domain_flag.keys())):
193
194
195
196
197
198
199
200
201
202
    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

Andreas Marek's avatar
Andreas Marek committed
203
    name = "test_autotune{langsuffix}_{d}_{p}".format(langsuffix=language_flag[lang], d=d, p=p)
204

205
    print("check_SCRIPTS += " + name + "_extended.sh")
206
    print("noinst_PROGRAMS += " + name)
Andreas Marek's avatar
Andreas Marek committed
207
208
209
210
211
212
213
214
    if lang == "Fortran":    
        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)")
215
        print(name + "_CFLAGS = $(test_program_cflags) \\")
Andreas Marek's avatar
Andreas Marek committed
216

217
    print("  " + " \\\n  ".join([
218
219
        domain_flag[d],
        prec_flag[p]]))
220
    print("endif\n" * endifs)