vSMC
vSMC: Scalable Monte Carlo
adapter.hpp
Go to the documentation of this file.
1 //============================================================================
2 // vSMC/include/vsmc/opencl/adapter.hpp
3 //----------------------------------------------------------------------------
4 // vSMC: Scalable Monte Carlo
5 //----------------------------------------------------------------------------
6 // Copyright (c) 2013,2014, Yan Zhou
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 // POSSIBILITY OF SUCH DAMAGE.
30 //============================================================================
31 
32 #ifndef VSMC_OPENCL_ADAPTER_HPP
33 #define VSMC_OPENCL_ADAPTER_HPP
34 
35 #include <vsmc/internal/common.hpp>
36 #include <vsmc/core/adapter.hpp>
38 
39 namespace vsmc {
40 
43 template <typename T, typename F>
45  public InitializeAdapterBase<T, F, InitializeCL<T> >
46 {
48 
49  public :
50 
52 
53  InitializeAdapter (const F &f) : base(f) {}
54 
55  void initialize_state (std::string &kernel_name)
56  {return this->implementation().initialize_state(kernel_name);}
57 }; // InitializeAdapter
58 
61 template <typename T, typename F>
62 class MoveAdapter<T, MoveCL, F> : public MoveAdapterBase<T, F, MoveCL<T> >
63 {
65 
66  public :
67 
69 
70  MoveAdapter (const F &f) : base(f) {}
71 
72  void move_state (std::size_t iter, std::string &kernel_name)
73  {return this->implementation().move_state(iter, kernel_name);}
74 }; // MoveAdapter
75 
78 template <typename T, typename F>
80  public MonitorEvalAdapterBase<T, F, MonitorEvalCL<T> >
81 {
83 
84  public :
85 
87 
88  MonitorEvalAdapter (const F &f) : base(f) {}
89 
90  void move_state (std::size_t iter, std::string &kernel_name)
91  {this->implementation().monitor_state(iter, kernel_name);}
92 }; // MonitorEvalAdapter
93 
96 template <typename T, typename F>
98  public PathEvalAdapterBase<T, F, PathEvalCL<T> >
99 {
101 
102  public :
103 
105 
106  PathEvalAdapter (const F &f) : base(f) {}
107 
108  void path_state (std::size_t iter, std::string &kernel_name)
109  {return this->implementation().path_state(iter, kernel_name);}
110 }; // PathEvalAdapter
111 
114 template <typename T>
116  public InitializeAdapterBase<T, NullType, InitializeCL<T> >
117 {
119 
120  public :
121 
122  typedef typename base::initialize_param_type initialize_param_type;
123  typedef typename base::pre_processor_type pre_processor_type;
124  typedef typename base::post_processor_type post_processor_type;
125 
126  InitializeAdapter (const std::string &init_state,
127  const initialize_param_type &init_param = initialize_param_type(),
128  const pre_processor_type &pre = pre_processor_type(),
129  const post_processor_type &post = post_processor_type()) :
130  base(init_param, pre, post), initialize_state_(init_state) {}
131 
132  void initialize_state (std::string &kernel_name)
133  {kernel_name = initialize_state_;}
134 
135  private :
136 
137  const std::string initialize_state_;
138 }; // class InitializeAdapter
139 
142 template <typename T>
144  public MoveAdapterBase<T, NullType, MoveCL<T> >
145 {
147 
148  public :
149 
150  typedef typename base::pre_processor_type pre_processor_type;
151  typedef typename base::post_processor_type post_processor_type;
152 
153  MoveAdapter (const std::string &move_state,
154  const pre_processor_type &pre = pre_processor_type(),
155  const post_processor_type &post = post_processor_type()) :
156  base(pre, post), move_state_(move_state) {}
157 
158  void move_state (std::size_t, std::string &kernel_name)
159  {kernel_name = move_state_;}
160 
161  private :
162 
163  const std::string move_state_;
164 }; // class MoveAdapter
165 
168 template <typename T>
170  public MonitorEvalAdapterBase<T, NullType, MonitorEvalCL<T> >
171 {
173 
174  public :
175 
176  typedef typename base::pre_processor_type pre_processor_type;
177  typedef typename base::post_processor_type post_processor_type;
178 
179  MonitorEvalAdapter (const std::string &monitor_state,
180  const pre_processor_type &pre = pre_processor_type(),
181  const post_processor_type &post = post_processor_type()) :
182  base(pre, post), monitor_state_(monitor_state) {}
183 
184  void monitor_state (std::size_t, std::string &kernel_name)
185  {kernel_name = monitor_state_;}
186 
187  private :
188 
189  const std::string monitor_state_;
190 }; // class MonitorEvalAdapter
191 
194 template <typename T>
196  public PathEvalAdapterBase<T, NullType, PathEvalCL<T> >
197 {
199 
200  public :
201 
202  typedef typename base::path_grid_type path_grid_type;
203  typedef typename base::pre_processor_type pre_processor_type;
204  typedef typename base::post_processor_type post_processor_type;
205 
206  PathEvalAdapter (const std::string &path_state,
207  const path_grid_type &path_grid,
208  const pre_processor_type &pre = pre_processor_type(),
209  const post_processor_type &post = post_processor_type()) :
210  base(path_grid, pre, post), path_state_(path_state) {}
211 
212  void path_state (std::size_t, std::string &kernel_name)
213  {kernel_name = path_state_;}
214 
215  private :
216 
217  const std::string path_state_;
218 }; // class PathEvalAdapter
219 
220 } // namespace vsmc
221 
222 #endif // VSMC_OPENCL_ADAPTER_HPP
base::post_processor_type post_processor_type
Definition: adapter.hpp:204
MonitorEvalAdapter(const std::string &monitor_state, const pre_processor_type &pre=pre_processor_type(), const post_processor_type &post=post_processor_type())
Definition: adapter.hpp:179
Definition: adapter.hpp:37
std::size_t move_state(std::size_t iter, SingleParticle< T > part)
Definition: adapter.hpp:76
void monitor_state(std::size_t, std::string &kernel_name)
Definition: adapter.hpp:184
void path_state(std::size_t, std::string &kernel_name)
Definition: adapter.hpp:212
void move_state(std::size_t iter, std::string &kernel_name)
Definition: adapter.hpp:90
double path_state(std::size_t iter, ConstSingleParticle< T > part)
Definition: adapter.hpp:117
void move_state(std::size_t iter, std::string &kernel_name)
Definition: adapter.hpp:72
Monitor evaluation base.
Definition: adapter.hpp:163
base::pre_processor_type pre_processor_type
Definition: adapter.hpp:150
Path evaluation class base.
Definition: adapter.hpp:213
Initialize class adapter base.
Definition: adapter.hpp:51
Path evaluation class adapter.
Definition: adapter.hpp:46
Monitor::eval_type subtype using OpenCL.
Definition: backend_cl.hpp:735
Sampler::move_type subtype using OpenCL.
Definition: backend_cl.hpp:639
void path_state(std::size_t iter, std::string &kernel_name)
Definition: adapter.hpp:108
double path_grid(std::size_t iter, const Particle< T > &particle)
Definition: adapter.hpp:221
base::initialize_param_type initialize_param_type
Definition: adapter.hpp:122
Path::eval_type subtype using OpenCL.
Definition: backend_cl.hpp:819
void initialize_state(std::string &kernel_name)
Definition: adapter.hpp:55
InitializeAdapter(const std::string &init_state, const initialize_param_type &init_param=initialize_param_type(), const pre_processor_type &pre=pre_processor_type(), const post_processor_type &post=post_processor_type())
Definition: adapter.hpp:126
void move_state(std::size_t, std::string &kernel_name)
Definition: adapter.hpp:158
Move class adapter base.
Definition: adapter.hpp:113
Sampler::init_type subtype using OpenCL.
Definition: backend_cl.hpp:543
base::post_processor_type post_processor_type
Definition: adapter.hpp:151
MoveAdapter(const std::string &move_state, const pre_processor_type &pre=pre_processor_type(), const post_processor_type &post=post_processor_type())
Definition: adapter.hpp:153
void monitor_state(std::size_t iter, std::size_t dim, ConstSingleParticle< T > part, double *res)
Definition: adapter.hpp:96
Move class adapter.
Definition: adapter.hpp:42
PathEvalAdapter(const std::string &path_state, const path_grid_type &path_grid, const pre_processor_type &pre=pre_processor_type(), const post_processor_type &post=post_processor_type())
Definition: adapter.hpp:206
Monitor evaluation class adapter.
Definition: adapter.hpp:44
Initialize class adapter.
Definition: adapter.hpp:40
void initialize_state(std::string &kernel_name)
Definition: adapter.hpp:132