Skip to content

Commit 0f42c75

Browse files
authoredMar 26, 2025
[SYCL] Optimize use of shared_ptr on kernel enqueue fast path (#17569)
Introduce a series of optimizations to how the shared_ptr type variables are passed, to minimize the number of reference counter increments and decrements.
1 parent cf86a44 commit 0f42c75

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed
 

‎sycl/source/detail/program_manager/program_manager.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ ProgramManager &ProgramManager::getInstance() {
7373
}
7474

7575
static ur_program_handle_t
76-
createBinaryProgram(const ContextImplPtr Context,
76+
createBinaryProgram(const ContextImplPtr &Context,
7777
const std::vector<device> &Devices,
7878
const uint8_t **Binaries, size_t *Lengths,
7979
const std::vector<ur_program_metadata_t> &Metadata) {
@@ -104,7 +104,7 @@ createBinaryProgram(const ContextImplPtr Context,
104104
return Program;
105105
}
106106

107-
static ur_program_handle_t createSpirvProgram(const ContextImplPtr Context,
107+
static ur_program_handle_t createSpirvProgram(const ContextImplPtr &Context,
108108
const unsigned char *Data,
109109
size_t DataLen) {
110110
ur_program_handle_t Program = nullptr;
@@ -369,7 +369,8 @@ static void appendCompileOptionsFromImage(std::string &CompileOpts,
369369

370370
appendCompileOptionsForGRFSizeProperties(CompileOpts, Img, isEsimdImage);
371371

372-
const auto PlatformImpl = detail::getSyclObjImpl(Devs[0].get_platform());
372+
platform Platform = Devs[0].get_platform();
373+
const auto &PlatformImpl = detail::getSyclObjImpl(Platform);
373374

374375
// Add optimization flags.
375376
auto str = getUint32PropAsOptStr(Img, "optLevel");
@@ -945,7 +946,7 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
945946
}
946947

947948
std::vector<ur_device_handle_t> URDevices;
948-
for (auto Dev : Devs)
949+
for (auto &Dev : Devs)
949950
URDevices.push_back(getSyclObjImpl(Dev).get()->getHandleRef());
950951

951952
ProgramPtr BuiltProgram =
@@ -1700,7 +1701,7 @@ static inline bool isDeviceImageCompressed(sycl_device_binary Bin) {
17001701
}
17011702

17021703
ProgramManager::ProgramPtr ProgramManager::build(
1703-
ProgramPtr Program, const ContextImplPtr Context,
1704+
ProgramPtr Program, const ContextImplPtr &Context,
17041705
const std::string &CompileOptions, const std::string &LinkOptions,
17051706
std::vector<ur_device_handle_t> &Devices, uint32_t DeviceLibReqMask,
17061707
const std::vector<ur_program_handle_t> &ExtraProgramsToLink,

‎sycl/source/detail/program_manager/program_manager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ class ProgramManager {
350350

351351
using ProgramPtr = std::unique_ptr<std::remove_pointer_t<ur_program_handle_t>,
352352
decltype(&::urProgramRelease)>;
353-
ProgramPtr build(ProgramPtr Program, const ContextImplPtr Context,
353+
ProgramPtr build(ProgramPtr Program, const ContextImplPtr &Context,
354354
const std::string &CompileOptions,
355355
const std::string &LinkOptions,
356356
std::vector<ur_device_handle_t> &Devices,

‎sycl/source/detail/queue_impl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ static event prepareSYCLEventAssociatedWithQueue(
126126
static event createDiscardedEvent() {
127127
EventImplPtr EventImpl =
128128
std::make_shared<event_impl>(event_impl::HES_Discarded);
129-
return createSyclObjFromImpl<event>(EventImpl);
129+
return createSyclObjFromImpl<event>(std::move(EventImpl));
130130
}
131131

132132
const std::vector<event> &
@@ -386,7 +386,7 @@ event queue_impl::submit_impl(const detail::type_erased_cgfo_ty &CGF,
386386

387387
addEvent(Event);
388388

389-
auto EventImpl = detail::getSyclObjImpl(Event);
389+
const auto &EventImpl = detail::getSyclObjImpl(Event);
390390
for (auto &Stream : Streams) {
391391
// We don't want stream flushing to be blocking operation that is why submit
392392
// a host task to print stream buffer. It will fire up as soon as the kernel

0 commit comments

Comments
 (0)