@@ -36,8 +36,8 @@ commandBufferDestroy(ur_exp_command_buffer_handle_t CommandBuffer) try {
3636 return Err;
3737}
3838
39- ur_result_t
40- commandHandleDestroy ( ur_exp_command_buffer_command_handle_t Command) try {
39+ ur_result_t commandHandleDestroy (
40+ std::unique_ptr<ur_exp_command_buffer_command_handle_t_> & Command) try {
4141 // We create the ur_event_t returned to the user for a signal node using
4242 // `makeWithNative` which sets `HasOwnership` to false. Therefore destruction
4343 // of the `ur_event_t` object doesn't free the underlying CuEvent_t object and
@@ -49,7 +49,6 @@ commandHandleDestroy(ur_exp_command_buffer_command_handle_t Command) try {
4949 UR_CHECK_ERROR (cuEventDestroy (SignalEvent));
5050 }
5151
52- delete Command;
5352 return UR_RESULT_SUCCESS;
5453} catch (ur_result_t Err) {
5554 return Err;
@@ -336,13 +335,14 @@ static ur_result_t enqueueCommandBufferFillHelper(
336335
337336 std::vector<CUgraphNode> WaitNodes =
338337 NumEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
339- auto NewCommand = new T (CommandBuffer, GraphNode, SignalNode, WaitNodes,
340- std::move (DecomposedNodes));
341- CommandBuffer->CommandHandles .push_back (NewCommand);
342-
338+ auto NewCommand = std::make_unique<T>(CommandBuffer, GraphNode, SignalNode,
339+ WaitNodes, std::move (DecomposedNodes));
343340 if (RetCommand) {
344- *RetCommand = NewCommand;
341+ *RetCommand = NewCommand. get () ;
345342 }
343+
344+ CommandBuffer->CommandHandles .push_back (std::move (NewCommand));
345+
346346 return UR_RESULT_SUCCESS;
347347} catch (ur_result_t Err) {
348348 return Err;
@@ -384,7 +384,7 @@ UR_APIEXPORT ur_result_t UR_APICALL
384384urCommandBufferReleaseExp (ur_exp_command_buffer_handle_t hCommandBuffer) {
385385 if (hCommandBuffer->decrementReferenceCount () == 0 ) {
386386 // Ref count has reached zero, release of created commands
387- for (auto Command : hCommandBuffer->CommandHandles ) {
387+ for (auto & Command : hCommandBuffer->CommandHandles ) {
388388 commandHandleDestroy (Command);
389389 }
390390
@@ -535,15 +535,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
535535
536536 std::vector<CUgraphNode> WaitNodes =
537537 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
538- auto NewCommand = new kernel_command_handle (
538+ auto NewCommand = std::make_unique< kernel_command_handle> (
539539 hCommandBuffer, hKernel, GraphNode, NodeParams, workDim,
540540 pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize,
541541 numKernelAlternatives, phKernelAlternatives, SignalNode, WaitNodes);
542- hCommandBuffer->CommandHandles .push_back (NewCommand);
543542
544543 if (phCommand) {
545- *phCommand = NewCommand;
544+ *phCommand = NewCommand. get () ;
546545 }
546+
547+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
547548 } catch (ur_result_t Err) {
548549 return Err;
549550 }
@@ -591,13 +592,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMMemcpyExp(
591592
592593 std::vector<CUgraphNode> WaitNodes =
593594 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
594- auto NewCommand = new usm_memcpy_command_handle (hCommandBuffer, GraphNode,
595- SignalNode, WaitNodes);
596- hCommandBuffer->CommandHandles .push_back (NewCommand);
597-
595+ auto NewCommand = std::make_unique<usm_memcpy_command_handle>(
596+ hCommandBuffer, GraphNode, SignalNode, WaitNodes);
598597 if (phCommand) {
599- *phCommand = NewCommand;
598+ *phCommand = NewCommand. get () ;
600599 }
600+
601+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
601602 return UR_RESULT_SUCCESS;
602603} catch (ur_result_t Err) {
603604 return Err;
@@ -656,13 +657,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp(
656657
657658 std::vector<CUgraphNode> WaitNodes =
658659 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
659- auto NewCommand = new buffer_copy_command_handle (hCommandBuffer, GraphNode,
660- SignalNode, WaitNodes);
661- hCommandBuffer->CommandHandles .push_back (NewCommand);
660+ auto NewCommand = std::make_unique<buffer_copy_command_handle>(
661+ hCommandBuffer, GraphNode, SignalNode, WaitNodes);
662662
663663 if (phCommand) {
664- *phCommand = NewCommand;
664+ *phCommand = NewCommand. get () ;
665665 }
666+
667+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
666668 return UR_RESULT_SUCCESS;
667669} catch (ur_result_t Err) {
668670 return Err;
@@ -718,13 +720,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp(
718720
719721 std::vector<CUgraphNode> WaitNodes =
720722 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
721- auto NewCommand = new buffer_copy_rect_command_handle (
723+ auto NewCommand = std::make_unique< buffer_copy_rect_command_handle> (
722724 hCommandBuffer, GraphNode, SignalNode, WaitNodes);
723- hCommandBuffer->CommandHandles .push_back (NewCommand);
724725
725726 if (phCommand) {
726- *phCommand = NewCommand;
727+ *phCommand = NewCommand. get () ;
727728 }
729+
730+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
728731 return UR_RESULT_SUCCESS;
729732} catch (ur_result_t Err) {
730733 return Err;
@@ -776,13 +779,13 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferWriteExp(
776779
777780 std::vector<CUgraphNode> WaitNodes =
778781 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
779- auto NewCommand = new buffer_write_command_handle (hCommandBuffer, GraphNode,
780- SignalNode, WaitNodes);
781- hCommandBuffer->CommandHandles .push_back (NewCommand);
782-
782+ auto NewCommand = std::make_unique<buffer_write_command_handle>(
783+ hCommandBuffer, GraphNode, SignalNode, WaitNodes);
783784 if (phCommand) {
784- *phCommand = NewCommand;
785+ *phCommand = NewCommand. get () ;
785786 }
787+
788+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
786789 return UR_RESULT_SUCCESS;
787790} catch (ur_result_t Err) {
788791 return Err;
@@ -833,13 +836,13 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferReadExp(
833836
834837 std::vector<CUgraphNode> WaitNodes =
835838 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
836- auto NewCommand = new buffer_read_command_handle (hCommandBuffer, GraphNode,
837- SignalNode, WaitNodes);
838- hCommandBuffer->CommandHandles .push_back (NewCommand);
839-
839+ auto NewCommand = std::make_unique<buffer_read_command_handle>(
840+ hCommandBuffer, GraphNode, SignalNode, WaitNodes);
840841 if (phCommand) {
841- *phCommand = NewCommand;
842+ *phCommand = NewCommand. get () ;
842843 }
844+
845+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
843846 return UR_RESULT_SUCCESS;
844847} catch (ur_result_t Err) {
845848 return Err;
@@ -894,13 +897,14 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferWriteRectExp(
894897
895898 std::vector<CUgraphNode> WaitNodes =
896899 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
897- auto NewCommand = new buffer_write_rect_command_handle (
900+ auto NewCommand = std::make_unique< buffer_write_rect_command_handle> (
898901 hCommandBuffer, GraphNode, SignalNode, WaitNodes);
899- hCommandBuffer->CommandHandles .push_back (NewCommand);
900902
901903 if (phCommand) {
902- *phCommand = NewCommand;
904+ *phCommand = NewCommand. get () ;
903905 }
906+
907+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
904908 return UR_RESULT_SUCCESS;
905909} catch (ur_result_t Err) {
906910 return Err;
@@ -955,13 +959,14 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferReadRectExp(
955959
956960 std::vector<CUgraphNode> WaitNodes =
957961 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
958- auto NewCommand = new buffer_read_rect_command_handle (
962+ auto NewCommand = std::make_unique< buffer_read_rect_command_handle> (
959963 hCommandBuffer, GraphNode, SignalNode, WaitNodes);
960- hCommandBuffer->CommandHandles .push_back (NewCommand);
961964
962965 if (phCommand) {
963- *phCommand = NewCommand;
966+ *phCommand = NewCommand. get () ;
964967 }
968+
969+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
965970 return UR_RESULT_SUCCESS;
966971} catch (ur_result_t Err) {
967972 return Err;
@@ -1008,13 +1013,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMPrefetchExp(
10081013
10091014 std::vector<CUgraphNode> WaitNodes =
10101015 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
1011- auto NewCommand = new usm_prefetch_command_handle (hCommandBuffer, GraphNode,
1012- SignalNode, WaitNodes);
1013- hCommandBuffer->CommandHandles .push_back (NewCommand);
1016+ auto NewCommand = std::make_unique<usm_prefetch_command_handle>(
1017+ hCommandBuffer, GraphNode, SignalNode, WaitNodes);
10141018
10151019 if (phCommand) {
1016- *phCommand = NewCommand;
1020+ *phCommand = NewCommand. get () ;
10171021 }
1022+
1023+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
10181024 return UR_RESULT_SUCCESS;
10191025} catch (ur_result_t Err) {
10201026 return Err;
@@ -1061,14 +1067,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMAdviseExp(
10611067
10621068 std::vector<CUgraphNode> WaitNodes =
10631069 numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
1064- auto NewCommand = new usm_advise_command_handle (hCommandBuffer, GraphNode,
1065- SignalNode, WaitNodes);
1066- hCommandBuffer->CommandHandles .push_back (NewCommand);
1070+ auto NewCommand = std::make_unique<usm_advise_command_handle>(
1071+ hCommandBuffer, GraphNode, SignalNode, WaitNodes);
10671072
10681073 if (phCommand) {
1069- *phCommand = NewCommand;
1074+ *phCommand = NewCommand. get () ;
10701075 }
10711076
1077+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
1078+
10721079 return UR_RESULT_SUCCESS;
10731080} catch (ur_result_t Err) {
10741081 return Err;
0 commit comments