YASK
Yet Another Stencil Kit: a software framework for creating HPC stencil code. Copyright 2014-2023 Intel Corporation.
Loading...
Searching...
No Matches
yk_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
27
28// This file uses Doxygen markup for API documentation-generation.
29// See https://www.doxygen.nl/manual/index.html.
32#pragma once
33
34#include "yask_kernel_api.hpp"
35
36namespace yask {
37
44
49 const int yask_numa_local = -1;
50
52
57 const int yask_numa_interleave = -2;
58
60
65 const int yask_numa_none = -9;
66
68
73 const int yask_numa_offload = -11;
74
76
83 public:
84 virtual ~yk_solution() {}
85
87
90 virtual const std::string&
91 get_name() const =0;
92
94
98 virtual const std::string&
99 get_description() const =0;
100
102
107 virtual std::string
108 get_target() const =0;
109
111
114 virtual bool
115 is_offloaded() const =0;
116
118
121 virtual int
123
125
130 virtual std::string
132
134
140 virtual int
142
144
149 virtual string_vec
151
153
161 virtual string_vec
163
165
187 virtual void
188 set_rank_domain_size(const std::string& dim,
191 idx_t size ) =0;
192
194
197 virtual void
200
201 #ifndef SWIG
203
206 virtual void
209 #endif
210
212
221 virtual idx_t
222 get_rank_domain_size(const std::string& dim) const =0;
225
227
231 virtual idx_t_vec
233
235
244 virtual void
245 set_overall_domain_size(const std::string& dim,
248 idx_t size ) =0;
249
251
254 virtual void
257
258 #ifndef SWIG
260
263 virtual void
266 #endif
267
269
281 virtual idx_t
282 get_overall_domain_size(const std::string& dim ) const =0;
285
287
292 virtual idx_t_vec
294
296
316 virtual void
317 set_block_size(const std::string& dim,
321 idx_t size ) =0;
323
325
332 virtual void
335
336 #ifndef SWIG
338
345 virtual void
348 #endif
349
351
356 virtual idx_t
357 get_block_size(const std::string& dim) const =0;
361
363
372 virtual idx_t_vec
374
376
404 virtual void
405 set_num_ranks(const std::string& dim,
408 idx_t num ) =0;
409
411
414 virtual void
415 set_num_ranks_vec(const idx_t_vec& vals) = 0;
417
418 #ifndef SWIG
420
423 virtual void
426 #endif
427
429
436 virtual idx_t
437 get_num_ranks(const std::string& dim) const =0;
440
442
446 virtual idx_t_vec
448
450
475 virtual void
476 set_rank_index(const std::string& dim,
479 idx_t num ) =0;
480
482
485 virtual void
488
489 #ifndef SWIG
491
494 virtual void
497 #endif
498
500
505 virtual idx_t
506 get_rank_index(const std::string& dim ) const =0;
509
511
517 virtual idx_t_vec
519
521
528 virtual int
530
532
540 virtual int
542
544
557 virtual std::string
558 apply_command_line_options(const std::string& args ) =0;
560
562
569 virtual std::string
570 apply_command_line_options(int argc, char* argv[]) =0;
571
573
579 virtual std::string
581
583
586 virtual std::string
588
590
596 virtual std::string
598
600
607 virtual int
608 get_num_vars() const =0;
609
611
616 virtual yk_var_ptr
617 get_var(const std::string& name ) =0;
619
621
624 virtual std::vector<yk_var_ptr>
626
628
638 virtual void
640
642
654 virtual idx_t
655 get_first_rank_domain_index(const std::string& dim ) const =0;
658
660
664 virtual idx_t_vec
666
668
681 virtual idx_t
682 get_last_rank_domain_index(const std::string& dim ) const =0;
685
687
691 virtual idx_t_vec
693
695
729 virtual void
730 run_solution(idx_t first_step_index ,
731 idx_t last_step_index ) =0;
732
734
759 virtual void
760 run_solution(idx_t step_index ) =0;
761
763
775 virtual void
777
779
791 virtual void
793
795
799 virtual void
801
803
808 virtual void
810
812
819 virtual yk_stats_ptr
821
823 virtual void
825
827
838 virtual void
839 reset_auto_tuner(bool enable,
842 bool verbose = false ) =0;
845
847
855 virtual bool
857
859
880 virtual void
881 run_auto_tuner_now(bool verbose = true ) =0;
884
885 /* Advanced APIs for yk_solution found below are not needed for most applications. */
886
888
926 virtual void
927 set_min_pad_size(const std::string& dim,
930 idx_t size ) =0;
933
935
940 virtual idx_t
941 get_min_pad_size(const std::string& dim) const =0;
944
946
994 virtual yk_var_ptr
995 new_var(const std::string& name,
998 const string_vec& dims ) =0;
1002
1003 #ifndef SWIG
1005
1011 virtual yk_var_ptr
1012 new_var(const std::string& name,
1015 const std::initializer_list<std::string>& dims ) =0;
1019 #endif
1020
1022
1069 virtual yk_var_ptr
1070 new_fixed_size_var(const std::string& name,
1073 const string_vec& dims,
1077 const idx_t_vec& dim_sizes ) =0;
1080
1081 #ifndef SWIG
1083
1089 virtual yk_var_ptr
1090 new_fixed_size_var(const std::string& name,
1093 const std::initializer_list<std::string>& dims,
1097 const idx_t_init_list& dim_sizes ) =0;
1100 #endif
1101
1103
1114 virtual bool
1126
1128
1131 virtual int
1133
1134 #ifndef SWIG
1136 typedef std::function<void(yk_solution&)> hook_fn_t;
1137
1139 typedef std::function<void(yk_solution& soln,
1140 idx_t first_step_index,
1141 idx_t last_step_index)> hook_fn_2idx_t;
1142
1144
1152 virtual void
1155
1157
1165 virtual void
1168
1170
1180 virtual void
1183
1185
1195 virtual void
1198 #endif
1199
1201
1206 virtual void
1209
1211 virtual void
1212 set_step_wrap(bool do_wrap) =0;
1214
1216
1219 virtual bool
1220 get_step_wrap() const =0;
1221
1224 virtual void
1226
1229 inline int
1231 return get_num_vars();
1232 }
1233
1236 inline yk_var_ptr
1237 get_grid(const std::string& name) {
1238 return get_var(name);
1239 }
1240
1243 inline std::vector<yk_var_ptr>
1245 return get_vars();
1246 }
1247
1250 inline yk_var_ptr
1251 new_grid(const std::string& name,
1252 const string_vec& dims) {
1253 return new_var(name, dims);
1254 }
1255
1256 #ifndef SWIG
1259 inline yk_var_ptr
1260 new_grid(const std::string& name,
1261 const std::initializer_list<std::string>& dims) {
1262 return new_var(name, dims);
1263 }
1264 #endif
1265
1268 inline yk_var_ptr
1269 new_fixed_size_grid(const std::string& name,
1270 const string_vec& dims,
1271 const idx_t_vec& dim_sizes) {
1272 return new_fixed_size_var(name, dims, dim_sizes);
1273 }
1274
1275 #ifndef SWIG
1278 inline yk_var_ptr
1279 new_fixed_size_grid(const std::string& name,
1280 const std::initializer_list<std::string>& dims,
1281 const idx_t_vec& dim_sizes) {
1282 return new_fixed_size_var(name, dims, dim_sizes);
1283 }
1284 #endif
1285
1288 inline void
1290 fuse_vars(source);
1291 }
1292 }; // yk_solution.
1293
1295
1300 class yk_stats {
1301 public:
1302 virtual ~yk_stats() {}
1303
1305
1311 virtual idx_t
1313
1315
1319 virtual idx_t
1321
1323
1327 virtual idx_t
1329
1331
1338 virtual idx_t
1340
1342
1346 virtual double
1348 }; // yk_stats.
1349
1351} // namespace yask.
Stencil solution as defined by the generated code from the YASK stencil compiler.
Definition yk_solution_api.hpp:82
virtual idx_t get_first_rank_domain_index(const std::string &dim) const =0
Get the first index of the sub-domain in this rank in the specified dimension.
virtual int get_default_numa_preferred() const =0
[Advanced] Get the default preferred NUMA node on which to allocate data.
virtual yk_var_ptr get_var(const std::string &name)=0
Get the specified var.
virtual int get_num_outer_threads() const =0
Get the number of outer OpenMP threads.
virtual const std::string & get_description() const =0
Get the description (long name) of the solution.
virtual bool is_auto_tuner_enabled() const =0
Determine whether the online auto-tuner is enabled on this rank.
virtual void copy_vars_from_device() const =0
Update data on the host.
YASK_DEPRECATED yk_var_ptr new_fixed_size_grid(const std::string &name, const std::initializer_list< std::string > &dims, const idx_t_vec &dim_sizes)
[Deprecated] Use new_fixed_size_var().
Definition yk_solution_api.hpp:1279
virtual void clear_stats()=0
Clear the internal stats.
virtual void run_solution(idx_t first_step_index, idx_t last_step_index)=0
Run the stencil solution for the specified steps.
virtual void set_rank_domain_size(const std::string &dim, idx_t size)=0
Set the local-domain size in the specified dimension, i.e., the size of the part of the domain that i...
virtual void set_overall_domain_size_vec(const idx_t_vec &vals)=0
Set the global-domain size in all domain dimensions.
virtual void set_block_size_vec(const idx_t_vec &vals)=0
Set the block size in all domain dimensions.
virtual idx_t get_min_pad_size(const std::string &dim) const =0
[Advanced] Get the minimum requested amount of padding for all vars.
std::function< void(yk_solution &soln, idx_t first_step_index, idx_t last_step_index)> hook_fn_2idx_t
[Advanced] Callback type with yk_solution and step-index parameters.
Definition yk_solution_api.hpp:1141
virtual void call_before_run_solution(hook_fn_2idx_t hook_fn)=0
[Advanced] Register a hook function to be called at the beginning of yk_solution::run_solution().
virtual string_vec get_domain_dim_names() const =0
Get all the domain dimension names.
virtual std::vector< yk_var_ptr > get_vars()=0
Get all the vars.
virtual const std::string & get_name() const =0
Get the name of the solution.
virtual yk_var_ptr new_fixed_size_var(const std::string &name, const string_vec &dims, const idx_t_vec &dim_sizes)=0
[Advanced] Add a new var to the solution with a specified size.
virtual bool is_offloaded() const =0
Get whether the stencil kernel will be offloaded to a device.
virtual void copy_vars_to_device() const =0
Update data on the device.
virtual void call_after_prepare_solution(hook_fn_t hook_fn)=0
[Advanced] Register a hook function to be called at the end of yk_solution::prepare_solution().
YASK_DEPRECATED yk_var_ptr new_grid(const std::string &name, const std::initializer_list< std::string > &dims)
[Deprecated] Use new_var().
Definition yk_solution_api.hpp:1260
virtual void set_rank_domain_size_vec(const idx_t_vec &vals)=0
Set the local-domain size in all domain dimensions.
virtual idx_t get_rank_index(const std::string &dim) const =0
Get the rank index in the specified dimension.
virtual int get_num_domain_dims() const =0
Get the number of domain dimensions used in this solution.
virtual string_vec get_misc_dim_names() const =0
Get all the miscellaneous dimension names.
virtual idx_t get_num_ranks(const std::string &dim) const =0
Get the number of MPI ranks in the given dimension.
virtual void set_overall_domain_size_vec(const idx_t_init_list &vals)=0
Set the global-domain size in all domain dimensions.
virtual void run_solution(idx_t step_index)=0
Run the stencil solution for the specified step.
virtual std::string get_command_line_values()=0
Return a description of the current settings of the command-line options.
YASK_DEPRECATED int get_num_grids() const
[Deprecated] Use get_num_vars().
Definition yk_solution_api.hpp:1230
virtual idx_t_vec get_rank_domain_size_vec() const =0
Get the local-domain size in all domain dimensions.
virtual int get_element_bytes() const =0
Get the floating-point precision size.
virtual void call_after_run_solution(hook_fn_2idx_t hook_fn)=0
[Advanced] Register a hook function to be called at the end of yk_solution::run_solution().
virtual std::string apply_command_line_options(const string_vec &args)=0
Set kernel options from a vector of strings.
YASK_DEPRECATED yk_var_ptr get_grid(const std::string &name)
[Deprecated] Use get_var().
Definition yk_solution_api.hpp:1237
virtual void fuse_vars(yk_solution_ptr source)=0
[Advanced] Merge YASK variables with another solution.
virtual idx_t get_rank_domain_size(const std::string &dim) const =0
Get the local-domain size in the specified dimension, i.e., the size in this rank.
virtual idx_t get_last_rank_domain_index(const std::string &dim) const =0
Get the last index of the sub-domain in this rank the specified dimension.
virtual idx_t get_block_size(const std::string &dim) const =0
Get the block size.
virtual idx_t_vec get_rank_index_vec() const =0
Get the rank index in all domain dimensions.
virtual void exchange_halos()=0
Force a halo exchange now.
virtual int get_num_inner_threads() const =0
Get the number of inner (nested) OpenMP threads.
virtual std::string get_step_dim_name() const =0
Get the solution step dimension.
virtual idx_t_vec get_num_ranks_vec() const =0
Get the number of MPI ranks in all domain dimensions.
virtual yk_var_ptr new_var(const std::string &name, const string_vec &dims)=0
[Advanced] Add a new var to the solution.
virtual idx_t_vec get_block_size_vec() const =0
Get the block size in all domain dimensions.
virtual idx_t_vec get_first_rank_domain_index_vec() const =0
Get the first index of the sub-domain in this rank in all domain dimensions.
virtual void set_num_ranks_vec(const idx_t_init_list &vals)=0
Set the number of all MPI ranks in all domain dimensions.
virtual YASK_DEPRECATED void set_debug_output(yask_output_ptr debug)=0
[Deprecated] Use yk_env::set_debug_output().
virtual void set_overall_domain_size(const std::string &dim, idx_t size)=0
Get the global-domain size in the specified dimension, i.e., the total size across all MPI ranks.
virtual void set_num_ranks_vec(const idx_t_vec &vals)=0
Set the number of MPI ranks in all domain dimensions.
YASK_DEPRECATED yk_var_ptr new_fixed_size_grid(const std::string &name, const string_vec &dims, const idx_t_vec &dim_sizes)
[Deprecated] Use new_fixed_size_var().
Definition yk_solution_api.hpp:1269
virtual yk_var_ptr new_fixed_size_var(const std::string &name, const std::initializer_list< std::string > &dims, const idx_t_init_list &dim_sizes)=0
[Advanced] Add a new var to the solution with a specified size.
virtual void run_auto_tuner_now(bool verbose=true)=0
Run the offline auto-tuner immediately, not preserving variable data.
std::function< void(yk_solution &)> hook_fn_t
[Advanced] Callback type with yk_solution parameter.
Definition yk_solution_api.hpp:1136
virtual void set_rank_index_vec(const idx_t_init_list &vals)=0
Set the rank index in all domain dimensions.
virtual void reset_auto_tuner(bool enable, bool verbose=false)=0
Start or stop the online auto-tuner on this rank.
virtual void set_block_size_vec(const idx_t_init_list &vals)=0
Set the block size in all domain dimensions.
virtual idx_t_vec get_last_rank_domain_index_vec() const =0
Get the last index of the sub-domain in this rank in all domain dimensions.
virtual void set_rank_domain_size_vec(const idx_t_init_list &vals)=0
Set the local-domain size in all domain dimensions.
virtual int get_num_vars() const =0
Get the number of vars in the solution.
virtual void prepare_solution()=0
Prepare the solution for stencil application.
virtual idx_t_vec get_overall_domain_size_vec() const =0
Get the global-domain size in all domain dimensions.
virtual idx_t get_overall_domain_size(const std::string &dim) const =0
Get the global-domain size in the specified dimension, i.e., the total size across all MPI ranks.
virtual std::string get_target() const =0
Get the target ISA.
virtual yk_stats_ptr get_stats()=0
Get performance statistics associated with preceding calls to run_solution().
virtual void set_min_pad_size(const std::string &dim, idx_t size)=0
[Advanced] Set the minimum amount of padding for all vars.
virtual void set_rank_index_vec(const idx_t_vec &vals)=0
Set the rank index in all domain dimensions.
virtual void set_block_size(const std::string &dim, idx_t size)=0
Set the block size in the given dimension.
virtual std::string get_command_line_help()=0
Return a help-string for the command-line options.
virtual void set_rank_index(const std::string &dim, idx_t num)=0
Set the rank index in the specified dimension.
virtual std::string apply_command_line_options(const std::string &args)=0
Set kernel options from a string.
YASK_DEPRECATED void fuse_grids(yk_solution_ptr source)
[Deprecated] Use fuse_vars().
Definition yk_solution_api.hpp:1289
virtual void set_num_ranks(const std::string &dim, idx_t num)=0
Set the number of MPI ranks in the given dimension.
YASK_DEPRECATED yk_var_ptr new_grid(const std::string &name, const string_vec &dims)
[Deprecated] Use new_var().
Definition yk_solution_api.hpp:1251
virtual bool set_default_numa_preferred(int numa_node)=0
[Advanced] Set the default preferred NUMA node on which to allocate data.
virtual std::string apply_command_line_options(int argc, char *argv[])=0
Set kernel options from standard C or C++ argc and argv parameters to main().
virtual bool get_step_wrap() const =0
[Advanced] Get whether invalid step indices alias to valid ones.
virtual yk_var_ptr new_var(const std::string &name, const std::initializer_list< std::string > &dims)=0
[Advanced] Add a new var to the solution.
virtual void call_before_prepare_solution(hook_fn_t hook_fn)=0
[Advanced] Register a function to be called at the beginning of yk_solution::prepare_solution().
YASK_DEPRECATED std::vector< yk_var_ptr > get_grids()
[Deprecated] Use get_vars().
Definition yk_solution_api.hpp:1244
virtual void set_step_wrap(bool do_wrap)=0
[Advanced] Set whether invalid step indices alias to valid ones.
virtual void end_solution()=0
Finish using a solution.
Statistics from calls to run_solution().
Definition yk_solution_api.hpp:1300
virtual idx_t get_est_fp_ops_done()=0
Get the estimated number of floating-point operations executed across all steps.
virtual idx_t get_num_elements()=0
Get the number of elements in the overall domain.
virtual idx_t get_num_steps_done()=0
Get the number of steps executed via run_solution().
virtual double get_elapsed_secs()=0
Get the number of seconds elapsed during calls to run_solution().
virtual idx_t get_num_writes_done()=0
Get the number of elements written across all steps.
YASK_INT64_T idx_t
Type to use for indexing grids.
Definition yask_common_api.hpp:86
std::vector< std::string > string_vec
Vector of strings.
Definition yask_common_api.hpp:99
std::shared_ptr< yask_output > yask_output_ptr
Shared pointer to yask_output.
Definition yask_common_api.hpp:105
std::initializer_list< idx_t > idx_t_init_list
Initializer list of indices.
Definition yask_common_api.hpp:96
std::vector< idx_t > idx_t_vec
Vector of indices.
Definition yask_common_api.hpp:89
std::shared_ptr< yk_stats > yk_stats_ptr
Shared pointer to yk_stats.
Definition yask_kernel_api.hpp:66
std::shared_ptr< yk_solution > yk_solution_ptr
Shared pointer to yk_solution.
Definition yask_kernel_api.hpp:58
const int yask_numa_none
Do not specify any NUMA binding.
Definition yk_solution_api.hpp:65
const int yask_numa_interleave
Allocate vars across all available NUMA nodes.
Definition yk_solution_api.hpp:57
const int yask_numa_local
Allocate vars on local NUMA node.
Definition yk_solution_api.hpp:49
std::shared_ptr< yk_var > yk_var_ptr
Shared pointer to yk_var.
Definition yask_kernel_api.hpp:62
const int yask_numa_offload
Do not specify any NUMA binding and use allocations optimized for offloading.
Definition yk_solution_api.hpp:73
#define YASK_DEPRECATED
Deprecated attribute.
Definition yask_common_api.hpp:60