Skip to content

Commit f799922

Browse files
authored
[Coverity][Graph] Address coverity issues with graphs (#18806)
- Fix copy instead of move (522061, 522073) - Fix auto causing copy (524557) - Fix uncaught exceptions in `graph_mem_pool` destructor (522004) Fixes: #18510
1 parent 5c6719e commit f799922

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed

sycl/source/detail/graph_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ void exec_graph_impl::findRealDeps(
805805
}
806806

807807
ur_exp_command_buffer_sync_point_t
808-
exec_graph_impl::enqueueNodeDirect(sycl::context Ctx,
808+
exec_graph_impl::enqueueNodeDirect(const sycl::context &Ctx,
809809
sycl::detail::device_impl &DeviceImpl,
810810
ur_exp_command_buffer_handle_t CommandBuffer,
811811
std::shared_ptr<node_impl> Node) {

sycl/source/detail/graph_impl.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,7 +1457,8 @@ class exec_graph_impl {
14571457
/// @param Node The node being enqueued.
14581458
/// @return UR sync point created for this node in the command-buffer.
14591459
ur_exp_command_buffer_sync_point_t
1460-
enqueueNodeDirect(sycl::context Ctx, sycl::detail::device_impl &DeviceImpl,
1460+
enqueueNodeDirect(const sycl::context &Ctx,
1461+
sycl::detail::device_impl &DeviceImpl,
14611462
ur_exp_command_buffer_handle_t CommandBuffer,
14621463
std::shared_ptr<node_impl> Node);
14631464

sycl/source/detail/graph_memory_pool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ graph_mem_pool::malloc(size_t Size, usm::alloc AllocType,
3333
AllocInfo.Kind = AllocType;
3434
// Collect relevant properties from memory pool
3535
if (MemPool) {
36-
auto PropList = MemPool->getPropList();
36+
const auto &PropList = MemPool->getPropList();
3737
if (PropList.has_property<property::memory_pool::zero_init>()) {
3838
AllocInfo.ZeroInit = true;
3939
}

sycl/source/detail/graph_memory_pool.hpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#pragma once
1010

11+
#include "sycl/detail/common.hpp"
1112
#include <detail/physical_mem_impl.hpp> // For physical_mem_impl
1213
#include <sycl/context.hpp> // For context
1314
#include <sycl/device.hpp> // For device
@@ -51,15 +52,19 @@ class graph_mem_pool {
5152
const device &Device)
5253
: MGraph(GraphImpl), MContext(Context), MDevice(Device) {}
5354
~graph_mem_pool() {
54-
for (auto &[Ptr, AllocInfo] : MAllocations) {
55-
// Unmap allocations if required before physical memory is released
56-
// Physical mem is released when MPhysicalMem is cleared
57-
if (AllocInfo.Mapped) {
58-
unmap(Ptr, AllocInfo.Size, MContext);
55+
try {
56+
for (auto &[Ptr, AllocInfo] : MAllocations) {
57+
// Unmap allocations if required before physical memory is released
58+
// Physical mem is released when MPhysicalMem is cleared
59+
if (AllocInfo.Mapped) {
60+
unmap(Ptr, AllocInfo.Size, MContext);
61+
}
62+
// Free the VA range
63+
free_virtual_mem(reinterpret_cast<uintptr_t>(Ptr), AllocInfo.Size,
64+
MContext);
5965
}
60-
// Free the VA range
61-
free_virtual_mem(reinterpret_cast<uintptr_t>(Ptr), AllocInfo.Size,
62-
MContext);
66+
} catch (std::exception &e) {
67+
__SYCL_REPORT_EXCEPTION_TO_STREAM("exception in ~graph_mem_pool", e);
6368
}
6469
MPhysicalMem.clear();
6570
}
@@ -119,7 +124,7 @@ class graph_mem_pool {
119124
[&](sycl::handler &CGH) { CGH.memset(Ptr, 0, AllocInfo.Size); });
120125
}
121126

122-
MPhysicalMem.push_back(PhysicalMem);
127+
MPhysicalMem.push_back(std::move(PhysicalMem));
123128
AllocInfo.PhysicalMemID = MPhysicalMem.size() - 1;
124129
AllocInfo.Mapped = true;
125130
}

sycl/source/detail/scheduler/commands.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ getCGKernelInfo(const CGExecKernel &CommandGroup, ContextImplPtr ContextImpl,
25582558
}
25592559

25602560
ur_result_t enqueueImpCommandBufferKernel(
2561-
context Ctx, device_impl &DeviceImpl,
2561+
const context &Ctx, device_impl &DeviceImpl,
25622562
ur_exp_command_buffer_handle_t CommandBuffer,
25632563
const CGExecKernel &CommandGroup,
25642564
std::vector<ur_exp_command_buffer_sync_point_t> &SyncPoints,

sycl/source/detail/scheduler/commands.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ class UpdateCommandBufferCommand : public Command {
737737

738738
// Enqueues a given kernel to a ur_exp_command_buffer_handle_t
739739
ur_result_t enqueueImpCommandBufferKernel(
740-
context Ctx, device_impl &DeviceImpl,
740+
const context &Ctx, device_impl &DeviceImpl,
741741
ur_exp_command_buffer_handle_t CommandBuffer,
742742
const CGExecKernel &CommandGroup,
743743
std::vector<ur_exp_command_buffer_sync_point_t> &SyncPoints,

0 commit comments

Comments
 (0)