Last active
August 29, 2015 14:16
-
-
Save pavanky/615be692b1eee9a4a21e to your computer and use it in GitHub Desktop.
Patch for debugging ArrayFire memory manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/backend/cpu/memory.cpp b/src/backend/cpu/memory.cpp | |
index 1f0ed5b..45481bc 100644 | |
--- a/src/backend/cpu/memory.cpp | |
+++ b/src/backend/cpu/memory.cpp | |
@@ -87,6 +87,15 @@ namespace cpu | |
T* ptr = NULL; | |
size_t alloc_bytes = divup(sizeof(T) * elements, 1024) * 1024; | |
+ printf("USED BYTES: %zu MB\n", used_bytes >> 20); | |
+ printf("NBUFFERS: %zu\n", memory_map.size()); | |
+ int count = 0; | |
+ for(mem_iter iter = memory_map.begin(); iter != memory_map.end(); iter++) { | |
+ if (!(iter->second).is_free) count++; | |
+ } | |
+ printf("Non free buffers: %d\n", count); | |
+ | |
+ | |
if (elements > 0) { | |
// FIXME: Add better checks for garbage collection | |
@@ -126,6 +135,15 @@ namespace cpu | |
} else { | |
freeWrapper(ptr); // Free it because we are not sure what the size is | |
} | |
+ | |
+ printf("USED BYTES: %zu MB\n", used_bytes >> 20); | |
+ printf("NBUFFERS: %zu\n", memory_map.size()); | |
+ int count = 0; | |
+ for(mem_iter iter = memory_map.begin(); iter != memory_map.end(); iter++) { | |
+ if (!(iter->second).is_free) count++; | |
+ } | |
+ printf("Non free buffers: %d\n", count); | |
+ | |
} | |
template<typename T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/backend/cuda/memory.cpp b/src/backend/cuda/memory.cpp | |
index 316aa35..6689463 100644 | |
--- a/src/backend/cuda/memory.cpp | |
+++ b/src/backend/cuda/memory.cpp | |
@@ -141,6 +141,14 @@ namespace cuda | |
T* ptr = NULL; | |
size_t alloc_bytes = divup(sizeof(T) * elements, 1024) * 1024; | |
+ printf("USED BYTES: %zu MB\n", used_bytes >> 20); | |
+ printf("NBUFFERS: %zu\n", memory_maps[n].size()); | |
+ int count = 0; | |
+ for(mem_iter iter = memory_maps[n].begin(); iter != memory_maps[n].end(); iter++) { | |
+ if (!(iter->second).is_free) count++; | |
+ } | |
+ printf("Non free buffers: %d\n", count); | |
+ | |
if (elements > 0) { | |
// FIXME: Add better checks for garbage collection | |
@@ -177,14 +185,26 @@ namespace cuda | |
void memFree(T *ptr) | |
{ | |
int n = getActiveDeviceId(); | |
- mem_iter iter = memory_maps[n].find((void *)ptr); | |
- if (iter != memory_maps[n].end()) { | |
- iter->second.is_free = true; | |
- used_bytes -= iter->second.bytes; | |
- } else { | |
- cudaFreeWrapper(ptr); // Free it because we are not sure what the size is | |
+ { | |
+ mem_iter iter = memory_maps[n].find((void *)ptr); | |
+ | |
+ if (iter != memory_maps[n].end()) { | |
+ iter->second.is_free = true; | |
+ used_bytes -= iter->second.bytes; | |
+ } else { | |
+ cudaFreeWrapper(ptr); // Free it because we are not sure what the size is | |
+ } | |
+ } | |
+ | |
+ printf("USED BYTES: %zu MB\n", used_bytes >> 20); | |
+ printf("NBUFFERS: %zu\n", memory_maps[n].size()); | |
+ int count = 0; | |
+ for(mem_iter iter = memory_maps[n].begin(); iter != memory_maps[n].end(); iter++) { | |
+ if (!(iter->second).is_free) count++; | |
} | |
+ printf("Non free buffers: %d\n", count); | |
+ | |
} | |
////////////////////////////////////////////////////////////////////////////// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/backend/opencl/memory.cpp b/src/backend/opencl/memory.cpp | |
index 5c3876f..2cbac29 100644 | |
--- a/src/backend/opencl/memory.cpp | |
+++ b/src/backend/opencl/memory.cpp | |
@@ -91,6 +91,14 @@ namespace opencl | |
cl::Buffer *ptr = NULL; | |
size_t alloc_bytes = divup(bytes, 1024) * 1024; | |
+ printf("USED BYTES: %zu MB\n", used_bytes >> 20); | |
+ printf("NBUFFERS: %zu\n", memory_maps[n].size()); | |
+ int count = 0; | |
+ for(mem_iter iter = memory_maps[n].begin(); iter != memory_maps[n].end(); iter++) { | |
+ if (!(iter->second).is_free) count++; | |
+ } | |
+ printf("Non free buffers: %d\n", count); | |
+ | |
if (bytes > 0) { | |
// FIXME: Add better checks for garbage collection | |
@@ -135,6 +143,14 @@ namespace opencl | |
} else { | |
destroy(ptr); // Free it because we are not sure what the size is | |
} | |
+ | |
+ printf("USED BYTES: %zu MB\n", used_bytes >> 20); | |
+ printf("NBUFFERS: %zu\n", memory_maps[n].size()); | |
+ int count = 0; | |
+ for(mem_iter iter = memory_maps[n].begin(); iter != memory_maps[n].end(); iter++) { | |
+ if (!(iter->second).is_free) count++; | |
+ } | |
+ printf("Non free buffers: %d\n", count); | |
} | |
template<typename T> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment