Skip to content

Commit

Permalink
[SYCL][L0] Address static analyzer issues (intel#7778)
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey V Maslov <sergey.v.maslov@intel.com>
  • Loading branch information
smaslov-intel authored Dec 14, 2022
1 parent de32430 commit bbcf93e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 34 deletions.
32 changes: 14 additions & 18 deletions sycl/plugins/level_zero/pi_level_zero.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -977,7 +977,7 @@ pi_result _pi_context::finalize() {
if (!DisableEventsCaching) {
std::scoped_lock<pi_mutex> Lock(EventCacheMutex);
for (auto &EventCache : EventCaches) {
for (auto Event : EventCache) {
for (auto &Event : EventCache) {
ZE_CALL(zeEventDestroy, (Event->ZeEvent));
delete Event;
}
Expand Down Expand Up @@ -1318,7 +1318,7 @@ static pi_result CleanupCompletedEvent(pi_event Event,
static pi_result
CleanupEventListFromResetCmdList(std::vector<pi_event> &EventListToCleanup,
bool QueueLocked = false) {
for (auto Event : EventListToCleanup) {
for (auto &Event : EventListToCleanup) {
// We don't need to synchronize the events since the fence associated with
// the command list was synchronized.
{
Expand Down Expand Up @@ -4029,7 +4029,7 @@ pi_result piQueueRelease(pi_queue Queue) {
Queue->CommandListMap.clear();
}

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

for (auto Cache : Queue->EventCaches)
for (auto Event : Cache)
for (auto &Cache : Queue->EventCaches)
for (auto &Event : Cache)
PI_CALL(piEventReleaseInternal(Event));

if (Queue->OwnZeCommandQueue) {
Expand Down Expand Up @@ -4117,7 +4117,7 @@ pi_result piQueueFinish(pi_queue Queue) {
Lock.unlock();
}

for (auto ZeQueue : ZeQueues) {
for (auto &ZeQueue : ZeQueues) {
if (ZeQueue)
ZE_CALL(zeHostSynchronize, (ZeQueue));
}
Expand Down Expand Up @@ -6377,7 +6377,7 @@ pi_result piEventsWait(pi_uint32 NumEvents, const pi_event *EventList) {

// We waited some events above, check queue for signaled command lists and
// reset them.
for (auto Q : Queues)
for (auto &Q : Queues)
resetCommandLists(Q);

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

if (Device->useImmediateCommandLists()) {
for (auto ImmCmdList : ComputeQueueGroup.ImmCmdLists)
for (auto &ImmCmdList : ComputeQueueGroup.ImmCmdLists)
syncImmCmdList(this, ImmCmdList);
for (auto ImmCmdList : CopyQueueGroup.ImmCmdLists)
for (auto &ImmCmdList : CopyQueueGroup.ImmCmdLists)
syncImmCmdList(this, ImmCmdList);
} else {
for (auto &ZeQueue : ComputeQueueGroup.ZeQueues)
Expand Down Expand Up @@ -7603,10 +7603,8 @@ pi_result piEnqueueMemBufferMap(pi_queue Queue, pi_mem Mem, pi_bool BlockingMap,
return Res;

// Add the event to the command list.
if (Event) {
CommandList->second.append(*Event);
(*Event)->RefCount.increment();
}
CommandList->second.append(*Event);
(*Event)->RefCount.increment();

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

// For integrated devices the buffer is allocated in host memory.
Expand Down
8 changes: 5 additions & 3 deletions sycl/plugins/level_zero/pi_level_zero.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,9 +1235,11 @@ struct _pi_ze_event_list_t {
// not assignment copyable. Just field by field copy of the other
// fields.
_pi_ze_event_list_t &operator=(const _pi_ze_event_list_t &other) {
this->ZeEventList = other.ZeEventList;
this->PiEventList = other.PiEventList;
this->Length = other.Length;
if (this != &other) {
this->ZeEventList = other.ZeEventList;
this->PiEventList = other.PiEventList;
this->Length = other.Length;
}
return *this;
}
};
Expand Down
20 changes: 12 additions & 8 deletions sycl/plugins/level_zero/usm_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,8 @@ std::ostream &operator<<(std::ostream &Os, const Slab &Slab) {
Slab::Slab(Bucket &Bkt)
: // In case bucket size is not a multiple of SlabMinSize, we would have
// some padding at the end of the slab.
Chunks(Bkt.SlabMinSize() / Bkt.getSize()), NumAllocated{0},
bucket(Bkt), SlabListIter{}, FirstFreeChunkIdx{0} {
Chunks(Bkt.SlabMinSize() / Bkt.getSize()), NumAllocated{0}, bucket(Bkt),
SlabListIter{}, FirstFreeChunkIdx{0} {
auto SlabSize = Bkt.SlabAllocSize();
MemPtr = Bkt.getMemHandle().allocate(SlabSize);
regSlab(*this);
Expand Down Expand Up @@ -1106,12 +1106,16 @@ USMAllocContext::~USMAllocContext() {
MemType MT = pImpl->getMemHandle().getMemType();
pImpl->printStats(TitlePrinted, HighBucketSize, HighPeakSlabsInUse, MT);
if (TitlePrinted) {
std::cout << "Current Pool Size " << USMSettings.CurPoolSize << std::endl;
const char *Label = USMSettings.MemTypeNames[MT];
std::cout << "Suggested Setting: SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=;"
<< std::string(1, tolower(*Label)) << std::string(Label + 1)
<< ":" << HighBucketSize << "," << HighPeakSlabsInUse << ",64K"
<< std::endl;
try { // cannot throw in destructor
std::cout << "Current Pool Size " << USMSettings.CurPoolSize
<< std::endl;
const char *Label = USMSettings.MemTypeNames[MT];
std::cout << "Suggested Setting: SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=;"
<< std::string(1, tolower(*Label)) << std::string(Label + 1)
<< ":" << HighBucketSize << "," << HighPeakSlabsInUse
<< ",64K" << std::endl;
} catch (...) { // ignore exceptions
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions sycl/plugins/opencl/pi_opencl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ static pi_result getExtFuncFromContext(pi_context context, T *fptr) {
thread_local static std::map<pi_context, T> FuncPtrs;

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

std::string ClResult(Size, ' ');
ret_err =
Res =
clGetProgramInfo(cast<cl_program>(program), PI_PROGRAM_INFO_KERNEL_NAMES,
ClResult.size(), &ClResult[0], nullptr);
if (Res != CL_SUCCESS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ zer_result_t _ur_level_zero_platform::initialize() {
ZE_CALL(zeDriverGetExtensionProperties,
(ZeDriver, &Count, ZeExtensions.data()));

for (auto extension : ZeExtensions) {
for (auto &extension : ZeExtensions) {
// Check if global offset extension is available
if (strncmp(extension.name, ZE_GLOBAL_OFFSET_EXP_NAME,
strlen(ZE_GLOBAL_OFFSET_EXP_NAME) + 1) == 0) {
Expand Down
5 changes: 3 additions & 2 deletions sycl/plugins/unified_runtime/adapters/level_zero/ur_level_zero.hpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,9 @@ using ur_level_zero_platform = _ur_level_zero_platform *;
class ZeUSMImportExtension {
// Pointers to functions that import/release host memory into USM
ze_result_t (*zexDriverImportExternalPointer)(ze_driver_handle_t hDriver,
void *, size_t);
ze_result_t (*zexDriverReleaseImportedPointer)(ze_driver_handle_t, void *);
void *, size_t) = nullptr;
ze_result_t (*zexDriverReleaseImportedPointer)(ze_driver_handle_t,
void *) = nullptr;

public:
// Whether user has requested Import/Release, and platform supports it.
Expand Down

0 comments on commit bbcf93e

Please sign in to comment.