[arrayfire] 141/284: FEAT Add printMemInfo to print memory information
Ghislain Vaillant
ghisvail-guest at moszumanska.debian.org
Sun Feb 7 18:59:27 UTC 2016
This is an automated email from the git hooks/post-receive script.
ghisvail-guest pushed a commit to branch debian/experimental
in repository arrayfire.
commit 330f4f87df56263375f904660ad7d800d94161f5
Author: Shehzan Mohammed <shehzan at arrayfire.com>
Date: Thu Dec 31 18:22:44 2015 -0500
FEAT Add printMemInfo to print memory information
---
include/af/device.h | 28 +++++++++++++++++++++++++++
src/api/c/device.cpp | 17 ++++++++++++++++
src/api/cpp/device.cpp | 5 +++++
src/api/unified/device.cpp | 5 +++++
src/backend/cpu/memory.cpp | 40 ++++++++++++++++++++++++++++++++++++++
src/backend/cpu/memory.hpp | 2 ++
src/backend/cuda/memory.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++
src/backend/cuda/memory.hpp | 2 ++
src/backend/opencl/memory.cpp | 41 +++++++++++++++++++++++++++++++++++++++
src/backend/opencl/memory.hpp | 2 ++
10 files changed, 187 insertions(+)
diff --git a/include/af/device.h b/include/af/device.h
index 394170c..4a3006f 100644
--- a/include/af/device.h
+++ b/include/af/device.h
@@ -205,6 +205,19 @@ namespace af
AFAPI void deviceMemInfo(size_t *alloc_bytes, size_t *alloc_buffers,
size_t *lock_bytes, size_t *lock_buffers);
+#if AF_API_VERSION >= 33
+ ///
+ /// Prints buffer details from the ArrayFire Device Manager
+ //
+ /// \param [in] msg A message to print before the table
+ /// \param [in] device_id print the memory info of the specified device.
+ /// -1 signifies active device.
+ //
+ /// \ingroup device_func_mem
+ ///
+ AFAPI void printMemInfo(const char *msg = NULL, const int device_id = -1);
+#endif
+
/// \brief Call the garbage collection function in the memory manager
///
/// \ingroup device_func_mem
@@ -324,6 +337,21 @@ extern "C" {
AFAPI af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
size_t *lock_bytes, size_t *lock_buffers);
+#if AF_API_VERSION >= 33
+ ///
+ /// Prints buffer details from the ArrayFire Device Manager
+ //
+ /// \param [in] msg A message to print before the table
+ /// \param [in] device_id print the memory info of the specified device.
+ /// -1 signifies active device.
+ ///
+ /// return AF_SUCCESS if successful
+ ///
+ /// \ingroup device_func_mem
+ ///
+ AFAPI af_err af_print_mem_info(const char *msg, const int device_id);
+#endif
+
/**
Call the garbage collection routine
\ingroup device_func_mem
diff --git a/src/api/c/device.cpp b/src/api/c/device.cpp
index c2f21a2..007e0ab 100644
--- a/src/api/c/device.cpp
+++ b/src/api/c/device.cpp
@@ -17,6 +17,7 @@
#include <handle.hpp>
#include <memory.hpp>
#include "err_common.hpp"
+#include <cstring>
using namespace detail;
@@ -340,6 +341,22 @@ af_err af_free_host(void *ptr)
return AF_SUCCESS;
}
+af_err af_print_mem_info(const char *msg, const int device_id)
+{
+ try {
+ int device = device_id;
+ if(device == -1) {
+ device = getActiveDeviceId();
+ }
+
+ if(msg != NULL) ARG_ASSERT(0, strlen(msg) < 256); // 256 character limit on msg
+ ARG_ASSERT(1, device >= 0 && device < getDeviceCount());
+
+ printMemInfo(msg ? msg : "", device);
+ } CATCHALL;
+ return AF_SUCCESS;
+}
+
af_err af_device_gc()
{
try {
diff --git a/src/api/cpp/device.cpp b/src/api/cpp/device.cpp
index 3f24417..3b1609b 100644
--- a/src/api/cpp/device.cpp
+++ b/src/api/cpp/device.cpp
@@ -159,6 +159,11 @@ namespace af
AF_THROW(af_free_host((void *)ptr));
}
+ void printMemInfo(const char *msg, const int device_id)
+ {
+ AF_THROW(af_print_mem_info(msg, device_id));
+ }
+
void deviceGC()
{
AF_THROW(af_device_gc());
diff --git a/src/api/unified/device.cpp b/src/api/unified/device.cpp
index 1d5979a..f7e9556 100644
--- a/src/api/unified/device.cpp
+++ b/src/api/unified/device.cpp
@@ -121,6 +121,11 @@ af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
return CALL(alloc_bytes, alloc_buffers, lock_bytes, lock_buffers);
}
+af_err af_print_mem_info(const char *msg, const int device_id)
+{
+ return CALL(msg, device_id);
+}
+
af_err af_device_gc()
{
return CALL_NO_PARAMS();
diff --git a/src/backend/cpu/memory.cpp b/src/backend/cpu/memory.cpp
index 0e14450..8718c1e 100644
--- a/src/backend/cpu/memory.cpp
+++ b/src/backend/cpu/memory.cpp
@@ -14,6 +14,9 @@
#include <dispatch.hpp>
#include <cstdlib>
#include <mutex>
+#include <iostream>
+#include <iomanip>
+#include <string>
#include <platform.hpp>
#include <queue.hpp>
@@ -103,6 +106,43 @@ void garbageCollect()
}
}
+void printMemInfo(const char *msg, const int device)
+{
+ std::cout << msg << std::endl;
+
+ static const std::string head("| POINTER | SIZE | AF LOCK | USER LOCK |");
+ static const std::string line(head.size(), '-');
+ std::cout << line << std::endl << head << std::endl << line << std::endl;
+
+ for(mem_iter iter = memory_map.begin();
+ iter != memory_map.end(); ++iter) {
+
+ std::string status_af("Unknown");
+ std::string status_us("Unknown");
+
+ if(!(iter->second.is_free)) status_af = "Yes";
+ else status_af = " No";
+
+ if((iter->second.is_unlinked)) status_us = "Yes";
+ else status_us = " No";
+
+ std::string unit = "KB";
+ double size = (double)(iter->second.bytes) / 1024;
+ if(size >= 1024) {
+ size = size / 1024;
+ unit = "MB";
+ }
+
+ std::cout << "| " << std::right << std::setw(14) << iter->first << " "
+ << " | " << std::setw(7) << std::setprecision(4) << size << " " << unit
+ << " | " << std::setw(9) << status_af
+ << " | " << std::setw(9) << status_us
+ << " |" << std::endl;
+ }
+
+ std::cout << line << std::endl;
+}
+
template<typename T>
T* memAlloc(const size_t &elements)
{
diff --git a/src/backend/cpu/memory.hpp b/src/backend/cpu/memory.hpp
index 1fb8c64..41a156f 100644
--- a/src/backend/cpu/memory.hpp
+++ b/src/backend/cpu/memory.hpp
@@ -28,6 +28,8 @@ namespace cpu
void garbageCollect();
void pinnedGarbageCollect();
+ void printMemInfo(const char *msg, const int device);
+
void setMemStepSize(size_t step_bytes);
size_t getMemStepSize(void);
}
diff --git a/src/backend/cuda/memory.cpp b/src/backend/cuda/memory.cpp
index e7ed8ac..50b1301 100644
--- a/src/backend/cuda/memory.cpp
+++ b/src/backend/cuda/memory.cpp
@@ -14,6 +14,9 @@
#include <err_cuda.hpp>
#include <util.hpp>
#include <types.hpp>
+#include <iostream>
+#include <iomanip>
+#include <string>
#include <map>
#include <dispatch.hpp>
#include <platform.hpp>
@@ -105,6 +108,10 @@ namespace cuda
{
}
+ void printMemInfo(const char *msg, const int device)
+ {
+ std::cout << "printMemInfo() disabled in AF_CUDA_MEM_DEBUG Mode" << std::endl;
+ }
#else
// Manager Class
@@ -190,6 +197,44 @@ namespace cuda
}
}
+ void printMemInfo(const char *msg, const int device)
+ {
+ std::cout << msg << std::endl;
+ std::cout << "Memory Map for Device: " << device << std::endl;
+
+ static const std::string head("| POINTER | SIZE | AF LOCK | USER LOCK |");
+ static const std::string line(head.size(), '-');
+ std::cout << line << std::endl << head << std::endl << line << std::endl;
+
+ for(mem_iter iter = memory_maps[device].begin();
+ iter != memory_maps[device].end(); ++iter) {
+
+ std::string status_af("Unknown");
+ std::string status_us("Unknown");
+
+ if(!(iter->second.is_free)) status_af = "Yes";
+ else status_af = " No";
+
+ if((iter->second.is_unlinked)) status_us = "Yes";
+ else status_us = " No";
+
+ std::string unit = "KB";
+ double size = (double)(iter->second.bytes) / 1024;
+ if(size >= 1024) {
+ size = size / 1024;
+ unit = "MB";
+ }
+
+ std::cout << "| " << std::right << std::setw(14) << iter->first << " "
+ << " | " << std::setw(7) << std::setprecision(4) << size << " " << unit
+ << " | " << std::setw(9) << status_af
+ << " | " << std::setw(9) << status_us
+ << " |" << std::endl;
+ }
+
+ std::cout << line << std::endl;
+ }
+
template<typename T>
T* memAlloc(const size_t &elements)
{
diff --git a/src/backend/cuda/memory.hpp b/src/backend/cuda/memory.hpp
index a4450f3..2d419f2 100644
--- a/src/backend/cuda/memory.hpp
+++ b/src/backend/cuda/memory.hpp
@@ -28,6 +28,8 @@ namespace cuda
void garbageCollect();
void pinnedGarbageCollect();
+ void printMemInfo(const char *msg, const int device);
+
void setMemStepSize(size_t step_bytes);
size_t getMemStepSize(void);
}
diff --git a/src/backend/opencl/memory.cpp b/src/backend/opencl/memory.cpp
index 7475710..2c9a613 100644
--- a/src/backend/opencl/memory.cpp
+++ b/src/backend/opencl/memory.cpp
@@ -10,6 +10,9 @@
#include <memory.hpp>
#include <dispatch.hpp>
#include <map>
+#include <iostream>
+#include <iomanip>
+#include <string>
#include <types.hpp>
namespace opencl
@@ -102,6 +105,44 @@ namespace opencl
}
}
+ void printMemInfo(const char *msg, const int device)
+ {
+ std::cout << msg << std::endl;
+ std::cout << "Memory Map for Device: " << device << std::endl;
+
+ static const std::string head("| POINTER | SIZE | AF LOCK | USER LOCK |");
+ static const std::string line(head.size(), '-');
+ std::cout << line << std::endl << head << std::endl << line << std::endl;
+
+ for(mem_iter iter = memory_maps[device].begin();
+ iter != memory_maps[device].end(); ++iter) {
+
+ std::string status_af("Unknown");
+ std::string status_us("Unknown");
+
+ if(!(iter->second.is_free)) status_af = "Yes";
+ else status_af = " No";
+
+ if((iter->second.is_unlinked)) status_us = "Yes";
+ else status_us = " No";
+
+ std::string unit = "KB";
+ double size = (double)(iter->second.bytes) / 1024;
+ if(size >= 1024) {
+ size = size / 1024;
+ unit = "MB";
+ }
+
+ std::cout << "| " << std::right << std::setw(14) << iter->first << " "
+ << " | " << std::setw(7) << std::setprecision(4) << size << " " << unit
+ << " | " << std::setw(9) << status_af
+ << " | " << std::setw(9) << status_us
+ << " |" << std::endl;
+ }
+
+ std::cout << line << std::endl;
+ }
+
cl::Buffer *bufferAlloc(const size_t &bytes)
{
int n = getActiveDeviceId();
diff --git a/src/backend/opencl/memory.hpp b/src/backend/opencl/memory.hpp
index 40e30eb..625bd10 100644
--- a/src/backend/opencl/memory.hpp
+++ b/src/backend/opencl/memory.hpp
@@ -35,6 +35,8 @@ namespace opencl
void garbageCollect();
void pinnedGarbageCollect();
+ void printMemInfo(const char *msg, const int device);
+
void setMemStepSize(size_t step_bytes);
size_t getMemStepSize(void);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/arrayfire.git
More information about the debian-science-commits
mailing list