QMCPACK
allocator_traits.hpp
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////////////////
2 // This file is distributed under the University of Illinois/NCSA Open Source License.
3 // See LICENSE file in top directory for details.
4 //
5 // Copyright (c) 2019 QMCPACK developers.
6 //
7 // File developed by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
8 //
9 // File created by: Ye Luo, yeluo@anl.gov, Argonne National Laboratory
10 //////////////////////////////////////////////////////////////////////////////////////
11 
12 
13 #ifndef QMCPLUSPLUS_ACCESS_TRAITS_H
14 #define QMCPLUSPLUS_ACCESS_TRAITS_H
15 
16 #include <algorithm>
17 
18 namespace qmcplusplus
19 {
20 /** template class analogous to std::allocator_traits.
21  * * defines the is_host_accessible and is_dual_space traits
22  * * abstracts the data movement on,off and from place to place on device.
23  * * abstracts the fill function for the allocator.
24  */
25 template<class Allocator>
27 {
29 
30  static constexpr bool is_host_accessible = true;
31  static constexpr bool is_dual_space = false;
32 
33  static void fill_n(value_type* ptr, size_t n, const value_type& value) { std::fill_n(ptr, n, value); };
34 
35  /** So we can write generic tests that work with all QMCPACK allocators
36  * @param ptr_offset pointer offset between to and from
37  */
38  static void attachReference(Allocator& from, Allocator& to, std::ptrdiff_t ptr_offset);
39  // These abstract synchronous transfers, async semantics are vender specific
40  static void updateTo(Allocator& a, value_type* host_ptr, size_t n, size_t offset = 0);
41  static void updateFrom(Allocator& a, value_type* host_ptr, size_t n, size_t offset = 0);
42  static void deviceSideCopyN(Allocator& a, size_t to, size_t n, size_t from);
43 };
44 
45 template<class Allocator>
46 using IsHostSafe = std::enable_if_t<qmc_allocator_traits<Allocator>::is_host_accessible>;
47 
48 template<class Allocator>
49 using IsNotHostSafe = std::enable_if_t<!qmc_allocator_traits<Allocator>::is_host_accessible>;
50 
51 template<class Allocator>
52 using IsDualSpace = std::enable_if_t<qmc_allocator_traits<Allocator>::is_dual_space>;
53 } // namespace qmcplusplus
54 
55 #endif // QMCPLUSPLUS_ACCESS_TRAITS_H
helper functions for EinsplineSetBuilder
Definition: Configuration.h:43
static void updateTo(Allocator &a, value_type *host_ptr, size_t n, size_t offset=0)
typename Allocator::value_type value_type
void fill_n(T *x, size_t count, const T &value)
Definition: OMPstd.hpp:21
static void deviceSideCopyN(Allocator &a, size_t to, size_t n, size_t from)
std::enable_if_t< qmc_allocator_traits< Allocator >::is_host_accessible > IsHostSafe
std::enable_if_t<!qmc_allocator_traits< Allocator >::is_host_accessible > IsNotHostSafe
static void attachReference(Allocator &from, Allocator &to, std::ptrdiff_t ptr_offset)
So we can write generic tests that work with all QMCPACK allocators.
static constexpr bool is_host_accessible
template class analogous to std::allocator_traits.
static void updateFrom(Allocator &a, value_type *host_ptr, size_t n, size_t offset=0)
std::enable_if_t< qmc_allocator_traits< Allocator >::is_dual_space > IsDualSpace
static void fill_n(value_type *ptr, size_t n, const value_type &value)
QMCTraits::FullPrecRealType value_type