Line data Source code
1 : /*!
2 : * \file
3 : * \brief Class module::Module.
4 : */
5 : #ifndef MODULE_HPP_
6 : #define MODULE_HPP_
7 :
8 : #include <cstddef>
9 : #include <functional>
10 : #include <memory>
11 : #include <string>
12 : #include <type_traits>
13 : #include <vector>
14 :
15 : #include "Runtime/Socket/Socket.hpp"
16 : #include "Runtime/Task/Task.hpp"
17 : #include "Tools/Interface/Interface_clone.hpp"
18 : #include "Tools/Interface/Interface_get_set_n_frames.hpp"
19 :
20 : namespace spu
21 : {
22 : namespace module
23 : {
24 : /*!
25 : * \class Module
26 : *
27 : * \brief A Module is an abstract concept. Basically, all the objects used in a Simulation are a Module.
28 : */
29 : class Module
30 : : public tools::Interface_clone
31 : , public tools::Interface_get_set_n_frames
32 : {
33 : protected:
34 : size_t n_frames; /*!< Number of frames to process in this Module */
35 : size_t n_frames_per_wave;
36 : size_t n_waves;
37 : size_t n_frames_per_wave_rest;
38 : bool single_wave;
39 : std::string name; /*!< Name of the Module. */
40 : std::string short_name; /*!< Short name of the Module. */
41 : std::string custom_name; /*!< Custom name of the Module. */
42 : std::vector<std::shared_ptr<runtime::Task>> tasks_with_nullptr;
43 :
44 : public:
45 : std::vector<std::shared_ptr<runtime::Task>> tasks;
46 :
47 : /*!
48 : * \brief Constructor.
49 : */
50 : explicit Module();
51 :
52 : /*!
53 : * \brief Destructor.
54 : */
55 766 : virtual ~Module() = default;
56 :
57 : virtual Module* clone() const;
58 :
59 : /*!
60 : * \brief Get the number of frames.
61 : *
62 : * \return the number of frames to process in this Module.
63 : */
64 : inline size_t get_n_frames() const;
65 :
66 : virtual void set_n_frames(const size_t n_frames);
67 :
68 : inline size_t get_n_frames_per_wave() const;
69 :
70 : inline size_t get_n_waves() const;
71 :
72 : inline size_t get_n_frames_per_wave_rest() const;
73 :
74 : inline bool is_single_wave() const;
75 :
76 : const std::string& get_name() const;
77 :
78 : const std::string& get_short_name() const;
79 :
80 : void set_custom_name(const std::string& custom_name);
81 :
82 : const std::string& get_custom_name() const;
83 :
84 : void remove_custom_name();
85 :
86 : inline runtime::Task& operator[](const size_t id);
87 : inline const runtime::Task& operator[](const size_t id) const;
88 : inline runtime::Socket& operator[](const std::string& tsk_sck);
89 : inline runtime::Task& operator()(const std::string& tsk_name);
90 :
91 : void set_fast(const bool fast);
92 :
93 : void create_reset_task();
94 :
95 : protected:
96 : void deep_copy(const Module& m);
97 :
98 : void set_name(const std::string& name);
99 :
100 : void set_short_name(const std::string& short_name);
101 :
102 : runtime::Task& create_task(const std::string& name, const int id = -1);
103 : runtime::Task& create_tsk(const std::string& name, const int id = -1);
104 :
105 : template<typename T>
106 : size_t create_socket_in(runtime::Task& task, const std::string& name, const size_t n_elmts);
107 : size_t create_socket_in(runtime::Task& task,
108 : const std::string& name,
109 : const size_t n_elmts,
110 : const std::type_index& datatype);
111 : size_t create_socket_in(runtime::Task& task,
112 : const std::string& name,
113 : const size_t n_elmts,
114 : const runtime::datatype_t datatype);
115 :
116 : template<typename T>
117 : size_t create_sck_in(runtime::Task& task, const std::string& name, const size_t n_elmts);
118 : size_t create_sck_in(runtime::Task& task,
119 : const std::string& name,
120 : const size_t n_elmts,
121 : const std::type_index& datatype);
122 : size_t create_sck_in(runtime::Task& task,
123 : const std::string& name,
124 : const size_t n_elmts,
125 : const runtime::datatype_t datatype);
126 :
127 : template<typename T>
128 : size_t create_socket_out(runtime::Task& task, const std::string& name, const size_t n_elmts);
129 : size_t create_socket_out(runtime::Task& task,
130 : const std::string& name,
131 : const size_t n_elmts,
132 : const std::type_index& datatype);
133 : size_t create_socket_out(runtime::Task& task,
134 : const std::string& name,
135 : const size_t n_elmts,
136 : const runtime::datatype_t datatype);
137 :
138 : template<typename T>
139 : size_t create_sck_out(runtime::Task& task, const std::string& name, const size_t n_elmts);
140 : size_t create_sck_out(runtime::Task& task,
141 : const std::string& name,
142 : const size_t n_elmts,
143 : const std::type_index& datatype);
144 : size_t create_sck_out(runtime::Task& task,
145 : const std::string& name,
146 : const size_t n_elmts,
147 : const runtime::datatype_t datatype);
148 :
149 : template<typename T>
150 : size_t create_socket_fwd(runtime::Task& task, const std::string& name, const size_t n_elmts);
151 : size_t create_socket_fwd(runtime::Task& task,
152 : const std::string& name,
153 : const size_t n_elmts,
154 : const std::type_index& datatype);
155 : size_t create_socket_fwd(runtime::Task& task,
156 : const std::string& name,
157 : const size_t n_elmts,
158 : const runtime::datatype_t datatype);
159 :
160 : template<typename T>
161 : size_t create_sck_fwd(runtime::Task& task, const std::string& name, const size_t n_elmts);
162 : size_t create_sck_fwd(runtime::Task& task,
163 : const std::string& name,
164 : const size_t n_elmts,
165 : const std::type_index& datatype);
166 : size_t create_sck_fwd(runtime::Task& task,
167 : const std::string& name,
168 : const size_t n_elmts,
169 : const runtime::datatype_t datatype);
170 :
171 : template<typename T>
172 : size_t create_2d_socket_in(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols);
173 : size_t create_2d_socket_in(runtime::Task& task,
174 : const std::string& name,
175 : const size_t n_rows,
176 : const size_t n_cols,
177 : const std::type_index& datatype);
178 : size_t create_2d_socket_in(runtime::Task& task,
179 : const std::string& name,
180 : const size_t n_rows,
181 : const size_t n_cols,
182 : const runtime::datatype_t datatype);
183 :
184 : template<typename T>
185 : size_t create_2d_sck_in(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols);
186 : size_t create_2d_sck_in(runtime::Task& task,
187 : const std::string& name,
188 : const size_t n_rows,
189 : const size_t n_cols,
190 : const std::type_index& datatype);
191 : size_t create_2d_sck_in(runtime::Task& task,
192 : const std::string& name,
193 : const size_t n_rows,
194 : const size_t n_cols,
195 : const runtime::datatype_t datatype);
196 :
197 : template<typename T>
198 : size_t create_2d_socket_out(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols);
199 : size_t create_2d_socket_out(runtime::Task& task,
200 : const std::string& name,
201 : const size_t n_rows,
202 : const size_t n_cols,
203 : const std::type_index& datatype);
204 : size_t create_2d_socket_out(runtime::Task& task,
205 : const std::string& name,
206 : const size_t n_rows,
207 : const size_t n_cols,
208 : const runtime::datatype_t datatype);
209 :
210 : template<typename T>
211 : size_t create_2d_sck_out(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols);
212 : size_t create_2d_sck_out(runtime::Task& task,
213 : const std::string& name,
214 : const size_t n_rows,
215 : const size_t n_cols,
216 : const std::type_index& datatype);
217 : size_t create_2d_sck_out(runtime::Task& task,
218 : const std::string& name,
219 : const size_t n_rows,
220 : const size_t n_cols,
221 : const runtime::datatype_t datatype);
222 :
223 : template<typename T>
224 : size_t create_2d_socket_fwd(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols);
225 : size_t create_2d_socket_fwd(runtime::Task& task,
226 : const std::string& name,
227 : const size_t n_rows,
228 : const size_t n_cols,
229 : const std::type_index& datatype);
230 : size_t create_2d_socket_fwd(runtime::Task& task,
231 : const std::string& name,
232 : const size_t n_rows,
233 : const size_t n_cols,
234 : const runtime::datatype_t datatype);
235 :
236 : template<typename T>
237 : size_t create_2d_sck_fwd(runtime::Task& task, const std::string& name, const size_t n_rows, const size_t n_cols);
238 : size_t create_2d_sck_fwd(runtime::Task& task,
239 : const std::string& name,
240 : const size_t n_rows,
241 : const size_t n_cols,
242 : const std::type_index& datatype);
243 : size_t create_2d_sck_fwd(runtime::Task& task,
244 : const std::string& name,
245 : const size_t n_rows,
246 : const size_t n_cols,
247 : const runtime::datatype_t datatype);
248 :
249 : void create_codelet(runtime::Task& task,
250 : std::function<int(Module& m, runtime::Task& t, const size_t frame_id)> codelet);
251 : void create_cdl(runtime::Task& task,
252 : std::function<int(Module& m, runtime::Task& t, const size_t frame_id)> codelet);
253 :
254 : void register_timer(runtime::Task& task, const std::string& key);
255 :
256 : virtual void set_n_frames_per_wave(const size_t n_frames_per_wave);
257 :
258 : void set_single_wave(const bool enable_single_wave);
259 :
260 : private:
261 : void _set_n_frames_per_wave(const size_t n_frames_per_wave);
262 : void _set_n_frames(const size_t n_frames);
263 : };
264 : }
265 : }
266 :
267 : #ifndef DOXYGEN_SHOULD_SKIP_THIS
268 : #include "Module/Module.hxx"
269 : #endif
270 :
271 : #endif /* MODULE_HPP_ */
|