Skip to content

Commit

Permalink
refactor: migration to std::make_unique C++17
Browse files Browse the repository at this point in the history
  • Loading branch information
GermanAizek committed Dec 31, 2024
1 parent c5d541d commit 5fdb97a
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 32 deletions.
2 changes: 1 addition & 1 deletion opencl/source/command_queue/command_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ void CommandQueue::enqueueBlockedMapUnmapOperation(const cl_event *eventWaitList
}

// store task data in event
auto cmd = std::unique_ptr<Command>(new CommandMapUnmap(opType, *memObj, copySize, copyOffset, readOnly, *this));
auto cmd = std::make_unique<CommandMapUnmap>(opType, *memObj, copySize, copyOffset, readOnly, *this);
eventBuilder->getEvent()->setCommand(std::move(cmd));

// bind output event with input events
Expand Down
2 changes: 1 addition & 1 deletion opencl/source/sharings/va/va_sharing_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void VASharingFunctions::initFunctions() {
void VASharingFunctions::querySupportedVaImageFormats(VADisplay vaDisplay) {
int maxFormats = this->maxNumImageFormats(vaDisplay);
if (maxFormats > 0) {
std::unique_ptr<VAImageFormat[]> allVaFormats(new VAImageFormat[maxFormats]);
auto allVaFormats = std::make_unique<VAImageFormat[]>(maxFormats);
auto result = this->queryImageFormats(vaDisplay, allVaFormats.get(), &maxFormats);
if (result == VA_STATUS_SUCCESS) {
for (int i = 0; i < maxFormats; i++) {
Expand Down
2 changes: 1 addition & 1 deletion opencl/source/utilities/cl_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void ClFileLogger<debugLevel>::dumpKernelArgs(const MultiDispatchInfo *multiDisp
type = "immediate";
auto crossThreadData = kernel->getCrossThreadData();
auto crossThreadDataSize = kernel->getCrossThreadDataSize();
argVal = std::unique_ptr<char[]>(new char[crossThreadDataSize]);
argVal = std::make_unique<char[]>(crossThreadDataSize);

size_t totalArgSize = 0;
for (const auto &element : arg.as<ArgDescValue>().elements) {
Expand Down
2 changes: 1 addition & 1 deletion shared/offline_compiler/source/ocloc_arg_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ std::vector<char> OclocArgHelper::readBinaryFile(const std::string &filename) {
std::unique_ptr<char[]> OclocArgHelper::loadDataFromFile(const std::string &filename, size_t &retSize) {
if (Source *s = findSourceFile(filename)) {
auto size = s->length;
std::unique_ptr<char[]> ret(new char[size]());
auto ret = std::make_unique<char[]>(size);
memcpy_s(ret.get(), size, s->data, s->length);
retSize = s->length;
return ret;
Expand Down
3 changes: 1 addition & 2 deletions shared/source/ail/ail_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ template <PRODUCT_FAMILY product>
class AILConfigurationHw : public AILConfiguration {
public:
static std::unique_ptr<AILConfiguration> create() {
auto ailConfiguration = std::unique_ptr<AILConfiguration>(new AILConfigurationHw());
return ailConfiguration;
return std::make_unique<AILConfigurationHw>();
}

void applyExt(RuntimeCapabilityTable &runtimeCapabilityTable) override;
Expand Down
4 changes: 2 additions & 2 deletions shared/source/built_ins/built_ins_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ BuiltinResourceT EmbeddedStorage::loadImpl(const std::string &fullResourceName)
}

BuiltinsLib::BuiltinsLib() {
allStorages.push_back(std::unique_ptr<Storage>(new EmbeddedStorage("")));
allStorages.push_back(std::unique_ptr<Storage>(new FileStorage(getDriverInstallationPath())));
allStorages.push_back(std::make_unique<EmbeddedStorage>(""));
allStorages.push_back(std::make_unique<FileStorage>(getDriverInstallationPath()));
}

BuiltinCode BuiltinsLib::getBuiltinCode(EBuiltInOps::Type builtin, BuiltinCode::ECodeType requestedCodeType, Device &device) {
Expand Down
2 changes: 1 addition & 1 deletion shared/source/command_container/cmdcontainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ CommandContainer::ErrorCode CommandContainer::initialize(Device *device, Allocat

addToResidencyContainer(cmdBufferAllocation);
if (requireHeaps) {
heapHelper = std::unique_ptr<HeapHelper>(new HeapHelper(device->getMemoryManager(), device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage(), device->getNumGenericSubDevices() > 1u));
heapHelper = std::make_unique<HeapHelper>(device->getMemoryManager(), device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage(), device->getNumGenericSubDevices() > 1u);

for (uint32_t i = 0; i < IndirectHeap::Type::numTypes; i++) {
auto heapType = static_cast<HeapType>(i);
Expand Down
2 changes: 1 addition & 1 deletion shared/source/dll/create_deferred_deleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

namespace NEO {
std::unique_ptr<DeferredDeleter> createDeferredDeleter() {
return std::unique_ptr<DeferredDeleter>(new DeferredDeleter());
return std::make_unique<DeferredDeleter>();
}
} // namespace NEO
6 changes: 3 additions & 3 deletions shared/source/os_interface/linux/drm_memory_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ GraphicsAllocation *DrmMemoryManager::allocatePhysicalDeviceMemory(const Allocat
auto isCoherent = productHelper.isCoherentAllocation(patIndex);
uint32_t handle = ioctlHelper->createGem(bufferSize, static_cast<uint32_t>(allocationData.storageInfo.memoryBanks.to_ulong()), isCoherent);

std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(allocationData.rootDeviceIndex, &drm, patIndex, handle, bufferSize, maxOsContextCount));
auto bo = std::make_unique<BufferObject>(allocationData.rootDeviceIndex, &drm, patIndex, handle, bufferSize, maxOsContextCount);

auto allocation = new DrmAllocation(allocationData.rootDeviceIndex, 1u /*num gmms*/, allocationData.type, bo.get(), nullptr, 0u, bufferSize, memoryPool);
allocation->setDefaultGmm(gmm.release());
Expand Down Expand Up @@ -842,7 +842,7 @@ GraphicsAllocation *DrmMemoryManager::allocateMemoryByKMD(const AllocationData &
boType = BufferObject::BOType::legacy;
}

std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(allocationData.rootDeviceIndex, &drm, patIndex, handle, bufferSize, maxOsContextCount));
auto bo = std::make_unique<BufferObject>(allocationData.rootDeviceIndex, &drm, patIndex, handle, bufferSize, maxOsContextCount);
bo->setAddress(gpuRange);
bo->setBOType(boType);

Expand Down Expand Up @@ -2683,7 +2683,7 @@ GraphicsAllocation *DrmMemoryManager::createSharedUnifiedMemoryAllocation(const
return nullptr;
}

std::unique_ptr<BufferObject, BufferObject::Deleter> bo(new BufferObject(allocationData.rootDeviceIndex, &drm, patIndex, handle, currentSize, maxOsContextCount));
auto bo = std::make_unique<BufferObject>(allocationData.rootDeviceIndex, &drm, patIndex, handle, currentSize, maxOsContextCount);

if (vmAdviseAttribute.has_value() && !ioctlHelper->setVmBoAdvise(bo->peekHandle(), vmAdviseAttribute.value(), nullptr)) {
ioctlHelper->munmapFunction(*this, cpuBasePointer, totalSizeToAlloc);
Expand Down
2 changes: 1 addition & 1 deletion shared/source/os_interface/linux/ioctl_helper_prelim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ std::unique_ptr<uint8_t[]> IoctlHelperPrelim20::prepareVmBindExt(const StackVec<
"Alignment of a buffer returned via new[] operator must allow storing the required type!");

const auto bufferSize{sizeof(prelim_drm_i915_vm_bind_ext_uuid) * bindExtHandles.size()};
std::unique_ptr<uint8_t[]> extensionsBuffer{new uint8_t[bufferSize]};
auto extensionsBuffer = std::make_unique<uint8_t[]>(bufferSize);

auto extensions = new (extensionsBuffer.get()) prelim_drm_i915_vm_bind_ext_uuid[bindExtHandles.size()];
std::memset(extensionsBuffer.get(), 0, bufferSize);
Expand Down
2 changes: 1 addition & 1 deletion shared/source/os_interface/linux/os_thread_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ decltype(&Thread::create) Thread::createFunc = Thread::create;
std::unique_ptr<Thread> Thread::create(void *(*func)(void *), void *arg) {
pthread_t threadId;
pthread_create(&threadId, nullptr, func, arg);
return std::unique_ptr<Thread>(new ThreadLinux(threadId));
return std::make_unique<ThreadLinux>(threadId);
}

void ThreadLinux::join() {
Expand Down
2 changes: 1 addition & 1 deletion shared/source/os_interface/linux/os_time_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ uint64_t OSTimeLinux::getCpuRawTimestamp() {
}

std::unique_ptr<OSTime> OSTimeLinux::create(OSInterface &osInterface, std::unique_ptr<DeviceTime> deviceTime) {
return std::unique_ptr<OSTime>(new OSTimeLinux(osInterface, std::move(deviceTime)));
return std::make_unique<OSTimeLinux>(osInterface, std::move(deviceTime));
}

} // namespace NEO
18 changes: 9 additions & 9 deletions shared/source/os_interface/windows/wddm/wddm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Wddm::Wddm(std::unique_ptr<HwDeviceIdWddm> &&hwDeviceIdIn, RootDeviceEnvironment
memset(gtSystemInfo.get(), 0, sizeof(*gtSystemInfo));
memset(gfxPlatform.get(), 0, sizeof(*gfxPlatform));
this->enablePreemptionRegValue = NEO::readEnablePreemptionRegKey();
kmDafListener = std::unique_ptr<KmDafListener>(new KmDafListener);
kmDafListener = std::make_unique<KmDafListener>();
temporaryResources = std::make_unique<WddmResidentAllocationsContainer>(this);
osMemory = OSMemory::create();
bool forceCheck = false;
Expand Down Expand Up @@ -864,10 +864,10 @@ bool Wddm::openSharedHandle(const MemoryManager::OsHandleData &osHandleData, Wdd
return false;
}

std::unique_ptr<char[]> allocPrivateData(new char[queryResourceInfo.TotalPrivateDriverDataSize]);
std::unique_ptr<char[]> resPrivateData(new char[queryResourceInfo.ResourcePrivateDriverDataSize]);
std::unique_ptr<char[]> resPrivateRuntimeData(new char[queryResourceInfo.PrivateRuntimeDataSize]);
std::unique_ptr<D3DDDI_OPENALLOCATIONINFO[]> allocationInfo(new D3DDDI_OPENALLOCATIONINFO[queryResourceInfo.NumAllocations]);
auto allocPrivateData = std::make_unique<char[]>(queryResourceInfo.TotalPrivateDriverDataSize);
auto resPrivateData = std::make_unique<char[]>(queryResourceInfo.ResourcePrivateDriverDataSize);
auto resPrivateRuntimeData = std::make_unique<char[]>(queryResourceInfo.PrivateRuntimeDataSize);
auto allocationInfo = std::make_unique<D3DDDI_OPENALLOCATIONINFO[]>(queryResourceInfo.NumAllocations);

D3DKMT_OPENRESOURCE openResource = {};

Expand Down Expand Up @@ -914,10 +914,10 @@ bool Wddm::openNTHandle(const MemoryManager::OsHandleData &osHandleData, WddmAll
return false;
}

std::unique_ptr<char[]> allocPrivateData(new char[queryResourceInfoFromNtHandle.TotalPrivateDriverDataSize]);
std::unique_ptr<char[]> resPrivateData(new char[queryResourceInfoFromNtHandle.ResourcePrivateDriverDataSize]);
std::unique_ptr<char[]> resPrivateRuntimeData(new char[queryResourceInfoFromNtHandle.PrivateRuntimeDataSize]);
std::unique_ptr<D3DDDI_OPENALLOCATIONINFO2[]> allocationInfo2(new D3DDDI_OPENALLOCATIONINFO2[queryResourceInfoFromNtHandle.NumAllocations]);
auto allocPrivateData = std::make_unique<char>(queryResourceInfoFromNtHandle.TotalPrivateDriverDataSize);
auto resPrivateData = std::make_unique<char>(queryResourceInfoFromNtHandle.ResourcePrivateDriverDataSize);
auto resPrivateRuntimeData = std::make_unique<char>(queryResourceInfoFromNtHandle.PrivateRuntimeDataSize);
auto allocationInfo2 = std::make_unique<D3DDDI_OPENALLOCATIONINFO2[]>(queryResourceInfoFromNtHandle.NumAllocations);

D3DKMT_OPENRESOURCEFROMNTHANDLE openResourceFromNtHandle = {};

Expand Down
2 changes: 1 addition & 1 deletion shared/source/program/print_formatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ void PrintFormatter::printString(const char *formatString, const std::function<v
size_t length = strnlen_s(formatString, maxSinglePrintStringLength - 1);

size_t cursor = 0;
std::unique_ptr<char[]> dataFormat(new char[length + 1]);
auto dataFormat = std::make_unique<char[]>(length + 1);

for (size_t i = 0; i <= length; i++) {
if (formatString[i] == '\\')
Expand Down
2 changes: 1 addition & 1 deletion shared/source/utilities/idlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ template <typename NodeObjectType, bool threadSafe = true, bool ownsNodes = true
class IDRefList : public IDList<IDNodeRef<NodeObjectType>, threadSafe, ownsNodes> {
public:
void pushRefFrontOne(NodeObjectType &node) {
auto refNode = std::unique_ptr<IDNodeRef<NodeObjectType>>(new IDNodeRef<NodeObjectType>(&node));
auto refNode = std::make_unique<IDNodeRef<NodeObjectType>>(&node);
this->pushFrontOne(*refNode);
refNode.release();
}
Expand Down
2 changes: 1 addition & 1 deletion shared/source/utilities/iflist.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ template <typename NodeObjectType, bool threadSafe = true, bool ownsNodes = true
class IFRefList : public IFList<IFNodeRef<NodeObjectType>, threadSafe, ownsNodes> {
public:
void pushRefFrontOne(NodeObjectType &node) {
auto up = std::unique_ptr<IFNodeRef<NodeObjectType>>(new IFNodeRef<NodeObjectType>(&node));
auto up = std::make_unique<IFNodeRef<NodeObjectType>>(&node);
this->pushFrontOne(*up);
up.release();
} // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
Expand Down
8 changes: 4 additions & 4 deletions shared/source/utilities/perf_profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ PerfProfiler *PerfProfiler::create(bool dumpToFile) {
if (gPerfProfiler == nullptr) {
int old = counter.fetch_add(1);
if (!dumpToFile) {
std::unique_ptr<std::stringstream> logs = std::unique_ptr<std::stringstream>(new std::stringstream());
std::unique_ptr<std::stringstream> sysLogs = std::unique_ptr<std::stringstream>(new std::stringstream());
auto logs = std::make_unique<std::stringstream>();
auto sysLogs = std::make_unique<std::stringstream>();
gPerfProfiler = new PerfProfiler(old, std::move(logs), std::move(sysLogs));
} else {
gPerfProfiler = new PerfProfiler(old);
Expand Down Expand Up @@ -63,7 +63,7 @@ PerfProfiler::PerfProfiler(int id, std::unique_ptr<std::ostream> &&logOut, std::
std::stringstream filename;
filename << "PerfReport_Thread_" << id << ".xml";

std::unique_ptr<std::ofstream> logToFile = std::unique_ptr<std::ofstream>(new std::ofstream());
auto logToFile = std::make_unique<std::ofstream>();
logToFile->exceptions(std::ios::failbit | std::ios::badbit);
logToFile->open(filename.str().c_str(), std::ios::trunc);
this->logFile = std::move(logToFile);
Expand All @@ -77,7 +77,7 @@ PerfProfiler::PerfProfiler(int id, std::unique_ptr<std::ostream> &&logOut, std::
std::stringstream filename;
filename << "SysPerfReport_Thread_" << id << ".xml";

std::unique_ptr<std::ofstream> sysLogToFile = std::unique_ptr<std::ofstream>(new std::ofstream());
auto sysLogToFile = std::make_unique<std::ofstream>();
sysLogToFile->exceptions(std::ios::failbit | std::ios::badbit);
sysLogToFile->open(filename.str().c_str(), std::ios::trunc);
this->sysLogFile = std::move(sysLogToFile);
Expand Down

0 comments on commit 5fdb97a

Please sign in to comment.