Skip to content
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

[L0] Check that program is in exe state in urProgramGetGlobalVariablePointer #2370

Merged
merged 2 commits into from
Nov 22, 2024
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