From c9cc91a95638f4d133dc6fc9ccef700299697f84 Mon Sep 17 00:00:00 2001 From: Charro Gruver Date: Thu, 6 Feb 2025 17:31:43 +0000 Subject: [PATCH 1/2] Detect Intel ARC GPU in Meteor Lake chipset Signed-off-by: Charro Gruver --- ramalama/common.py | 12 +++++++++++- ramalama/model.py | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ramalama/common.py b/ramalama/common.py index 240f38b4..810954d7 100644 --- a/ramalama/common.py +++ b/ramalama/common.py @@ -282,9 +282,19 @@ def get_gpu(): os.environ["HIP_VISIBLE_DEVICES"] = str(gpu_num) return + # INTEL iGPU CASE (Look for ARC GPU) + if os.path.exists('/sys/bus/pci/drivers/i915/0000:00:02.0/device'): + try: + with open('/sys/bus/pci/drivers/i915/0000:00:02.0/device', 'rb') as f: + content = f.read() + if b"0x7d55" in content: + os.environ["INTEL_VISIBLE_DEVICES"] = "1" + except OSError: + # Handle the case where the file does not exist + pass def get_env_vars(): - prefixes = ("ASAHI_", "CUDA_", "HIP_", "HSA_") + prefixes = ("ASAHI_", "CUDA_", "HIP_", "HSA_", "INTEL_") env_vars = {k: v for k, v in os.environ.items() if k.startswith(prefixes)} # gpu_type, gpu_num = get_gpu() diff --git a/ramalama/model.py b/ramalama/model.py index 48ca3750..2f2820e6 100644 --- a/ramalama/model.py +++ b/ramalama/model.py @@ -129,6 +129,7 @@ def _image(self, args): "HIP_VISIBLE_DEVICES": "quay.io/ramalama/rocm", "CUDA_VISIBLE_DEVICES": "quay.io/ramalama/cuda", "ASAHI_VISIBLE_DEVICES": "quay.io/ramalama/asahi", + "INTEL_VISIBLE_DEVICES": "quay.io/ramalama/intel-gpu", } image = images.get(gpu_type, args.image) @@ -199,6 +200,7 @@ def gpu_args(self, args, runner=False): or os.getenv("HIP_VISIBLE_DEVICES") or os.getenv("ASAHI_VISIBLE_DEVICES") or os.getenv("CUDA_VISIBLE_DEVICES") + or os.getenv("INTEL_VISIBLE_DEVICES") or ( # linux and macOS report aarch64 differently platform.machine() in {"aarch64", "arm64"} From df6e7677feac2541d7ab415d4fa1c0fd71ad1539 Mon Sep 17 00:00:00 2001 From: Charro Gruver Date: Fri, 7 Feb 2025 20:38:31 +0000 Subject: [PATCH 2/2] update check for Intel iGPU to use glob Signed-off-by: Charro Gruver --- ramalama/common.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ramalama/common.py b/ramalama/common.py index 810954d7..cc3233e3 100644 --- a/ramalama/common.py +++ b/ramalama/common.py @@ -283,15 +283,15 @@ def get_gpu(): return # INTEL iGPU CASE (Look for ARC GPU) - if os.path.exists('/sys/bus/pci/drivers/i915/0000:00:02.0/device'): - try: - with open('/sys/bus/pci/drivers/i915/0000:00:02.0/device', 'rb') as f: - content = f.read() - if b"0x7d55" in content: - os.environ["INTEL_VISIBLE_DEVICES"] = "1" - except OSError: - # Handle the case where the file does not exist - pass + igpu_num = 0 + for fp in sorted(glob.glob('/sys/bus/pci/drivers/i915/*/device')): + with open(fp, 'rb') as file: + content = file.read() + if b"0x7d55" in content: + igpu_num += 1 + + if igpu_num: + os.environ["INTEL_VISIBLE_DEVICES"] = str(igpu_num) def get_env_vars(): prefixes = ("ASAHI_", "CUDA_", "HIP_", "HSA_", "INTEL_")