|
1 | | - |
2 | 1 | #!/bin/bash |
3 | 2 | # Copyright (c) Meta Platforms, Inc. and affiliates. |
4 | 3 | # All rights reserved. |
@@ -43,7 +42,72 @@ install_vulkan_sdk() { |
43 | 42 | export PATH="${PATH}:${_vulkan_sdk_dir}/${VULKAN_SDK_VERSION}/x86_64/bin/" |
44 | 43 | } |
45 | 44 |
|
| 45 | +_maybe_sudo() { |
| 46 | + if [ "$(id -u)" -eq 0 ]; then |
| 47 | + "$@" |
| 48 | + else |
| 49 | + sudo "$@" |
| 50 | + fi |
| 51 | +} |
| 52 | + |
| 53 | +install_glslc() { |
| 54 | + # The glslc shipped in the LunarG SDK is dynamically linked against a newer |
| 55 | + # glibc/libstdc++ than the manylinux_2_28 / AlmaLinux 8 CUDA runner image |
| 56 | + # provides (glibc 2.28), where it fails to load with "GLIBC_2.29 not found". |
| 57 | + # conda-forge's shaderc is built against an old sysroot, runs there, and is |
| 58 | + # recent enough for the GL_EXT_integer_dot_product / GL_KHR_cooperative_matrix |
| 59 | + # extensions the Vulkan shaders use. Install it into an isolated prefix so the |
| 60 | + # base conda env that builds ExecuTorch is left untouched, then put it on PATH. |
| 61 | + _glslc_prefix=/tmp/shaderc |
| 62 | + conda create -y -p "${_glslc_prefix}" -c conda-forge shaderc |
| 63 | + export PATH="${_glslc_prefix}/bin:${PATH}" |
| 64 | +} |
| 65 | + |
| 66 | +install_vulkan_loader() { |
| 67 | + # libvulkan.so.1 (the Khronos loader that volk dlopen()s at runtime) is not part |
| 68 | + # of the NVIDIA driver and is absent from the CUDA builder image; vulkan-tools |
| 69 | + # provides vulkaninfo for the device sanity check. Both ship as native el8 RPMs. |
| 70 | + if command -v dnf >/dev/null 2>&1; then |
| 71 | + _maybe_sudo dnf install -y vulkan-loader vulkan-tools |
| 72 | + fi |
| 73 | +} |
| 74 | + |
| 75 | +setup_real_gpu_icd() { |
| 76 | + # On a real-GPU runner the system Vulkan ICD is installed by the GPU driver. |
| 77 | + # The loader searches both /etc/vulkan/icd.d and /usr/share/vulkan/icd.d, so |
| 78 | + # check both. If a system ICD is present, do NOT use SwiftShader so the real |
| 79 | + # device (and its fp16/int16/dot-product shader variants) is exercised. Fall |
| 80 | + # back to SwiftShader if no system ICD is found so the job stays green either |
| 81 | + # way. |
| 82 | + # Match each directory separately: a single `ls` over both globs returns |
| 83 | + # non-zero if either directory has no match, which would mask a real ICD that |
| 84 | + # is present in only one location (e.g. NVIDIA's in /usr/share/vulkan/icd.d). |
| 85 | + if compgen -G "/etc/vulkan/icd.d/*.json" >/dev/null || \ |
| 86 | + compgen -G "/usr/share/vulkan/icd.d/*.json" >/dev/null; then |
| 87 | + echo "System Vulkan ICD(s) detected:" |
| 88 | + ls /etc/vulkan/icd.d/*.json /usr/share/vulkan/icd.d/*.json 2>/dev/null || true |
| 89 | + unset ETVK_USING_SWIFTSHADER || true |
| 90 | + else |
| 91 | + echo "WARNING: no system Vulkan ICD found; using SwiftShader." |
| 92 | + install_swiftshader |
| 93 | + fi |
| 94 | +} |
| 95 | + |
46 | 96 | VULKAN_SDK_VERSION="1.4.321.1" |
47 | 97 |
|
48 | | -install_swiftshader |
49 | | -install_vulkan_sdk "${VULKAN_SDK_VERSION}" |
| 98 | +# The no-argument default installs SwiftShader so the existing CPU-runner CI is |
| 99 | +# unchanged. Pass "real-gpu" to prefer a real system ICD when one is present. |
| 100 | +case "${1:-swiftshader}" in |
| 101 | + real-gpu) |
| 102 | + # Do not download the LunarG SDK here: its prebuilt glslc cannot run on the |
| 103 | + # old-glibc CUDA image. glslc comes from conda-forge and the loader from the |
| 104 | + # system package manager instead. |
| 105 | + install_vulkan_loader |
| 106 | + install_glslc |
| 107 | + setup_real_gpu_icd |
| 108 | + ;; |
| 109 | + swiftshader | *) |
| 110 | + install_swiftshader |
| 111 | + install_vulkan_sdk "${VULKAN_SDK_VERSION}" |
| 112 | + ;; |
| 113 | +esac |
0 commit comments