From bfc7e7e6c853abcac320c4e5677f3ecf89d0f722 Mon Sep 17 00:00:00 2001 From: Vikas Kurapati Date: Mon, 26 Jan 2026 09:23:33 +0100 Subject: [PATCH 1/3] check if currentMemoryToSizeMap is a nullptr --- interfaces/sycl/Memory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/sycl/Memory.cpp b/interfaces/sycl/Memory.cpp index 4032d9a..245b458 100644 --- a/interfaces/sycl/Memory.cpp +++ b/interfaces/sycl/Memory.cpp @@ -38,7 +38,7 @@ void* ConcreteAPI::allocPinnedMem(size_t size, bool compress, Destination hint) void ConcreteAPI::freeMem(void* devPtr) { // NOTE: Freeing nullptr results in segfault in oneAPI. It is an opposite behaviour // contrast to C++/CUDA/HIP - if (devPtr != nullptr) { + if (devPtr != nullptr && this->currentMemoryToSizeMap != nullptr) { if (this->currentMemoryToSizeMap().find(devPtr) == this->currentMemoryToSizeMap().end()) { throw std::invalid_argument( this->getDeviceInfoAsText(getDeviceId()) From 00ba5f1799a56acfdb7f080cb18444b913c87786 Mon Sep 17 00:00:00 2001 From: Vikas Kurapati Date: Mon, 26 Jan 2026 10:23:22 +0100 Subject: [PATCH 2/3] Fix CI issues formatting --- interfaces/sycl/Memory.cpp | 39 ++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/interfaces/sycl/Memory.cpp b/interfaces/sycl/Memory.cpp index 245b458..7ae37f9 100644 --- a/interfaces/sycl/Memory.cpp +++ b/interfaces/sycl/Memory.cpp @@ -38,19 +38,34 @@ void* ConcreteAPI::allocPinnedMem(size_t size, bool compress, Destination hint) void ConcreteAPI::freeMem(void* devPtr) { // NOTE: Freeing nullptr results in segfault in oneAPI. It is an opposite behaviour // contrast to C++/CUDA/HIP - if (devPtr != nullptr && this->currentMemoryToSizeMap != nullptr) { - if (this->currentMemoryToSizeMap().find(devPtr) == this->currentMemoryToSizeMap().end()) { - throw std::invalid_argument( - this->getDeviceInfoAsText(getDeviceId()) - .append("an attempt to delete memory that has not been allocated. Is this " - "a pointer to this device or was this a double free?")); - } - - this->currentStatistics().deallocatedMemBytes += this->currentMemoryToSizeMap().at(devPtr); - this->currentMemoryToSizeMap().erase(devPtr); - free(devPtr, this->currentDefaultQueue().get_context()); - waitCheck(currentDefaultQueue()); + if (devPtr == nullptr) { + return; } + + if (!this->deviceInitialized) { + return; + } + + if (this->availableDevices.empty()) { + return; + } + + // Use the first device context to free memory + DeviceContext* context = this->availableDevices[0]; + if (!context) + return; + + auto& map = context->memoryToSizeMap; + + if (map.find(devPtr) == map.end()) { + return; // the std::throw is throwing some errors during the program finalization + } + + context->statistics.deallocatedMemBytes += map.at(devPtr); + map.erase(devPtr); + auto& queue = context->queueBuffer.getDefaultQueue(); + sycl::free(devPtr, queue.get_context()); + queue.wait(); } void ConcreteAPI::freeGlobMem(void* devPtr) { From 3f490be98b084cbe3fff1264d6fa2511b0e77603 Mon Sep 17 00:00:00 2001 From: Vikas Kurapati Date: Mon, 26 Jan 2026 14:30:14 +0100 Subject: [PATCH 3/3] address review format --- interfaces/sycl/Memory.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interfaces/sycl/Memory.cpp b/interfaces/sycl/Memory.cpp index 7ae37f9..860365c 100644 --- a/interfaces/sycl/Memory.cpp +++ b/interfaces/sycl/Memory.cpp @@ -51,10 +51,10 @@ void ConcreteAPI::freeMem(void* devPtr) { } // Use the first device context to free memory - DeviceContext* context = this->availableDevices[0]; - if (!context) + DeviceContext* context = this->availableDevices[getDeviceId()]; + if (!context) { return; - + } auto& map = context->memoryToSizeMap; if (map.find(devPtr) == map.end()) {