Go to the documentation of this file.
23 template <
class T,
int rank,
int myMem,
int myStyle>
28 typedef typename std::remove_cv<T>::type
type;
46 #ifdef YAKL_ENABLE_STREAMS
51 struct StreamListDummy {
52 static bool constexpr empty() {
return true; }
53 void push_back(
Stream stream ) { }
54 int size() {
return 0; }
86 void create_inform() {
88 std::string msg =
"Allocating ";
89 if constexpr (myMem ==
memHost) {
90 msg += std::string(
"host, ");
92 msg += std::string(
"device, ");
94 if constexpr (myStyle ==
styleC) {
95 msg += std::string(
"C-style, ");
97 msg += std::string(
"Fortran-style, ");
99 msg += std::string(
"rank ") + std::to_string(rank) + std::string(
" Array");
100 msg += std::string(
" of size ") + std::to_string(
totElems()*
sizeof(T)) + std::string(
" bytes");
101 verbose_inform(msg,this->
label());
107 void destroy_inform() {
109 std::string msg =
"Deallocating ";
110 if constexpr (myMem ==
memHost) {
111 msg += std::string(
"host, ");
113 msg += std::string(
"device, ");
115 if constexpr (myStyle ==
styleC) {
116 msg += std::string(
"C-style, ");
118 msg += std::string(
"Fortran-style, ");
120 msg += std::string(
"rank ") + std::to_string(rank) + std::string(
" Array");
121 verbose_inform(msg,this->
label());
128 void copy_inform(ARR
const &dest)
const {
130 std::string msg =
"Initiating ";
131 if (myMem ==
memHost ) msg += std::string(
"host to ");
132 if (myMem ==
memDevice) msg += std::string(
"device to ");
133 if (dest.get_memory_space() ==
memHost ) msg += std::string(
"host memcpy of ");
134 if (dest.get_memory_space() ==
memDevice) msg += std::string(
"device memcpy of ");
135 msg += std::to_string(
totElems()*
sizeof(T)) + std::string(
" bytes");
136 if (
label() !=
"") msg +=
" from Array labeled \"" + std::string(
label()) + std::string(
"\"");
137 if (dest.label() !=
"") msg +=
" to Array labeled \"" + std::string(dest.label()) + std::string(
"\"");
149 template <
int theirRank,
int theirStyle>
155 if (this->
totElems() != lhs.totElems()) {
yakl_throw(
"ERROR: deep_copy_to with different number of elements"); }
156 if (this->myData ==
nullptr || lhs.myData ==
nullptr) {
yakl_throw(
"ERROR: deep_copy_to with nullptr"); }
160 #ifdef YAKL_AUTO_FENCE
172 template <
int theirRank,
int theirStyle>
178 if (this->
totElems() != lhs.totElems()) {
yakl_throw(
"ERROR: deep_copy_to with different number of elements"); }
179 if (this->myData ==
nullptr || lhs.myData ==
nullptr) {
yakl_throw(
"ERROR: deep_copy_to with nullptr"); }
183 #ifdef YAKL_AUTO_FENCE
194 index_t tot = this->dimension[0];
195 for (
int i=1; i<rank; i++) { tot *= this->dimension[i]; }
222 return "\"Unlabeled: YAKL_DEBUG CPP macro not defined\"";
232 if (this->refCount !=
nullptr) {
return *(this->refCount); }
239 template <class TLOC=T, typename std::enable_if< ! std::is_const<TLOC>::value ,
int >
::type = 0>
240 inline void allocate() {
244 this->refCount =
new int;
245 (*(this->refCount)) = 1;
249 this->myData =
new T[this->
totElems()];
252 this->create_inform();
267 template <class TLOC=T, typename std::enable_if< std::is_const<TLOC>::value ,
int >
::type = 0>
270 typedef typename std::remove_cv<T>::type T_non_const;
271 T_non_const *
data =
const_cast<T_non_const *
>(this->myData);
272 if (this->refCount !=
nullptr) {
273 (*(this->refCount))--;
275 if (*this->refCount == 0) {
279 delete this->refCount;
280 this->refCount =
nullptr;
284 std::vector<Event> event_dependencies;
288 get_yakl_instance().pool.free_with_event_dependencies(
data , event_dependencies , this->
label() );
295 this->myData =
nullptr;
306 template <class TLOC=T, typename std::enable_if< ! std::is_const<TLOC>::value ,
int >
::type = 0>
309 if (this->refCount !=
nullptr) {
310 (*(this->refCount))--;
312 if (*this->refCount == 0) {
316 delete this->refCount;
317 this->refCount =
nullptr;
321 std::vector<Event> event_dependencies;
325 get_yakl_instance().pool.free_with_event_dependencies( this->myData , event_dependencies , this->
label() );
330 delete[] this->myData;
332 this->myData =
nullptr;
344 os <<
"For Array labeled: " << v.label() <<
"\n";
345 os <<
"Number of Dimensions: " << rank <<
"\n";
346 os <<
"Total Number of Elements: " << v.totElems() <<
"\n";
347 os <<
"Dimension Sizes: ";
348 for (
int i=0; i<rank; i++) {
349 os << v.dimension[i] <<
", ";
356 #ifdef YAKL_ENABLE_STREAMS
363 for (
index_t i=0; i<v.totElems(); i++) {
364 os << local[i] <<
" ";
YAKL_INLINE int get_memory_space() const
Returns this array object's string label if the YAKL_DEBUG CPP macro is defined. Otherwise,...
Definition: YAKL_ArrayBase.h:217
constexpr int memDevice
Specifies a device memory address space for a yakl::Array object.
Definition: YAKL_memory_spaces.h:13
T value_type
This is the type T exactly as it was defined upon array object creation.
Definition: YAKL_ArrayBase.h:30
YAKL_INLINE T * data() const
Returns the raw data pointer of this array object.
Definition: YAKL_ArrayBase.h:205
YAKL_INLINE bool initialized() const
Returns whether this array object has is in an initialized / allocated state.
Definition: YAKL_ArrayBase.h:215
YAKL_INLINE int get_rank() const
Returns the number of dimensions in this array object.
Definition: YAKL_ArrayBase.h:191
friend std::ostream & operator<<(std::ostream &os, Array< T, rank, myMem, myStyle > const &v)
Allows the user to std::cout << this_array_object;. This works even for yakl::memDevice array objects...
Definition: YAKL_ArrayBase.h:343
Implements the functionality of a stream for parallel kernel execution. If the Stream::create() metho...
Definition: YAKL_streams_events.h:394
void deep_copy_to(Array< typename std::remove_cv< T >::type, theirRank, memHost, theirStyle > const &lhs, Stream stream=Stream()) const
[ASYNCHRONOUS] [DEEP_COPY] Copy this array's contents to a yakl::memHost array.
Definition: YAKL_ArrayBase.h:150
const char * label() const
Definition: YAKL_ArrayBase.h:218
std::remove_const< type >::type non_const_value_type
This is the type T with const removed from it (if the original type has volatile, then so will this t...
Definition: YAKL_ArrayBase.h:34
YAKL_INLINE index_t totElems() const
Returns the total number of elements in this array object.
Definition: YAKL_ArrayBase.h:201
YAKL_INLINE bool span_is_contiguous() const
Always true. yakl::Array objects are always contiguous in memory with no padding.
Definition: YAKL_ArrayBase.h:213
std::add_const< type >::type const_value_type
This is the type T with const added to it (if the original type has volatile, then so will this type.
Definition: YAKL_ArrayBase.h:32
bool use_pool()
If true, then the pool allocator is being used for all device allocations.
Definition: YAKL_allocators.h:16
YAKL_INLINE T * begin() const
Returns pointer to beginning of the data.
Definition: YAKL_ArrayBase.h:209
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
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
void free_device(void *ptr, char const *label)
Free on the device using YAKL's device deallocator.
Definition: YAKL_allocators.h:237
constexpr bool streams_enabled
If the CPP Macro YAKL_ENABLE_STREAMS is defined, then this bool is set to true
Definition: YAKL_streams_events.h:11
void add_stream_dependency(Stream stream)
Declare a dependency on the passed stream.
Definition: YAKL_ArrayBase.h:67
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
#define YAKL_INLINE
Used to decorate functions called from kernels (parallel_for and parallel_outer) or from CPU function...
Definition: YAKL_defines.h:140
void add_stream_dependencies(std::vector< Stream > streams)
Declare a dependencies on the multiple streams at one time.
Definition: YAKL_ArrayBase.h:76
int use_count() const
Returns how many array objects share this pointer if owned; or 0 if unowned.
Definition: YAKL_ArrayBase.h:231
void fence()
Block the host code until all device code has completed.
Definition: YAKL_fence.h:16
Implements a list of Stream objects. Needs to store a pointer to avoid construction on the device sin...
Definition: YAKL_streams_events.h:446
YAKL_INLINE T * get_data() const
Returns the raw data pointer of this array object.
Definition: YAKL_ArrayBase.h:207
YAKL_INLINE index_t get_elem_count() const
Returns the total number of elements in this array object.
Definition: YAKL_ArrayBase.h:199
unsigned int index_t
Definition: YAKL.h:41
YAKL_INLINE void yakl_throw(const char *msg)
Throw an error message. Works from the host or device.
Definition: YAKL_error.h:17
constexpr int styleC
Template parameter for yakl::Array that specifies it should follow C-style behavior.
Definition: YAKL_Array.h:20
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
YAKL_INLINE index_t get_totElems() const
Returns the total number of elements in this array object.
Definition: YAKL_ArrayBase.h:193
Event record_event(Stream stream=Stream())
Create, record, and return an event using the given stream.
Definition: YAKL_streams_events.h:438
std::remove_cv< T >::type type
This is the type T without const and volatile modifiers.
Definition: YAKL_ArrayBase.h:28
This declares the yakl::Array class. Please see the yakl::styleC and yakl::styleFortran template spec...
Definition: YAKL_Array.h:40
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
void * alloc_device(size_t bytes, char const *label)
Allocate on the device using YAKL's device allocator.
Definition: YAKL_allocators.h:234
void deallocate()
If owned, decrement the reference counter; if ref counter reaches zero, deallocate memory; If non-own...
Definition: YAKL_ArrayBase.h:268
YAKL_INLINE index_t size() const
Returns the total number of elements in this array object.
Definition: YAKL_ArrayBase.h:203
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_INLINE T * end() const
Returns pointer to end of the data.
Definition: YAKL_ArrayBase.h:211
StreamListDummy stream_dependencies
Definition: YAKL_ArrayBase.h:57
This class implements functionality common to both yakl::styleC and yakl::styleFortran Array objects.
Definition: YAKL_ArrayBase.h:24
constexpr int memHost
Specifies a device memory address space for a yakl::Array object.
Definition: YAKL_memory_spaces.h:15
void deep_copy_to(Array< typename std::remove_cv< T >::type, theirRank, memDevice, theirStyle > const &lhs, Stream stream=Stream()) const
[ASYNCHRONOUS] [DEEP_COPY] Copy this array's contents to a yakl::memDevice array.
Definition: YAKL_ArrayBase.h:173