Skip to content

Commit cecde73

Browse files
Addressed concern regarding #494
Added logic to verify that all bits of property integer were recognized and used. Added test to verify handling of property bits.
1 parent 9197366 commit cecde73

File tree

3 files changed

+50
-5
lines changed

3 files changed

+50
-5
lines changed

dpctl-capi/include/dpctl_sycl_enum_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ typedef enum
146146
{
147147
// clang-format off
148148
DPCTL_DEFAULT_PROPERTY = 0,
149-
DPCTL_ENABLE_PROFILING = 1 << 1,
150-
DPCTL_IN_ORDER = 1 << 2
149+
DPCTL_ENABLE_PROFILING = 1 << 0,
150+
DPCTL_IN_ORDER = 1 << 1
151151
// clang-format on
152152
} DPCTLQueuePropertyType;
153153

dpctl-capi/source/dpctl_sycl_queue_interface.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ bool set_kernel_arg(handler &cgh,
119119
std::unique_ptr<property_list> create_property_list(int properties)
120120
{
121121
std::unique_ptr<property_list> propList;
122-
if (properties & DPCTL_ENABLE_PROFILING) {
123-
if (properties & DPCTL_IN_ORDER) {
122+
int _prop = properties;
123+
if (_prop & DPCTL_ENABLE_PROFILING) {
124+
_prop = _prop ^ DPCTL_ENABLE_PROFILING;
125+
if (_prop & DPCTL_IN_ORDER) {
126+
_prop = _prop ^ DPCTL_IN_ORDER;
124127
propList = std::make_unique<property_list>(
125128
sycl::property::queue::enable_profiling(),
126129
sycl::property::queue::in_order());
@@ -130,11 +133,18 @@ std::unique_ptr<property_list> create_property_list(int properties)
130133
sycl::property::queue::enable_profiling());
131134
}
132135
}
133-
else if (properties & DPCTL_IN_ORDER) {
136+
else if (_prop & DPCTL_IN_ORDER) {
137+
_prop = _prop ^ DPCTL_IN_ORDER;
134138
propList =
135139
std::make_unique<property_list>(sycl::property::queue::in_order());
136140
}
137141

142+
if (_prop) {
143+
// todo: log error
144+
std::cerr << "Invalid queue property argument (" << std::hex
145+
<< properties << "), interpreted as (" << (properties ^ _prop)
146+
<< ")" << '\n';
147+
}
138148
return propList;
139149
}
140150

dpctl-capi/tests/test_sycl_queue_interface.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,41 @@ TEST(TestDPCTLSyclQueueInterface, CheckHasEnableProfilingInvalid)
292292
EXPECT_FALSE(ioq);
293293
}
294294

295+
TEST(TestDPCTLSyclQueueInterface, CheckPropertyHandling)
296+
{
297+
DPCTLSyclQueueRef QRef = nullptr;
298+
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
299+
DPCTLSyclDeviceRef DRef = nullptr;
300+
301+
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLDefaultSelector_Create());
302+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
303+
304+
::testing::internal::CaptureStderr();
305+
EXPECT_NO_FATAL_FAILURE(QRef = DPCTLQueue_CreateForDevice(
306+
DRef, nullptr, DPCTL_DEFAULT_PROPERTY));
307+
std::string capt1 = ::testing::internal::GetCapturedStderr();
308+
ASSERT_TRUE(capt1.empty());
309+
ASSERT_FALSE(DPCTLQueue_IsInOrder(QRef));
310+
ASSERT_FALSE(DPCTLQueue_HasEnableProfiling(QRef));
311+
EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(QRef));
312+
313+
QRef = nullptr;
314+
::testing::internal::CaptureStderr();
315+
int invalid_prop = -1;
316+
EXPECT_NO_FATAL_FAILURE(
317+
QRef = DPCTLQueue_CreateForDevice(DRef, nullptr, invalid_prop));
318+
std::string capt2 = ::testing::internal::GetCapturedStderr();
319+
ASSERT_TRUE(!capt2.empty());
320+
ASSERT_TRUE(DPCTLQueue_IsInOrder(QRef) ==
321+
bool((invalid_prop & DPCTL_IN_ORDER)));
322+
ASSERT_TRUE(DPCTLQueue_HasEnableProfiling(QRef) ==
323+
bool((invalid_prop & DPCTL_ENABLE_PROFILING)));
324+
EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(QRef));
325+
326+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
327+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
328+
}
329+
295330
TEST_P(TestDPCTLQueueMemberFunctions, CheckGetBackend)
296331
{
297332
auto q = unwrap(QRef);

0 commit comments

Comments
 (0)