Skip to content

Commit 55ec3e9

Browse files
committed
[EXP][Command-Buffer] Fix CUDA Coverity issues
Address issues in the CUDA adapter code added by oneapi-src#1089 flagged by Coverity. * Uninitalized struct member of `CUDA_KERNEL_NODE_PARAMS` struct * copying instead of moving a shared pointer to a node when constructing a command-handle.
1 parent 227a5ed commit 55ec3e9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

source/adapters/cuda/command_buffer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
7272
ur_exp_command_buffer_command_handle_t_::
7373
ur_exp_command_buffer_command_handle_t_(
7474
ur_exp_command_buffer_handle_t CommandBuffer, ur_kernel_handle_t Kernel,
75-
std::shared_ptr<CUgraphNode> Node, CUDA_KERNEL_NODE_PARAMS Params,
75+
std::shared_ptr<CUgraphNode> &&Node, CUDA_KERNEL_NODE_PARAMS Params,
7676
uint32_t WorkDim, const size_t *GlobalWorkOffsetPtr,
7777
const size_t *GlobalWorkSizePtr, const size_t *LocalWorkSizePtr)
78-
: CommandBuffer(CommandBuffer), Kernel(Kernel), Node(Node), Params(Params),
79-
WorkDim(WorkDim), RefCountInternal(1), RefCountExternal(1) {
78+
: CommandBuffer(CommandBuffer), Kernel(Kernel), Node{std::move(Node)},
79+
Params(Params), WorkDim(WorkDim), RefCountInternal(1),
80+
RefCountExternal(1) {
8081
CommandBuffer->incrementInternalReferenceCount();
8182

8283
const size_t CopySize = sizeof(size_t) * WorkDim;
@@ -375,6 +376,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
375376
NodeParams.blockDimZ = ThreadsPerBlock[2];
376377
NodeParams.sharedMemBytes = LocalSize;
377378
NodeParams.kernelParams = const_cast<void **>(ArgIndices.data());
379+
NodeParams.kern = nullptr;
378380
NodeParams.extra = nullptr;
379381

380382
// Create and add an new kernel node to the Cuda graph
@@ -392,8 +394,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
392394
}
393395

394396
auto NewCommand = new ur_exp_command_buffer_command_handle_t_{
395-
hCommandBuffer, hKernel, NodeSP, NodeParams,
396-
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize};
397+
hCommandBuffer, hKernel, std::move(NodeSP), NodeParams,
398+
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize};
397399

398400
NewCommand->incrementInternalReferenceCount();
399401
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

0 commit comments

Comments
 (0)