RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
InitLocalMem.hpp
Go to the documentation of this file.
1 
11 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
12 // Copyright (c) Lawrence Livermore National Security, LLC and other
13 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
14 // files for dates and other details. No copyright assignment is required
15 // to contribute to RAJA.
16 //
17 // SPDX-License-Identifier: (BSD-3-Clause)
18 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
19 
20 #ifndef RAJA_pattern_kernel_InitLocalMem_HPP
21 #define RAJA_pattern_kernel_InitLocalMem_HPP
22 
23 #include "RAJA/config.hpp"
24 
25 #include <iostream>
26 #include <type_traits>
27 #include <memory>
28 
29 namespace RAJA
30 {
31 
32 // Policies for RAJA local arrays
33 struct cpu_tile_mem;
34 
35 namespace statement
36 {
37 
38 
48 template<typename Pol, typename Indices, typename... EnclosedStmts>
49 struct InitLocalMem : public internal::Statement<camp::nil>
50 {};
51 
52 // Policy Specialization
53 template<camp::idx_t... Indices, typename... EnclosedStmts>
54 struct InitLocalMem<RAJA::cpu_tile_mem,
55  camp::idx_seq<Indices...>,
56  EnclosedStmts...> : public internal::Statement<camp::nil>
57 {};
58 
59 
60 } // end namespace statement
61 
62 namespace internal
63 {
64 
65 // Statement executor to initalize RAJA local array
66 template<camp::idx_t... Indices, typename... EnclosedStmts, typename Types>
67 struct StatementExecutor<statement::InitLocalMem<RAJA::cpu_tile_mem,
68  camp::idx_seq<Indices...>,
69  EnclosedStmts...>,
70  Types>
71 {
72 
73  // Execute statement list
74  template<class Data>
75  static void RAJA_INLINE exec_expanded(Data&& data)
76  {
77  execute_statement_list<camp::list<EnclosedStmts...>, Types>(data);
78  }
79 
80  // Intialize local array
81  // Identifies type + number of elements needed
82  template<camp::idx_t Pos, camp::idx_t... others, class Data>
83  static void RAJA_INLINE exec_expanded(Data&& data)
84  {
85  using varType = typename camp::tuple_element_t<
86  Pos, typename camp::decay<Data>::param_tuple_t>::value_type;
87 
88  // Initialize memory
89  auto local_mem =
90  std::make_unique<varType[]>(camp::get<Pos>(data.param_tuple).size());
91  camp::get<Pos>(data.param_tuple).set_data(local_mem.get());
92 
93  // Initialize others and execute
94  exec_expanded<others...>(data);
95 
96  // Cleanup and return
97  camp::get<Pos>(data.param_tuple).set_data(nullptr);
98  }
99 
100  template<typename Data>
101  static RAJA_INLINE void exec(Data&& data)
102  {
103  // Initalize local arrays + execute statements + cleanup
104  exec_expanded<Indices...>(data);
105  }
106 };
107 
108 
109 } // namespace internal
110 } // end namespace RAJA
111 
112 
113 #endif /* RAJA_pattern_kernel_HPP */
RAJA_INLINE void execute_statement_list(Data &&data)
Definition: StatementList.hpp:84
Definition: AlignedRangeIndexSetBuilders.cpp:35
Definition: Statement.hpp:48
Definition: Statement.hpp:35
Definition: InitLocalMem.hpp:50