Skip to content

Commit

Permalink
Initial work on memory pressure handling. See #904.
Browse files Browse the repository at this point in the history
  • Loading branch information
azonenberg committed Oct 2, 2024
1 parent 6b0a06e commit 3b27272
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
4 changes: 2 additions & 2 deletions scopehal/AcceleratorBuffer.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/***********************************************************************************************************************
* *
* libscopehal v0.1 *
* libscopehal *
* *
* Copyright (c) 2012-2022 Andrew D. Zonenberg and contributors *
* Copyright (c) 2012-2024 Andrew D. Zonenberg and contributors *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
Expand Down
12 changes: 12 additions & 0 deletions scopehal/scopehal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,3 +987,15 @@ const char* ScopehalGetVersion()
{
return SCOPEHAL_VERSION;
}

/**
@brief Called when we run low on memory
@param level Indicates if this is a soft or hard memory exhaustion condition
@param type Indicates if we are low on CPU or GPU memory
*/
void OnMemoryPressure(MemoryPressureLevel level, MemoryPressureType type)
{
for(auto handler : g_memoryPressureHandlers)
handler(level, type);
}
35 changes: 35 additions & 0 deletions scopehal/scopehal.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,39 @@ uint32_t ColorFromString(const std::string& str, unsigned int alpha = 255);

const char* ScopehalGetVersion();

///@brief Levels of memory pressure
enum class MemoryPressureLevel
{
///@brief A memory allocation has failed and we need to free memory immediately to continue execution
Hard,

/**
@brief Free memory has reached a warning threshold.
We should trim caches or otherwise try to make space but don't need to be too aggressive about it.
This level is only available if we have VK_EXT_memory_budget; without this extension we do not know about
memory pressure until a hard allocation failure occurs.
*/
Soft
};

///@brief Types of memory pressure
enum class MemoryPressureType
{
///@brief Pinned CPU-side memory
Host,

///@brief GPU-side memory
Device
};

///@brief Memory pressure handler type, called when free memory reaches a warning level or a Vulkan allocation fails
typedef void (*MemoryPressureHandler)(MemoryPressureLevel level, MemoryPressureType type);

///@brief List of handlers for low memory registered by various subsystems
std::set<MemoryPressureHandler> g_memoryPressureHandlers;

void OnMemoryPressure(MemoryPressureLevel level, MemoryPressureType type);

#endif

0 comments on commit 3b27272

Please sign in to comment.