Hex  2.2
Hydrogen-electron collision solver
GPUPreconditioner.h
Go to the documentation of this file.
1 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
2 // //
3 // / / / / __ \ \ / / //
4 // / /__ / / / _ \ \ \/ / //
5 // / ___ / | |/_/ / /\ \ //
6 // / / / / \_\ / / \ \ //
7 // //
8 // //
9 // Copyright (c) 2016, Jakub Benda, Charles University in Prague //
10 // //
11 // MIT License: //
12 // //
13 // Permission is hereby granted, free of charge, to any person obtaining a //
14 // copy of this software and associated documentation files (the "Software"), //
15 // to deal in the Software without restriction, including without limitation //
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense, //
17 // and/or sell copies of the Software, and to permit persons to whom the //
18 // Software is furnished to do so, subject to the following conditions: //
19 // //
20 // The above copyright notice and this permission notice shall be included //
21 // in all copies or substantial portions of the Software. //
22 // //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS //
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, //
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE //
26 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, //
27 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF //
28 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
29 // //
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 
32 #if (!defined(HEX_GPUPRECONDITIONER_H) && defined(WITH_OPENCL))
33 #define HEX_GPUPRECONDITIONER_H
34 
35 // --------------------------------------------------------------------------------- //
36 
37 #include <string>
38 
39 // --------------------------------------------------------------------------------- //
40 
41 #include <CL/cl.h>
42 
43 // --------------------------------------------------------------------------------- //
44 
45 #include "hex-arrays.h"
46 #include "hex-matrix.h"
47 
48 // --------------------------------------------------------------------------------- //
49 
50 #include "KPAPreconditioner.h"
51 
52 // --------------------------------------------------------------------------------- //
53 
54 #include "clarrays.h"
55 
56 // --------------------------------------------------------------------------------- //
57 
72 {
73  public:
74 
75  // run-time selection mechanism
77 
78  typedef struct sData
79  {
81  void hdflink (const char * file);
82 
84  bool hdfload (const char * file = nullptr);
85 
87  bool hdfsave (const char * file = nullptr) const;
88 
90  RowMatrix<Complex> invCl_invsqrtS, invsqrtS_Cl;
91 
93  cArray Dl;
94 
96  std::string filename;
97  } Data;
98 
99  // default constructor needed by the RTS mechanism
101 
102  // constructor
104  (
105  CommandLine const & cmd,
106  InputFile const & inp,
107  Parallel const & par,
108  AngularBasis const & ang,
109  Bspline const & bspline_inner,
110  Bspline const & bspline_full,
111  Bspline const & bspline_panel_x,
112  Bspline const & bspline_panel_y
113  ) : CGPreconditioner
114  (
115  cmd, inp, par, ang,
116  bspline_inner,
117  bspline_full,
118  bspline_panel_x,
119  bspline_panel_y
120  ),
122  (
123  cmd, inp, par, ang,
124  bspline_inner,
125  bspline_full,
126  bspline_panel_x,
127  bspline_panel_y
128  )
129  {
130  // nothing more to do
131  }
132 
133  // preconditioner description
134  virtual std::string description () const;
135 
136  // reuse parent definitions
139 
140  // declare own definitions
141  virtual void setup ();
142  virtual void finish ();
143  virtual void multiply (BlockArray<Complex> const & p, BlockArray<Complex> & q, MatrixSelection::Selection tri) const;
144  virtual void precondition (BlockArray<Complex> const & r, BlockArray<Complex> & z) const;
145 
146  protected:
147 
148  // OpenCL environment
149  cl_platform_id platform_;
150  cl_device_id device_;
151  cl_context context_;
152  cl_command_queue queue_;
153  cl_program program_;
154 
155  // size of a workgroup
156  std::size_t Nlocal_;
157  std::size_t blocksize_;
158 
159  // memory allocation flags
160  cl_mem_flags smallDataFlags_;
161  cl_mem_flags largeDataFlags_;
162 
163  // computational kernels
164  cl_kernel mabt_;
165  cl_kernel mml1_;
166  cl_kernel mml2_dcpl_, mml2_cpld_;
168  cl_kernel axby_;
169  cl_kernel norm_;
170  cl_kernel spro_;
171  cl_kernel krdv_;
172 
173  // device data connections
179  std::vector<clArrayView<Complex>> M_L_inner_a_, M_mLm1_inner_a_;
180  std::vector<clArrayView<Complex>> M_L_inner_p_, M_mLm1_inner_p_;
181  std::vector<clArrayView<LU_int_t>> R_coupled_p_, R_coupled_i_;
182  std::vector<clArrayView<Complex>> R_coupled_x_;
183 
184  cl_short nsrcseg_, ndstseg_;
185 };
186 
187 // --------------------------------------------------------------------------------- //
188 
189 #endif
clArray< Complex > tmA_
Definition: GPUPreconditioner.h:174
clArrayView< Complex > D_inner_p_
Definition: GPUPreconditioner.h:178
cl_mem_flags smallDataFlags_
Definition: GPUPreconditioner.h:160
clArrayView< Complex > t_inner_p_
Definition: GPUPreconditioner.h:176
virtual std::string description() const
Description of the preconditioner.
Definition: GPUPreconditioner.cpp:62
cl_mem_flags largeDataFlags_
Definition: GPUPreconditioner.h:161
cl_kernel norm_
Definition: GPUPreconditioner.h:169
GPUCGPreconditioner()
Definition: GPUPreconditioner.h:100
clArray< Complex > tmp_
Definition: GPUPreconditioner.h:174
B-spline environment.
Definition: bspline.h:57
cl_kernel spro_
Definition: GPUPreconditioner.h:170
Data
Definition: GPUPreconditioner.h:97
cl_kernel mml2_dcpl_
Definition: GPUPreconditioner.h:166
virtual void finish()
Clean up memory etc.
Definition: GPUPreconditioner.cpp:841
Angular basis.
Definition: ang.h:44
cl_kernel mml1_
Definition: GPUPreconditioner.h:165
virtual void update(Real E)
Update the preconditioner for the next energy.
Definition: NoPreconditioner.cpp:498
preconditionerRunTimeSelectionDefinitions(GPUCGPreconditioner, "GPU") typedef struct sData
Definition: GPUPreconditioner.h:76
cl_kernel axby_
Definition: GPUPreconditioner.h:168
cl_kernel mml2_dcpl_offset_
Definition: GPUPreconditioner.h:167
cl_device_id device_
Definition: GPUPreconditioner.h:150
Command line parameters.
Definition: io.h:57
std::size_t Nlocal_
Definition: GPUPreconditioner.h:156
std::vector< clArrayView< Complex > > M_L_inner_a_
Definition: GPUPreconditioner.h:179
clArrayView< Complex > Mm2_inner_a_
Definition: GPUPreconditioner.h:177
virtual void multiply(BlockArray< Complex > const &p, BlockArray< Complex > &q, MatrixSelection::Selection tri) const
Multiply by the matrix equation.
Definition: GPUPreconditioner.cpp:389
cl_short nsrcseg_
Definition: GPUPreconditioner.h:184
cl_kernel mml2_cpld_
Definition: GPUPreconditioner.h:166
KPACGPreconditioner(CommandLine const &cmd, InputFile const &inp, Parallel const &par, AngularBasis const &ang, Bspline const &bspline_inner, Bspline const &bspline_full, Bspline const &bspline_panel_x, Bspline const &bspline_panel_y)
Definition: KPAPreconditioner.h:78
cl_program program_
Definition: GPUPreconditioner.h:153
virtual void precondition(BlockArray< Complex > const &r, BlockArray< Complex > &z) const
Precondition the equation.
Definition: GPUPreconditioner.cpp:516
cl_kernel krdv_
Definition: GPUPreconditioner.h:171
virtual void rhs(BlockArray< Complex > &chi, int ienergy, int instate) const
Calculate the right-hand side.
Definition: NoPreconditioner.cpp:821
std::size_t blocksize_
Definition: GPUPreconditioner.h:157
KPA-preconditioned CG-preconditioner.
Definition: GPUPreconditioner.h:71
Input parameters.
Definition: io.h:321
clArrayView< Complex > D_inner_a_
Definition: GPUPreconditioner.h:177
clArrayView< Complex > Mm1_inner_p_
Definition: GPUPreconditioner.h:178
MPI info.
Definition: parallel.h:50
cl_kernel mabt_
Definition: GPUPreconditioner.h:164
cl_platform_id platform_
Definition: GPUPreconditioner.h:149
clArrayView< Complex > Mm1_inner_a_
Definition: GPUPreconditioner.h:177
KPA-preconditioned CG-preconditioner.
Definition: KPAPreconditioner.h:66
cl_command_queue queue_
Definition: GPUPreconditioner.h:152
std::vector< clArrayView< Complex > > M_mLm1_inner_p_
Definition: GPUPreconditioner.h:180
cl_context context_
Definition: GPUPreconditioner.h:151
clArrayView< Complex > S_inner_p_
Definition: GPUPreconditioner.h:178
clArray< Real > nrm_
Definition: GPUPreconditioner.h:175
cl_kernel mml2_cpld_offset_
Definition: GPUPreconditioner.h:167
std::vector< clArrayView< Complex > > R_coupled_x_
Definition: GPUPreconditioner.h:182
clArrayView< Complex > t_inner_a_
Definition: GPUPreconditioner.h:176
clArrayView< Complex > Mm2_inner_p_
Definition: GPUPreconditioner.h:178
std::vector< clArrayView< LU_int_t > > R_coupled_p_
Definition: GPUPreconditioner.h:181
cl_short ndstseg_
Definition: GPUPreconditioner.h:184
virtual void setup()
Initialize the preconditioner.
Definition: GPUPreconditioner.cpp:70
clArrayView< Complex > S_inner_a_
Definition: GPUPreconditioner.h:177
std::vector< clArrayView< Complex > > M_L_inner_p_
Definition: GPUPreconditioner.h:180
std::vector< clArrayView< Complex > > M_mLm1_inner_a_
Definition: GPUPreconditioner.h:179
std::vector< clArrayView< LU_int_t > > R_coupled_i_
Definition: GPUPreconditioner.h:181
CGPreconditioner(CommandLine const &cmd, InputFile const &inp, Parallel const &par, AngularBasis const &ang, Bspline const &bspline_inner, Bspline const &bspline_full, Bspline const &bspline_panel_x, Bspline const &bspline_panel_y)
Definition: CGPreconditioner.h:60