Skip to content

Commit 43b32ff

Browse files
authored
Merge pull request #2370 from againull/multi_device_sanitizer
[L0] Check that program is in exe state in urProgramGetGlobalVariablePointer
2 parents dba0de0 + f83b3a2 commit 43b32ff

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

source/adapters/level_zero/program.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ ur_result_t urProgramGetGlobalVariablePointer(
618618
///< variable if it is found in the program.
619619
) {
620620
std::scoped_lock<ur_shared_mutex> lock(Program->Mutex);
621+
if (Program->getState(Device->ZeDevice) != ur_program_handle_t_::Exe) {
622+
return UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE;
623+
}
621624

622625
ze_module_handle_t ZeModuleEntry{};
623626
ZeModuleEntry = Program->getZeModuleHandle(Device->ZeDevice);

test/conformance/program/program_adapter_native_cpu.match

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidVariableName/*
4242
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidNullPointerVariableName/*
4343
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidNullPointerVariablePointer/*
44+
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidProgramExecutable/*
4445
{{OPT}}urProgramGetInfoTest.Success/*
4546
{{OPT}}urProgramGetInfoTest.InvalidNullHandleProgram/*
4647
{{OPT}}urProgramGetInfoTest.InvalidEnumeration/*

test/conformance/program/urProgramGetGlobalVariablePointer.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,32 @@ TEST_P(urProgramGetGlobalVariablePointerTest,
5959
&global_variable_size, nullptr),
6060
UR_RESULT_ERROR_INVALID_NULL_POINTER);
6161
}
62+
63+
TEST_P(urProgramGetGlobalVariablePointerTest, InvalidProgramExecutable) {
64+
ur_platform_backend_t backend;
65+
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
66+
sizeof(ur_platform_backend_t), &backend,
67+
nullptr));
68+
if (backend != UR_PLATFORM_BACKEND_LEVEL_ZERO) {
69+
GTEST_SKIP();
70+
}
71+
// Get IL from the compiled program.
72+
size_t il_size = 0;
73+
ASSERT_SUCCESS(
74+
urProgramGetInfo(program, UR_PROGRAM_INFO_IL, 0, nullptr, &il_size));
75+
ASSERT_GT(il_size, 0);
76+
std::vector<char> il(il_size);
77+
ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_IL, il_size,
78+
il.data(), nullptr));
79+
// Create program with IL.
80+
ur_program_handle_t program_with_il;
81+
ASSERT_SUCCESS(urProgramCreateWithIL(context, il.data(), il.size(), nullptr,
82+
&program_with_il));
83+
// Expect error when trying to get global variable pointer from a program which is not in exe state.
84+
size_t global_variable_size = 0;
85+
void *global_variable_pointer;
86+
ASSERT_EQ_RESULT(urProgramGetGlobalVariablePointer(
87+
device, program_with_il, global_var.name.c_str(),
88+
&global_variable_size, &global_variable_pointer),
89+
UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE);
90+
}

0 commit comments

Comments
 (0)