Skip to content

Commit f8fc936

Browse files
authored
Merge pull request intel#1179 from pbalcer/coverity-issues
[L0] coverity fixes
2 parents 20b9a83 + 4210433 commit f8fc936

File tree

9 files changed

+42
-36
lines changed

9 files changed

+42
-36
lines changed

source/adapters/level_zero/adapter.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urAdapterRetain(ur_adapter_handle_t) {
156156
}
157157

158158
UR_APIEXPORT ur_result_t UR_APICALL urAdapterGetLastError(
159-
[[maybe_unused]] ur_adapter_handle_t
160-
AdapterHandle, ///< [in] handle of the platform instance
159+
ur_adapter_handle_t, ///< [in] handle of the platform instance
161160
const char **Message, ///< [out] pointer to a C string where the adapter
162161
///< specific error message will be stored.
163-
[[maybe_unused]] int32_t
164-
*Error ///< [out] pointer to an integer where the adapter specific
165-
///< error code will be stored.
162+
int32_t *Error ///< [out] pointer to an integer where the adapter specific
163+
///< error code will be stored.
166164
) {
167-
AdapterHandle = &Adapter;
168165
*Message = ErrorMessage;
169-
Error = &ErrorAdapterNativeCode;
166+
*Error = ErrorAdapterNativeCode;
170167

171168
return ErrorMessageCode;
172169
}

source/adapters/level_zero/device.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "ur_level_zero.hpp"
1313
#include <algorithm>
1414
#include <climits>
15+
#include <optional>
1516

1617
UR_APIEXPORT ur_result_t UR_APICALL urDeviceGet(
1718
ur_platform_handle_t Platform, ///< [in] handle of the platform instance
@@ -353,8 +354,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
353354
UR_DEVICE_AFFINITY_DOMAIN_FLAG_NEXT_PARTITIONABLE));
354355
case UR_DEVICE_INFO_PARTITION_TYPE: {
355356
// For root-device there is no partitioning to report.
356-
if (pSize && !Device->isSubDevice()) {
357-
*pSize = 0;
357+
if (Device->SubDeviceCreationProperty == std::nullopt ||
358+
!Device->isSubDevice()) {
359+
if (pSize)
360+
*pSize = 0;
358361
return UR_RESULT_SUCCESS;
359362
}
360363

@@ -365,7 +368,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(
365368
return ReturnValue(cslice);
366369
}
367370

368-
return ReturnValue(Device->SubDeviceCreationProperty);
371+
return ReturnValue(*Device->SubDeviceCreationProperty);
369372
}
370373
// Everything under here is not supported yet
371374
case UR_EXT_DEVICE_INFO_OPENCL_C_VERSION:
@@ -1218,16 +1221,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition(
12181221
UR_ASSERT(NumDevices == EffectiveNumDevices, UR_RESULT_ERROR_INVALID_VALUE);
12191222

12201223
for (uint32_t I = 0; I < NumDevices; I++) {
1221-
Device->SubDevices[I]->SubDeviceCreationProperty =
1222-
Properties->pProperties[0];
1223-
if (Properties->pProperties[0].type ==
1224-
UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN) {
1224+
auto prop = Properties->pProperties[0];
1225+
if (prop.type == UR_DEVICE_PARTITION_BY_AFFINITY_DOMAIN) {
12251226
// In case the value is NEXT_PARTITIONABLE, we need to change it to the
12261227
// chosen domain. This will always be NUMA since that's the only domain
12271228
// supported by level zero.
1228-
Device->SubDevices[I]->SubDeviceCreationProperty.value.affinity_domain =
1229-
UR_DEVICE_AFFINITY_DOMAIN_FLAG_NUMA;
1229+
prop.value.affinity_domain = UR_DEVICE_AFFINITY_DOMAIN_FLAG_NUMA;
12301230
}
1231+
Device->SubDevices[I]->SubDeviceCreationProperty = prop;
12311232

12321233
OutDevices[I] = Device->SubDevices[I];
12331234
// reusing the same pi_device needs to increment the reference count

source/adapters/level_zero/device.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <cassert>
1313
#include <list>
1414
#include <map>
15+
#include <optional>
1516
#include <stdarg.h>
1617
#include <string>
1718
#include <unordered_map>
@@ -116,7 +117,7 @@ struct ur_device_handle_t_ : _ur_object {
116117

117118
// If this device is a subdevice, this variable contains the properties that
118119
// were used during its creation.
119-
ur_device_partition_property_t SubDeviceCreationProperty;
120+
std::optional<ur_device_partition_property_t> SubDeviceCreationProperty;
120121

121122
// PI platform to which this device belongs.
122123
// This field is only set at _ur_device_handle_t creation time, and cannot

source/adapters/level_zero/kernel.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@
1616
struct ur_kernel_handle_t_ : _ur_object {
1717
ur_kernel_handle_t_(ze_kernel_handle_t Kernel, bool OwnZeHandle,
1818
ur_program_handle_t Program)
19-
: Program{Program}, ZeKernel{Kernel}, SubmissionsCount{0}, MemAllocs{} {
19+
: Context{nullptr}, Program{Program}, ZeKernel{Kernel},
20+
SubmissionsCount{0}, MemAllocs{} {
2021
OwnNativeHandle = OwnZeHandle;
2122
}
2223

2324
ur_kernel_handle_t_(ze_kernel_handle_t Kernel, bool OwnZeHandle,
2425
ur_context_handle_t Context)
25-
: Context{Context}, ZeKernel{Kernel}, SubmissionsCount{0}, MemAllocs{} {
26+
: Context{Context}, Program{nullptr}, ZeKernel{Kernel},
27+
SubmissionsCount{0}, MemAllocs{} {
2628
OwnNativeHandle = OwnZeHandle;
2729
}
2830

source/adapters/level_zero/memory.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2078,9 +2078,9 @@ ur_result_t _ur_buffer::getZeHandle(char *&ZeHandle, access_mode_t AccessMode,
20782078
auto &Allocation = Allocations[Device];
20792079

20802080
// Sub-buffers don't maintain own allocations but rely on parent buffer.
2081-
if (isSubBuffer()) {
2082-
UR_CALL(SubBuffer.Parent->getZeHandle(ZeHandle, AccessMode, Device));
2083-
ZeHandle += SubBuffer.Origin;
2081+
if (SubBuffer) {
2082+
UR_CALL(SubBuffer->Parent->getZeHandle(ZeHandle, AccessMode, Device));
2083+
ZeHandle += SubBuffer->Origin;
20842084
// Still store the allocation info in the PI sub-buffer for
20852085
// getZeHandlePtr to work. At least zeKernelSetArgumentValue needs to
20862086
// be given a pointer to the allocation handle rather than its value.
@@ -2312,7 +2312,7 @@ ur_result_t _ur_buffer::free() {
23122312
// Buffer constructor
23132313
_ur_buffer::_ur_buffer(ur_context_handle_t Context, size_t Size, char *HostPtr,
23142314
bool ImportedHostPtr = false)
2315-
: ur_mem_handle_t_(Context), Size(Size), SubBuffer{nullptr, 0} {
2315+
: ur_mem_handle_t_(Context), Size(Size) {
23162316

23172317
// We treat integrated devices (physical memory shared with the CPU)
23182318
// differently from discrete devices (those with distinct memories).
@@ -2347,7 +2347,7 @@ _ur_buffer::_ur_buffer(ur_context_handle_t Context, ur_device_handle_t Device,
23472347
_ur_buffer::_ur_buffer(ur_context_handle_t Context, size_t Size,
23482348
ur_device_handle_t Device, char *ZeMemHandle,
23492349
bool OwnZeMemHandle)
2350-
: ur_mem_handle_t_(Context, Device), Size(Size), SubBuffer{nullptr, 0} {
2350+
: ur_mem_handle_t_(Context, Device), Size(Size) {
23512351

23522352
// Device == nullptr means host allocation
23532353
Allocations[Device].ZeHandle = ZeMemHandle;

source/adapters/level_zero/memory.hpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <cassert>
1414
#include <list>
1515
#include <map>
16+
#include <optional>
1617
#include <stdarg.h>
1718
#include <string>
1819
#include <unordered_map>
@@ -84,7 +85,8 @@ struct ur_mem_handle_t_ : _ur_object {
8485
virtual ~ur_mem_handle_t_() = default;
8586

8687
protected:
87-
ur_mem_handle_t_(ur_context_handle_t Context) : UrContext{Context} {}
88+
ur_mem_handle_t_(ur_context_handle_t Context)
89+
: UrContext{Context}, UrDevice{nullptr} {}
8890

8991
ur_mem_handle_t_(ur_context_handle_t Context, ur_device_handle_t Device)
9092
: UrContext{Context}, UrDevice(Device) {}
@@ -101,7 +103,7 @@ struct _ur_buffer final : ur_mem_handle_t_ {
101103
// Sub-buffer constructor
102104
_ur_buffer(_ur_buffer *Parent, size_t Origin, size_t Size)
103105
: ur_mem_handle_t_(Parent->UrContext),
104-
Size(Size), SubBuffer{Parent, Origin} {}
106+
Size(Size), SubBuffer{{Parent, Origin}} {}
105107

106108
// Interop-buffer constructor
107109
_ur_buffer(ur_context_handle_t Context, size_t Size,
@@ -121,8 +123,7 @@ struct _ur_buffer final : ur_mem_handle_t_ {
121123
ur_device_handle_t Device = nullptr) override;
122124

123125
bool isImage() const override { return false; }
124-
125-
bool isSubBuffer() const { return SubBuffer.Parent != nullptr; }
126+
bool isSubBuffer() const { return SubBuffer != std::nullopt; }
126127

127128
// Frees all allocations made for the buffer.
128129
ur_result_t free();
@@ -174,10 +175,11 @@ struct _ur_buffer final : ur_mem_handle_t_ {
174175
size_t Size;
175176
size_t getAlignment() const;
176177

177-
struct {
178+
struct SubBuffer_t {
178179
_ur_buffer *Parent;
179-
size_t Origin; // only valid if Parent != nullptr
180-
} SubBuffer;
180+
size_t Origin;
181+
};
182+
std::optional<SubBuffer_t> SubBuffer;
181183
};
182184

183185
struct _ur_image final : ur_mem_handle_t_ {

source/adapters/level_zero/platform.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
#pragma once
1111

1212
#include "common.hpp"
13+
#include "ze_api.h"
1314

1415
struct ur_device_handle_t_;
1516

1617
struct ur_platform_handle_t_ : public _ur_platform {
17-
ur_platform_handle_t_(ze_driver_handle_t Driver) : ZeDriver{Driver} {}
18+
ur_platform_handle_t_(ze_driver_handle_t Driver)
19+
: ZeDriver{Driver}, ZeApiVersion{ZE_API_VERSION_CURRENT} {}
1820
// Performs initialization of a newly constructed PI platform.
1921
ur_result_t initialize();
2022

source/adapters/level_zero/queue.cpp

100755100644
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueGetInfo(
219219
if (ImmCmdList == Queue->CommandListMap.end())
220220
continue;
221221

222-
auto EventList = ImmCmdList->second.EventList;
222+
const auto &EventList = ImmCmdList->second.EventList;
223223
for (auto It = EventList.crbegin(); It != EventList.crend(); It++) {
224224
ze_result_t ZeResult =
225225
ZE_CALL_NOCHECK(zeEventQueryStatus, ((*It)->ZeEvent));
@@ -391,11 +391,11 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate(
391391
// At this point only the thread creating the queue will have associated
392392
// command-lists. Other threads have not accessed the queue yet. So we can
393393
// only warmup the initial thread's command-lists.
394-
auto QueueGroup = Q->ComputeQueueGroupsByTID.get();
394+
const auto &QueueGroup = Q->ComputeQueueGroupsByTID.get();
395395
UR_CALL(warmupQueueGroup(false, QueueGroup.UpperIndex -
396396
QueueGroup.LowerIndex + 1));
397397
if (Q->useCopyEngine()) {
398-
auto QueueGroup = Q->CopyQueueGroupsByTID.get();
398+
const auto &QueueGroup = Q->CopyQueueGroupsByTID.get();
399399
UR_CALL(warmupQueueGroup(true, QueueGroup.UpperIndex -
400400
QueueGroup.LowerIndex + 1));
401401
}

source/adapters/level_zero/queue.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ struct ur_queue_handle_t_ : _ur_object {
424424
// checked. Otherwise, the OpenCommandList containing compute commands is
425425
// checked.
426426
bool hasOpenCommandList(bool IsCopy) const {
427-
auto CommandBatch = (IsCopy) ? CopyCommandBatch : ComputeCommandBatch;
427+
const auto &CommandBatch =
428+
(IsCopy) ? CopyCommandBatch : ComputeCommandBatch;
428429
return CommandBatch.OpenCommandList != CommandListMap.end();
429430
}
430431

0 commit comments

Comments
 (0)