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
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  */
49 {
50  public:
51  /// Only TParameters can create this class.
52  friend class TParameters;
53  /// Destructor.
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.
65  /// Get grid size for the transposition kernels.
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.
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.
94 
95  /// Copy constructor not allowed for public.
96  TCUDAParameters(const TCUDAParameters& src);
97 
98  /// operator = not allowed for public.
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.
111 
112  /// Number of threads for 1D block used by kSpaceSolver.
114  /// Number of block for 1D grid used by kSpaceSolver.
116 
117  /// Block size for the transposition kernels
119  /// Grid size for the transposition kernels
121 
122  /// Number of threads for the 1D data sampling kernels
124  /// Number of blocks for the 1D data sampling kernels
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 
int samplerGridSize1D
Number of blocks for the 1D data sampling kernels.
dim3 solverTransposeBlockSize
Block size for the transposition kernels.
int GetSamplerGridSize1D() const
Get Number of blocks for the 1D data sampling kernels.
int deviceIdx
Index of the device the code is being run on.
dim3 solverTransposeGirdSize
Grid size for the transposition kernels.
static const int DEFAULT_DEVICE_IDX
Default Device Index - no default GPU.
int samplerBlockSize1D
Number of threads for the 1D data sampling kernels.
void SetUpDeviceConstants() const
Upload useful simulation constants into device constant memory.
dim3 GetSolverTransposeBlockSize() const
Get block size for the transposition kernels.
int solverBlockSize1D
Number of threads for 1D block used by kSpaceSolver.
Class responsible for CUDA runtime setup.
std::string GetDeviceName() const
Get the name of the device used.
TCUDAParameters & operator=(const TCUDAParameters &src)
operator = not allowed for public.
void SelectDevice(const int DeviceIdx=DEFAULT_DEVICE_IDX)
Select cuda device for execution.
TCUDAParameters()
Default constructor - only friend class can create an instance.
Class storing all parameters of the simulation.
Definition: Parameters.h:49
static const int UNDEFINDED_SIZE
Undefined block or grid size.
int GetSamplerBlockSize1D() const
Get number of threads for the 1D data sampling kernels.
The header file containing the structure with 3D dimension sizes.
int GetSolverGridSize1D() const
Get number of block for 1D grid used by kSpaceSolver.
int GetDeviceIdx() const
Get Idx of the device being used.
dim3 GetSolverTransposeGirdSize() const
Get grid size for the transposition kernels.
int GetSolverBlockSize1D() const
Get number of threads for 1D block used by kSpaceSolver.
cudaDeviceProp deviceProperties
Device properties of the selected GPU.
int solverGridSize1D
Number of block for 1D grid used by kSpaceSolver.
~TCUDAParameters()
Destructor.
void CheckCUDAVersion()
Check whether the CUDA driver version installed is sufficient for the code.
void SetKernelConfiguration()
Set kernel configurations based on the simulation parameters.
const cudaDeviceProp & GetDeviceProperties() const
Return properties of currently used GPU.
bool CheckCUDACodeVersion()
Check whether the code was compiled for a given SM model.