Front-end for parsing scalar expressions into GPU/CPU executors.
More...
#include <AMReX_Parser.H>
|
| | Parser (std::string const &func_body) |
| | Construct a parser by immediately parsing func_body.
|
| |
| | Parser ()=default |
| | Default-construct; call define() before compilation.
|
| |
| void | define (std::string const &func_body) |
| | Parse and own a new expression, replacing any previous state.
|
| |
| | operator bool () const |
| | True when an expression has been parsed successfully.
|
| |
| void | setConstant (std::string const &name, double c) |
| | Bind a named constant to c.
|
| |
| void | registerVariables (Vector< std::string > const &vars) |
| | Register the ordered list of variable names used by the expression.
|
| |
| void | registerUserFn1 (std::string const &name, ParserUserFn1 fh, ParserUserFn1 fd) |
| | Register a user-defined unary function available to expressions.
|
| |
| void | registerUserFn2 (std::string const &name, ParserUserFn2 fh, ParserUserFn2 fd) |
| | Register a user-defined binary function.
|
| |
| void | registerUserFn3 (std::string const &name, ParserUserFn3 fh, ParserUserFn3 fd) |
| | Register a user-defined ternary function.
|
| |
| void | registerUserFn4 (std::string const &name, ParserUserFn4 fh, ParserUserFn4 fd) |
| | Register a user-defined function with four arguments.
|
| |
| void | print () const |
| | Print a human-readable representation of the parser tree to stdout.
|
| |
| void | printExe () const |
| | Dump the compiled bytecode to stdout for debugging.
|
| |
| int | depth () const |
| | Return the maximum tree depth of the parsed expression.
|
| |
| int | maxStackSize () const |
| | Return the maximum stack usage recorded during compilation.
|
| |
| std::string | expr () const |
| | Return the sanitized expression string currently managed by the Parser.
|
| |
| std::set< std::string > | symbols () const |
| | Return the set of symbols (variables and functions) referenced by the expression.
|
| |
| std::map< std::string, int > const & | userFunctions () const |
| | Access the map of registered user-defined functions.
|
| |
| template<int N> |
| ParserExecutor< N > | compile () const |
| | Compile the current expression into a host/device executor.
|
| |
| template<int N> |
| ParserExecutor< N > | compileHost () const |
| | Compile the current expression into a host-only executor.
|
| |
Front-end for parsing scalar expressions into GPU/CPU executors.
A Parser instance owns the expression string, parser state, and registered variables. After calling define(), registerVariables(), and (optionally) registerUserFn*, the expression can be compiled into a ParserExecutor that evaluates it efficiently on host or device.
Different Parser objects may be constructed or defined concurrently from multiple host threads. For parallel evaluation, prefer sharing the compiled ParserExecutor across threads instead of constructing one Parser per thread.
◆ Parser() [1/2]
| amrex::Parser::Parser |
( |
std::string const & |
func_body | ) |
|
Construct a parser by immediately parsing func_body.
- Parameters
-
| func_body | Expression text; pass an empty string to defer parsing. |
◆ Parser() [2/2]
| amrex::Parser::Parser |
( |
| ) |
|
|
default |
Default-construct; call define() before compilation.
◆ compile()
Compile the current expression into a host/device executor.
- Template Parameters
-
| N | Number of registered variables. |
- Returns
- ParserExecutor callable on both host and GPU (if available).
◆ compileHost()
Compile the current expression into a host-only executor.
- Template Parameters
-
| N | Number of registered variables. |
- Returns
- ParserExecutor that executes only on the host.
◆ define()
| void amrex::Parser::define |
( |
std::string const & |
func_body | ) |
|
Parse and own a new expression, replacing any previous state.
- Parameters
-
| func_body | Expression text to parse. |
◆ depth()
| int amrex::Parser::depth |
( |
| ) |
const |
Return the maximum tree depth of the parsed expression.
- Returns
- Depth measured in parse-tree levels (0 if undefined).
◆ expr()
| std::string amrex::Parser::expr |
( |
| ) |
const |
Return the sanitized expression string currently managed by the Parser.
- Returns
- Copy of the parsed expression, or an empty string if undefined.
◆ maxStackSize()
| int amrex::Parser::maxStackSize |
( |
| ) |
const |
Return the maximum stack usage recorded during compilation.
- Returns
- Stack depth in parser instructions (0 if undefined).
◆ operator bool()
| amrex::Parser::operator bool |
( |
| ) |
const |
|
explicit |
True when an expression has been parsed successfully.
◆ print()
| void amrex::Parser::print |
( |
| ) |
const |
Print a human-readable representation of the parser tree to stdout.
◆ printExe()
| void amrex::Parser::printExe |
( |
| ) |
const |
Dump the compiled bytecode to stdout for debugging.
◆ registerUserFn1()
| void amrex::Parser::registerUserFn1 |
( |
std::string const & |
name, |
|
|
ParserUserFn1 |
fh, |
|
|
ParserUserFn1 |
fd |
|
) |
| |
Register a user-defined unary function available to expressions.
- Parameters
-
| name | Function identifier used inside expressions. |
| fh | Host function pointer (double(double)). |
| fd | Device function pointer (double(double)); may be nullptr on CPU-only builds. |
◆ registerUserFn2()
| void amrex::Parser::registerUserFn2 |
( |
std::string const & |
name, |
|
|
ParserUserFn2 |
fh, |
|
|
ParserUserFn2 |
fd |
|
) |
| |
Register a user-defined binary function.
- Parameters
-
| name | Function identifier. |
| fh | Host implementation taking two doubles. |
| fd | Device implementation taking two doubles; may be nullptr on CPU builds. |
◆ registerUserFn3()
| void amrex::Parser::registerUserFn3 |
( |
std::string const & |
name, |
|
|
ParserUserFn3 |
fh, |
|
|
ParserUserFn3 |
fd |
|
) |
| |
Register a user-defined ternary function.
- Parameters
-
| name | Function identifier. |
| fh | Host implementation taking three doubles. |
| fd | Device implementation taking three doubles; may be nullptr on CPU builds. |
◆ registerUserFn4()
| void amrex::Parser::registerUserFn4 |
( |
std::string const & |
name, |
|
|
ParserUserFn4 |
fh, |
|
|
ParserUserFn4 |
fd |
|
) |
| |
Register a user-defined function with four arguments.
- Parameters
-
| name | Function identifier. |
| fh | Host implementation taking four doubles. |
| fd | Device implementation taking four doubles; may be nullptr on CPU builds. |
◆ registerVariables()
| void amrex::Parser::registerVariables |
( |
Vector< std::string > const & |
vars | ) |
|
Register the ordered list of variable names used by the expression.
The ordering determines how arguments are passed to ParserExecutor::operator().
- Parameters
-
| vars | Variable names supplied in parser argument order. |
◆ setConstant()
| void amrex::Parser::setConstant |
( |
std::string const & |
name, |
|
|
double |
c |
|
) |
| |
Bind a named constant to c.
- Parameters
-
| name | Identifier referenced inside the expression. |
| c | Constant value substituted when compiling. |
◆ symbols()
| std::set< std::string > amrex::Parser::symbols |
( |
| ) |
const |
Return the set of symbols (variables and functions) referenced by the expression.
- Returns
- Alphabetically sorted symbol names.
◆ userFunctions()
| std::map< std::string, int > const & amrex::Parser::userFunctions |
( |
| ) |
const |
Access the map of registered user-defined functions.
- Returns
- Map from function name to argument count.
The documentation for this class was generated from the following files: