Skip to content

[UR][Offload] Implement (most) kernel info queries #19806

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

Open
wants to merge 1 commit into
base: sycl
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions unified-runtime/source/adapters/offload/kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ urKernelCreate(ur_program_handle_t hProgram, const char *pKernelName,
return offloadResultToUR(Res);
}

Kernel->Name = pKernelName;
Kernel->Program = hProgram;

*phKernel = Kernel;

return UR_RESULT_SUCCESS;
Expand All @@ -44,6 +47,17 @@ UR_APIEXPORT ur_result_t UR_APICALL urKernelGetInfo(ur_kernel_handle_t hKernel,
switch (propName) {
case UR_KERNEL_INFO_REFERENCE_COUNT:
return ReturnValue(hKernel->RefCount.load());
case UR_KERNEL_INFO_FUNCTION_NAME:
return ReturnValue(hKernel->Name.c_str());
case UR_KERNEL_INFO_PROGRAM:
return ReturnValue(hKernel->Program);
case UR_KERNEL_INFO_CONTEXT:
return ReturnValue(hKernel->Program->URContext);
case UR_KERNEL_INFO_ATTRIBUTES:
return ReturnValue("");
case UR_KERNEL_INFO_NUM_ARGS:
// This is unimplementable on liboffload (and AMD/Nvidia in general)
[[fallthrough]];
default:
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
Expand Down
2 changes: 2 additions & 0 deletions unified-runtime/source/adapters/offload/kernel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,7 @@ struct ur_kernel_handle_t_ : RefCounted {
};

ol_symbol_handle_t OffloadKernel;
ur_program_handle_t Program;
OffloadKernelArguments Args{};
std::string Name;
};
27 changes: 15 additions & 12 deletions unified-runtime/test/conformance/kernel/urKernelGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ TEST_P(urKernelGetInfoTest, SuccessFunctionName) {
}

TEST_P(urKernelGetInfoTest, SuccessNumArgs) {
// Not implementable on liboffload
UUR_KNOWN_FAILURE_ON(uur::Offload{});

const ur_kernel_info_t property_name = UR_KERNEL_INFO_NUM_ARGS;
size_t property_size = 0;

Expand Down Expand Up @@ -245,40 +248,40 @@ TEST_P(urKernelGetInfoTest, InvalidEnumeration) {

TEST_P(urKernelGetInfoTest, InvalidSizeZero) {
size_t property_size = 0;
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
&property_size));
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME, 0,
nullptr, &property_size));

std::vector<char> property_value(property_size);
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0,
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME, 0,
property_value.data(), nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urKernelGetInfoTest, InvalidSizeSmall) {
size_t property_size = 0;
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
&property_size));
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME, 0,
nullptr, &property_size));

std::vector<char> property_value(property_size);
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME,
property_value.size() - 1,
property_value.data(), nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urKernelGetInfoTest, InvalidNullPointerPropValue) {
size_t property_size = 0;
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr,
&property_size));
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS,
ASSERT_SUCCESS(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME, 0,
nullptr, &property_size));
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME,
property_size, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urKernelGetInfoTest, InvalidNullPointerPropSizeRet) {
ASSERT_EQ_RESULT(
urKernelGetInfo(kernel, UR_KERNEL_INFO_NUM_ARGS, 0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
ASSERT_EQ_RESULT(urKernelGetInfo(kernel, UR_KERNEL_INFO_FUNCTION_NAME, 0,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urKernelGetInfoTest, KernelNameCorrect) {
Expand Down
Loading