2121 *
2222 */
2323
24- #ifndef TILEDARRAY_DEVICE_PLATFORM_H__INCLUDED
25- #define TILEDARRAY_DEVICE_PLATFORM_H__INCLUDED
24+ #ifndef TILEDARRAY_PLATFORM_H__INCLUDED
25+ #define TILEDARRAY_PLATFORM_H__INCLUDED
26+
27+ #include < TiledArray/fwd.h>
28+
29+ #include < TiledArray/type_traits.h>
2630
2731namespace TiledArray {
2832
@@ -54,6 +58,40 @@ constexpr bool overlap(MemorySpace space1, MemorySpace space2) {
5458 return (space1 & space2) != MemorySpace::Null;
5559}
5660
61+ // customization point: is_constexpr_size_of_v<S,T> reports whether
62+ // size_of<S>(T) is the same for all T
63+ template <MemorySpace S, typename T>
64+ inline constexpr bool is_constexpr_size_of_v = detail::is_numeric_v<T>;
65+
66+ // customization point: size_of<S>(O) -> std::size_t reports the number of
67+ // bytes occupied by O in S
68+ template <MemorySpace S, typename T,
69+ typename = std::enable_if_t <is_constexpr_size_of_v<S, T>>>
70+ constexpr std::size_t size_of (const T& t) {
71+ return sizeof (T);
72+ }
73+
74+ // customization point: allocates_memory_space<S>(A) -> bool reports whether
75+ // allocator A allocates memory in space S
76+ template <MemorySpace S, typename T>
77+ constexpr bool allocates_memory_space (const std::allocator<T>& a) {
78+ return S == MemorySpace::Host;
79+ }
80+ template <MemorySpace S, typename T>
81+ constexpr bool allocates_memory_space (const Eigen::aligned_allocator<T>& a) {
82+ return S == MemorySpace::Host;
83+ }
84+ template <MemorySpace S, typename T>
85+ constexpr bool allocates_memory_space (const host_allocator<T>& a) {
86+ return S == MemorySpace::Host;
87+ }
88+ #ifdef TILEDARRAY_HAS_DEVICE
89+ template <MemorySpace S, typename T>
90+ constexpr bool allocates_memory_space (const device_um_allocator<T>& a) {
91+ return S == MemorySpace::Device_UM;
92+ }
93+ #endif
94+
5795// / enumerates the execution spaces
5896enum class ExecutionSpace { Host, Device };
5997
@@ -62,4 +100,4 @@ enum class ExecutionSpace { Host, Device };
62100
63101} // namespace TiledArray
64102
65- #endif // TILEDARRAY_DEVICE_PLATFORM_H__INCLUDED
103+ #endif // TILEDARRAY_PLATFORM_H__INCLUDED
0 commit comments