From 9d4302769afd85d18fdb6989b12e170c70f9206b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz>
Date: Sat, 19 Nov 2016 15:08:06 +0100
Subject: [PATCH] Moved getFreeMemory from Cuda to CudaDeviceInfo

---
 src/TNL/Devices/Cuda.cpp           |  5 -----
 src/TNL/Devices/Cuda.h             |  2 --
 src/TNL/Devices/CudaDeviceInfo.cpp |  7 +++++++
 src/TNL/Devices/CudaDeviceInfo.cu  | 10 ++++++++++
 src/TNL/Devices/CudaDeviceInfo.h   |  2 ++
 5 files changed, 19 insertions(+), 7 deletions(-)

diff --git a/src/TNL/Devices/Cuda.cpp b/src/TNL/Devices/Cuda.cpp
index 30ce841c4c..64a7ee1e9f 100644
--- a/src/TNL/Devices/Cuda.cpp
+++ b/src/TNL/Devices/Cuda.cpp
@@ -38,11 +38,6 @@ int Cuda::getNumberOfGrids( const int blocks,
    return roundUpDivision( blocks, gridSize );
 }
 
-/*size_t Cuda::getFreeMemory()
-{
-
-}*/
-
 void Cuda::configSetup( Config::ConfigDescription& config,
                         const String& prefix )
 {
diff --git a/src/TNL/Devices/Cuda.h b/src/TNL/Devices/Cuda.h
index 71a372c9f8..23f2f342ea 100644
--- a/src/TNL/Devices/Cuda.h
+++ b/src/TNL/Devices/Cuda.h
@@ -60,8 +60,6 @@ class Cuda
    static int getNumberOfGrids( const int blocks,
                                 const int gridSize = getMaxGridSize() );
 
-   static size_t getFreeMemory();
-
    template< typename ObjectType >
    static ObjectType* passToDevice( const ObjectType& object );
 
diff --git a/src/TNL/Devices/CudaDeviceInfo.cpp b/src/TNL/Devices/CudaDeviceInfo.cpp
index 93061f8bd5..3a4fc16674 100644
--- a/src/TNL/Devices/CudaDeviceInfo.cpp
+++ b/src/TNL/Devices/CudaDeviceInfo.cpp
@@ -64,6 +64,13 @@ getGlobalMemory( int deviceNum )
    return 0;
 }
 
+size_t
+CudaDeviceInfo::
+getFreeGlobalMemory()
+{
+   return 0;
+}
+
 int
 CudaDeviceInfo::
 getMemoryClockRate( int deviceNum )
diff --git a/src/TNL/Devices/CudaDeviceInfo.cu b/src/TNL/Devices/CudaDeviceInfo.cu
index 390984f836..452080f057 100644
--- a/src/TNL/Devices/CudaDeviceInfo.cu
+++ b/src/TNL/Devices/CudaDeviceInfo.cu
@@ -81,6 +81,16 @@ getGlobalMemory( int deviceNum )
     return properties.totalGlobalMem;
 }
 
+size_t
+CudaDeviceInfo::
+getFreeGlobalMemory()
+{
+   size_t free = 0;
+   size_t total = 0;
+   cudaMemGetInfo( &free, &total );
+   return free;
+}
+
 int
 CudaDeviceInfo::
 getMemoryClockRate( int deviceNum )
diff --git a/src/TNL/Devices/CudaDeviceInfo.h b/src/TNL/Devices/CudaDeviceInfo.h
index 3bc7475727..c98f539572 100644
--- a/src/TNL/Devices/CudaDeviceInfo.h
+++ b/src/TNL/Devices/CudaDeviceInfo.h
@@ -34,6 +34,8 @@ class CudaDeviceInfo
 
       static size_t getGlobalMemory( int deviceNum );
 
+      static size_t getFreeGlobalMemory();
+
       static int getMemoryClockRate( int deviceNum );
 
       static bool getECCEnabled( int deviceNum );
-- 
GitLab