Skip to content

Commit ba85a4c

Browse files
[SYCL] Add spill_memory_size unittest (#17657)
This adds a unittest for the kernel queries extension according to #17593.
1 parent 80cf11c commit ba85a4c

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

sycl/unittests/Extensions/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@ add_subdirectory(VirtualFunctions)
2929
add_subdirectory(VirtualMemory)
3030
add_subdirectory(NumComputeUnits)
3131
add_subdirectory(FreeFunctionCommands)
32+
add_subdirectory(KernelQueries)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
add_sycl_unittest(KernelQueriesTests OBJECT
2+
SpillMemorySize.cpp
3+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
//==----------------------- SpillMemorySize.cpp ----------------------------==//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include <gtest/gtest.h>
10+
#include <helpers/TestKernel.hpp>
11+
#include <helpers/UrMock.hpp>
12+
#include <sycl/kernel_bundle.hpp>
13+
#include <sycl/sycl.hpp>
14+
#include <vector>
15+
16+
using namespace sycl;
17+
18+
namespace {
19+
ur_result_t redefinedKernelGetInfo(void *pParams) {
20+
constexpr size_t DeviceNum = 1;
21+
auto params = *static_cast<ur_kernel_get_info_params_t *>(pParams);
22+
23+
if (*params.ppropName == UR_KERNEL_INFO_SPILL_MEM_SIZE) {
24+
if (*params.ppPropValue == nullptr) {
25+
size_t *ResultValuesNumber =
26+
reinterpret_cast<size_t *>(*params.ppPropSizeRet);
27+
*ResultValuesNumber = DeviceNum * sizeof(uint32_t);
28+
} else {
29+
constexpr uint32_t Device2SpillMap[] = {42};
30+
assert(*params.ppropSize == sizeof(Device2SpillMap));
31+
32+
std::memcpy(*params.ppPropValue, Device2SpillMap,
33+
sizeof(Device2SpillMap));
34+
}
35+
}
36+
return UR_RESULT_SUCCESS;
37+
}
38+
} // namespace
39+
40+
class KernelQueriesTests : public ::testing::Test {
41+
public:
42+
KernelQueriesTests()
43+
: Mock{},
44+
Queue{sycl::context(sycl::platform()), sycl::default_selector_v} {}
45+
46+
inline sycl::kernel GetTestKernel() {
47+
auto KB = sycl::get_kernel_bundle<sycl::bundle_state::executable>(
48+
Queue.get_context());
49+
return KB.get_kernel<TestKernel<>>();
50+
}
51+
52+
protected:
53+
void SetUp() override {
54+
mock::getCallbacks().set_after_callback("urKernelGetInfo",
55+
&redefinedKernelGetInfo);
56+
}
57+
58+
sycl::unittest::UrMock<backend::ext_oneapi_level_zero> Mock;
59+
sycl::queue Queue;
60+
};
61+
62+
TEST(KernelQueriesBasicTests, NoAspect) {
63+
sycl::unittest::UrMock<> Mock;
64+
sycl::queue q{sycl::context(sycl::platform()), sycl::default_selector_v};
65+
auto KB =
66+
sycl::get_kernel_bundle<sycl::bundle_state::executable>(q.get_context());
67+
auto kernel = KB.get_kernel<TestKernel<>>();
68+
const auto dev = q.get_device();
69+
try {
70+
kernel.template get_info<
71+
sycl::ext::intel::info::kernel_device_specific::spill_memory_size>(dev);
72+
FAIL() << "Exception was expected.";
73+
} catch (const sycl::exception &E) {
74+
// Intention of this test is to ensure that whenever a device does not
75+
// expose an aspect required by the query an exception is thrown.
76+
ASSERT_EQ(E.code(),
77+
sycl::make_error_code(sycl::errc::feature_not_supported));
78+
}
79+
}
80+
81+
TEST_F(KernelQueriesTests, SpillMemorySize) {
82+
sycl::kernel kernel = GetTestKernel();
83+
const auto dev = Queue.get_device();
84+
const auto spillMemSz = kernel.get_info<
85+
sycl::ext::intel::info::kernel_device_specific::spill_memory_size>(dev);
86+
87+
static_assert(std::is_same_v<std::remove_cv_t<decltype(spillMemSz)>, size_t>,
88+
"spill_memory_size query must return size_t");
89+
90+
EXPECT_EQ(spillMemSz, size_t{42});
91+
}

0 commit comments

Comments
 (0)