24#ifndef CALCSERVER_H_INCLUDED
25#define CALCSERVER_H_INCLUDED
40#ifndef N_PROFILING_SNAPSHOTS
41#define N_PROFILING_SNAPSHOTS 2
44#define CHECK_OCL_OR_THROW(err_code, msg) \
45 if (err_code != CL_SUCCESS) { \
46 LOG(L_ERROR, std::string(msg) + "\n"); \
47 Aqua::InputOutput::Logger::singleton()->printOpenCLError(err_code); \
48 throw std::runtime_error("OpenCL error"); \
70 : std::runtime_error(msg){};
118 inline cl_ulong
step()
const {
return _step; }
146 std::string name = tool->
name() +
"::" + substage->
name();
148 while ((parent = parent->parent())) {
149 name = parent->name() +
"::" + name;
157 std::deque<ProfilingSnapshot>
get()
const;
168 static inline cl_long
delta(
const cl_ulong& t,
const cl_ulong& t0)
170 return (t > t0) ? t - t0 : -(cl_long)(t0 - t);
185 std::deque<ProfilingSnapshot> _snapshots;
253 inline std::vector<std::string>
definitions()
const {
return _definitions; }
258 inline std::vector<Tool*>
tools()
const {
return _tools; }
263 inline cl_context
context()
const {
return _context; }
268 inline cl_platform_id
platform()
const {
return _platform; }
273 inline cl_device_id
device()
const {
return _device; }
285 return _device_compile_flags.c_str();
294 template <
typename T>
318 cl_command_queue command_queue(
319 cmd_queue which = cmd_queue::cmd_queue_current);
327 cl_int err_code = CL_SUCCESS;
328 for (
auto queue : _command_queues)
329 err_code |= clFinish(queue);
330 err_code |= clFinish(_command_queue_parallel);
341 std::vector<cl_event> all_events()
const;
347 cl_event marker()
const;
356 cl_event marker(cl_command_queue cmd, std::vector<cl_event> events)
const;
368 auto now = std::chrono::system_clock::now();
369 return (cl_ulong)std::chrono::duration_cast<std::chrono::nanoseconds>(
370 now.time_since_epoch())
385 cl_event getUnsortedMem(
const std::string var_name,
393 const std::string
base_path()
const {
return _base_path.c_str(); }
400 inline bool have_3d()
const {
return _sim_data.dims() == 3; }
408 return _sim_data.settings.debug_tools;
418 return _sim_data.settings.debug_tools & opt;
425 std::tuple<std::vector<InputOutput::Variable*>,
426 std::vector<InputOutput::Variable*>>
427 eventVars(cl_event event)
const;
432 Tool* eventTool(cl_event event)
const;
443 void setupPlatform();
449 cl_uint _num_platforms;
451 cl_platform_id* _platforms;
453 cl_uint _num_devices;
455 cl_device_id* _devices;
459 cl_platform_id _platform;
461 cl_device_id _device;
463 cl_uint _device_bits;
465 std::string _device_compile_flags;
476 unsigned int _command_queue_current;
478 std::vector<cl_command_queue> _command_queues;
482 cl_command_queue _command_queue_parallel;
485 cl_ulong _device_timer_offset;
491 std::vector<std::string> _definitions;
494 std::vector<Tool*> _tools;
500 std::string _base_path;
510 char* _current_tool_name;
515 std::map<std::string, UnSort*> unsorters;
525 cl_mem __phony_mems[2];
#define N_PROFILING_SNAPSHOTS
Definition CalcServer.hpp:41
Simulation configuration data structures. (See Aqua::InputOutput::ProblemSetup for details)
#define T
Definition Sort.hcl.in:83
Simulation time flow events manager. (See Aqua::InputOutput::TimeManager for details)
Virtual variables environment to allow the user define/manipulate the variables used in the simulatio...
std::vector< std::string > definitions() const
Definition CalcServer.hpp:253
CalcServer(const Aqua::InputOutput::ProblemSetup &sim_data)
Constructor.
Definition CalcServer.cpp:139
void update(InputOutput::TimeManager &t_manager)
Internal time loop.
Definition CalcServer.cpp:592
cl_device_id device() const
Definition CalcServer.hpp:273
std::vector< Tool * > tools() const
Definition CalcServer.hpp:258
InputOutput::Variables * variables()
Definition CalcServer.hpp:248
const std::string base_path() const
Get the AQUAgpusph root path.
Definition CalcServer.hpp:393
bool have_3d() const
Get if 3 dimensions are considered.
Definition CalcServer.hpp:400
void raiseSIGINT()
Raise a SIGINT/SIGTERM signal.
Definition CalcServer.cpp:584
cl_context context() const
Definition CalcServer.hpp:263
void setup()
Setup some additional simulation data.
Definition CalcServer.cpp:1435
bool debug_mode() const
Report if any tools debug option is enabled.
Definition CalcServer.hpp:406
static cl_ulong host_timer()
Get the host timer.
Definition CalcServer.hpp:366
const char * device_compile_flags() const
Get the device compilation flags.
Definition CalcServer.hpp:283
cl_int finish() const
Definition CalcServer.hpp:325
cl_ulong device_timer_offset() const
Get the offset between the device timer and the host one.
Definition CalcServer.hpp:361
cl_int setKernelSizeArg(cl_kernel kernel, cl_uint arg_index, const T arg_value)
wrapper to clSetKernelArg to set variables which size depends on the device address bits
bool debug_mode(debug_opts opt) const
Report if the tools debug mode option is enabled.
Definition CalcServer.hpp:416
cl_uint device_addr_bits() const
Get the device address bits.
Definition CalcServer.hpp:278
cmd_queue
Definition CalcServer.hpp:300
@ cmd_queue_current
Definition CalcServer.hpp:301
@ cmd_queue_new
Definition CalcServer.hpp:302
@ cmd_queue_mpi
Definition CalcServer.hpp:303
cl_platform_id platform() const
Definition CalcServer.hpp:268
static CalcServer * singleton()
Get –creating it the first time– the logger instance.
Definition CalcServer.cpp:578
void name(const std::string tool_name)
Definition Tool.hpp:66
Profiler subinstance base class.
Definition Tool.hpp:84
A FIFO list of profiling snapshots.
Definition CalcServer.hpp:99
cl_ulong step() const
Get the number of times the tools pack has been executed.
Definition CalcServer.hpp:118
std::deque< ProfilingSnapshot > get() const
Get the stored snapshots.
Definition CalcServer.cpp:101
ProfilingInfo(const cl_uint n=N_PROFILING_SNAPSHOTS)
Constructor.
Definition CalcServer.hpp:104
void sample(cl_ulong step, Tool *tool, Profile *substage, cl_ulong start, cl_ulong end)
Add a new sample to an specific step.
Definition CalcServer.hpp:140
~ProfilingInfo()
Destructor.
Definition CalcServer.hpp:111
void sample(cl_ulong step, Tool *tool, std::string name, cl_ulong start, cl_ulong end)
Add a new sample to an specific step.
Definition CalcServer.cpp:108
void newStep()
Let the profiler know that a new step of tools execution is about to start.
Definition CalcServer.cpp:125
static cl_long delta(const cl_ulong &t, const cl_ulong &t0)
Get the delta time.
Definition CalcServer.hpp:168
user_interruption(const std::string msg)
Constructor.
Definition CalcServer.hpp:69
struct Aqua::CalcServer::_ProfilingSnapshot ProfilingSnapshot
Profiling snapshot.
InputOutput::ProblemSetup::sphSettings::debug_opts debug_opts
Definition CalcServer.hpp:56
struct Aqua::CalcServer::_ProfilingSample ProfilingSample
Profiling sample.
Main AQUAgpusph namespace.
Definition ArgumentsManager.cpp:50
Set of definitions and macros related with the implementation.
#define DECLDIR
Prefix to export C functions on the compiled library.
Definition sphPrerequisites.hpp:65
Profiling sample.
Definition CalcServer.hpp:75
Tool * tool
The triggering tool.
Definition CalcServer.hpp:77
cl_ulong start
The starting timer.
Definition CalcServer.hpp:81
std::string name
The name of the sample.
Definition CalcServer.hpp:79
cl_ulong end
The ending timer.
Definition CalcServer.hpp:83
Profiling snapshot.
Definition CalcServer.hpp:88
cl_ulong step
The profiling step.
Definition CalcServer.hpp:90
std::vector< ProfilingSample > samples
The list of samples.
Definition CalcServer.hpp:92