Skip to content

Commit 2d5031b

Browse files
committed
[SYCL] Add support for sycl::ext::oneapi::property::queue::use_priority
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent 7e0f76b commit 2d5031b

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed

sycl/include/sycl/detail/pi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
// 11.16 Add PI_EXT_INTEL_DEVICE_INFO_MEMORY_CLOCK_RATE and
5757
// PI_EXT_INTEL_DEVICE_INFO_MEMORY_BUS_WIDTH as an extension for
5858
// piDeviceGetInfo.
59+
// 11.17 Added new PI_EXT_ONEAPI_QUEUE_PRIORITY_LOW and
60+
// PI_EXT_ONEAPI_QUEUE_PRIORITY_HIGH queue properties.
5961

6062
#define _PI_H_VERSION_MAJOR 11
6163
#define _PI_H_VERSION_MINOR 16
@@ -580,6 +582,8 @@ constexpr pi_queue_properties PI_QUEUE_PROFILING_ENABLE = (1 << 1);
580582
constexpr pi_queue_properties PI_QUEUE_ON_DEVICE = (1 << 2);
581583
constexpr pi_queue_properties PI_QUEUE_ON_DEVICE_DEFAULT = (1 << 3);
582584
constexpr pi_queue_properties PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS = (1 << 4);
585+
constexpr pi_queue_properties PI_EXT_ONEAPI_QUEUE_PRIORITY_LOW = (1 << 5);
586+
constexpr pi_queue_properties PI_EXT_ONEAPI_QUEUE_PRIORITY_HIGH = (1 << 6);
583587

584588
using pi_result = _pi_result;
585589
using pi_platform_info = _pi_platform_info;

sycl/include/sycl/detail/properties_traits.def

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ __SYCL_PARAM_TRAITS_SPEC(sycl::property::buffer::context_bound)
44
__SYCL_PARAM_TRAITS_SPEC(sycl::property::image::use_host_ptr)
55
__SYCL_PARAM_TRAITS_SPEC(sycl::property::image::use_mutex)
66
__SYCL_PARAM_TRAITS_SPEC(sycl::property::image::context_bound)
7-
__SYCL_PARAM_TRAITS_SPEC(sycl::ext::oneapi::property::buffer::use_pinned_host_memory)
7+
__SYCL_PARAM_TRAITS_SPEC(
8+
sycl::ext::oneapi::property::buffer::use_pinned_host_memory)
89
__SYCL_PARAM_TRAITS_SPEC(sycl::property::noinit)
910
__SYCL_PARAM_TRAITS_SPEC(sycl::property::no_init)
10-
__SYCL_PARAM_TRAITS_SPEC(sycl::property::context::cuda::use_primary_context) // Deprecated
11-
__SYCL_PARAM_TRAITS_SPEC(sycl::ext::oneapi::cuda::property::context::use_primary_context)
11+
__SYCL_PARAM_TRAITS_SPEC(
12+
sycl::property::context::cuda::use_primary_context) // Deprecated
13+
__SYCL_PARAM_TRAITS_SPEC(
14+
sycl::ext::oneapi::cuda::property::context::use_primary_context)
1215
__SYCL_PARAM_TRAITS_SPEC(sycl::property::queue::in_order)
1316
__SYCL_PARAM_TRAITS_SPEC(sycl::property::reduction::initialize_to_identity)
17+
__SYCL_PARAM_TRAITS_SPEC(sycl::ext::oneapi::property::queue::use_priority)

sycl/include/sycl/detail/property_helper.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ enum PropWithDataKind {
4949
ImageContextBound = 3,
5050
BufferMemChannel = 4,
5151
AccPropBufferLocation = 5,
52-
PropWithDataKindSize = 6,
52+
QueuePriority = 6,
53+
PropWithDataKindSize = 7,
5354
};
5455

5556
// Base class for dataless properties, needed to check that the type of an

sycl/include/sycl/properties/queue_properties.hpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,21 @@ namespace property {
2828
namespace queue {
2929
class discard_events
3030
: public ::sycl::detail::DataLessProperty<::sycl::detail::DiscardEvents> {};
31+
32+
class use_priority : public sycl::detail::PropertyWithData<
33+
sycl::detail::PropWithDataKind::QueuePriority> {
34+
public:
35+
using priority_type = enum {
36+
normal = 0, // default
37+
low = 1,
38+
high = 2
39+
};
40+
use_priority(priority_type Priority) : MPriority(Priority) {}
41+
priority_type get_priority() const { return MPriority; }
42+
43+
private:
44+
priority_type MPriority;
45+
};
3146
} // namespace queue
3247
} // namespace property
3348

@@ -67,6 +82,9 @@ template <>
6782
struct is_property_of<ext::oneapi::property::queue::discard_events, queue>
6883
: std::true_type {};
6984
template <>
85+
struct is_property_of<ext::oneapi::property::queue::use_priority, queue>
86+
: std::true_type {};
87+
template <>
7088
struct is_property_of<property::queue::cuda::use_default_stream, queue>
7189
: std::true_type {};
7290
template <>

sycl/plugins/level_zero/pi_level_zero.cpp

100755100644
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,14 @@ bool _pi_queue::isDiscardEvents() const {
10021002
return ((this->Properties & PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS) != 0);
10031003
}
10041004

1005+
bool _pi_queue::isPriorityLow() const {
1006+
return ((this->Properties & PI_EXT_ONEAPI_QUEUE_PRIORITY_LOW) != 0);
1007+
}
1008+
1009+
bool _pi_queue::isPriorityHigh() const {
1010+
return ((this->Properties & PI_EXT_ONEAPI_QUEUE_PRIORITY_HIGH) != 0);
1011+
}
1012+
10051013
pi_result
10061014
_pi_queue::resetCommandList(pi_command_list_ptr_t CommandList,
10071015
bool MakeAvailable,
@@ -1829,6 +1837,11 @@ _pi_queue::pi_queue_group_t::getZeQueue(uint32_t *QueueGroupOrdinal) {
18291837
ZeCommandQueueDesc.ordinal = *QueueGroupOrdinal;
18301838
ZeCommandQueueDesc.index = QueueIndex;
18311839
ZeCommandQueueDesc.mode = ZE_COMMAND_QUEUE_MODE_ASYNCHRONOUS;
1840+
if (Queue->isPriorityLow()) {
1841+
ZeCommandQueueDesc.priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_LOW;
1842+
} else if (Queue->isPriorityHigh()) {
1843+
ZeCommandQueueDesc.priority = ZE_COMMAND_QUEUE_PRIORITY_PRIORITY_HIGH;
1844+
}
18321845

18331846
// Evaluate performance of explicit usage for "0" index.
18341847
if (QueueIndex != 0) {
@@ -3523,7 +3536,9 @@ pi_result piQueueCreate(pi_context Context, pi_device Device,
35233536
PI_ASSERT(!(Properties & ~(PI_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE |
35243537
PI_QUEUE_PROFILING_ENABLE | PI_QUEUE_ON_DEVICE |
35253538
PI_QUEUE_ON_DEVICE_DEFAULT |
3526-
PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS)),
3539+
PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS |
3540+
PI_EXT_ONEAPI_QUEUE_PRIORITY_LOW |
3541+
PI_EXT_ONEAPI_QUEUE_PRIORITY_HIGH)),
35273542
PI_ERROR_INVALID_VALUE);
35283543

35293544
PI_ASSERT(Context, PI_ERROR_INVALID_CONTEXT);

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,9 @@ using pi_command_list_ptr_t = pi_command_list_map_t::iterator;
432432
struct _pi_context : _pi_object {
433433
_pi_context(ze_context_handle_t ZeContext, pi_uint32 NumDevices,
434434
const pi_device *Devs, bool OwnZeContext)
435-
: ZeContext{ZeContext},
436-
OwnZeContext{OwnZeContext}, Devices{Devs, Devs + NumDevices},
437-
SingleRootDevice(getRootDevice()), ZeCommandListInit{nullptr} {
435+
: ZeContext{ZeContext}, OwnZeContext{OwnZeContext},
436+
Devices{Devs, Devs + NumDevices}, SingleRootDevice(getRootDevice()),
437+
ZeCommandListInit{nullptr} {
438438
// NOTE: one must additionally call initialize() to complete
439439
// PI context creation.
440440
}
@@ -788,6 +788,10 @@ struct _pi_queue : _pi_object {
788788
// Returns true if the queue has discard events property.
789789
bool isDiscardEvents() const;
790790

791+
// Returns true if the queue has explicit priority set by user.
792+
bool isPriorityLow() const;
793+
bool isPriorityHigh() const;
794+
791795
// adjust the queue's batch size, knowing that the current command list
792796
// is being closed with a full batch.
793797
// For copy commands, IsCopy is set to 'true'.
@@ -1366,9 +1370,9 @@ struct _pi_program : _pi_object {
13661370

13671371
// Construct a program in IL or Native state.
13681372
_pi_program(state St, pi_context Context, const void *Input, size_t Length)
1369-
: Context{Context},
1370-
OwnZeModule{true}, State{St}, Code{new uint8_t[Length]},
1371-
CodeLength{Length}, ZeModule{nullptr}, ZeBuildLog{nullptr} {
1373+
: Context{Context}, OwnZeModule{true}, State{St},
1374+
Code{new uint8_t[Length]}, CodeLength{Length}, ZeModule{nullptr},
1375+
ZeBuildLog{nullptr} {
13721376
std::memcpy(Code.get(), Input, Length);
13731377
}
13741378

sycl/source/detail/queue_impl.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,15 @@ class queue_impl {
312312
// queue property.
313313
CreationFlags |= PI_EXT_ONEAPI_QUEUE_DISCARD_EVENTS;
314314
}
315+
if (MPropList.has_property<ext::oneapi::property::queue::use_priority>()) {
316+
auto Priority =
317+
MPropList.get_property<ext::oneapi::property::queue::use_priority>()
318+
.get_priority();
319+
if (Priority == ext::oneapi::property::queue::use_priority::high)
320+
CreationFlags |= PI_EXT_ONEAPI_QUEUE_PRIORITY_HIGH;
321+
else if (Priority == ext::oneapi::property::queue::use_priority::low)
322+
CreationFlags |= PI_EXT_ONEAPI_QUEUE_PRIORITY_LOW;
323+
}
315324
RT::PiQueue Queue{};
316325
RT::PiContext Context = MContext->getHandleRef();
317326
RT::PiDevice Device = MDevice->getHandleRef();

0 commit comments

Comments
 (0)