KIDS  ver-0.0.1
KIDS : Kernel Integrated Dynamics Simulator
Loading...
Searching...
No Matches
Kernel.h
Go to the documentation of this file.
1
45#ifndef KIDS_Kernel_H
46#define KIDS_Kernel_H
47
48#include <memory>
49
50#include "kids/DataSet.h"
51#include "kids/Param.h"
52#include "kids/RuleSet.h"
53#include "kids/Status.h"
54
55namespace PROJECT_NS {
56
60class Kernel : public std::enable_shared_from_this<Kernel> {
61 public:
69 inline virtual const std::string getName() { return utils::concat("Kernel__", kernel_name); }
70
71 static int dump(Kernel* ker) { return 0; }
72
73 static int report(Kernel* ker) { return 0; }
74
75 static int mpi_reduce_info(Kernel* ker) { return 0; }
76
82 Kernel(const std::string& customized_name = "");
83
87 virtual ~Kernel();
88
94 void setInputParam(std::shared_ptr<Param>& PM);
95
101 void setInputDataSet(std::shared_ptr<DataSet>& DS);
102
108 std::shared_ptr<Param> getParam() const;
109
115 std::shared_ptr<DataSet> getDataSet() const;
116
124
132
140
150 virtual int getType() const;
151
157 int getID() const;
158
165 bool operator==(const Kernel& ker);
166
173 Kernel& appendChild(std::shared_ptr<Kernel> ker);
174
182 Kernel& insertAt(std::vector<std::size_t> indexes, std::shared_ptr<Kernel> ker);
183
190 Kernel& removeAt(std::vector<std::size_t> indexes);
191
199 Kernel& updateAt(std::vector<std::size_t> indexes, std::shared_ptr<Kernel> ker);
200
206 std::tuple<Kernel*, std::size_t> getLastParentKernelAndChildOrder();
207
213 std::shared_ptr<RuleSet> getRuleSet();
214
221 static const std::string serializeKernel(const Kernel& ker);
222
229 static std::shared_ptr<Kernel> deserializeKernel(const std::string& str);
230
243 const std::string generateInformationString(double total_time = -1.0f, //
244 int current_layer = 0, //
245 int total_depth = 0, //
246 int total_align_size = 0);
247
248
249 protected:
255 bool is_timing = false;
256 bool has_parent = false;
257 int count_calc = 0;
258 int count_exec = 0;
259 int kernel_id = 0;
260 int kernel_type = 0;
261 double exec_time = 0.0f;
262 int depth = 0;
264 std::string kernel_name;
265
273 std::shared_ptr<Param> _param;
274
278 std::shared_ptr<DataSet> _dataset;
279
283 std::shared_ptr<RuleSet> _ruleset;
284
289
293 std::size_t _order_in_parent;
294
298 std::vector<std::shared_ptr<Kernel>> _child_kernels;
299
303 std::vector<std::shared_ptr<Kernel>> _all_kernels;
304
310 virtual void setInputParam_impl(std::shared_ptr<Param>& PM);
311
317 virtual void setInputDataSet_impl(std::shared_ptr<DataSet>& DS);
318
325 virtual Status& initializeKernel_impl(Status& stat);
326
333 virtual Status& executeKernel_impl(Status& stat);
334
341 virtual Status& finalizeKernel_impl(Status& stat);
342
343 private:
352 void connectRelatedKernels(std::shared_ptr<Kernel>& ker);
353
362 static std::map<std::string, Kernel*>& getDictOfKernels();
363
371 static std::vector<Kernel*>& getKernels();
372};
373
374}; // namespace PROJECT_NS
375
376#endif // KIDS_Kernel_H
Declaration of the DataSet class and related classes.
Provide struct and interfaces for input parameters.
provide RuleSet class
provide Status class
this class provides the container and implementation of algorithms
Definition Kernel.h:60
virtual Status & initializeKernel_impl(Status &stat)
Virtual function to initialize the kernel implementation.
Definition Kernel.cpp:222
static std::shared_ptr< Kernel > deserializeKernel(const std::string &str)
Deserialize a string representation into a Kernel object.
Definition Kernel.cpp:187
Kernel * _parent_kernel
Pointer to the parent kernel.
Definition Kernel.h:288
std::shared_ptr< DataSet > getDataSet() const
Get the data set associated with the kernel.
Definition Kernel.cpp:37
Kernel & appendChild(std::shared_ptr< Kernel > ker)
Append a kernel as the last child of the current tree node.
Definition Kernel.cpp:78
std::shared_ptr< Param > getParam() const
Get the parameter associated with the kernel.
Definition Kernel.cpp:35
static int mpi_reduce_info(Kernel *ker)
Definition Kernel.h:75
std::vector< std::shared_ptr< Kernel > > _child_kernels
Vector containing shared pointers to the child kernels of this kernel.
Definition Kernel.h:298
virtual Status & finalizeKernel_impl(Status &stat)
Virtual function to finalize the kernel implementation.
Definition Kernel.cpp:226
static std::vector< Kernel * > & getKernels()
Get the vector of all kernel pointers.
Definition Kernel.cpp:247
virtual const std::string getName()
Get the name of the kernel.
Definition Kernel.h:69
std::shared_ptr< RuleSet > getRuleSet()
Get RuleSet associated with the Kernel.
Definition Kernel.cpp:183
static const std::string serializeKernel(const Kernel &ker)
Serialize a Kernel object into a string representation.
Definition Kernel.cpp:185
int getID() const
Get the ID of the kernel.
Definition Kernel.cpp:74
Kernel & removeAt(std::vector< std::size_t > indexes)
Remove kernels at specified indexes from the tree.
Definition Kernel.cpp:128
std::shared_ptr< Param > _param
Shared pointer to the Param object associated with this kernel.
Definition Kernel.h:273
virtual Status & executeKernel_impl(Status &stat)
Virtual function to execute the kernel implementation.
Definition Kernel.cpp:224
void setInputDataSet(std::shared_ptr< DataSet > &DS)
Set input data set for the kernel and its children.
Definition Kernel.cpp:28
static std::map< std::string, Kernel * > & getDictOfKernels()
Get the dictionary of kernels (mapping from names to kernel pointers).
virtual ~Kernel()
Destructor.
Definition Kernel.cpp:19
virtual int getType() const
Get the type of the kernel.
Definition Kernel.cpp:72
Status & executeKernel(Status &stat)
Execute the kernel's algorithm and those of its children.
Definition Kernel.cpp:48
virtual void setInputDataSet_impl(std::shared_ptr< DataSet > &DS)
Virtual function to set input data set for the kernel implementation.
Definition Kernel.cpp:220
virtual void setInputParam_impl(std::shared_ptr< Param > &PM)
Virtual function to set input parameters for the kernel implementation.
Definition Kernel.cpp:218
std::vector< std::shared_ptr< Kernel > > _all_kernels
Vector containing shared pointers to all descendant kernels of this kernel.
Definition Kernel.h:303
const std::string generateInformationString(double total_time=-1.0f, int current_layer=0, int total_depth=0, int total_align_size=0)
Generate a formatted string containing information about the kernel.
Definition Kernel.cpp:189
static int dump(Kernel *ker)
Definition Kernel.h:71
std::tuple< Kernel *, std::size_t > getLastParentKernelAndChildOrder()
Retrieve the last parent kernel along with the order of its child kernels, if available.
Definition Kernel.cpp:178
std::shared_ptr< DataSet > _dataset
Shared pointer to the DataSet object associated with this kernel.
Definition Kernel.h:278
Kernel(const std::string &customized_name="")
Constructor with an optional specified name.
Definition Kernel.cpp:12
void connectRelatedKernels(std::shared_ptr< Kernel > &ker)
Connect related kernels to this kernel.
Definition Kernel.cpp:228
Kernel & insertAt(std::vector< std::size_t > indexes, std::shared_ptr< Kernel > ker)
Insert a kernel at specified indexes in the tree.
Definition Kernel.cpp:102
Status & finalizeKernel(Status &stat)
Finalize the kernel and its children, performing any necessary cleanup.
Definition Kernel.cpp:66
std::size_t _order_in_parent
Order of this kernel in its parent's children.
Definition Kernel.h:293
bool operator==(const Kernel &ker)
Overloaded equality operator to compare two Kernel objects by their IDs.
Definition Kernel.cpp:76
Kernel & updateAt(std::vector< std::size_t > indexes, std::shared_ptr< Kernel > ker)
Update the kernel at specified indexes in the tree.
Definition Kernel.cpp:147
Status & initializeKernel(Status &stat)
Prepare initial conditions for the kernel and its children.
Definition Kernel.cpp:39
void setInputParam(std::shared_ptr< Param > &PM)
Set input parameters for the kernel and its children.
Definition Kernel.cpp:21
static int report(Kernel *ker)
Definition Kernel.h:73
std::shared_ptr< RuleSet > _ruleset
Recorded Rules associated with the Kernel.
Definition Kernel.h:283
int kernel_type
Type of the kernel.
Definition Kernel.h:260
std::string kernel_name
Name of the kernel.
Definition Kernel.h:264
int depth
Depth of the kernel in the tree structure.
Definition Kernel.h:262
int kernel_id
ID of the kernel.
Definition Kernel.h:259
int count_exec
Counter for the number of executions performed by this kernel.
Definition Kernel.h:258
int max_align_size
Maximum alignment size used by this kernel.
Definition Kernel.h:263
double exec_time
Total execution time of the kernel.
Definition Kernel.h:261
bool has_parent
Flag indicating whether the kernel has a parent.
Definition Kernel.h:256
int count_calc
Counter for the number of calculations performed by this kernel.
Definition Kernel.h:257
bool is_timing
Flag indicating whether timing is enabled for this kernel.
Definition Kernel.h:255
< http://warp.povusers.org/FunctionParser/fparser.html
Definition Context.h:39
std::basic_string< CharT > concat(const separator_t< CharT > &sep, Args &&... seq)
Definition concat.h:242