| 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
CUDAParameters.h
Go to the documentation of this file.
1 /**
2 * @file CUDAParameters.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 for the class for setting CUDA kernel parameters.
10 *
11 * @version kspaceFirstOrder3D 3.4
12 *
13 * @date 12 November 2015, 16:49 (created) \n
14 * 25 July 2016, 13:17 (revised)
15 *
16 * @section License
17 * This file is part of the C++ extension of the k-Wave Toolbox
18 * (http://www.k-wave.org).\n Copyright (C) 2016 Jiri Jaros and Bradley Treeby.
19 *
20 * This file is part of the k-Wave. k-Wave is free software: you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as published by the Free Software
22 * Foundation, either version 3 of the License, or (at your option) any later version.
23 *
24 * k-Wave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
25 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
26 * General Public License for more details.
27 *
28 * You should have received a copy of the GNU Lesser General Public License along with k-Wave.
29 * If not, see http://www.gnu.org/licenses/.
30 */
31
32 #ifndef CUDA_PARAMETERS_H
33 #define CUDA_PARAMETERS_H
34
35 #include <cuda_runtime.h>
36
37 #include <Utils/DimensionSizes.h>
38
39
40 /**
41 * @class TCUDAParameters
42 * @brief Class responsible for CUDA runtime setup
43 * @details Class responsible for selecting a CUDA device, block and grid dimensions,
44 * etc. \n
45 * The class can only by constructed from inside TPrameters and there mustn't be more
46 * than 1 instance in the code
47 */
48 class TCUDAParameters
49 {
50 public:
51 /// Only TParameters can create this class.
52 friend class TParameters;
53 /// Destructor.
54 ~TCUDAParameters() {}
55
56 /// Get Idx of the device being used
57 int GetDeviceIdx() const { return deviceIdx; }
58 /// Get number of threads for 1D block used by kSpaceSolver.
59 int GetSolverBlockSize1D() const { return solverBlockSize1D; }
60 /// Get number of block for 1D grid used by kSpaceSolver.
61 int GetSolverGridSize1D() const { return solverGridSize1D; }
62
63 /// Get block size for the transposition kernels.
64 dim3 GetSolverTransposeBlockSize() const { return solverTransposeBlockSize;}
65 /// Get grid size for the transposition kernels.
66 dim3 GetSolverTransposeGirdSize() const { return solverTransposeGirdSize; }
67
68 /// Get number of threads for the 1D data sampling kernels.
69 int GetSamplerBlockSize1D() const { return samplerBlockSize1D; }
70 /// Get Number of blocks for the 1D data sampling kernels.
71 int GetSamplerGridSize1D() const { return samplerGridSize1D; }
72
73 /// Get the name of the device used.
74 std::string GetDeviceName() const;
75
76 /// Select cuda device for execution.
77 void SelectDevice(const int DeviceIdx = DEFAULT_DEVICE_IDX);
78
79 /// Set kernel configurations based on the simulation parameters.
80 void SetKernelConfiguration();
81
82 /// Upload useful simulation constants into device constant memory.
83 void SetUpDeviceConstants() const;
84
85 /// Return properties of currently used GPU
86 const cudaDeviceProp& GetDeviceProperties() const {return deviceProperties;};
87
88 /// Default Device Index - no default GPU
89 static const int DEFAULT_DEVICE_IDX = -1;
90
91 protected:
92 /// Default constructor - only friend class can create an instance.
93 TCUDAParameters();
94
95 /// Copy constructor not allowed for public.
96 TCUDAParameters(const TCUDAParameters& src);
97
98 /// operator = not allowed for public.
99 TCUDAParameters& operator = (const TCUDAParameters& src);
100
101 /// Check whether the CUDA driver version installed is sufficient for the code.
102 void CheckCUDAVersion();
103
104 /// Check whether the code was compiled for a given SM model.
105 bool CheckCUDACodeVersion();
106
107 private:
108
109 /// Index of the device the code is being run on.
110 int deviceIdx;
111
112 /// Number of threads for 1D block used by kSpaceSolver.
113 int solverBlockSize1D;
114 /// Number of block for 1D grid used by kSpaceSolver.
115 int solverGridSize1D;
116
117 /// Block size for the transposition kernels
118 dim3 solverTransposeBlockSize;
119 /// Grid size for the transposition kernels
120 dim3 solverTransposeGirdSize;
121
122 /// Number of threads for the 1D data sampling kernels
123 int samplerBlockSize1D;
124 /// Number of blocks for the 1D data sampling kernels
125 int samplerGridSize1D;
126
127 /// Device properties of the selected GPU.
128 cudaDeviceProp deviceProperties;
129
130 /// Undefined block or grid size
131 static const int UNDEFINDED_SIZE = -1;
132
133 };// end of TCUDAParameters
134 //--------------------------------------------------------------------------------------------------
135
136 #endif /* CUDA_PARAMETERS_H */
137
TCUDAParameters::samplerGridSize1D
int samplerGridSize1D
Number of blocks for the 1D data sampling kernels.
Definition: CUDAParameters.h:125
TCUDAParameters::solverTransposeBlockSize
dim3 solverTransposeBlockSize
Block size for the transposition kernels.
Definition: CUDAParameters.h:118
TCUDAParameters::GetSamplerGridSize1D
int GetSamplerGridSize1D() const
Get Number of blocks for the 1D data sampling kernels.
Definition: CUDAParameters.h:71
TCUDAParameters::deviceIdx
int deviceIdx
Index of the device the code is being run on.
Definition: CUDAParameters.h:110
TCUDAParameters::solverTransposeGirdSize
dim3 solverTransposeGirdSize
Grid size for the transposition kernels.
Definition: CUDAParameters.h:120
TCUDAParameters::DEFAULT_DEVICE_IDX
static const int DEFAULT_DEVICE_IDX
Default Device Index - no default GPU.
Definition: CUDAParameters.h:89
TCUDAParameters::samplerBlockSize1D
int samplerBlockSize1D
Number of threads for the 1D data sampling kernels.
Definition: CUDAParameters.h:123
TCUDAParameters::SetUpDeviceConstants
void SetUpDeviceConstants() const
Upload useful simulation constants into device constant memory.
Definition: CUDAParameters.cpp:254
TCUDAParameters::GetSolverTransposeBlockSize
dim3 GetSolverTransposeBlockSize() const
Get block size for the transposition kernels.
Definition: CUDAParameters.h:64
TCUDAParameters::solverBlockSize1D
int solverBlockSize1D
Number of threads for 1D block used by kSpaceSolver.
Definition: CUDAParameters.h:113
TCUDAParameters
Class responsible for CUDA runtime setup.
Definition: CUDAParameters.h:48
TCUDAParameters::GetDeviceName
std::string GetDeviceName() const
Get the name of the device used.
Definition: CUDAParameters.cpp:73
TCUDAParameters::operator=
TCUDAParameters & operator=(const TCUDAParameters &src)
operator = not allowed for public.
TCUDAParameters::SelectDevice
void SelectDevice(const int DeviceIdx=DEFAULT_DEVICE_IDX)
Select cuda device for execution.
Definition: CUDAParameters.cpp:90
TCUDAParameters::TCUDAParameters
TCUDAParameters()
Default constructor - only friend class can create an instance.
Definition: CUDAParameters.cpp:51
TParameters
Class storing all parameters of the simulation.
Definition: Parameters.h:49
TCUDAParameters::UNDEFINDED_SIZE
static const int UNDEFINDED_SIZE
Undefined block or grid size.
Definition: CUDAParameters.h:131
TCUDAParameters::GetSamplerBlockSize1D
int GetSamplerBlockSize1D() const
Get number of threads for the 1D data sampling kernels.
Definition: CUDAParameters.h:69
DimensionSizes.h
The header file containing the structure with 3D dimension sizes.
TCUDAParameters::GetSolverGridSize1D
int GetSolverGridSize1D() const
Get number of block for 1D grid used by kSpaceSolver.
Definition: CUDAParameters.h:61
TCUDAParameters::GetDeviceIdx
int GetDeviceIdx() const
Get Idx of the device being used.
Definition: CUDAParameters.h:57
TCUDAParameters::GetSolverTransposeGirdSize
dim3 GetSolverTransposeGirdSize() const
Get grid size for the transposition kernels.
Definition: CUDAParameters.h:66
TCUDAParameters::GetSolverBlockSize1D
int GetSolverBlockSize1D() const
Get number of threads for 1D block used by kSpaceSolver.
Definition: CUDAParameters.h:59
TCUDAParameters::deviceProperties
cudaDeviceProp deviceProperties
Device properties of the selected GPU.
Definition: CUDAParameters.h:128
TCUDAParameters::solverGridSize1D
int solverGridSize1D
Number of block for 1D grid used by kSpaceSolver.
Definition: CUDAParameters.h:115
TCUDAParameters::~TCUDAParameters
~TCUDAParameters()
Destructor.
Definition: CUDAParameters.h:54
TCUDAParameters::CheckCUDAVersion
void CheckCUDAVersion()
Check whether the CUDA driver version installed is sufficient for the code.
Definition: CUDAParameters.cpp:321
TCUDAParameters::SetKernelConfiguration
void SetKernelConfiguration()
Set kernel configurations based on the simulation parameters.
Definition: CUDAParameters.cpp:197
TCUDAParameters::GetDeviceProperties
const cudaDeviceProp & GetDeviceProperties() const
Return properties of currently used GPU.
Definition: CUDAParameters.h:86
TCUDAParameters::CheckCUDACodeVersion
bool CheckCUDACodeVersion()
Check whether the code was compiled for a given SM model.
Definition: CUDAParameters.cpp:350