Skip to content

Commit b6501db

Browse files
author
bragadeesh
committed
fixing event leak bug that affects gtest unit tests; was identified by OS X team when running on Mac
1 parent b0d70b3 commit b6501db

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/tests/cl_transform.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class clfft {
151151
// OpenCL resources that need to be carefully managed
152152
std::unique_ptr< _cl_context, clContext_deleter > context;
153153
std::unique_ptr< _cl_command_queue, clCommQueue_deleter > queue;
154-
std::unique_ptr< _cl_event, clEvent_deleter > an_event;
155154
std::vector< std::unique_ptr< _cl_mem, clMem_deleter > > cl_mem_input;
156155
std::vector< std::unique_ptr< _cl_mem, clMem_deleter > > cl_mem_output;
157156
std::vector< cl_device_id > device_id;
@@ -630,7 +629,6 @@ class clfft {
630629

631630
// In order to call clfftEnqueueTransform, we need to pass naked pointers
632631
cl_command_queue tempQueue = queue.get( );
633-
cl_event tempEvent = an_event.get( );
634632
size_t buffer_size = 0;
635633

636634
EXPECT_EQ( CLFFT_SUCCESS, clfftBakePlan(*plan_handle, 1, &tempQueue, NULL, NULL ));
@@ -683,7 +681,7 @@ class clfft {
683681

684682
// In order to call clfftEnqueueTransform, we need to pass naked pointers
685683
cl_command_queue tempQueue = queue.get( );
686-
cl_event tempEvent = an_event.get( );
684+
std::unique_ptr< _cl_event, clEvent_deleter > tempEvent;
687685
std::unique_ptr< _cl_mem, clMem_deleter > intermediate_buffer;
688686

689687
throw_if_total_memory_footprint_is_too_large_for_device();
@@ -726,6 +724,7 @@ class clfft {
726724
for( cl_uint i = 0; i < cl_mem_output.size( ); ++i )
727725
tempOutput[ i ] = cl_mem_output[ i ].get( );
728726

727+
cl_event tevent = NULL;
729728
if( buffer_size )
730729
{
731730
status = clfftEnqueueTransform(*plan_handle,
@@ -734,7 +733,7 @@ class clfft {
734733
&tempQueue,
735734
0,
736735
NULL,
737-
&tempEvent,
736+
&tevent,
738737
&tempInput[ 0 ],
739738
&tempOutput[ 0 ],
740739
intermediate_buffer.get() );
@@ -747,24 +746,26 @@ class clfft {
747746
&tempQueue,
748747
0,
749748
NULL,
750-
&tempEvent,
749+
&tevent,
751750
&tempInput[ 0 ],
752751
&tempOutput[ 0 ],
753752
NULL );
754753
}
755754
clFinish(tempQueue);
755+
tempEvent.reset(tevent); tevent = NULL;
756756

757757
if( status != CLFFT_SUCCESS )
758758
{
759759
throw std::runtime_error(prettyPrintclFFTStatus(status).c_str());
760760
}
761761

762762
// wait for the kernel call to finish execution
763-
cl_int wait_status = clWaitForEvents(1, &tempEvent);
763+
const cl_event revent = tempEvent.get();
764+
cl_int wait_status = clWaitForEvents(1, &revent);
764765
if( wait_status == CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST )
765766
{
766767
cl_int error_code;
767-
clGetEventInfo( tempEvent, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &error_code, NULL );
768+
clGetEventInfo( revent, CL_EVENT_COMMAND_EXECUTION_STATUS, sizeof(cl_int), &error_code, NULL );
768769
throw std::runtime_error(prettyPrintclFFTStatus(error_code).c_str());
769770
}
770771
else if( wait_status != CL_SUCCESS )

0 commit comments

Comments
 (0)