Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions source/adapters/level_zero/program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ ur_result_t urProgramGetGlobalVariablePointer(
///< variable if it is found in the program.
) {
std::scoped_lock<ur_shared_mutex> lock(Program->Mutex);
if (Program->getState(Device->ZeDevice) != ur_program_handle_t_::Exe) {
return UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE;
}

ze_module_handle_t ZeModuleEntry{};
ZeModuleEntry = Program->getZeModuleHandle(Device->ZeDevice);
Expand Down
29 changes: 29 additions & 0 deletions test/conformance/program/urProgramGetGlobalVariablePointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,32 @@ TEST_P(urProgramGetGlobalVariablePointerTest,
&global_variable_size, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urProgramGetGlobalVariablePointerTest, InvalidProgramExecutable) {
ur_platform_backend_t backend;
ASSERT_SUCCESS(urPlatformGetInfo(platform, UR_PLATFORM_INFO_BACKEND,
sizeof(ur_platform_backend_t), &backend,
nullptr));
if (backend != UR_PLATFORM_BACKEND_LEVEL_ZERO) {
GTEST_SKIP();
}
// Get IL from the compiled program.
size_t il_size = 0;
ASSERT_SUCCESS(
urProgramGetInfo(program, UR_PROGRAM_INFO_IL, 0, nullptr, &il_size));
ASSERT_GT(il_size, 0);
std::vector<char> il(il_size);
ASSERT_SUCCESS(urProgramGetInfo(program, UR_PROGRAM_INFO_IL, il_size,
il.data(), nullptr));
// Create program with IL.
ur_program_handle_t program_with_il;
ASSERT_SUCCESS(urProgramCreateWithIL(context, il.data(), il.size(), nullptr,
&program_with_il));
// Expect error when trying to get global variable pointer from a program which is not in exe state.
size_t global_variable_size = 0;
void *global_variable_pointer;
ASSERT_EQ_RESULT(urProgramGetGlobalVariablePointer(
device, program_with_il, global_var.name.c_str(),
&global_variable_size, &global_variable_pointer),
UR_RESULT_ERROR_INVALID_PROGRAM_EXECUTABLE);
}
Loading