Skip to content

Commit 722f6c0

Browse files
committed
[Testing] Improve "program" testing to better match the DPC++ e2e tests
This adds a number of conformance tests to test things that are required for the "program" DPC++ e2e tests. Note that these tests don't all pass. Adapter testing infrastructure for level zero has been added, and a single test has been added to check their specific handling of linker errors (they write it to the build log of the output program). Other than that, test additions are as follows: * A few specialization constant tests to test usage of a kernel with multiple specialization constants defined. * Testing of the default specialization values. * KernelGetInfo outputs the correct kernel name and context pointer. * Compiling an (valid or invalid) program produces a valid (though unspecified) build log. * The "num devices" program info is sensible.
1 parent a6cdcf4 commit 722f6c0

25 files changed

+416
-2
lines changed

include/ur_api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4076,6 +4076,8 @@ typedef struct ur_program_properties_t {
40764076
///
40774077
/// @details
40784078
/// - The application may call this function from simultaneous threads.
4079+
/// - The adapter may (but is not required to) perform validation of the
4080+
/// provided module during this call.
40794081
///
40804082
/// @remarks
40814083
/// _Analogues_
@@ -4118,6 +4120,8 @@ urProgramCreateWithIL(
41184120
/// ::UR_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`.
41194121
/// - The device specified by `hDevice` must be device associated with
41204122
/// context.
4123+
/// - The adapter may (but is not required to) perform validation of the
4124+
/// provided module during this call.
41214125
///
41224126
/// @remarks
41234127
/// _Analogues_

scripts/core/program.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ analogue:
8989
- "**clCreateProgramWithIL**"
9090
details:
9191
- "The application may call this function from simultaneous threads."
92+
- "The adapter may (but is not required to) perform validation of the provided module during this call."
9293
params:
9394
- type: $x_context_handle_t
9495
name: hContext
@@ -129,6 +130,7 @@ details:
129130
- "The application may call this function from simultaneous threads."
130131
- "Following a successful call to this entry point, `phProgram` will contain a binary of type $X_PROGRAM_BINARY_TYPE_COMPILED_OBJECT or $X_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`."
131132
- "The device specified by `hDevice` must be device associated with context."
133+
- "The adapter may (but is not required to) perform validation of the provided module during this call."
132134
params:
133135
- type: $x_context_handle_t
134136
name: hContext

source/loader/ur_libapi.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,8 @@ ur_result_t UR_APICALL urPhysicalMemRelease(
28902890
///
28912891
/// @details
28922892
/// - The application may call this function from simultaneous threads.
2893+
/// - The adapter may (but is not required to) perform validation of the
2894+
/// provided module during this call.
28932895
///
28942896
/// @remarks
28952897
/// _Analogues_
@@ -2942,6 +2944,8 @@ ur_result_t UR_APICALL urProgramCreateWithIL(
29422944
/// ::UR_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`.
29432945
/// - The device specified by `hDevice` must be device associated with
29442946
/// context.
2947+
/// - The adapter may (but is not required to) perform validation of the
2948+
/// provided module during this call.
29452949
///
29462950
/// @remarks
29472951
/// _Analogues_

source/ur_api.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,8 @@ ur_result_t UR_APICALL urPhysicalMemRelease(
24592459
///
24602460
/// @details
24612461
/// - The application may call this function from simultaneous threads.
2462+
/// - The adapter may (but is not required to) perform validation of the
2463+
/// provided module during this call.
24622464
///
24632465
/// @remarks
24642466
/// _Analogues_
@@ -2505,6 +2507,8 @@ ur_result_t UR_APICALL urProgramCreateWithIL(
25052507
/// ::UR_PROGRAM_BINARY_TYPE_LIBRARY for `hDevice`.
25062508
/// - The device specified by `hDevice` must be device associated with
25072509
/// context.
2510+
/// - The adapter may (but is not required to) perform validation of the
2511+
/// provided module during this call.
25082512
///
25092513
/// @remarks
25102514
/// _Analogues_

test/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
1717
FetchContent_MakeAvailable(googletest)
1818
enable_testing()
1919

20+
# Conformance defines the generate_device_binaries target which should be
21+
# imported first
22+
add_subdirectory(conformance)
23+
2024
add_subdirectory(loader)
2125
add_subdirectory(adapters)
22-
add_subdirectory(conformance)
2326
add_subdirectory(usm)
2427
add_subdirectory(layers)
2528
add_subdirectory(unit)

test/adapters/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ function(add_adapter_test name)
2424

2525
target_compile_definitions(${target} PRIVATE
2626
${args_FIXTURE}_ENVIRONMENT)
27+
28+
if(${args_FIXTURE} STREQUAL "KERNELS")
29+
target_compile_definitions(${target} PRIVATE KERNELS_ENVIRONMENT PRIVATE
30+
KERNELS_DEFAULT_DIR="${UR_CONFORMANCE_DEVICE_BINARIES_DIR}")
31+
target_include_directories(${target}
32+
PRIVATE ${UR_CONFORMANCE_DEVICE_BINARIES_DIR})
33+
add_dependencies(${target} generate_device_binaries kernel_names_header)
34+
endif()
35+
2736
target_link_libraries(${target} PRIVATE
2837
${PROJECT_NAME}::loader
2938
${PROJECT_NAME}::headers
@@ -46,3 +55,7 @@ endif()
4655
if(UR_BUILD_ADAPTER_HIP OR UR_BUILD_ADAPTER_ALL)
4756
add_subdirectory(hip)
4857
endif()
58+
59+
if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_ALL)
60+
add_subdirectory(level_zero)
61+
endif()
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright (C) 2024 Intel Corporation
2+
# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
# See LICENSE.TXT
4+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
if(NOT UR_DPCXX)
7+
# Tests that require kernels can't be used if we aren't generating
8+
# device binaries
9+
message(WARNING
10+
"UR_DPCXX is not defined, skipping adapter tests for level_zero")
11+
else()
12+
add_adapter_test(level_zero
13+
FIXTURE KERNELS
14+
SOURCES
15+
urProgramLink.cpp
16+
ENVIRONMENT
17+
"UR_ADAPTERS_FORCE_LOAD=\"$<TARGET_FILE:ur_adapter_level_zero>\""
18+
)
19+
20+
target_include_directories(test-adapter-level_zero PRIVATE
21+
${PROJECT_SOURCE_DIR}/source
22+
${PROJECT_SOURCE_DIR}/source/adapters/level_zero
23+
)
24+
25+
add_dependencies(test-adapter-level_zero
26+
generate_device_binaries kernel_names_header)
27+
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include <uur/fixtures.h>
7+
8+
using urLevelZeroProgramLinkTest = uur::urProgramTest;
9+
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urLevelZeroProgramLinkTest);
10+
11+
TEST_P(urLevelZeroProgramLinkTest, InvalidLinkOptionsPrintedInLog) {
12+
ur_program_handle_t linked_program = nullptr;
13+
ASSERT_SUCCESS(urProgramCompile(context, program, "-foo"));
14+
ASSERT_EQ_RESULT(
15+
UR_RESULT_ERROR_PROGRAM_LINK_FAILURE,
16+
urProgramLink(context, 1, &program, "-foo", &linked_program));
17+
18+
size_t logSize;
19+
std::vector<char> log;
20+
21+
ASSERT_SUCCESS(urProgramGetBuildInfo(linked_program, device,
22+
UR_PROGRAM_BUILD_INFO_LOG, 0, nullptr,
23+
&logSize));
24+
log.resize(logSize);
25+
log[logSize - 1] = 'x';
26+
ASSERT_SUCCESS(urProgramGetBuildInfo(linked_program, device,
27+
UR_PROGRAM_BUILD_INFO_LOG, logSize,
28+
log.data(), nullptr));
29+
ASSERT_EQ(log[logSize - 1], '\0');
30+
ASSERT_NE(std::string{log.data()}.find("-foo"), std::string::npos);
31+
}

test/conformance/device_code/CMakeLists.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ macro(add_device_binary SOURCE_FILE)
6767
if(${TRIPLE} MATCHES "amd" AND ${KERNEL_NAME} MATCHES "image_copy")
6868
continue()
6969
endif()
70+
71+
# This seems to fail to build the SYCL binary due to the invalid asm
72+
if(${TRIPLE} MATCHES "cuda" AND ${KERNEL_NAME} MATCHES "build_failure")
73+
continue()
74+
endif()
75+
if(${TRIPLE} MATCHES "amd" AND ${KERNEL_NAME} MATCHES "build_failure")
76+
continue()
77+
endif()
78+
7079
add_custom_command(OUTPUT ${EXE_PATH}
7180
COMMAND ${UR_DPCXX} -fsycl -fsycl-targets=${TRIPLE} -fsycl-device-code-split=off
7281
${AMD_TARGET_BACKEND} ${AMD_OFFLOAD_ARCH} ${AMD_NOGPULIB}
@@ -93,10 +102,12 @@ add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/foo.cpp)
93102
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/image_copy.cpp)
94103
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/mean.cpp)
95104
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/spec_constant.cpp)
105+
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/spec_constant_multiple.cpp)
96106
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/usm_ll.cpp)
97107
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/saxpy.cpp)
98108
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/saxpy_usm.cpp)
99109
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/indexers_usm.cpp)
110+
add_device_binary(${CMAKE_CURRENT_SOURCE_DIR}/build_failure.cpp)
100111

101112
set(KERNEL_HEADER ${UR_CONFORMANCE_DEVICE_BINARIES_DIR}/kernel_entry_points.h)
102113
add_custom_command(OUTPUT ${KERNEL_HEADER}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2024 Intel Corporation
2+
// Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
3+
// See LICENSE.TXT
4+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5+
6+
#include <sycl/sycl.hpp>
7+
8+
int main() {
9+
sycl::queue deviceQueue;
10+
11+
auto Kernel = []() {
12+
#ifdef __SYCL_DEVICE_ONLY__
13+
asm volatile("undefined\n");
14+
#endif // __SYCL_DEVICE_ONLY__
15+
};
16+
17+
deviceQueue.submit(
18+
[&](sycl::handler &cgh) { cgh.single_task<class Foo>(Kernel); });
19+
20+
return 0;
21+
}

0 commit comments

Comments
 (0)