Skip to content

[UR][Test] Expose UR_CONFORMANCE_TARGET_TRIPLES to tests #18280

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

Closed
Closed
Show file tree
Hide file tree
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
42 changes: 22 additions & 20 deletions unified-runtime/test/conformance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ function(add_conformance_test_with_platform_environment name)
target_compile_definitions("test-${name}" PRIVATE PLATFORM_ENVIRONMENT)
endfunction()

if(UR_FOUND_DPCXX)
add_custom_target(generate_device_binaries)

set(UR_CONFORMANCE_DEVICE_BINARIES_DIR
"${CMAKE_CURRENT_BINARY_DIR}/device_binaries" CACHE INTERNAL UR_CONFORMANCE_DEVICE_BINARIES_DIR)
file(MAKE_DIRECTORY ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})

if("${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_L0_V2 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "spir64")
endif()
if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "nvptx64-nvidia-cuda")
endif()
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "amdgcn-amd-amdhsa")
endif()
else()
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
endif()
endif()

add_subdirectory(testing)

add_subdirectory(adapter)
Expand Down Expand Up @@ -118,26 +140,6 @@ set(TEST_SUBDIRECTORIES_DPCXX
)

if(UR_FOUND_DPCXX)
add_custom_target(generate_device_binaries)

set(UR_CONFORMANCE_DEVICE_BINARIES_DIR
"${CMAKE_CURRENT_BINARY_DIR}/device_binaries" CACHE INTERNAL UR_CONFORMANCE_DEVICE_BINARIES_DIR)
file(MAKE_DIRECTORY ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})

if("${UR_CONFORMANCE_TARGET_TRIPLES}" STREQUAL "")
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_L0_V2 OR UR_BUILD_ADAPTER_OPENCL OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "spir64")
endif()
if(UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "nvptx64-nvidia-cuda")
endif()
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
list(APPEND TARGET_TRIPLES "amdgcn-amd-amdhsa")
endif()
else()
string(REPLACE "," ";" TARGET_TRIPLES ${UR_CONFORMANCE_TARGET_TRIPLES})
endif()

foreach(dir ${TEST_SUBDIRECTORIES_DPCXX})
add_subdirectory(${dir})
endforeach()
Expand Down
9 changes: 9 additions & 0 deletions unified-runtime/test/conformance/source/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <ur_util.hpp>
#include <uur/environment.h>
#include <uur/targets.h>
#include <uur/utils.h>

namespace uur {
Expand Down Expand Up @@ -240,6 +241,14 @@ KernelsEnvironment::getKernelSourcePath(const std::string &kernel_name,
return path.str();
}

bool KernelsEnvironment::HaveSourcesForTarget(const std::string &target_name) {
auto it = std::find_if(
Copy link
Contributor

Choose a reason for hiding this comment

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

std::any_of might be more idiomatic here.

std::begin(uur::UR_CONFORMANCE_TARGET_TRIPLES),
std::end(uur::UR_CONFORMANCE_TARGET_TRIPLES),
[&target_name](const char *triple) { return target_name == triple; });
return it != std::end(uur::UR_CONFORMANCE_TARGET_TRIPLES);
}

void KernelsEnvironment::LoadSource(
const std::string &kernel_name, ur_platform_handle_t platform,
std::shared_ptr<std::vector<char>> &binary_out) {
Expand Down
24 changes: 23 additions & 1 deletion unified-runtime/test/conformance/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,32 @@
# See LICENSE.TXT
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

function(configure_targets_header input output)
cmake_parse_arguments(PARSE_ARGV 2 ARG "" VAR_PREFIX TARGETS)
if (ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unexpected arguments \"${ARG_UNPARSED_ARGUMENTS}\"")
endif()

list(LENGTH ARG_TARGETS "${ARG_VAR_PREFIX}_NUM")
list(TRANSFORM ARG_TARGETS PREPEND "\"")
list(TRANSFORM ARG_TARGETS APPEND "\"")
list(JOIN ARG_TARGETS ",\n" "${ARG_VAR_PREFIX}_INITIALIZER")

configure_file(${input} ${output} @ONLY)
endfunction()

configure_targets_header(
${CMAKE_CURRENT_SOURCE_DIR}/include/uur/targets.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/uur/targets.h
VAR_PREFIX UR_CONFORMANCE_TARGET_TRIPLES
TARGETS ${TARGET_TRIPLES})

add_ur_library(ur_testing STATIC
source/utils.cpp
source/fixtures.cpp)
target_include_directories(ur_testing PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(ur_testing PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include)
target_link_libraries(ur_testing PRIVATE
gtest_main
${PROJECT_NAME}::common
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct KernelsEnvironment : DevicesEnvironment {
virtual void SetUp() override;
virtual void TearDown() override;

static bool HaveSourcesForTarget(const std::string &target_name);

void LoadSource(const std::string &kernel_name, ur_platform_handle_t platform,
std::shared_ptr<std::vector<char>> &binary_out);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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

#ifndef UR_CONFORMANCE_INCLUDE_TARGETS_H_INCLUDED
#define UR_CONFORMANCE_INCLUDE_TARGETS_H_INCLUDED

#include <array>

namespace uur {
// clang-format off
constexpr std::array<const char *, @UR_CONFORMANCE_TARGET_TRIPLES_NUM@> UR_CONFORMANCE_TARGET_TRIPLES = {
@UR_CONFORMANCE_TARGET_TRIPLES_INITIALIZER@
};
// clang-format on
} // namespace uur

#endif // UR_CONFORMANCE_INCLUDE_TARGETS_H_INCLUDED