Skip to content

Commit bfdfc3a

Browse files
authored
[SYCL] Increase test coverage for root group extension (#18745)
Certain branches in functions related to the root group extension's work item query were not covered by any tests. This change removes a subset of them (conditionally, using the `__INTEL_PREVIEW_BREAKING_CHANGES` macro, to maintain the ABI) and adds tests for the others. --------- Signed-off-by: Michael Aziz <[email protected]>
1 parent 19964c3 commit bfdfc3a

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed

sycl/source/detail/kernel_impl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,17 @@ class kernel_impl {
115115
typename Param::return_type get_info(const device &Device,
116116
const range<3> &WGSize) const;
117117

118+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
119+
// This function is unused and should be removed in the next ABI breaking.
120+
118121
/// Query queue/launch-specific information from a kernel using the
119122
/// info::kernel_queue_specific descriptor for a specific Queue.
120123
///
121124
/// \param Queue is a valid SYCL queue.
122125
/// \return depends on information being queried.
123126
template <typename Param>
124127
typename Param::return_type ext_oneapi_get_info(queue Queue) const;
128+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
125129

126130
/// Query queue/launch-specific information from a kernel using the
127131
/// info::kernel_queue_specific descriptor for a specific Queue and values.
@@ -440,6 +444,9 @@ inline typename ext::intel::info::kernel_device_specific::spill_memory_size::
440444
getAdapter());
441445
}
442446

447+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
448+
// These functions are unused and should be removed in the next ABI breaking.
449+
443450
template <>
444451
inline typename syclex::info::kernel_queue_specific::max_work_group_size::
445452
return_type
@@ -491,6 +498,8 @@ ADD_TEMPLATE_METHOD_SPEC(3)
491498

492499
#undef ADD_TEMPLATE_METHOD_SPEC
493500

501+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
502+
494503
#define ADD_TEMPLATE_METHOD_SPEC(QueueSpec, Num, Kind, Reg) \
495504
template <> \
496505
inline typename syclex::info::kernel_queue_specific::QueueSpec::return_type \

sycl/source/detail/scheduler/commands.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ bool Command::isHostTask() const {
303303
CGType::CodeplayHostTask);
304304
}
305305

306+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
307+
// This function is unused and should be removed in the next ABI-breaking
308+
// window.
306309
bool Command::isFusable() const {
307310
if ((MType != CommandType::RUN_CG)) {
308311
return false;
@@ -312,6 +315,7 @@ bool Command::isFusable() const {
312315
(!static_cast<const CGExecKernel &>(CG).MKernelIsCooperative) &&
313316
(!static_cast<const CGExecKernel &>(CG).MKernelUsesClusterLaunch);
314317
}
318+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
315319

316320
static void flushCrossQueueDeps(const std::vector<EventImplPtr> &EventImpls,
317321
const QueueImplPtr &Queue) {

sycl/source/detail/scheduler/commands.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,11 @@ class Command {
251251

252252
bool isHostTask() const;
253253

254+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
255+
// This function is unused and should be removed in the next ABI-breaking
256+
// window.
254257
bool isFusable() const;
258+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
255259

256260
protected:
257261
QueueImplPtr MQueue;

sycl/source/kernel.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,15 @@ template __SYCL_EXPORT uint32_t
114114
kernel::get_info<info::kernel_device_specific::max_sub_group_size>(
115115
const device &, const sycl::range<3> &) const;
116116

117+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
118+
// This function is unused and should be removed in the next ABI-breaking
119+
// window.
117120
template <typename Param>
118121
typename detail::is_kernel_queue_specific_info_desc<Param>::return_type
119122
kernel::ext_oneapi_get_info(queue Queue) const {
120123
return impl->ext_oneapi_get_info<Param>(std::move(Queue));
121124
}
125+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
122126

123127
template <typename Param>
124128
typename detail::is_kernel_queue_specific_info_desc<Param>::return_type
@@ -162,6 +166,10 @@ kernel::ext_oneapi_get_info(queue Queue, const range<3> &WorkGroupSize,
162166
DynamicLocalMemorySize);
163167
}
164168

169+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
170+
// These functions are unused and should be removed in the next ABI-breaking
171+
// window.
172+
165173
template __SYCL_EXPORT typename ext::oneapi::experimental::info::
166174
kernel_queue_specific::max_work_group_size::return_type
167175
kernel::ext_oneapi_get_info<ext::oneapi::experimental::info::
@@ -186,6 +194,8 @@ template __SYCL_EXPORT typename ext::oneapi::experimental::info::
186194
ext::oneapi::experimental::info::kernel_queue_specific::
187195
max_work_item_sizes<3>>(queue Queue) const;
188196

197+
#endif // __INTEL_PREVIEW_BREAKING_CHANGES
198+
189199
template __SYCL_EXPORT typename ext::oneapi::experimental::info::
190200
kernel_queue_specific::max_sub_group_size::return_type
191201
kernel::ext_oneapi_get_info<ext::oneapi::experimental::info::

sycl/unittests/Extensions/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_sycl_unittest(ExtensionsTests OBJECT
2121
LaunchQueries.cpp
2222
EventMode.cpp
2323
DeviceInfo.cpp
24+
RootGroup.cpp
2425
)
2526

2627
add_subdirectory(CommandGraph)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//==-------------- RootGroup.cpp - root group extension test ---------------==//
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 <sycl/ext/oneapi/experimental/root_group.hpp>
11+
12+
// Include helpers for device image, kernel info, and Unified Runtime (UR) mocks
13+
#include "helpers/MockDeviceImage.hpp"
14+
#include "helpers/MockKernelInfo.hpp"
15+
#include "helpers/UrMock.hpp"
16+
17+
// Define a mock kernel class with several operator() overloads for different
18+
// SYCL item types
19+
class QueryKernel {
20+
public:
21+
void operator()() const {}
22+
void operator()(sycl::item<1>) const {}
23+
void operator()(sycl::nd_item<1> Item) const {}
24+
};
25+
26+
// Specialize KernelInfo for QueryKernel to provide mock metadata for the kernel
27+
namespace sycl {
28+
inline namespace _V1 {
29+
namespace detail {
30+
template <>
31+
struct KernelInfo<QueryKernel> : public unittest::MockKernelInfoBase {
32+
static constexpr const char *getName() { return "QueryKernel"; }
33+
static constexpr int64_t getKernelSize() { return sizeof(QueryKernel); }
34+
static constexpr const char *getFileName() { return "QueryKernel.hpp"; }
35+
static constexpr const char *getFunctionName() {
36+
return "QueryKernelFunctionName";
37+
}
38+
static constexpr unsigned getLineNumber() { return 1; }
39+
static constexpr unsigned getColumnNumber() { return 1; }
40+
};
41+
} // namespace detail
42+
} // namespace _V1
43+
} // namespace sycl
44+
45+
// Test that querying max_num_work_groups with an invalid (zero) work-group size
46+
// throws the correct exception
47+
TEST(RootGroupTests, InvalidWorkGroupSize) {
48+
namespace syclex = sycl::ext::oneapi::experimental;
49+
50+
// Create a mock device image containing the QueryKernel
51+
sycl::unittest::MockDeviceImage Img =
52+
sycl::unittest::generateDefaultImage({"QueryKernel"});
53+
const sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img};
54+
const sycl::unittest::UrMock<> Mock;
55+
56+
const sycl::queue q;
57+
// Get the kernel bundle and kernel object for QueryKernel
58+
const auto bundle =
59+
sycl::get_kernel_bundle<sycl::bundle_state::executable>(q.get_context());
60+
const auto kernel = bundle.get_kernel<QueryKernel>();
61+
try {
62+
// Attempt to query max_num_work_groups with a zero work-group size
63+
kernel.ext_oneapi_get_info<
64+
syclex::info::kernel_queue_specific::max_num_work_groups>(q, {0}, 0);
65+
FAIL() << "The ext_oneapi_get_info query should have thrown.";
66+
} catch (const sycl::exception &e) {
67+
// Check that the correct error code and message are returned
68+
EXPECT_EQ(e.code(), sycl::make_error_code(sycl::errc::invalid));
69+
EXPECT_STREQ(e.what(), "The launch work-group size cannot be zero.");
70+
}
71+
}
72+
73+
// Test that querying max_num_work_groups with a valid work-group size returns
74+
// the expected value
75+
TEST(RootGroupTests, ValidNumWorkGroupsQuery) {
76+
namespace syclex = sycl::ext::oneapi::experimental;
77+
78+
// Create a mock device image containing the QueryKernel
79+
sycl::unittest::MockDeviceImage Img =
80+
sycl::unittest::generateDefaultImage({"QueryKernel"});
81+
const sycl::unittest::MockDeviceImageArray<1> ImgArray{&Img};
82+
const sycl::unittest::UrMock<> Mock;
83+
84+
// Set up a mock callback to return a specific group count when queried
85+
constexpr std::size_t mock_group_count = 42;
86+
mock::getCallbacks().set_replace_callback(
87+
"urKernelSuggestMaxCooperativeGroupCountExp", [](void *pParams) {
88+
auto params = static_cast<
89+
ur_kernel_suggest_max_cooperative_group_count_exp_params_t *>(
90+
pParams);
91+
**params->ppGroupCountRet = mock_group_count;
92+
return UR_RESULT_SUCCESS;
93+
});
94+
95+
const sycl::queue q;
96+
// Get the kernel bundle and kernel object for QueryKernel
97+
const auto bundle =
98+
sycl::get_kernel_bundle<sycl::bundle_state::executable>(q.get_context());
99+
const auto kernel = bundle.get_kernel<QueryKernel>();
100+
// Query max_num_work_groups with a valid work-group size (1)
101+
const auto maxWGs = kernel.ext_oneapi_get_info<
102+
syclex::info::kernel_queue_specific::max_num_work_groups>(q, {1}, 0);
103+
// Check that the returned value matches the mock group count
104+
EXPECT_EQ(maxWGs, mock_group_count);
105+
}

0 commit comments

Comments
 (0)