Skip to content

Commit

Permalink
Merge pull request #2370 from againull/multi_device_sanitizer
Browse files Browse the repository at this point in the history
[L0] Check that program is in exe state in urProgramGetGlobalVariablePointer
  • Loading branch information
callumfare authored Nov 22, 2024
2 parents b0f9293 + b693389 commit 2f479e0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
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
1 change: 1 addition & 0 deletions test/conformance/program/program_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidVariableName/*
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidNullPointerVariableName/*
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidNullPointerVariablePointer/*
{{OPT}}urProgramGetGlobalVariablePointerTest.InvalidProgramExecutable/*
{{OPT}}urProgramGetInfoTest.Success/*
{{OPT}}urProgramGetInfoTest.InvalidNullHandleProgram/*
{{OPT}}urProgramGetInfoTest.InvalidEnumeration/*
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);
}

0 comments on commit 2f479e0

Please sign in to comment.