From c9c4a605e63d35c64a8e2a05b51948ca2cd5c0ed Mon Sep 17 00:00:00 2001 From: Eric Curtin Date: Tue, 4 Feb 2025 10:42:28 +0000 Subject: [PATCH] Check for apple,arm-platform in /proc In /proc/device-tree/compatible specifically, thanks Asahi Lina! It's more portable accross Fedora Asahi Remix and Ubuntu Asahi Remix. Also added env var to container image. Co-authored-by: Asahi Lina Co-authored-by: Daniel J Walsh Signed-off-by: Eric Curtin --- container-images/asahi/Containerfile | 1 + ramalama/common.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/container-images/asahi/Containerfile b/container-images/asahi/Containerfile index eab5a2ee..3b758d2a 100644 --- a/container-images/asahi/Containerfile +++ b/container-images/asahi/Containerfile @@ -1,5 +1,6 @@ FROM fedora:41 +ENV ASAHI_VISIBLE_DEVICES 1 COPY ../scripts /scripts RUN chmod +x /scripts/*.sh && \ /scripts/build_llama_and_whisper.sh "asahi" diff --git a/ramalama/common.py b/ramalama/common.py index 50c1db2f..b5d63ca7 100644 --- a/ramalama/common.py +++ b/ramalama/common.py @@ -244,12 +244,16 @@ def get_gpu(): return # ASAHI CASE - if os.path.exists('/etc/os-release'): - with open('/etc/os-release', 'r') as file: - if "asahi" in file.read().lower(): - # Set Env Var and break - os.environ["ASAHI_VISIBLE_DEVICES"] = "1" - return + if os.path.exists('/proc/device-tree/compatible'): + try: + with open('/proc/device-tree/compatible', 'rb') as f: + content = f.read().split(b"\0") + # Check if "apple,arm-platform" is in the content + if b"apple,arm-platform" in content: + os.environ["ASAHI_VISIBLE_DEVICES"] = "1" + except OSError: + # Handle the case where the file does not exist + pass # NVIDIA CASE try: