1 #ifndef AMREX_IPARSER_H_
2 #define AMREX_IPARSER_H_
19 template <
int M=N, std::enable_if_t<M==0,
int> = 0>
27 template <
typename... Ts>
29 std::enable_if_t<
sizeof...(Ts) == N && std::conjunction_v<std::is_integral<Ts>...>,
31 operator() (Ts... var)
const noexcept
46 explicit operator bool ()
const {
60 IParser (std::string
const& func_body);
62 void define (std::string
const& func_body);
64 explicit operator bool ()
const;
66 void setConstant (std::string
const& name,
long long c);
72 [[nodiscard]]
int depth ()
const;
75 [[nodiscard]] std::string
expr ()
const;
77 [[nodiscard]] std::set<std::string>
symbols ()
const;
116 if (!(
m_data->m_host_executor)) {
118 m_data->m_exe_size =
static_cast<int>
123 amrex::Abort(
"amrex::IParser: AMREX_IPARSER_STACK_SIZE, "
127 if (stack_size != 0) {
128 amrex::Abort(
"amrex::IParser: something went wrong with iparser stack! "
129 + std::to_string(stack_size));
133 if (
m_data->m_host_executor ==
nullptr) {
135 m_data->m_use_arena =
false;
140 }
catch (
const std::runtime_error& e) {
141 throw std::runtime_error(std::string(e.what()) +
" in IParser expression \""
142 +
m_data->m_expression +
"\"");
160 auto exe = compileHost<N>();
170 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_IPARSER_STACK_SIZE
Definition: AMReX_IParser_Exe.H:12
virtual void * alloc(std::size_t sz)=0
Definition: AMReX_IParser.H:58
void print() const
Definition: AMReX_IParser.cpp:82
std::set< std::string > symbols() const
Definition: AMReX_IParser.cpp:120
void setConstant(std::string const &name, long long c)
Definition: AMReX_IParser.cpp:63
IParserExecutor< N > compileHost() const
This compiles for CPU only.
Definition: AMReX_IParser.H:111
std::string expr() const
Definition: AMReX_IParser.cpp:110
IParserExecutor< N > compile() const
This compiles for both GPU and CPU.
Definition: AMReX_IParser.H:158
void registerVariables(Vector< std::string > const &vars)
Definition: AMReX_IParser.cpp:71
int depth() const
Definition: AMReX_IParser.cpp:90
void define(std::string const &func_body)
Definition: AMReX_IParser.cpp:18
std::shared_ptr< Data > m_data
Definition: AMReX_IParser.H:106
int maxStackSize() const
Definition: AMReX_IParser.cpp:100
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
void iparser_compile(struct amrex_iparser *parser, char *p)
Definition: AMReX_IParser_Exe.H:515
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE long long iparser_exe_eval(const char *p, long long const *x)
Definition: AMReX_IParser_Exe.H:231
Arena * The_Pinned_Arena()
Definition: AMReX_Arena.cpp:649
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
Arena * The_Arena()
Definition: AMReX_Arena.cpp:609
std::size_t iparser_exe_size(struct amrex_iparser *parser, int &max_stack_size, int &stack_size)
Definition: AMReX_IParser_Exe.H:502
Definition: AMReX_Array.H:34
Definition: AMReX_IParser.H:18
char * m_device_executor
Definition: AMReX_IParser.H:53
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE long long operator()() const noexcept
Definition: AMReX_IParser.H:21
char * m_host_executor
Definition: AMReX_IParser.H:51
Definition: AMReX_IParser.H:87
int m_exe_size
Definition: AMReX_IParser.H:97
~Data()
Definition: AMReX_IParser.cpp:41
int m_max_stack_size
Definition: AMReX_IParser.H:96
int m_nvars
Definition: AMReX_IParser.H:90
char * m_device_executor
Definition: AMReX_IParser.H:94
std::string m_expression
Definition: AMReX_IParser.H:88
char * m_host_executor
Definition: AMReX_IParser.H:92
Data(Data const &)=delete
struct amrex_iparser * m_iparser
Definition: AMReX_IParser.H:89
bool m_use_arena
Definition: AMReX_IParser.H:91
Data & operator=(Data const &)=delete
Definition: AMReX_IParser_Y.H:153