|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +"""Test Matrix Generator |
| 7 | +
|
| 8 | +Generates pairwise test combinations used in spack.yml using |
| 9 | +[allpairspy](https://github.com/thombashi/allpairspy). |
| 10 | +
|
| 11 | +## Usage |
| 12 | +
|
| 13 | +```bash |
| 14 | +pip install -U pyyaml allpairspy |
| 15 | +python generate_test_matrix.py |
| 16 | +``` |
| 17 | +
|
| 18 | +It enforces certain constrains. |
| 19 | +
|
| 20 | +""" |
| 21 | +from allpairspy import AllPairs |
| 22 | +import yaml |
| 23 | + |
| 24 | +parameters = [ |
| 25 | + ["x86", "x86", "arm"], # Favor x86 |
| 26 | + ["gcc", "llvm", "intel-oneapi-compilers"], |
| 27 | + ["openmpi", "mpich", "intel-oneapi-mpi"], |
| 28 | + ["openblas", "amdblis", "armpl-gcc", "intel-oneapi-mkl"], |
| 29 | + ["+shared", "~shared"], |
| 30 | + ["+int64", "~int64"], |
| 31 | + ["~openmp", "+openmp"], |
| 32 | + ["+arpack", "+slepc"], |
| 33 | + ["+mumps", "+superlu-dist", "+strumpack"], |
| 34 | + ["~cuda", "+cuda"], |
| 35 | +] |
| 36 | + |
| 37 | +def is_valid(combo): |
| 38 | + if len(combo) < 4: |
| 39 | + # AllPairs creates partial combinations |
| 40 | + return True |
| 41 | + |
| 42 | + arch, compiler, mpi, math_libs = combo[0], combo[1], combo[2], combo[3] |
| 43 | + |
| 44 | + # AllPairs creates partial combinations, so we don't always have 9 entries |
| 45 | + openmp = combo[6] if len(combo) > 6 else "~openmp" |
| 46 | + cuda = combo[9] if len(combo) > 9 else "~cuda" |
| 47 | + |
| 48 | + # Intel packages must all be together and only on x86 |
| 49 | + |
| 50 | + # We also do not allow the CUDA+Intel combination because the "g" instances |
| 51 | + # are all AMD |
| 52 | + intel_packages = [compiler == "intel-oneapi-compilers", |
| 53 | + mpi == "intel-oneapi-mpi", |
| 54 | + math_libs == "intel-oneapi-mkl"] |
| 55 | + if any(intel_packages): |
| 56 | + if arch != "x86" or not all(intel_packages) or cuda == "+cuda": |
| 57 | + return False |
| 58 | + |
| 59 | + if cuda == "+cuda": |
| 60 | + # We only have GPUs on x86 machines |
| 61 | + if arch != "x86": |
| 62 | + return False |
| 63 | + # We don't want to mix GPU with OpenMP |
| 64 | + if openmp == "+openmp": |
| 65 | + return False |
| 66 | + |
| 67 | + # Use ARMPL only with GCC and ARM |
| 68 | + if math_libs == "armpl-gcc" and (compiler != "gcc" or arch != "arm"): |
| 69 | + return False |
| 70 | + |
| 71 | + # On ARM, use armpl-gcc or openblas |
| 72 | + if arch == "arm" and math_libs not in ("armpl-gcc", "openblas"): |
| 73 | + return False |
| 74 | + |
| 75 | + return True |
| 76 | + |
| 77 | +matrix = [] |
| 78 | +for combo in AllPairs(parameters, filter_func=is_valid): |
| 79 | + matrix.append({ |
| 80 | + "arch": combo[0], |
| 81 | + "compiler": combo[1], |
| 82 | + "mpi": combo[2], |
| 83 | + "math-libs": combo[3], |
| 84 | + "shared": combo[4], |
| 85 | + "int": combo[5], |
| 86 | + "openmp": combo[6], |
| 87 | + "eigensolver": combo[7], |
| 88 | + "solver": combo[8], |
| 89 | + "cuda": combo[9], |
| 90 | + }) |
| 91 | + |
| 92 | +# Add more CUDA test cases with different solver/eigensolver combinations |
| 93 | +# (AllPairs is highly constrained with CUDA, so we manually add a couple of |
| 94 | +# extra cases) |
| 95 | +desired_cuda_cases = [ |
| 96 | + { |
| 97 | + "arch": "x86", "compiler": "gcc", "mpi": "openmpi", "math-libs": "openblas", |
| 98 | + "shared": "+shared", "int": "+int64", "openmp": "~openmp", |
| 99 | + "eigensolver": "+slepc", "solver": "+superlu-dist", "cuda": "+cuda" |
| 100 | + }, |
| 101 | + { |
| 102 | + "arch": "x86", "compiler": "llvm", "mpi": "openmpi", "math-libs": "amdblis", |
| 103 | + "shared": "~shared", "int": "~int64", "openmp": "~openmp", |
| 104 | + "eigensolver": "+arpack", "solver": "+strumpack", "cuda": "+cuda" |
| 105 | + }, |
| 106 | + |
| 107 | +] |
| 108 | + |
| 109 | +# Add one case where we turn a multiple solvers (to check that there's no |
| 110 | +# problem with compiling multiple solvers) |
| 111 | +for cuda in ("~cuda", "+cuda"): |
| 112 | + matrix.append({ |
| 113 | + "arch": "x86", |
| 114 | + "compiler": "gcc", |
| 115 | + "mpi": "openmpi", |
| 116 | + "math-libs": "openblas", |
| 117 | + "shared": "+shared", |
| 118 | + "int": "~int64", |
| 119 | + "openmp": "~openmp", |
| 120 | + "eigensolver": "+slepc+arpack", |
| 121 | + "solver": "+superlu-dist+mumps+sundials+strumpack", |
| 122 | + "cuda": cuda |
| 123 | + }) |
| 124 | + |
| 125 | +for cuda_case in desired_cuda_cases: |
| 126 | + exists = any( |
| 127 | + all(existing.get(k) == v for k, v in cuda_case.items()) |
| 128 | + for existing in matrix |
| 129 | + ) |
| 130 | + if not exists: |
| 131 | + matrix.append(cuda_case) |
| 132 | + |
| 133 | + |
| 134 | +# Custom list class for flow-style output, so that we can print it as [self-hosted, gpu] |
| 135 | +# instead of |
| 136 | +# - self-hosted |
| 137 | +# - gpu |
| 138 | +class FlowList(list): |
| 139 | + pass |
| 140 | + |
| 141 | +def represent_flow_list(dumper, data): |
| 142 | + return dumper.represent_sequence('tag:yaml.org,2002:seq', data, flow_style=True) |
| 143 | + |
| 144 | +yaml.add_representer(FlowList, represent_flow_list) |
| 145 | + |
| 146 | +# Add runners |
| 147 | +for entry in matrix: |
| 148 | + if entry["arch"] == "arm": |
| 149 | + entry["runner"] = FlowList(["self-hosted", "arm64"]) |
| 150 | + elif entry["cuda"] == "+cuda": |
| 151 | + entry["runner"] = FlowList(["self-hosted", "gpu"]) |
| 152 | + else: |
| 153 | + entry["runner"] = "palace_ubuntu-latest_16-core" |
| 154 | + |
| 155 | +print(yaml.dump(matrix, default_flow_style=False, sort_keys=False)) |
0 commit comments