[llvm] [offload] Add CUDA_ROOT to path for unit tests (PR #214282)

Nick Sarnie via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 09:53:18 PDT 2026


https://github.com/sarnex updated https://github.com/llvm/llvm-project/pull/214282

>From 5d6550dc245764914ebbf8cc1868ca744ae84995 Mon Sep 17 00:00:00 2001
From: Nick Sarnie <nick.sarnie at intel.com>
Date: Wed, 5 Aug 2026 08:55:12 -0700
Subject: [PATCH] [offload] Add CUDA_ROOT to path for unit tests

Signed-off-by: Nick Sarnie <nick.sarnie at intel.com>

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply at anthropic.com>
---
 offload/test/unit/lit.cfg.py      | 21 +++++++++++++++------
 offload/test/unit/lit.site.cfg.in |  1 +
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/offload/test/unit/lit.cfg.py b/offload/test/unit/lit.cfg.py
index 41d64da9ae9c2..01435e59ae03b 100644
--- a/offload/test/unit/lit.cfg.py
+++ b/offload/test/unit/lit.cfg.py
@@ -13,16 +13,25 @@
 # suffixes: A list of file extensions to treat as test files.
 config.suffixes = []
 
+
+def prepend_executable_path(path):
+    old_path = config.environment.get("PATH")
+    config.environment["PATH"] = (
+        f"{path}{os.path.pathsep}{old_path}" if old_path else path
+    )
+
+
 # Add the tools bin dir to the search path so the JIT tests can
 # find it. Prefer the tools from the configured LLVM install or
 # bootstrapping build.
 if config.bin_llvm_tools_dir:
-    old_path = config.environment.get("PATH")
-    config.environment["PATH"] = (
-        f"{config.bin_llvm_tools_dir}{os.path.pathsep}{old_path}"
-        if old_path
-        else config.bin_llvm_tools_dir
-    )
+    prepend_executable_path(config.bin_llvm_tools_dir)
+
+# The CUDA plugin invokes 'ptxas' via the PATH when JIT-compiling PTX for
+# NVPTX devices. Add the CUDA bin dir to the search path so the unit tests can
+# find it, mirroring what the main lit.cfg does for the lit tests.
+if config.cuda_path:
+    prepend_executable_path(f"{config.cuda_path}{os.path.sep}bin")
 
 # test_source_root: The root path where tests are located.
 # test_exec_root: The root path where tests should be run.
diff --git a/offload/test/unit/lit.site.cfg.in b/offload/test/unit/lit.site.cfg.in
index 7c1becaefbee1..821503a92327c 100644
--- a/offload/test/unit/lit.site.cfg.in
+++ b/offload/test/unit/lit.site.cfg.in
@@ -4,6 +4,7 @@ config.library_dir = "@LIBOMPTARGET_LIBRARY_DIR@"
 config.unittest_dir = "@OFFLOAD_UNITTEST_DIR@"
 config.llvm_build_mode = lit_config.substitute("@LLVM_BUILD_MODE@")
 config.bin_llvm_tools_dir = "@LLVM_TOOLS_BINARY_DIR@"
+config.cuda_path = "@CUDA_ROOT@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/unit/lit.cfg.py")



More information about the llvm-commits mailing list