Skip to content

Commit 0f7fcdb

Browse files
committed
[UR][Test] Expose UR_CONFORMANCE_TARGET_TRIPLES to tests
Forward the value of UR_CONFORMANCE_TARGET_TRIPLES as an array to the conformance tests, and make it available to tests via `KernelsEnvironment::HaveSourcesForTarget(target_name)`. This allows tests to require specific targets to be available.
1 parent f3b040c commit 0f7fcdb

File tree

5 files changed

+73
-21
lines changed

5 files changed

+73
-21
lines changed

unified-runtime/test/conformance/CMakeLists.txt

+22-20
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,28 @@ function(add_conformance_test_with_platform_environment name)
9191
target_compile_definitions("test-${name}" PRIVATE PLATFORM_ENVIRONMENT)
9292
endfunction()
9393

94+
if(UR_FOUND_DPCXX)
95+
add_custom_target(generate_device_binaries)
96+
97+
set(UR_CONFORMANCE_DEVICE_BINARIES_DIR
98+
"${CMAKE_CURRENT_BINARY_DIR}/device_binaries" CACHE INTERNAL UR_CONFORMANCE_DEVICE_BINARIES_DIR)
99+
file(MAKE_DIRECTORY ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
100+
101+
if("${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
102+
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_L0_V2 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL)
103+
list(APPEND TARGET_TRIPLES "spir64")
104+
endif()
105+
if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
106+
list(APPEND TARGET_TRIPLES "nvptx64-nvidia-cuda")
107+
endif()
108+
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
109+
list(APPEND TARGET_TRIPLES "amdgcn-amd-amdhsa")
110+
endif()
111+
else()
112+
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
113+
endif()
114+
endif()
115+
94116
add_subdirectory(testing)
95117

96118
add_subdirectory(adapter)
@@ -118,26 +140,6 @@ set(TEST_SUBDIRECTORIES_DPCXX
118140
)
119141

120142
if(UR_FOUND_DPCXX)
121-
add_custom_target(generate_device_binaries)
122-
123-
set(UR_CONFORMANCE_DEVICE_BINARIES_DIR
124-
"${CMAKE_CURRENT_BINARY_DIR}/device_binaries" CACHE INTERNAL UR_CONFORMANCE_DEVICE_BINARIES_DIR)
125-
file(MAKE_DIRECTORY ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
126-
127-
if("${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
128-
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_L0_V2 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL)
129-
list(APPEND TARGET_TRIPLES "spir64")
130-
endif()
131-
if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
132-
list(APPEND TARGET_TRIPLES "nvptx64-nvidia-cuda")
133-
endif()
134-
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
135-
list(APPEND TARGET_TRIPLES "amdgcn-amd-amdhsa")
136-
endif()
137-
else()
138-
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
139-
endif()
140-
141143
foreach(dir ${TEST_SUBDIRECTORIES_DPCXX})
142144
add_subdirectory(${dir})
143145
endforeach()

unified-runtime/test/conformance/source/environment.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include <ur_util.hpp>
2222
#include <uur/environment.h>
23+
#include <uur/targets.h>
2324
#include <uur/utils.h>
2425

2526
namespace uur {
@@ -240,6 +241,14 @@ KernelsEnvironment::getKernelSourcePath(const std::string &kernel_name,
240241
return path.str();
241242
}
242243

244+
bool KernelsEnvironment::HaveSourcesForTarget(const std::string &target_name) {
245+
auto it = std::find_if(
246+
std::begin(uur::UR_CONFORMANCE_TARGET_TRIPLES),
247+
std::end(uur::UR_CONFORMANCE_TARGET_TRIPLES),
248+
[&target_name](const char *triple) { return target_name == triple; });
249+
return it != std::end(uur::UR_CONFORMANCE_TARGET_TRIPLES);
250+
}
251+
243252
void KernelsEnvironment::LoadSource(
244253
const std::string &kernel_name, ur_platform_handle_t platform,
245254
std::shared_ptr<std::vector<char>> &binary_out) {

unified-runtime/test/conformance/testing/CMakeLists.txt

+22-1
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@
33
# See LICENSE.TXT
44
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
55

6+
function(configure_targets_header input output)
7+
cmake_parse_arguments(PARSE_ARGV 2 ARG "" TARGETS_VAR TARGETS)
8+
if (ARG_UNPARSED_ARGUMENTS)
9+
message(FATAL_ERROR "Unexpected arguments \"${ARG_UNPARSED_ARGUMENTS}\"")
10+
endif()
11+
12+
list(TRANSFORM ARG_TARGETS PREPEND "\"")
13+
list(TRANSFORM ARG_TARGETS APPEND "\"")
14+
list(JOIN ARG_TARGETS ",\n" "${ARG_TARGETS_VAR}")
15+
16+
configure_file(${input} ${output} @ONLY)
17+
endfunction()
18+
19+
configure_targets_header(
20+
${CMAKE_CURRENT_SOURCE_DIR}/include/uur/targets.h.in
21+
${CMAKE_CURRENT_BINARY_DIR}/include/uur/targets.h
22+
TARGETS_VAR UR_CONFORMANCE_TARGET_TRIPLES_INITIALIZER
23+
TARGETS ${TARGET_TRIPLES})
24+
625
add_ur_library(ur_testing STATIC
726
source/utils.cpp
827
source/fixtures.cpp)
9-
target_include_directories(ur_testing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
28+
target_include_directories(ur_testing PUBLIC
29+
${CMAKE_CURRENT_SOURCE_DIR}/include
30+
${CMAKE_CURRENT_BINARY_DIR}/include)
1031
target_link_libraries(ur_testing PRIVATE
1132
gtest_main
1233
${PROJECT_NAME}::common

unified-runtime/test/conformance/testing/include/uur/environment.h

+2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ struct KernelsEnvironment : DevicesEnvironment {
6868
virtual void SetUp() override;
6969
virtual void TearDown() override;
7070

71+
static bool HaveSourcesForTarget(const std::string &target_name);
72+
7173
void LoadSource(const std::string &kernel_name, ur_platform_handle_t platform,
7274
std::shared_ptr<std::vector<char>> &binary_out);
7375

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2025 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM
3+
// Exceptions. See LICENSE.TXT
4+
//
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
7+
#ifndef UR_CONFORMANCE_INCLUDE_TARGETS_H_INCLUDED
8+
#define UR_CONFORMANCE_INCLUDE_TARGETS_H_INCLUDED
9+
10+
namespace uur {
11+
// clang-format off
12+
constexpr const char *UR_CONFORMANCE_TARGET_TRIPLES[] = {
13+
@UR_CONFORMANCE_TARGET_TRIPLES_INITIALIZER@
14+
};
15+
// clang-format on
16+
} // namespace uur
17+
18+
#endif // UR_CONFORMANCE_INCLUDE_TARGETS_H_INCLUDED

0 commit comments

Comments
 (0)