Skip to content

Commit bbcf93e

Browse files
[SYCL][L0] Address static analyzer issues (#7778)
Signed-off-by: Sergey V Maslov <[email protected]>
1 parent de32430 commit bbcf93e

File tree

6 files changed

+39
-34
lines changed

6 files changed

+39
-34
lines changed

sycl/plugins/level_zero/pi_level_zero.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ pi_result _pi_context::finalize() {
977977
if (!DisableEventsCaching) {
978978
std::scoped_lock<pi_mutex> Lock(EventCacheMutex);
979979
for (auto &EventCache : EventCaches) {
980-
for (auto Event : EventCache) {
980+
for (auto &Event : EventCache) {
981981
ZE_CALL(zeEventDestroy, (Event->ZeEvent));
982982
delete Event;
983983
}
@@ -1318,7 +1318,7 @@ static pi_result CleanupCompletedEvent(pi_event Event,
13181318
static pi_result
13191319
CleanupEventListFromResetCmdList(std::vector<pi_event> &EventListToCleanup,
13201320
bool QueueLocked = false) {
1321-
for (auto Event : EventListToCleanup) {
1321+
for (auto &Event : EventListToCleanup) {
13221322
// We don't need to synchronize the events since the fence associated with
13231323
// the command list was synchronized.
13241324
{
@@ -4029,7 +4029,7 @@ pi_result piQueueRelease(pi_queue Queue) {
40294029
Queue->CommandListMap.clear();
40304030
}
40314031

4032-
for (auto Event : EventListToCleanup) {
4032+
for (auto &Event : EventListToCleanup) {
40334033
// We don't need to synchronize the events since the queue
40344034
// synchronized above already does that.
40354035
{
@@ -4051,8 +4051,8 @@ static pi_result piQueueReleaseInternal(pi_queue Queue) {
40514051
if (!Queue->RefCount.decrementAndTest())
40524052
return PI_SUCCESS;
40534053

4054-
for (auto Cache : Queue->EventCaches)
4055-
for (auto Event : Cache)
4054+
for (auto &Cache : Queue->EventCaches)
4055+
for (auto &Event : Cache)
40564056
PI_CALL(piEventReleaseInternal(Event));
40574057

40584058
if (Queue->OwnZeCommandQueue) {
@@ -4117,7 +4117,7 @@ pi_result piQueueFinish(pi_queue Queue) {
41174117
Lock.unlock();
41184118
}
41194119

4120-
for (auto ZeQueue : ZeQueues) {
4120+
for (auto &ZeQueue : ZeQueues) {
41214121
if (ZeQueue)
41224122
ZE_CALL(zeHostSynchronize, (ZeQueue));
41234123
}
@@ -6377,7 +6377,7 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {
63776377

63786378
// We waited some events above, check queue for signaled command lists and
63796379
// reset them.
6380-
for (auto Q : Queues)
6380+
for (auto &Q : Queues)
63816381
resetCommandLists(Q);
63826382

63836383
return PI_SUCCESS;
@@ -6876,7 +6876,7 @@ pi_result piEnqueueEventsWaitWithBarrier(pi_queue Queue,
68766876
// these so a queue-wide barrier can be inserted into each command
68776877
// queue.
68786878
CmdLists.reserve(NumQueues);
6879-
for (auto QueueGroup : {Queue->ComputeQueueGroup, Queue->CopyQueueGroup}) {
6879+
for (auto &QueueGroup : {Queue->ComputeQueueGroup, Queue->CopyQueueGroup}) {
68806880
bool UseCopyEngine = QueueGroup.Type != _pi_queue::queue_type::Compute;
68816881
for (ze_command_queue_handle_t ZeQueue : QueueGroup.ZeQueues) {
68826882
if (ZeQueue) {
@@ -7041,9 +7041,9 @@ pi_result _pi_queue::synchronize() {
70417041
};
70427042

70437043
if (Device->useImmediateCommandLists()) {
7044-
for (auto ImmCmdList : ComputeQueueGroup.ImmCmdLists)
7044+
for (auto &ImmCmdList : ComputeQueueGroup.ImmCmdLists)
70457045
syncImmCmdList(this, ImmCmdList);
7046-
for (auto ImmCmdList : CopyQueueGroup.ImmCmdLists)
7046+
for (auto &ImmCmdList : CopyQueueGroup.ImmCmdLists)
70477047
syncImmCmdList(this, ImmCmdList);
70487048
} else {
70497049
for (auto &ZeQueue : ComputeQueueGroup.ZeQueues)
@@ -7603,10 +7603,8 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Mem, pi_bool BlockingMap,
76037603
return Res;
76047604

76057605
// Add the event to the command list.
7606-
if (Event) {
7607-
CommandList->second.append(*Event);
7608-
(*Event)->RefCount.increment();
7609-
}
7606+
CommandList->second.append(*Event);
7607+
(*Event)->RefCount.increment();
76107608

76117609
const auto &ZeCommandList = CommandList->first;
76127610
const auto &WaitList = (*Event)->WaitList;
@@ -7683,10 +7681,8 @@ pi_result piEnqueueMemUnmap(pi_queue Queue, pi_mem Mem, void *MappedPtr,
76837681
// do so in piEventRelease called for the pi_event tracking the unmap.
76847682
// In the case of an integrated device, the map operation does not allocate
76857683
// any memory, so there is nothing to free. This is indicated by a nullptr.
7686-
if (Event)
7687-
(*Event)->CommandData =
7688-
(Buffer->OnHost ? nullptr
7689-
: (Buffer->MapHostPtr ? nullptr : MappedPtr));
7684+
(*Event)->CommandData =
7685+
(Buffer->OnHost ? nullptr : (Buffer->MapHostPtr ? nullptr : MappedPtr));
76907686
}
76917687

76927688
// For integrated devices the buffer is allocated in host memory.

sycl/plugins/level_zero/pi_level_zero.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,11 @@ struct _pi_ze_event_list_t {
12351235
// not assignment copyable. Just field by field copy of the other
12361236
// fields.
12371237
_pi_ze_event_list_t &operator=(const _pi_ze_event_list_t &other) {
1238-
this->ZeEventList = other.ZeEventList;
1239-
this->PiEventList = other.PiEventList;
1240-
this->Length = other.Length;
1238+
if (this != &other) {
1239+
this->ZeEventList = other.ZeEventList;
1240+
this->PiEventList = other.PiEventList;
1241+
this->Length = other.Length;
1242+
}
12411243
return *this;
12421244
}
12431245
};

sycl/plugins/level_zero/usm_allocator.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,8 @@ std::ostream &operator<<(std::ostream &Os, const Slab &Slab) {
592592
Slab::Slab(Bucket &Bkt)
593593
: // In case bucket size is not a multiple of SlabMinSize, we would have
594594
// some padding at the end of the slab.
595-
Chunks(Bkt.SlabMinSize() / Bkt.getSize()), NumAllocated{0},
596-
bucket(Bkt), SlabListIter{}, FirstFreeChunkIdx{0} {
595+
Chunks(Bkt.SlabMinSize() / Bkt.getSize()), NumAllocated{0}, bucket(Bkt),
596+
SlabListIter{}, FirstFreeChunkIdx{0} {
597597
auto SlabSize = Bkt.SlabAllocSize();
598598
MemPtr = Bkt.getMemHandle().allocate(SlabSize);
599599
regSlab(*this);
@@ -1106,12 +1106,16 @@ USMAllocContext::~USMAllocContext() {
11061106
MemType MT = pImpl->getMemHandle().getMemType();
11071107
pImpl->printStats(TitlePrinted, HighBucketSize, HighPeakSlabsInUse, MT);
11081108
if (TitlePrinted) {
1109-
std::cout << "Current Pool Size " << USMSettings.CurPoolSize << std::endl;
1110-
const char *Label = USMSettings.MemTypeNames[MT];
1111-
std::cout << "Suggested Setting: SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=;"
1112-
<< std::string(1, tolower(*Label)) << std::string(Label + 1)
1113-
<< ":" << HighBucketSize << "," << HighPeakSlabsInUse << ",64K"
1114-
<< std::endl;
1109+
try { // cannot throw in destructor
1110+
std::cout << "Current Pool Size " << USMSettings.CurPoolSize
1111+
<< std::endl;
1112+
const char *Label = USMSettings.MemTypeNames[MT];
1113+
std::cout << "Suggested Setting: SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=;"
1114+
<< std::string(1, tolower(*Label)) << std::string(Label + 1)
1115+
<< ":" << HighBucketSize << "," << HighPeakSlabsInUse
1116+
<< ",64K" << std::endl;
1117+
} catch (...) { // ignore exceptions
1118+
}
11151119
}
11161120
}
11171121
}

sycl/plugins/opencl/pi_opencl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ static pi_result getExtFuncFromContext(pi_context context, T *fptr) {
162162
thread_local static std::map<pi_context, T> FuncPtrs;
163163

164164
// if cached, return cached FuncPtr
165-
if (auto F = FuncPtrs[context]) {
165+
auto It = FuncPtrs.find(context);
166+
if (It != FuncPtrs.end()) {
167+
auto F = It->second;
166168
// if cached that extension is not available return nullptr and
167169
// PI_ERROR_INVALID_VALUE
168170
*fptr = F;
@@ -771,7 +773,7 @@ pi_result piextGetDeviceFunctionPointer(pi_device device, pi_program program,
771773
return cast<pi_result>(Res);
772774

773775
std::string ClResult(Size, ' ');
774-
ret_err =
776+
Res =
775777
clGetProgramInfo(cast<cl_program>(program), PI_PROGRAM_INFO_KERNEL_NAMES,
776778
ClResult.size(), &ClResult[0], nullptr);
777779
if (Res != CL_SUCCESS)

sycl/plugins/unified_runtime/adapters/level_zero/ur_level_zero.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ zer_result_t _ur_level_zero_platform::initialize() {
179179
ZE_CALL(zeDriverGetExtensionProperties,
180180
(ZeDriver, &Count, ZeExtensions.data()));
181181

182-
for (auto extension : ZeExtensions) {
182+
for (auto &extension : ZeExtensions) {
183183
// Check if global offset extension is available
184184
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
185185
strlen(ZE_GLOBAL_OFFSET_EXP_NAME) + 1) == 0) {

sycl/plugins/unified_runtime/adapters/level_zero/ur_level_zero.hpp

100755100644
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,9 @@ using ur_level_zero_platform = _ur_level_zero_platform *;
170170
class ZeUSMImportExtension {
171171
// Pointers to functions that import/release host memory into USM
172172
ze_result_t (*zexDriverImportExternalPointer)(ze_driver_handle_t hDriver,
173-
void *, size_t);
174-
ze_result_t (*zexDriverReleaseImportedPointer)(ze_driver_handle_t, void *);
173+
void *, size_t) = nullptr;
174+
ze_result_t (*zexDriverReleaseImportedPointer)(ze_driver_handle_t,
175+
void *) = nullptr;
175176

176177
public:
177178
// Whether user has requested Import/Release, and platform supports it.

0 commit comments

Comments
 (0)