YAKL
YAKL_CArray.h
Go to the documentation of this file.
1 
2 #pragma once
3 // Included by YAKL_Array.h
4 
6 namespace yakl {
7 
54  template <class T, int rank, int myMem>
55  class Array<T,rank,myMem,styleC> : public ArrayBase<T,rank,myMem,styleC> {
56  public:
57 
59  typedef typename std::remove_cv<T>::type type;
61  typedef T value_type;
64  typedef typename std::add_const<type>::type const_value_type;
67  typedef typename std::remove_const<type>::type non_const_value_type;
68 
69 
70  // Start off all constructors making sure the pointers are null
72  YAKL_INLINE void nullify() {
73  this->myData = nullptr;
74  this->refCount = nullptr;
75  for (int i=0; i < rank; i++) { this->dimension[i] = 0; }
76  #ifdef YAKL_DEBUG
77  this->myname="Uninitialized";
78  #endif
79  }
80 
81  /* CONSTRUCTORS
82  Always nullify before beginning so that myData == nullptr upon init.
83  */
86  nullify();
87  }
89  YAKL_INLINE explicit Array(char const * label) {
90  nullify();
91  #ifdef YAKL_DEBUG
92  this->myname = label;
93  #endif
94  }
95 
96  // This exists to hold common documentation for all owned constructors.
119  YAKL_INLINE Array( char const* label , index_t d1 ) : Array(label,Dims(d1)) {
120  static_assert( rank == 1 , "ERROR: Calling constructor with 1 bound on non-rank-1 array" );
121  }
124  YAKL_INLINE Array( char const* label , index_t d1 ,
125  index_t d2 ) : Array(label,Dims(d1,d2)) {
126  static_assert( rank == 2 , "ERROR: Calling constructor with 2 bound on non-rank-2 array" );
127  }
130  YAKL_INLINE Array( char const* label , index_t d1 ,
131  index_t d2 ,
132  index_t d3 ) : Array(label,Dims(d1,d2,d3)) {
133  static_assert( rank == 3 , "ERROR: Calling constructor with 3 bound on non-rank-3 array" );
134  }
137  YAKL_INLINE Array( char const* label , index_t d1 ,
138  index_t d2 ,
139  index_t d3 ,
140  index_t d4 ) : Array(label,Dims(d1,d2,d3,d4)) {
141  static_assert( rank == 4 , "ERROR: Calling constructor with 4 bound on non-rank-4 array" );
142  }
145  YAKL_INLINE Array( char const* label , index_t d1 ,
146  index_t d2 ,
147  index_t d3 ,
148  index_t d4 ,
149  index_t d5 ) : Array(label,Dims(d1,d2,d3,d4,d5)) {
150  static_assert( rank == 5 , "ERROR: Calling constructor with 5 bound on non-rank-5 array" );
151  }
154  YAKL_INLINE Array( char const* label , index_t d1 ,
155  index_t d2 ,
156  index_t d3 ,
157  index_t d4 ,
158  index_t d5 ,
159  index_t d6 ) : Array(label,Dims(d1,d2,d3,d4,d5,d6)) {
160  static_assert( rank == 6 , "ERROR: Calling constructor with 6 bound on non-rank-6 array" );
161  }
164  YAKL_INLINE Array( char const* label , index_t d1 ,
165  index_t d2 ,
166  index_t d3 ,
167  index_t d4 ,
168  index_t d5 ,
169  index_t d6 ,
170  index_t d7 ) : Array(label,Dims(d1,d2,d3,d4,d5,d6,d7)) {
171  static_assert( rank == 7 , "ERROR: Calling constructor with 7 bound on non-rank-7 array" );
172  }
175  YAKL_INLINE Array( char const* label , index_t d1 ,
176  index_t d2 ,
177  index_t d3 ,
178  index_t d4 ,
179  index_t d5 ,
180  index_t d6 ,
181  index_t d7 ,
182  index_t d8 ) : Array(label,Dims(d1,d2,d3,d4,d5,d6,d7,d8)) {
183  static_assert( rank == 8 , "ERROR: Calling constructor with 8 bound on non-rank-8 array" );
184  }
187  YAKL_INLINE Array(char const * label, Dims const dims) {
188  static_assert( rank >= 1 && rank <= 8 , "ERROR: Creating Array with a rank < 1 or > 8" );
189  nullify();
190  #ifdef YAKL_DEBUG
191  if (dims.size() != rank) yakl_throw("ERROR: Number of constructor dimensions does not match the Array rank");
192  #endif
193  YAKL_EXECUTE_ON_HOST_ONLY( this->deallocate(); )
194  #ifdef YAKL_DEBUG
195  this->myname = label;
196  #endif
197  for (int i=0; i < rank; i++) { this->dimension[i] = dims[i]; }
198  YAKL_EXECUTE_ON_HOST_ONLY( this->allocate(); )
199  }
200 
201 
202  // This exists to hold common documentation for all non-owned constructors.
231  YAKL_INLINE Array(char const *label, T *data, index_t const d1) : Array(label,data,Dims(d1)) {
232  static_assert( rank == 1 , "ERROR: Calling constructor with 1 bound on non-rank-1 array" );
233  }
236  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
237  index_t const d2) : Array(label,data,Dims(d1,d2)) {
238  static_assert( rank == 2 , "ERROR: Calling constructor with 2 bound on non-rank-2 array" );
239  }
242  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
243  index_t const d2,
244  index_t const d3) : Array(label,data,Dims(d1,d2,d3)) {
245  static_assert( rank == 3 , "ERROR: Calling constructor with 3 bound on non-rank-3 array" );
246  }
249  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
250  index_t const d2,
251  index_t const d3,
252  index_t const d4) : Array(label,data,Dims(d1,d2,d3,d4)) {
253  static_assert( rank == 4 , "ERROR: Calling constructor with 4 bound on non-rank-4 array" );
254  }
257  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
258  index_t const d2,
259  index_t const d3,
260  index_t const d4,
261  index_t const d5) : Array(label,data,Dims(d1,d2,d3,d4,d5)) {
262  static_assert( rank == 5 , "ERROR: Calling constructor with 5 bound on non-rank-5 array" );
263  }
266  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
267  index_t const d2,
268  index_t const d3,
269  index_t const d4,
270  index_t const d5,
271  index_t const d6) : Array(label,data,Dims(d1,d2,d3,d4,d5,d6)) {
272  static_assert( rank == 6 , "ERROR: Calling constructor with 6 bound on non-rank-6 array" );
273  }
276  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
277  index_t const d2,
278  index_t const d3,
279  index_t const d4,
280  index_t const d5,
281  index_t const d6,
282  index_t const d7) : Array(label,data,Dims(d1,d2,d3,d4,d5,d6,d7)) {
283  static_assert( rank == 7 , "ERROR: Calling constructor with 7 bound on non-rank-7 array" );
284  }
287  YAKL_INLINE Array(char const *label, T *data, index_t const d1,
288  index_t const d2,
289  index_t const d3,
290  index_t const d4,
291  index_t const d5,
292  index_t const d6,
293  index_t const d7,
294  index_t const d8) : Array(label,data,Dims(d1,d2,d3,d4,d5,d6,d7,d8)) {
295  static_assert( rank == 8 , "ERROR: Calling constructor with 8 bound on non-rank-8 array" );
296  }
299  YAKL_INLINE Array(char const *label, T *data, Dims const dims) {
300  static_assert( rank >= 1 && rank <= 8 , "ERROR: Creating Array with a rank < 1 or > 8" );
301  nullify();
302  #ifdef YAKL_DEBUG
303  if ( dims.size() < rank ) yakl_throw("ERROR: dims < rank");
304  if (data == nullptr) yakl_throw("ERROR: wrapping nullptr with a YAKL Array object");
305  this->myname = label;
306  #endif
307  for (int i=0; i < rank; i++) { this->dimension[i] = dims[i]; }
308  this->myData = data;
309  this->refCount = nullptr;
310  }
311 
312 
313  /*
314  COPY CONSTRUCTORS / FUNCTIONS
315  This shares the pointers with another Array and increments the refCounter
316  */
319  // constructor, so no need to deallocate
320  nullify();
321  copy_constructor_common(rhs);
322  }
325  static_assert( std::is_const<T>::value ,
326  "ERROR: Cannot create non-const Array using const Array" );
327  // constructor, so no need to deallocate
328  nullify();
329  copy_constructor_common(rhs);
330  }
331 
332 
335  if constexpr (! std::is_const<T>::value) {
336  if (this == &rhs) { return *this; }
337  }
338  YAKL_EXECUTE_ON_HOST_ONLY( this->deallocate(); )
339  copy_constructor_common(rhs);
340  return *this;
341  }
344  static_assert( std::is_const<T>::value ,
345  "ERROR: Cannot create non-const Array using const Array" );
346  if constexpr (std::is_const<T>::value) {
347  if (this == &rhs) { return *this; }
348  }
349  YAKL_EXECUTE_ON_HOST_ONLY( this->deallocate(); )
350  copy_constructor_common(rhs);
351  return *this;
352  }
353 
355  template <class TLOC>
356  YAKL_INLINE void copy_constructor_common(Array<TLOC,rank,myMem,styleC> const &rhs) {
357  for (int i=0; i<rank; i++) {
358  this->dimension[i] = rhs.dimension[i];
359  }
360  #ifdef YAKL_DEBUG
361  this->myname = rhs.myname;
362  #endif
363  this->myData = rhs.myData;
364  YAKL_EXECUTE_ON_HOST_ONLY( yakl_mtx_lock(); )
365  this->refCount = rhs.refCount;
366  if (this->refCount != nullptr) {
367  // YAKL_EXECUTE_ON_HOST_ONLY( (*(this->refCount))++; ) // This gives an nvc++ error
368  YAKL_EXECUTE_ON_HOST_ONLY( { (*(this->refCount))++; } ) // This works around the nvc++ error
369  }
370  YAKL_EXECUTE_ON_HOST_ONLY( yakl_mtx_unlock(); )
371  }
372 
373 
374  /*
375  MOVE CONSTRUCTORS
376  This steals the pointers form the rhs rather than sharing and sets rhs pointers to nullptr.
377  Therefore, no need to increment refCout
378  */
381  // constructor, so no need to deallocate
382  nullify();
383  for (int i=0; i<rank; i++) {
384  this->dimension[i] = rhs.dimension[i];
385  }
386  #ifdef YAKL_DEBUG
387  this->myname = rhs.myname;
388  #endif
389  this->myData = rhs.myData;
390  rhs.myData = nullptr;
391 
392  this->refCount = rhs.refCount;
393  rhs.refCount = nullptr;
394  }
395 
396 
399  if (this == &rhs) { return *this; }
400  YAKL_EXECUTE_ON_HOST_ONLY( this->deallocate(); )
401  for (int i=0; i<rank; i++) {
402  this->dimension[i] = rhs.dimension[i];
403  }
404  #ifdef YAKL_DEBUG
405  this->myname = rhs.myname;
406  #endif
407  this->myData = rhs.myData;
408  rhs.myData = nullptr;
409 
410  this->refCount = rhs.refCount;
411  rhs.refCount = nullptr;
412 
413  return *this;
414  }
415 
416 
417  /*
418  DESTRUCTOR
419  Decrement the refCounter, and if it's zero, deallocate and nullify.
420  */
423  YAKL_EXECUTE_ON_HOST_ONLY( this->deallocate(); )
424  }
425 
426 
429  nullify();
430  if (myMem == memDevice && (! ir.data_valid_on_device())) yakl_throw("ERROR: wrapping non-device-valid ArrayIR with memDevice yakl::CArray");
431  if (myMem == memHost && (! ir.data_valid_on_host ())) yakl_throw("ERROR: wrapping non-host-valid ArrayIR with memHost yakl::CArray");
432  this->myData = ir.data();
433  #ifdef YAKL_DEBUG
434  this->myname = ir.label();
435  #endif
436  for (int i=0; i < rank; i++) { this->dimension[i] = ir.extent(i); }
437  }
438 
439 
441  template <class TLOC = T>
443  std::array<size_t,rank> dimensions;
444  for (int i=0; i < rank; i++) { dimensions[i] = this->dimension[i]; }
445  if (myMem == memHost) {
446  return array_ir::ArrayIR<TLOC,rank>(const_cast<TLOC *>(this->myData),dimensions,array_ir::MEMORY_HOST,this->label());
447  } else {
448  #ifdef YAKL_MANAGED_MEMORY
449  return array_ir::ArrayIR<TLOC,rank>(const_cast<TLOC *>(this->myData),dimensions,array_ir::MEMORY_SHARED,this->label());
450  #else
451  return array_ir::ArrayIR<TLOC,rank>(const_cast<TLOC *>(this->myData),dimensions,array_ir::MEMORY_DEVICE,this->label());
452  #endif
453  }
454  }
455 
456 
457  // Common detailed documentation for all indexers
466  /* ARRAY INDEXERS (FORTRAN index ordering)
467  Return the element at the given index (either read-only or read-write)
468  */
472  static_assert( rank == 1 , "ERROR: Indexing non-rank-1 array with 1 index" );
473  #ifdef YAKL_DEBUG
474  check(i0);
475  #endif
476  index_t ind = i0;
477  return this->myData[ind];
478  }
482  static_assert( rank == 2 , "ERROR: Indexing non-rank-2 array with 2 indices" );
483  #ifdef YAKL_DEBUG
484  check(i0,i1);
485  #endif
486  index_t ind = i0*this->dimension[1] + i1;
487  return this->myData[ind];
488  }
492  static_assert( rank == 3 , "ERROR: Indexing non-rank-3 array with 3 indices" );
493  #ifdef YAKL_DEBUG
494  check(i0,i1,i2);
495  #endif
496  index_t ind = (i0*this->dimension[1] + i1)*
497  this->dimension[2] + i2;
498  return this->myData[ind];
499  }
503  static_assert( rank == 4 , "ERROR: Indexing non-rank-4 array with 4 indices" );
504  #ifdef YAKL_DEBUG
505  check(i0,i1,i2,i3);
506  #endif
507  index_t ind = ((i0*this->dimension[1] + i1)*
508  this->dimension[2] + i2)*
509  this->dimension[3] + i3;
510  return this->myData[ind];
511  }
514  YAKL_INLINE T &operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4) const {
515  static_assert( rank == 5 , "ERROR: Indexing non-rank-5 array with 5 indices" );
516  #ifdef YAKL_DEBUG
517  check(i0,i1,i2,i3,i4);
518  #endif
519  index_t ind = (((i0*this->dimension[1] + i1)*
520  this->dimension[2] + i2)*
521  this->dimension[3] + i3)*
522  this->dimension[4] + i4;
523  return this->myData[ind];
524  }
527  YAKL_INLINE T &operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5) const {
528  static_assert( rank == 6 , "ERROR: Indexing non-rank-6 array with 6 indices" );
529  #ifdef YAKL_DEBUG
530  check(i0,i1,i2,i3,i4,i5);
531  #endif
532  index_t ind = ((((i0*this->dimension[1] + i1)*
533  this->dimension[2] + i2)*
534  this->dimension[3] + i3)*
535  this->dimension[4] + i4)*
536  this->dimension[5] + i5;
537  return this->myData[ind];
538  }
541  YAKL_INLINE T &operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6) const {
542  static_assert( rank == 7 , "ERROR: Indexing non-rank-7 array with 7 indices" );
543  #ifdef YAKL_DEBUG
544  check(i0,i1,i2,i3,i4,i5,i6);
545  #endif
546  index_t ind = (((((i0*this->dimension[1] + i1)*
547  this->dimension[2] + i2)*
548  this->dimension[3] + i3)*
549  this->dimension[4] + i4)*
550  this->dimension[5] + i5)*
551  this->dimension[6] + i6;
552  return this->myData[ind];
553  }
557  index_t i7) const {
558  static_assert( rank == 8 , "ERROR: Indexing non-rank-8 array with 8 indices" );
559  #ifdef YAKL_DEBUG
560  check(i0,i1,i2,i3,i4,i5,i6,i7);
561  #endif
562  index_t ind = ((((((i0*this->dimension[1] + i1)*
563  this->dimension[2] + i2)*
564  this->dimension[3] + i3)*
565  this->dimension[4] + i4)*
566  this->dimension[5] + i5)*
567  this->dimension[6] + i6)*
568  this->dimension[7] + i7;
569  return this->myData[ind];
570  }
571 
572 
574  YAKL_INLINE void check(index_t i0, index_t i1=0, index_t i2=0, index_t i3=0, index_t i4=0, index_t i5=0,
575  index_t i6=0, index_t i7=0) const {
576  #ifdef YAKL_DEBUG
577  if (! this->initialized()) { yakl_throw("Error: Using operator() on an Array that isn't allocated"); }
578  if constexpr (rank >= 1) { if (i0 >= this->dimension[0]) ind_out_bounds<0>(i0); }
579  if constexpr (rank >= 2) { if (i1 >= this->dimension[1]) ind_out_bounds<1>(i1); }
580  if constexpr (rank >= 3) { if (i2 >= this->dimension[2]) ind_out_bounds<2>(i2); }
581  if constexpr (rank >= 4) { if (i3 >= this->dimension[3]) ind_out_bounds<3>(i3); }
582  if constexpr (rank >= 5) { if (i4 >= this->dimension[4]) ind_out_bounds<4>(i4); }
583  if constexpr (rank >= 6) { if (i5 >= this->dimension[5]) ind_out_bounds<5>(i5); }
584  if constexpr (rank >= 7) { if (i6 >= this->dimension[6]) ind_out_bounds<6>(i6); }
585  if constexpr (rank >= 8) { if (i7 >= this->dimension[7]) ind_out_bounds<7>(i7); }
586  #if defined(YAKL_SEPARATE_MEMORY_SPACE)
587  YAKL_EXECUTE_ON_DEVICE_ONLY( if constexpr (myMem == memHost) yakl_throw("ERROR: host array being accessed in a device kernel"); )
588  #if !defined(YAKL_MANAGED_MEMORY)
590  if constexpr (myMem == memDevice) {
591  std::cerr << "ERROR: For Array labeled: " << this->myname << ":" << std::endl;
592  yakl_throw("Device array being accessed on the host without managed memory turned on");
593  }
594  )
595  #endif
596  #endif
597  #endif
598  }
599 
600 
601  // if this function gets called, then there was definitely an error
603  template <int I>
604  YAKL_INLINE void ind_out_bounds(index_t ind) const {
605  #ifdef YAKL_DEBUG
607  std::cerr << "ERROR: For Array labeled: " << this->myname << ":" << std::endl;
608  std::cerr << "Index " << I+1 << " of " << rank << " is out of bounds. Provided index: " << ind
609  << ". Upper Bound: " << this->dimension[I]-1 << std::endl;
610  )
611  yakl_throw("ERROR: Index out of bounds.");
612  #endif
613  }
614 
615 
617  template <class TLOC, typename std::enable_if<std::is_arithmetic<TLOC>::value,bool>::type = false>
618  Array operator=(TLOC const &rhs) const {
619  memset_loc(rhs);
620  return *this;
621  }
622 
623 
625  template <class TLOC>
626  void memset_loc(TLOC rhs) const {
627  if (myMem == memDevice) {
628  #ifdef YAKL_ENABLE_STREAMS
629  fence();
630  #endif
631  memset(*this, rhs);
632  #ifdef YAKL_ENABLE_STREAMS
633  fence();
634  #endif
635  } else {
636  for (int i=0; i < this->totElems(); i++) { this->myData[i] = rhs; }
637  }
638  }
639 
640 
644 
645 
648  #ifdef YAKL_DEBUG
649  if (! this->initialized()) { yakl_throw("ERROR: Trying to subset_slowest_dimension an Array that hasn't been initialized"); }
650  if (l < 0) { yakl_throw("ERROR: subset_slowest_dimension lower bound < 0"); }
651  if (u < 0) { yakl_throw("ERROR: subset_slowest_dimension upper bound < 0"); }
652  if (l > u) { yakl_throw("ERROR: subset_slowest_dimension lower bound > upper bounds"); }
653  if (u > this->dimension[0]-1) { yakl_throw("ERROR: subset_slowest_dimension upper bound out of bounds"); }
654  #endif
655  auto ret = *this;
656  auto &d = this->dimension;
657  if constexpr (rank == 1) ret.myData += l;
658  if constexpr (rank == 2) ret.myData += l*d[1];
659  if constexpr (rank == 3) ret.myData += l*d[1]*d[2];
660  if constexpr (rank == 4) ret.myData += l*d[1]*d[2]*d[3];
661  if constexpr (rank == 5) ret.myData += l*d[1]*d[2]*d[3]*d[4];
662  if constexpr (rank == 6) ret.myData += l*d[1]*d[2]*d[3]*d[4]*d[5];
663  if constexpr (rank == 7) ret.myData += l*d[1]*d[2]*d[3]*d[4]*d[5]*d[6];
664  if constexpr (rank == 8) ret.myData += l*d[1]*d[2]*d[3]*d[4]*d[5]*d[6]*d[7];
665  ret.dimension[0] = u-l+1;
666  return ret;
667  }
668 
669 
695  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( Dims const &dims ) const {
696  #ifdef YAKL_DEBUG
697  if (rank != dims.size()) {
698  YAKL_EXECUTE_ON_HOST_ONLY( std::cerr << "For Array named " << this->myname << ": "; )
699  yakl_throw("ERROR: slice rank must be equal to dims.size()");
700  }
701  for (int i = rank-1-N; i >= 0; i--) {
702  if (dims.data[i] >= this->dimension[i]) {
703  YAKL_EXECUTE_ON_HOST_ONLY( std::cerr << "For Array named " << this->myname << ": "; )
704  yakl_throw("ERROR: One of the slicing dimension dimensions is out of bounds");
705  }
706  }
707  if (! this->initialized()) {
708  YAKL_EXECUTE_ON_HOST_ONLY( std::cerr << "For Array named " << this->myname << ": "; )
709  yakl_throw("ERROR: calling slice() on an Array that hasn't been allocated");
710  }
711  #endif
713  index_t offset = 1;
714  for (int i = rank-1; i > rank-1-N; i--) {
715  ret.dimension[i-(rank-N)] = this->dimension[i];
716  offset *= this->dimension[i];
717  }
718  index_t retOff = 0;
719  for (int i = rank-1-N; i >= 0; i--) {
720  retOff += dims.data[i]*offset;
721  offset *= this->dimension[i];
722  }
723  ret.myData = &(this->myData[retOff]);
725  yakl_mtx_lock();
726  ret.refCount = this->refCount;
727  if (this->refCount != nullptr) {
728  (*(this->refCount))++;
729  }
730  yakl_mtx_unlock();
731  )
732  return ret;
733  }
736  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0 ) const {
737  static_assert( rank == 1 , "ERROR: Calling slice() with 1 index on a non-rank-1 array" );
738  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
739  return slice<N>( Dims(i0) );
740  }
743  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1 ) const {
744  static_assert( rank == 2 , "ERROR: Calling slice() with 2 index on a non-rank-2 array" );
745  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
746  return slice<N>( Dims(i0,i1) );
747  }
750  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1, int i2 ) const {
751  static_assert( rank == 3 , "ERROR: Calling slice() with 3 index on a non-rank-3 array" );
752  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
753  return slice<N>( Dims(i0,i1,i2) );
754  }
757  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1, int i2, int i3 ) const {
758  static_assert( rank == 4 , "ERROR: Calling slice() with 4 index on a non-rank-4 array" );
759  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
760  return slice<N>( Dims(i0,i1,i2,i3) );
761  }
764  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1, int i2, int i3, int i4 ) const {
765  static_assert( rank == 5 , "ERROR: Calling slice() with 5 index on a non-rank-5 array" );
766  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
767  return slice<N>( Dims(i0,i1,i2,i3,i4) );
768  }
771  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1, int i2, int i3, int i4, int i5 ) const {
772  static_assert( rank == 6 , "ERROR: Calling slice() with 6 index on a non-rank-6 array" );
773  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
774  return slice<N>( Dims(i0,i1,i2,i3,i4,i5) );
775  }
778  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1, int i2, int i3, int i4, int i5,
779  int i6 ) const {
780  static_assert( rank == 7 , "ERROR: Calling slice() with 7 index on a non-rank-7 array" );
781  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
782  return slice<N>( Dims(i0,i1,i2,i3,i4,i5,i6) );
783  }
786  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> slice( int i0, int i1, int i2, int i3, int i4, int i5, int i6,
787  int i7 ) const {
788  static_assert( rank == 8 , "ERROR: Calling slice() with 8 index on a non-rank-8 array" );
789  static_assert( N <= rank , "ERROR: Calling slice() with more dimenions than this array's rank" );
790  return slice<N>( Dims(i0,i1,i2,i3,i4,i5,i6,i7) );
791  }
792 
793 
820  template <int N> YAKL_INLINE Array<T,N,myMem,styleC> reshape(Dims const &dims) const {
821  #ifdef YAKL_DEBUG
822  if (! this->initialized()) { yakl_throw("ERROR: Trying to reshape an Array that hasn't been initialized"); }
823  if (dims.size() != N) { yakl_throw("ERROR: new number of reshaped array dimensions does not match the templated rank"); }
824  index_t totelems = 1;
825  for (int i=0; i < N; i++) { totelems *= dims.data[i]; }
826  if (totelems != this->totElems()) { yakl_throw("ERROR: Total number of reshaped array elements is not consistent with this array"); }
827  #endif
829  for (int i=0; i < N; i++) {
830  ret.dimension[i] = dims.data[i];
831  }
832  #ifdef YAKL_DEBUG
833  ret.myname = this->myname;
834  #endif
835  ret.myData = this->myData;
837  yakl_mtx_lock();
838  ret.refCount = this->refCount;
839  if (this->refCount != nullptr) {
840  (*(this->refCount))++;
841  }
842  yakl_mtx_unlock();
843  )
844  return ret;
845  }
848  YAKL_INLINE Array<T,1,myMem,styleC> reshape(index_t i0 ) const { return reshape<1>( Dims(i0) ); }
851  YAKL_INLINE Array<T,2,myMem,styleC> reshape(index_t i0, index_t i1 ) const { return reshape<2>( Dims(i0,i1) ); }
854  YAKL_INLINE Array<T,3,myMem,styleC> reshape(index_t i0, index_t i1, index_t i2 ) const { return reshape<3>( Dims(i0,i1,i2) ); }
857  YAKL_INLINE Array<T,4,myMem,styleC> reshape(index_t i0, index_t i1, index_t i2, index_t i3 ) const { return reshape<4>( Dims(i0,i1,i2,i3) ); }
860  YAKL_INLINE Array<T,5,myMem,styleC> reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4 ) const { return reshape<5>( Dims(i0,i1,i2,i3,i4) ); }
863  YAKL_INLINE Array<T,6,myMem,styleC> reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5 ) const { return reshape<6>( Dims(i0,i1,i2,i3,i4,i5) ); }
866  YAKL_INLINE Array<T,7,myMem,styleC> reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6 ) const { return reshape<7>( Dims(i0,i1,i2,i3,i4,i5,i6) ); }
869  YAKL_INLINE Array<T,8,myMem,styleC> reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6, index_t i7) const { return reshape<8>( Dims(i0,i1,i2,i3,i4,i5,i6,i7) ); }
870 
871 
885  #ifdef YAKL_DEBUG
886  if (! this->initialized()) { yakl_throw("ERROR: Trying to collapse an Array that hasn't been initialized"); }
887  #endif
889  ret.dimension[0] = this->totElems();
890  #ifdef YAKL_DEBUG
891  ret.myname = this->myname;
892  #endif
893  ret.myData = this->myData;
895  yakl_mtx_lock();
896  ret.refCount = this->refCount;
897  if (this->refCount != nullptr) {
898  (*(this->refCount))++;
899  }
900  yakl_mtx_unlock();
901  )
902  return ret;
903  }
904 
905 
906  // Create a host copy of this array. Even if the array exists on the host, a deep copy to a separate
907  // object is still performed to avoid any potential bugs when the user expects this behavior
919  template <class TLOC=T>
921  auto ret = createHostObject();
922  this->copy_inform(ret);
923  if (myMem == memHost) { memcpy_host_to_host ( ret.myData , this->myData , this->totElems() ); }
924  else { memcpy_device_to_host( ret.myData , this->myData , this->totElems() , stream ); }
925  if (stream.is_default_stream()) { fence(); }
926  else { stream.fence(); }
928  }
929 
930 
931  // Create a separately allocate host object with the same rank, memory space, and style
938  template <class TLOC=typename std::remove_cv<T>::type>
940  #ifdef YAKL_DEBUG
941  if (! this->initialized()) {
942  YAKL_EXECUTE_ON_HOST_ONLY( std::cerr << "For Array named " << this->myname << ": "; )
943  yakl_throw("Error: createHostObject() called on an Array that hasn't been allocated");
944  }
945  #endif
946  // If this Array is of const type, then we need to use non-const when allocating, then cast it to const aterward
948  for (int i=0; i<rank; i++) { ret.dimension[i] = this->dimension[i]; }
949  #ifdef YAKL_DEBUG
950  ret.myname = this->myname;
951  #endif
952  ret.allocate();
953  return ret;
954  }
955 
956 
957  // Create a device copy of this array. Even if the array exists on the host, a deep copy to a separate
958  // object is still performed to avoid any potential bugs when the user expects this behavior
970  template <class TLOC=T>
972  auto ret = createDeviceObject();
973  this->copy_inform(ret);
974  if (myMem == memHost) { memcpy_host_to_device ( ret.myData , this->myData , this->totElems() , stream ); }
975  else { memcpy_device_to_device( ret.myData , this->myData , this->totElems() , stream ); }
976  if (stream.is_default_stream()) { fence(); }
977  else { stream.fence(); }
979  }
980 
981 
982  // Create a separately allocate device object with the same rank, memory space, and style
989  template <class TLOC=typename std::remove_cv<T>::type>
991  #ifdef YAKL_DEBUG
992  if (! this->initialized()) {
993  YAKL_EXECUTE_ON_HOST_ONLY( std::cerr << "For Array named " << this->myname << ": "; )
994  yakl_throw("Error: createDeviceObject() called on an Array that hasn't been allocated.");
995  }
996  #endif
997  // If this Array is of const type, then we need to use non-const when allocating, then cast it to const aterward
999  for (int i=0; i<rank; i++) { ret.dimension[i] = this->dimension[i]; }
1000  #ifdef YAKL_DEBUG
1001  ret.myname = this->myname;
1002  #endif
1003  ret.allocate();
1004  return ret;
1005  }
1006 
1007 
1008  /* ACCESSORS */
1014  for (int i=0; i<rank; i++) { ret(i) = this->dimension[i]; }
1015  return ret;
1016  }
1022  for (int i=0; i<rank; i++) { ret(i) = 0; }
1023  return ret;
1024  }
1030  for (int i=0; i<rank; i++) { ret(i) = this->dimension[i]-1; }
1031  return ret;
1032  }
1036  YAKL_INLINE index_t extent( int dim ) const {
1037  #ifdef YAKL_DEBUG
1038  if (dim < 0 || dim > rank-1) yakl_throw("ERROR: calling extent() with an out of bounds index");
1039  #endif
1040  return this->dimension[dim];
1041  }
1042 
1043  };
1044 
1045 }
1047 
1048 
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2)
2-D owned constructor
Definition: YAKL_CArray.h:124
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6, index_t i7) const
Return reference to element at the requested indices (8-D)
Definition: YAKL_CArray.h:556
yakl::Array< T, rank, myMem, styleC >::get_dimensions
YAKL_INLINE SArray< index_t, 1, rank > get_dimensions() const
Returns the dimensions of this array as a yakl::SArray object.
Definition: YAKL_CArray.h:1012
YAKL_EXECUTE_ON_DEVICE_ONLY
#define YAKL_EXECUTE_ON_DEVICE_ONLY(...)
[NOT COMMONLY USED] Macro function used to determine if the current code is compiling for the device.
Definition: YAKL_defines.h:158
yakl::memDevice
constexpr int memDevice
Specifies a device memory address space for a yakl::Array object.
Definition: YAKL_memory_spaces.h:13
yakl::Array< T, rank, myMem, styleC >::const_value_type
std::add_const< type >::type const_value_type
This is the type T with const added to it.
Definition: YAKL_CArray.h:64
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0) const
Return reference to element at the requested index (1-D)
Definition: YAKL_CArray.h:471
array_ir::MEMORY_SHARED
constexpr int MEMORY_SHARED
Declares that the data pointer is defined in both host and device memory.
Definition: ArrayIR.h:18
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2, index_t const d3, index_t const d4, index_t const d5, index_t const d6)
6-D non-owned constructor
Definition: YAKL_CArray.h:266
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1, int i2, int i3) const
Array slice of 4-D array.
Definition: YAKL_CArray.h:757
yakl::Array< T, rank, myMem, styleC >
This implements the yakl:Array class with yakl::styleC behavior.
Definition: YAKL_CArray.h:55
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2, index_t d3, index_t d4, index_t d5)
5-D owned constructor
Definition: YAKL_CArray.h:145
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 3, myMem, styleC > reshape(index_t i0, index_t i1, index_t i2) const
Reshape array into a 3-D array.
Definition: YAKL_CArray.h:854
yakl::Stream
Implements the functionality of a stream for parallel kernel execution. If the Stream::create() metho...
Definition: YAKL_streams_events.h:394
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 1, myMem, styleC > reshape(index_t i0) const
Reshape array into a 1-D array.
Definition: YAKL_CArray.h:848
yakl::Array< T, rank, myMem, styleC >::operator=
YAKL_INLINE Array & operator=(Array< non_const_value_type, rank, myMem, styleC > const &rhs)
Copy metadata, share data pointer; if owned, increment reference counter. No deep copy.
Definition: YAKL_CArray.h:334
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1, index_t i2, index_t i3) const
Return reference to element at the requested indices (4-D)
Definition: YAKL_CArray.h:502
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array()
Create an empty, unallocated object.
Definition: YAKL_CArray.h:85
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5) const
Return reference to element at the requested indices (6-D)
Definition: YAKL_CArray.h:527
yakl::Array< T, rank, myMem, styleC >::non_const_value_type
std::remove_const< type >::type non_const_value_type
This is the type T with const removed from it.
Definition: YAKL_CArray.h:67
yakl::Array< T, rank, myMem, styleC >::~Array
YAKL_INLINE ~Array()
If owned, decrement reference counter, and deallocate data when it reaches zero. If non-owned,...
Definition: YAKL_CArray.h:422
yakl::Array< T, rank, myMem, styleC >::type
std::remove_cv< T >::type type
This is the type T without const and volatile modifiers.
Definition: YAKL_CArray.h:59
yakl::Array< T, rank, myMem, styleC >::createDeviceObject
Array< typename std::remove_cv< TLOC >::type, rank, memDevice, styleC > createDeviceObject() const
Create and allocate a yakl::memDevice array object of the same type, rank, dimensions,...
Definition: YAKL_CArray.h:990
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1, int i2, int i3, int i4, int i5, int i6, int i7) const
Array slice of 8-D array.
Definition: YAKL_CArray.h:786
yakl::Array< T, rank, myMem, styleC >::operator=
Array operator=(TLOC const &rhs) const
[ASYNCHRONOUS] Assign a scalar arithmetic value to all entries in this array object
Definition: YAKL_CArray.h:618
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2, index_t const d3, index_t const d4, index_t const d5, index_t const d6, index_t const d7, index_t const d8)
8-D non-owned constructor
Definition: YAKL_CArray.h:287
yakl::Array< T, rank, myMem, styleC >::get_ubounds
YAKL_INLINE SArray< index_t, 1, rank > get_ubounds() const
Returns the upper bound of each dimension of this array as a yakl::SArray object.
Definition: YAKL_CArray.h:1028
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, Dims const dims)
Generic initializer-list or std::vector based owned constructor.
Definition: YAKL_CArray.h:187
yakl::Array< T, rank, myMem, styleC >::createDeviceCopy
Array< TLOC, rank, memDevice, styleC > createDeviceCopy(Stream stream=Stream()) const
[DEEP_COPY] Create a copy of this array in yakl::memDevice space
Definition: YAKL_CArray.h:971
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1) const
Return reference to element at the requested indices (2-D)
Definition: YAKL_CArray.h:481
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
array_ir::MEMORY_HOST
constexpr int MEMORY_HOST
Declares that the data pointer is defined only in host memory.
Definition: ArrayIR.h:14
yakl::memcpy_host_to_device
void memcpy_host_to_device(T1 *dst, T2 *src, index_t elems, Stream stream=Stream())
[USE AT YOUR OWN RISK]: memcpy the specified number of elements from host to device
Definition: YAKL_mem_transfers.h:85
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2, index_t d3, index_t d4)
4-D owned constructor
Definition: YAKL_CArray.h:137
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2, index_t const d3, index_t const d4)
4-D non-owned constructor
Definition: YAKL_CArray.h:249
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6) const
Return reference to element at the requested indices (7-D)
Definition: YAKL_CArray.h:541
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1, int i2, int i3, int i4, int i5) const
Array slice of 6-D array.
Definition: YAKL_CArray.h:771
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2, index_t const d3, index_t const d4, index_t const d5, index_t const d6, index_t const d7)
7-D non-owned constructor
Definition: YAKL_CArray.h:276
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0) const
Array slice of 1-D array.
Definition: YAKL_CArray.h:736
array_ir::MEMORY_DEVICE
constexpr int MEMORY_DEVICE
Declares that the data pointer is defined only in device memory.
Definition: ArrayIR.h:16
yakl::Array< T, rank, myMem, styleC >::get_lbounds
YAKL_INLINE SArray< index_t, 1, rank > get_lbounds() const
Returns the lower bound of each dimension of this array (which are always all zero) as a yakl::SArray...
Definition: YAKL_CArray.h:1020
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1, index_t i2) const
Return reference to element at the requested indices (3-D)
Definition: YAKL_CArray.h:491
yakl::Array< T, rank, myMem, styleC >::operator=
YAKL_INLINE Array & operator=(Array< const_value_type, rank, myMem, styleC > const &rhs)
Copy metadata, share data pointer; if owned, increment reference counter. No deep copy.
Definition: YAKL_CArray.h:343
yakl::Array< T, rank, myMem, styleC >::operator=
YAKL_INLINE Array & operator=(Array &&rhs)
Move metadata and data pointer. No deep copy.
Definition: YAKL_CArray.h:398
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1)
1-D non-owned constructor
Definition: YAKL_CArray.h:231
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
yakl::Array< T, rank, myMem, styleC >::operator()
YAKL_INLINE T & operator()(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4) const
Return reference to element at the requested indices (5-D)
Definition: YAKL_CArray.h:514
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1)
1-D owned constructor
Definition: YAKL_CArray.h:119
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2, index_t const d3)
3-D non-owned constructor
Definition: YAKL_CArray.h:242
YAKL_INLINE
#define YAKL_INLINE
Used to decorate functions called from kernels (parallel_for and parallel_outer) or from CPU function...
Definition: YAKL_defines.h:140
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 5, myMem, styleC > reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4) const
Reshape array into a 5-D array.
Definition: YAKL_CArray.h:860
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2)
2-D non-owned constructor
Definition: YAKL_CArray.h:236
array_ir::ArrayIR
The ArrayIR class holds library-agnostic Array metadata to make it easy to transfer array objects bet...
Definition: ArrayIR.h:39
yakl::Dims::size
YAKL_INLINE int size() const
Get the number of dimensions.
Definition: YAKL_Array.h:166
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label)
Create an empty, unallocated object with a label.
Definition: YAKL_CArray.h:89
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2, index_t d3, index_t d4, index_t d5, index_t d6)
6-D owned constructor
Definition: YAKL_CArray.h:154
yakl::fence
void fence()
Block the host code until all device code has completed.
Definition: YAKL_fence.h:16
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 4, myMem, styleC > reshape(index_t i0, index_t i1, index_t i2, index_t i3) const
Reshape array into a 4-D array.
Definition: YAKL_CArray.h:857
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(Array &&rhs)
Move metadata and data pointer. No deep copy.
Definition: YAKL_CArray.h:380
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, N, myMem, styleC > reshape(Dims const &dims) const
Reshape array using initializer list or std::vector indices.
Definition: YAKL_CArray.h:820
yakl::Array< T, rank, myMem, styleC >::extent
YAKL_INLINE index_t extent(int dim) const
Returns the extent of the requested dimension of this array.
Definition: YAKL_CArray.h:1036
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1, int i2, int i3, int i4, int i5, int i6) const
Array slice of 7-D array.
Definition: YAKL_CArray.h:778
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, index_t const d1, index_t const d2, index_t const d3, index_t const d4, index_t const d5)
5-D non-owned constructor
Definition: YAKL_CArray.h:257
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1, int i2) const
Array slice of 3-D array.
Definition: YAKL_CArray.h:750
YAKL_EXECUTE_ON_HOST_ONLY
#define YAKL_EXECUTE_ON_HOST_ONLY(...)
[NOT COMMONLY USED] Macro function used to determine if the current code is compiling for the host.
Definition: YAKL_defines.h:153
yakl::index_t
unsigned int index_t
Definition: YAKL.h:41
yakl::Array< T, rank, myMem, styleC >::subset_slowest_dimension
YAKL_INLINE Array< T, rank, myMem, styleC > subset_slowest_dimension(int l, int u) const
Return an array aliasing a contiguous subset of the slowest dimension.
Definition: YAKL_CArray.h:647
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(Array< const_value_type, rank, myMem, styleC > const &rhs)
Copy metadata, share data pointer; if owned, increment reference counter. No deep copy.
Definition: YAKL_CArray.h:324
yakl::yakl_throw
YAKL_INLINE void yakl_throw(const char *msg)
Throw an error message. Works from the host or device.
Definition: YAKL_error.h:17
yakl::styleC
constexpr int styleC
Template parameter for yakl::Array that specifies it should follow C-style behavior.
Definition: YAKL_Array.h:20
yakl::memcpy_host_to_host
void memcpy_host_to_host(T1 *dst, T2 *src, index_t elems)
[USE AT YOUR OWN RISK]: memcpy the specified number of elements on the host
Definition: YAKL_mem_transfers.h:20
array_ir::ArrayIR::label
const char * label() const
Get the label for this array.
Definition: ArrayIR.h:117
yakl::Array< T, rank, myMem, styleC >::value_type
T value_type
This is the type T exactly as it was defined upon array object creation.
Definition: YAKL_CArray.h:61
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 2, myMem, styleC > reshape(index_t i0, index_t i1) const
Reshape array into a 2-D array.
Definition: YAKL_CArray.h:851
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(Dims const &dims) const
Array slice using initializer list or std::vector indices.
Definition: YAKL_CArray.h:695
yakl::Dims
This class holds C-style dimensions for using in yakl::Array objects.
Definition: YAKL_Array.h:50
yakl::Array< T, rank, myMem, styleC >::createHostObject
Array< typename std::remove_cv< TLOC >::type, rank, memHost, styleC > createHostObject() const
Create and allocate a yakl::memHost array object of the same type, rank, dimensions,...
Definition: YAKL_CArray.h:939
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 6, myMem, styleC > reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5) const
Reshape array into a 6-D array.
Definition: YAKL_CArray.h:863
array_ir::ArrayIR::data_valid_on_device
bool data_valid_on_device() const
Determine if the data pointer is valid on the device.
Definition: ArrayIR.h:127
yakl::Array< T, rank, myMem, styleC >::createHostCopy
Array< TLOC, rank, memHost, styleC > createHostCopy(Stream stream=Stream()) const
[DEEP_COPY] Create a copy of this array in yakl::memHost space
Definition: YAKL_CArray.h:920
yakl::Array
This declares the yakl::Array class. Please see the yakl::styleC and yakl::styleFortran template spec...
Definition: YAKL_Array.h:40
yakl::memcpy_device_to_device
void memcpy_device_to_device(T1 *dst, T2 *src, index_t elems, Stream stream=Stream())
[USE AT YOUR OWN RISK]: memcpy the specified number of elements on the device
Definition: YAKL_mem_transfers.h:119
yakl::CSArray
C-style array on the stack similar in nature to, e.g., float arr[ny][nx];
Definition: YAKL_CSArray.h:30
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 7, myMem, styleC > reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6) const
Reshape array into a 7-D array.
Definition: YAKL_CArray.h:866
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(Array< non_const_value_type, rank, myMem, styleC > const &rhs)
Copy metadata, share data pointer; if owned, increment reference counter. No deep copy.
Definition: YAKL_CArray.h:318
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, T *data, Dims const dims)
Generic initializer-list or std::vector based owned constructor.
Definition: YAKL_CArray.h:299
yakl::Array< T, rank, myMem, styleC >::subset_slowest_dimension
YAKL_INLINE Array< T, rank, myMem, styleC > subset_slowest_dimension(int u) const
Return an array aliasing a contiguous subset of the slowest dimension. Retuns the same array with the...
Definition: YAKL_CArray.h:643
yakl::Array< T, rank, myMem, styleC >::reshape
YAKL_INLINE Array< T, 8, myMem, styleC > reshape(index_t i0, index_t i1, index_t i2, index_t i3, index_t i4, index_t i5, index_t i6, index_t i7) const
Reshape array into a 8-D array.
Definition: YAKL_CArray.h:869
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1) const
Array slice of 2-D array.
Definition: YAKL_CArray.h:743
array_ir::ArrayIR::extent
size_t extent(int i) const
Get the extent of the dimension of the provided index.
Definition: ArrayIR.h:108
yakl
array_ir::ArrayIR::data
T * data() const
Get the data pointer.
Definition: ArrayIR.h:102
yakl::Array< T, rank, myMem, styleC >::create_ArrayIR
array_ir::ArrayIR< TLOC, rank > create_ArrayIR() const
Create an ArrayIR object from this CArray object for easy interoperability with other C++ portability...
Definition: YAKL_CArray.h:442
yakl::memcpy_device_to_host
void memcpy_device_to_host(T1 *dst, T2 *src, index_t elems, Stream stream=Stream())
[USE AT YOUR OWN RISK]: memcpy the specified number of elements from device to host
Definition: YAKL_mem_transfers.h:51
yakl::Array< T, rank, myMem, styleC >::Array
Array(array_ir::ArrayIR< T, rank > const &ir)
Construct this CArray object from an ArrayIR object for easy interoperability with other C++ portabil...
Definition: YAKL_CArray.h:428
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2, index_t d3)
3-D owned constructor
Definition: YAKL_CArray.h:130
yakl::Array< T, rank, myMem, styleC >::collapse
YAKL_INLINE Array< T, 1, myMem, styleC > collapse() const
Collapse this array into a 1-D array.
Definition: YAKL_CArray.h:884
array_ir::ArrayIR::data_valid_on_host
bool data_valid_on_host() const
Determine if the data pointer is valid on the host.
Definition: ArrayIR.h:125
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2, index_t d3, index_t d4, index_t d5, index_t d6, index_t d7)
7-D owned constructor
Definition: YAKL_CArray.h:164
yakl::Array< T, rank, myMem, styleC >::slice
YAKL_INLINE Array< T, N, myMem, styleC > slice(int i0, int i1, int i2, int i3, int i4) const
Array slice of 5-D array.
Definition: YAKL_CArray.h:764
yakl::ArrayBase
This class implements functionality common to both yakl::styleC and yakl::styleFortran Array objects.
Definition: YAKL_ArrayBase.h:24
yakl::Array< T, rank, myMem, styleC >::Array
YAKL_INLINE Array(char const *label, index_t d1, index_t d2, index_t d3, index_t d4, index_t d5, index_t d6, index_t d7, index_t d8)
8-D owned constructor
Definition: YAKL_CArray.h:175
yakl::memHost
constexpr int memHost
Specifies a device memory address space for a yakl::Array object.
Definition: YAKL_memory_spaces.h:15