Skip to content

Commit 9701510

Browse files
committed
Fix CI issues
fix formatting
1 parent bfc7e7e commit 9701510

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

interfaces/sycl/Memory.cpp

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,34 @@ void* ConcreteAPI::allocPinnedMem(size_t size, bool compress, Destination hint)
3838
void ConcreteAPI::freeMem(void* devPtr) {
3939
// NOTE: Freeing nullptr results in segfault in oneAPI. It is an opposite behaviour
4040
// contrast to C++/CUDA/HIP
41-
if (devPtr != nullptr && this->currentMemoryToSizeMap != nullptr) {
42-
if (this->currentMemoryToSizeMap().find(devPtr) == this->currentMemoryToSizeMap().end()) {
43-
throw std::invalid_argument(
44-
this->getDeviceInfoAsText(getDeviceId())
45-
.append("an attempt to delete memory that has not been allocated. Is this "
46-
"a pointer to this device or was this a double free?"));
47-
}
48-
49-
this->currentStatistics().deallocatedMemBytes += this->currentMemoryToSizeMap().at(devPtr);
50-
this->currentMemoryToSizeMap().erase(devPtr);
51-
free(devPtr, this->currentDefaultQueue().get_context());
52-
waitCheck(currentDefaultQueue());
41+
if (devPtr == nullptr) {
42+
return;
5343
}
44+
45+
if (!this->deviceInitialized){
46+
return;
47+
}
48+
49+
if (this->availableDevices.empty()){
50+
return;
51+
}
52+
53+
// Use the first device context to free memory
54+
DeviceContext* context = this->availableDevices[0];
55+
if (!context)
56+
return;
57+
58+
auto& map = context->memoryToSizeMap;
59+
60+
if (map.find(devPtr) == map.end()){
61+
return; // the std::throw is throwing some errors during the program finalization
62+
}
63+
64+
context->statistics.deallocatedMemBytes += map.at(devPtr);
65+
map.erase(devPtr);
66+
auto& queue = context->queueBuffer.getDefaultQueue();
67+
sycl::free(devPtr, queue.get_context());
68+
queue.wait();
5469
}
5570

5671
void ConcreteAPI::freeGlobMem(void* devPtr) {

0 commit comments

Comments
 (0)