YASK
Yet Another Stencil Kit: a software framework for creating HPC stencil code. Copyright 2014-2023 Intel Corporation.
Loading...
Searching...
No Matches
yc_solution_api.hpp
Go to the documentation of this file.
1/*****************************************************************************
2
3YASK: Yet Another Stencil Kit
4Copyright (c) 2014-2023, Intel Corporation
5
6Permission is hereby granted, free of charge, to any person obtaining a copy
7of this software and associated documentation files (the "Software"), to
8deal in the Software without restriction, including without limitation the
9rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10sell copies of the Software, and to permit persons to whom the Software is
11furnished to do so, subject to the following conditions:
12
13* The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22IN THE SOFTWARE.
23
24*****************************************************************************/
25
26// This file contains a base class and macros to create
27// stencils to be included in the YASK compiler binary utility.
28
29// This file uses Doxygen markup for API documentation-generation.
30// See https://www.doxygen.nl/manual/index.html.
33#pragma once
34
35// Standard headers.
36#include <cassert>
37#include <map>
38
39namespace yask {
40
47
58
59 public:
61
64 typedef std::map<std::string, yc_solution_base*> soln_map;
65
66 private:
67
69 yc_solution_ptr _soln;
70
72 yc_factory _yc_factory;
73
75 yc_node_factory _node_factory;
76
77 public:
78
80
87 yc_solution_base(const std::string& name);
88
90
96
98 virtual ~yc_solution_base() { }
99
101
105
107
122 virtual void
124
126 inline yc_solution_ptr
128 return _soln;
129 }
130
132 inline yc_index_node_ptr
133 new_step_index(const std::string& name) {
134 return _node_factory.new_step_index(name);
135 }
136
138 inline yc_index_node_ptr
139 new_domain_index(const std::string& name) {
140 return _node_factory.new_domain_index(name);
141 }
142
144 inline yc_index_node_ptr
145 new_misc_index(const std::string& name) {
146 return _node_factory.new_misc_index(name);
147 }
148
150 inline yc_number_node_ptr
152 return _node_factory.new_number_node(arg);
153 }
154
156 inline yc_number_node_ptr
158 return _node_factory.new_first_domain_index(dim);
159 }
160
162 inline yc_number_node_ptr
164 return _node_factory.new_last_domain_index(dim);
165 }
166 };
167
169
177 private:
178
180 int _radius;
181
182 public:
184 yc_solution_with_radius_base(const std::string& name, int radius) :
185 yc_solution_base(name) {
186 set_radius(radius);
187 }
188
190
193 virtual void
194 define() override;
195
197
202 virtual bool
203 set_radius(int radius) {
204 _radius = radius;
205 auto soln = get_soln();
206 soln->set_description(soln->get_name() + " radius " + std::to_string(radius));
207 return radius >= 0; // support only non-neg. radius.
208 }
209
211
214 virtual int
215 get_radius() const {
216 return _radius;
217 }
218 };
219
221 /*** Example: `MAKE_STEP_INDEX(t)` */
222 #define MAKE_STEP_INDEX(dim_name) yc_index_node_ptr dim_name = new_step_index(#dim_name)
223
225 /*** Example: `MAKE_DOMAIN_INDEX(x)` */
226 #define MAKE_DOMAIN_INDEX(dim_name) yc_index_node_ptr dim_name = new_domain_index(#dim_name)
227
229 /*** Example: `MAKE_MISC_INDEX(a)` */
230 #define MAKE_MISC_INDEX(dim_name) yc_index_node_ptr dim_name = new_misc_index(#dim_name)
231
233 /*** Example: `MAKE_VAR(pressure, t, x, y, z)` */
234 #define MAKE_VAR(var_name, ...) \
235 yc_var_proxy var_name = yc_var_proxy(#var_name, get_soln(), { __VA_ARGS__ }, false)
236
238 #define MAKE_SCRATCH_VAR(var_name, ...) \
239 yc_var_proxy var_name = yc_var_proxy(#var_name, get_soln(), { __VA_ARGS__ }, true)
240
242 #define MAKE_SCALAR_VAR(var_name) MAKE_VAR(var_name)
243
245 // and registering it in the list used by the YASK compiler binary.
246 #define REGISTER_SOLUTION(class_name) \
247 static class_name class_name ## _instance
248
251} // namespace yask.
Bootstrap factory to create objects needed to define a stencil solution.
Definition yask_compiler_api.hpp:96
Factory to create AST nodes.
Definition yc_node_api.hpp:609
virtual yc_index_node_ptr new_step_index(const std::string &name) const
Create a step-index node.
virtual yc_index_node_ptr new_first_domain_index(yc_index_node_ptr idx) const
Create a symbol for the first index value in a given dimension.
virtual yc_index_node_ptr new_last_domain_index(yc_index_node_ptr idx) const
Create a symbol for the last index value in a given dimension.
virtual yc_number_node_ptr new_number_node(yc_number_any_arg arg) const
Create a numerical-value expression node.
Definition yc_node_api.hpp:698
virtual yc_index_node_ptr new_misc_index(const std::string &name) const
Create a new miscellaneous index.
virtual yc_index_node_ptr new_domain_index(const std::string &name) const
Create a domain-index node.
Arguments that may be YASK or non-YASK numeric types.
Definition yc_node_api.hpp:563
A base class for defining solutions to be kept in a common registry.
Definition yc_solution_api.hpp:57
yc_index_node_ptr new_misc_index(const std::string &name)
A simple wrapper for yc_node_factory::new_misc_index().
Definition yc_solution_api.hpp:145
yc_number_node_ptr first_domain_index(yc_index_node_ptr dim)
A simple wrapper for yc_node_factory::new_first_domain_index().
Definition yc_solution_api.hpp:157
yc_index_node_ptr new_domain_index(const std::string &name)
A simple wrapper for yc_node_factory::new_domain_index().
Definition yc_solution_api.hpp:139
static soln_map & get_registry()
Access to the registry.
yc_number_node_ptr new_number_node(yc_number_any_arg arg)
A simple wrapper for yc_node_factory::new_number_node().
Definition yc_solution_api.hpp:151
std::map< std::string, yc_solution_base * > soln_map
Type for a common registry shared among all yc_solution_base objects.
Definition yc_solution_api.hpp:64
yc_solution_base(yc_solution_base &base)
[Advanced] Constructor that uses an existing yc_solution_base to share underlying solutions.
yc_solution_ptr get_soln()
Access the underlying solution.
Definition yc_solution_api.hpp:127
yc_number_node_ptr last_domain_index(yc_index_node_ptr dim)
A simple wrapper for yc_node_factory::new_last_domain_index().
Definition yc_solution_api.hpp:163
virtual void define()
Define all functionality of this solution.
yc_solution_base(const std::string &name)
Constructor.
yc_index_node_ptr new_step_index(const std::string &name)
A simple wrapper for yc_node_factory::new_step_index().
Definition yc_solution_api.hpp:133
virtual ~yc_solution_base()
Destructor.
Definition yc_solution_api.hpp:98
A base class for stencils that have a "radius" size parameter.
Definition yc_solution_api.hpp:176
virtual bool set_radius(int radius)
Set radius and updates the solution decription.
Definition yc_solution_api.hpp:203
virtual int get_radius() const
Get radius.
Definition yc_solution_api.hpp:215
yc_solution_with_radius_base(const std::string &name, int radius)
Constructor.
Definition yc_solution_api.hpp:184
virtual void define() override
Define all functionality of this solution.
std::shared_ptr< yc_number_node > yc_number_node_ptr
Shared pointer to yc_number_node.
Definition yask_compiler_api.hpp:69
std::shared_ptr< yc_solution > yc_solution_ptr
Shared pointer to yc_solution.
Definition yask_compiler_api.hpp:51
std::shared_ptr< yc_index_node > yc_index_node_ptr
Shared pointer to yc_index_node.
Definition yask_compiler_api.hpp:73