Skip to content

[UR] Move adapter tests over to lit #18397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ur-build-hw.yml
Original file line number Diff line number Diff line change
@@ -164,7 +164,8 @@ jobs:
- name: Test adapter specific
env:
ZE_ENABLE_LOADER_DEBUG_TRACE: 1
run: ctest -C ${{matrix.build_type}} --test-dir build --output-on-failure -L "adapter-specific" -E "memcheck" --timeout 600 -VV
LIT_OPTS: "--timeout 120 --filter-out 'adapters/level_zero/memcheck.test'"
run: cmake --build build -j $(nproc) -- check-unified-runtime-adapter
# Don't run adapter specific tests when building multiple adapters
if: ${{ matrix.adapter.other_name == '' }}

30 changes: 20 additions & 10 deletions unified-runtime/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -26,6 +26,10 @@ set(INSTALL_GTEST OFF)
FetchContent_MakeAvailable(googletest)
enable_testing()

# At the time of writing this comment, this is only used for level_zero adapter testing.
# It is found here for use in `lit.site.cfg.py.in`, which is inherited by said testing.
find_program(VALGRIND valgrind)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to have just been moved from unified-runtime/test/adapters/CMakeLists.txt, but what do we need valgrind for? Is it to propagate it in the lit configuration further down?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, it's so the .in file can be populated with the path to the valgrind binary. In theory I could add a .in file in test/adapters, but that feels like more effort than it's worth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable, but a comment might be good.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.


# Set up the root `check-unified-runtime` target
configure_file(lit.site.cfg.py.in lit.site.cfg.py)
add_custom_target(deps_check-unified-runtime)
@@ -77,24 +81,30 @@ function(add_ur_lit_testsuite suite)
set(TEST_CURRENT_SUITE "${TARGET}" PARENT_SCOPE)
endfunction()

# Add a new gtest test; it will be added to the dependency list of the current `add_ur_lit_testsuite`
function(add_gtest_test name)
set(TEST_TARGET_NAME ${name}-test)
add_ur_executable(${TEST_TARGET_NAME} ${ARGN})
target_link_libraries(${TEST_TARGET_NAME}
function(add_testing_binary target)
add_ur_executable(${target} ${ARGN})
target_link_libraries(${target}
PRIVATE
${PROJECT_NAME}::loader
${PROJECT_NAME}::headers
${PROJECT_NAME}::testing
${PROJECT_NAME}::mock
${PROJECT_NAME}::common
gmock
GTest::gtest_main)
set_target_properties(${TEST_TARGET_NAME}
${PROJECT_NAME}::common)
set_target_properties(${target}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
)
add_dependencies(deps_${TEST_CURRENT_SUITE} ${TEST_TARGET_NAME})
add_dependencies(deps_${TEST_CURRENT_SUITE} ${target})
endfunction()

# Add a new gtest test; it will be added to the dependency list of the current `add_ur_lit_testsuite`
function(add_gtest_test name)
set(TEST_TARGET_NAME ${name}-test)
add_testing_binary(${TEST_TARGET_NAME} ${ARGN})
target_link_libraries(${TEST_TARGET_NAME}
PRIVATE
gmock
GTest::gtest_main)
endfunction()

# Conformance defines the generate_device_binaries target which should be
73 changes: 1 addition & 72 deletions unified-runtime/test/adapters/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -3,78 +3,7 @@
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

function(add_adapter_test name)
cmake_parse_arguments(args
"" # options
"FIXTURE" # one value keywords
"SOURCES;ENVIRONMENT" # multi value keywords
${ARGN})

set(target test-adapter-${name})
add_ur_executable(${target} ${args_SOURCES}
${PROJECT_SOURCE_DIR}/test/conformance/source/environment.cpp
${PROJECT_SOURCE_DIR}/test/conformance/source/main.cpp
)

set(fixtures "PLATFORM;DEVICES;KERNELS")
if(NOT args_FIXTURE IN_LIST fixtures)
message(FATAL_ERROR
"FIXTURE must be one of: ${fixtures}. Found: ${args_FIXTURE}")
endif()

target_compile_definitions(${target} PRIVATE
${args_FIXTURE}_ENVIRONMENT)

if(${args_FIXTURE} STREQUAL "KERNELS")
target_compile_definitions(${target} PRIVATE KERNELS_ENVIRONMENT PRIVATE
KERNELS_DEFAULT_DIR="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}")
target_include_directories(${target}
PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
add_dependencies(${target} generate_device_binaries kernel_names_header)
endif()

target_link_libraries(${target} PRIVATE
${PROJECT_NAME}::loader
${PROJECT_NAME}::headers
${PROJECT_NAME}::testing
${PROJECT_NAME}::common
GTest::gtest)

add_test(NAME ${target} COMMAND $<TARGET_FILE:${target}>
--devices_count=${UR_TEST_DEVICES_COUNT}
--platforms_count=${UR_TEST_DEVICES_COUNT})
set_tests_properties(${target} PROPERTIES
LABELS "adapter-specific;${name}"
ENVIRONMENT "${args_ENVIRONMENT}")
endfunction()

find_program(VALGRIND valgrind)

function(add_adapter_memcheck_test name)
cmake_parse_arguments(args
"" # options
"" # one value keywords
"ENVIRONMENT" # multi value keywords
${ARGN})
if(VALGRIND)
set(target test-adapter-${name})
set(test_name ${target}-memcheck)

add_test(NAME ${test_name}
COMMAND ${CMAKE_COMMAND}
-D TEST_FILE=valgrind
-D TEST_ARGS="--tool=memcheck --leak-check=full $<TARGET_FILE:${target}> --backend=${backend} --devices_count=${UR_TEST_DEVICES_COUNT} --platforms_count=${UR_TEST_DEVICES_COUNT}"
-D MODE=stderr
-D MATCH_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${name}_memcheck.match
-P ${PROJECT_SOURCE_DIR}/cmake/match.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)

set_tests_properties(${test_name} PROPERTIES
LABELS "adapter-specific;${name}"
ENVIRONMENT "${args_ENVIRONMENT}")
endif()
endfunction()
add_custom_target(check-unified-runtime-adapter)

if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
add_subdirectory(cuda)
41 changes: 20 additions & 21 deletions unified-runtime/test/adapters/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -9,32 +9,31 @@ if(NOT UR_FOUND_DPCXX)
return()
endif()

add_adapter_test(cuda
FIXTURE DEVICES
SOURCES
fixtures.h
context_tests.cpp
urContextGetNativeHandle.cpp
urDeviceGetNativeHandle.cpp
urDeviceCreateWithNativeHandle.cpp
urEventGetNativeHandle.cpp
urEventCreateWithNativeHandle.cpp
urQueueGetNativeHandle.cpp
kernel_tests.cpp
memory_tests.cpp
event_tests.cpp
#FIXME: make this cleaner
${CMAKE_CURRENT_SOURCE_DIR}/../../../source/adapters/cuda/queue.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../../source/adapters/cuda/common.cpp
ENVIRONMENT
"UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_cuda>\""
add_ur_lit_testsuite(cuda)
add_dependencies(check-unified-runtime-adapter check-unified-runtime-cuda)

add_conformance_devices_test(adapter-cuda
fixtures.h
context_tests.cpp
urContextGetNativeHandle.cpp
urDeviceGetNativeHandle.cpp
urDeviceCreateWithNativeHandle.cpp
urEventGetNativeHandle.cpp
urEventCreateWithNativeHandle.cpp
urQueueGetNativeHandle.cpp
kernel_tests.cpp
memory_tests.cpp
event_tests.cpp
#FIXME: make this cleaner
${CMAKE_CURRENT_SOURCE_DIR}/../../../source/adapters/cuda/queue.cpp
${CMAKE_CURRENT_SOURCE_DIR}/../../../source/adapters/cuda/common.cpp
)

target_include_directories(test-adapter-cuda PRIVATE
target_include_directories(adapter-cuda-test PRIVATE
${PROJECT_SOURCE_DIR}/source
${PROJECT_SOURCE_DIR}/source/adapters/cuda
)

find_package(CUDAToolkit 10.1 REQUIRED)

target_link_libraries(test-adapter-cuda PRIVATE cudadrv CUDA::nvml ${PROJECT_NAME}::umf)
target_link_libraries(adapter-cuda-test PRIVATE cudadrv CUDA::nvml ${PROJECT_NAME}::umf)
17 changes: 17 additions & 0 deletions unified-runtime/test/adapters/cuda/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Copyright (C) 2025 Intel Corporation

Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

"""

import lit.formats

config.name = "Unified Runtime Adapter (CUDA)"
config.test_format = lit.formats.GoogleTest("", "-test")
config.test_source_root = config.binary_dir
config.test_exec_root = config.binary_dir

config.environment["ONEAPI_DEVICE_SELECTOR"] = "cuda:*"
3 changes: 3 additions & 0 deletions unified-runtime/test/adapters/cuda/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.binary_dir = "@CMAKE_CURRENT_BINARY_DIR@"

lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
29 changes: 14 additions & 15 deletions unified-runtime/test/adapters/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -9,29 +9,28 @@ if(NOT UR_FOUND_DPCXX)
return()
endif()

add_adapter_test(hip
FIXTURE KERNELS
SOURCES
fixtures.h
urContextGetNativeHandle.cpp
urDeviceGetNativeHandle.cpp
urEventGetNativeHandle.cpp
test_context.cpp
test_event.cpp
kernel_tests.cpp
ENVIRONMENT
"UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_hip>\""
add_ur_lit_testsuite(hip)
add_dependencies(check-unified-runtime-adapter check-unified-runtime-hip)

add_conformance_kernels_test(adapter-hip
fixtures.h
urContextGetNativeHandle.cpp
urDeviceGetNativeHandle.cpp
urEventGetNativeHandle.cpp
test_context.cpp
test_event.cpp
kernel_tests.cpp
)

target_include_directories(test-adapter-hip PRIVATE
target_include_directories(adapter-hip-test PRIVATE
${PROJECT_SOURCE_DIR}/source
${PROJECT_SOURCE_DIR}/source/adapters/hip
)

get_target_property(HIP_COMPILE_DEFINITIONS
ur_adapter_hip COMPILE_DEFINITIONS)
target_compile_definitions(test-adapter-hip PRIVATE
target_compile_definitions(adapter-hip-test PRIVATE
${HIP_COMPILE_DEFINITIONS}
)

target_link_libraries(test-adapter-hip PRIVATE rocmdrv ${PROJECT_NAME}::umf)
target_link_libraries(adapter-hip-test PRIVATE rocmdrv ${PROJECT_NAME}::umf)
17 changes: 17 additions & 0 deletions unified-runtime/test/adapters/hip/lit.cfg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Copyright (C) 2025 Intel Corporation

Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

"""

import lit.formats

config.name = "Unified Runtime Adapter (HIP)"
config.test_format = lit.formats.GoogleTest("", "-test")
config.test_source_root = config.binary_dir
config.test_exec_root = config.binary_dir

config.environment["ONEAPI_DEVICE_SELECTOR"] = "hip:*"
3 changes: 3 additions & 0 deletions unified-runtime/test/adapters/hip/lit.site.cfg.py.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.binary_dir = "@CMAKE_CURRENT_BINARY_DIR@"

lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
Loading