Callable#
-
class Callable#
Public Functions
-
Callable()#
Construct a default Callable.
This is not usable (trying to call it will fail). The defined() method will return false.
-
bool defined() const#
Return true if the Callable is well-defined and usable, false if it is a default-constructed empty Callable.
-
template<typename First, typename ...Rest>
inline std::function<int(First, Rest...)> make_std_function() const# 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?
-
int 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):
Arguments are passed in the same order as they appear in the C function argument list.
The first entry in argv must always be a JITUserContext*. Please, note that this means that argv[0] actually contains JITUserContext**.
All scalar arguments are passed by pointer, not by value, regardless of size.
All buffer arguments (input or output) are passed as halide_buffer_t*.
-
Callable()#