Skip to content

Commit e2ee9a4

Browse files
authored
Merge pull request #1340 from Bensuo/ewan/coverity_cuda_update
[HIP][CUDA][Command-Buffer] Fix Coverity issues in HIP/CUDA command-buffer code
2 parents 7a5150c + be622e7 commit e2ee9a4

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

source/adapters/cuda/command_buffer.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,20 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
6666
cuGraphDestroy(CudaGraph);
6767

6868
// Release the memory allocated to the CudaGraphExec
69-
cuGraphExecDestroy(CudaGraphExec);
69+
if (CudaGraphExec) {
70+
cuGraphExecDestroy(CudaGraphExec);
71+
}
7072
}
7173

7274
ur_exp_command_buffer_command_handle_t_::
7375
ur_exp_command_buffer_command_handle_t_(
7476
ur_exp_command_buffer_handle_t CommandBuffer, ur_kernel_handle_t Kernel,
75-
std::shared_ptr<CUgraphNode> Node, CUDA_KERNEL_NODE_PARAMS Params,
77+
std::shared_ptr<CUgraphNode> &&Node, CUDA_KERNEL_NODE_PARAMS Params,
7678
uint32_t WorkDim, const size_t *GlobalWorkOffsetPtr,
7779
const size_t *GlobalWorkSizePtr, const size_t *LocalWorkSizePtr)
78-
: CommandBuffer(CommandBuffer), Kernel(Kernel), Node(Node), Params(Params),
79-
WorkDim(WorkDim), RefCountInternal(1), RefCountExternal(1) {
80+
: CommandBuffer(CommandBuffer), Kernel(Kernel), Node{std::move(Node)},
81+
Params(Params), WorkDim(WorkDim), RefCountInternal(1),
82+
RefCountExternal(1) {
8083
CommandBuffer->incrementInternalReferenceCount();
8184

8285
const size_t CopySize = sizeof(size_t) * WorkDim;
@@ -375,6 +378,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
375378
NodeParams.blockDimZ = ThreadsPerBlock[2];
376379
NodeParams.sharedMemBytes = LocalSize;
377380
NodeParams.kernelParams = const_cast<void **>(ArgIndices.data());
381+
NodeParams.kern = nullptr;
378382
NodeParams.extra = nullptr;
379383

380384
// Create and add an new kernel node to the Cuda graph
@@ -392,8 +396,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
392396
}
393397

394398
auto NewCommand = new ur_exp_command_buffer_command_handle_t_{
395-
hCommandBuffer, hKernel, NodeSP, NodeParams,
396-
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize};
399+
hCommandBuffer, hKernel, std::move(NodeSP), NodeParams,
400+
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize};
397401

398402
NewCommand->incrementInternalReferenceCount();
399403
hCommandBuffer->CommandHandles.push_back(NewCommand);

source/adapters/cuda/command_buffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static inline const char *getUrResultString(ur_result_t Result) {
183183
struct ur_exp_command_buffer_command_handle_t_ {
184184
ur_exp_command_buffer_command_handle_t_(
185185
ur_exp_command_buffer_handle_t CommandBuffer, ur_kernel_handle_t Kernel,
186-
std::shared_ptr<CUgraphNode> Node, CUDA_KERNEL_NODE_PARAMS Params,
186+
std::shared_ptr<CUgraphNode> &&Node, CUDA_KERNEL_NODE_PARAMS Params,
187187
uint32_t WorkDim, const size_t *GlobalWorkOffsetPtr,
188188
const size_t *GlobalWorkSizePtr, const size_t *LocalWorkSizePtr);
189189

source/adapters/hip/command_buffer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ ur_exp_command_buffer_handle_t_::ur_exp_command_buffer_handle_t_(
5050
ur_context_handle_t hContext, ur_device_handle_t hDevice, bool IsUpdatable)
5151
: Context(hContext), Device(hDevice),
5252
IsUpdatable(IsUpdatable), HIPGraph{nullptr}, HIPGraphExec{nullptr},
53-
RefCountInternal{1}, RefCountExternal{1} {
53+
RefCountInternal{1}, RefCountExternal{1}, NextSyncPoint{0} {
5454
urContextRetain(hContext);
5555
urDeviceRetain(hDevice);
5656
}
@@ -65,11 +65,11 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
6565
UR_TRACE(urDeviceRelease(Device));
6666

6767
// Release the memory allocated to the HIPGraph
68-
UR_CHECK_ERROR(hipGraphDestroy(HIPGraph));
68+
(void)hipGraphDestroy(HIPGraph);
6969

7070
// Release the memory allocated to the HIPGraphExec
7171
if (HIPGraphExec) {
72-
UR_CHECK_ERROR(hipGraphExecDestroy(HIPGraphExec));
72+
(void)hipGraphExecDestroy(HIPGraphExec);
7373
}
7474
}
7575

source/adapters/hip/command_buffer.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ struct ur_exp_command_buffer_handle_t_ {
254254
~ur_exp_command_buffer_handle_t_();
255255

256256
void registerSyncPoint(ur_exp_command_buffer_sync_point_t SyncPoint,
257-
std::shared_ptr<hipGraphNode_t> HIPNode) {
258-
SyncPoints[SyncPoint] = HIPNode;
257+
std::shared_ptr<hipGraphNode_t> &&HIPNode) {
258+
SyncPoints[SyncPoint] = std::move(HIPNode);
259259
NextSyncPoint++;
260260
}
261261

@@ -269,7 +269,7 @@ struct ur_exp_command_buffer_handle_t_ {
269269
ur_exp_command_buffer_sync_point_t
270270
addSyncPoint(std::shared_ptr<hipGraphNode_t> HIPNode) {
271271
ur_exp_command_buffer_sync_point_t SyncPoint = NextSyncPoint;
272-
registerSyncPoint(SyncPoint, HIPNode);
272+
registerSyncPoint(SyncPoint, std::move(HIPNode));
273273
return SyncPoint;
274274
}
275275
uint32_t incrementInternalReferenceCount() noexcept {

0 commit comments

Comments
 (0)