Skip to content

Commit fc7429e

Browse files
authoredMay 6, 2025
[SYCL] Use raw pointers in enqueue flow (#18306)
For `kernel_impl` parameter - it's an optional input only parameter that is owned by the caller for the duration of the call and we don't extend its lifetime/create copies as can be seen by the absence of changes in the callee (all we need is to access its data). For `event_impl` "out" parameter the semantics is such that the caller creates an object, and the modified interfaces update that object with the UR handles once enqueue/launch is done. The ownership remains controlled by the caller. --------- Signed-off-by: Sergei Vinogradov <sergey.vinogradov@intel.com>
1 parent 64ceadc commit fc7429e

File tree

4 files changed

+20
-23
lines changed

4 files changed

+20
-23
lines changed
 

‎sycl/source/detail/kernel_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ class kernel_impl {
231231
ur_program_handle_t getProgramRef() const { return MProgram; }
232232
ContextImplPtr getContextImplPtr() const { return MContext; }
233233

234-
std::mutex &getNoncacheableEnqueueMutex() {
234+
std::mutex &getNoncacheableEnqueueMutex() const {
235235
return MNoncacheableEnqueueMutex;
236236
}
237237

@@ -247,7 +247,7 @@ class kernel_impl {
247247
const DeviceImageImplPtr MDeviceImageImpl;
248248
const KernelBundleImplPtr MKernelBundleImpl;
249249
bool MIsInterop = false;
250-
std::mutex MNoncacheableEnqueueMutex;
250+
mutable std::mutex MNoncacheableEnqueueMutex;
251251
const KernelArgMask *MKernelArgMaskPtr;
252252
std::mutex *MCacheMutex = nullptr;
253253
mutable std::string MName;

‎sycl/source/detail/scheduler/commands.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2380,8 +2380,7 @@ static ur_result_t SetKernelParamsAndLaunch(
23802380
const QueueImplPtr &Queue, std::vector<ArgDesc> &Args,
23812381
const std::shared_ptr<device_image_impl> &DeviceImageImpl,
23822382
ur_kernel_handle_t Kernel, NDRDescT &NDRDesc,
2383-
std::vector<ur_event_handle_t> &RawEvents,
2384-
const detail::EventImplPtr &OutEventImpl,
2383+
std::vector<ur_event_handle_t> &RawEvents, detail::event_impl *OutEventImpl,
23852384
const KernelArgMask *EliminatedArgMask,
23862385
const std::function<void *(Requirement *Req)> &getMemAllocationFunc,
23872386
bool IsCooperative, bool KernelUsesClusterLaunch,
@@ -2651,9 +2650,8 @@ ur_result_t enqueueImpCommandBufferKernel(
26512650
void enqueueImpKernel(
26522651
const QueueImplPtr &Queue, NDRDescT &NDRDesc, std::vector<ArgDesc> &Args,
26532652
const std::shared_ptr<detail::kernel_bundle_impl> &KernelBundleImplPtr,
2654-
const std::shared_ptr<detail::kernel_impl> &MSyclKernel,
2655-
KernelNameStrRefT KernelName, std::vector<ur_event_handle_t> &RawEvents,
2656-
const detail::EventImplPtr &OutEventImpl,
2653+
const detail::kernel_impl *MSyclKernel, KernelNameStrRefT KernelName,
2654+
std::vector<ur_event_handle_t> &RawEvents, detail::event_impl *OutEventImpl,
26572655
const std::function<void *(Requirement *Req)> &getMemAllocationFunc,
26582656
ur_kernel_cache_config_t KernelCacheConfig, const bool KernelIsCooperative,
26592657
const bool KernelUsesClusterLaunch, const size_t WorkGroupMemorySize,
@@ -2761,7 +2759,7 @@ ur_result_t enqueueReadWriteHostPipe(const QueueImplPtr &Queue,
27612759
const std::string &PipeName, bool blocking,
27622760
void *ptr, size_t size,
27632761
std::vector<ur_event_handle_t> &RawEvents,
2764-
const detail::EventImplPtr &OutEventImpl,
2762+
detail::event_impl *OutEventImpl,
27652763
bool read) {
27662764
assert(Queue &&
27672765
"ReadWrite host pipe submissions should have an associated queue");
@@ -3122,7 +3120,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
31223120

31233121
ur_event_handle_t UREvent = nullptr;
31243122
ur_event_handle_t *Event = DiscardUrEvent ? nullptr : &UREvent;
3125-
detail::EventImplPtr EventImpl = DiscardUrEvent ? nullptr : MEvent;
3123+
detail::event_impl *EventImpl = DiscardUrEvent ? nullptr : MEvent.get();
31263124

31273125
auto SetEventHandleOrDiscard = [&]() {
31283126
if (Event)
@@ -3237,7 +3235,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
32373235
(!SyclKernel || SyclKernel->hasSYCLMetadata()) &&
32383236
ProgramManager::getInstance().kernelUsesAssert(KernelName);
32393237
if (KernelUsesAssert) {
3240-
EventImpl = MEvent;
3238+
EventImpl = MEvent.get();
32413239
}
32423240
}
32433241

@@ -3248,7 +3246,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
32483246
assert(BinImage && "Failed to obtain a binary image.");
32493247
}
32503248
enqueueImpKernel(MQueue, NDRDesc, Args, ExecKernel->getKernelBundle(),
3251-
SyclKernel, KernelName, RawEvents, EventImpl,
3249+
SyclKernel.get(), KernelName, RawEvents, EventImpl,
32523250
getMemAllocationFunc, ExecKernel->MKernelCacheConfig,
32533251
ExecKernel->MKernelIsCooperative,
32543252
ExecKernel->MKernelUsesClusterLaunch,
@@ -3645,7 +3643,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
36453643
bool read = ExecReadWriteHostPipe->isReadHostPipe();
36463644

36473645
if (!EventImpl) {
3648-
EventImpl = MEvent;
3646+
EventImpl = MEvent.get();
36493647
}
36503648
return enqueueReadWriteHostPipe(MQueue, pipeName, blocking, hostPtr,
36513649
typeSize, RawEvents, EventImpl, read);

‎sycl/source/detail/scheduler/commands.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,14 @@ ur_result_t enqueueReadWriteHostPipe(const QueueImplPtr &Queue,
614614
const std::string &PipeName, bool blocking,
615615
void *ptr, size_t size,
616616
std::vector<ur_event_handle_t> &RawEvents,
617-
const detail::EventImplPtr &OutEventImpl,
617+
detail::event_impl *OutEventImpl,
618618
bool read);
619619

620620
void enqueueImpKernel(
621621
const QueueImplPtr &Queue, NDRDescT &NDRDesc, std::vector<ArgDesc> &Args,
622622
const std::shared_ptr<detail::kernel_bundle_impl> &KernelBundleImplPtr,
623-
const std::shared_ptr<detail::kernel_impl> &MSyclKernel,
624-
KernelNameStrRefT KernelName, std::vector<ur_event_handle_t> &RawEvents,
625-
const detail::EventImplPtr &Event,
623+
const detail::kernel_impl *MSyclKernel, KernelNameStrRefT KernelName,
624+
std::vector<ur_event_handle_t> &RawEvents, detail::event_impl *OutEventImpl,
626625
const std::function<void *(Requirement *Req)> &getMemAllocationFunc,
627626
ur_kernel_cache_config_t KernelCacheConfig, bool KernelIsCooperative,
628627
const bool KernelUsesClusterLaunch, const size_t WorkGroupMemorySize,

‎sycl/source/handler.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,13 @@ event handler::finalize() {
537537
detail::retrieveKernelBinary(MQueue, MKernelName.data());
538538
assert(BinImage && "Failed to obtain a binary image.");
539539
}
540-
enqueueImpKernel(
541-
MQueue, impl->MNDRDesc, impl->MArgs, KernelBundleImpPtr, MKernel,
542-
MKernelName.data(), RawEvents,
543-
DiscardEvent ? detail::EventImplPtr{} : LastEventImpl, nullptr,
544-
impl->MKernelCacheConfig, impl->MKernelIsCooperative,
545-
impl->MKernelUsesClusterLaunch, impl->MKernelWorkGroupMemorySize,
546-
BinImage);
540+
enqueueImpKernel(MQueue, impl->MNDRDesc, impl->MArgs,
541+
KernelBundleImpPtr, MKernel.get(), MKernelName.data(),
542+
RawEvents,
543+
DiscardEvent ? nullptr : LastEventImpl.get(), nullptr,
544+
impl->MKernelCacheConfig, impl->MKernelIsCooperative,
545+
impl->MKernelUsesClusterLaunch,
546+
impl->MKernelWorkGroupMemorySize, BinImage);
547547
#ifdef XPTI_ENABLE_INSTRUMENTATION
548548
// Emit signal only when event is created
549549
if (!DiscardEvent) {

0 commit comments

Comments
 (0)