1 #ifndef AMREX_PARSER_H_
2 #define AMREX_PARSER_H_
20 template <
int M=N, std::enable_if_t<M==0,
int> = 0>
28 template <
typename... Ts>
31 operator() (Ts... var)
const noexcept
38 template <
typename... Ts>
41 operator() (Ts... var)
const noexcept
56 explicit operator bool ()
const {
70 Parser (std::string
const& func_body);
72 void define (std::string
const& func_body);
74 explicit operator bool ()
const;
76 void setConstant (std::string
const& name,
double c);
83 [[nodiscard]]
int depth ()
const;
86 [[nodiscard]] std::string
expr ()
const;
88 [[nodiscard]] std::set<std::string>
symbols ()
const;
129 if (!(
m_data->m_host_executor)) {
131 m_data->m_exe_size =
static_cast<int>
140 if (stack_size != 0) {
141 amrex::Abort(
"amrex::Parser: something went wrong with parser stack! "
142 + std::to_string(stack_size));
146 if (
m_data->m_host_executor ==
nullptr) {
148 m_data->m_use_arena =
false;
154 }
catch (
const std::runtime_error& e) {
155 throw std::runtime_error(std::string(e.what()) +
" in Parser expression \""
156 +
m_data->m_expression +
"\"");
174 auto exe = compileHost<N>();
184 exe.m_device_executor =
m_data->m_device_executor;
#define AMREX_ASSERT(EX)
Definition: AMReX_BLassert.H:38
#define AMREX_FORCE_INLINE
Definition: AMReX_Extension.H:119
#define AMREX_IF_ON_DEVICE(CODE)
Definition: AMReX_GpuQualifiers.H:56
#define AMREX_IF_ON_HOST(CODE)
Definition: AMReX_GpuQualifiers.H:58
#define AMREX_GPU_HOST_DEVICE
Definition: AMReX_GpuQualifiers.H:20
#define AMREX_PARSER_STACK_SIZE
Definition: AMReX_Parser_Exe.H:12
virtual void * alloc(std::size_t sz)=0
Definition: AMReX_Parser.H:68
std::set< std::string > symbols() const
Definition: AMReX_Parser.cpp:121
void print() const
Definition: AMReX_Parser.cpp:83
std::shared_ptr< Data > m_data
Definition: AMReX_Parser.H:118
int maxStackSize() const
Definition: AMReX_Parser.cpp:101
ParserExecutor< N > compileHost() const
This compiles for CPU only.
Definition: AMReX_Parser.H:124
Vector< std::string > m_vars
Definition: AMReX_Parser.H:119
std::string expr() const
Definition: AMReX_Parser.cpp:111
void define(std::string const &func_body)
Definition: AMReX_Parser.cpp:18
ParserExecutor< N > compile() const
This compiles for both GPU and CPU.
Definition: AMReX_Parser.H:172
void printExe() const
Definition: AMReX_Parser.cpp:131
void setConstant(std::string const &name, double c)
Definition: AMReX_Parser.cpp:63
void registerVariables(Vector< std::string > const &vars)
Definition: AMReX_Parser.cpp:71
int depth() const
Definition: AMReX_Parser.cpp:91
void streamSynchronize() noexcept
Definition: AMReX_GpuDevice.H:237
void htod_memcpy_async(void *p_d, const void *p_h, const std::size_t sz) noexcept
Definition: AMReX_GpuDevice.H:251
Definition: AMReX_Amr.cpp:49
Arena * The_Pinned_Arena()
Definition: AMReX_Arena.cpp:649
std::size_t parser_exe_size(struct amrex_parser *parser, int &max_stack_size, int &stack_size)
Definition: AMReX_Parser_Exe.H:507
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double parser_exe_eval(const char *p, double const *x)
Definition: AMReX_Parser_Exe.H:222
Arena * The_Arena()
Definition: AMReX_Arena.cpp:609
Vector< char const * > parser_compile(struct amrex_parser *parser, char *p)
Definition: AMReX_Parser_Exe.H:521
Definition: AMReX_Array.H:34
Definition: AMReX_Parser.H:19
char * m_host_executor
Definition: AMReX_Parser.H:61
char * m_device_executor
Definition: AMReX_Parser.H:63
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE double operator()() const noexcept
Definition: AMReX_Parser.H:22
Definition: AMReX_Parser.H:98
~Data()
Definition: AMReX_Parser.cpp:41
int m_max_stack_size
Definition: AMReX_Parser.H:107
bool m_use_arena
Definition: AMReX_Parser.H:102
int m_exe_size
Definition: AMReX_Parser.H:108
Data & operator=(Data const &)=delete
int m_nvars
Definition: AMReX_Parser.H:101
struct amrex_parser * m_parser
Definition: AMReX_Parser.H:100
std::string m_expression
Definition: AMReX_Parser.H:99
Data(Data const &)=delete
Vector< char const * > m_locals
Definition: AMReX_Parser.H:109
char * m_host_executor
Definition: AMReX_Parser.H:103
char * m_device_executor
Definition: AMReX_Parser.H:105
Definition: AMReX_TypeTraits.H:130
Definition: AMReX_Parser_Y.H:257