YAKL
YAKL_ScalarLiveOut.h
Go to the documentation of this file.
1 
2 #pragma once
3 // Included by YAKL.h
4 
6 namespace yakl {
7 
39  template <class T> class ScalarLiveOut {
40  protected:
43 
44  public:
47  data = Array<T,1,memDevice,styleC>("ScalarLiveOut_data",1); // Create array
48  }
50  explicit ScalarLiveOut(T val, Stream stream = Stream() ) {
51  data = Array<T,1,memDevice,styleC>("ScalarLiveOut_data",1); // Create array
52  hostWrite(val,stream); // Copy to device
53  }
57  }
58 
60  YAKL_INLINE ScalarLiveOut ( ScalarLiveOut const &rhs) { this->data = rhs.data; }
62  YAKL_INLINE ScalarLiveOut & operator=( ScalarLiveOut const &rhs) { this->data = rhs.data; return *this; }
64  YAKL_INLINE ScalarLiveOut ( ScalarLiveOut &&rhs) { this->data = rhs.data; }
66  YAKL_INLINE ScalarLiveOut & operator=( ScalarLiveOut &&rhs) { this->data = rhs.data; return *this; }
67 
69  template <class TLOC , typename std::enable_if< std::is_arithmetic<TLOC>::value , int >::type = 0>
70  YAKL_INLINE T &operator= (TLOC rhs) const { data(0) = rhs; return data(0); }
71 
73  YAKL_INLINE T &operator() () const {
74  return data(0);
75  }
76 
78  YAKL_INLINE T get() const {
79  return data(0);
80  }
81 
83  inline T hostRead(Stream stream = Stream()) const {
84  return data.createHostCopy(stream)(0);
85  }
86 
88  inline void hostWrite(T val, Stream stream = Stream()) {
89  // Copy data to device
90  auto &myData = this->data;
91  c::parallel_for( c::Bounds<1>(1) , YAKL_LAMBDA (int dummy) {
92  myData(0) = val;
93  } , DefaultLaunchConfig().set_stream(stream) );
94  }
95 
96  };
97 }
99 
100 
yakl::ScalarLiveOut::ScalarLiveOut
YAKL_INLINE ScalarLiveOut()
Default constructor allocates room on the device for one scalar of type T
Definition: YAKL_ScalarLiveOut.h:46
yakl::ScalarLiveOut::get
YAKL_INLINE T get() const
Returns a modifiable reference to the underlying data on the device.
Definition: YAKL_ScalarLiveOut.h:78
yakl::Stream
Implements the functionality of a stream for parallel kernel execution. If the Stream::create() metho...
Definition: YAKL_streams_events.h:394
yakl::c::Bounds
Describes a set of C-style tightly-nested loops.
Definition: YAKL_Bounds_c.h:84
yakl::ScalarLiveOut::operator()
YAKL_INLINE T & operator()() const
Returns a modifiable reference to the underlying data on the device.
Definition: YAKL_ScalarLiveOut.h:73
yakl::c::parallel_for
void parallel_for(char const *str, Bounds< N, simple > const &bounds, F const &f, LaunchConfig< VecLen, B4B > config=LaunchConfig<>())
[ASYNCHRONOUS] Launch the passed functor in parallel.
yakl::ScalarLiveOut::hostRead
T hostRead(Stream stream=Stream()) const
Returns a host copy of the data. This is blocking.
Definition: YAKL_ScalarLiveOut.h:83
__YAKL_NAMESPACE_WRAPPER_END__
#define __YAKL_NAMESPACE_WRAPPER_END__
Definition: YAKL.h:20
yakl::ScalarLiveOut::hostWrite
void hostWrite(T val, Stream stream=Stream())
[ASYNCHRONOUS] Writes a value to the device-resident underlying data
Definition: YAKL_ScalarLiveOut.h:88
yakl::ScalarLiveOut::ScalarLiveOut
YAKL_INLINE ScalarLiveOut(ScalarLiveOut &&rhs)
Copies and moves are shallow, not deep copy.
Definition: YAKL_ScalarLiveOut.h:64
__YAKL_NAMESPACE_WRAPPER_BEGIN__
#define __YAKL_NAMESPACE_WRAPPER_BEGIN__
Definition: YAKL.h:19
yakl::DefaultLaunchConfig
LaunchConfig<> DefaultLaunchConfig
This launch configuration sets vector length to the device default and B4B to false.
Definition: YAKL_LaunchConfig.h:77
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::ScalarLiveOut
Class to handle scalars that exist before kernels, are written to by kernels, and read after the kern...
Definition: YAKL_ScalarLiveOut.h:39
yakl::ScalarLiveOut::operator=
YAKL_INLINE ScalarLiveOut & operator=(ScalarLiveOut const &rhs)
Copies and moves are shallow, not deep copy.
Definition: YAKL_ScalarLiveOut.h:62
yakl::ScalarLiveOut::~ScalarLiveOut
YAKL_INLINE ~ScalarLiveOut()
Deallocates the scalar value on the device.
Definition: YAKL_ScalarLiveOut.h:55
yakl::Array< T, 1, memDevice, styleC >
yakl::ScalarLiveOut::ScalarLiveOut
ScalarLiveOut(T val, Stream stream=Stream())
[ASYNCHRONOUS] This constructor allocates room on the device for one scalar of type T and initializes...
Definition: YAKL_ScalarLiveOut.h:50
yakl
yakl::ScalarLiveOut::operator=
YAKL_INLINE ScalarLiveOut & operator=(ScalarLiveOut &&rhs)
Copies and moves are shallow, not deep copy.
Definition: YAKL_ScalarLiveOut.h:66
yakl::ScalarLiveOut::ScalarLiveOut
YAKL_INLINE ScalarLiveOut(ScalarLiveOut const &rhs)
Copies and moves are shallow, not deep copy.
Definition: YAKL_ScalarLiveOut.h:60
YAKL_LAMBDA
#define YAKL_LAMBDA
Used to create C++ lambda expressions passed to parallel_for and parallel_outer
Definition: YAKL_defines.h:128