1 /* Copyright (C) 2018 Federico Simmross Wattenberg,
2 * Manuel Rodríguez Cayetano,
3 * Javier Royuela del Val,
4 * Elena Martín González,
6 * Marcos Martín Fernández and
7 * Carlos Alberola López
9 * This file is part of OpenCLIPER.
11 * OpenCLIPER is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 3 of the License.
15 * OpenCLIPER is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with OpenCLIPER; If not, see <http://www.gnu.org/licenses/>.
26 * Federico Simmross Wattenberg
27 * E.T.S.I. Telecomunicación
28 * Universidad de Valladolid
30 * 47011 Valladolid, Spain.
35 * @brief File with macros and type definitions used by several classes
37 #ifndef INCLUDE_OPENCLIPER_LPIDATAMODELCOMMONDEFS_HPP_
38 #define INCLUDE_OPENCLIPER_LPIDATAMODELCOMMONDEFS_HPP_
39 #include <OpenCLIPER/OpenCLIPERDataModelConfig.hpp>
42 #ifdef __cplusplus // OpenCL kernels may include this header and they only support C language syntax
46 #include <stdexcept> //g++ 4.8 doesn't seem to include <stdexcept> from <exception>
47 #include <memory> // for smart pointers
48 #include <chrono> // Execution times measurement
50 // Needed by libmatio, library for reading matlab data files (.mat)
57 /// Type for storing float point values
58 #define realType double
60 /// Type for storing float point values
61 #define realType float
65 #define IMAGEELELEMENTTYPE double4
67 /// Data type for an OpenCL image element
68 #define IMAGEELEMENTTYPE float4
71 /// Size of data type used for OpenCL vector operations (in number of elements)
72 #define VECTORDATATYPESIZE 16
74 #if defined(__APPLE__) || defined(__MACOSX)
75 #include<OpenCL/cl_platform.h>
77 #include<CL/cl_platform.h>
81 /// Position of width value in dimensions vector
83 /// Position of height value in dimensions vector
85 /// Position of depth value in dimensions vector
87 /// Macro for getting width of an ndarray object (returns 1 if that dimension is not defined)
88 #define NDARRAYWIDTH(ndarray) (((ndarray)->getNDims() > WIDTHPOS) ? ((ndarray)->getDims()->at(WIDTHPOS)) : (1))
89 /// Macro for getting height of an ndarray object (returns 1 if that dimension is not defined)
90 #define NDARRAYHEIGHT(ndarray) (((ndarray)->getNDims() > HEIGHTPOS) ? ((ndarray)->getDims()->at(HEIGHTPOS)) : (1))
91 /// Macro for getting depth of an ndarray object (returns 1 if that dimension is not defined)
92 #define NDARRAYDEPTH(ndarray) (((ndarray)->getNDims() > DEPTHPOS) ? ((ndarray)->getDims()->at(DEPTHPOS)) : (1))
93 /// Macro for getting first NDArray from a Data object
94 #define PNDARRAY0 getData()->at(0)
96 /// Type of array with Data dimensions information
97 typedef uint* dimsInfo_t;
99 /// Type of array with Data stride dimensions information
100 typedef uint* stridesInfo_t;
102 /// Minimum number of positions of dimensions info array
103 #define NUMINITIALPOSITIONSDIMSINFO 4
104 /// Known positions for array storing data dimensions (spatial, temporal and number of coils)
105 enum knownDimPos {NumSpatialDimsPos=0, AllSizesEqualPos=1, NumCoilsPos=2, NumTemporalDimsPos=3, FirstTemporalDimPos=4};
106 /// Known positions for array storing data strides (spatial, temporal and number of coils)
107 // Note: stride position for element and column are the same thing (sure!)
108 enum knownStridePos {ElementStridePos=0, FirstSpatialStridePos=0};
110 /// Known positions for spatial dimensions in array storing data dimensions
111 enum knownSpatialDimPos{COLUMNS=WIDTHPOS, ROWS=HEIGHTPOS, SLICES=DEPTHPOS};
113 #ifdef __cplusplus // OpenCL kernels may include this header and they only support C language syntax
114 /// Type used for storing complex values
115 #define complexType std::complex<realType>
117 #define set std::vector<bool>
119 using namespace std; // for using vector instead of std::vector everywhere
121 /// String with prefix for error messages (the name of the namespace)
122 #define ERRORNAMESPACEPREFIX "OpenCLIPER::"
123 /// Name of OpenCL kernels base dir based on project base directory from CMakeLists.txt
124 #define KERNEL_SOURCE_DIR PROJECT_SOURCE_DIR "/src/kernels"
125 /// Type for specifying fragments of images
126 #define FragmentSpecif uint8_t
128 /// Handle for a process bound to an OpenCL context
129 typedef unsigned int ProcessHandle;
130 /// Value for an invalid process handle
131 #define INVALIDPROCESSHANDLE 0
132 /// Value for first valid process handle
133 #define FIRSTVALIDPROCESSHANDLE (INVALIDPROCESSHANDLE+1)
135 /// Handle for a Data object bound to an OpenCL context
136 typedef unsigned int DataHandle;
137 /// Value for an invalid data handle
138 #define INVALIDDATAHANDLE 0
139 /// Value for first valid data handle
140 #define FIRSTVALIDDATAHANDLE (INVALIDDATAHANDLE+1)
142 /// data type for variables storing number of coils or coils index
143 typedef uint32_t numCoilsType;
145 /// data type for variables storing a 1-dimensional index calculated from indexes of several dimensions
146 typedef uint32_t index1DType;
148 /// data type for variables storing an index from a several dimensions image
149 typedef uint32_t dimIndexType;
151 /// data type for variables storing the number of dimensions of an image
152 typedef uint32_t numberOfDimensionsType;
154 #endif // __cplusplus
156 //typedef cl_uint indexType;
158 /// Macro for calculation of modulus of a complex number
159 #define MOD(complex) sqrt(pow((complex).real(), 2) + pow((complex).imag(), 2))
160 /// Macro for calculation of modulus of a real number
161 #define MODREALS(real1, real2) sqrt(pow((real1), 2) + pow((real2), 2))
162 /// Format used for storing complex numbers as image data with two color channels (one channel for the real part and the other for the imaginary part)
163 #define OPENCLCHANNELFORMAT CL_RG
165 /// Macro for declaring bT (begin time) variable and storing current time in it
166 #define BEGIN_TIME(bT) std::chrono::high_resolution_clock::time_point bT = \
167 std::chrono::high_resolution_clock::now();
168 /// Macro for declaring eT (end time) variable and storing current time in it
169 #define END_TIME(eT) std::chrono::high_resolution_clock::time_point eT = \
170 std::chrono::high_resolution_clock::now();
171 /// Data type for a number storing the difference between two time values
172 #define TIME_DIFF_TYPE double
173 /// Macro for calculation of time difference betweent eT and bT and storing result in diffT
174 #define TIME_DIFF(diffT, bT,eT) diffT = \
175 (std::chrono::duration_cast<std::chrono::nanoseconds>(eT - bT).count()) / 1e9
178 /// Main namespace of the OpenCLIPER framework
179 namespace OpenCLIPER {
181 /// Struct for storing messages related to performance analysis and debugging
183 /// title for the info element
185 /// value for the info element
189 /// Type storing a list of infoItem elements
190 typedef std::vector<InfoItem> InfoItems;
193 * @brief Enumerated type for device memory formats
195 * Enumerated type for describing device memory formats for storing data. Used by
196 * host2device method to get format of data to store in device memory and by
197 * device2host method to get format of data to be read from device memory.
199 enum class SyncSource {
200 /// Both buffer and image formats used (not valid for device2host method)
202 /// Buffer format used
204 /// Image format used
208 /// Default source of data (buffers, images, etc.)
209 #define SYNCSOURCEDEFAULT SyncSource::BUFFER_ONLY
213 /// Macro for printing a vector <i>vector</i> of type <i>baseType</i> prefixed by title <i>title</i>
214 #define PRINTVECTOR(labelText, vector, baseType) CERR((labelText) << ": ");\
215 std::copy((vector).begin(), (vector).end(), std::ostream_iterator<baseType>(std::cerr, " ")); CERR(std::endl);
216 /// Macro for printing an array <i>array</i> of size <i>size</i> prefixed by title <i>title</i>
217 #define PRINTARRAY(labelText, array, size) CERR(labelText << ": "); for (uint i = 0; i < (size); i++) CERR((array)[i] << " ");
219 /// @brief Data type of NDArray elements
220 typedef std::type_index ElementDataType;
221 #endif // __cplusplus
223 /// @brief Name of file with common (kernel/host) utility functions
224 #define HOSTKERNELFUNCTIONSFILE "hostKernelFunctions.cl"
226 #endif // INCLUDE_OPENCLIPER_LPIDATAMODELCOMMONDEFS_HPP_