kspaceFirstOrder3D-CUDA  1.1
The CUDA/C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
BaseFloatMatrix.h
Go to the documentation of this file.
1 /**
2  * @file BaseFloatMatrix.h
3  *
4  * @author Jiri Jaros \n
5  * Faculty of Information Technology \n
6  * Brno University of Technology \n
7  * jarosjir@fit.vutbr.cz
8  *
9  * @brief The header file containing the base class for single precisions floating point
10  * numbers (floats).
11  *
12  * @version kspaceFirstOrder3D 3.4
13  *
14  * @date 11 July 2011, 12:13 (created) \n
15  * 29 July 2016, 16:50 (revised)
16  *
17  * @section License
18  * This file is part of the C++ extension of the k-Wave Toolbox
19  * (http://www.k-wave.org).\n Copyright (C) 2016 Jiri Jaros and Bradley Treeby.
20  *
21  * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify
22  * it under the terms of the GNU Lesser General Public License as published by the Free Software
23  * Foundation, either version 3 of the License, or (at your option) any later version.
24  *
25  * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
26  * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
27  * General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
30  * If not, see http://www.gnu.org/licenses/.
31  */
32 
33 #ifndef BASE_FLOAT_MATRIX_H
34 #define BASE_FLOAT_MATRIX_H
35 
37 #include <Utils/DimensionSizes.h>
38 
39 
40 /**
41  * @class TBaseFloatMatrix
42  * @brief Abstract base class for float based matrices defining basic interface. Higher dimensional
43  * matrices stored as 1D arrays, row-major order.
44  *
45  * @details Abstract base class for float based matrices defining basic interface. Higher
46  * dimensional matrices stored as 1D arrays, row-major order.Implemented both on
47  * CPU and GPU side.
48  */
50 {
51  public:
52  /// Default constructor.
54  //Destructor.
55  virtual ~TBaseFloatMatrix() {};
56 
57  /// Get dimension sizes of the matrix.
59  {
60  return dimensionSizes;
61  }
62 
63  /// Get element count of the matrix.
64  virtual size_t GetElementCount() const
65  {
66  return nElements;
67  };
68 
69  /// Get total allocated element count (might differ from total element count used for the simulation because of padding).
70  virtual size_t GetAllocatedElementCount() const
71  {
72  return nAllocatedElements;
73  };
74 
75  /// Zero all elements of the matrix (NUMA first touch).
76  virtual void ZeroMatrix();
77 
78  /// Divide scalar/ matrix_element[i].
79  virtual void ScalarDividedBy(const float scalar);
80 
81 
82  /// Get raw CPU data out of the class (for direct CPU kernel access).
83  virtual float* GetHostData()
84  {
85  return hostData;
86  }
87 
88  /// Get raw CPU data out of the class (for direct CPU kernel access).
89  virtual const float* GetHostData() const
90  {
91  return hostData;
92  }
93 
94  /// Get raw GPU data out of the class (for direct GPU kernel access).
95  virtual float* GetDeviceData()
96  {
97  return deviceData;
98  }
99 
100  /// Get raw GPU data out of the class (for direct GPU kernel access).
101  virtual const float* GetDeviceData() const
102  {
103  return deviceData;
104  }
105 
106  /// Copy data from CPU -> GPU (Host -> Device).
107  virtual void CopyToDevice();
108  /// Copy data from GPU -> CPU (Device -> Host).
109  virtual void CopyFromDevice();
110 
111 
112  protected:
113 
114  /// Memory allocation (both on CPU and GPU).
115  virtual void AllocateMemory();
116  /// Memory allocation (both on CPU and GPU).
117  virtual void FreeMemory();
118 
119  /// Copy constructor is not directly allowed.
121  /// Operator = is not directly allowed.
123 
124  /// Total number of elements.
125  size_t nElements;
126  /// Total number of allocated elements (in terms of floats).
128 
129  /// Dimension sizes.
131 
132  /// Size of a 1D row in X dimension.
133  size_t dataRowSize;
134  /// Size of a 2D slab.
135  size_t dataSlabSize;
136 
137  /// Raw CPU matrix data.
138  float* hostData;
139  /// Raw GPU matrix data.
140  float* deviceData;
141 
142  private:
143 
144 };//end of class TBaseFloatMatrix
145 //--------------------------------------------------------------------------------------------------
146 
147 #endif /* BASE_FLOAT_MATRIX_H */
Abstract base class for float based matrices defining basic interface. Higher dimensional matrices st...
float * hostData
Raw CPU matrix data.
virtual void FreeMemory()
Memory allocation (both on CPU and GPU).
Abstract base class. The common ancestor defining the common interface and allowing derived classes t...
Definition: BaseMatrix.h:48
virtual void ZeroMatrix()
Zero all elements of the matrix (NUMA first touch).
virtual void AllocateMemory()
Memory allocation (both on CPU and GPU).
struct TDimensionSizes dimensionSizes
Dimension sizes.
TBaseFloatMatrix()
Default constructor.
virtual const float * GetDeviceData() const
Get raw GPU data out of the class (for direct GPU kernel access).
virtual size_t GetElementCount() const
Get element count of the matrix.
virtual float * GetHostData()
Get raw CPU data out of the class (for direct CPU kernel access).
size_t nAllocatedElements
Total number of allocated elements (in terms of floats).
virtual const float * GetHostData() const
Get raw CPU data out of the class (for direct CPU kernel access).
virtual TDimensionSizes GetDimensionSizes() const
Get dimension sizes of the matrix.
float * deviceData
Raw GPU matrix data.
size_t nElements
Total number of elements.
The header file containing the structure with 3D dimension sizes.
virtual size_t GetAllocatedElementCount() const
Get total allocated element count (might differ from total element count used for the simulation beca...
TBaseFloatMatrix & operator=(const TBaseFloatMatrix &src)
Operator = is not directly allowed.
size_t dataRowSize
Size of a 1D row in X dimension.
virtual float * GetDeviceData()
Get raw GPU data out of the class (for direct GPU kernel access).
virtual void CopyToDevice()
Copy data from CPU -> GPU (Host -> Device).
virtual void ScalarDividedBy(const float scalar)
Divide scalar/ matrix_element[i].
virtual void CopyFromDevice()
Copy data from GPU -> CPU (Device -> Host).
size_t dataSlabSize
Size of a 2D slab.
The header file of the common ancestor of all matrix classes. A pure abstract class.
Structure with 4D dimension sizes (3 in space and 1 in time).