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

via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 9 12:01:14 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-offload

Author: Ɓukasz Plewa (lplewa)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/185492.diff


2 Files Affected:

- (modified) offload/unittests/CMakeLists.txt (+21) 
- (modified) offload/unittests/OffloadAPI/common/Environment.cpp (+2) 


``````````diff
diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index 308849a8364ac..d38b67ed39d20 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;

``````````

</details>


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


More information about the llvm-commits mailing list