Halide 19.0.0
Halide compiler and libraries
|
#include <Callable.h>
Public Member Functions | |
Callable () | |
Construct a default Callable. | |
bool | defined () const |
Return true if the Callable is well-defined and usable, false if it is a default-constructed empty Callable. | |
template<typename... Args> | |
HALIDE_FUNCTION_ATTRS int | operator() (JITUserContext *context, Args &&...args) const |
template<typename... Args> | |
HALIDE_FUNCTION_ATTRS int | operator() (Args &&...args) const |
template<typename First , typename... Rest> | |
std::function< int(First, Rest...)> | make_std_function () const |
This allows us to construct a std::function<> that wraps the Callable. | |
int | call_argv_fast (size_t argc, const void *const *argv) const |
Unsafe low-overhead way of invoking the Callable. | |
Definition at line 82 of file Callable.h.
Halide::Callable::Callable | ( | ) |
bool Halide::Callable::defined | ( | ) | const |
|
inline |
Definition at line 314 of file Callable.h.
|
inline |
Definition at line 320 of file Callable.h.
|
inline |
This allows us to construct a std::function<> that wraps the Callable.
This is nice in that it is, well, just a std::function, but also in that since the argument-count-and-type checking are baked into the language, we can do the relevant checking only once – when we first create the std::function – and skip it on all actual calls to the function, making it slightly more efficient. It's also more type-forgiving, in that the usual C++ numeric coercion rules apply here.
The downside is that there isn't (currently) any way to automatically infer the static types reliably, since we may be using (e.g.) a Param<void>, where the type in question isn't available to the C++ compiler. This means that the coder must supply the correct type signature when calling this function – but the good news is that if you get it wrong, this function will fail when you call it. (In other words: it can't choose the right thing for you, but it can tell you when you do the wrong thing.)
TODO: it's possible that we could infer the correct signatures in some cases, and only fail for the ambiguous cases, but that would require a lot more template-fu here and elsewhere. I think this is good enough for now.
TODO: is it possible to annotate the result of a std::function<> with HALIDE_FUNCTION_ATTRS?
Definition at line 347 of file Callable.h.
References call_argv_fast().
int Halide::Callable::call_argv_fast | ( | size_t | argc, |
const void *const * | argv ) const |
Unsafe low-overhead way of invoking the Callable.
This function relies on the same calling convention as the argv-based functions generated for ahead-of-time compiled Halide pilelines.
Very rough specifications of the calling convention (but check the source code to be sure):
Referenced by make_std_function().