Skip to content

Commit f541207

Browse files
[SYCL] Fix warnings in sycl/source Part 2 (#16359)
Signed-off-by: Tikhomirova, Kseniya <kseniya.tikhomirova@intel.com>
1 parent 9a8613a commit f541207

File tree

8 files changed

+55
-44
lines changed

8 files changed

+55
-44
lines changed

sycl/source/detail/graph_impl.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ node modifiable_command_graph::addImpl(dynamic_command_group &DynCGF,
16371637

16381638
graph_impl::WriteLock Lock(impl->MMutex);
16391639
std::shared_ptr<detail::node_impl> NodeImpl = impl->add(DynCGFImpl, DepImpls);
1640-
return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
1640+
return sycl::detail::createSyclObjFromImpl<node>(std::move(NodeImpl));
16411641
}
16421642

16431643
node modifiable_command_graph::addImpl(const std::vector<node> &Deps) {
@@ -1649,7 +1649,7 @@ node modifiable_command_graph::addImpl(const std::vector<node> &Deps) {
16491649

16501650
graph_impl::WriteLock Lock(impl->MMutex);
16511651
std::shared_ptr<detail::node_impl> NodeImpl = impl->add(DepImpls);
1652-
return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
1652+
return sycl::detail::createSyclObjFromImpl<node>(std::move(NodeImpl));
16531653
}
16541654

16551655
node modifiable_command_graph::addImpl(std::function<void(handler &)> CGF,
@@ -1662,7 +1662,7 @@ node modifiable_command_graph::addImpl(std::function<void(handler &)> CGF,
16621662

16631663
graph_impl::WriteLock Lock(impl->MMutex);
16641664
std::shared_ptr<detail::node_impl> NodeImpl = impl->add(CGF, {}, DepImpls);
1665-
return sycl::detail::createSyclObjFromImpl<node>(NodeImpl);
1665+
return sycl::detail::createSyclObjFromImpl<node>(std::move(NodeImpl));
16661666
}
16671667

16681668
void modifiable_command_graph::addGraphLeafDependencies(node Node) {
@@ -1987,8 +1987,8 @@ void dynamic_command_group_impl::finalizeCGFList(
19871987
// shared_ptr<detail::CGExecKernel> to store
19881988
sycl::detail::CG *RawCGPtr = Handler.impl->MGraphNodeCG.release();
19891989
auto RawCGExecPtr = static_cast<sycl::detail::CGExecKernel *>(RawCGPtr);
1990-
auto CGExecSP = std::shared_ptr<sycl::detail::CGExecKernel>(RawCGExecPtr);
1991-
MKernels.push_back(CGExecSP);
1990+
MKernels.push_back(
1991+
std::shared_ptr<sycl::detail::CGExecKernel>(RawCGExecPtr));
19921992

19931993
// Track dynamic_parameter usage in command-list
19941994
auto &DynamicParams = Handler.impl->MDynamicParameters;

sycl/source/detail/graph_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ class node_impl : public std::enable_shared_from_this<node_impl> {
140140
/// @param NodeType Type of the command-group.
141141
/// @param CommandGroup The CG which stores the command information for this
142142
/// node.
143-
node_impl(node_type NodeType, std::shared_ptr<sycl::detail::CG> CommandGroup)
143+
node_impl(node_type NodeType,
144+
const std::shared_ptr<sycl::detail::CG> &CommandGroup)
144145
: MCGType(CommandGroup->getType()), MNodeType(NodeType),
145146
MCommandGroup(CommandGroup) {
146147
if (NodeType == node_type::subgraph) {

sycl/source/detail/kernel_program_cache.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ class KernelProgramCache {
442442
return;
443443

444444
// Save reference between the program and the fast cache key.
445+
std::unique_lock<std::mutex> Lock(MKernelFastCacheMutex);
445446
MProgramToKernelFastCacheKeyMap[Program].emplace_back(CacheKey);
446447
}
447448

@@ -495,16 +496,18 @@ class KernelProgramCache {
495496
LockedCacheKP.get().erase(NativePrg);
496497
}
497498

498-
// Remove corresponding entries from KernelFastCache.
499-
auto FastCacheKeyItr =
500-
MProgramToKernelFastCacheKeyMap.find(NativePrg);
501-
if (FastCacheKeyItr != MProgramToKernelFastCacheKeyMap.end()) {
502-
for (const auto &FastCacheKey : FastCacheKeyItr->second) {
503-
std::unique_lock<std::mutex> Lock(MKernelFastCacheMutex);
504-
MKernelFastCache.erase(FastCacheKey);
505-
traceKernel("Kernel evicted.", std::get<2>(FastCacheKey), true);
499+
{
500+
// Remove corresponding entries from KernelFastCache.
501+
std::unique_lock<std::mutex> Lock(MKernelFastCacheMutex);
502+
if (auto FastCacheKeyItr =
503+
MProgramToKernelFastCacheKeyMap.find(NativePrg);
504+
FastCacheKeyItr != MProgramToKernelFastCacheKeyMap.end()) {
505+
for (const auto &FastCacheKey : FastCacheKeyItr->second) {
506+
MKernelFastCache.erase(FastCacheKey);
507+
traceKernel("Kernel evicted.", std::get<2>(FastCacheKey), true);
508+
}
509+
MProgramToKernelFastCacheKeyMap.erase(FastCacheKeyItr);
506510
}
507-
MProgramToKernelFastCacheKeyMap.erase(FastCacheKeyItr);
508511
}
509512

510513
// Remove entry from ProgramCache KeyMap.
@@ -617,16 +620,15 @@ class KernelProgramCache {
617620
///
618621
/// This member function should only be used in unit tests.
619622
void reset() {
623+
std::lock_guard<std::mutex> EvictionListLock(MProgramEvictionListMutex);
620624
std::lock_guard<std::mutex> L1(MProgramCacheMutex);
621625
std::lock_guard<std::mutex> L2(MKernelsPerProgramCacheMutex);
622626
std::lock_guard<std::mutex> L3(MKernelFastCacheMutex);
623627
MCachedPrograms = ProgramCache{};
624628
MKernelsPerProgramCache = KernelCacheT{};
625629
MKernelFastCache = KernelFastCacheT{};
626630
MProgramToKernelFastCacheKeyMap.clear();
627-
628631
// Clear the eviction lists and its mutexes.
629-
std::lock_guard<std::mutex> EvictionListLock(MProgramEvictionListMutex);
630632
MEvictionList.clear();
631633
}
632634

sycl/source/detail/online_compiler/online_compiler.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,18 @@ compileToSPIRV(string_view Src, sycl::info::device_type DeviceType,
9898
#else
9999
static const std::string OclocLibraryName = "libocloc.so";
100100
#endif
101-
void *OclocLibrary = sycl::detail::ur::loadOsLibrary(OclocLibraryName);
101+
auto CustomDeleter = [](void *StoredPtr) {
102+
if (!StoredPtr)
103+
return;
104+
std::ignore = sycl::detail::ur::unloadOsLibrary(StoredPtr);
105+
};
106+
std::unique_ptr<void, decltype(CustomDeleter)> OclocLibrary(
107+
sycl::detail::ur::loadOsLibrary(OclocLibraryName), CustomDeleter);
102108
if (!OclocLibrary)
103109
throw online_compile_error("Cannot load ocloc library: " +
104110
OclocLibraryName);
105-
void *OclocVersionHandle =
106-
sycl::detail::ur::getOsLibraryFuncAddress(OclocLibrary, "oclocVersion");
111+
void *OclocVersionHandle = sycl::detail::ur::getOsLibraryFuncAddress(
112+
OclocLibrary.get(), "oclocVersion");
107113
// The initial versions of ocloc library did not have the oclocVersion()
108114
// function. Those versions had the same API as the first version of ocloc
109115
// library having that oclocVersion() function.
@@ -129,18 +135,21 @@ compileToSPIRV(string_view Src, sycl::info::device_type DeviceType,
129135
std::to_string(CurrentVersionMajor) +
130136
".N), where (N >= " + std::to_string(CurrentVersionMinor) + ").");
131137

132-
CompileToSPIRVHandle =
133-
sycl::detail::ur::getOsLibraryFuncAddress(OclocLibrary, "oclocInvoke");
138+
CompileToSPIRVHandle = sycl::detail::ur::getOsLibraryFuncAddress(
139+
OclocLibrary.get(), "oclocInvoke");
134140
if (!CompileToSPIRVHandle)
135141
throw online_compile_error("Cannot load oclocInvoke() function");
136142
FreeSPIRVOutputsHandle = sycl::detail::ur::getOsLibraryFuncAddress(
137-
OclocLibrary, "oclocFreeOutput");
138-
if (!FreeSPIRVOutputsHandle)
143+
OclocLibrary.get(), "oclocFreeOutput");
144+
if (!FreeSPIRVOutputsHandle) {
145+
CompileToSPIRVHandle = NULL;
139146
throw online_compile_error("Cannot load oclocFreeOutput() function");
147+
}
148+
OclocLibrary.release();
140149
}
141150

142151
std::string CombinedUserArgs;
143-
for (auto UserArg : UserArgs) {
152+
for (const auto &UserArg : UserArgs) {
144153
if (UserArg == "")
145154
continue;
146155
if (CombinedUserArgs != "")

sycl/source/detail/program_manager/program_manager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -799,9 +799,9 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
799799
RootDevImpl->getHandleRef(), UR_DEVICE_INFO_BUILD_ON_SUBDEVICE,
800800
sizeof(ur_bool_t), &MustBuildOnSubdevice, nullptr);
801801

802-
DeviceImplPtr Dev = (MustBuildOnSubdevice == true) ? DeviceImpl : RootDevImpl;
803802
auto Context = createSyclObjFromImpl<context>(ContextImpl);
804-
auto Device = createSyclObjFromImpl<device>(Dev);
803+
auto Device = createSyclObjFromImpl<device>(
804+
MustBuildOnSubdevice == true ? DeviceImpl : RootDevImpl);
805805
const RTDeviceBinaryImage &Img =
806806
getDeviceImage(KernelName, Context, Device, JITCompilationIsRequired);
807807

@@ -822,7 +822,7 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
822822
std::copy(DeviceImagesToLink.begin(), DeviceImagesToLink.end(),
823823
std::back_inserter(AllImages));
824824

825-
return getBuiltURProgram(std::move(AllImages), Context, {Device});
825+
return getBuiltURProgram(std::move(AllImages), Context, {std::move(Device)});
826826
}
827827

828828
ur_program_handle_t ProgramManager::getBuiltURProgram(
@@ -1008,7 +1008,7 @@ ur_program_handle_t ProgramManager::getBuiltURProgram(
10081008
}
10091009
}
10101010
// Change device in the cache key to reduce copying of spec const data.
1011-
CacheKey.second = Subset;
1011+
CacheKey.second = std::move(Subset);
10121012
bool DidInsert = Cache.insertBuiltProgram(CacheKey, ResProgram);
10131013
if (DidInsert) {
10141014
// For every cached copy of the program, we need to increment its

sycl/source/detail/scheduler/commands.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,9 +2569,8 @@ getCGKernelInfo(const CGExecKernel &CommandGroup, ContextImplPtr ContextImpl,
25692569
// they can simply be launched directly.
25702570
if (auto KernelBundleImplPtr = CommandGroup.MKernelBundle;
25712571
KernelBundleImplPtr && !KernelBundleImplPtr->isInterop()) {
2572-
auto KernelName = CommandGroup.MKernelName;
2573-
kernel_id KernelID =
2574-
detail::ProgramManager::getInstance().getSYCLKernelID(KernelName);
2572+
kernel_id KernelID = detail::ProgramManager::getInstance().getSYCLKernelID(
2573+
CommandGroup.MKernelName);
25752574

25762575
kernel SyclKernel =
25772576
KernelBundleImplPtr->get_kernel(KernelID, KernelBundleImplPtr);
@@ -2775,16 +2774,16 @@ void enqueueImpKernel(
27752774
// Initialize device globals associated with this.
27762775
std::vector<ur_event_handle_t> DeviceGlobalInitEvents =
27772776
ContextImpl->initializeDeviceGlobals(Program, Queue);
2778-
std::vector<ur_event_handle_t> EventsWithDeviceGlobalInits;
27792777
if (!DeviceGlobalInitEvents.empty()) {
2778+
std::vector<ur_event_handle_t> EventsWithDeviceGlobalInits;
27802779
EventsWithDeviceGlobalInits.reserve(RawEvents.size() +
27812780
DeviceGlobalInitEvents.size());
27822781
EventsWithDeviceGlobalInits.insert(EventsWithDeviceGlobalInits.end(),
27832782
RawEvents.begin(), RawEvents.end());
27842783
EventsWithDeviceGlobalInits.insert(EventsWithDeviceGlobalInits.end(),
27852784
DeviceGlobalInitEvents.begin(),
27862785
DeviceGlobalInitEvents.end());
2787-
EventsWaitList = EventsWithDeviceGlobalInits;
2786+
EventsWaitList = std::move(EventsWithDeviceGlobalInits);
27882787
}
27892788

27902789
ur_result_t Error = UR_RESULT_SUCCESS;
@@ -3642,6 +3641,7 @@ ur_result_t ExecCGCommand::enqueueImpQueue() {
36423641
// we don't need to enqueue anything.
36433642
return UR_RESULT_SUCCESS;
36443643
}
3644+
assert(MQueue && "Empty node should have an associated queue");
36453645
const detail::AdapterPtr &Adapter = MQueue->getAdapter();
36463646
ur_event_handle_t Event;
36473647
ur_result_t Result = Adapter->call_nocheck<UrApiKind::urEnqueueEventsWait>(

sycl/source/handler.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -543,11 +543,10 @@ event handler::finalize() {
543543
// In-order queues create implicit linear dependencies between nodes.
544544
// Find the last node added to the graph from this queue, so our new
545545
// node can set it as a predecessor.
546-
auto DependentNode = GraphImpl->getLastInorderNode(MQueue);
547546
std::vector<std::shared_ptr<ext::oneapi::experimental::detail::node_impl>>
548547
Deps;
549-
if (DependentNode) {
550-
Deps.push_back(DependentNode);
548+
if (auto DependentNode = GraphImpl->getLastInorderNode(MQueue)) {
549+
Deps.push_back(std::move(DependentNode));
551550
}
552551
NodeImpl = GraphImpl->add(NodeType, std::move(CommandGroup), Deps);
553552

@@ -571,7 +570,7 @@ event handler::finalize() {
571570
}
572571

573572
// Associate an event with this new node and return the event.
574-
GraphImpl->addEventForNode(EventImpl, NodeImpl);
573+
GraphImpl->addEventForNode(EventImpl, std::move(NodeImpl));
575574

576575
return detail::createSyclObjFromImpl<event>(EventImpl);
577576
}

sycl/source/queue.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,12 @@ event queue::mem_advise(const void *Ptr, size_t Length, int Advice,
199199
/// TODO: Unused. Remove these when ABI-break window is open.
200200
event queue::submit_impl(std::function<void(handler &)> CGH,
201201
const detail::code_location &CodeLoc) {
202-
return submit_with_event_impl(CGH, {}, CodeLoc, true);
202+
return submit_with_event_impl(std::move(CGH), {}, CodeLoc, true);
203203
}
204204
event queue::submit_impl(std::function<void(handler &)> CGH,
205205
const detail::code_location &CodeLoc,
206206
bool IsTopCodeLoc) {
207-
return submit_with_event_impl(CGH, {}, CodeLoc, IsTopCodeLoc);
207+
return submit_with_event_impl(std::move(CGH), {}, CodeLoc, IsTopCodeLoc);
208208
}
209209

210210
event queue::submit_impl(std::function<void(handler &)> CGH, queue SecondQueue,
@@ -219,27 +219,27 @@ event queue::submit_impl(std::function<void(handler &)> CGH, queue SecondQueue,
219219

220220
void queue::submit_without_event_impl(std::function<void(handler &)> CGH,
221221
const detail::code_location &CodeLoc) {
222-
submit_without_event_impl(CGH, {}, CodeLoc, true);
222+
submit_without_event_impl(std::move(CGH), {}, CodeLoc, true);
223223
}
224224
void queue::submit_without_event_impl(std::function<void(handler &)> CGH,
225225
const detail::code_location &CodeLoc,
226226
bool IsTopCodeLoc) {
227-
submit_without_event_impl(CGH, {}, CodeLoc, IsTopCodeLoc);
227+
submit_without_event_impl(std::move(CGH), {}, CodeLoc, IsTopCodeLoc);
228228
}
229229

230230
event queue::submit_impl_and_postprocess(
231231
std::function<void(handler &)> CGH, const detail::code_location &CodeLoc,
232232
const detail::SubmitPostProcessF &PostProcess) {
233233
detail::SubmissionInfo SI{};
234234
SI.PostProcessorFunc() = std::move(PostProcess);
235-
return submit_with_event_impl(CGH, SI, CodeLoc, true);
235+
return submit_with_event_impl(std::move(CGH), SI, CodeLoc, true);
236236
}
237237
event queue::submit_impl_and_postprocess(
238238
std::function<void(handler &)> CGH, const detail::code_location &CodeLoc,
239239
const detail::SubmitPostProcessF &PostProcess, bool IsTopCodeLoc) {
240240
detail::SubmissionInfo SI{};
241241
SI.PostProcessorFunc() = std::move(PostProcess);
242-
return submit_with_event_impl(CGH, SI, CodeLoc, IsTopCodeLoc);
242+
return submit_with_event_impl(std::move(CGH), SI, CodeLoc, IsTopCodeLoc);
243243
}
244244

245245
event queue::submit_impl_and_postprocess(

0 commit comments

Comments
 (0)