Halide 22.0.0 Halide compiler and libraries

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Halide::Callable Class Reference

`#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.

## Detailed Description

Definition at line 82 of file Callable.h.

## Constructor & Destructor Documentation

## ◆ Callable()

Halide::Callable::Callable | ( |  | ) |

Construct a default Callable.

This is not usable (trying to call it will fail). The defined() method will return false.

## Member Function Documentation

## ◆ defined()

bool Halide::Callable::defined | ( |  | ) | const

Return true if the Callable is well-defined and usable, false if it is a default-constructed empty Callable.

## ◆ operator()() [1/2]

template<typename... Args>

HALIDE_FUNCTION_ATTRS int Halide::Callable::operator() | ( | JITUserContext * | context,
|  | Args &&... | args
| ) |  | const
| inline

Definition at line 314 of file Callable.h.

## ◆ operator()() [2/2]

template<typename... Args>

HALIDE_FUNCTION_ATTRS int Halide::Callable::operator() | ( | Args &&... | args | ) | const
| inline

Definition at line 320 of file Callable.h.

## ◆ make_std_function()

template<typename First , typename... Rest>

std::function< int(First, Rest...)> Halide::Callable::make_std_function | ( |  | ) | const
| 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(), and Halide::cast().

## ◆ 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):

- 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*.

Referenced by make_std_function().

The documentation for this class was generated from the following file:

- src/Callable.h