|
| 1 | +# Data Parallel Control (dpctl) |
| 2 | +# |
| 3 | +# Copyright 2020-2021 Intel Corporation |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import os |
| 18 | +import subprocess |
| 19 | +import sys |
| 20 | + |
| 21 | + |
| 22 | +def run( |
| 23 | + use_oneapi=True, |
| 24 | + c_compiler=None, |
| 25 | + cxx_compiler=None, |
| 26 | + level_zero=True, |
| 27 | + compiler_root=None, |
| 28 | + bin_llvm=None, |
| 29 | + doxyrest_dir=None, |
| 30 | +): |
| 31 | + IS_LIN = False |
| 32 | + |
| 33 | + if "linux" in sys.platform: |
| 34 | + IS_LIN = True |
| 35 | + elif sys.platform in ["win32", "cygwin"]: |
| 36 | + pass |
| 37 | + else: |
| 38 | + assert False, sys.platform + " not supported" |
| 39 | + |
| 40 | + if not IS_LIN: |
| 41 | + raise RuntimeError( |
| 42 | + "This scripts only supports coverage collection on Linux" |
| 43 | + ) |
| 44 | + setup_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 45 | + cmake_args = [ |
| 46 | + sys.executable, |
| 47 | + "setup.py", |
| 48 | + "develop", |
| 49 | + "--", |
| 50 | + "-G", |
| 51 | + "Unix Makefiles", |
| 52 | + "-DCMAKE_BUILD_TYPE=Debug", |
| 53 | + "-DCMAKE_C_COMPILER:PATH=" + c_compiler, |
| 54 | + "-DCMAKE_CXX_COMPILER:PATH=" + cxx_compiler, |
| 55 | + "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=" + ("ON" if level_zero else "OFF"), |
| 56 | + "-DDPCTL_DPCPP_FROM_ONEAPI:BOOL=" + ("ON" if use_oneapi else "OFF"), |
| 57 | + "-DDPCTL_GENERATE_DOCS=ON", |
| 58 | + ] |
| 59 | + |
| 60 | + if doxyrest_dir: |
| 61 | + cmake_args.append("-DDPCTL_ENABLE_DOXYREST=ON") |
| 62 | + cmake_args.append("-DDoxyrest_DIR=" + doxyrest_dir) |
| 63 | + |
| 64 | + if compiler_root: |
| 65 | + cmake_args += [ |
| 66 | + "-DDPCTL_DPCPP_HOME_DIR:PATH=" + compiler_root, |
| 67 | + ] |
| 68 | + env = None |
| 69 | + if bin_llvm: |
| 70 | + env = { |
| 71 | + "PATH": ":".join((os.environ.get("PATH", ""), bin_llvm)), |
| 72 | + } |
| 73 | + env.update({k: v for k, v in os.environ.items() if k != "PATH"}) |
| 74 | + # Install dpctl package |
| 75 | + subprocess.check_call(cmake_args, shell=False, cwd=setup_dir, env=env) |
| 76 | + # Get the path for the build directory |
| 77 | + build_dir = ( |
| 78 | + subprocess.check_output( |
| 79 | + ["find", "_skbuild", "-name", "cmake-build"], |
| 80 | + cwd=setup_dir, |
| 81 | + ) |
| 82 | + .decode("utf-8") |
| 83 | + .strip("\n") |
| 84 | + ) |
| 85 | + # Generate docs |
| 86 | + subprocess.check_call( |
| 87 | + ["cmake", "--build", ".", "--target", "Sphinx"], cwd=build_dir |
| 88 | + ) |
| 89 | + generated_doc_dir = ( |
| 90 | + subprocess.check_output( |
| 91 | + ["find", "_skbuild", "-name", "index.html"], cwd=setup_dir |
| 92 | + ) |
| 93 | + .decode("utf-8") |
| 94 | + .strip("\n") |
| 95 | + ) |
| 96 | + print("Generated documentation placed under ", generated_doc_dir) |
| 97 | + |
| 98 | + |
| 99 | +if __name__ == "__main__": |
| 100 | + import argparse |
| 101 | + |
| 102 | + parser = argparse.ArgumentParser( |
| 103 | + description="Driver to build dpctl and generate coverage" |
| 104 | + ) |
| 105 | + driver = parser.add_argument_group(title="Coverage driver arguments") |
| 106 | + driver.add_argument("--c-compiler", help="Name of C compiler", default=None) |
| 107 | + driver.add_argument( |
| 108 | + "--cxx-compiler", help="Name of C++ compiler", default=None |
| 109 | + ) |
| 110 | + driver.add_argument( |
| 111 | + "--not-oneapi", |
| 112 | + help="Is one-API installation", |
| 113 | + dest="oneapi", |
| 114 | + action="store_false", |
| 115 | + ) |
| 116 | + driver.add_argument( |
| 117 | + "--compiler-root", type=str, help="Path to compiler home directory" |
| 118 | + ) |
| 119 | + driver.add_argument( |
| 120 | + "--no-level-zero", |
| 121 | + help="Enable Level Zero support", |
| 122 | + dest="level_zero", |
| 123 | + action="store_false", |
| 124 | + ) |
| 125 | + driver.add_argument( |
| 126 | + "--bin-llvm", help="Path to folder where llvm-cov can be found" |
| 127 | + ) |
| 128 | + driver.add_argument( |
| 129 | + "--doxyrest-root", |
| 130 | + help=( |
| 131 | + "Path to Doxyrest installation to use to generate Sphinx docs" |
| 132 | + + "for libsyclinterface" |
| 133 | + ), |
| 134 | + ) |
| 135 | + |
| 136 | + args = parser.parse_args() |
| 137 | + |
| 138 | + if args.oneapi: |
| 139 | + args.c_compiler = "icx" |
| 140 | + args.cxx_compiler = "icpx" |
| 141 | + args.compiler_root = None |
| 142 | + icx_path = subprocess.check_output(["which", "icx"]) |
| 143 | + bin_dir = os.path.dirname(os.path.dirname(icx_path)) |
| 144 | + args.bin_llvm = os.path.join(bin_dir.decode("utf-8"), "bin-llvm") |
| 145 | + else: |
| 146 | + args_to_validate = [ |
| 147 | + "c_compiler", |
| 148 | + "cxx_compiler", |
| 149 | + "compiler_root", |
| 150 | + "bin_llvm", |
| 151 | + ] |
| 152 | + for p in args_to_validate: |
| 153 | + arg = getattr(args, p, None) |
| 154 | + if not isinstance(arg, str): |
| 155 | + opt_name = p.replace("_", "-") |
| 156 | + raise RuntimeError( |
| 157 | + f"Option {opt_name} must be provided is " |
| 158 | + "using non-default DPC++ layout" |
| 159 | + ) |
| 160 | + if not os.path.exists(arg): |
| 161 | + raise RuntimeError(f"Path {arg} must exist") |
| 162 | + |
| 163 | + run( |
| 164 | + use_oneapi=args.oneapi, |
| 165 | + c_compiler=args.c_compiler, |
| 166 | + cxx_compiler=args.cxx_compiler, |
| 167 | + level_zero=args.level_zero, |
| 168 | + compiler_root=args.compiler_root, |
| 169 | + bin_llvm=args.bin_llvm, |
| 170 | + doxyrest_dir=args.doxyrest_root, |
| 171 | + ) |
0 commit comments