Skip to content

Commit

Permalink
[EXP][Command-Buffer] Fix CUDA Coverity issues
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EwanC committed Feb 14, 2024
1 parent c96e4ae commit d93d7a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions source/adapters/cuda/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ ur_exp_command_buffer_handle_t_::~ur_exp_command_buffer_handle_t_() {
ur_exp_command_buffer_command_handle_t_::
ur_exp_command_buffer_command_handle_t_(
ur_exp_command_buffer_handle_t CommandBuffer, ur_kernel_handle_t Kernel,
std::shared_ptr<CUgraphNode> Node, CUDA_KERNEL_NODE_PARAMS Params,
std::shared_ptr<CUgraphNode> &&Node, CUDA_KERNEL_NODE_PARAMS Params,
uint32_t WorkDim, const size_t *GlobalWorkOffsetPtr,
const size_t *GlobalWorkSizePtr, const size_t *LocalWorkSizePtr)
: CommandBuffer(CommandBuffer), Kernel(Kernel), Node(Node), Params(Params),
WorkDim(WorkDim), RefCountInternal(1), RefCountExternal(1) {
: CommandBuffer(CommandBuffer), Kernel(Kernel), Node{std::move(Node)},
Params(Params), WorkDim(WorkDim), RefCountInternal(1),
RefCountExternal(1) {
CommandBuffer->incrementInternalReferenceCount();

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

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

auto NewCommand = new ur_exp_command_buffer_command_handle_t_{
hCommandBuffer, hKernel, NodeSP, NodeParams,
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize};
hCommandBuffer, hKernel, std::move(NodeSP), NodeParams,
workDim, pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize};

NewCommand->incrementInternalReferenceCount();
hCommandBuffer->CommandHandles.push_back(NewCommand);
Expand Down
2 changes: 1 addition & 1 deletion source/adapters/cuda/command_buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ static inline const char *getUrResultString(ur_result_t Result) {
struct ur_exp_command_buffer_command_handle_t_ {
ur_exp_command_buffer_command_handle_t_(
ur_exp_command_buffer_handle_t CommandBuffer, ur_kernel_handle_t Kernel,
std::shared_ptr<CUgraphNode> Node, CUDA_KERNEL_NODE_PARAMS Params,
std::shared_ptr<CUgraphNode> &&Node, CUDA_KERNEL_NODE_PARAMS Params,
uint32_t WorkDim, const size_t *GlobalWorkOffsetPtr,
const size_t *GlobalWorkSizePtr, const size_t *LocalWorkSizePtr);

Expand Down

0 comments on commit d93d7a3

Please sign in to comment.