base_paralution.hpp 3.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
// **************************************************************************
//
//    PARALUTION   www.paralution.com
//
//    Copyright (C) 2015  PARALUTION Labs UG (haftungsbeschränkt) & Co. KG
//                        Am Hasensprung 6, 76571 Gaggenau
//                        Handelsregister: Amtsgericht Mannheim, HRA 706051
//                        Vertreten durch:
//                        PARALUTION Labs Verwaltungs UG (haftungsbeschränkt)
//                        Am Hasensprung 6, 76571 Gaggenau
//                        Handelsregister: Amtsgericht Mannheim, HRB 721277
//                        Geschäftsführer: Dimitar Lukarski, Nico Trost
//
//    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 3 of the License, or
//    (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program.  If not, see <http://www.gnu.org/licenses/>.
//
// **************************************************************************



// PARALUTION version 1.1.0 


#ifndef PARALUTION_BASE_HPP_
#define PARALUTION_BASE_HPP_

#include "backend_manager.hpp"

#include <complex>
#include <vector>

namespace paralution {

class ParalutionObj {

public:

  ParalutionObj();
  virtual ~ParalutionObj();

  /// Clear (free all data) the object
  virtual void Clear() = 0;

protected:
  size_t global_obj_id;

};

/// Global data for all PARALUTION objects
struct Paralution_Object_Data {
  
  std::vector<class ParalutionObj*> all_obj;

};

/// Global obj tracking structure
extern struct Paralution_Object_Data Paralution_Object_Data_Tracking;

/// Base class for operator and vector 
/// (i.e. global/local matrix/stencil/vector) classes,
/// all the backend-related interface and data 
/// are defined here
template <typename ValueType>
class BaseParalution : public ParalutionObj {

public:

  BaseParalution();
  BaseParalution(const BaseParalution<ValueType> &src);
  virtual ~BaseParalution();

  BaseParalution<ValueType>& operator=(const BaseParalution<ValueType> &src);

  /// Move the object to the Accelerator backend
  virtual void MoveToAccelerator(void) = 0;

  /// Move the object to the Host backend
  virtual void MoveToHost(void) = 0;

  /// Move the object to the Accelerator backend with async move
  virtual void MoveToAcceleratorAsync(void);

  /// Move the object to the Host backend with async move
  virtual void MoveToHostAsync(void);

  // Sync (the async move)
  virtual void Sync(void);

  /// Clone the Backend descriptor from another object
  void CloneBackend(const BaseParalution<ValueType> &src);

  /// Clone the Backend descriptor from another object with different template ValueType
  template <typename ValueType2>
  void CloneBackend(const BaseParalution<ValueType2> &src);

  /// Print the object information (properties, backends)
  virtual void info() const = 0;

  /// Clear (free all data) the object
  virtual void Clear() = 0;

protected:

  /// Name of the object
  std::string object_name_;

  /// Backend descriptor 
  Paralution_Backend_Descriptor local_backend_;

  /// Return true if the object is on the host
  virtual bool is_host(void) const = 0;

  /// Return true if the object is on the accelerator
  virtual bool is_accel(void) const = 0;

  // active async transfer
  bool asyncf;

  friend class BaseParalution<double>;
  friend class BaseParalution<float>;
  friend class BaseParalution<std::complex<double> >;
  friend class BaseParalution<std::complex<float> >;

  friend class BaseParalution<int>;

};


}

#endif // PARALUTION_LOCAL_BASE_HPP_