From 896116b233ee94f04f375f702813f43c1f462eb4 Mon Sep 17 00:00:00 2001
From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz>
Date: Mon, 15 Jul 2013 16:57:06 +0200
Subject: [PATCH] Refactoring the array operations.

---
 src/core/arrays/CMakeLists.txt                |   1 +
 src/core/arrays/tnlArrayOperations.h          | 154 ++++++++++++++++++
 .../core/vectors/tnlVectorOperationsTester.h  |   4 +-
 3 files changed, 156 insertions(+), 3 deletions(-)
 create mode 100644 src/core/arrays/tnlArrayOperations.h

diff --git a/src/core/arrays/CMakeLists.txt b/src/core/arrays/CMakeLists.txt
index 519dea4e2f..d922e8e712 100755
--- a/src/core/arrays/CMakeLists.txt
+++ b/src/core/arrays/CMakeLists.txt
@@ -1,4 +1,5 @@
 set( headers tnlArray.h
+             tnlArrayOperations.h
              tnlMultiArray.h
              tnlSharedArray.h )
 
diff --git a/src/core/arrays/tnlArrayOperations.h b/src/core/arrays/tnlArrayOperations.h
new file mode 100644
index 0000000000..5101b73cdc
--- /dev/null
+++ b/src/core/arrays/tnlArrayOperations.h
@@ -0,0 +1,154 @@
+/***************************************************************************
+                          tnlArrayOperationsTest.cpp  -  description
+                             -------------------
+    begin                : Jul 15, 2013
+    copyright            : (C) 2013 by Tomas Oberhuber
+    email                : tomas.oberhuber@fjfi.cvut.cz
+ ***************************************************************************/
+
+/***************************************************************************
+ *                                                                         *
+ *   This program is free software; you can redistribute it and/or modify  *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ ***************************************************************************/
+
+#ifndef TNLARRAYOPERATIONS_H_
+#define TNLARRAYOPERATIONS_H_
+
+#include <core/tnlHost.h>
+#include <core/tnlCuda.h>
+
+template< typename Device >
+class tnlArrayOperations{};
+
+template<>
+class tnlArrayOperations< tnlHost >
+{
+   public:
+
+   template< typename Element, typename Index >
+   static bool allocateMemory( Element*& data,
+                               const Index size );
+
+   template< typename Element >
+   bool freeMemory( Element* data );
+
+   template< typename Element, typename Index >
+   bool setMemory( Element* data,
+                       const Element& value,
+                       const Index size );
+
+   template< typename DestinationElement, typename SourceElement, typename Index >
+   bool copyMemoryToHost( DestinationElement* destination,
+                          const SourceElement* source,
+                          const Index size );
+
+   template< typename Element, typename Index >
+   bool copyMemoryToHost( Element* destination,
+                              const Element* source,
+                              const Index size );
+
+   template< typename DestinationElement, typename SourceElement, typename Index >
+   bool copyMemoryToCuda( DestinationElement* destination,
+                          const SourceElement* source,
+                          const Index size );
+
+   template< typename Element, typename Index >
+   bool copyMemoryToCuda( Element* destination,
+                              const Element* source,
+                              const Index size );
+
+   template< typename Element,
+             typename Index >
+   bool compareMemoryOnHost( const Element* data1,
+                           const Element* data2,
+                           const Index size );
+
+   template< typename Element1,
+             typename Element2,
+             typename Index >
+   bool compareMemoryOnHost( const Element1* data1,
+                           const Element2* data2,
+                           const Index size );
+
+   template< typename Element1,
+             typename Element2,
+             typename Index >
+   bool compareMemoryOnCuda( const Element1* hostData,
+                               const Element2* deviceData,
+                               const Index size );
+   template< typename Element,
+             typename Index >
+   bool compareMemoryOnCuda( const Element* deviceData1,
+                             const Element* deviceData2,
+                             const Index size );
+};
+
+template<>
+class tnlArrayOperations< tnlCuda >
+{
+   public:
+
+   template< typename Element, typename Index >
+   static bool allocateMemory( Element*& data,
+                               const Index size );
+
+   template< typename Element >
+   bool freeMemory( Element* data );
+
+   template< typename Element, typename Index >
+   bool setMemory( Element* data,
+                       const Element& value,
+                       const Index size );
+
+   template< typename DestinationElement, typename SourceElement, typename Index >
+   bool copyMemoryToHost( DestinationElement* destination,
+                          const SourceElement* source,
+                          const Index size );
+
+   template< typename Element, typename Index >
+   bool copyMemoryToHost( Element* destination,
+                              const Element* source,
+                              const Index size );
+
+   template< typename DestinationElement, typename SourceElement, typename Index >
+   bool copyMemoryToCuda( DestinationElement* destination,
+                          const SourceElement* source,
+                          const Index size );
+
+   template< typename Element, typename Index >
+   bool copyMemoryToCuda( Element* destination,
+                              const Element* source,
+                              const Index size );
+
+   template< typename Element,
+             typename Index >
+   bool compareMemoryOnHost( const Element* data1,
+                           const Element* data2,
+                           const Index size );
+
+   template< typename Element1,
+             typename Element2,
+             typename Index >
+   bool compareMemoryOnHost( const Element1* data1,
+                           const Element2* data2,
+                           const Index size );
+
+   template< typename Element1,
+             typename Element2,
+             typename Index >
+   bool compareMemoryOnCuda( const Element1* hostData,
+                               const Element2* deviceData,
+                               const Index size );
+   template< typename Element,
+             typename Index >
+   bool compareMemoryOnCuda( const Element* deviceData1,
+                             const Element* deviceData2,
+                             const Index size );
+};
+
+
+#endif /* TNLARRAYOPERATIONS_H_ */
diff --git a/tests/unit-tests/core/vectors/tnlVectorOperationsTester.h b/tests/unit-tests/core/vectors/tnlVectorOperationsTester.h
index 9da836ff19..a535a0573a 100644
--- a/tests/unit-tests/core/vectors/tnlVectorOperationsTester.h
+++ b/tests/unit-tests/core/vectors/tnlVectorOperationsTester.h
@@ -265,12 +265,10 @@ class tnlVectorOperationsTester : public CppUnit :: TestCase
       CPPUNIT_ASSERT( tnlVectorOperations< Device > :: getVectorDifferenceLpNorm( u, v, 1.0 ) == 2.0 * size );
       CPPUNIT_ASSERT( tnlVectorOperations< Device > :: getVectorDifferenceLpNorm( u, v, 2.0 ) == sqrt( 4.0 * size ) );
    }
-
-
 };
 
 #else
-template< typename Device >
+template< typename Real, typename Device >
 class tnlVectorOperationsTester
 {};
 #endif /* HAVE_CPPUNIT */
-- 
GitLab