Skip to content

Commit f3fa464

Browse files
committed
Enable program conformace test for L0
1 parent 0e397ca commit f3fa464

File tree

6 files changed

+53
-13
lines changed

6 files changed

+53
-13
lines changed

.github/workflows/multi_device.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,4 @@ jobs:
6363

6464
- name: Test adapters
6565
working-directory: ${{github.workspace}}/build
66-
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "enqueue|kernel|program|integration|exp_command_buffer|exp_enqueue_native|exp_launch_properties|exp_usm_p2p" --timeout 180
66+
run: env UR_CTS_ADAPTER_PLATFORM="${{matrix.adapter.platform}}" ctest -C ${{matrix.build_type}} --output-on-failure -L "conformance" -E "enqueue|kernel|integration|exp_command_buffer|exp_enqueue_native|exp_launch_properties|exp_usm_p2p" --timeout 180

source/adapters/level_zero/program.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,8 +905,15 @@ ur_result_t urProgramGetNativeHandle(
905905

906906
std::shared_lock<ur_shared_mutex> Guard(Program->Mutex);
907907
assert(Program->AssociatedDevices.size() > 0);
908-
auto Module =
909-
Program->getZeModuleHandle(Program->AssociatedDevices[0]->ZeDevice);
908+
// Current API doesn't allow to specify device for which we want to get the
909+
// native handle. So, find the first device with a valid module handle.
910+
ze_module_handle_t Module = nullptr;
911+
for (const auto &Device : Program->AssociatedDevices) {
912+
Module = Program->getZeModuleHandle(Device->ZeDevice);
913+
if (Module) {
914+
break;
915+
}
916+
}
910917
if (!Module)
911918
return UR_RESULT_ERROR_INVALID_OPERATION;
912919

@@ -924,7 +931,6 @@ ur_result_t urProgramCreateWithNativeHandle(
924931
ur_program_handle_t *Program ///< [out] pointer to the handle of the
925932
///< program object created.
926933
) {
927-
std::ignore = Properties;
928934
UR_ASSERT(Context && NativeProgram, UR_RESULT_ERROR_INVALID_NULL_HANDLE);
929935
UR_ASSERT(Program, UR_RESULT_ERROR_INVALID_NULL_POINTER);
930936
auto ZeModule = ur_cast<ze_module_handle_t>(NativeProgram);
@@ -934,9 +940,9 @@ ur_result_t urProgramCreateWithNativeHandle(
934940
// executable (state Object).
935941

936942
try {
937-
ur_program_handle_t_ *UrProgram =
938-
new ur_program_handle_t_(ur_program_handle_t_::Exe, Context, ZeModule,
939-
Properties->isNativeHandleOwned);
943+
ur_program_handle_t_ *UrProgram = new ur_program_handle_t_(
944+
ur_program_handle_t_::Exe, Context, ZeModule,
945+
Properties ? Properties->isNativeHandleOwned : false);
940946
*Program = reinterpret_cast<ur_program_handle_t>(UrProgram);
941947
} catch (const std::bad_alloc &) {
942948
return UR_RESULT_ERROR_OUT_OF_HOST_MEMORY;

test/conformance/program/urProgramCreateWithNativeHandle.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ struct urProgramCreateWithNativeHandleTest : uur::urProgramTest {
99
void SetUp() override {
1010
UUR_RETURN_ON_FATAL_FAILURE(urProgramTest::SetUp());
1111
{
12+
ur_platform_backend_t backend;
13+
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
14+
sizeof(backend), &backend,
15+
nullptr));
16+
// For Level Zero we have to build the program to have the native handle.
17+
if (backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
18+
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
19+
}
1220
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
1321
urProgramGetNativeHandle(program, &native_program_handle));
1422
}

test/conformance/program/urProgramGetBuildInfo.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,19 @@ TEST_P(urProgramGetBuildInfoTest, Success) {
3333
auto property_name = getParam();
3434
size_t property_size = 0;
3535
std::vector<char> property_value;
36-
ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, property_name, 0,
37-
nullptr, &property_size));
36+
ur_platform_backend_t backend;
37+
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
38+
sizeof(backend), &backend, nullptr));
39+
auto result = urProgramGetBuildInfo(program, device, property_name, 0,
40+
nullptr, &property_size);
41+
42+
if (property_name == UR_PROGRAM_BUILD_INFO_STATUS &&
43+
backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
44+
ASSERT_EQ(UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION, result);
45+
return;
46+
}
47+
48+
ASSERT_SUCCESS(result);
3849
property_value.resize(property_size);
3950
ASSERT_SUCCESS(urProgramGetBuildInfo(program, device, property_name,
4051
property_size, property_value.data(),

test/conformance/program/urProgramGetFunctionPointer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,18 @@ TEST_P(urProgramGetFunctionPointerTest, Success) {
2929
TEST_P(urProgramGetFunctionPointerTest, InvalidKernelName) {
3030
void *function_pointer = nullptr;
3131
std::string missing_function = "aFakeFunctionName";
32-
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_NAME,
33-
urProgramGetFunctionPointer(device, program,
34-
missing_function.data(),
35-
&function_pointer));
32+
auto result = urProgramGetFunctionPointer(
33+
device, program, missing_function.data(), &function_pointer);
34+
ur_platform_backend_t backend;
35+
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
36+
sizeof(backend), &backend, nullptr));
37+
// TODO: level zero backend incorrectly returns UR_RESULT_ERROR_UNSUPPORTED_FEATURE
38+
if (backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
39+
ASSERT_EQ(UR_RESULT_ERROR_UNSUPPORTED_FEATURE, result);
40+
} else {
41+
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_KERNEL_NAME, result);
42+
}
43+
3644
ASSERT_EQ(function_pointer, nullptr);
3745
}
3846

test/conformance/program/urProgramGetNativeHandle.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ using urProgramGetNativeHandleTest = uur::urProgramTest;
99
UUR_INSTANTIATE_KERNEL_TEST_SUITE_P(urProgramGetNativeHandleTest);
1010

1111
TEST_P(urProgramGetNativeHandleTest, Success) {
12+
ur_platform_backend_t backend;
13+
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
14+
sizeof(backend), &backend, nullptr));
15+
// For Level Zero we have to build the program to have the native handle.
16+
if (backend == UR_PLATFORM_BACKEND_LEVEL_ZERO) {
17+
ASSERT_SUCCESS(urProgramBuild(context, program, nullptr));
18+
}
1219
ur_native_handle_t native_program_handle = 0;
1320
if (auto error =
1421
urProgramGetNativeHandle(program, &native_program_handle)) {

0 commit comments

Comments
 (0)