Skip to content

Commit 82ac451

Browse files
Merge pull request #531 from IntelPython/queue-has-enable-profiling
Queue has enable profiling
2 parents db44872 + ad31122 commit 82ac451

File tree

6 files changed

+88
-11
lines changed

6 files changed

+88
-11
lines changed

dpctl-capi/include/dpctl_sycl_queue_interface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,17 @@ void DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
333333
DPCTL_API
334334
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef);
335335

336+
/*!
337+
* @brief C-API wrapper for
338+
* sycl::queue::has_property<sycl::property::queue::enable_profiling>() that
339+
* indicates whether the referenced queue was constructed with this property.
340+
*
341+
* @param QRef An opaque pointer to the ``sycl::queue``.
342+
* @ingroup QueueInterface
343+
*/
344+
DPCTL_API
345+
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef);
346+
336347
/*!
337348
* @brief C-API wrapper for std::hash<sycl::queue>'s operator().
338349
*

dpctl-capi/source/dpctl_sycl_queue_interface.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,16 @@ bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
520520
return false;
521521
}
522522

523+
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
524+
{
525+
auto Q = unwrap(QRef);
526+
if (Q) {
527+
return Q->has_property<sycl::property::queue::enable_profiling>();
528+
}
529+
else
530+
return false;
531+
}
532+
523533
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
524534
{
525535
auto Q = unwrap(QRef);

dpctl-capi/tests/test_sycl_queue_interface.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ TEST(TestDPCTLSyclQueueInterface, CheckCopy)
115115
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
116116
}
117117

118-
TEST(TestDPCTLSyclQueueInterface, CheckCopy_Invalid)
118+
TEST(TestDPCTLSyclQueueInterface, CheckCopyInvalid)
119119
{
120120
DPCTLSyclQueueRef Q1 = nullptr;
121121
DPCTLSyclQueueRef Q2 = nullptr;
@@ -125,7 +125,7 @@ TEST(TestDPCTLSyclQueueInterface, CheckCopy_Invalid)
125125
EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(Q2));
126126
}
127127

128-
TEST(TestDPCTLSyclQueueInterface, CheckAreEq_False)
128+
TEST(TestDPCTLSyclQueueInterface, CheckAreEqFalse)
129129
{
130130
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
131131
DPCTLSyclDeviceRef DRef = nullptr;
@@ -152,7 +152,7 @@ TEST(TestDPCTLSyclQueueInterface, CheckAreEq_False)
152152
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
153153
}
154154

155-
TEST(TestDPCTLSyclQueueInterface, CheckAreEq_True)
155+
TEST(TestDPCTLSyclQueueInterface, CheckAreEqTrue)
156156
{
157157
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
158158
DPCTLSyclDeviceRef DRef = nullptr;
@@ -172,7 +172,7 @@ TEST(TestDPCTLSyclQueueInterface, CheckAreEq_True)
172172
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
173173
}
174174

175-
TEST(TestDPCTLSyclQueueInterface, CheckAreEq_Invalid)
175+
TEST(TestDPCTLSyclQueueInterface, CheckAreEqInvalid)
176176
{
177177
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
178178
DPCTLSyclDeviceRef DRef = nullptr;
@@ -192,31 +192,31 @@ TEST(TestDPCTLSyclQueueInterface, CheckAreEq_Invalid)
192192
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
193193
}
194194

195-
TEST(TestDPCTLSyclQueueInterface, CheckHash_Invalid)
195+
TEST(TestDPCTLSyclQueueInterface, CheckHashInvalid)
196196
{
197197
DPCTLSyclQueueRef Q1 = nullptr;
198198
DPCTLSyclQueueRef Q2 = nullptr;
199199
EXPECT_TRUE(DPCTLQueue_Hash(Q1) == 0);
200200
EXPECT_TRUE(DPCTLQueue_Hash(Q2) == 0);
201201
}
202202

203-
TEST(TestDPCTLSyclQueueInterface, CheckGetBackend_Invalid)
203+
TEST(TestDPCTLSyclQueueInterface, CheckGetBackendInvalid)
204204
{
205205
DPCTLSyclQueueRef Q = nullptr;
206206
DPCTLSyclBackendType Bty = DPCTL_UNKNOWN_BACKEND;
207207
EXPECT_NO_FATAL_FAILURE(Bty = DPCTLQueue_GetBackend(Q));
208208
EXPECT_TRUE(Bty == DPCTL_UNKNOWN_BACKEND);
209209
}
210210

211-
TEST(TestDPCTLSyclQueueInterface, CheckGetContext_Invalid)
211+
TEST(TestDPCTLSyclQueueInterface, CheckGetContextInvalid)
212212
{
213213
DPCTLSyclQueueRef Q = nullptr;
214214
DPCTLSyclContextRef CRef = nullptr;
215215
EXPECT_NO_FATAL_FAILURE(CRef = DPCTLQueue_GetContext(Q));
216216
EXPECT_TRUE(CRef == nullptr);
217217
}
218218

219-
TEST(TestDPCTLSyclQueueInterface, CheckGetDevice_Invalid)
219+
TEST(TestDPCTLSyclQueueInterface, CheckGetDeviceInvalid)
220220
{
221221
DPCTLSyclQueueRef Q = nullptr;
222222
DPCTLSyclDeviceRef DRef = nullptr;
@@ -250,14 +250,48 @@ TEST(TestDPCTLSyclQueueInterface, CheckIsInOrder)
250250
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
251251
}
252252

253-
TEST(TestDPCTLSyclQueueInterface, CheckIsInOrder_Invalid)
253+
TEST(TestDPCTLSyclQueueInterface, CheckIsInOrderInvalid)
254254
{
255255
bool ioq = true;
256256
DPCTLSyclQueueRef Q1 = nullptr;
257257
EXPECT_NO_FATAL_FAILURE(ioq = DPCTLQueue_IsInOrder(Q1));
258258
EXPECT_FALSE(ioq);
259259
}
260260

261+
TEST(TestDPCTLSyclQueueInterface, CheckHasEnableProfiling)
262+
{
263+
bool ioq = true;
264+
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
265+
DPCTLSyclDeviceRef DRef = nullptr;
266+
DPCTLSyclQueueRef Q1 = nullptr;
267+
DPCTLSyclQueueRef Q2 = nullptr;
268+
269+
EXPECT_NO_FATAL_FAILURE(DSRef = DPCTLDefaultSelector_Create());
270+
EXPECT_NO_FATAL_FAILURE(DRef = DPCTLDevice_CreateFromSelector(DSRef));
271+
EXPECT_NO_FATAL_FAILURE(
272+
Q1 = DPCTLQueue_CreateForDevice(DRef, nullptr, DPCTL_DEFAULT_PROPERTY));
273+
EXPECT_NO_FATAL_FAILURE(ioq = DPCTLQueue_HasEnableProfiling(Q1));
274+
EXPECT_FALSE(ioq);
275+
276+
EXPECT_NO_FATAL_FAILURE(
277+
Q2 = DPCTLQueue_CreateForDevice(DRef, nullptr, DPCTL_ENABLE_PROFILING));
278+
EXPECT_NO_FATAL_FAILURE(ioq = DPCTLQueue_HasEnableProfiling(Q2));
279+
EXPECT_TRUE(ioq);
280+
281+
EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(Q1));
282+
EXPECT_NO_FATAL_FAILURE(DPCTLQueue_Delete(Q2));
283+
EXPECT_NO_FATAL_FAILURE(DPCTLDevice_Delete(DRef));
284+
EXPECT_NO_FATAL_FAILURE(DPCTLDeviceSelector_Delete(DSRef));
285+
}
286+
287+
TEST(TestDPCTLSyclQueueInterface, CheckHasEnableProfilingInvalid)
288+
{
289+
bool ioq = true;
290+
DPCTLSyclQueueRef Q1 = nullptr;
291+
EXPECT_NO_FATAL_FAILURE(ioq = DPCTLQueue_HasEnableProfiling(Q1));
292+
EXPECT_FALSE(ioq);
293+
}
294+
261295
TEST_P(TestDPCTLQueueMemberFunctions, CheckGetBackend)
262296
{
263297
auto q = unwrap(QRef);

dpctl/_backend.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ cdef extern from "dpctl_sycl_queue_interface.h":
353353
const DPCTLSyclQueueRef QRef,
354354
const DPCTLSyclEventRef *DepEvents,
355355
size_t NDepEvents)
356+
cdef bool DPCTLQueue_HasEnableProfiling(const DPCTLSyclQueueRef QRef)
356357

357358

358359
cdef extern from "dpctl_sycl_queue_manager.h":

dpctl/_sycl_queue.pyx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ from ._backend cimport ( # noqa: E211
3838
DPCTLQueue_GetBackend,
3939
DPCTLQueue_GetContext,
4040
DPCTLQueue_GetDevice,
41+
DPCTLQueue_HasEnableProfiling,
4142
DPCTLQueue_Hash,
4243
DPCTLQueue_IsInOrder,
4344
DPCTLQueue_MemAdvise,
@@ -851,17 +852,29 @@ cdef class SyclQueue(_SyclQueue):
851852
"""True if SyclQueue is in-order, False if it is out-of-order."""
852853
return DPCTLQueue_IsInOrder(self._queue_ref)
853854

855+
@property
856+
def has_enable_profiling(self):
857+
"""True if SyclQueue was constructed with enabled_profiling property,
858+
False otherwise."""
859+
return DPCTLQueue_HasEnableProfiling(self._queue_ref)
860+
854861
@property
855862
def __name__(self):
856863
return "SyclQueue"
857864

858865
def __repr__(self):
859866
cdef cpp_bool in_order = DPCTLQueue_IsInOrder(self._queue_ref)
860-
if in_order:
867+
cdef cpp_bool en_prof = DPCTLQueue_HasEnableProfiling(self._queue_ref)
868+
if in_order or en_prof:
869+
prop = []
870+
if in_order:
871+
prop.append("in_order")
872+
if en_prof:
873+
prop.append("enable_profiling")
861874
return (
862875
"<dpctl."
863876
+ self.__name__
864-
+ " at {}, property=in_order>".format(hex(id(self)))
877+
+ " at {}, property={}>".format(hex(id(self)), prop)
865878
)
866879
else:
867880
return "<dpctl." + self.__name__ + " at {}>".format(hex(id(self)))

dpctl/tests/test_sycl_queue.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ def test_context_equals():
373373
assert hash(ctx0) == hash(ctx1)
374374

375375

376+
def test_has_enable_profiling():
377+
try:
378+
q = dpctl.SyclQueue(property="enable_profiling")
379+
except dpctl.SyclQueueCreationError:
380+
pytest.skip()
381+
assert q.has_enable_profiling
382+
383+
376384
def test_hashing_of_queue():
377385
"""
378386
Test that a :class:`dpctl.SyclQueue` object can be used as

0 commit comments

Comments
 (0)