| kspaceFirstOrder3D-CUDA 1.1 The CUDA/C++ implementation of the k-wave toolbox for the time-domain simulation of acoustic wave fields in 3D

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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
36 #include <MatrixClasses/BaseMatrix.h>
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 */
49 class TBaseFloatMatrix : public TBaseMatrix
50 {
51 public:
52 /// Default constructor.
53 TBaseFloatMatrix();
54 //Destructor.
55 virtual ~TBaseFloatMatrix() {};
56
57 /// Get dimension sizes of the matrix.
58 virtual TDimensionSizes GetDimensionSizes() const
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.
120 TBaseFloatMatrix(const TBaseFloatMatrix& src);
121 /// Operator = is not directly allowed.
122 TBaseFloatMatrix& operator =(const TBaseFloatMatrix& src);
123
124 /// Total number of elements.
125 size_t nElements;
126 /// Total number of allocated elements (in terms of floats).
127 size_t nAllocatedElements;
128
129 /// Dimension sizes.
130 struct TDimensionSizes dimensionSizes;
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 */
TBaseFloatMatrix
Abstract base class for float based matrices defining basic interface. Higher dimensional matrices st...
Definition: BaseFloatMatrix.h:49
TBaseFloatMatrix::hostData
float * hostData
Raw CPU matrix data.
Definition: BaseFloatMatrix.h:138
TBaseFloatMatrix::FreeMemory
virtual void FreeMemory()
Memory allocation (both on CPU and GPU).
Definition: BaseFloatMatrix.cpp:162
TBaseMatrix
Abstract base class. The common ancestor defining the common interface and allowing derived classes t...
Definition: BaseMatrix.h:48
TBaseFloatMatrix::ZeroMatrix
virtual void ZeroMatrix()
Zero all elements of the matrix (NUMA first touch).
Definition: BaseFloatMatrix.cpp:73
TBaseFloatMatrix::AllocateMemory
virtual void AllocateMemory()
Memory allocation (both on CPU and GPU).
Definition: BaseFloatMatrix.cpp:133
TBaseFloatMatrix::dimensionSizes
struct TDimensionSizes dimensionSizes
Dimension sizes.
Definition: BaseFloatMatrix.h:130
TBaseFloatMatrix::TBaseFloatMatrix
TBaseFloatMatrix()
Default constructor.
Definition: BaseFloatMatrix.cpp:56
TBaseFloatMatrix::GetDeviceData
virtual const float * GetDeviceData() const
Get raw GPU data out of the class (for direct GPU kernel access).
Definition: BaseFloatMatrix.h:101
TBaseFloatMatrix::GetElementCount
virtual size_t GetElementCount() const
Get element count of the matrix.
Definition: BaseFloatMatrix.h:64
TBaseFloatMatrix::GetHostData
virtual float * GetHostData()
Get raw CPU data out of the class (for direct CPU kernel access).
Definition: BaseFloatMatrix.h:83
TBaseFloatMatrix::nAllocatedElements
size_t nAllocatedElements
Total number of allocated elements (in terms of floats).
Definition: BaseFloatMatrix.h:127
TBaseFloatMatrix::GetHostData
virtual const float * GetHostData() const
Get raw CPU data out of the class (for direct CPU kernel access).
Definition: BaseFloatMatrix.h:89
TBaseFloatMatrix::GetDimensionSizes
virtual TDimensionSizes GetDimensionSizes() const
Get dimension sizes of the matrix.
Definition: BaseFloatMatrix.h:58
TBaseFloatMatrix::deviceData
float * deviceData
Raw GPU matrix data.
Definition: BaseFloatMatrix.h:140
TBaseFloatMatrix::nElements
size_t nElements
Total number of elements.
Definition: BaseFloatMatrix.h:125
DimensionSizes.h
The header file containing the structure with 3D dimension sizes.
TBaseFloatMatrix::GetAllocatedElementCount
virtual size_t GetAllocatedElementCount() const
Get total allocated element count (might differ from total element count used for the simulation beca...
Definition: BaseFloatMatrix.h:70
TBaseFloatMatrix::operator=
TBaseFloatMatrix & operator=(const TBaseFloatMatrix &src)
Operator = is not directly allowed.
TBaseFloatMatrix::dataRowSize
size_t dataRowSize
Size of a 1D row in X dimension.
Definition: BaseFloatMatrix.h:133
TBaseFloatMatrix::GetDeviceData
virtual float * GetDeviceData()
Get raw GPU data out of the class (for direct GPU kernel access).
Definition: BaseFloatMatrix.h:95
TBaseFloatMatrix::CopyToDevice
virtual void CopyToDevice()
Copy data from CPU -> GPU (Host -> Device).
Definition: BaseFloatMatrix.cpp:102
TBaseFloatMatrix::ScalarDividedBy
virtual void ScalarDividedBy(const float scalar)
Divide scalar/ matrix_element[i].
Definition: BaseFloatMatrix.cpp:88
TBaseFloatMatrix::CopyFromDevice
virtual void CopyFromDevice()
Copy data from GPU -> CPU (Device -> Host).
Definition: BaseFloatMatrix.cpp:115
TBaseFloatMatrix::dataSlabSize
size_t dataSlabSize
Size of a 2D slab.
Definition: BaseFloatMatrix.h:135
BaseMatrix.h
The header file of the common ancestor of all matrix classes. A pure abstract class.
TDimensionSizes
Structure with 4D dimension sizes (3 in space and 1 in time).
Definition: DimensionSizes.h:66