Skip to content

Commit f678ad7

Browse files
committed
move platform.h from device to top-level
1 parent 2cb5ae1 commit f678ad7

File tree

5 files changed

+49
-11
lines changed

5 files changed

+49
-11
lines changed

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ TiledArray/error.h
3838
TiledArray/initialize.h
3939
TiledArray/perm_index.h
4040
TiledArray/permutation.h
41+
TiledArray/platform.h
4142
TiledArray/proc_grid.h
4243
TiledArray/range.h
4344
TiledArray/range1.h
@@ -239,7 +240,6 @@ if(TILEDARRAY_HAS_HIP OR TILEDARRAY_HAS_CUDA)
239240
TiledArray/device/kernel/reduce_kernel.h
240241
TiledArray/device/kernel/thrust/mult_kernel.h
241242
TiledArray/device/kernel/thrust/reduce_kernel.h
242-
TiledArray/device/platform.h
243243
TiledArray/device/thrust.h
244244
TiledArray/device/um_storage.h
245245
)

src/TiledArray/device/btas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737

3838
#include <TiledArray/device/kernel/mult_kernel.h>
3939
#include <TiledArray/device/kernel/reduce_kernel.h>
40-
#include <TiledArray/device/platform.h>
4140
#include <TiledArray/device/um_storage.h>
4241
#include <TiledArray/math/gemm_helper.h>
42+
#include <TiledArray/platform.h>
4343

4444
namespace TiledArray {
4545

src/TiledArray/device/cpu_cuda_vector.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include <btas/array_adaptor.h>
66

7-
#include <TiledArray/device/platform.h>
87
#include <TiledArray/device/thrust.h>
8+
#include <TiledArray/platform.h>
99

1010
#include <madness/world/archive.h>
1111

@@ -213,18 +213,18 @@ struct ArchiveLoadImpl<Archive, TiledArray::cpu_cuda_vector<T>> {
213213
static inline void load(const Archive& ar,
214214
TiledArray::cpu_cuda_vector<T>& x) {
215215
typename TiledArray::cpu_cuda_vector<T>::size_type n(0);
216-
ar& n;
216+
ar & n;
217217
x.resize(n);
218-
for (auto& xi : x) ar& xi;
218+
for (auto& xi : x) ar & xi;
219219
}
220220
};
221221

222222
template <class Archive, typename T>
223223
struct ArchiveStoreImpl<Archive, TiledArray::cpu_cuda_vector<T>> {
224224
static inline void store(const Archive& ar,
225225
const TiledArray::cpu_cuda_vector<T>& x) {
226-
ar& x.size();
227-
for (const auto& xi : x) ar& xi;
226+
ar & x.size();
227+
for (const auto& xi : x) ar & xi;
228228
}
229229
};
230230

src/TiledArray/device/um_storage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include <btas/array_adaptor.h>
3232
#include <btas/varray/varray.h>
3333

34-
#include <TiledArray/device/platform.h>
34+
#include <TiledArray/platform.h>
3535
#include <TiledArray/utility.h>
3636

3737
#include <madness/world/archive.h>
Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@
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

2731
namespace 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
5896
enum 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

Comments
 (0)