From 0e122bea82651561891b76043dee0fc6749f64b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Plewa?= Date: Wed, 11 Mar 2026 15:09:59 +0100 Subject: [PATCH] [OFFLOAD] Enable Level Zero unittests (#185492) --- 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 308849a8364a..33b22b56b195 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 devices is not implemented yet. + # TODO: Remove the -ffreestanding flag once libc can be built for spirv64. + 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 ce06e6ff38a7..ba0474a826e7 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;