|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
| 5 | +import shutil |
5 | 6 | import os |
6 | 7 | import subprocess |
7 | 8 | import sys |
|
10 | 11 | from common import find_file |
11 | 12 |
|
12 | 13 |
|
13 | | -def find_windows_tbb_runtime_dir() -> Path | None: |
14 | | - build_root = Path("build").resolve() |
15 | | - fallback: Path | None = None |
16 | | - for current_root, _, files in os.walk(build_root): |
17 | | - current_files = set(files) |
18 | | - if "tbb12.dll" not in current_files: |
19 | | - continue |
20 | | - |
21 | | - candidate = Path(current_root) |
22 | | - if "tbbmalloc.dll" in current_files or "tbbmalloc_proxy.dll" in current_files: |
23 | | - return candidate |
24 | | - if fallback is None: |
25 | | - fallback = candidate |
26 | | - |
27 | | - return fallback |
28 | | - |
29 | | - |
30 | | -def configure_windows_opencl_tbb() -> None: |
| 14 | +def prepare_windows_opencl_runtime() -> None: |
31 | 15 | if os.environ.get("RUNNER_OS") != "Windows": |
32 | 16 | return |
33 | 17 |
|
34 | 18 | icd_path = os.environ.get("OCL_ICD_FILENAMES") |
35 | 19 | if not icd_path: |
36 | 20 | return |
37 | 21 |
|
38 | | - config_path = Path(icd_path).with_name("cl.cfg") |
39 | | - if not config_path.exists(): |
| 22 | + runtime_dir = Path(icd_path).resolve().parent |
| 23 | + runtime_opencl = runtime_dir / "OpenCL.dll" |
| 24 | + if not runtime_opencl.exists(): |
40 | 25 | return |
41 | 26 |
|
42 | | - tbb_runtime_dir = find_windows_tbb_runtime_dir() |
43 | | - if tbb_runtime_dir is None: |
| 27 | + example_binary = find_file([Path("build").resolve()], "SYCL_Example.exe") |
| 28 | + if example_binary is None: |
44 | 29 | return |
45 | 30 |
|
46 | | - tbb_dir = str(tbb_runtime_dir.resolve()) |
47 | | - existing_lines = config_path.read_text(encoding="utf-8").splitlines() |
48 | | - updated_lines: list[str] = [] |
49 | | - updated = False |
50 | | - for line in existing_lines: |
51 | | - if line.strip().startswith("CL_CONFIG_TBB_DLL_PATH"): |
52 | | - updated_lines.append(f"CL_CONFIG_TBB_DLL_PATH = {tbb_dir}") |
53 | | - updated = True |
54 | | - else: |
55 | | - updated_lines.append(line) |
56 | | - |
57 | | - if not updated: |
58 | | - updated_lines.append(f"CL_CONFIG_TBB_DLL_PATH = {tbb_dir}") |
59 | | - |
60 | | - config_path.write_text("\n".join(updated_lines) + "\n", encoding="utf-8") |
61 | | - print(f"+ patched {config_path} with CL_CONFIG_TBB_DLL_PATH={tbb_dir}", flush=True) |
| 31 | + staged_opencl = example_binary.parent / runtime_opencl.name |
| 32 | + shutil.copy2(runtime_opencl, staged_opencl) |
| 33 | + print( |
| 34 | + f"+ staged {runtime_opencl} next to {example_binary}", |
| 35 | + flush=True, |
| 36 | + ) |
62 | 37 |
|
63 | 38 |
|
64 | 39 | def main() -> int: |
65 | | - configure_windows_opencl_tbb() |
| 40 | + prepare_windows_opencl_runtime() |
66 | 41 |
|
67 | 42 | env = os.environ.copy() |
68 | | - if os.environ.get("RUNNER_OS") == "Windows": |
69 | | - tbb_runtime_dir = find_windows_tbb_runtime_dir() |
70 | | - if tbb_runtime_dir is not None: |
71 | | - env["PATH"] = f"{tbb_runtime_dir}{os.pathsep}{env.get('PATH', '')}" |
72 | 43 |
|
73 | 44 | device_selector = env.get("DEVICE_SELECTOR", "") |
74 | 45 | if device_selector: |
|
0 commit comments