From ff5ebc1d014258b80555aba81f270f05de7803ff Mon Sep 17 00:00:00 2001 From: omarahmed1111 Date: Thu, 14 Dec 2023 10:44:10 +0000 Subject: [PATCH] Use unique_ptr instead of new to auto handle memory allocations --- source/adapters/opencl/command_buffer.cpp | 4 +- source/adapters/opencl/context.cpp | 9 ++- source/adapters/opencl/device.cpp | 11 ++-- source/adapters/opencl/enqueue.cpp | 80 +++++++++++++++++------ source/adapters/opencl/event.cpp | 4 +- source/adapters/opencl/memory.cpp | 15 +++-- source/adapters/opencl/platform.cpp | 10 +-- source/adapters/opencl/platform.hpp | 7 +- source/adapters/opencl/program.cpp | 23 +++++-- source/adapters/opencl/queue.cpp | 11 +++- source/adapters/opencl/sampler.cpp | 7 +- source/adapters/opencl/usm.cpp | 24 +++++-- 12 files changed, 147 insertions(+), 58 deletions(-) diff --git a/source/adapters/opencl/command_buffer.cpp b/source/adapters/opencl/command_buffer.cpp index 79db8b88a0..d015548f01 100644 --- a/source/adapters/opencl/command_buffer.cpp +++ b/source/adapters/opencl/command_buffer.cpp @@ -324,7 +324,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urCommandBufferEnqueueExp( NumberOfQueues, &CLQueue, hCommandBuffer->CLCommandBuffer, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/context.cpp b/source/adapters/opencl/context.cpp index 07207009f9..5dc18dc49e 100644 --- a/source/adapters/opencl/context.cpp +++ b/source/adapters/opencl/context.cpp @@ -45,8 +45,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreate( cl_context Ctx = clCreateContext( nullptr, cl_adapter::cast(DeviceCount), CLDevices.data(), nullptr, nullptr, cl_adapter::cast(&Ret)); - - *phContext = new ur_context_handle_t_(Ctx, DeviceCount, phDevices); + auto URContext = + std::make_unique(Ctx, DeviceCount, phDevices); + *phContext = URContext.release(); return mapCLErrorToUR(Ret); } @@ -142,7 +143,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle( ur_context_handle_t *phContext) { cl_context NativeHandle = reinterpret_cast(hNativeContext); - *phContext = new ur_context_handle_t_(NativeHandle, numDevices, phDevices); + auto URContext = std::make_unique( + NativeHandle, numDevices, phDevices); + *phContext = URContext.release(); return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/device.cpp b/source/adapters/opencl/device.cpp index 629e205b1a..e4520bb882 100644 --- a/source/adapters/opencl/device.cpp +++ b/source/adapters/opencl/device.cpp @@ -86,7 +86,7 @@ urDeviceGet(ur_platform_handle_t hPlatform, ur_device_type_t DeviceType, cl_device_type DeviceType = hPlatform->Devices[i]->Type; if (DeviceType == Type || Type == CL_DEVICE_TYPE_ALL) { if (phDevices) { - phDevices[DeviceNumIter] = hPlatform->Devices[i]; + phDevices[DeviceNumIter] = hPlatform->Devices[i].get(); } DeviceNumIter++; } @@ -999,8 +999,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDevicePartition( CLNumDevicesRet, CLSubDevices.data(), nullptr)); for (uint32_t i = 0; i < NumDevices; i++) { - phSubDevices[i] = - new ur_device_handle_t_(CLSubDevices[i], hDevice->Platform, hDevice); + auto URSubDevice = std::make_unique( + CLSubDevices[i], hDevice->Platform, hDevice); + phSubDevices[i] = URSubDevice.release(); } } @@ -1033,7 +1034,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceCreateWithNativeHandle( ur_native_handle_t hNativeDevice, ur_platform_handle_t hPlatform, const ur_device_native_properties_t *, ur_device_handle_t *phDevice) { cl_device_id NativeHandle = reinterpret_cast(hNativeDevice); - *phDevice = new ur_device_handle_t_(NativeHandle, hPlatform, nullptr); + auto URDevice = + std::make_unique(NativeHandle, hPlatform, nullptr); + *phDevice = URDevice.release(); return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/enqueue.cpp b/source/adapters/opencl/enqueue.cpp index 0da75663a5..13e952d1a4 100644 --- a/source/adapters/opencl/enqueue.cpp +++ b/source/adapters/opencl/enqueue.cpp @@ -45,7 +45,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueKernelLaunch( pGlobalWorkOffset, pGlobalWorkSize, pLocalWorkSize, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -61,7 +63,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWait( CL_RETURN_ON_FAILURE(clEnqueueMarkerWithWaitList( hQueue->get(), numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -77,7 +81,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueEventsWaitWithBarrier( CL_RETURN_ON_FAILURE(clEnqueueBarrierWithWaitList( hQueue->get(), numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -95,7 +101,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferRead( hQueue->get(), hBuffer->get(), blockingRead, offset, size, pDst, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -113,7 +121,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferWrite( hQueue->get(), hBuffer->get(), blockingWrite, offset, size, pSrc, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -139,7 +149,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferReadRect( Region, bufferRowPitch, bufferSlicePitch, hostRowPitch, hostSlicePitch, pDst, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -165,7 +177,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferWriteRect( Region, bufferRowPitch, bufferSlicePitch, hostRowPitch, hostSlicePitch, pSrc, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -184,7 +198,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferCopy( hQueue->get(), hBufferSrc->get(), hBufferDst->get(), srcOffset, dstOffset, size, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -209,7 +225,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferCopyRect( Region, srcRowPitch, srcSlicePitch, dstRowPitch, dstSlicePitch, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -231,7 +249,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferFill( hQueue->get(), hBuffer->get(), pPattern, patternSize, offset, size, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -271,7 +291,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferFill( } if (phEvent) { - *phEvent = new ur_event_handle_t_(WriteEvent, hQueue->Context, hQueue); + auto UREvent = std::make_unique( + WriteEvent, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } else { CL_RETURN_ON_FAILURE(clReleaseEvent(WriteEvent)); } @@ -295,7 +317,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead( hQueue->get(), hImage->get(), blockingRead, Origin, Region, rowPitch, slicePitch, pDst, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -316,7 +340,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite( hQueue->get(), hImage->get(), blockingWrite, Origin, Region, rowPitch, slicePitch, pSrc, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -339,7 +365,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy( hQueue->get(), hImageSrc->get(), hImageDst->get(), SrcOrigin, DstOrigin, Region, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -360,7 +388,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemBufferMap( numEventsInWaitList, CLWaitEvents.data(), &Event, &Err); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return mapCLErrorToUR(Err); } @@ -378,7 +408,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemUnmap( pMappedPtr, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -406,7 +438,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableWrite( Res = F(hQueue->get(), hProgram->get(), name, blockingWrite, count, offset, pSrc, numEventsInWaitList, CLWaitEvents.data(), &Event); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return mapCLErrorToUR(Res); } @@ -434,7 +468,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueDeviceGlobalVariableRead( Res = F(hQueue->get(), hProgram->get(), name, blockingRead, count, offset, pDst, numEventsInWaitList, CLWaitEvents.data(), &Event); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return mapCLErrorToUR(Res); } @@ -463,7 +499,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueReadHostPipe( blocking, pDst, size, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } } @@ -494,7 +532,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueWriteHostPipe( blocking, pSrc, size, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } } diff --git a/source/adapters/opencl/event.cpp b/source/adapters/opencl/event.cpp index 5e1d2fabe4..a41561f06c 100644 --- a/source/adapters/opencl/event.cpp +++ b/source/adapters/opencl/event.cpp @@ -115,7 +115,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEventCreateWithNativeHandle( const ur_event_native_properties_t *pProperties, ur_event_handle_t *phEvent) { cl_event NativeHandle = reinterpret_cast(hNativeEvent); - *phEvent = new ur_event_handle_t_(NativeHandle, hContext, nullptr); + auto UREvent = + std::make_unique(NativeHandle, hContext, nullptr); + *phEvent = UREvent.release(); if (!pProperties || !pProperties->isNativeHandleOwned) { return urEventRetain(*phEvent); } diff --git a/source/adapters/opencl/memory.cpp b/source/adapters/opencl/memory.cpp index 0d3fecd305..e1e7f12f70 100644 --- a/source/adapters/opencl/memory.cpp +++ b/source/adapters/opencl/memory.cpp @@ -266,7 +266,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate( cl_mem Buffer = FuncPtr( CLContext, PropertiesIntel.data(), static_cast(flags), size, pProperties->pHost, cl_adapter::cast(&RetErr)); - *phBuffer = new ur_mem_handle_t_(Buffer, hContext); + auto URMem = std::make_unique(Buffer, hContext); + *phBuffer = URMem.release(); return mapCLErrorToUR(RetErr); } } @@ -276,7 +277,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreate( clCreateBuffer(hContext->get(), static_cast(flags), size, HostPtr, cl_adapter::cast(&RetErr)); CL_RETURN_ON_FAILURE(RetErr); - *phBuffer = new ur_mem_handle_t_(Buffer, hContext); + auto URMem = std::make_unique(Buffer, hContext); + *phBuffer = URMem.release(); return UR_RESULT_SUCCESS; } @@ -296,7 +298,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreate( clCreateImage(hContext->get(), MapFlags, &ImageFormat, &ImageDesc, pHost, cl_adapter::cast(&RetErr)); CL_RETURN_ON_FAILURE(RetErr); - *phMem = new ur_mem_handle_t_(Mem, hContext); + auto URMem = std::make_unique(Mem, hContext); + *phMem = URMem.release(); return UR_RESULT_SUCCESS; } @@ -344,7 +347,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle( ur_native_handle_t hNativeMem, ur_context_handle_t hContext, const ur_mem_native_properties_t *pProperties, ur_mem_handle_t *phMem) { cl_mem NativeHandle = reinterpret_cast(hNativeMem); - *phMem = new ur_mem_handle_t_(NativeHandle, hContext); + auto URMem = std::make_unique(NativeHandle, hContext); + *phMem = URMem.release(); if (!pProperties || !pProperties->isNativeHandleOwned) { return urMemRetain(*phMem); } @@ -357,7 +361,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemImageCreateWithNativeHandle( [[maybe_unused]] const ur_image_desc_t *pImageDesc, const ur_mem_native_properties_t *pProperties, ur_mem_handle_t *phMem) { cl_mem NativeHandle = reinterpret_cast(hNativeMem); - *phMem = new ur_mem_handle_t_(NativeHandle, hContext); + auto URMem = std::make_unique(NativeHandle, hContext); + *phMem = URMem.release(); if (!pProperties || !pProperties->isNativeHandleOwned) { return urMemRetain(*phMem); } diff --git a/source/adapters/opencl/platform.cpp b/source/adapters/opencl/platform.cpp index 2526c14a51..89bb16d7e9 100644 --- a/source/adapters/opencl/platform.cpp +++ b/source/adapters/opencl/platform.cpp @@ -87,7 +87,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries, ur_platform_handle_t *phPlatforms, uint32_t *pNumPlatforms) { - static std::vector URPlatforms; + static std::vector> URPlatforms; static std::once_flag InitFlag; static uint32_t NumPlatforms = 0; cl_int Result = CL_SUCCESS; @@ -107,7 +107,8 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries, } URPlatforms.resize(NumPlatforms); for (uint32_t i = 0; i < NumPlatforms; i++) { - URPlatforms[i] = new ur_platform_handle_t_(CLPlatforms[i]); + URPlatforms[i] = + std::make_unique(CLPlatforms[i]); } return Result; }, @@ -125,7 +126,7 @@ urPlatformGet(ur_adapter_handle_t *, uint32_t, uint32_t NumEntries, } if (NumEntries && phPlatforms) { for (uint32_t i = 0; i < NumEntries; i++) { - phPlatforms[i] = URPlatforms[i]; + phPlatforms[i] = URPlatforms[i].get(); } } return mapCLErrorToUR(Result); @@ -142,7 +143,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urPlatformCreateWithNativeHandle( ur_platform_handle_t *phPlatform) { cl_platform_id NativeHandle = reinterpret_cast(hNativePlatform); - *phPlatform = new ur_platform_handle_t_(NativeHandle); + auto URPlatform = std::make_unique(NativeHandle); + *phPlatform = URPlatform.release(); return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/platform.hpp b/source/adapters/opencl/platform.hpp index 667b998970..5939545707 100644 --- a/source/adapters/opencl/platform.hpp +++ b/source/adapters/opencl/platform.hpp @@ -175,7 +175,7 @@ struct ur_platform_handle_t_ { using native_type = cl_platform_id; native_type Platform = nullptr; std::unique_ptr ExtFuncPtr; - std::vector Devices; + std::vector> Devices; ur_platform_handle_t_(native_type Plat) : Platform(Plat) { ExtFuncPtr = std::make_unique(); @@ -209,9 +209,10 @@ struct ur_platform_handle_t_ { CL_RETURN_ON_FAILURE(clGetDeviceIDs(Platform, CL_DEVICE_TYPE_ALL, DeviceNum, CLDevices.data(), nullptr)); - Devices = std::vector(DeviceNum); + Devices.resize(DeviceNum); for (size_t i = 0; i < DeviceNum; i++) { - Devices[i] = new ur_device_handle_t_(CLDevices[i], this, nullptr); + Devices[i] = + std::make_unique(CLDevices[i], this, nullptr); } return UR_RESULT_SUCCESS; diff --git a/source/adapters/opencl/program.cpp b/source/adapters/opencl/program.cpp index 07b2841d91..858add97b4 100644 --- a/source/adapters/opencl/program.cpp +++ b/source/adapters/opencl/program.cpp @@ -72,8 +72,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL( cl_program Program = clCreateProgramWithIL(hContext->get(), pIL, length, &Err); CL_RETURN_ON_FAILURE(Err); - - *phProgram = new ur_program_handle_t_(Program, hContext); + auto URProgram = std::make_unique(Program, hContext); + *phProgram = URProgram.release(); } else { /* If none of the devices conform with CL 2.1 or newer make sure they all @@ -100,7 +100,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithIL( assert(FuncPtr != nullptr); cl_program Program = FuncPtr(hContext->get(), pIL, length, &Err); - *phProgram = new ur_program_handle_t_(Program, hContext); + auto URProgram = std::make_unique(Program, hContext); + *phProgram = URProgram.release(); CL_RETURN_ON_FAILURE(Err); } @@ -120,7 +121,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithBinary( cl_program Program = clCreateProgramWithBinary( hContext->get(), cl_adapter::cast(1u), Devices, Lengths, &pBinary, BinaryStatus, &CLResult); - *phProgram = new ur_program_handle_t_(Program, hContext); + + auto URProgram = std::make_unique(Program, hContext); + *phProgram = URProgram.release(); CL_RETURN_ON_FAILURE(BinaryStatus[0]); CL_RETURN_ON_FAILURE(CLResult); @@ -186,6 +189,10 @@ urProgramGetInfo(ur_program_handle_t hProgram, ur_program_info_t propName, cl_uint DeviceCount = hProgram->Context->DeviceCount; return ReturnValue(DeviceCount); } + case UR_PROGRAM_INFO_DEVICES: { + return ReturnValue(&hProgram->Context->Devices[0], + hProgram->Context->DeviceCount); + } default: { size_t CheckPropSize = 0; auto ClResult = clGetProgramInfo(hProgram->get(), CLPropName, propSize, @@ -230,7 +237,8 @@ urProgramLink(ur_context_handle_t hContext, uint32_t count, hContext->get(), 0, nullptr, pOptions, cl_adapter::cast(count), CLPrograms.data(), nullptr, nullptr, &CLResult); CL_RETURN_ON_FAILURE(CLResult); - *phProgram = new ur_program_handle_t_(Program, hContext); + auto URProgram = std::make_unique(Program, hContext); + *phProgram = URProgram.release(); return UR_RESULT_SUCCESS; } @@ -340,7 +348,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urProgramCreateWithNativeHandle( const ur_program_native_properties_t *pProperties, ur_program_handle_t *phProgram) { cl_program NativeHandle = reinterpret_cast(hNativeProgram); - *phProgram = new ur_program_handle_t_(NativeHandle, hContext); + + auto URProgram = + std::make_unique(NativeHandle, hContext); + *phProgram = URProgram.release(); if (!pProperties || !pProperties->isNativeHandleOwned) { return urProgramRetain(*phProgram); } diff --git a/source/adapters/opencl/queue.cpp b/source/adapters/opencl/queue.cpp index 41ff096acc..477bcb2015 100644 --- a/source/adapters/opencl/queue.cpp +++ b/source/adapters/opencl/queue.cpp @@ -95,7 +95,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate( clCreateCommandQueue(hContext->get(), hDevice->get(), CLProperties & SupportByOpenCL, &RetErr); CL_RETURN_ON_FAILURE(RetErr); - *phQueue = new ur_queue_handle_t_(Queue, hContext, hDevice); + auto URQueue = + std::make_unique(Queue, hContext, hDevice); + *phQueue = URQueue.release(); return UR_RESULT_SUCCESS; } @@ -105,7 +107,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreate( cl_command_queue Queue = clCreateCommandQueueWithProperties( hContext->get(), hDevice->get(), CreationFlagProperties, &RetErr); CL_RETURN_ON_FAILURE(RetErr); - *phQueue = new ur_queue_handle_t_(Queue, hContext, hDevice); + auto URQueue = std::make_unique(Queue, hContext, hDevice); + *phQueue = URQueue.release(); return UR_RESULT_SUCCESS; } @@ -167,7 +170,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urQueueCreateWithNativeHandle( cl_command_queue NativeHandle = reinterpret_cast(hNativeQueue); - *phQueue = new ur_queue_handle_t_(NativeHandle, hContext, hDevice); + auto URQueue = + std::make_unique(NativeHandle, hContext, hDevice); + *phQueue = URQueue.release(); cl_int RetErr = clRetainCommandQueue(cl_adapter::cast(hNativeQueue)); diff --git a/source/adapters/opencl/sampler.cpp b/source/adapters/opencl/sampler.cpp index 51457535ec..6a59fe7eaf 100644 --- a/source/adapters/opencl/sampler.cpp +++ b/source/adapters/opencl/sampler.cpp @@ -148,7 +148,8 @@ ur_result_t urSamplerCreate(ur_context_handle_t hContext, cl_sampler Sampler = clCreateSampler( hContext->get(), static_cast(pDesc->normalizedCoords), AddressingMode, FilterMode, cl_adapter::cast(&ErrorCode)); - *phSampler = new ur_sampler_handle_t_(Sampler, hContext); + auto URSampler = std::make_unique(Sampler, hContext); + *phSampler = URSampler.release(); return mapCLErrorToUR(ErrorCode); } @@ -200,6 +201,8 @@ UR_APIEXPORT ur_result_t UR_APICALL urSamplerCreateWithNativeHandle( ur_native_handle_t hNativeSampler, ur_context_handle_t hContext, const ur_sampler_native_properties_t *, ur_sampler_handle_t *phSampler) { cl_sampler NativeHandle = reinterpret_cast(hNativeSampler); - *phSampler = new ur_sampler_handle_t_(NativeHandle, hContext); + auto URSampler = + std::make_unique(NativeHandle, hContext); + *phSampler = URSampler.release(); return UR_RESULT_SUCCESS; } diff --git a/source/adapters/opencl/usm.cpp b/source/adapters/opencl/usm.cpp index 684004e126..7ad7e825d8 100644 --- a/source/adapters/opencl/usm.cpp +++ b/source/adapters/opencl/usm.cpp @@ -252,7 +252,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill( patternSize, size, numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; } @@ -326,7 +328,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill( CL_RETURN_ON_FAILURE(ClErr); } if (phEvent) { - *phEvent = new ur_event_handle_t_(CopyEvent, hQueue->Context, hQueue); + auto UREvent = std::make_unique( + CopyEvent, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } else { CL_RETURN_ON_FAILURE(clReleaseEvent(CopyEvent)); } @@ -357,7 +361,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemcpy( numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } } @@ -378,7 +384,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch( CL_RETURN_ON_FAILURE(clEnqueueMarkerWithWaitList( hQueue->get(), numEventsInWaitList, CLWaitEvents.data(), &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; /* @@ -411,7 +419,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMAdvise( CL_RETURN_ON_FAILURE( clEnqueueMarkerWithWaitList(hQueue->get(), 0, nullptr, &Event)); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } return UR_RESULT_SUCCESS; /* @@ -491,7 +501,9 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemcpy2D( ClResult = clEnqueueBarrierWithWaitList(hQueue->get(), Events.size(), Events.data(), &Event); if (phEvent) { - *phEvent = new ur_event_handle_t_(Event, hQueue->Context, hQueue); + auto UREvent = + std::make_unique(Event, hQueue->Context, hQueue); + *phEvent = UREvent.release(); } } for (const auto &E : Events) {