Skip to content

[SYCL] Add a built-in kernel test #5046

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

Merged
merged 2 commits into from
Dec 1, 2021
Merged
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
41 changes: 41 additions & 0 deletions sycl/unittests/kernel-and-program/DeviceInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ struct TestCtx {

context &Ctx;
bool UUIDInfoCalled = false;

std::string BuiltInKernels;
};
} // namespace

Expand All @@ -31,6 +33,13 @@ static pi_result redefinedDeviceGetInfo(pi_device device,
size_t *param_value_size_ret) {
if (param_name == PI_DEVICE_INFO_UUID) {
TestContext->UUIDInfoCalled = true;
} else if (param_name == PI_DEVICE_INFO_BUILT_IN_KERNELS) {
if (param_value_size_ret) {
*param_value_size_ret = TestContext->BuiltInKernels.size() + 1;
} else if (param_value) {
char *dst = static_cast<char *>(param_value);
dst[TestContext->BuiltInKernels.copy(dst, param_value_size)] = '\0';
}
}

return PI_SUCCESS;
Expand Down Expand Up @@ -85,3 +94,35 @@ TEST_F(DeviceInfoTest, GetDeviceUUID) {
<< "Expect device UUID to be "
<< "of 16 bytes";
}

TEST_F(DeviceInfoTest, BuiltInKernelIDs) {
if (Plt.is_host()) {
return;
}

context Ctx{Plt.get_devices()[0]};
TestContext.reset(new TestCtx(Ctx));
TestContext->BuiltInKernels = "Kernel0;Kernel1;Kernel2";

device Dev = Ctx.get_devices()[0];

auto ids = Dev.get_info<info::device::built_in_kernel_ids>();

ASSERT_EQ(ids.size(), 3u);
EXPECT_STREQ(ids[0].get_name(), "Kernel0");
EXPECT_STREQ(ids[1].get_name(), "Kernel1");
EXPECT_STREQ(ids[2].get_name(), "Kernel2");

errc val = errc::success;
std::string msg;
try {
get_kernel_bundle<bundle_state::executable>(Ctx, {Dev}, ids);
} catch (sycl::exception &e) {
val = errc(e.code().value());
msg = e.what();
}

EXPECT_EQ(val, errc::kernel_argument);
EXPECT_EQ(
msg, "Attempting to use a built-in kernel. They are not fully supported");
}