Commit 82ffbd38 authored by Pavel Kus's avatar Pavel Kus
Browse files

adding tool to check GPU memory

parent ee0e63d0
#define DEBUG_CUDA 1
#include <stdio.h>
#include <math.h>
#include <stdio.h>
......@@ -157,7 +158,7 @@ extern "C" {
cudaError_t cuerr = cudaMalloc((void **) a, width_height);
#ifdef DEBUG_CUDA
printf("Malloc pointer address: %p \n", *a);
printf("CUDA Malloc, pointer address: %p, size: %d \n", *a, width_height);
#endif
if (cuerr != cudaSuccess) {
errormessage("Error in cudaMalloc: %s\n",cudaGetErrorString(cuerr));
......@@ -167,7 +168,7 @@ extern "C" {
}
int cudaFreeFromC(intptr_t *a) {
#ifdef DEBUG_CUDA
printf("Free pointer address: %p \n", a);
printf("CUDA Free, pointer address: %p \n", a);
#endif
cudaError_t cuerr = cudaFree(a);
......
#! /usr/bin/env python3
import sys
#CUDA Malloc, pointer address: 0x2b2597bf0200, size: 32768
#CUDA Free, pointer address: 0x2ac28dbe8400
filename = sys.argv[1]
allocated = {}
watermark = -1000
biggest = -1000
actual = 0
total = 0
with open(filename, "r") as f:
for line in f:
if(line.startswith("CUDA Malloc")):
tokens = line.replace(",", " ").split()
adr = tokens[4]
size = int(tokens[6])
#print("%s, %s" % (adr, size))
if(adr in allocated.keys()):
raise Exception("Address already allocated")
allocated[adr] = size
actual += size
watermark = max(watermark, actual)
biggest = max(biggest, size)
total += size
if(line.startswith("CUDA Free")):
tokens = line.replace(",", " ").split()
adr = tokens[4]
#print("%s, %s" % (adr))
if(adr not in allocated.keys()):
raise Exception("Address not allocated cannot be freed")
size = allocated[adr]
actual -= size
allocated.pop(adr)
print("Watermark %.2f MB" % (watermark / 2**20))
print("Total %.2f MB" % (total / 2**20))
print("Biggest %.2f MB" % (biggest / 2**20))
print("Nonfreed %.2f MB" % (actual / 2**20))
print(allocated)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment