#ifndef HALIDE_HALIDERUNTIME_H
#define HALIDE_HALIDERUNTIME_H
#ifndef COMPILING_HALIDE_RUNTIME
#ifdef __cplusplus
#include <cstddef>
#include <cstdint>
#include <cstring>
#else
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#endif
#else
#include "runtime_internal.h"
#endif
#ifdef __cplusplus
template<typename T>
struct halide_handle_traits;
#endif
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _MSC_VER
#define HALIDE_ALWAYS_INLINE __forceinline
#define HALIDE_NEVER_INLINE __declspec(noinline)
#else
#define HALIDE_ALWAYS_INLINE inline __attribute__((always_inline))
#define HALIDE_NEVER_INLINE __attribute__((noinline))
#endif
#ifndef HALIDE_MUST_USE_RESULT
#ifdef __has_attribute
#if __has_attribute(nodiscard)
#define HALIDE_MUST_USE_RESULT [[nodiscard]]
#elif __has_attribute(warn_unused_result)
#define HALIDE_MUST_USE_RESULT __attribute__((warn_unused_result))
#else
#define HALIDE_MUST_USE_RESULT
#endif
#else
#define HALIDE_MUST_USE_RESULT
#endif
#endif
struct halide_buffer_t;
extern void halide_print(void *user_context, const char *);
extern void halide_default_print(void *user_context, const char *);
typedef void (*halide_print_t)(void *, const char *);
extern halide_print_t halide_set_custom_print(halide_print_t print);
extern void halide_error(void *user_context, const char *);
extern void halide_default_error(void *user_context, const char *);
typedef void (*halide_error_handler_t)(void *, const char *);
extern halide_error_handler_t halide_set_error_handler(halide_error_handler_t handler);
struct halide_mutex {
uintptr_t _private[1];
};
struct halide_cond {
uintptr_t _private[1];
};
extern void halide_mutex_lock(struct halide_mutex *mutex);
extern void halide_mutex_unlock(struct halide_mutex *mutex);
extern void halide_cond_signal(struct halide_cond *cond);
extern void halide_cond_broadcast(struct halide_cond *cond);
extern void halide_cond_wait(struct halide_cond *cond, struct halide_mutex *mutex);
struct halide_mutex_array;
extern struct halide_mutex_array *halide_mutex_array_create(int sz);
extern void halide_mutex_array_destroy(void *user_context, void *array);
extern int halide_mutex_array_lock(struct halide_mutex_array *array, int entry);
extern int halide_mutex_array_unlock(struct halide_mutex_array *array, int entry);
typedef int (*halide_task_t)(void *user_context, int task_number, uint8_t *closure);
extern int halide_do_par_for(void *user_context,
halide_task_t task,
int min, int size, uint8_t *closure);
extern void halide_shutdown_thread_pool();
typedef int (*halide_do_par_for_t)(void *, halide_task_t, int, int, uint8_t *);
extern halide_do_par_for_t halide_set_custom_do_par_for(halide_do_par_for_t do_par_for);
struct halide_semaphore_t {
uint64_t _private[2];
};
struct halide_semaphore_acquire_t {
struct halide_semaphore_t *semaphore;
int count;
};
extern int halide_semaphore_init(struct halide_semaphore_t *, int n);
extern int halide_semaphore_release(struct halide_semaphore_t *, int n);
extern bool halide_semaphore_try_acquire(struct halide_semaphore_t *, int n);
typedef int (*halide_semaphore_init_t)(struct halide_semaphore_t *, int);
typedef int (*halide_semaphore_release_t)(struct halide_semaphore_t *, int);
typedef bool (*halide_semaphore_try_acquire_t)(struct halide_semaphore_t *, int);
typedef int (*halide_loop_task_t)(void *user_context, int min, int extent,
uint8_t *closure, void *task_parent);
struct halide_parallel_task_t {
halide_loop_task_t fn;
uint8_t *closure;
const char *name;
struct halide_semaphore_acquire_t *semaphores;
int num_semaphores;
int min, extent;
int min_threads;
bool serial;
};
extern int halide_do_parallel_tasks(void *user_context, int num_tasks,
struct halide_parallel_task_t *tasks,
void *task_parent);
typedef int (*halide_do_task_t)(void *, halide_task_t, int, uint8_t *);
extern halide_do_task_t halide_set_custom_do_task(halide_do_task_t do_task);
extern int halide_do_task(void *user_context, halide_task_t f, int idx,
uint8_t *closure);
typedef int (*halide_do_loop_task_t)(void *, halide_loop_task_t, int, int, uint8_t *, void *);
extern halide_do_loop_task_t halide_set_custom_do_loop_task(halide_do_loop_task_t do_task);
extern int halide_do_loop_task(void *user_context, halide_loop_task_t f, int min, int extent,
uint8_t *closure, void *task_parent);
typedef int (*halide_do_parallel_tasks_t)(void *, int, struct halide_parallel_task_t *,
void *task_parent);
extern void halide_set_custom_parallel_runtime(
halide_do_par_for_t,
halide_do_task_t,
halide_do_loop_task_t,
halide_do_parallel_tasks_t,
halide_semaphore_init_t,
halide_semaphore_try_acquire_t,
halide_semaphore_release_t);
extern int halide_default_do_par_for(void *user_context,
halide_task_t task,
int min, int size, uint8_t *closure);
extern int halide_default_do_parallel_tasks(void *user_context,
int num_tasks,
struct halide_parallel_task_t *tasks,
void *task_parent);
extern int halide_default_do_task(void *user_context, halide_task_t f, int idx,
uint8_t *closure);
extern int halide_default_do_loop_task(void *user_context, halide_loop_task_t f,
int min, int extent,
uint8_t *closure, void *task_parent);
extern int halide_default_semaphore_init(struct halide_semaphore_t *, int n);
extern int halide_default_semaphore_release(struct halide_semaphore_t *, int n);
extern bool halide_default_semaphore_try_acquire(struct halide_semaphore_t *, int n);
struct halide_thread;
extern struct halide_thread *halide_spawn_thread(void (*f)(void *), void *closure);
extern void halide_join_thread(struct halide_thread *);
extern int halide_set_num_threads(int n);
extern void *halide_malloc(void *user_context, size_t x);
extern void halide_free(void *user_context, void *ptr);
extern void *halide_default_malloc(void *user_context, size_t x);
extern void halide_default_free(void *user_context, void *ptr);
typedef void *(*halide_malloc_t)(void *, size_t);
typedef void (*halide_free_t)(void *, void *);
extern halide_malloc_t halide_set_custom_malloc(halide_malloc_t user_malloc);
extern halide_free_t halide_set_custom_free(halide_free_t user_free);
extern void *halide_get_symbol(const char *name);
extern void *halide_load_library(const char *name);
extern void *halide_get_library_symbol(void *lib, const char *name);
extern void *halide_default_get_symbol(const char *name);
extern void *halide_default_load_library(const char *name);
extern void *halide_default_get_library_symbol(void *lib, const char *name);
typedef void *(*halide_get_symbol_t)(const char *name);
typedef void *(*halide_load_library_t)(const char *name);
typedef void *(*halide_get_library_symbol_t)(void *lib, const char *name);
extern halide_get_symbol_t halide_set_custom_get_symbol(halide_get_symbol_t user_get_symbol);
extern halide_load_library_t halide_set_custom_load_library(halide_load_library_t user_load_library);
extern halide_get_library_symbol_t halide_set_custom_get_library_symbol(halide_get_library_symbol_t user_get_library_symbol);
extern int32_t halide_debug_to_file(void *user_context, const char *filename,
int32_t type_code,
struct halide_buffer_t *buf);
typedef enum halide_type_code_t
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
: uint8_t
#endif
{
halide_type_int = 0, halide_type_uint = 1, halide_type_float = 2, halide_type_handle = 3, halide_type_bfloat = 4, } halide_type_code_t;
#ifndef HALIDE_ATTRIBUTE_ALIGN
#ifdef _MSC_VER
#define HALIDE_ATTRIBUTE_ALIGN(x) __declspec(align(x))
#else
#define HALIDE_ATTRIBUTE_ALIGN(x) __attribute__((aligned(x)))
#endif
#endif
struct halide_type_t {
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
HALIDE_ATTRIBUTE_ALIGN(1)
halide_type_code_t code; #else
HALIDE_ATTRIBUTE_ALIGN(1)
uint8_t code; #endif
HALIDE_ATTRIBUTE_ALIGN(1)
uint8_t bits;
HALIDE_ATTRIBUTE_ALIGN(2)
uint16_t lanes;
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
HALIDE_ALWAYS_INLINE constexpr halide_type_t(halide_type_code_t code, uint8_t bits, uint16_t lanes = 1)
: code(code), bits(bits), lanes(lanes) {
}
HALIDE_ALWAYS_INLINE constexpr halide_type_t()
: code((halide_type_code_t)0), bits(0), lanes(0) {
}
HALIDE_ALWAYS_INLINE constexpr halide_type_t with_lanes(uint16_t new_lanes) const {
return halide_type_t((halide_type_code_t)code, bits, new_lanes);
}
HALIDE_ALWAYS_INLINE constexpr halide_type_t element_of() const {
return with_lanes(1);
}
HALIDE_ALWAYS_INLINE constexpr bool operator==(const halide_type_t &other) const {
return as_u32() == other.as_u32();
}
HALIDE_ALWAYS_INLINE constexpr bool operator!=(const halide_type_t &other) const {
return !(*this == other);
}
HALIDE_ALWAYS_INLINE constexpr bool operator<(const halide_type_t &other) const {
return as_u32() < other.as_u32();
}
HALIDE_ALWAYS_INLINE constexpr int bytes() const {
return (bits + 7) / 8;
}
HALIDE_ALWAYS_INLINE constexpr uint32_t as_u32() const {
return static_cast<uint8_t>(code) |
(static_cast<uint16_t>(bits) << 8) |
(static_cast<uint32_t>(lanes) << 16);
}
#endif
};
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
static_assert(sizeof(halide_type_t) == sizeof(uint32_t), "size mismatch in halide_type_t");
#endif
enum halide_trace_event_code_t { halide_trace_load = 0,
halide_trace_store = 1,
halide_trace_begin_realization = 2,
halide_trace_end_realization = 3,
halide_trace_produce = 4,
halide_trace_end_produce = 5,
halide_trace_consume = 6,
halide_trace_end_consume = 7,
halide_trace_begin_pipeline = 8,
halide_trace_end_pipeline = 9,
halide_trace_tag = 10 };
struct halide_trace_event_t {
const char *func;
void *value;
int32_t *coordinates;
const char *trace_tag;
struct halide_type_t type;
enum halide_trace_event_code_t event;
int32_t parent_id;
int32_t value_index;
int32_t dimensions;
};
extern int32_t halide_trace(void *user_context, const struct halide_trace_event_t *event);
extern int32_t halide_default_trace(void *user_context, const struct halide_trace_event_t *event);
typedef int32_t (*halide_trace_t)(void *user_context, const struct halide_trace_event_t *);
extern halide_trace_t halide_set_custom_trace(halide_trace_t trace);
struct halide_trace_packet_t {
uint32_t size;
int32_t id;
struct halide_type_t type;
enum halide_trace_event_code_t event;
int32_t parent_id;
int32_t value_index;
int32_t dimensions;
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
HALIDE_ALWAYS_INLINE const int *coordinates() const {
return (const int *)(this + 1);
}
HALIDE_ALWAYS_INLINE int *coordinates() {
return (int *)(this + 1);
}
HALIDE_ALWAYS_INLINE const void *value() const {
return (const void *)(coordinates() + dimensions);
}
HALIDE_ALWAYS_INLINE void *value() {
return (void *)(coordinates() + dimensions);
}
HALIDE_ALWAYS_INLINE const char *func() const {
return (const char *)value() + type.lanes * type.bytes();
}
HALIDE_ALWAYS_INLINE char *func() {
return (char *)value() + type.lanes * type.bytes();
}
HALIDE_ALWAYS_INLINE const char *trace_tag() const {
const char *f = func();
while (*f++) {
}
return f;
}
HALIDE_ALWAYS_INLINE char *trace_tag() {
char *f = func();
while (*f++) {
}
return f;
}
#endif
};
extern void halide_set_trace_file(int fd);
extern int halide_get_trace_file(void *user_context);
extern int halide_shutdown_trace();
struct halide_device_interface_impl_t;
struct halide_device_interface_t {
int (*device_malloc)(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
int (*device_free)(void *user_context, struct halide_buffer_t *buf);
int (*device_sync)(void *user_context, struct halide_buffer_t *buf);
void (*device_release)(void *user_context,
const struct halide_device_interface_t *device_interface);
int (*copy_to_host)(void *user_context, struct halide_buffer_t *buf);
int (*copy_to_device)(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
int (*device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
int (*device_and_host_free)(void *user_context, struct halide_buffer_t *buf);
int (*buffer_copy)(void *user_context, struct halide_buffer_t *src,
const struct halide_device_interface_t *dst_device_interface, struct halide_buffer_t *dst);
int (*device_crop)(void *user_context, const struct halide_buffer_t *src,
struct halide_buffer_t *dst);
int (*device_slice)(void *user_context, const struct halide_buffer_t *src,
int slice_dim, int slice_pos, struct halide_buffer_t *dst);
int (*device_release_crop)(void *user_context, struct halide_buffer_t *buf);
int (*wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle,
const struct halide_device_interface_t *device_interface);
int (*detach_native)(void *user_context, struct halide_buffer_t *buf);
int (*compute_capability)(void *user_context, int *major, int *minor);
const struct halide_device_interface_impl_t *impl;
};
extern void halide_device_release(void *user_context,
const struct halide_device_interface_t *device_interface);
extern int halide_copy_to_host(void *user_context, struct halide_buffer_t *buf);
extern int halide_copy_to_device(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
extern int halide_buffer_copy(void *user_context, struct halide_buffer_t *src,
const struct halide_device_interface_t *dst_device_interface,
struct halide_buffer_t *dst);
extern int halide_device_crop(void *user_context,
const struct halide_buffer_t *src,
struct halide_buffer_t *dst);
extern int halide_device_slice(void *user_context,
const struct halide_buffer_t *src,
int slice_dim, int slice_pos,
struct halide_buffer_t *dst);
extern int halide_device_release_crop(void *user_context,
struct halide_buffer_t *buf);
extern int halide_device_sync(void *user_context, struct halide_buffer_t *buf);
extern int halide_device_malloc(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
extern int halide_device_free(void *user_context, struct halide_buffer_t *buf);
extern int halide_device_wrap_native(void *user_context,
struct halide_buffer_t *buf,
uint64_t handle,
const struct halide_device_interface_t *device_interface);
extern int halide_device_detach_native(void *user_context, struct halide_buffer_t *buf);
extern void halide_set_gpu_device(int n);
extern int halide_get_gpu_device(void *user_context);
extern void halide_memoization_cache_set_size(int64_t size);
extern int halide_memoization_cache_lookup(void *user_context, const uint8_t *cache_key, int32_t size,
struct halide_buffer_t *realized_bounds,
int32_t tuple_count, struct halide_buffer_t **tuple_buffers);
extern int halide_memoization_cache_store(void *user_context, const uint8_t *cache_key, int32_t size,
struct halide_buffer_t *realized_bounds,
int32_t tuple_count,
struct halide_buffer_t **tuple_buffers,
bool has_eviction_key, uint64_t eviction_key);
extern void halide_memoization_cache_evict(void *user_context, uint64_t eviction_key);
extern void halide_memoization_cache_release(void *user_context, void *host);
extern void halide_memoization_cache_cleanup();
extern int halide_msan_check_memory_is_initialized(void *user_context, const void *ptr, uint64_t len, const char *name);
extern int halide_msan_check_buffer_is_initialized(void *user_context, struct halide_buffer_t *buffer, const char *buf_name);
extern int halide_msan_annotate_memory_is_initialized(void *user_context, const void *ptr, uint64_t len);
extern int halide_msan_annotate_buffer_is_initialized(void *user_context, struct halide_buffer_t *buffer);
extern void halide_msan_annotate_buffer_is_initialized_as_destructor(void *user_context, void *buffer);
enum halide_error_code_t {
halide_error_code_success = 0,
halide_error_code_generic_error = -1,
halide_error_code_explicit_bounds_too_small = -2,
halide_error_code_bad_type = -3,
halide_error_code_access_out_of_bounds = -4,
halide_error_code_buffer_allocation_too_large = -5,
halide_error_code_buffer_extents_too_large = -6,
halide_error_code_constraints_make_required_region_smaller = -7,
halide_error_code_constraint_violated = -8,
halide_error_code_param_too_small = -9,
halide_error_code_param_too_large = -10,
halide_error_code_out_of_memory = -11,
halide_error_code_buffer_argument_is_null = -12,
halide_error_code_debug_to_file_failed = -13,
halide_error_code_copy_to_host_failed = -14,
halide_error_code_copy_to_device_failed = -15,
halide_error_code_device_malloc_failed = -16,
halide_error_code_device_sync_failed = -17,
halide_error_code_device_free_failed = -18,
halide_error_code_no_device_interface = -19,
halide_error_code_matlab_init_failed = -20,
halide_error_code_matlab_bad_param_type = -21,
halide_error_code_internal_error = -22,
halide_error_code_device_run_failed = -23,
halide_error_code_unaligned_host_ptr = -24,
halide_error_code_bad_fold = -25,
halide_error_code_fold_factor_too_small = -26,
halide_error_code_requirement_failed = -27,
halide_error_code_buffer_extents_negative = -28,
halide_error_code_unused_29 = -29,
halide_error_code_unused_30 = -30,
halide_error_code_specialize_fail = -31,
halide_error_code_device_wrap_native_failed = -32,
halide_error_code_device_detach_native_failed = -33,
halide_error_code_host_is_null = -34,
halide_error_code_bad_extern_fold = -35,
halide_error_code_device_interface_no_device = -36,
halide_error_code_host_and_device_dirty = -37,
halide_error_code_buffer_is_null = -38,
halide_error_code_device_buffer_copy_failed = -39,
halide_error_code_device_crop_unsupported = -40,
halide_error_code_device_crop_failed = -41,
halide_error_code_incompatible_device_interface = -42,
halide_error_code_bad_dimensions = -43,
halide_error_code_device_dirty_with_no_device_support = -44,
halide_error_code_storage_bound_too_small = -45,
};
extern int halide_error_bounds_inference_call_failed(void *user_context, const char *extern_stage_name, int result);
extern int halide_error_extern_stage_failed(void *user_context, const char *extern_stage_name, int result);
extern int halide_error_explicit_bounds_too_small(void *user_context, const char *func_name, const char *var_name,
int min_bound, int max_bound, int min_required, int max_required);
extern int halide_error_bad_type(void *user_context, const char *func_name,
uint32_t type_given, uint32_t correct_type); extern int halide_error_bad_dimensions(void *user_context, const char *func_name,
int32_t dimensions_given, int32_t correct_dimensions);
extern int halide_error_access_out_of_bounds(void *user_context, const char *func_name,
int dimension, int min_touched, int max_touched,
int min_valid, int max_valid);
extern int halide_error_buffer_allocation_too_large(void *user_context, const char *buffer_name,
uint64_t allocation_size, uint64_t max_size);
extern int halide_error_buffer_extents_negative(void *user_context, const char *buffer_name, int dimension, int extent);
extern int halide_error_buffer_extents_too_large(void *user_context, const char *buffer_name,
int64_t actual_size, int64_t max_size);
extern int halide_error_constraints_make_required_region_smaller(void *user_context, const char *buffer_name,
int dimension,
int constrained_min, int constrained_extent,
int required_min, int required_extent);
extern int halide_error_constraint_violated(void *user_context, const char *var, int val,
const char *constrained_var, int constrained_val);
extern int halide_error_param_too_small_i64(void *user_context, const char *param_name,
int64_t val, int64_t min_val);
extern int halide_error_param_too_small_u64(void *user_context, const char *param_name,
uint64_t val, uint64_t min_val);
extern int halide_error_param_too_small_f64(void *user_context, const char *param_name,
double val, double min_val);
extern int halide_error_param_too_large_i64(void *user_context, const char *param_name,
int64_t val, int64_t max_val);
extern int halide_error_param_too_large_u64(void *user_context, const char *param_name,
uint64_t val, uint64_t max_val);
extern int halide_error_param_too_large_f64(void *user_context, const char *param_name,
double val, double max_val);
extern int halide_error_out_of_memory(void *user_context);
extern int halide_error_buffer_argument_is_null(void *user_context, const char *buffer_name);
extern int halide_error_debug_to_file_failed(void *user_context, const char *func,
const char *filename, int error_code);
extern int halide_error_unaligned_host_ptr(void *user_context, const char *func_name, int alignment);
extern int halide_error_host_is_null(void *user_context, const char *func_name);
extern int halide_error_bad_fold(void *user_context, const char *func_name, const char *var_name,
const char *loop_name);
extern int halide_error_bad_extern_fold(void *user_context, const char *func_name,
int dim, int min, int extent, int valid_min, int fold_factor);
extern int halide_error_fold_factor_too_small(void *user_context, const char *func_name, const char *var_name,
int fold_factor, const char *loop_name, int required_extent);
extern int halide_error_requirement_failed(void *user_context, const char *condition, const char *message);
extern int halide_error_specialize_fail(void *user_context, const char *message);
extern int halide_error_no_device_interface(void *user_context);
extern int halide_error_device_interface_no_device(void *user_context);
extern int halide_error_host_and_device_dirty(void *user_context);
extern int halide_error_buffer_is_null(void *user_context, const char *routine);
extern int halide_error_device_dirty_with_no_device_support(void *user_context, const char *buffer_name);
extern int halide_error_storage_bound_too_small(void *user_context, const char *func_name, const char *var_name,
int provided_size, int required_size);
extern int halide_error_device_crop_failed(void *user_context);
typedef enum halide_target_feature_t {
halide_target_feature_jit = 0, halide_target_feature_debug, halide_target_feature_no_asserts, halide_target_feature_no_bounds_query,
halide_target_feature_sse41, halide_target_feature_avx, halide_target_feature_avx2, halide_target_feature_fma, halide_target_feature_fma4, halide_target_feature_f16c,
halide_target_feature_armv7s, halide_target_feature_no_neon,
halide_target_feature_vsx, halide_target_feature_power_arch_2_07,
halide_target_feature_cuda, halide_target_feature_cuda_capability30, halide_target_feature_cuda_capability32, halide_target_feature_cuda_capability35, halide_target_feature_cuda_capability50, halide_target_feature_cuda_capability61, halide_target_feature_cuda_capability70, halide_target_feature_cuda_capability75, halide_target_feature_cuda_capability80, halide_target_feature_cuda_capability86,
halide_target_feature_opencl, halide_target_feature_cl_doubles, halide_target_feature_cl_atomic64,
halide_target_feature_openglcompute,
halide_target_feature_user_context,
halide_target_feature_matlab,
halide_target_feature_profile, halide_target_feature_no_runtime,
halide_target_feature_metal,
halide_target_feature_c_plus_plus_mangling,
halide_target_feature_large_buffers,
halide_target_feature_hvx_128, halide_target_feature_hvx_v62, halide_target_feature_fuzz_float_stores, halide_target_feature_soft_float_abi, halide_target_feature_msan, halide_target_feature_avx512, halide_target_feature_avx512_knl, halide_target_feature_avx512_skylake, halide_target_feature_avx512_cannonlake, halide_target_feature_avx512_sapphirerapids, halide_target_feature_hvx_use_shared_object, halide_target_feature_trace_loads, halide_target_feature_trace_stores, halide_target_feature_trace_realizations, halide_target_feature_trace_pipeline, halide_target_feature_hvx_v65, halide_target_feature_hvx_v66, halide_target_feature_cl_half, halide_target_feature_strict_float, halide_target_feature_tsan, halide_target_feature_asan, halide_target_feature_d3d12compute, halide_target_feature_check_unsafe_promises, halide_target_feature_hexagon_dma, halide_target_feature_embed_bitcode, halide_target_feature_enable_llvm_loop_opt, halide_target_feature_disable_llvm_loop_opt, halide_target_feature_wasm_simd128, halide_target_feature_wasm_signext, halide_target_feature_wasm_sat_float_to_int, halide_target_feature_wasm_threads, halide_target_feature_wasm_bulk_memory, halide_target_feature_sve, halide_target_feature_sve2, halide_target_feature_egl, halide_target_feature_arm_dot_prod, halide_target_feature_arm_fp16, halide_llvm_large_code_model, halide_target_feature_rvv, halide_target_feature_armv81a, halide_target_feature_sanitizer_coverage, halide_target_feature_end } halide_target_feature_t;
extern int halide_can_use_target_features(int count, const uint64_t *features);
typedef int (*halide_can_use_target_features_t)(int count, const uint64_t *features);
extern halide_can_use_target_features_t halide_set_custom_can_use_target_features(halide_can_use_target_features_t);
extern int halide_default_can_use_target_features(int count, const uint64_t *features);
typedef struct halide_dimension_t {
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
int32_t min = 0, extent = 0, stride = 0;
uint32_t flags = 0;
HALIDE_ALWAYS_INLINE halide_dimension_t() = default;
HALIDE_ALWAYS_INLINE halide_dimension_t(int32_t m, int32_t e, int32_t s, uint32_t f = 0)
: min(m), extent(e), stride(s), flags(f) {
}
HALIDE_ALWAYS_INLINE bool operator==(const halide_dimension_t &other) const {
return (min == other.min) &&
(extent == other.extent) &&
(stride == other.stride) &&
(flags == other.flags);
}
HALIDE_ALWAYS_INLINE bool operator!=(const halide_dimension_t &other) const {
return !(*this == other);
}
#else
int32_t min, extent, stride;
uint32_t flags;
#endif
} halide_dimension_t;
#ifdef __cplusplus
} #endif
typedef enum { halide_buffer_flag_host_dirty = 1,
halide_buffer_flag_device_dirty = 2 } halide_buffer_flags;
typedef struct halide_buffer_t {
uint64_t device;
const struct halide_device_interface_t *device_interface;
uint8_t *host;
uint64_t flags;
struct halide_type_t type;
int32_t dimensions;
halide_dimension_t *dim;
void *padding;
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
HALIDE_ALWAYS_INLINE bool get_flag(halide_buffer_flags flag) const {
return (flags & flag) != 0;
}
HALIDE_ALWAYS_INLINE void set_flag(halide_buffer_flags flag, bool value) {
if (value) {
flags |= flag;
} else {
flags &= ~uint64_t(flag);
}
}
HALIDE_ALWAYS_INLINE bool host_dirty() const {
return get_flag(halide_buffer_flag_host_dirty);
}
HALIDE_ALWAYS_INLINE bool device_dirty() const {
return get_flag(halide_buffer_flag_device_dirty);
}
HALIDE_ALWAYS_INLINE void set_host_dirty(bool v = true) {
set_flag(halide_buffer_flag_host_dirty, v);
}
HALIDE_ALWAYS_INLINE void set_device_dirty(bool v = true) {
set_flag(halide_buffer_flag_device_dirty, v);
}
HALIDE_ALWAYS_INLINE size_t number_of_elements() const {
size_t s = 1;
for (int i = 0; i < dimensions; i++) {
s *= dim[i].extent;
}
return s;
}
HALIDE_ALWAYS_INLINE ptrdiff_t begin_offset() const {
ptrdiff_t index = 0;
for (int i = 0; i < dimensions; i++) {
const int stride = dim[i].stride;
if (stride < 0) {
index += stride * (ptrdiff_t)(dim[i].extent - 1);
}
}
return index;
}
HALIDE_ALWAYS_INLINE ptrdiff_t end_offset() const {
ptrdiff_t index = 0;
for (int i = 0; i < dimensions; i++) {
const int stride = dim[i].stride;
if (stride > 0) {
index += stride * (ptrdiff_t)(dim[i].extent - 1);
}
}
index += 1;
return index;
}
HALIDE_ALWAYS_INLINE uint8_t *begin() const {
return host + begin_offset() * type.bytes();
}
HALIDE_ALWAYS_INLINE uint8_t *end() const {
return host + end_offset() * type.bytes();
}
HALIDE_ALWAYS_INLINE size_t size_in_bytes() const {
return (size_t)(end_offset() - begin_offset()) * type.bytes();
}
HALIDE_ALWAYS_INLINE uint8_t *address_of(const int *pos) const {
ptrdiff_t index = 0;
for (int i = 0; i < dimensions; i++) {
index += (ptrdiff_t)dim[i].stride * (pos[i] - dim[i].min);
}
return host + index * type.bytes();
}
HALIDE_ALWAYS_INLINE int device_sync(void *ctx = nullptr) {
if (device_interface && device_interface->device_sync) {
return device_interface->device_sync(ctx, this);
}
return 0;
}
HALIDE_ALWAYS_INLINE bool is_bounds_query() const {
return host == nullptr && device == 0;
}
#endif
} halide_buffer_t;
#ifdef __cplusplus
extern "C" {
#endif
#ifndef HALIDE_ATTRIBUTE_DEPRECATED
#ifdef HALIDE_ALLOW_DEPRECATED
#define HALIDE_ATTRIBUTE_DEPRECATED(x)
#else
#ifdef _MSC_VER
#define HALIDE_ATTRIBUTE_DEPRECATED(x) __declspec(deprecated(x))
#else
#define HALIDE_ATTRIBUTE_DEPRECATED(x) __attribute__((deprecated(x)))
#endif
#endif
#endif
struct halide_scalar_value_t {
union {
bool b;
int8_t i8;
int16_t i16;
int32_t i32;
int64_t i64;
uint8_t u8;
uint16_t u16;
uint32_t u32;
uint64_t u64;
float f32;
double f64;
void *handle;
} u;
#ifdef __cplusplus
HALIDE_ALWAYS_INLINE halide_scalar_value_t() {
u.u64 = 0;
}
#endif
};
enum halide_argument_kind_t {
halide_argument_kind_input_scalar = 0,
halide_argument_kind_input_buffer = 1,
halide_argument_kind_output_buffer = 2
};
struct halide_filter_argument_t_v0 {
const char *name;
int32_t kind;
int32_t dimensions;
struct halide_type_t type;
const struct halide_scalar_value_t *def, *min, *max;
};
struct halide_filter_argument_t {
const char *name; int32_t kind; int32_t dimensions; struct halide_type_t type;
const struct halide_scalar_value_t *scalar_def, *scalar_min, *scalar_max, *scalar_estimate;
int64_t const *const *buffer_estimates;
};
struct halide_filter_metadata_t {
#ifdef __cplusplus
static const int32_t VERSION = 1;
#endif
int32_t version;
int32_t num_arguments;
const struct halide_filter_argument_t *arguments;
const char *target;
const char *name;
};
void halide_register_argv_and_metadata(
int (*filter_argv_call)(void **),
const struct halide_filter_metadata_t *filter_metadata,
const char *const *extra_key_value_pairs);
struct halide_profiler_func_stats {
uint64_t time;
uint64_t memory_current;
uint64_t memory_peak;
uint64_t memory_total;
uint64_t stack_peak;
uint64_t active_threads_numerator, active_threads_denominator;
const char *name;
int num_allocs;
};
struct halide_profiler_pipeline_stats {
uint64_t time;
uint64_t memory_current;
uint64_t memory_peak;
uint64_t memory_total;
uint64_t active_threads_numerator, active_threads_denominator;
const char *name;
struct halide_profiler_func_stats *funcs;
void *next;
int num_funcs;
int first_func_id;
int runs;
int samples;
int num_allocs;
};
struct halide_profiler_state {
struct halide_mutex lock;
int sleep_time;
int first_free_id;
int current_func;
int active_threads;
struct halide_profiler_pipeline_stats *pipelines;
void (*get_remote_profiler_state)(int *func, int *active_workers);
struct halide_thread *sampling_thread;
};
enum {
halide_profiler_outside_of_halide = -1,
halide_profiler_please_stop = -2
};
extern struct halide_profiler_state *halide_profiler_get_state();
extern struct halide_profiler_pipeline_stats *halide_profiler_get_pipeline_state(const char *pipeline_name);
extern void halide_profiler_reset();
void halide_profiler_shutdown();
extern void halide_profiler_report(void *user_context);
extern float halide_float16_bits_to_float(uint16_t);
extern double halide_float16_bits_to_double(uint16_t);
extern int halide_reuse_device_allocations(void *user_context, bool);
extern bool halide_can_reuse_device_allocations(void *user_context);
struct halide_device_allocation_pool {
int (*release_unused)(void *user_context);
struct halide_device_allocation_pool *next;
};
extern void halide_register_device_allocation_pool(struct halide_device_allocation_pool *);
#ifdef __cplusplus
} #endif
#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
namespace {
template<typename T>
struct check_is_pointer {
static constexpr bool value = false;
};
template<typename T>
struct check_is_pointer<T *> {
static constexpr bool value = true;
};
}
template<typename T>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of() {
static_assert(check_is_pointer<T>::value, "Expected a pointer type here");
return halide_type_t(halide_type_handle, 64);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<float>() {
return halide_type_t(halide_type_float, 32);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<double>() {
return halide_type_t(halide_type_float, 64);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<bool>() {
return halide_type_t(halide_type_uint, 1);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint8_t>() {
return halide_type_t(halide_type_uint, 8);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint16_t>() {
return halide_type_t(halide_type_uint, 16);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint32_t>() {
return halide_type_t(halide_type_uint, 32);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint64_t>() {
return halide_type_t(halide_type_uint, 64);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int8_t>() {
return halide_type_t(halide_type_int, 8);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int16_t>() {
return halide_type_t(halide_type_int, 16);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int32_t>() {
return halide_type_t(halide_type_int, 32);
}
template<>
HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int64_t>() {
return halide_type_t(halide_type_int, 64);
}
#endif
#endif