9.2
general documentation
cs_mdspan.h
Go to the documentation of this file.
1#ifndef CS_MDSPAN_H
2#define CS_MDSPAN_H
3
4/*============================================================================
5 * mdspan class and handling utilities.
6 *============================================================================*/
7
8/*
9 This file is part of code_saturne, a general-purpose CFD tool.
10
11 Copyright (C) 1998-2026 EDF S.A.
12
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License as published by the Free Software
15 Foundation; either version 2 of the License, or (at your option) any later
16 version.
17
18 This program is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 details.
22
23 You should have received a copy of the GNU General Public License along with
24 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
25 Street, Fifth Floor, Boston, MA 02110-1301, USA.
26*/
27
28/*----------------------------------------------------------------------------*/
29
30/*----------------------------------------------------------------------------
31 * Standard library headers
32 *----------------------------------------------------------------------------*/
33
34#include <string.h>
35
36/*----------------------------------------------------------------------------
37 * Local headers
38 *----------------------------------------------------------------------------*/
39
40#include "base/cs_defs.h"
41
42#include "base/cs_dispatch.h"
44
45/*----------------------------------------------------------------------------*/
46
47namespace cs {
48
50enum class
51layout {
52 right,
53 left,
54 unknown
55};
56
57/*----------------------------------------------------------------------------*/
65/*----------------------------------------------------------------------------*/
66
67template<class T, int N, layout L = layout::right>
68class mdspan {
69
70/*=============================================================================
71 * Public methods
72 *============================================================================*/
73
74public:
75
76 /* Make array class friend */
77 template<class _T_, int _N_, layout _L_> friend class array;
78
79 /*--------------------------------------------------------------------------*/
83 /*--------------------------------------------------------------------------*/
84
87 _extent{0},
88 _offset{0},
89 _size(0),
90 _data(nullptr)
91 {}
92
93 /*--------------------------------------------------------------------------*/
97 /*--------------------------------------------------------------------------*/
98
99 template<typename... Args>
102 (
103 T *data,
104 Args... indices
105 )
106 {
107 check_operator_args_(indices...);
108 set_size_(indices...);
109 _data = data;
110 }
111
112 /*--------------------------------------------------------------------------*/
116 /*--------------------------------------------------------------------------*/
117
120 (
121 T *data,
122 const cs_lnum_t(&dims)[N]
123 )
124 {
125 set_size_(dims);
126 _data = data;
127 }
128
129 /*--------------------------------------------------------------------------*/
133 /*--------------------------------------------------------------------------*/
134
137 (
138 const mdspan& other
139 )
140 {
141 set_size_(other._extent);
142 _data = other._data;
143 }
144
145 /*--------------------------------------------------------------------------*/
149 /*--------------------------------------------------------------------------*/
150
153 (
154 mdspan&& other
155 )
156 : mdspan()
157 {
158 swap(*this, other);
159 }
160
161 /*--------------------------------------------------------------------------*/
165 /*--------------------------------------------------------------------------*/
166
169 {
170 _data = nullptr;
171 }
172
173 /*--------------------------------------------------------------------------*/
177 /*--------------------------------------------------------------------------*/
178
180 friend void
182 (
183 mdspan& first,
184 mdspan& second
185 )
186 {
187 cs::swap_objects(first._extent, second._extent);
188 cs::swap_objects(first._offset, second._offset);
189 cs::swap_objects(first._size, second._size);
190 cs::swap_objects(first._data, second._data);
191 }
192
193 /*===========================================================================
194 * Operators
195 *==========================================================================*/
196
197 /*--------------------------------------------------------------------------*/
201 /*--------------------------------------------------------------------------*/
202
204 mdspan& operator=(const mdspan& other)
205 {
206 for (int i = 0; i < N; i++) {
207 _extent[i] = other._extent[i];
208 _offset[i] = other._offset[i];
209 }
210 _size = other._size;
211 _data = other._data;
212
213 return *this;
214 }
215
218 {
219
220 swap(*this, other);
221
222 return *this;
223 }
224
225 /*--------------------------------------------------------------------------*/
231 /*--------------------------------------------------------------------------*/
232
234 operator T*() const
235 {
236 return _data;
237 }
238
239 /*--------------------------------------------------------------------------*/
245 /*--------------------------------------------------------------------------*/
246
248 inline
249 T& operator[]
250 (
251 cs_lnum_t i
252 )
253 {
254#if defined(CS_ARRAY_DBG_BOUNDS)
255 check_bounds_(i);
256#endif
257 return _data[i];
258 }
259
260 /*--------------------------------------------------------------------------*/
266 /*--------------------------------------------------------------------------*/
267
269 inline
270 T& operator[]
271 (
272 cs_lnum_t i
273 ) const
274 {
275#if defined(CS_ARRAY_DBG_BOUNDS)
276 check_bounds_(i);
277#endif
278 return _data[i];
279 }
280
281 /*--------------------------------------------------------------------------*/
287 /*--------------------------------------------------------------------------*/
288
289 template<typename Id1>
291 inline
292 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
293 operator()
294 (
295 Id1 i
296 )
297 {
299#if defined(CS_ARRAY_DBG_BOUNDS)
300 check_bounds_(i);
301#endif
302 return _data[i];
303 }
304
305 /*--------------------------------------------------------------------------*/
311 /*--------------------------------------------------------------------------*/
312
313 template<typename Id1>
315 inline
316 std::enable_if_t<cs::always_true<Id1>::value && N==1, T&>
317 operator()
318 (
319 Id1 i
320 ) const
321 {
323#if defined(CS_ARRAY_DBG_BOUNDS)
324 check_bounds_(i);
325#endif
326 return _data[i];
327 }
328
329 /*--------------------------------------------------------------------------*/
335 /*--------------------------------------------------------------------------*/
336
337 template<typename Id1, typename Id2>
339 inline
340 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
341 operator()
342 (
343 Id1 i,
344 Id2 j
345 )
346 {
348#if defined(CS_ARRAY_DBG_BOUNDS)
349 check_bounds_(i,j);
350#endif
351
352 if (L == layout::right)
353 return _data[i*_offset[0] + j];
354 else if (L == layout::left)
355 return _data[i + j*_offset[1]];
356 else
357 return _data[i*_offset[0] + j*_offset[1]];
358 }
359
360 /*--------------------------------------------------------------------------*/
366 /*--------------------------------------------------------------------------*/
367
368 template<typename Id1, typename Id2>
370 inline
371 std::enable_if_t<cs::always_true<Id1, Id2>::value && N==2, T&>
372 operator()
373 (
374 Id1 i,
375 Id2 j
376 ) const
377 {
379#if defined(CS_ARRAY_DBG_BOUNDS)
380 check_bounds_(i,j);
381#endif
382
383 if (L == layout::right)
384 return _data[i*_offset[0] + j];
385 else if (L == layout::left)
386 return _data[i + j*_offset[1]];
387 else
388 return _data[i*_offset[0] + j*_offset[1]];
389 }
390
391 /*--------------------------------------------------------------------------*/
397 /*--------------------------------------------------------------------------*/
398
399 template<typename... Args>
401 inline
402 std::enable_if_t<cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
403 operator()
404 (
405 Args... indices
406 )
407 {
408 check_operator_args_(indices...);
409#if defined(CS_ARRAY_DBG_BOUNDS)
410 check_bounds_(indices...);
411#endif
412
413 return _data[data_offset_(indices...)];
414 }
415
416 /*--------------------------------------------------------------------------*/
422 /*--------------------------------------------------------------------------*/
423
424 template<typename... Args>
426 inline
427 std::enable_if_t<cs::always_true<Args...>::value && (N!=2) && (N!=1), T&>
428 operator()
429 (
430 Args... indices
431 ) const
432 {
433 check_operator_args_(indices...);
434#if defined(CS_ARRAY_DBG_BOUNDS)
435 check_bounds_(indices...);
436#endif
437
438 return _data[data_offset_(indices...)];
439 }
440
441 /*===========================================================================
442 * Getters / Setters
443 *==========================================================================*/
444
445 /*--------------------------------------------------------------------------*/
449 /*--------------------------------------------------------------------------*/
450
452 void
454 (
455 T* data_ptr
456 ) const
457 {
458 _data = data_ptr;
459 }
460
461 /*--------------------------------------------------------------------------*/
465 /*--------------------------------------------------------------------------*/
466
467 template<typename... Args>
469 void
471 (
472 T* data_ptr,
473 Args... dims
474 )
475 {
476 check_operator_args_(dims...);
477 set_size_(dims...);
478 set_data_ptr(data_ptr);
479 }
480
481 /*--------------------------------------------------------------------------*/
487 /*--------------------------------------------------------------------------*/
488
490 inline
491 bool
492 empty() const
493 {
494 return (_size == 0);
495 }
496
497 /*--------------------------------------------------------------------------*/
503 /*--------------------------------------------------------------------------*/
504
506 inline
508 size() const
509 {
510 return _size;
511 }
512
513 /*--------------------------------------------------------------------------*/
519 /*--------------------------------------------------------------------------*/
520
522 inline
525 (
526 int i
527 ) const
528 {
529 return _extent[i];
530 }
531
532 /*--------------------------------------------------------------------------*/
538 /*--------------------------------------------------------------------------*/
539
541 inline
544 (
545 int i
546 ) const
547 {
548 return _offset[i];
549 }
550
551 /*--------------------------------------------------------------------------*/
557 /*--------------------------------------------------------------------------*/
558
560 T*
561 data() const
562 {
563 return _data;
564 }
565
566 /*--------------------------------------------------------------------------*/
574 /*--------------------------------------------------------------------------*/
575
576 template<typename U>
578 U*
579 data() const
580 {
581 return reinterpret_cast<U*>(_data);
582 }
583
584 /*--------------------------------------------------------------------------*/
590 /*--------------------------------------------------------------------------*/
591
595 {
596 return mdspan<T,1,L>(_data, _size);
597 }
598
599 /*--------------------------------------------------------------------------*/
605 /*--------------------------------------------------------------------------*/
606
607 template<typename... Args>
609 mdspan<T, N-sizeof...(Args), L>
611 (
612 Args... indices
613 )
614 {
615 check_sub_function_args_(indices...);
616
617 constexpr int n_idx = sizeof...(Args);
618
619 cs_lnum_t dims[N - n_idx];
620
621 if (L == layout::right) {
622 for (int i = 0; i < N - n_idx; i++)
623 dims[i] = _extent[i+n_idx];
624 }
625 else if (L == layout::left) {
626 for (int i = 0; i < N - n_idx; i++)
627 dims[i] = _extent[i];
628 }
629
630 return mdspan<T,N-n_idx,L>(_data + contiguous_data_offset_(indices...), dims);
631 }
632
633 /*--------------------------------------------------------------------------*/
637 /*--------------------------------------------------------------------------*/
638
639 template<typename... Args>
641 T*
643 (
644 Args... indices
645 )
646 {
647 check_sub_function_args_(indices...);
648
649 return _data + contiguous_data_offset_(indices...);
650 }
651
652 /*--------------------------------------------------------------------------*/
656 /*--------------------------------------------------------------------------*/
657
658 template<typename... Args>
660 T*
662 (
663 Args... indices
664 ) const
665 {
666 check_sub_function_args_(indices...);
667
668 return _data + contiguous_data_offset_(indices...);
669 }
670
671 /*--------------------------------------------------------------------------*/
675 /*--------------------------------------------------------------------------*/
676
678 inline
680 (
681 T val,
682 const cs_lnum_t n_vals = -1
684 )
685 {
686 auto& ctx = cs::execution::default_context();
687 set_to_val(ctx, val, n_vals);
688 ctx.wait();
689 }
690
691 /*--------------------------------------------------------------------------*/
697 /*--------------------------------------------------------------------------*/
698
701 (
703 T val,
704 const cs_lnum_t n_vals = -1
706 )
707 {
708 assert(n_vals <= _size);
709
710 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
711
712 // Explicit pointer, avoid passing internal member of class to the functor
713 T* data_ptr = _data;
714
715 /* No wait here since context is passed as argument */
716 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
717 data_ptr[e_id] = val;
718 });
719 }
720
721 /*--------------------------------------------------------------------------*/
725 /*--------------------------------------------------------------------------*/
726
728 inline
730 (
731 T val,
732 const cs_lnum_t n_elts,
733 const cs_lnum_t elt_ids[]
734 )
735 {
736 auto& ctx = cs::execution::default_context();
737 set_to_val_on_subset(ctx, val, n_elts, elt_ids);
738 ctx.wait();
739 }
740
741 /*--------------------------------------------------------------------------*/
747 /*--------------------------------------------------------------------------*/
748
751 (
753 T val,
754 const cs_lnum_t n_elts,
755 const cs_lnum_t elt_ids[]
756 )
757 {
758 assert(n_elts <= _size && n_elts >= 0);
759
760 if (n_elts < 1)
761 return;
762
763 /* No wait here since context is passed as argument */
764 if (elt_ids == nullptr)
765 set_to_val(ctx, val, n_elts);
766 else {
767 // Explicit pointer, avoid passing internal member of class to the functor
768 T* data_ptr = _data;
769 ctx.parallel_for(n_elts, CS_LAMBDA (cs_lnum_t e_id) {
770 data_ptr[elt_ids[e_id]] = val;
771 });
772 }
773 }
774
775 /*--------------------------------------------------------------------------*/
779 /*--------------------------------------------------------------------------*/
780
782 inline
783 void
785 {
786 auto& ctx = cs::execution::default_context();
787 zero(ctx);
788 ctx.wait();
789 }
790
791 /*--------------------------------------------------------------------------*/
795 /*--------------------------------------------------------------------------*/
796
798 void
800 (
802 )
803 {
804 // Explicit pointer, avoid passing internal member of class to the functor
805 T* data_ptr = _data;
806
808 data_ptr[e_id] = static_cast<T>(0);
809 });
810 }
811
812 /*--------------------------------------------------------------------------*/
817 /*--------------------------------------------------------------------------*/
818
820 void
821 inline
823 (
824 const T *data,
825 const cs_lnum_t n_vals = -1
827 )
828 {
829 auto& ctx = cs::execution::default_context();
830 copy_data(ctx, data, n_vals);
831 ctx.wait();
832 }
833
834 /*--------------------------------------------------------------------------*/
839 /*--------------------------------------------------------------------------*/
840
842 inline
843 void
845 (
846 mdspan& other,
847 const cs_lnum_t n_vals = -1
849 )
850 {
851 auto& ctx = cs::execution::default_context();
852 copy_data(ctx, other, n_vals);
853 ctx.wait();
854 }
855
856 /*--------------------------------------------------------------------------*/
862 /*--------------------------------------------------------------------------*/
863
865 void
867 (
869 T *data,
870 const cs_lnum_t n_vals = -1
872 )
873 {
874 assert(n_vals <= _size);
875
876 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
877
878 // Explicit pointer, avoid passing internal member of class to the functor
879 T* data_ptr = _data;
880
881 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
882 data_ptr[e_id] = data[e_id];
883 });
884 }
885
886 /*--------------------------------------------------------------------------*/
892 /*--------------------------------------------------------------------------*/
893
895 void
897 (
899 const T *data,
900 const cs_lnum_t n_vals = -1
902 )
903 {
904 assert(n_vals <= _size);
905
906 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
907
908 // Explicit pointer, avoid passing internal member of class to the functor
909 T* data_ptr = _data;
910
911 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
912 data_ptr[e_id] = data[e_id];
913 });
914 }
915
916 /*--------------------------------------------------------------------------*/
921 /*--------------------------------------------------------------------------*/
922
924 void
926 (
928 mdspan &other,
929 const cs_lnum_t n_vals = -1
931 )
932 {
933 const cs_lnum_t loop_size = (n_vals == -1) ? _size : n_vals;
934
935 assert(loop_size <= _size);
936 assert(loop_size <= other.size());
937
938 // Explicit pointer, avoid passing internal member of class to the functor
939 T* data_ptr = _data;
940 T* o_data_ptr = other._data;
941
942 ctx.parallel_for(loop_size, CS_LAMBDA (cs_lnum_t e_id) {
943 data_ptr[e_id] = o_data_ptr[e_id];
944 });
945 }
946
947//private:
948protected:
949
950 /*--------------------------------------------------------------------------*/
954 /*--------------------------------------------------------------------------*/
955
956 template<typename... Args>
958 static inline
959 void
961 (
962 Args...
963 )
964 {
965 static_assert(sizeof...(Args) == N, "Wrong number of arguments");
966 static_assert(sizeof...(Args) != 0, "No input arguments provided...");
967 static_assert(cs::are_integral<Args...>::value, "Non integral input arguments.");
968 }
969
970 /*--------------------------------------------------------------------------*/
974 /*--------------------------------------------------------------------------*/
975
976 template<typename... Args>
978 static inline
979 void
981 (
982 Args...
983 )
984 {
985 static_assert(sizeof...(Args) < N, "Too many input arguments.");
986 static_assert(sizeof...(Args) != 0, "No input arguments provided...");
987 static_assert(cs::are_integral<Args...>::value, "Non integral indices provided");
988 }
989
990 /*--------------------------------------------------------------------------*/
994 /*--------------------------------------------------------------------------*/
995
996 template<typename... Args>
998 inline
1001 (
1002 Args... indices
1003 ) const
1004 {
1005 static_assert(sizeof...(Args) <= N && sizeof...(Args) > 0,
1006 "Number of indices is out of bounds");
1007
1008 constexpr int n_idx = sizeof...(Args);
1009
1010 cs_lnum_t _indices[n_idx] = {indices...};
1011
1012 cs_lnum_t retval = 0;
1013 for (int i = 0; i < n_idx; i++)
1014 retval +=_indices[i] * _offset[i];
1015
1016 return retval;
1017 }
1018
1019 /*--------------------------------------------------------------------------*/
1023 /*--------------------------------------------------------------------------*/
1024
1025 template<typename... Args>
1027 inline
1028 cs_lnum_t
1030 (
1031 Args... indices
1032 ) const
1033 {
1034 static_assert(sizeof...(Args) <= N && sizeof...(Args) > 0,
1035 "Number of indices is out of bounds");
1036
1037 constexpr int n_idx = sizeof...(Args);
1038
1039 cs_lnum_t _indices[n_idx] = {indices...};
1040
1041 cs_lnum_t retval = 0;
1042 if (L == layout::right) {
1043 for (int i = 0; i < n_idx; i++)
1044 retval +=_indices[i] * _offset[i];
1045 }
1046 else if (L == layout::left) {
1047 for (int i = 0; i < n_idx; i++)
1048 retval +=_indices[i] * _offset[N-1-i];
1049 }
1050
1051 return retval;
1052 }
1053
1054 /*===========================================================================
1055 * Private methods
1056 *==========================================================================*/
1057
1058 /*--------------------------------------------------------------------------*/
1062 /*--------------------------------------------------------------------------*/
1063
1065 void
1067 (
1068 const cs_lnum_t(&dims)[N]
1069 )
1070 {
1071 _size = (N > 0) ? 1 : 0;
1072 for (int i = 0; i < N; i++) {
1073 _extent[i] = dims[i];
1074 _size *= dims[i];
1075 _offset[i] = 1;
1076 }
1077
1078 /* Compute offset values for getters */
1079
1080 if (L == layout::right) {
1081 /* Version for Layout right */
1082 for (int i = 0; i < N-1; i++) {
1083 for (int j = i + 1; j < N; j++)
1084 _offset[i] *= dims[j];
1085 }
1086 }
1087 else if (L == layout::left) {
1088 for (int i = N-1; i >= 1; i--) {
1089 for (int j = i - 1; j >= 0; j--)
1090 _offset[i] *= dims[j];
1091 }
1092 }
1093 }
1094
1095 /*--------------------------------------------------------------------------*/
1099 /*--------------------------------------------------------------------------*/
1100
1101 template<typename... Args>
1103 void
1105 (
1106 Args... dims
1107 )
1108 {
1109 check_operator_args_(dims...);
1110
1111 cs_lnum_t loc_dims[N] = {dims...};
1112
1113 set_size_(loc_dims);
1114 }
1115
1116 /*--------------------------------------------------------------------------*/
1122 /*--------------------------------------------------------------------------*/
1123
1124 template<typename... Args>
1126 inline
1127 bool
1129 (
1130 Args... dims
1131 ) const
1132 {
1133 bool out_of_bounds = false;
1134 constexpr int n_idx = sizeof...(Args);
1135 cs_lnum_t idx[n_idx] = {dims...};
1136 for (int i = 0; i < n_idx; i++) {
1137 if (idx[i] >= _extent[i]) {
1138 out_of_bounds = true;
1139 break;
1140 }
1141 }
1142
1143 if (out_of_bounds) {
1144 char err[256] = "Error: Out of bounds access with indices [";
1145 const char *sep = ",\0";
1146 const char *closeb = "]\0";
1147 for (int i = 0; i < n_idx; i++) {
1148 char tmp[20] = "";
1149 uint_to_char(tmp, idx[i]);
1150 concatenate_char(err, tmp);
1151 if (i < n_idx - 1)
1152 concatenate_char(err, sep);
1153 }
1154 concatenate_char(err, closeb);
1155
1156 const char *tmp2 = " but extents are [\0";
1157 concatenate_char(err, tmp2);
1158 for (int i = 0; i < n_idx; i++) {
1159 char tmp[20] = "";
1160 uint_to_char(tmp, _extent[i]);
1161 concatenate_char(err, tmp);
1162 if (i < n_idx - 1)
1163 concatenate_char(err, sep);
1164 }
1165 concatenate_char(err, closeb);
1166
1167#if !defined(__CUDA_ARCH__) && \
1168 !defined(SYCL_LANGUAGE_VERSION) && \
1169 !defined(__HIP_DEVICE_COMPILE__)
1170 bft_error(__FILE__,__LINE__,0,"%s\n", err);
1171#else
1172 const char *empty_str = " ";
1173 __assert_fail(err, empty_str, 0, empty_str);
1174#endif
1175 }
1176 return out_of_bounds;
1177 }
1178
1179 /*===========================================================================
1180 * Private members
1181 *==========================================================================*/
1182
1186 mutable T* _data;
1187};
1188
1189} /* namespace cs */
1190
1191template<class T, cs::layout L = cs::layout::right>
1193
1194template<class T, cs::layout L = cs::layout::right>
1196
1197template<class T, cs::layout L = cs::layout::right>
1199
1200template<class T, cs::layout L = cs::layout::right>
1202
1203template<class T, int N>
1205
1206template<class T, int N>
1208
1209/*--------------------------------------------------------------------------*/
1210
1211#endif /* CS_MDSPAN_H */
void bft_error(const char *const file_name, const int line_num, const int sys_error_code, const char *const format,...)
Calls the error handler (set by bft_error_handler_set() or default).
Definition: bft_error.cpp:187
Define a templated array class (owner of data)
Definition: cs_array.h:1118
Define a templated mdspan class (non owner of data)
Definition: cs_mdspan.h:68
CS_F_HOST_DEVICE mdspan(mdspan &&other)
Move constructor.
Definition: cs_mdspan.h:153
CS_F_HOST_DEVICE friend void swap(mdspan &first, mdspan &second)
Class swap operator used for assignment or move.
Definition: cs_mdspan.h:182
CS_F_HOST void copy_data(cs_dispatch_context &ctx, T *data, const cs_lnum_t n_vals=-1)
Copy data from raw pointer, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:867
CS_F_HOST void set_to_val_on_subset(T val, const cs_lnum_t n_elts, const cs_lnum_t elt_ids[])
Set subset of values of the data array to a constant value.
Definition: cs_mdspan.h:730
CS_F_HOST void zero(cs_dispatch_context &ctx)
Set all values of the data array to 0.
Definition: cs_mdspan.h:800
CS_F_HOST void set_to_val(T val, const cs_lnum_t n_vals=-1)
Set all values of the data array to a constant value.
Definition: cs_mdspan.h:680
CS_F_HOST_DEVICE mdspan< T, 1, L > view_1d()
Get span 1D view of the array, same total size.
Definition: cs_mdspan.h:594
CS_F_HOST void copy_data(mdspan &other, const cs_lnum_t n_vals=-1)
Copy data from another mdspan, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:845
CS_F_HOST_DEVICE bool check_bounds_(Args... dims) const
Check if provided arguments are within array bounds.
Definition: cs_mdspan.h:1129
CS_F_HOST_DEVICE mdspan(T *data, const cs_lnum_t(&dims)[N])
Constructor method using dimensions.
Definition: cs_mdspan.h:120
CS_F_HOST_DEVICE U * data() const
Getter for data raw pointer with recast (casts T* to U*)
Definition: cs_mdspan.h:579
CS_F_HOST void copy_data(cs_dispatch_context &ctx, const T *data, const cs_lnum_t n_vals=-1)
Copy data from const raw pointer, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:897
CS_F_HOST_DEVICE void set_size_(const cs_lnum_t(&dims)[N])
Set size of array based on dimensions.
Definition: cs_mdspan.h:1067
CS_F_HOST_DEVICE cs_lnum_t contiguous_data_offset_(Args... indices) const
Helper function to compute value offset.
Definition: cs_mdspan.h:1030
T * _data
Definition: cs_mdspan.h:1186
CS_F_HOST_DEVICE bool empty() const
Check if object is empty or not.
Definition: cs_mdspan.h:492
CS_F_HOST_DEVICE mdspan & operator=(mdspan &&other)
Definition: cs_mdspan.h:217
static CS_F_HOST_DEVICE void check_sub_function_args_(Args...)
Helper function to static check sub-function input arguments.
Definition: cs_mdspan.h:981
CS_F_HOST_DEVICE T * sub_array(Args... indices)
Get sub array based on index.
Definition: cs_mdspan.h:643
CS_F_HOST_DEVICE cs_lnum_t size() const
Getter for total size.
Definition: cs_mdspan.h:508
CS_F_HOST_DEVICE cs_lnum_t offset(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:544
CS_F_HOST void zero()
Set all values of the data array to 0.
Definition: cs_mdspan.h:784
CS_F_HOST void set_to_val_on_subset(cs_dispatch_context &ctx, T val, const cs_lnum_t n_elts, const cs_lnum_t elt_ids[])
Set a subset of values of the data array to a constant value while providing a dispatch context....
Definition: cs_mdspan.h:751
CS_F_HOST_DEVICE mdspan()
Default constructor method leading to "empty container".
Definition: cs_mdspan.h:86
cs_lnum_t _size
Definition: cs_mdspan.h:1185
CS_F_HOST_DEVICE cs_lnum_t data_offset_(Args... indices) const
Helper function to compute value offset.
Definition: cs_mdspan.h:1001
cs_lnum_t _extent[N]
Definition: cs_mdspan.h:1183
CS_F_HOST_DEVICE ~mdspan()
Desstructor method using dimensions.
Definition: cs_mdspan.h:168
static CS_F_HOST_DEVICE void check_operator_args_(Args...)
Helper function to static check operator input arguments.
Definition: cs_mdspan.h:961
CS_F_HOST_DEVICE void set_size_(Args... dims)
Set size of N indices (variadic template)
Definition: cs_mdspan.h:1105
CS_F_HOST_DEVICE void update_data(T *data_ptr, Args... dims)
Update data pointer and dimensions of span.
Definition: cs_mdspan.h:471
cs_lnum_t _offset[N]
Definition: cs_mdspan.h:1184
CS_F_HOST_DEVICE mdspan(const mdspan &other)
Constructor method using copy. May be a shallow copy.
Definition: cs_mdspan.h:137
CS_F_HOST_DEVICE T * data() const
Getter for data raw pointer.
Definition: cs_mdspan.h:561
CS_F_HOST_DEVICE mdspan< T, N-sizeof...(Args), L > sub_view(Args... indices)
Getter for a subspan based on first dimension.
Definition: cs_mdspan.h:611
CS_F_HOST_DEVICE cs_lnum_t extent(int i) const
Getter for extent along a given dimension.
Definition: cs_mdspan.h:525
CS_F_HOST void copy_data(const T *data, const cs_lnum_t n_vals=-1)
Copy data from const raw pointer, we suppose that data size is same as that of the array.
Definition: cs_mdspan.h:823
CS_F_HOST_DEVICE mdspan(T *data, Args... indices)
Constructor method using only global size (works for N=1).
Definition: cs_mdspan.h:102
CS_F_HOST void set_to_val(cs_dispatch_context &ctx, T val, const cs_lnum_t n_vals=-1)
Set all values of the data array to a constant value while providing a dispatch context....
Definition: cs_mdspan.h:701
CS_F_HOST void copy_data(cs_dispatch_context &ctx, mdspan &other, const cs_lnum_t n_vals=-1)
Copy data from another mdspan, we suppose that data size is same as that of the array....
Definition: cs_mdspan.h:926
CS_F_HOST_DEVICE void set_data_ptr(T *data_ptr) const
Set data pointer.
Definition: cs_mdspan.h:454
CS_F_HOST_DEVICE T * sub_array(Args... indices) const
Get sub array based on index.
Definition: cs_mdspan.h:662
CS_F_HOST mdspan & operator=(const mdspan &other)
Assignment operator.
Definition: cs_mdspan.h:204
auto parallel_for(cs_lnum_t n, F &&f, Args &&... args)
Definition: cs_dispatch.h:2146
Definition: cs_dispatch.h:2288
#define CS_F_HOST_DEVICE
Definition: cs_defs.h:555
#define CS_LAMBDA
Definition: cs_defs.h:564
int cs_lnum_t
local mesh entity id
Definition: cs_defs.h:325
#define CS_F_HOST
Definition: cs_defs.h:553
cs_dispatch_context & default_context(void)
Definition: cs_execution_context.cpp:62
Definition: cs_algorithm.h:51
layout
Definition: cs_mdspan.h:51
CS_F_HOST_DEVICE void concatenate_char(char *dest, const char *src)
Concatenate two strings (char *)
Definition: cs_defs.h:922
CS_F_HOST_DEVICE void uint_to_char(char *dest, Id1 val)
Convert an unsigned integer to an array of char.
Definition: cs_defs.h:886
CS_F_HOST_DEVICE constexpr std::enable_if_t< std::is_move_constructible< T >::value &&std::is_move_assignable< T >::value > swap_objects(T &obj1, T &obj2)
A swap method which is callable from GPU and not only CPU.
Definition: cs_defs.h:814
Utility template which returns "true" for a given pack. This is necessary of std::enable_if_t<> when ...
Definition: cs_defs.h:798
Utility template to check if a pack of parameters is made of integral types.
Definition: cs_defs.h:775