[llvm] [OFFLOAD] Enable Level Zero unittests (PR #185492)

Ɓukasz Plewa via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 12:02:38 PDT 2026


https://github.com/lplewa updated https://github.com/llvm/llvm-project/pull/185492

>From 03cb6d8a990ab338397bcd105c1ee9281a1ece7a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Plewa?= <lukasz.plewa at intel.com>
Date: Mon, 9 Mar 2026 19:42:08 +0100
Subject: [PATCH] [OFFLOAD] Enable Level Zero unittests

---
 offload/unittests/CMakeLists.txt              | 21 +++++++++++++++++++
 .../OffloadAPI/common/Environment.cpp         |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index 308849a8364ac..76b9543477ce4 100644
--- a/offload/unittests/CMakeLists.txt
+++ b/offload/unittests/CMakeLists.txt
@@ -102,6 +102,24 @@ function(add_offload_test_device_code test_filename test_name)
     endif()
   endif()
 
+  # Try to build with support for Level Zero SPIRV devices.
+  if("level_zero" IN_LIST LIBOMPTARGET_PLUGINS_TO_BUILD)
+    set(spirv_compile_flags ${OFFLOAD_TESTS_UNPARSED_ARGUMENTS})
+    set(output_file "${CMAKE_CURRENT_BINARY_DIR}/${test_name}.spirv64.bin")
+    # TODO: building for specific device is not implemented yet.
+    # TODO: remove the -ffreestanding flag once the libc for spirv64-intel target will be available.
+    add_custom_command(
+      OUTPUT ${output_file}
+      COMMAND ${CMAKE_CXX_COMPILER}
+      -I${OFFLOAD_UNITTESTS_DIR}
+      --target=spirv64-intel
+      -ffreestanding
+      -nogpulib -flto ${spirv_compile_flags} ${SRC_PATH} -o ${output_file}
+      DEPENDS ${SRC_PATH}
+    )
+    add_custom_target(${test_name}.spirv64 DEPENDS ${output_file})
+  endif()
+
   # Create a single dependency target for the device code.
   add_custom_target(${test_name}.bin)
   if(TARGET ${test_name}.amdgpu)
@@ -110,6 +128,9 @@ function(add_offload_test_device_code test_filename test_name)
   if(TARGET ${test_name}.nvptx64)
     add_dependencies(${test_name}.bin ${test_name}.nvptx64)
   endif()
+  if(TARGET ${test_name}.spirv64)
+    add_dependencies(${test_name}.bin ${test_name}.spirv64)
+  endif()
 endfunction()
 
 function(add_offload_unittest test_dirname)
diff --git a/offload/unittests/OffloadAPI/common/Environment.cpp b/offload/unittests/OffloadAPI/common/Environment.cpp
index ce06e6ff38a73..ba0474a826e7e 100644
--- a/offload/unittests/OffloadAPI/common/Environment.cpp
+++ b/offload/unittests/OffloadAPI/common/Environment.cpp
@@ -179,6 +179,8 @@ bool TestEnvironment::loadDeviceBinary(
     FileExtension = ".amdgpu.bin";
   } else if (Backend == OL_PLATFORM_BACKEND_CUDA) {
     FileExtension = ".nvptx64.bin";
+  } else if (Backend == OL_PLATFORM_BACKEND_LEVEL_ZERO) {
+    FileExtension = ".spirv64.bin";
   } else {
     errs() << "Unsupported platform type for a device binary test.\n";
     return false;



More information about the llvm-commits mailing list