YASK
Yet Another Stencil Kit: a software framework for creating HPC stencil code. Copyright 2014-2023 Intel Corporation.
Loading...
Searching...
No Matches
yk_var_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
185 class yk_var {
186 public:
187 virtual ~yk_var() {}
188
190
196 virtual const std::string& get_name() const =0;
197
199
205 virtual int get_num_dims() const =0;
206
208
212 virtual string_vec
213 get_dim_names() const =0;
214
216
221 virtual int get_num_domain_dims() const =0;
222
224
228 virtual bool
229 is_dim_used(const std::string& dim) const =0;
230
232
236 virtual bool is_fixed_size() const =0;
237
239
252 virtual idx_t
253 get_first_local_index(const std::string& dim ) const =0;
256
258
262 virtual idx_t_vec
264
266
279 virtual idx_t
280 get_last_local_index(const std::string& dim ) const =0;
283
285
289 virtual idx_t_vec
291
293
300 virtual idx_t
301 get_alloc_size(const std::string& dim ) const =0;
304
306
310 virtual idx_t_vec
312
314
322 virtual idx_t
324
326
334 virtual idx_t
336
338
346 virtual idx_t
347 get_rank_domain_size(const std::string& dim) const =0;
351
353
357 virtual idx_t_vec
359
361
369 virtual idx_t
370 get_first_rank_domain_index(const std::string& dim ) const =0;
374
376
380 virtual idx_t_vec
382
384
393 virtual idx_t
394 get_last_rank_domain_index(const std::string& dim ) const =0;
398
400
404 virtual idx_t_vec
406
408
412 virtual idx_t
413 get_left_halo_size(const std::string& dim ) const =0;
418
420
424 virtual idx_t
425 get_right_halo_size(const std::string& dim ) const =0;
430
432
440 virtual idx_t
441 get_first_rank_halo_index(const std::string& dim ) const =0;
445
447
451 virtual idx_t_vec
453
455
463 virtual idx_t
464 get_last_rank_halo_index(const std::string& dim ) const =0;
468
470
474 virtual idx_t_vec
476
478
486 virtual idx_t
487 get_left_pad_size(const std::string& dim ) const =0;
492
494
502 virtual idx_t
503 get_right_pad_size(const std::string& dim ) const =0;
508
510
515 virtual idx_t
516 get_left_extra_pad_size(const std::string& dim ) const =0;
521
523
528 virtual idx_t
529 get_right_extra_pad_size(const std::string& dim ) const =0;
534
536
540 virtual idx_t
541 get_first_misc_index(const std::string& dim ) const =0;
544
546
550 virtual idx_t
551 get_last_misc_index(const std::string& dim ) const =0;
555
557
564 virtual bool
565 are_indices_local(const idx_t_vec& indices ) const =0;
567
568 #ifndef SWIG
570
573 virtual bool
574 are_indices_local(const idx_t_init_list& indices ) const =0;
576 #endif
577
579
595 virtual double
596 get_element(const idx_t_vec& indices ) const =0;
598
599 #ifndef SWIG
601
608 virtual double
609 get_element(const idx_t_init_list& indices ) const =0;
611 #endif
612
614
635 virtual idx_t
636 set_element(double val ,
637 const idx_t_vec& indices,
639 bool strict_indices = true ) =0;
644
645 #ifndef SWIG
647
654 virtual idx_t
655 set_element(double val ,
656 const idx_t_init_list& indices,
658 bool strict_indices = true ) =0;
663
665
699 virtual idx_t
700 get_elements_in_slice(float* buffer_ptr,
702 size_t buffer_size,
704 const idx_t_vec& first_indices,
706 const idx_t_vec& last_indices ) const =0;
708
710
743 virtual idx_t
744 get_elements_in_slice(double* buffer_ptr,
746 size_t buffer_size,
748 const idx_t_vec& first_indices,
750 const idx_t_vec& last_indices ) const =0;
752 #endif
753
755
773 virtual idx_t
774 add_to_element(double val ,
775 const idx_t_vec& indices,
777 bool strict_indices = true ) =0;
781
782 #ifndef SWIG
784
788 virtual idx_t
789 add_to_element(double val ,
790 const idx_t_init_list& indices,
792 bool strict_indices = true ) =0;
796 #endif
797
799
808 virtual void
809 set_all_elements_same(double val ) =0;
810
812
830 virtual idx_t
832 const idx_t_vec& first_indices,
834 const idx_t_vec& last_indices,
836 bool strict_indices = true ) =0;
840
841 #ifndef SWIG
843
876 virtual idx_t
877 set_elements_in_slice(const float* buffer_ptr,
879 size_t buffer_size,
881 const idx_t_vec& first_indices,
883 const idx_t_vec& last_indices ) =0;
885
886
888
922 virtual idx_t
923 set_elements_in_slice(const double* buffer_ptr,
925 size_t buffer_size,
927 const idx_t_vec& first_indices,
929 const idx_t_vec& last_indices ) =0;
931 #endif
932
933 #ifdef COPY_SLICE_IMPLEMENTED
935
950 virtual idx_t
953 const idx_t_vec& first_source_indices,
956 const idx_t_vec& first_target_indices,
959 const idx_t_vec& last_target_indices ) =0;
962 #endif
963
965 static constexpr int yk_sum_reduction = 0x01;
966
968 static constexpr int yk_sum_squares_reduction = 0x02;
969
971 static constexpr int yk_product_reduction = 0x04;
972
974 static constexpr int yk_max_reduction = 0x08;
975
977 static constexpr int yk_min_reduction = 0x10;
978
980
985 public:
986
988
991 virtual int
993
995
998 virtual idx_t
1000
1002
1007 virtual double
1008 get_sum() const =0;
1009
1011
1016 virtual double
1018
1020
1025 virtual double
1026 get_product() const =0;
1027
1029
1034 virtual double
1035 get_max() const =0;
1036
1038
1043 virtual double
1044 get_min() const =0;
1045 };
1046
1048 typedef std::shared_ptr<yk_reduction_result> yk_reduction_result_ptr;
1049
1051
1069 reduce_elements_in_slice(int reduction_mask ,
1070 const idx_t_vec& first_indices,
1072 const idx_t_vec& last_indices,
1074 bool strict_indices = true ) =0;
1078
1080
1084 virtual std::string
1085 format_indices(const idx_t_vec& indices ) const =0;
1087
1088 #ifndef SWIG
1090
1094 virtual std::string
1095 format_indices(const idx_t_init_list& indices ) const =0;
1097 #endif
1098
1099 /* Advanced APIs for yk_var found below are not needed for most applications. */
1100
1102
1119 virtual int
1121
1123
1128 virtual void
1132
1134
1137 virtual bool
1139
1141
1148 virtual bool
1149 set_numa_preferred(int numa_node) =0;
1152
1154
1157 virtual int
1159
1161
1171 virtual void
1172 set_left_min_pad_size(const std::string& dim,
1176 idx_t size ) =0;
1179
1181
1191 virtual void
1192 set_right_min_pad_size(const std::string& dim,
1196 idx_t size ) =0;
1199
1201
1204 virtual void
1205 set_min_pad_size(const std::string& dim,
1209 idx_t size ) =0;
1212
1214
1223 virtual void
1224 set_left_halo_size(const std::string& dim,
1228 idx_t size ) =0;
1230
1232
1241 virtual void
1242 set_right_halo_size(const std::string& dim,
1246 idx_t size ) =0;
1248
1250
1253 virtual void
1254 set_halo_size(const std::string& dim,
1258 idx_t size ) =0;
1260
1261
1263
1288 virtual void
1289 set_alloc_size(const std::string& dim,
1293 idx_t size ) =0;
1294
1296
1302 virtual void
1303 set_first_misc_index(const std::string& dim,
1306 idx_t idx ) =0;
1308
1310
1314 virtual bool
1316
1318
1322 virtual idx_t
1324
1326
1329 virtual idx_t
1331
1333
1339 virtual void
1341
1343
1347 virtual void
1349
1351
1367 virtual bool
1369
1371
1395 virtual void
1398
1400
1437 virtual void* get_raw_storage_buffer() =0;
1438
1439
1441
1448 virtual idx_t
1449 get_elements_in_slice(void* buffer_ptr,
1451 const idx_t_vec& first_indices,
1453 const idx_t_vec& last_indices ) const =0;
1455
1457
1464 virtual idx_t
1465 set_elements_in_slice(const void* buffer_ptr,
1467 const idx_t_vec& first_indices,
1469 const idx_t_vec& last_indices ) =0;
1471
1474 virtual idx_t
1475 get_first_rank_alloc_index(const std::string& dim) const {
1476 return get_first_local_index(dim);
1477 }
1478
1481 virtual idx_t
1482 get_last_rank_alloc_index(const std::string& dim) const {
1483 return get_last_local_index(dim);
1484 }
1485
1486 }; // yk_var.
1487
1490 typedef yk_var yk_grid;
1491
1493} // namespace yask.
Class returned from reduce_elements_in_slice().
Definition yk_var_api.hpp:984
virtual double get_min() const =0
Get min.
virtual double get_product() const =0
Get product.
virtual int get_reduction_mask() const =0
Get the allowed reductions.
virtual double get_max() const =0
Get max.
virtual double get_sum_squares() const =0
Get sum of squares.
virtual idx_t get_num_elements_reduced() const =0
Get the number of elements reduced.
virtual double get_sum() const =0
Get sum.
A run-time YASK data container.
Definition yk_var_api.hpp:185
virtual idx_t_vec get_last_local_index_vec() const =0
Get the last valid index in this rank in all dimensions in this var.
virtual YASK_DEPRECATED idx_t get_first_rank_alloc_index(const std::string &dim) const
[Deprecated] Use get_first_local_index().
Definition yk_var_api.hpp:1475
virtual void set_right_min_pad_size(const std::string &dim, idx_t size)=0
[Advanced] Set the minimum right padding in the specified dimension.
virtual int get_numa_preferred() const =0
[Advanced] Get the default preferred NUMA node on which to allocate data.
virtual YASK_DEPRECATED idx_t get_elements_in_slice(void *buffer_ptr, const idx_t_vec &first_indices, const idx_t_vec &last_indices) const =0
[Deprecated] Use the float* or double* version.
virtual void set_all_elements_same(double val)=0
Initialize all var elements to the same value.
virtual yk_reduction_result_ptr reduce_elements_in_slice(int reduction_mask, const idx_t_vec &first_indices, const idx_t_vec &last_indices, bool strict_indices=true)=0
Perform requested reductions over elements within specified subset of the var.
virtual void set_min_pad_size(const std::string &dim, idx_t size)=0
[Advanced] Set the minimum padding in the specified dimension.
virtual idx_t get_alloc_size(const std::string &dim) const =0
Get the number of elements allocated in the specified dimension.
static constexpr int yk_max_reduction
Bitmask for maximum-value reduction.
Definition yk_var_api.hpp:974
virtual idx_t get_left_pad_size(const std::string &dim) const =0
Get the actual left padding in the specified dimension.
virtual int get_halo_exchange_l1_norm() const =0
[Advanced] Get the maximum L1-norm of a neighbor rank for halo exchange.
virtual idx_t_vec get_rank_domain_size_vec() const =0
Get the domain size for this rank in all domain dimensions in this var.
virtual bool is_storage_layout_identical(const yk_var_ptr other) const =0
[Advanced] Determines whether storage layout is the same as another var.
virtual idx_t get_first_rank_halo_index(const std::string &dim) const =0
Get the first index of the left halo in this rank in the specified dimension.
virtual void set_left_min_pad_size(const std::string &dim, idx_t size)=0
[Advanced] Set the minimum left padding in the specified dimension.
virtual bool is_storage_allocated() const =0
[Advanced] Determine whether storage has been allocated.
virtual idx_t_vec get_first_local_index_vec() const =0
Get the first valid index in this rank in all dimensions in this var.
virtual bool are_indices_local(const idx_t_vec &indices) const =0
Determine whether the given indices refer to an accessible element in this rank.
virtual idx_t get_rank_domain_size(const std::string &dim) const =0
Get the domain size for this rank in the specified dimension.
static constexpr int yk_min_reduction
Bitmask for minimum-value reduction.
Definition yk_var_api.hpp:977
virtual bool is_fixed_size() const =0
Determine whether this var is not automatically resized based on the solution.
virtual idx_t set_element(double val, const idx_t_init_list &indices, bool strict_indices=true)=0
Set the value of one element in this var.
virtual idx_t get_right_pad_size(const std::string &dim) const =0
Get the actual right padding in the specified dimension.
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 in this var.
virtual idx_t get_num_storage_bytes() const =0
[Advanced] Determine size of raw storage in bytes.
virtual idx_t set_elements_in_slice(const double *buffer_ptr, size_t buffer_size, const idx_t_vec &first_indices, const idx_t_vec &last_indices)=0
Set elements within specified subset of the var from values in a double buffer.
virtual void * get_raw_storage_buffer()=0
[Advanced] Get pointer to raw data storage buffer.
virtual std::string format_indices(const idx_t_vec &indices) const =0
Format the indices for human-readable display.
virtual void set_first_misc_index(const std::string &dim, idx_t idx)=0
[Advanced] Set the first index of a specified miscellaneous dimension.
virtual idx_t set_elements_in_slice(const float *buffer_ptr, size_t buffer_size, const idx_t_vec &first_indices, const idx_t_vec &last_indices)=0
Set elements within specified subset of the var from values in a float buffer.
virtual void set_halo_exchange_l1_norm(int norm)=0
[Advanced] Set the maximum L1-norm of a neighbor rank for halo exchange.
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 idx_t get_elements_in_slice(double *buffer_ptr, size_t buffer_size, const idx_t_vec &first_indices, const idx_t_vec &last_indices) const =0
Copy elements within specified subset of this var into a double buffer.
virtual idx_t get_first_valid_step_index() const =0
Get the first valid index in the step dimension.
virtual void set_right_halo_size(const std::string &dim, idx_t size)=0
[Advanced] Set the right halo size in the specified dimension.
static constexpr int yk_sum_squares_reduction
Bitmask for sum-of-squares reduction.
Definition yk_var_api.hpp:968
virtual void set_halo_size(const std::string &dim, idx_t size)=0
[Advanced] Set the left and right halo sizes in the specified dimension.
virtual idx_t get_last_local_index(const std::string &dim) const =0
Get the last index in this rank in the specified dimension.
static constexpr int yk_product_reduction
Bitmask for product reduction.
Definition yk_var_api.hpp:971
virtual idx_t get_num_storage_elements() const =0
[Advanced] Determine size of raw storage in elements.
virtual idx_t get_last_valid_step_index() const =0
Get the last valid index in the step dimension.
virtual void set_alloc_size(const std::string &dim, idx_t size)=0
[Advanced] Set the number of elements to allocate in the specified dimension.
virtual idx_t get_elements_in_slice(float *buffer_ptr, size_t buffer_size, const idx_t_vec &first_indices, const idx_t_vec &last_indices) const =0
Copy elements within specified subset of this var into a float buffer.
virtual void set_left_halo_size(const std::string &dim, idx_t size)=0
[Advanced] Set the left halo size in the specified dimension.
virtual bool are_indices_local(const idx_t_init_list &indices) const =0
Determine whether the given indices refer to an accessible element in this rank.
virtual bool is_dynamic_step_alloc() const =0
[Advanced] Get whether the allocation of the step dimension of this var can be modified at run-time.
virtual void release_storage()=0
[Advanced] Explicitly release any allocated data-storage for this var.
virtual idx_t get_first_misc_index(const std::string &dim) const =0
Get the first index of a specified miscellaneous dimension.
virtual void fuse_vars(yk_var_ptr source)=0
[Advanced] Merge this var with another var.
virtual void alloc_storage()=0
[Advanced] Explicitly allocate data-storage memory for this var.
virtual int get_num_dims() const =0
Get the number of dimensions used in this var.
virtual idx_t_vec get_last_rank_halo_index_vec() const =0
Get the last index of the right halo in this rank in all domain dimensions in this var.
virtual idx_t add_to_element(double val, const idx_t_vec &indices, bool strict_indices=true)=0
Atomically add to the value of one var element.
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 in the specified dimension.
virtual idx_t get_first_local_index(const std::string &dim) const =0
Get the first valid index in this rank in the specified dimension.
virtual idx_t_vec get_first_rank_halo_index_vec() const =0
Get the first index of the left halo in this rank in all domain dimensions in this var.
virtual const std::string & get_name() const =0
Get the name of the var.
virtual idx_t get_last_misc_index(const std::string &dim) const =0
Get the last index of a specified miscellaneous dimension.
virtual YASK_DEPRECATED idx_t set_elements_in_slice(const void *buffer_ptr, const idx_t_vec &first_indices, const idx_t_vec &last_indices)=0
[Deprecated] Use the float* or double* version.
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 in this var.
static constexpr int yk_sum_reduction
Bitmask for sum reduction.
Definition yk_var_api.hpp:965
virtual idx_t set_element(double val, const idx_t_vec &indices, bool strict_indices=true)=0
Set the value of one element in this var.
std::shared_ptr< yk_reduction_result > yk_reduction_result_ptr
Shared pointer to yk_reduction_result.
Definition yk_var_api.hpp:1048
virtual bool set_numa_preferred(int numa_node)=0
[Advanced] Set the default preferred NUMA node on which to allocate data.
virtual YASK_DEPRECATED idx_t get_last_rank_alloc_index(const std::string &dim) const
[Deprecated] Use get_last_local_index().
Definition yk_var_api.hpp:1482
virtual idx_t get_left_halo_size(const std::string &dim) const =0
Get the left halo size in the specified dimension.
virtual bool is_dim_used(const std::string &dim) const =0
Determine whether specified dimension exists in this var.
virtual idx_t get_last_rank_halo_index(const std::string &dim) const =0
Get the last index of the right halo in this rank in the specified dimension.
virtual idx_t set_elements_in_slice_same(double val, const idx_t_vec &first_indices, const idx_t_vec &last_indices, bool strict_indices=true)=0
Initialize var elements within specified subset of the var to the same value.
virtual string_vec get_dim_names() const =0
Get all the dimensions in this var.
virtual idx_t add_to_element(double val, const idx_t_init_list &indices, bool strict_indices=true)=0
Atomically add to the value of one var element.
virtual idx_t get_left_extra_pad_size(const std::string &dim) const =0
Get the actual extra left padding in the specified dimension.
virtual std::string format_indices(const idx_t_init_list &indices) const =0
Format the indices for human-readable display.
virtual idx_t get_right_halo_size(const std::string &dim) const =0
Get the right halo size in the specified dimension.
virtual double get_element(const idx_t_vec &indices) const =0
Read the value of one element in this var.
virtual idx_t_vec get_alloc_size_vec() const =0
Get the number of elements allocated in all dimensions in this var.
virtual double get_element(const idx_t_init_list &indices) const =0
Read the value of one element in this var.
virtual int get_num_domain_dims() const =0
Get the number of domain dimensions used in this var.
virtual idx_t get_right_extra_pad_size(const std::string &dim) const =0
Get the actual extra right padding in the specified dimension.
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::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_var > yk_var_ptr
Shared pointer to yk_var.
Definition yask_kernel_api.hpp:62
YASK_DEPRECATED typedef yk_var yk_grid
[Deprecated] Use yk_var.
Definition yask_kernel_api.hpp:299
#define YASK_DEPRECATED
Deprecated attribute.
Definition yask_common_api.hpp:60