|
18 | 18 | """
|
19 | 19 |
|
20 | 20 |
|
21 |
| -import glob |
22 |
| -import os |
23 |
| -import shutil |
24 |
| -import subprocess |
25 |
| -import sys |
26 |
| - |
27 |
| -IS_WIN = False |
28 |
| -IS_LIN = False |
29 |
| - |
30 |
| -if "linux" in sys.platform: |
31 |
| - IS_LIN = True |
32 |
| -elif sys.platform in ["win32", "cygwin"]: |
33 |
| - IS_WIN = True |
34 |
| -else: |
35 |
| - assert False, sys.platform + " not supported" |
36 |
| - |
37 |
| -ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT") |
38 |
| -CODE_COVERAGE = os.environ.get("CODE_COVERAGE") |
39 |
| - |
40 |
| -if IS_LIN: |
41 |
| - DPCPP_ROOT = os.path.join(ONEAPI_ROOT, r"compiler/latest/linux") |
42 |
| -if IS_WIN: |
43 |
| - DPCPP_ROOT = os.path.join(ONEAPI_ROOT, r"compiler\latest\windows") |
44 |
| - |
45 |
| -dpctl_dir = os.getcwd() |
46 |
| -build_cmake_dir = os.path.join(dpctl_dir, "build_cmake") |
47 |
| -if os.path.exists(build_cmake_dir): |
48 |
| - for f in os.listdir(build_cmake_dir): |
49 |
| - f_path = os.path.join(build_cmake_dir, f) |
50 |
| - if os.path.isdir(f_path): |
51 |
| - if (f == "level-zero") and os.path.isdir( |
52 |
| - os.path.join(f_path, ".git") |
53 |
| - ): |
54 |
| - # do not delete Git checkout of level zero headers |
55 |
| - pass |
| 21 | +def build_backend(l0_support=False): |
| 22 | + import glob |
| 23 | + import os |
| 24 | + import shutil |
| 25 | + import subprocess |
| 26 | + import sys |
| 27 | + |
| 28 | + IS_WIN = False |
| 29 | + IS_LIN = False |
| 30 | + |
| 31 | + if "linux" in sys.platform: |
| 32 | + IS_LIN = True |
| 33 | + elif sys.platform in ["win32", "cygwin"]: |
| 34 | + IS_WIN = True |
| 35 | + else: |
| 36 | + assert False, sys.platform + " not supported" |
| 37 | + |
| 38 | + CODE_COVERAGE = os.environ.get("CODE_COVERAGE") |
| 39 | + ONEAPI_ROOT = os.environ.get("ONEAPI_ROOT") |
| 40 | + |
| 41 | + if IS_LIN: |
| 42 | + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, r"compiler/latest/linux") |
| 43 | + elif IS_WIN: |
| 44 | + DPCPP_ROOT = os.path.join(ONEAPI_ROOT, r"compiler\latest\windows") |
| 45 | + |
| 46 | + dpctl_dir = os.getcwd() |
| 47 | + build_cmake_dir = os.path.join(dpctl_dir, "build_cmake") |
| 48 | + if os.path.exists(build_cmake_dir): |
| 49 | + for f in os.listdir(build_cmake_dir): |
| 50 | + f_path = os.path.join(build_cmake_dir, f) |
| 51 | + if os.path.isdir(f_path): |
| 52 | + if (f == "level-zero") and os.path.isdir( |
| 53 | + os.path.join(f_path, ".git") |
| 54 | + ): |
| 55 | + # do not delete Git checkout of level zero headers |
| 56 | + pass |
| 57 | + else: |
| 58 | + shutil.rmtree(f_path) |
56 | 59 | else:
|
57 |
| - shutil.rmtree(f_path) |
58 |
| - else: |
59 |
| - os.remove(f_path) |
60 |
| -else: |
61 |
| - os.mkdir(build_cmake_dir) |
62 |
| -os.chdir(build_cmake_dir) |
63 |
| - |
64 |
| -INSTALL_PREFIX = os.path.join(dpctl_dir, "install") |
65 |
| -if os.path.exists(INSTALL_PREFIX): |
66 |
| - shutil.rmtree(INSTALL_PREFIX) |
67 |
| - |
68 |
| -backends = os.path.join(dpctl_dir, "dpctl-capi") |
69 |
| - |
70 |
| -if IS_LIN: |
71 |
| - if CODE_COVERAGE: |
72 |
| - cmake_args = [ |
73 |
| - "cmake", |
74 |
| - "-DCMAKE_BUILD_TYPE=Debug", |
75 |
| - "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, |
76 |
| - "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, |
77 |
| - "-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT, |
78 |
| - "-DCMAKE_C_COMPILER:PATH=" |
79 |
| - + os.path.join(DPCPP_ROOT, "bin", "clang"), |
80 |
| - "-DCMAKE_CXX_COMPILER:PATH=" |
81 |
| - + os.path.join(DPCPP_ROOT, "bin", "dpcpp"), |
82 |
| - "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON", |
83 |
| - "-DDPCTL_BUILD_CAPI_TESTS=ON", |
84 |
| - "-DDPCTL_GENERATE_COVERAGE=ON", |
85 |
| - "-DDPCTL_COVERAGE_REPORT_OUTPUT_DIR=" + dpctl_dir, |
86 |
| - backends, |
87 |
| - ] |
88 |
| - subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False) |
89 |
| - subprocess.check_call(["make", "V=1", "-j", "4"]) |
90 |
| - subprocess.check_call(["make", "install"]) |
91 |
| - subprocess.check_call(["make", "lcov-genhtml"]) |
92 |
| - |
| 60 | + os.remove(f_path) |
93 | 61 | else:
|
| 62 | + os.mkdir(build_cmake_dir) |
| 63 | + os.chdir(build_cmake_dir) |
| 64 | + |
| 65 | + INSTALL_PREFIX = os.path.join(dpctl_dir, "install") |
| 66 | + if os.path.exists(INSTALL_PREFIX): |
| 67 | + shutil.rmtree(INSTALL_PREFIX) |
| 68 | + |
| 69 | + backends = os.path.join(dpctl_dir, "dpctl-capi") |
| 70 | + |
| 71 | + ENABLE_LO_PROGRAM_CREATION = "ON" if l0_support else "OFF" |
| 72 | + |
| 73 | + if IS_LIN: |
| 74 | + if CODE_COVERAGE: |
| 75 | + cmake_args = [ |
| 76 | + "cmake", |
| 77 | + "-DCMAKE_BUILD_TYPE=Debug", |
| 78 | + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, |
| 79 | + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, |
| 80 | + "-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT, |
| 81 | + "-DCMAKE_C_COMPILER:PATH=" |
| 82 | + + os.path.join(DPCPP_ROOT, "bin", "clang"), |
| 83 | + "-DCMAKE_CXX_COMPILER:PATH=" |
| 84 | + + os.path.join(DPCPP_ROOT, "bin", "dpcpp"), |
| 85 | + "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=" |
| 86 | + + ENABLE_LO_PROGRAM_CREATION, |
| 87 | + "-DDPCTL_BUILD_CAPI_TESTS=ON", |
| 88 | + "-DDPCTL_GENERATE_COVERAGE=ON", |
| 89 | + "-DDPCTL_COVERAGE_REPORT_OUTPUT_DIR=" + dpctl_dir, |
| 90 | + backends, |
| 91 | + ] |
| 92 | + subprocess.check_call( |
| 93 | + cmake_args, stderr=subprocess.STDOUT, shell=False |
| 94 | + ) |
| 95 | + subprocess.check_call(["make", "V=1", "-j", "4"]) |
| 96 | + subprocess.check_call(["make", "install"]) |
| 97 | + subprocess.check_call(["make", "lcov-genhtml"]) |
| 98 | + else: |
| 99 | + cmake_args = [ |
| 100 | + "cmake", |
| 101 | + "-DCMAKE_BUILD_TYPE=Release", |
| 102 | + "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, |
| 103 | + "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, |
| 104 | + "-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT, |
| 105 | + "-DCMAKE_C_COMPILER:PATH=" |
| 106 | + + os.path.join(DPCPP_ROOT, "bin", "clang"), |
| 107 | + "-DCMAKE_CXX_COMPILER:PATH=" |
| 108 | + + os.path.join(DPCPP_ROOT, "bin", "dpcpp"), |
| 109 | + "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=" |
| 110 | + + ENABLE_LO_PROGRAM_CREATION, |
| 111 | + backends, |
| 112 | + ] |
| 113 | + subprocess.check_call( |
| 114 | + cmake_args, stderr=subprocess.STDOUT, shell=False |
| 115 | + ) |
| 116 | + subprocess.check_call(["make", "V=1", "-j", "4"]) |
| 117 | + subprocess.check_call(["make", "install"]) |
| 118 | + |
| 119 | + os.chdir(dpctl_dir) |
| 120 | + for file in glob.glob( |
| 121 | + os.path.join(dpctl_dir, "install", "lib", "*.so*") |
| 122 | + ): |
| 123 | + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
| 124 | + elif IS_WIN: |
94 | 125 | cmake_args = [
|
95 | 126 | "cmake",
|
| 127 | + "-G", |
| 128 | + "Ninja", |
96 | 129 | "-DCMAKE_BUILD_TYPE=Release",
|
97 | 130 | "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX,
|
98 | 131 | "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX,
|
99 | 132 | "-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT,
|
100 | 133 | "-DCMAKE_C_COMPILER:PATH="
|
101 |
| - + os.path.join(DPCPP_ROOT, "bin", "clang"), |
| 134 | + + os.path.join(DPCPP_ROOT, "bin", "clang-cl.exe"), |
102 | 135 | "-DCMAKE_CXX_COMPILER:PATH="
|
103 |
| - + os.path.join(DPCPP_ROOT, "bin", "dpcpp"), |
104 |
| - "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON", |
| 136 | + + os.path.join(DPCPP_ROOT, "bin", "dpcpp.exe"), |
| 137 | + "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=" + ENABLE_LO_PROGRAM_CREATION, |
105 | 138 | backends,
|
106 | 139 | ]
|
107 | 140 | subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False)
|
108 |
| - subprocess.check_call(["make", "V=1", "-j", "4"]) |
109 |
| - subprocess.check_call(["make", "install"]) |
110 |
| - |
111 |
| - os.chdir(dpctl_dir) |
112 |
| - for file in glob.glob(os.path.join(dpctl_dir, "install", "lib", "*.so*")): |
113 |
| - shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
114 |
| - |
115 |
| -if IS_WIN: |
116 |
| - cmake_args = [ |
117 |
| - "cmake", |
118 |
| - "-G", |
119 |
| - "Ninja", |
120 |
| - "-DCMAKE_BUILD_TYPE=Release", |
121 |
| - "-DCMAKE_INSTALL_PREFIX=" + INSTALL_PREFIX, |
122 |
| - "-DCMAKE_PREFIX_PATH=" + INSTALL_PREFIX, |
123 |
| - "-DDPCPP_INSTALL_DIR=" + DPCPP_ROOT, |
124 |
| - "-DCMAKE_C_COMPILER:PATH=" |
125 |
| - + os.path.join(DPCPP_ROOT, "bin", "clang-cl.exe"), |
126 |
| - "-DCMAKE_CXX_COMPILER:PATH=" |
127 |
| - + os.path.join(DPCPP_ROOT, "bin", "dpcpp.exe"), |
128 |
| - "-DDPCTL_ENABLE_LO_PROGRAM_CREATION=ON", |
129 |
| - backends, |
130 |
| - ] |
131 |
| - subprocess.check_call(cmake_args, stderr=subprocess.STDOUT, shell=False) |
132 |
| - subprocess.check_call(["ninja", "-n"]) |
133 |
| - subprocess.check_call(["ninja", "install"]) |
134 |
| - |
135 |
| - os.chdir(dpctl_dir) |
136 |
| - for file in glob.glob(os.path.join(dpctl_dir, "install", "lib", "*.lib")): |
137 |
| - shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
138 |
| - |
139 |
| - for file in glob.glob(os.path.join(dpctl_dir, "install", "bin", "*.dll")): |
140 |
| - shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
141 |
| - |
142 |
| -include_dir = os.path.join(dpctl_dir, "dpctl", "include") |
143 |
| -if os.path.exists(include_dir): |
144 |
| - shutil.rmtree(include_dir) |
145 |
| - |
146 |
| -shutil.copytree(os.path.join(dpctl_dir, "dpctl-capi", "include"), include_dir) |
| 141 | + subprocess.check_call(["ninja", "-n"]) |
| 142 | + subprocess.check_call(["ninja", "install"]) |
| 143 | + |
| 144 | + os.chdir(dpctl_dir) |
| 145 | + for file in glob.glob( |
| 146 | + os.path.join(dpctl_dir, "install", "lib", "*.lib") |
| 147 | + ): |
| 148 | + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
| 149 | + |
| 150 | + for file in glob.glob( |
| 151 | + os.path.join(dpctl_dir, "install", "bin", "*.dll") |
| 152 | + ): |
| 153 | + shutil.copy(file, os.path.join(dpctl_dir, "dpctl")) |
| 154 | + |
| 155 | + include_dir = os.path.join(dpctl_dir, "dpctl", "include") |
| 156 | + if os.path.exists(include_dir): |
| 157 | + shutil.rmtree(include_dir) |
| 158 | + |
| 159 | + shutil.copytree( |
| 160 | + os.path.join(dpctl_dir, "dpctl-capi", "include"), include_dir |
| 161 | + ) |
| 162 | + |
| 163 | + |
| 164 | +if __name__ == "__main__": |
| 165 | + build_backend() |
0 commit comments