AQUAgpusph 5.0.4
Loading...
Searching...
No Matches
Aqua::CalcServer::CalcServer Class Reference

Entity that perform the main work of the simulation. More...

#include <CalcServer.hpp>

Inheritance diagram for Aqua::CalcServer::CalcServer:
Collaboration diagram for Aqua::CalcServer::CalcServer:

Public Types

enum  cmd_queue { cmd_queue_current , cmd_queue_new , cmd_queue_mpi }

Public Member Functions

 CalcServer (const Aqua::InputOutput::ProblemSetup &sim_data)
 Constructor.
 ~CalcServer ()
 Destructor.
void raiseSIGINT ()
 Raise a SIGINT/SIGTERM signal.
void update (InputOutput::TimeManager &t_manager)
 Internal time loop.
void setup ()
 Setup some additional simulation data.
InputOutput::Variablesvariables ()
std::vector< std::string > definitions () const
std::vector< Tool * > tools () const
cl_context context () const
cl_platform_id platform () const
cl_device_id device () const
cl_uint device_addr_bits () const
 Get the device address bits.
const char * device_compile_flags () const
 Get the device compilation flags.
template<typename T>
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
cl_command_queue command_queue (cmd_queue which=cmd_queue::cmd_queue_current)
cl_int finish () const
std::vector< cl_event > all_events () const
cl_event marker () const
cl_event marker (cl_command_queue cmd, std::vector< cl_event > events) const
cl_ulong device_timer_offset () const
 Get the offset between the device timer and the host one.
cl_event getUnsortedMem (const std::string var_name, size_t offset, size_t cb, void *ptr)
 Download a unsorted variable from the device.
const std::string base_path () const
 Get the AQUAgpusph root path.
bool have_3d () const
 Get if 3 dimensions are considered.
bool debug_mode () const
 Report if any tools debug option is enabled.
bool debug_mode (debug_opts opt) const
 Report if the tools debug mode option is enabled.
std::tuple< std::vector< InputOutput::Variable * >, std::vector< InputOutput::Variable * > > eventVars (cl_event event) const
 Get the variables associated to an event, if any.
TooleventTool (cl_event event) const
 Get the tool that emitted an event, if any.
template<>
cl_int setKernelSizeArg (cl_kernel kernel, cl_uint arg_index, const size_t arg_value)
Public Member Functions inherited from Aqua::CalcServer::ProfilingInfo
 ProfilingInfo (const cl_uint n=N_PROFILING_SNAPSHOTS)
 Constructor.
 ~ProfilingInfo ()
 Destructor.
cl_ulong step () const
 Get the number of times the tools pack has been executed.
void sample (cl_ulong step, Tool *tool, std::string name, cl_ulong start, cl_ulong end)
 Add a new sample to an specific step.
void sample (cl_ulong step, Tool *tool, Profile *substage, cl_ulong start, cl_ulong end)
 Add a new sample to an specific step.
std::deque< ProfilingSnapshotget () const
 Get the stored snapshots.

Static Public Member Functions

static CalcServersingleton ()
 Get –creating it the first time– the logger instance.
static cl_ulong host_timer ()
 Get the host timer.
Static Public Member Functions inherited from Aqua::CalcServer::ProfilingInfo
static cl_long delta (const cl_ulong &t, const cl_ulong &t0)
 Get the delta time.

Additional Inherited Members

Protected Member Functions inherited from Aqua::CalcServer::ProfilingInfo
void newStep ()
 Let the profiler know that a new step of tools execution is about to start.

Detailed Description

Entity that perform the main work of the simulation.

In the Aqua::CalcServer::CalcServer a time subloop is performed where the SPH simulation is performed while no output files should be updated.

Note
Updating output files require to download data from the server, which due to the low bandwidth asigned is usually a bottleneck, hence letting the Aqua::CalcServer::CalcServer works without interrumptions is the best optimization technique.
Remarks
Some output files are managed internally by this class, like the log file, the energy file, pressure sensors file, or bounds file.

Member Enumeration Documentation

◆ cmd_queue

Enumerator
cmd_queue_current 
cmd_queue_new 
cmd_queue_mpi 

Constructor & Destructor Documentation

◆ CalcServer()

Aqua::CalcServer::CalcServer::CalcServer ( const Aqua::InputOutput::ProblemSetup & sim_data)

Constructor.

Parameters
sim_dataSimulation data read from XML files
Here is the call graph for this function:

◆ ~CalcServer()

Aqua::CalcServer::CalcServer::~CalcServer ( )

Destructor.

Here is the call graph for this function:

Member Function Documentation

◆ all_events()

std::vector< cl_event > Aqua::CalcServer::CalcServer::all_events ( ) const

Collect all the events stored on the variables

This includes the user events that shall be set by callbacks. Thus, this function is more powerful than finish() at the time to set a synchronization point. It is slower also.

Returns
The full list of events, collected from the variables

◆ base_path()

const std::string Aqua::CalcServer::CalcServer::base_path ( ) const
inline

Get the AQUAgpusph root path.

Returns
AQUAgpusph root path

◆ command_queue()

cl_command_queue Aqua::CalcServer::CalcServer::command_queue ( cmd_queue which = cmd_queue::cmd_queue_current)

Get a command queue

To allow the asynchronous "As-Fast-As-Possible" execution of commands they can be enqueued on different queues. The queues are always reseted when a new time step is executed.

Parameters
whichcmd_queue::cmd_queue_current to enqueue the command on the current command queue, cmd_queue::cmd_queue_new to raise a new one where commands can be executed in parallel, cmd_queue::cmd_queue_mpi to get the command queue designed to exchange info with other processes
Returns
The command queue @raise std::runtime_error if the command queue cannot be created
Here is the call graph for this function:

◆ context()

cl_context Aqua::CalcServer::CalcServer::context ( ) const
inline

Get the active context

Returns
OpenCL context

◆ debug_mode() [1/2]

bool Aqua::CalcServer::CalcServer::debug_mode ( ) const
inline

Report if any tools debug option is enabled.

See also
Aqua::InputOutput::ProblemSetup::sphSettings::debug_tools
Returns
true if any tools debug mode option is enabled, false otherwise

◆ debug_mode() [2/2]

bool Aqua::CalcServer::CalcServer::debug_mode ( debug_opts opt) const
inline

Report if the tools debug mode option is enabled.

Parameters
optThe options to check
See also
Aqua::InputOutput::ProblemSetup::sphSettings::debug_tools
Returns
true if the tools debug mode option is enabled, false otherwise

◆ definitions()

std::vector< std::string > Aqua::CalcServer::CalcServer::definitions ( ) const
inline

Get the definitions registered.

Returns
List of definitions.

◆ device()

cl_device_id Aqua::CalcServer::CalcServer::device ( ) const
inline

Get the device

Returns
OpenCL device

◆ device_addr_bits()

cl_uint Aqua::CalcServer::CalcServer::device_addr_bits ( ) const
inline

Get the device address bits.

Returns
The device address bits (either 32 or 64)

◆ device_compile_flags()

const char * Aqua::CalcServer::CalcServer::device_compile_flags ( ) const
inline

Get the device compilation flags.

Returns
The device compilation flags

◆ device_timer_offset()

cl_ulong Aqua::CalcServer::CalcServer::device_timer_offset ( ) const
inline

Get the offset between the device timer and the host one.

Returns
The time offset, in nanoseconds

◆ eventTool()

Tool * Aqua::CalcServer::CalcServer::eventTool ( cl_event event) const

Get the tool that emitted an event, if any.

Returns
The tool that created the event. Null if no tool is found

◆ eventVars()

std::tuple< std::vector< InputOutput::Variable * >, std::vector< InputOutput::Variable * > > Aqua::CalcServer::CalcServer::eventVars ( cl_event event) const

Get the variables associated to an event, if any.

Returns
The list of variables that depends on the event, both for writing and reading

◆ finish()

cl_int Aqua::CalcServer::CalcServer::finish ( ) const
inline

Call clFinish() on top of all known command queues

Returns
CL_SUCCESS if clFinish() is correctly called on all queues, an error code otherwise

◆ getUnsortedMem()

cl_event Aqua::CalcServer::CalcServer::getUnsortedMem ( const std::string var_name,
size_t offset,
size_t cb,
void * ptr )

Download a unsorted variable from the device.

Parameters
var_nameVariable to unsort and download.
offsetThe offset in bytes in the memory object to read from.
cbThe size in bytes of data being downloaded.
ptrThe host memory where the data should be copied
Returns
The data download event, NULL if errors are detected.
Note
The caller must wait for the events (clWaitForEvents) before accessing the downloaded data.
Remarks
The caller must call clReleaseEvent to destroy the event. Otherwise a memory leak can be expected.
Here is the call graph for this function:

◆ have_3d()

bool Aqua::CalcServer::CalcServer::have_3d ( ) const
inline

Get if 3 dimensions are considered.

See also
Aqua::InputOutput::ProblemSetup::dims()
Returns
true if a 3D simulation is considered, false if it is conversely a 2D simulation

◆ host_timer()

cl_ulong Aqua::CalcServer::CalcServer::host_timer ( )
inlinestatic

Get the host timer.

Returns
The host timer in nanoseconds

◆ marker() [1/2]

cl_event Aqua::CalcServer::CalcServer::marker ( ) const

Create a marker to be set as completed when all the enqued commnands on all the command queues are finished.

Returns
the master event
Here is the call graph for this function:

◆ marker() [2/2]

cl_event Aqua::CalcServer::CalcServer::marker ( cl_command_queue cmd,
std::vector< cl_event > events ) const

Wrapper over clEnqueueMarkerWithWaitList()

Note
2024/05/24 NVIDIA's platform clEnqueueMarkerWithWaitList() is broken. This method is circumventing it by a less performant method
Returns
The marker event
See also
https://registry.khronos.org/OpenCL/sdk/3.0/docs/man/html/clEnqueueMarkerWithWaitList.html
Here is the call graph for this function:

◆ platform()

cl_platform_id Aqua::CalcServer::CalcServer::platform ( ) const
inline

Get the platform

Returns
OpenCL platform

◆ raiseSIGINT()

void Aqua::CalcServer::CalcServer::raiseSIGINT ( )

Raise a SIGINT/SIGTERM signal.

This can be useful for instance to asynchronously interrupt the execution after detecting errors

Note
This function will never force the execution termination. If the signal has been already rised somewhere else, this function will just gently wait for the execution to be finished
Here is the call graph for this function:

◆ setKernelSizeArg() [1/2]

template<>
cl_int Aqua::CalcServer::CalcServer::setKernelSizeArg ( cl_kernel kernel,
cl_uint arg_index,
const size_t arg_value )
Here is the call graph for this function:

◆ setKernelSizeArg() [2/2]

template<typename T>
cl_int Aqua::CalcServer::CalcServer::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

Parameters
kernelOpenCL kernel object
arg_indexis the argument index
arg_valueis a pointer to data

◆ setup()

void Aqua::CalcServer::CalcServer::setup ( )

Setup some additional simulation data.

Even thought this work is associated with the constructor CalcServer(), when something may fail it is preferable to let it to a separated method that could report errors, allowing the program to deal with them.

Here is the call graph for this function:

◆ singleton()

CalcServer * Aqua::CalcServer::CalcServer::singleton ( )
static

Get –creating it the first time– the logger instance.

Just one logger can simultaneously exist

Returns
The logger
Here is the call graph for this function:

◆ tools()

std::vector< Tool * > Aqua::CalcServer::CalcServer::tools ( ) const
inline

Get the tools registered.

Returns
List of tools.

◆ update()

void Aqua::CalcServer::CalcServer::update ( InputOutput::TimeManager & t_manager)

Internal time loop.

Calculation server will be iterating while no output files should be updated (or even the simulation is finished).

Parameters
t_managerTime manager to let the calculation server when shall stop the internal loop.
Here is the call graph for this function:

◆ variables()

InputOutput::Variables * Aqua::CalcServer::CalcServer::variables ( )
inline

Get the variables manager

Returns
Variables manager

The documentation for this class was generated from the following files: