Update Kokkos library in LAMMPS to v2.7.24
This commit is contained in:
@ -96,6 +96,7 @@ template< class DataType ,
|
||||
class Arg3Type = void>
|
||||
class DualView : public ViewTraits< DataType , Arg1Type , Arg2Type, Arg3Type >
|
||||
{
|
||||
template< class , class , class , class > friend class DualView ;
|
||||
public:
|
||||
//! \name Typedefs for device types and various Kokkos::View specializations.
|
||||
//@{
|
||||
@ -182,8 +183,20 @@ public:
|
||||
//! \name Counters to keep track of changes ("modified" flags)
|
||||
//@{
|
||||
|
||||
View<unsigned int,LayoutLeft,typename t_host::execution_space> modified_device;
|
||||
View<unsigned int,LayoutLeft,typename t_host::execution_space> modified_host;
|
||||
#ifndef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
protected:
|
||||
// modified_flags[0] -> host
|
||||
// modified_flags[1] -> device
|
||||
typedef View<unsigned int[2],LayoutLeft,Kokkos::HostSpace> t_modified_flags;
|
||||
t_modified_flags modified_flags;
|
||||
|
||||
public:
|
||||
#else
|
||||
typedef View<unsigned int[2],LayoutLeft,typename t_host::execution_space> t_modified_flags;
|
||||
typedef View<unsigned int,LayoutLeft,typename t_host::execution_space> t_modified_flag;
|
||||
t_modified_flags modified_flags;
|
||||
t_modified_flag modified_host,modified_device;
|
||||
#endif
|
||||
|
||||
//@}
|
||||
//! \name Constructors
|
||||
@ -194,10 +207,14 @@ public:
|
||||
/// Both device and host View objects are constructed using their
|
||||
/// default constructors. The "modified" flags are both initialized
|
||||
/// to "unmodified."
|
||||
DualView () :
|
||||
modified_device (View<unsigned int,LayoutLeft,typename t_host::execution_space> ("DualView::modified_device")),
|
||||
modified_host (View<unsigned int,LayoutLeft,typename t_host::execution_space> ("DualView::modified_host"))
|
||||
{}
|
||||
#ifndef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
DualView () = default;
|
||||
#else
|
||||
DualView ():modified_flags (t_modified_flags("DualView::modified_flags")) {
|
||||
modified_host = t_modified_flag(modified_flags,0);
|
||||
modified_device = t_modified_flag(modified_flags,1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// \brief Constructor that allocates View objects on both host and device.
|
||||
///
|
||||
@ -219,17 +236,24 @@ public:
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG)
|
||||
: d_view (label, n0, n1, n2, n3, n4, n5, n6, n7)
|
||||
, h_view (create_mirror_view (d_view)) // without UVM, host View mirrors
|
||||
, modified_device (View<unsigned int,LayoutLeft,typename t_host::execution_space> ("DualView::modified_device"))
|
||||
, modified_host (View<unsigned int,LayoutLeft,typename t_host::execution_space> ("DualView::modified_host"))
|
||||
{}
|
||||
, modified_flags (t_modified_flags("DualView::modified_flags"))
|
||||
{
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
modified_host = t_modified_flag(modified_flags,0);
|
||||
modified_device = t_modified_flag(modified_flags,1);
|
||||
#endif
|
||||
}
|
||||
|
||||
//! Copy constructor (shallow copy)
|
||||
template<class SS, class LS, class DS, class MS>
|
||||
DualView (const DualView<SS,LS,DS,MS>& src) :
|
||||
d_view (src.d_view),
|
||||
h_view (src.h_view),
|
||||
modified_device (src.modified_device),
|
||||
modified_host (src.modified_host)
|
||||
modified_flags (src.modified_flags)
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
, modified_host(src.modified_host)
|
||||
, modified_device(src.modified_device)
|
||||
#endif
|
||||
{}
|
||||
|
||||
//! Subview constructor
|
||||
@ -241,8 +265,11 @@ public:
|
||||
)
|
||||
: d_view( Kokkos::subview( src.d_view , arg0 , args ... ) )
|
||||
, h_view( Kokkos::subview( src.h_view , arg0 , args ... ) )
|
||||
, modified_device (src.modified_device)
|
||||
, modified_host (src.modified_host)
|
||||
, modified_flags (src.modified_flags)
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
, modified_host(src.modified_host)
|
||||
, modified_device(src.modified_device)
|
||||
#endif
|
||||
{}
|
||||
|
||||
/// \brief Create DualView from existing device and host View objects.
|
||||
@ -258,8 +285,7 @@ public:
|
||||
DualView (const t_dev& d_view_, const t_host& h_view_) :
|
||||
d_view (d_view_),
|
||||
h_view (h_view_),
|
||||
modified_device (View<unsigned int,LayoutLeft,typename t_host::execution_space> ("DualView::modified_device")),
|
||||
modified_host (View<unsigned int,LayoutLeft,typename t_host::execution_space> ("DualView::modified_host"))
|
||||
modified_flags (t_modified_flags("DualView::modified_flags"))
|
||||
{
|
||||
if ( int(d_view.rank) != int(h_view.rank) ||
|
||||
d_view.extent(0) != h_view.extent(0) ||
|
||||
@ -281,6 +307,10 @@ public:
|
||||
d_view.span() != h_view.span() ) {
|
||||
Kokkos::Impl::throw_runtime_exception("DualView constructed with incompatible views");
|
||||
}
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
modified_host = t_modified_flag(modified_flags,0);
|
||||
modified_device = t_modified_flag(modified_flags,1);
|
||||
#endif
|
||||
}
|
||||
|
||||
//@}
|
||||
@ -316,6 +346,30 @@ public:
|
||||
t_dev,
|
||||
t_host>::type& view () const
|
||||
{
|
||||
#ifndef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
constexpr bool device_is_memspace = std::is_same<Device,typename Device::memory_space>::value;
|
||||
constexpr bool device_is_execspace = std::is_same<Device,typename Device::execution_space>::value;
|
||||
constexpr bool device_exec_is_t_dev_exec = std::is_same<typename Device::execution_space,typename t_dev::execution_space>::value;
|
||||
constexpr bool device_mem_is_t_dev_mem = std::is_same<typename Device::memory_space,typename t_dev::memory_space>::value;
|
||||
constexpr bool device_exec_is_t_host_exec = std::is_same<typename Device::execution_space,typename t_host::execution_space>::value;
|
||||
constexpr bool device_mem_is_t_host_mem = std::is_same<typename Device::memory_space,typename t_host::memory_space>::value;
|
||||
constexpr bool device_is_t_host_device = std::is_same<typename Device::execution_space,typename t_host::device_type>::value;
|
||||
constexpr bool device_is_t_dev_device = std::is_same<typename Device::memory_space,typename t_host::device_type>::value;
|
||||
|
||||
static_assert(
|
||||
device_is_t_dev_device || device_is_t_host_device ||
|
||||
(device_is_memspace && (device_mem_is_t_dev_mem || device_mem_is_t_host_mem) ) ||
|
||||
(device_is_execspace && (device_exec_is_t_dev_exec || device_exec_is_t_host_exec) ) ||
|
||||
(
|
||||
(!device_is_execspace && !device_is_memspace) && (
|
||||
(device_mem_is_t_dev_mem || device_mem_is_t_host_mem) ||
|
||||
(device_exec_is_t_dev_exec || device_exec_is_t_host_exec)
|
||||
)
|
||||
)
|
||||
,
|
||||
"Template parameter to .view() must exactly match one of the DualView's device types or one of the execution or memory spaces");
|
||||
#endif
|
||||
|
||||
return Impl::if_c<
|
||||
std::is_same<
|
||||
typename t_dev::memory_space,
|
||||
@ -324,6 +378,72 @@ public:
|
||||
t_host >::select (d_view , h_view);
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
t_host view_host() const {
|
||||
return h_view;
|
||||
}
|
||||
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
t_dev view_device() const {
|
||||
return d_view;
|
||||
}
|
||||
|
||||
template<class Device>
|
||||
static int get_device_side() {
|
||||
constexpr bool device_is_memspace = std::is_same<Device,typename Device::memory_space>::value;
|
||||
constexpr bool device_is_execspace = std::is_same<Device,typename Device::execution_space>::value;
|
||||
constexpr bool device_exec_is_t_dev_exec = std::is_same<typename Device::execution_space,typename t_dev::execution_space>::value;
|
||||
constexpr bool device_mem_is_t_dev_mem = std::is_same<typename Device::memory_space,typename t_dev::memory_space>::value;
|
||||
constexpr bool device_exec_is_t_host_exec = std::is_same<typename Device::execution_space,typename t_host::execution_space>::value;
|
||||
constexpr bool device_mem_is_t_host_mem = std::is_same<typename Device::memory_space,typename t_host::memory_space>::value;
|
||||
constexpr bool device_is_t_host_device = std::is_same<typename Device::execution_space,typename t_host::device_type>::value;
|
||||
constexpr bool device_is_t_dev_device = std::is_same<typename Device::memory_space,typename t_host::device_type>::value;
|
||||
|
||||
#ifndef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
static_assert(
|
||||
device_is_t_dev_device || device_is_t_host_device ||
|
||||
(device_is_memspace && (device_mem_is_t_dev_mem || device_mem_is_t_host_mem) ) ||
|
||||
(device_is_execspace && (device_exec_is_t_dev_exec || device_exec_is_t_host_exec) ) ||
|
||||
(
|
||||
(!device_is_execspace && !device_is_memspace) && (
|
||||
(device_mem_is_t_dev_mem || device_mem_is_t_host_mem) ||
|
||||
(device_exec_is_t_dev_exec || device_exec_is_t_host_exec)
|
||||
)
|
||||
)
|
||||
,
|
||||
"Template parameter to .sync() must exactly match one of the DualView's device types or one of the execution or memory spaces");
|
||||
#endif
|
||||
|
||||
#ifndef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
int dev = -1;
|
||||
#else
|
||||
int dev = 0;
|
||||
#endif
|
||||
if(device_is_t_dev_device) dev = 1;
|
||||
else if(device_is_t_host_device) dev = 0;
|
||||
else {
|
||||
if(device_is_memspace) {
|
||||
if(device_mem_is_t_dev_mem) dev = 1;
|
||||
if(device_mem_is_t_host_mem) dev = 0;
|
||||
if(device_mem_is_t_host_mem && device_mem_is_t_dev_mem) dev = -1;
|
||||
}
|
||||
if(device_is_execspace) {
|
||||
if(device_exec_is_t_dev_exec) dev = 1;
|
||||
if(device_exec_is_t_host_exec) dev = 0;
|
||||
if(device_exec_is_t_host_exec && device_exec_is_t_dev_exec) dev = -1;
|
||||
}
|
||||
if(!device_is_execspace && !device_is_memspace) {
|
||||
if(device_mem_is_t_dev_mem) dev = 1;
|
||||
if(device_mem_is_t_host_mem) dev = 0;
|
||||
if(device_mem_is_t_host_mem && device_mem_is_t_dev_mem) dev = -1;
|
||||
if(device_exec_is_t_dev_exec) dev = 1;
|
||||
if(device_exec_is_t_host_exec) dev = 0;
|
||||
if(device_exec_is_t_host_exec && device_exec_is_t_dev_exec) dev = -1;
|
||||
}
|
||||
}
|
||||
return dev;
|
||||
}
|
||||
|
||||
/// \brief Update data on device or host only if data in the other
|
||||
/// space has been marked as modified.
|
||||
///
|
||||
@ -347,23 +467,20 @@ public:
|
||||
( std::is_same< Device , int>::value)
|
||||
, int >::type& = 0)
|
||||
{
|
||||
const unsigned int dev =
|
||||
Impl::if_c<
|
||||
std::is_same<
|
||||
typename t_dev::memory_space,
|
||||
typename Device::memory_space>::value ,
|
||||
unsigned int,
|
||||
unsigned int>::select (1, 0);
|
||||
if(modified_flags.data()==NULL) return;
|
||||
|
||||
if (dev) { // if Device is the same as DualView's device type
|
||||
if ((modified_host () > 0) && (modified_host () >= modified_device ())) {
|
||||
int dev = get_device_side<Device>();
|
||||
|
||||
if (dev == 1) { // if Device is the same as DualView's device type
|
||||
if ((modified_flags(0) > 0) && (modified_flags(0) >= modified_flags(1))) {
|
||||
deep_copy (d_view, h_view);
|
||||
modified_host() = modified_device() = 0;
|
||||
modified_flags(0) = modified_flags(1) = 0;
|
||||
}
|
||||
} else { // hopefully Device is the same as DualView's host type
|
||||
if ((modified_device () > 0) && (modified_device () >= modified_host ())) {
|
||||
}
|
||||
if (dev == 0) { // hopefully Device is the same as DualView's host type
|
||||
if ((modified_flags(1) > 0) && (modified_flags(1) >= modified_flags(0))) {
|
||||
deep_copy (h_view, d_view);
|
||||
modified_host() = modified_device() = 0;
|
||||
modified_flags(0) = modified_flags(1) = 0;
|
||||
}
|
||||
}
|
||||
if(std::is_same<typename t_host::memory_space,typename t_dev::memory_space>::value) {
|
||||
@ -378,46 +495,71 @@ public:
|
||||
( std::is_same< Device , int>::value)
|
||||
, int >::type& = 0 )
|
||||
{
|
||||
const unsigned int dev =
|
||||
Impl::if_c<
|
||||
std::is_same<
|
||||
typename t_dev::memory_space,
|
||||
typename Device::memory_space>::value,
|
||||
unsigned int,
|
||||
unsigned int>::select (1, 0);
|
||||
if (dev) { // if Device is the same as DualView's device type
|
||||
if ((modified_host () > 0) && (modified_host () >= modified_device ())) {
|
||||
if(modified_flags.data()==NULL) return;
|
||||
|
||||
int dev = get_device_side<Device>();
|
||||
|
||||
if (dev == 1) { // if Device is the same as DualView's device type
|
||||
if ((modified_flags(0) > 0) && (modified_flags(0) >= modified_flags(1))) {
|
||||
Impl::throw_runtime_exception("Calling sync on a DualView with a const datatype.");
|
||||
}
|
||||
} else { // hopefully Device is the same as DualView's host type
|
||||
if ((modified_device () > 0) && (modified_device () >= modified_host ())) {
|
||||
}
|
||||
if (dev == 0){ // hopefully Device is the same as DualView's host type
|
||||
if ((modified_flags(1) > 0) && (modified_flags(1) >= modified_flags(0))) {
|
||||
Impl::throw_runtime_exception("Calling sync on a DualView with a const datatype.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void sync_host() {
|
||||
if( ! std::is_same< typename traits::data_type , typename traits::non_const_data_type>::value )
|
||||
Impl::throw_runtime_exception("Calling sync_host on a DualView with a const datatype.");
|
||||
if(modified_flags.data()==NULL) return;
|
||||
if(modified_flags(1) > modified_flags(0)) {
|
||||
deep_copy (h_view, d_view);
|
||||
modified_flags(1) = modified_flags(0) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void sync_device() {
|
||||
if( ! std::is_same< typename traits::data_type , typename traits::non_const_data_type>::value )
|
||||
Impl::throw_runtime_exception("Calling sync_device on a DualView with a const datatype.");
|
||||
if(modified_flags.data()==NULL) return;
|
||||
if(modified_flags(0) > modified_flags(1)) {
|
||||
deep_copy (d_view, h_view);
|
||||
modified_flags(1) = modified_flags(0) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
template<class Device>
|
||||
bool need_sync() const
|
||||
{
|
||||
const unsigned int dev =
|
||||
Impl::if_c<
|
||||
std::is_same<
|
||||
typename t_dev::memory_space,
|
||||
typename Device::memory_space>::value ,
|
||||
unsigned int,
|
||||
unsigned int>::select (1, 0);
|
||||
if(modified_flags.data()==NULL) return false;
|
||||
int dev = get_device_side<Device>();
|
||||
|
||||
if (dev) { // if Device is the same as DualView's device type
|
||||
if ((modified_host () > 0) && (modified_host () >= modified_device ())) {
|
||||
if (dev == 1) { // if Device is the same as DualView's device type
|
||||
if ((modified_flags(0) > 0) && (modified_flags(0) >= modified_flags(1))) {
|
||||
return true;
|
||||
}
|
||||
} else { // hopefully Device is the same as DualView's host type
|
||||
if ((modified_device () > 0) && (modified_device () >= modified_host ())) {
|
||||
}
|
||||
if (dev == 0){ // hopefully Device is the same as DualView's host type
|
||||
if ((modified_flags(1) > 0) && (modified_flags(1) >= modified_flags(0))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool need_sync_host() const {
|
||||
if(modified_flags.data()==NULL) return false;
|
||||
return modified_flags(0)<modified_flags(1);
|
||||
}
|
||||
|
||||
inline bool need_sync_device() const {
|
||||
if(modified_flags.data()==NULL) return false;
|
||||
return modified_flags(1)<modified_flags(0);
|
||||
}
|
||||
|
||||
/// \brief Mark data as modified on the given device \c Device.
|
||||
///
|
||||
/// If \c Device is the same as this DualView's device type, then
|
||||
@ -425,26 +567,22 @@ public:
|
||||
/// data as modified.
|
||||
template<class Device>
|
||||
void modify () {
|
||||
const unsigned int dev =
|
||||
Impl::if_c<
|
||||
std::is_same<
|
||||
typename t_dev::memory_space,
|
||||
typename Device::memory_space>::value,
|
||||
unsigned int,
|
||||
unsigned int>::select (1, 0);
|
||||
if(modified_flags.data()==NULL) return;
|
||||
int dev = get_device_side<Device>();
|
||||
|
||||
if (dev) { // if Device is the same as DualView's device type
|
||||
if (dev == 1) { // if Device is the same as DualView's device type
|
||||
// Increment the device's modified count.
|
||||
modified_device () = (modified_device () > modified_host () ?
|
||||
modified_device () : modified_host ()) + 1;
|
||||
} else { // hopefully Device is the same as DualView's host type
|
||||
modified_flags(1) = (modified_flags(1) > modified_flags(0) ?
|
||||
modified_flags(1) : modified_flags(0)) + 1;
|
||||
}
|
||||
if (dev == 0) { // hopefully Device is the same as DualView's host type
|
||||
// Increment the host's modified count.
|
||||
modified_host () = (modified_device () > modified_host () ?
|
||||
modified_device () : modified_host ()) + 1;
|
||||
modified_flags(0) = (modified_flags(1) > modified_flags(0) ?
|
||||
modified_flags(1) : modified_flags(0)) + 1;
|
||||
}
|
||||
|
||||
#ifdef KOKKOS_ENABLE_DEBUG_DUALVIEW_MODIFY_CHECK
|
||||
if (modified_host() && modified_device()) {
|
||||
if (modified_flags(0) && modified_flags(1)) {
|
||||
std::string msg = "Kokkos::DualView::modify ERROR: ";
|
||||
msg += "Concurrent modification of host and device views ";
|
||||
msg += "in DualView \"";
|
||||
@ -455,6 +593,45 @@ public:
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void modify_host() {
|
||||
if(modified_flags.data()!=NULL) {
|
||||
modified_flags(0) = (modified_flags(1) > modified_flags(0) ?
|
||||
modified_flags(1) : modified_flags(0)) + 1;
|
||||
#ifdef KOKKOS_ENABLE_DEBUG_DUALVIEW_MODIFY_CHECK
|
||||
if (modified_flags(0) && modified_flags(1)) {
|
||||
std::string msg = "Kokkos::DualView::modify_host ERROR: ";
|
||||
msg += "Concurrent modification of host and device views ";
|
||||
msg += "in DualView \"";
|
||||
msg += d_view.label();
|
||||
msg += "\"\n";
|
||||
Kokkos::abort(msg.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline void modify_device() {
|
||||
if(modified_flags.data()!=NULL) {
|
||||
modified_flags(1) = (modified_flags(1) > modified_flags(0) ?
|
||||
modified_flags(1) : modified_flags(0)) + 1;
|
||||
#ifdef KOKKOS_ENABLE_DEBUG_DUALVIEW_MODIFY_CHECK
|
||||
if (modified_flags(0) && modified_flags(1)) {
|
||||
std::string msg = "Kokkos::DualView::modify_device ERROR: ";
|
||||
msg += "Concurrent modification of host and device views ";
|
||||
msg += "in DualView \"";
|
||||
msg += d_view.label();
|
||||
msg += "\"\n";
|
||||
Kokkos::abort(msg.c_str());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
inline void clear_sync_state() {
|
||||
if(modified_flags.data()!=NULL)
|
||||
modified_flags(1) = modified_flags(0) = 0;
|
||||
}
|
||||
|
||||
//@}
|
||||
//! \name Methods for reallocating or resizing the View objects.
|
||||
//@{
|
||||
@ -476,7 +653,10 @@ public:
|
||||
h_view = create_mirror_view( d_view );
|
||||
|
||||
/* Reset dirty flags */
|
||||
modified_device() = modified_host() = 0;
|
||||
if(modified_flags.data()==NULL) {
|
||||
modified_flags = t_modified_flags("DualView::modified_flags");
|
||||
} else
|
||||
modified_flags(1) = modified_flags(0) = 0;
|
||||
}
|
||||
|
||||
/// \brief Resize both views, copying old contents into new if necessary.
|
||||
@ -491,13 +671,16 @@ public:
|
||||
const size_t n5 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
|
||||
const size_t n6 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ,
|
||||
const size_t n7 = KOKKOS_IMPL_CTOR_DEFAULT_ARG ) {
|
||||
if(modified_device() >= modified_host()) {
|
||||
if(modified_flags.data()==NULL) {
|
||||
modified_flags = t_modified_flags("DualView::modified_flags");
|
||||
}
|
||||
if(modified_flags(1) >= modified_flags(0)) {
|
||||
/* Resize on Device */
|
||||
::Kokkos::resize(d_view,n0,n1,n2,n3,n4,n5,n6,n7);
|
||||
h_view = create_mirror_view( d_view );
|
||||
|
||||
/* Mark Device copy as modified */
|
||||
modified_device() = modified_device()+1;
|
||||
modified_flags(1) = modified_flags(1)+1;
|
||||
|
||||
} else {
|
||||
/* Realloc on Device */
|
||||
@ -525,7 +708,7 @@ public:
|
||||
d_view = create_mirror_view( typename t_dev::execution_space(), h_view );
|
||||
|
||||
/* Mark Host copy as modified */
|
||||
modified_host() = modified_host()+1;
|
||||
modified_flags(0) = modified_flags(0)+1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -649,7 +832,10 @@ void
|
||||
deep_copy (DualView<DT,DL,DD,DM> dst, // trust me, this must not be a reference
|
||||
const DualView<ST,SL,SD,SM>& src )
|
||||
{
|
||||
if (src.modified_device () >= src.modified_host ()) {
|
||||
if(src.modified_flags.data()==NULL || dst.modified_flags.data()==NULL) {
|
||||
return deep_copy(dst.d_view, src.d_view);
|
||||
}
|
||||
if (src.modified_flags(1) >= src.modified_flags(0)) {
|
||||
deep_copy (dst.d_view, src.d_view);
|
||||
dst.template modify<typename DualView<DT,DL,DD,DM>::device_type> ();
|
||||
} else {
|
||||
@ -666,7 +852,10 @@ deep_copy (const ExecutionSpace& exec ,
|
||||
DualView<DT,DL,DD,DM> dst, // trust me, this must not be a reference
|
||||
const DualView<ST,SL,SD,SM>& src )
|
||||
{
|
||||
if (src.modified_device () >= src.modified_host ()) {
|
||||
if(src.modified_flags.data()==NULL || dst.modified_flags.data()==NULL) {
|
||||
return deep_copy(exec, dst.d_view, src.d_view);
|
||||
}
|
||||
if (src.modified_flags(1) >= src.modified_flags(0)) {
|
||||
deep_copy (exec, dst.d_view, src.d_view);
|
||||
dst.template modify<typename DualView<DT,DL,DD,DM>::device_type> ();
|
||||
} else {
|
||||
|
||||
@ -64,7 +64,7 @@ namespace Impl {
|
||||
template <typename Specialize>
|
||||
struct DynRankDimTraits {
|
||||
|
||||
enum : size_t{unspecified =KOKKOS_INVALID_INDEX};
|
||||
enum : size_t{unspecified = KOKKOS_INVALID_INDEX};
|
||||
|
||||
// Compute the rank of the view from the nonzero dimension arguments.
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
@ -384,8 +384,8 @@ public:
|
||||
// Removed dimension checks...
|
||||
|
||||
typedef typename DstType::offset_type dst_offset_type ;
|
||||
dst.m_map.m_offset = dst_offset_type(std::integral_constant<unsigned,0>() , src.layout() ); //Check this for integer input1 for padding, etc
|
||||
dst.m_map.m_handle = Kokkos::Impl::ViewDataHandle< DstTraits >::assign( src.m_map.m_handle , src.m_track );
|
||||
dst.m_map.m_impl_offset = dst_offset_type(std::integral_constant<unsigned,0>() , src.layout() ); //Check this for integer input1 for padding, etc
|
||||
dst.m_map.m_impl_handle = Kokkos::Impl::ViewDataHandle< DstTraits >::assign( src.m_map.m_impl_handle , src.m_track );
|
||||
dst.m_track.assign( src.m_track , DstTraits::is_managed );
|
||||
dst.m_rank = src.Rank ;
|
||||
}
|
||||
@ -565,10 +565,14 @@ public:
|
||||
|
||||
//----------------------------------------
|
||||
// Allow specializations to query their specialized map
|
||||
|
||||
#ifdef KOKKOS_ENABLE_DEPRECATED_CODE
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
const Kokkos::Impl::ViewMapping< traits , void > &
|
||||
implementation_map() const { return m_map ; }
|
||||
#endif
|
||||
KOKKOS_INLINE_FUNCTION
|
||||
const Kokkos::Impl::ViewMapping< traits , void > &
|
||||
impl_map() const { return m_map ; }
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
@ -624,7 +628,7 @@ public:
|
||||
reference_type operator()() const
|
||||
{
|
||||
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (0 , this->rank(), m_track, m_map) )
|
||||
return implementation_map().reference();
|
||||
return impl_map().reference();
|
||||
//return m_map.reference(0,0,0,0,0,0,0);
|
||||
}
|
||||
|
||||
@ -647,7 +651,7 @@ public:
|
||||
typename std::enable_if< !std::is_same<typename drvtraits::value_type, typename drvtraits::scalar_array_type>::value && std::is_integral<iType>::value, reference_type>::type
|
||||
operator[](const iType & i0) const
|
||||
{
|
||||
// auto map = implementation_map();
|
||||
// auto map = impl_map();
|
||||
const size_t dim_scalar = m_map.dimension_scalar();
|
||||
const size_t bytes = this->span() / dim_scalar;
|
||||
|
||||
@ -785,7 +789,7 @@ public:
|
||||
reference_type access() const
|
||||
{
|
||||
KOKKOS_IMPL_VIEW_OPERATOR_VERIFY( (0 , this->rank(), m_track, m_map) )
|
||||
return implementation_map().reference();
|
||||
return impl_map().reference();
|
||||
//return m_map.reference(0,0,0,0,0,0,0);
|
||||
}
|
||||
|
||||
@ -1004,7 +1008,7 @@ public:
|
||||
|
||||
//----------------------------------------
|
||||
// Allocation according to allocation properties and array layout
|
||||
// unused arg_layout dimensions must be set toKOKKOS_INVALID_INDEX so that rank deduction can properly take place
|
||||
// unused arg_layout dimensions must be set to KOKKOS_INVALID_INDEX so that rank deduction can properly take place
|
||||
template< class ... P >
|
||||
explicit inline
|
||||
DynRankView( const Kokkos::Impl::ViewCtorProp< P ... > & arg_prop
|
||||
@ -1179,7 +1183,7 @@ public:
|
||||
: DynRankView( Kokkos::Impl::ViewCtorProp< std::string >( arg_label )
|
||||
, typename traits::array_layout
|
||||
( arg_N0 , arg_N1 , arg_N2 , arg_N3 , arg_N4 , arg_N5 , arg_N6 , arg_N7 )
|
||||
)
|
||||
)
|
||||
{}
|
||||
|
||||
// For backward compatibility
|
||||
@ -1189,8 +1193,7 @@ public:
|
||||
, const typename traits::array_layout & arg_layout
|
||||
)
|
||||
: DynRankView( Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
|
||||
|
||||
, Impl::DynRankDimTraits<typename traits::specialize>::createLayout(arg_layout)
|
||||
, arg_layout
|
||||
)
|
||||
{}
|
||||
|
||||
@ -1205,7 +1208,9 @@ public:
|
||||
, const size_t arg_N6 =KOKKOS_INVALID_INDEX
|
||||
, const size_t arg_N7 =KOKKOS_INVALID_INDEX
|
||||
)
|
||||
: DynRankView(Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing ), arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7 )
|
||||
: DynRankView(Kokkos::Impl::ViewCtorProp< std::string , Kokkos::Impl::WithoutInitializing_t >( arg_prop.label , Kokkos::WithoutInitializing )
|
||||
, typename traits::array_layout(arg_N0, arg_N1, arg_N2, arg_N3, arg_N4, arg_N5, arg_N6, arg_N7)
|
||||
)
|
||||
{}
|
||||
|
||||
//----------------------------------------
|
||||
@ -1445,30 +1450,30 @@ public:
|
||||
ret_type dst ;
|
||||
|
||||
const SubviewExtents< 7 , rank > extents =
|
||||
ExtentGenerator< Args ... >::generator( src.m_map.m_offset.m_dim , args... ) ;
|
||||
ExtentGenerator< Args ... >::generator( src.m_map.m_impl_offset.m_dim , args... ) ;
|
||||
|
||||
dst_offset_type tempdst( src.m_map.m_offset , extents ) ;
|
||||
dst_offset_type tempdst( src.m_map.m_impl_offset , extents ) ;
|
||||
|
||||
dst.m_track = src.m_track ;
|
||||
|
||||
dst.m_map.m_offset.m_dim.N0 = tempdst.m_dim.N0 ;
|
||||
dst.m_map.m_offset.m_dim.N1 = tempdst.m_dim.N1 ;
|
||||
dst.m_map.m_offset.m_dim.N2 = tempdst.m_dim.N2 ;
|
||||
dst.m_map.m_offset.m_dim.N3 = tempdst.m_dim.N3 ;
|
||||
dst.m_map.m_offset.m_dim.N4 = tempdst.m_dim.N4 ;
|
||||
dst.m_map.m_offset.m_dim.N5 = tempdst.m_dim.N5 ;
|
||||
dst.m_map.m_offset.m_dim.N6 = tempdst.m_dim.N6 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N0 = tempdst.m_dim.N0 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N1 = tempdst.m_dim.N1 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N2 = tempdst.m_dim.N2 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N3 = tempdst.m_dim.N3 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N4 = tempdst.m_dim.N4 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N5 = tempdst.m_dim.N5 ;
|
||||
dst.m_map.m_impl_offset.m_dim.N6 = tempdst.m_dim.N6 ;
|
||||
|
||||
dst.m_map.m_offset.m_stride.S0 = tempdst.m_stride.S0 ;
|
||||
dst.m_map.m_offset.m_stride.S1 = tempdst.m_stride.S1 ;
|
||||
dst.m_map.m_offset.m_stride.S2 = tempdst.m_stride.S2 ;
|
||||
dst.m_map.m_offset.m_stride.S3 = tempdst.m_stride.S3 ;
|
||||
dst.m_map.m_offset.m_stride.S4 = tempdst.m_stride.S4 ;
|
||||
dst.m_map.m_offset.m_stride.S5 = tempdst.m_stride.S5 ;
|
||||
dst.m_map.m_offset.m_stride.S6 = tempdst.m_stride.S6 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S0 = tempdst.m_stride.S0 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S1 = tempdst.m_stride.S1 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S2 = tempdst.m_stride.S2 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S3 = tempdst.m_stride.S3 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S4 = tempdst.m_stride.S4 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S5 = tempdst.m_stride.S5 ;
|
||||
dst.m_map.m_impl_offset.m_stride.S6 = tempdst.m_stride.S6 ;
|
||||
|
||||
dst.m_map.m_handle = dst_handle_type( src.m_map.m_handle +
|
||||
src.m_map.m_offset( extents.domain_offset(0)
|
||||
dst.m_map.m_impl_handle = dst_handle_type( src.m_map.m_impl_handle +
|
||||
src.m_map.m_impl_offset( extents.domain_offset(0)
|
||||
, extents.domain_offset(1)
|
||||
, extents.domain_offset(2)
|
||||
, extents.domain_offset(3)
|
||||
@ -1896,6 +1901,7 @@ inline
|
||||
typename DynRankView<T,P...>::HostMirror
|
||||
create_mirror( const DynRankView<T,P...> & src
|
||||
, typename std::enable_if<
|
||||
std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
|
||||
! std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
|
||||
, Kokkos::LayoutStride >::value
|
||||
>::type * = 0
|
||||
@ -1914,6 +1920,7 @@ inline
|
||||
typename DynRankView<T,P...>::HostMirror
|
||||
create_mirror( const DynRankView<T,P...> & src
|
||||
, typename std::enable_if<
|
||||
std::is_same< typename ViewTraits<T,P...>::specialize , void >::value &&
|
||||
std::is_same< typename Kokkos::ViewTraits<T,P...>::array_layout
|
||||
, Kokkos::LayoutStride >::value
|
||||
>::type * = 0
|
||||
@ -1929,7 +1936,11 @@ create_mirror( const DynRankView<T,P...> & src
|
||||
|
||||
// Create a mirror in a new space (specialization for different space)
|
||||
template<class Space, class T, class ... P>
|
||||
typename Impl::MirrorDRVType<Space,T,P ...>::view_type create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src) {
|
||||
typename Impl::MirrorDRVType<Space,T,P ...>::view_type
|
||||
create_mirror(const Space& , const Kokkos::DynRankView<T,P...> & src
|
||||
, typename std::enable_if<
|
||||
std::is_same< typename ViewTraits<T,P...>::specialize , void >::value
|
||||
>::type * = 0) {
|
||||
return typename Impl::MirrorDRVType<Space,T,P ...>::view_type(src.label(), Impl::reconstructLayout(src.layout(), src.rank()) );
|
||||
}
|
||||
|
||||
@ -1985,6 +1996,29 @@ create_mirror_view(const Space& , const Kokkos::DynRankView<T,P...> & src
|
||||
return typename Impl::MirrorDRViewType<Space,T,P ...>::view_type(src.label(), Impl::reconstructLayout(src.layout(), src.rank()) );
|
||||
}
|
||||
|
||||
// Create a mirror view and deep_copy in a new space (specialization for same space)
|
||||
template<class Space, class T, class ... P>
|
||||
typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
|
||||
create_mirror_view_and_copy(const Space& , const Kokkos::DynRankView<T,P...> & src
|
||||
, std::string const& name = ""
|
||||
, typename std::enable_if<Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
|
||||
(void)name;
|
||||
return src;
|
||||
}
|
||||
|
||||
// Create a mirror view and deep_copy in a new space (specialization for different space)
|
||||
template<class Space, class T, class ... P>
|
||||
typename Impl::MirrorDRViewType<Space,T,P ...>::view_type
|
||||
create_mirror_view_and_copy(const Space& , const Kokkos::DynRankView<T,P...> & src
|
||||
, std::string const& name = ""
|
||||
, typename std::enable_if<!Impl::MirrorDRViewType<Space,T,P ...>::is_same_memspace>::type* = 0 ) {
|
||||
using Mirror = typename Impl::MirrorDRViewType<Space,T,P ...>::view_type;
|
||||
std::string label = name.empty() ? src.label() : name;
|
||||
auto mirror = Mirror( Kokkos::ViewAllocateWithoutInitializing(label), Impl::reconstructLayout(src.layout(), src.rank()) );
|
||||
deep_copy(mirror, src);
|
||||
return mirror;
|
||||
}
|
||||
|
||||
} //end Kokkos
|
||||
|
||||
|
||||
|
||||
1895
lib/kokkos/containers/src/Kokkos_OffsetView.hpp
Normal file
1895
lib/kokkos/containers/src/Kokkos_OffsetView.hpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -47,7 +47,9 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <Kokkos_Core.hpp>
|
||||
#include <Kokkos_View.hpp>
|
||||
#include <Kokkos_Parallel.hpp>
|
||||
#include <Kokkos_Parallel_Reduce.hpp>
|
||||
|
||||
namespace Kokkos {
|
||||
|
||||
|
||||
@ -86,14 +86,13 @@ public:
|
||||
vector():DV() {
|
||||
_size = 0;
|
||||
_extra_storage = 1.1;
|
||||
DV::modified_host() = 1;
|
||||
}
|
||||
|
||||
|
||||
vector(int n, Scalar val=Scalar()):DualView<Scalar*,LayoutLeft,Arg1Type>("Vector",size_t(n*(1.1))) {
|
||||
_size = n;
|
||||
_extra_storage = 1.1;
|
||||
DV::modified_host() = 1;
|
||||
DV::modified_flags(0) = 1;
|
||||
|
||||
assign(n,val);
|
||||
}
|
||||
@ -119,16 +118,16 @@ public:
|
||||
|
||||
/* Assign value either on host or on device */
|
||||
|
||||
if( DV::modified_host() >= DV::modified_device() ) {
|
||||
if( DV::template need_sync<typename DV::t_dev::device_type>() ) {
|
||||
set_functor_host f(DV::h_view,val);
|
||||
parallel_for(n,f);
|
||||
DV::t_host::execution_space::fence();
|
||||
DV::modified_host()++;
|
||||
DV::template modify<typename DV::t_host::device_type>();
|
||||
} else {
|
||||
set_functor f(DV::d_view,val);
|
||||
parallel_for(n,f);
|
||||
DV::t_dev::execution_space::fence();
|
||||
DV::modified_device()++;
|
||||
DV::template modify<typename DV::t_dev::device_type>();
|
||||
}
|
||||
}
|
||||
|
||||
@ -137,7 +136,8 @@ public:
|
||||
}
|
||||
|
||||
void push_back(Scalar val) {
|
||||
DV::modified_host()++;
|
||||
DV::template sync<typename DV::t_host::device_type>();
|
||||
DV::template modify<typename DV::t_host::device_type>();
|
||||
if(_size == span()) {
|
||||
size_t new_size = _size*_extra_storage;
|
||||
if(new_size == _size) new_size++;
|
||||
@ -247,10 +247,10 @@ public:
|
||||
}
|
||||
|
||||
void on_host() {
|
||||
DV::modified_host() = DV::modified_device() + 1;
|
||||
DV::template modify<typename DV::t_host::device_type>();
|
||||
}
|
||||
void on_device() {
|
||||
DV::modified_device() = DV::modified_host() + 1;
|
||||
DV::template modify<typename DV::t_dev::device_type>();
|
||||
}
|
||||
|
||||
void set_overallocation(float extra) {
|
||||
|
||||
Reference in New Issue
Block a user