@@ -36,8 +36,8 @@ commandBufferDestroy(ur_exp_command_buffer_handle_t CommandBuffer) try {
36
36
return Err;
37
37
}
38
38
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 {
41
41
// We create the ur_event_t returned to the user for a signal node using
42
42
// `makeWithNative` which sets `HasOwnership` to false. Therefore destruction
43
43
// 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 {
49
49
UR_CHECK_ERROR (cuEventDestroy (SignalEvent));
50
50
}
51
51
52
- delete Command;
53
52
return UR_RESULT_SUCCESS;
54
53
} catch (ur_result_t Err) {
55
54
return Err;
@@ -336,13 +335,14 @@ static ur_result_t enqueueCommandBufferFillHelper(
336
335
337
336
std::vector<CUgraphNode> WaitNodes =
338
337
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));
343
340
if (RetCommand) {
344
- *RetCommand = NewCommand;
341
+ *RetCommand = NewCommand. get () ;
345
342
}
343
+
344
+ CommandBuffer->CommandHandles .push_back (std::move (NewCommand));
345
+
346
346
return UR_RESULT_SUCCESS;
347
347
} catch (ur_result_t Err) {
348
348
return Err;
@@ -384,7 +384,7 @@ UR_APIEXPORT ur_result_t UR_APICALL
384
384
urCommandBufferReleaseExp (ur_exp_command_buffer_handle_t hCommandBuffer) {
385
385
if (hCommandBuffer->decrementReferenceCount () == 0 ) {
386
386
// Ref count has reached zero, release of created commands
387
- for (auto Command : hCommandBuffer->CommandHandles ) {
387
+ for (auto & Command : hCommandBuffer->CommandHandles ) {
388
388
commandHandleDestroy (Command);
389
389
}
390
390
@@ -535,15 +535,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendKernelLaunchExp(
535
535
536
536
std::vector<CUgraphNode> WaitNodes =
537
537
numEventsInWaitList ? std::move (DepsList) : std::vector<CUgraphNode>();
538
- auto NewCommand = new kernel_command_handle (
538
+ auto NewCommand = std::make_unique< kernel_command_handle> (
539
539
hCommandBuffer, hKernel, GraphNode, NodeParams, workDim,
540
540
pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize,
541
541
numKernelAlternatives, phKernelAlternatives, SignalNode, WaitNodes);
542
- hCommandBuffer->CommandHandles .push_back (NewCommand);
543
542
544
543
if (phCommand) {
545
- *phCommand = NewCommand;
544
+ *phCommand = NewCommand. get () ;
546
545
}
546
+
547
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
547
548
} catch (ur_result_t Err) {
548
549
return Err;
549
550
}
@@ -591,13 +592,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMMemcpyExp(
591
592
592
593
std::vector<CUgraphNode> WaitNodes =
593
594
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);
598
597
if (phCommand) {
599
- *phCommand = NewCommand;
598
+ *phCommand = NewCommand. get () ;
600
599
}
600
+
601
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
601
602
return UR_RESULT_SUCCESS;
602
603
} catch (ur_result_t Err) {
603
604
return Err;
@@ -656,13 +657,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyExp(
656
657
657
658
std::vector<CUgraphNode> WaitNodes =
658
659
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);
662
662
663
663
if (phCommand) {
664
- *phCommand = NewCommand;
664
+ *phCommand = NewCommand. get () ;
665
665
}
666
+
667
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
666
668
return UR_RESULT_SUCCESS;
667
669
} catch (ur_result_t Err) {
668
670
return Err;
@@ -718,13 +720,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendMemBufferCopyRectExp(
718
720
719
721
std::vector<CUgraphNode> WaitNodes =
720
722
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> (
722
724
hCommandBuffer, GraphNode, SignalNode, WaitNodes);
723
- hCommandBuffer->CommandHandles .push_back (NewCommand);
724
725
725
726
if (phCommand) {
726
- *phCommand = NewCommand;
727
+ *phCommand = NewCommand. get () ;
727
728
}
729
+
730
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
728
731
return UR_RESULT_SUCCESS;
729
732
} catch (ur_result_t Err) {
730
733
return Err;
@@ -776,13 +779,13 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferWriteExp(
776
779
777
780
std::vector<CUgraphNode> WaitNodes =
778
781
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);
783
784
if (phCommand) {
784
- *phCommand = NewCommand;
785
+ *phCommand = NewCommand. get () ;
785
786
}
787
+
788
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
786
789
return UR_RESULT_SUCCESS;
787
790
} catch (ur_result_t Err) {
788
791
return Err;
@@ -833,13 +836,13 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferReadExp(
833
836
834
837
std::vector<CUgraphNode> WaitNodes =
835
838
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);
840
841
if (phCommand) {
841
- *phCommand = NewCommand;
842
+ *phCommand = NewCommand. get () ;
842
843
}
844
+
845
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
843
846
return UR_RESULT_SUCCESS;
844
847
} catch (ur_result_t Err) {
845
848
return Err;
@@ -894,13 +897,14 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferWriteRectExp(
894
897
895
898
std::vector<CUgraphNode> WaitNodes =
896
899
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> (
898
901
hCommandBuffer, GraphNode, SignalNode, WaitNodes);
899
- hCommandBuffer->CommandHandles .push_back (NewCommand);
900
902
901
903
if (phCommand) {
902
- *phCommand = NewCommand;
904
+ *phCommand = NewCommand. get () ;
903
905
}
906
+
907
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
904
908
return UR_RESULT_SUCCESS;
905
909
} catch (ur_result_t Err) {
906
910
return Err;
@@ -955,13 +959,14 @@ ur_result_t UR_APICALL urCommandBufferAppendMemBufferReadRectExp(
955
959
956
960
std::vector<CUgraphNode> WaitNodes =
957
961
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> (
959
963
hCommandBuffer, GraphNode, SignalNode, WaitNodes);
960
- hCommandBuffer->CommandHandles .push_back (NewCommand);
961
964
962
965
if (phCommand) {
963
- *phCommand = NewCommand;
966
+ *phCommand = NewCommand. get () ;
964
967
}
968
+
969
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
965
970
return UR_RESULT_SUCCESS;
966
971
} catch (ur_result_t Err) {
967
972
return Err;
@@ -1008,13 +1013,14 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMPrefetchExp(
1008
1013
1009
1014
std::vector<CUgraphNode> WaitNodes =
1010
1015
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);
1014
1018
1015
1019
if (phCommand) {
1016
- *phCommand = NewCommand;
1020
+ *phCommand = NewCommand. get () ;
1017
1021
}
1022
+
1023
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
1018
1024
return UR_RESULT_SUCCESS;
1019
1025
} catch (ur_result_t Err) {
1020
1026
return Err;
@@ -1061,14 +1067,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferAppendUSMAdviseExp(
1061
1067
1062
1068
std::vector<CUgraphNode> WaitNodes =
1063
1069
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);
1067
1072
1068
1073
if (phCommand) {
1069
- *phCommand = NewCommand;
1074
+ *phCommand = NewCommand. get () ;
1070
1075
}
1071
1076
1077
+ hCommandBuffer->CommandHandles .push_back (std::move (NewCommand));
1078
+
1072
1079
return UR_RESULT_SUCCESS;
1073
1080
} catch (ur_result_t Err) {
1074
1081
return Err;
0 commit comments