Skip to content

Commit

Permalink
Merge pull request #482 from jjfumero/chore/mem/actions
Browse files Browse the repository at this point in the history
When TornadoVM raises OOM, it prints a possible action to fix it
  • Loading branch information
jjfumero authored Jul 3, 2024
2 parents ddd006d + 81ca3b2 commit 942dc88
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is part of Tornado: A heterogeneous programming framework:
* /~https://github.com/beehive-lab/tornadovm
*
* Copyright (c) 2022, APT Group, Department of Computer Science,
* Copyright (c) 2022, 2024, APT Group, Department of Computer Science,
* The University of Manchester. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -48,6 +48,10 @@ public abstract class TornadoBufferProvider {
protected final List<BufferContainer> usedBuffers;
protected long currentMemoryAvailable;

private static final String RESET = "\u001B[0m";
public static final String YELLOW = "\u001B[33m";
private static final String OUT_OF_MEMORY_MESSAGE = YELLOW + "\n\tTo increase the maximum device memory, use -Dtornado.device.memory=<X>GB\n" + RESET;

protected TornadoBufferProvider(TornadoDeviceContext deviceContext) {
this.deviceContext = deviceContext;
this.usedBuffers = new ArrayList<>();
Expand Down Expand Up @@ -134,7 +138,7 @@ private synchronized long freeUnusedNativeBufferAndAssignRegion(long sizeInBytes
if (sizeInBytes <= currentMemoryAvailable) {
return allocate(sizeInBytes);
} else {
throw new TornadoOutOfMemoryException("Unable to allocate " + sizeInBytes + " bytes of memory.");
throw new TornadoOutOfMemoryException("Unable to allocate " + sizeInBytes + " bytes of memory." + OUT_OF_MEMORY_MESSAGE);
}
}

Expand Down Expand Up @@ -164,7 +168,7 @@ public synchronized long getOrAllocateBufferWithSize(long sizeInBytes) {
return freeUnusedNativeBufferAndAssignRegion(sizeInBytes);
}
} else {
throw new TornadoOutOfMemoryException("[ERROR] Unable to allocate " + sizeInBytes + " bytes of memory.");
throw new TornadoOutOfMemoryException("[ERROR] Unable to allocate " + sizeInBytes + " bytes of memory." + OUT_OF_MEMORY_MESSAGE);
}
}

Expand Down

0 comments on commit 942dc88

Please sign in to comment.