Hex: src/preconditioners/GPUPreconditioner.h Source File

| 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
71 class GPUCGPreconditioner : public virtual KPACGPreconditioner
72 {
73 public:
74
75 // run-time selection mechanism
76 preconditionerRunTimeSelectionDefinitions(GPUCGPreconditioner, "GPU")
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
100 GPUCGPreconditioner () {}
101
102 // constructor
103 GPUCGPreconditioner
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 ),
121 KPACGPreconditioner
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
137 using KPACGPreconditioner::rhs;
138 using KPACGPreconditioner::update;
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_;
167 cl_kernel mml2_dcpl_offset_, mml2_cpld_offset_;
168 cl_kernel axby_;
169 cl_kernel norm_;
170 cl_kernel spro_;
171 cl_kernel krdv_;
172
173 // device data connections
174 mutable clArray<Complex> tmp_, tmA_;
175 mutable clArray<Real> nrm_;
176 clArrayView<Complex> t_inner_a_, t_inner_p_;
177 clArrayView<Complex> S_inner_a_, D_inner_a_, Mm1_inner_a_, Mm2_inner_a_;
178 clArrayView<Complex> S_inner_p_, D_inner_p_, Mm1_inner_p_, Mm2_inner_p_;
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
GPUCGPreconditioner::tmA_
clArray< Complex > tmA_
Definition: GPUPreconditioner.h:174
GPUCGPreconditioner::D_inner_p_
clArrayView< Complex > D_inner_p_
Definition: GPUPreconditioner.h:178
GPUCGPreconditioner::smallDataFlags_
cl_mem_flags smallDataFlags_
Definition: GPUPreconditioner.h:160
GPUCGPreconditioner::t_inner_p_
clArrayView< Complex > t_inner_p_
Definition: GPUPreconditioner.h:176
GPUCGPreconditioner::description
virtual std::string description() const
Description of the preconditioner.
Definition: GPUPreconditioner.cpp:62
GPUCGPreconditioner::largeDataFlags_
cl_mem_flags largeDataFlags_
Definition: GPUPreconditioner.h:161
GPUCGPreconditioner::norm_
cl_kernel norm_
Definition: GPUPreconditioner.h:169
clarrays.h
GPUCGPreconditioner::GPUCGPreconditioner
GPUCGPreconditioner()
Definition: GPUPreconditioner.h:100
GPUCGPreconditioner::tmp_
clArray< Complex > tmp_
Definition: GPUPreconditioner.h:174
Bspline
B-spline environment.
Definition: bspline.h:57
GPUCGPreconditioner::spro_
cl_kernel spro_
Definition: GPUPreconditioner.h:170
GPUCGPreconditioner::Data
Data
Definition: GPUPreconditioner.h:97
GPUCGPreconditioner::mml2_dcpl_
cl_kernel mml2_dcpl_
Definition: GPUPreconditioner.h:166
GPUCGPreconditioner::finish
virtual void finish()
Clean up memory etc.
Definition: GPUPreconditioner.cpp:841
AngularBasis
Angular basis.
Definition: ang.h:44
GPUCGPreconditioner::mml1_
cl_kernel mml1_
Definition: GPUPreconditioner.h:165
NoPreconditioner::update
virtual void update(Real E)
Update the preconditioner for the next energy.
Definition: NoPreconditioner.cpp:498
GPUCGPreconditioner::preconditionerRunTimeSelectionDefinitions
preconditionerRunTimeSelectionDefinitions(GPUCGPreconditioner, "GPU") typedef struct sData
Definition: GPUPreconditioner.h:76
GPUCGPreconditioner::axby_
cl_kernel axby_
Definition: GPUPreconditioner.h:168
GPUCGPreconditioner::mml2_dcpl_offset_
cl_kernel mml2_dcpl_offset_
Definition: GPUPreconditioner.h:167
GPUCGPreconditioner::device_
cl_device_id device_
Definition: GPUPreconditioner.h:150
CommandLine
Command line parameters.
Definition: io.h:57
GPUCGPreconditioner::Nlocal_
std::size_t Nlocal_
Definition: GPUPreconditioner.h:156
GPUCGPreconditioner::M_L_inner_a_
std::vector< clArrayView< Complex > > M_L_inner_a_
Definition: GPUPreconditioner.h:179
GPUCGPreconditioner::Mm2_inner_a_
clArrayView< Complex > Mm2_inner_a_
Definition: GPUPreconditioner.h:177
GPUCGPreconditioner::multiply
virtual void multiply(BlockArray< Complex > const &p, BlockArray< Complex > &q, MatrixSelection::Selection tri) const
Multiply by the matrix equation.
Definition: GPUPreconditioner.cpp:389
GPUCGPreconditioner::nsrcseg_
cl_short nsrcseg_
Definition: GPUPreconditioner.h:184
clArray< Complex >
GPUCGPreconditioner::mml2_cpld_
cl_kernel mml2_cpld_
Definition: GPUPreconditioner.h:166
clArrayView< Complex >
KPACGPreconditioner::KPACGPreconditioner
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
GPUCGPreconditioner::program_
cl_program program_
Definition: GPUPreconditioner.h:153
GPUCGPreconditioner::precondition
virtual void precondition(BlockArray< Complex > const &r, BlockArray< Complex > &z) const
Precondition the equation.
Definition: GPUPreconditioner.cpp:516
GPUCGPreconditioner::krdv_
cl_kernel krdv_
Definition: GPUPreconditioner.h:171
NoPreconditioner::rhs
virtual void rhs(BlockArray< Complex > &chi, int ienergy, int instate) const
Calculate the right-hand side.
Definition: NoPreconditioner.cpp:821
GPUCGPreconditioner::blocksize_
std::size_t blocksize_
Definition: GPUPreconditioner.h:157
GPUCGPreconditioner
KPA-preconditioned CG-preconditioner.
Definition: GPUPreconditioner.h:71
InputFile
Input parameters.
Definition: io.h:321
GPUCGPreconditioner::D_inner_a_
clArrayView< Complex > D_inner_a_
Definition: GPUPreconditioner.h:177
GPUCGPreconditioner::Mm1_inner_p_
clArrayView< Complex > Mm1_inner_p_
Definition: GPUPreconditioner.h:178
Parallel
MPI info.
Definition: parallel.h:50
GPUCGPreconditioner::mabt_
cl_kernel mabt_
Definition: GPUPreconditioner.h:164
GPUCGPreconditioner::platform_
cl_platform_id platform_
Definition: GPUPreconditioner.h:149
GPUCGPreconditioner::Mm1_inner_a_
clArrayView< Complex > Mm1_inner_a_
Definition: GPUPreconditioner.h:177
KPACGPreconditioner
KPA-preconditioned CG-preconditioner.
Definition: KPAPreconditioner.h:66
GPUCGPreconditioner::queue_
cl_command_queue queue_
Definition: GPUPreconditioner.h:152
GPUCGPreconditioner::M_mLm1_inner_p_
std::vector< clArrayView< Complex > > M_mLm1_inner_p_
Definition: GPUPreconditioner.h:180
GPUCGPreconditioner::context_
cl_context context_
Definition: GPUPreconditioner.h:151
GPUCGPreconditioner::S_inner_p_
clArrayView< Complex > S_inner_p_
Definition: GPUPreconditioner.h:178
GPUCGPreconditioner::nrm_
clArray< Real > nrm_
Definition: GPUPreconditioner.h:175
GPUCGPreconditioner::mml2_cpld_offset_
cl_kernel mml2_cpld_offset_
Definition: GPUPreconditioner.h:167
GPUCGPreconditioner::R_coupled_x_
std::vector< clArrayView< Complex > > R_coupled_x_
Definition: GPUPreconditioner.h:182
GPUCGPreconditioner::t_inner_a_
clArrayView< Complex > t_inner_a_
Definition: GPUPreconditioner.h:176
GPUCGPreconditioner::Mm2_inner_p_
clArrayView< Complex > Mm2_inner_p_
Definition: GPUPreconditioner.h:178
GPUCGPreconditioner::R_coupled_p_
std::vector< clArrayView< LU_int_t > > R_coupled_p_
Definition: GPUPreconditioner.h:181
GPUCGPreconditioner::ndstseg_
cl_short ndstseg_
Definition: GPUPreconditioner.h:184
GPUCGPreconditioner::setup
virtual void setup()
Initialize the preconditioner.
Definition: GPUPreconditioner.cpp:70
GPUCGPreconditioner::S_inner_a_
clArrayView< Complex > S_inner_a_
Definition: GPUPreconditioner.h:177
GPUCGPreconditioner::M_L_inner_p_
std::vector< clArrayView< Complex > > M_L_inner_p_
Definition: GPUPreconditioner.h:180
KPAPreconditioner.h
GPUCGPreconditioner::M_mLm1_inner_a_
std::vector< clArrayView< Complex > > M_mLm1_inner_a_
Definition: GPUPreconditioner.h:179
GPUCGPreconditioner::R_coupled_i_
std::vector< clArrayView< LU_int_t > > R_coupled_i_
Definition: GPUPreconditioner.h:181
CGPreconditioner::CGPreconditioner
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