Serialbox  2.2.0
Data serialization library and tools for C/C++, Python and Fortran
StorageViewHelper.h
Go to the documentation of this file.
1 //===-- serialbox/core/frontend/gridtools/StorageViewHelper.h -----------------------*- C++ -*-===//
2 //
3 // S E R I A L B O X
4 //
5 // This file is distributed under terms of BSD license.
6 // See LICENSE.txt for more information
7 //
8 //===------------------------------------------------------------------------------------------===//
9 //
13 //===------------------------------------------------------------------------------------------===//
14 
15 #ifndef SERIALBOX_CORE_FRONTEND_GRIDTOOLS_STORAGE_VIEW_HELPER_H
16 #define SERIALBOX_CORE_FRONTEND_GRIDTOOLS_STORAGE_VIEW_HELPER_H
17 
18 #include <boost/mpl/max_element.hpp>
19 #include <storage/common/storage_info_rt.hpp>
20 #include <utility>
21 #include <vector>
22 
23 namespace serialbox {
24 
25 namespace gridtools {
26 
27 namespace internal {
28 
29 inline std::vector<int> unsigned_to_int(const std::vector<unsigned int>& in) {
30  std::vector<int> out(in.size());
31  std::copy(in.begin(), in.end(), out.begin());
32  return out;
33 }
34 
35 template <typename StorageType>
36 std::vector<int> get_strides(const StorageType& storage) {
37  return unsigned_to_int(::gridtools::to_vector(storage.strides()));
38 }
39 
40 /*
41  * @brief gets the unaligned dims from gridtools (not including alignment)
42  */
43 template <typename StorageType>
44 std::vector<int> get_dims(const StorageType& storage) noexcept {
45  return unsigned_to_int(::gridtools::to_vector(
46  ::gridtools::make_unaligned_dims_array(*storage.get_storage_info_ptr())));
47 }
48 
49 template <typename StorageType>
50 void* get_origin_ptr(const StorageType& storage, unsigned int field_idx) noexcept {
51  // TODO test data_fields
52  auto* data_ptr = storage.get_storage_ptr()->get_cpu_ptr();
53  auto index = storage.get_storage_info_ptr()->index(
54  {}); // http://en.cppreference.com/w/cpp/language/zero_initialization
55  return static_cast<void*>(data_ptr + index);
56 }
57 
58 } // namespace internal
59 
60 } // namespace gridtools
61 
62 } // namespace serialbox
63 
64 #endif
Namespace of the serialbox library.
Definition: Archive.h:25
Namespace of the gridtools frontend.