Halide 22.0.0 Halide compiler and libraries

HalideRuntime.h
Go to the documentation of this file.
1#ifndef HALIDE_HALIDERUNTIME_H
2#define HALIDE_HALIDERUNTIME_H
3
4#ifndef COMPILING_HALIDE_RUNTIME
5#ifdef __cplusplus
6#include <array>
7#include <cstddef>
8#include <cstdint>
9#include <cstring>
10#include <string_view>
11#else
12#include <stdbool.h>
13#include <stddef.h>
14#include <stdint.h>
15#include <string.h>
16#endif
17#else
18#include "runtime_internal.h"
19#endif
20
21// Note that the canonical Halide version is considered to be defined here
22// (rather than in the build system); we redundantly define the value in
23// our CMake build, so that we ensure that the in-build metadata (eg soversion)
24// matches, but keeping the canonical version here makes it easier to keep
25// downstream build systems (eg Blaze/Bazel) properly in sync with the source.
26#define HALIDE_VERSION_MAJOR 22
27#define HALIDE_VERSION_MINOR 0
28#define HALIDE_VERSION_PATCH 0
29
30#ifdef __cplusplus
31// Forward declare type to allow naming typed handles.
32// See Type.h for documentation.
33 template<typename T>
34 struct halide_handle_traits;
35#endif
36
37#ifdef __cplusplus
38 extern "C" {
39#endif
40
41#ifdef _MSC_VER
42// Note that (for MSVC) you should not use "inline" along with HALIDE_ALWAYS_INLINE;
43// it is not necessary, and may produce warnings for some build configurations.
44#define HALIDE_ALWAYS_INLINE __forceinline
45#define HALIDE_NEVER_INLINE __declspec(noinline)
46#else
47// Note that (for Posixy compilers) you should always use "inline" along with HALIDE_ALWAYS_INLINE;
48// otherwise some corner-case scenarios may erroneously report link errors.
49#define HALIDE_ALWAYS_INLINE inline __attribute__((always_inline))
50#define HALIDE_NEVER_INLINE __attribute__((noinline))
51#endif
52
53#ifndef HALIDE_MUST_USE_RESULT
54#ifdef __has_attribute
55#if __has_attribute(nodiscard)
56// C++17 or later
57#define HALIDE_MUST_USE_RESULT [[nodiscard]]
58#elif __has_attribute(warn_unused_result)
59// Clang/GCC
60#define HALIDE_MUST_USE_RESULT __attribute__((warn_unused_result))
61#else
62#define HALIDE_MUST_USE_RESULT
63#endif
64#else
65#define HALIDE_MUST_USE_RESULT
66#endif
67#endif
68
69// Annotation for AOT and JIT calls -- if undefined, use no annotation.
70// To ensure that all results are checked, do something like
71//
72// -DHALIDE_FUNCTION_ATTRS=HALIDE_MUST_USE_RESULT
73//
74// in your C++ compiler options
75#ifndef HALIDE_FUNCTION_ATTRS
76#define HALIDE_FUNCTION_ATTRS
77#endif
78
79#ifndef HALIDE_EXPORT_SYMBOL
80#ifdef _MSC_VER
81#define HALIDE_EXPORT_SYMBOL __declspec(dllexport)
82#else
83#define HALIDE_EXPORT_SYMBOL __attribute__((visibility("default")))
84#endif
85#endif
86
87#ifndef COMPILING_HALIDE_RUNTIME
88
89// ASAN builds can cause linker errors for Float16, so sniff for that and
90// don't enable it by default.
91#if defined(__has_feature)
92#if __has_feature(address_sanitizer)
93#define HALIDE_RUNTIME_ASAN_DETECTED
94#endif
95#endif
96
97#if defined(__SANITIZE_ADDRESS__) && !defined(HALIDE_RUNTIME_ASAN_DETECTED)
98#define HALIDE_RUNTIME_ASAN_DETECTED
99#endif
100
101#if !defined(HALIDE_RUNTIME_ASAN_DETECTED)
102
103// clang had _Float16 added as a reserved name in clang 8, but
104// doesn't actually support it on most platforms until clang 15.
105// Ideally there would be a better way to detect if the type
106// is supported, even in a compiler independent fashion, but
107// coming up with one has proven elusive.
108#if defined(__clang__) && (__clang_major__ >= 15) && !defined(__EMSCRIPTEN__) && !defined(__i386__)
109#if defined(__is_identifier)
110#if !__is_identifier(_Float16)
111#define HALIDE_CPP_COMPILER_HAS_FLOAT16
112#endif
113#endif
114#endif
115
116// Similarly, detecting _Float16 for gcc is problematic.
117// For now, we say that if >= v12, and compiling on x86 or arm,
118// we assume support. This may need revision.
119#if defined(__GNUC__) && (__GNUC__ >= 12)
120#if defined(__x86_64__) || (defined(__i386__) && (__GNUC__ >= 14) && defined(__SSE2__)) || ((defined(__arm__) || defined(__aarch64__)) && (__GNUC__ >= 13))
121#define HALIDE_CPP_COMPILER_HAS_FLOAT16
122#endif
123#endif
124
125#endif // !HALIDE_RUNTIME_ASAN_DETECTED
126
127#endif // !COMPILING_HALIDE_RUNTIME
128
129/** \file
130 *
131 * This file declares the routines used by Halide internally in its
132 * runtime. On platforms that support weak linking, these can be
133 * replaced with user-defined versions by defining an extern "C"
134 * function with the same name and signature.
135 *
136 * When doing Just In Time (JIT) compilation members of
137 * some_pipeline_or_func.jit_handlers() must be replaced instead. The
138 * corresponding methods are documented below.
139 *
140 * All of these functions take a "void *user_context" parameter as their
141 * first argument; if the Halide kernel that calls back to any of these
142 * functions has been compiled with the UserContext feature set on its Target,
143 * then the value of that pointer passed from the code that calls the
144 * Halide kernel is piped through to the function.
145 *
146 * Some of these are also useful to call when using the default
147 * implementation. E.g. halide_shutdown_thread_pool.
148 *
149 * Note that even on platforms with weak linking, some linker setups
150 * may not respect the override you provide. E.g. if the override is
151 * in a shared library and the halide object files are linked directly
152 * into the output, the builtin versions of the runtime functions will
153 * be called. See your linker documentation for more details. On
154 * Linux, LD_DYNAMIC_WEAK=1 may help.
155 *
156 */
157
158// Forward-declare to suppress warnings if compiling as C.
159 struct halide_buffer_t;
160
161/** Print a message to stderr. Main use is to support tracing
162 * functionality, print, and print_when calls. Also called by the default
163 * halide_error. This function can be replaced in JITed code by using
164 * halide_custom_print and providing an implementation of halide_print
165 * in AOT code. See Func::set_custom_print.
166 */
167// @{
168 extern void halide_print(void *user_context, const char *);
169 extern void halide_default_print(void *user_context, const char *);
170 typedef void (*halide_print_t)(void *, const char *);
171 extern halide_print_t halide_set_custom_print(halide_print_t print);
172// @}
173
174/** Halide calls this function on runtime errors (for example bounds
175 * checking failures). This function can be replaced in JITed code by
176 * using Func::set_error_handler, or in AOT code by calling
177 * halide_set_error_handler. In AOT code on platforms that support
178 * weak linking (i.e. not Windows), you can also override it by simply
179 * defining your own halide_error.
180 */
181// @{
182 extern void halide_error(void *user_context, const char *);
183 extern void halide_default_error(void *user_context, const char *);
184 typedef void (*halide_error_handler_t)(void *, const char *);
185 extern halide_error_handler_t halide_set_error_handler(halide_error_handler_t handler);
186// @}
187
188/** Cross-platform mutex. Must be initialized with zero and implementation
189 * must treat zero as an unlocked mutex with no waiters, etc.
190 */
191 struct halide_mutex {
192 uintptr_t _private[1];
193};
194
195/** Cross platform condition variable. Must be initialized to 0. */
196 struct halide_cond {
197 uintptr_t _private[1];
198};
199
200/** A basic set of mutex and condition variable functions, which call
201 * platform specific code for mutual exclusion. Equivalent to posix
202 * calls. */
203//@{
204 extern void halide_mutex_lock(struct halide_mutex *mutex);
205 extern void halide_mutex_unlock(struct halide_mutex *mutex);
206 extern void halide_cond_signal(struct halide_cond *cond);
207 extern void halide_cond_broadcast(struct halide_cond *cond);
208 extern void halide_cond_wait(struct halide_cond *cond, struct halide_mutex *mutex);
209//@}
210
211/** Functions for constructing/destroying/locking/unlocking arrays of mutexes. */
212 struct halide_mutex_array;
213//@{
214 extern struct halide_mutex_array *halide_mutex_array_create(uint64_t sz);
215 extern void halide_mutex_array_destroy(void *user_context, void *array);
216 extern int halide_mutex_array_lock(struct halide_mutex_array *array, int entry);
217 extern int halide_mutex_array_unlock(struct halide_mutex_array *array, int entry);
218//@}
219
220/** Define halide_do_par_for to replace the default thread pool
221 * implementation. halide_shutdown_thread_pool can also be called to
222 * release resources used by the default thread pool on platforms
223 * where it makes sense. See Func::set_custom_do_task and
224 * Func::set_custom_do_par_for. Should return zero if all the jobs
225 * return zero, or an arbitrarily chosen return value from one of the
226 * jobs otherwise.
227 */
228//@{
229 typedef int (*halide_task_t)(void *user_context, int task_number, uint8_t *closure);
230 extern int halide_do_par_for(void *user_context,
231 halide_task_t task,
232 int min, int size, uint8_t *closure);
233 extern void halide_shutdown_thread_pool(void);
234//@}
235
236/** Set a custom method for performing a parallel for loop. Returns
237 * the old do_par_for handler. */
238 typedef int (*halide_do_par_for_t)(void *, halide_task_t, int, int, uint8_t *);
239 extern halide_do_par_for_t halide_set_custom_do_par_for(halide_do_par_for_t do_par_for);
240
241/** An opaque struct representing a semaphore. Used by the task system for async tasks. */
242 struct halide_semaphore_t {
243 uint64_t _private[2];
244};
245
246/** A struct representing a semaphore and a number of items that must
247 * be acquired from it. Used in halide_parallel_task_t below. */
248 struct halide_semaphore_acquire_t {
249 struct halide_semaphore_t *semaphore;
250 int count;
251};
252 extern int halide_semaphore_init(struct halide_semaphore_t *, int n);
253 extern int halide_semaphore_release(struct halide_semaphore_t *, int n);
254 extern bool halide_semaphore_try_acquire(struct halide_semaphore_t *, int n);
255 typedef int (*halide_semaphore_init_t)(struct halide_semaphore_t *, int);
256 typedef int (*halide_semaphore_release_t)(struct halide_semaphore_t *, int);
257 typedef bool (*halide_semaphore_try_acquire_t)(struct halide_semaphore_t *, int);
258
259/** A task representing a serial for loop evaluated over some range.
260 * Note that task_parent is a pass through argument that should be
261 * passed to any dependent taks that are invoked using halide_do_parallel_tasks
262 * underneath this call. */
263 typedef int (*halide_loop_task_t)(void *user_context, int min, int extent,
264 uint8_t *closure, void *task_parent);
265
266/** A parallel task to be passed to halide_do_parallel_tasks. This
267 * task may recursively call halide_do_parallel_tasks, and there may
268 * be complex dependencies between seemingly unrelated tasks expressed
269 * using semaphores. If you are using a custom task system, care must
270 * be taken to avoid potential deadlock. This can be done by carefully
271 * respecting the static metadata at the end of the task struct.*/
272 struct halide_parallel_task_t {
273 // The function to call. It takes a user context, a min and
274 // extent, a closure, and a task system pass through argument.
275 halide_loop_task_t fn;
276
277 // The closure to pass it
278 uint8_t *closure;
279
280 // The name of the function to be called. For debugging purposes only.
281 const char *name;
282
283 // An array of semaphores that must be acquired before the
284 // function is called. Must be reacquired for every call made.
285 struct halide_semaphore_acquire_t *semaphores;
286 int num_semaphores;
287
288 // The entire range the function should be called over. This range
289 // may be sliced up and the function called multiple times.
290 int min, extent;
291
292 // A parallel task provides several pieces of metadata to prevent
293 // unbounded resource usage or deadlock.
294
295 // The first is the minimum number of execution contexts (call
296 // stacks or threads) necessary for the function to run to
297 // completion. This may be greater than one when there is nested
298 // parallelism with internal producer-consumer relationships
299 // (calling the function recursively spawns and blocks on parallel
300 // sub-tasks that communicate with each other via semaphores). If
301 // a parallel runtime calls the function when fewer than this many
302 // threads are idle, it may need to create more threads to
303 // complete the task, or else risk deadlock due to committing all
304 // threads to tasks that cannot complete without more.
305 //
306 // FIXME: Note that extern stages are assumed to only require a
307 // single thread to complete. If the extern stage is itself a
308 // Halide pipeline, this may be an underestimate.
309 int min_threads;
310
311 // The calls to the function should be in serial order from min to min+extent-1, with only
312 // one executing at a time. If false, any order is fine, and
313 // concurrency is fine.
314 bool serial;
315};
316
317/** Enqueue some number of the tasks described above and wait for them
318 * to complete. While waiting, the calling threads assists with either
319 * the tasks enqueued, or other non-blocking tasks in the task
320 * system. Note that task_parent should be NULL for top-level calls
321 * and the pass through argument if this call is being made from
322 * another task. */
323 extern int halide_do_parallel_tasks(void *user_context, int num_tasks,
324 struct halide_parallel_task_t *tasks,
325 void *task_parent);
326
327/** If you use the default do_par_for, you can still set a custom
328 * handler to perform each individual task. Returns the old handler. */
329//@{
330 typedef int (*halide_do_task_t)(void *, halide_task_t, int, uint8_t *);
331 extern halide_do_task_t halide_set_custom_do_task(halide_do_task_t do_task);
332 extern int halide_do_task(void *user_context, halide_task_t f, int idx,
333 uint8_t *closure);
334//@}
335
336/** The version of do_task called for loop tasks. By default calls the
337 * loop task with the same arguments. */
338// @{
339 typedef int (*halide_do_loop_task_t)(void *, halide_loop_task_t, int, int, uint8_t *, void *);
340 extern halide_do_loop_task_t halide_set_custom_do_loop_task(halide_do_loop_task_t do_task);
341 extern int halide_do_loop_task(void *user_context, halide_loop_task_t f, int min, int extent,
342 uint8_t *closure, void *task_parent);
343//@}
344
345/** Provide an entire custom tasking runtime via function
346 * pointers. Note that do_task and semaphore_try_acquire are only ever
347 * called by halide_default_do_par_for and
348 * halide_default_do_parallel_tasks, so it's only necessary to provide
349 * those if you are mixing in the default implementations of
350 * do_par_for and do_parallel_tasks. */
351// @{
352 typedef int (*halide_do_parallel_tasks_t)(void *, int, struct halide_parallel_task_t *,
353 void *task_parent);
354 extern void halide_set_custom_parallel_runtime(
355 halide_do_par_for_t,
356 halide_do_task_t,
357 halide_do_loop_task_t,
358 halide_do_parallel_tasks_t,
359 halide_semaphore_init_t,
360 halide_semaphore_try_acquire_t,
361 halide_semaphore_release_t);
362// @}
363
364/** The default versions of the parallel runtime functions. */
365// @{
366 extern int halide_default_do_par_for(void *user_context,
367 halide_task_t task,
368 int min, int size, uint8_t *closure);
369 extern int halide_default_do_parallel_tasks(void *user_context,
370 int num_tasks,
371 struct halide_parallel_task_t *tasks,
372 void *task_parent);
373 extern int halide_default_do_task(void *user_context, halide_task_t f, int idx,
374 uint8_t *closure);
375 extern int halide_default_do_loop_task(void *user_context, halide_loop_task_t f,
376 int min, int extent,
377 uint8_t *closure, void *task_parent);
378 extern int halide_default_semaphore_init(struct halide_semaphore_t *, int n);
379 extern int halide_default_semaphore_release(struct halide_semaphore_t *, int n);
380 extern bool halide_default_semaphore_try_acquire(struct halide_semaphore_t *, int n);
381// @}
382
383 struct halide_thread;
384
385/** Spawn a thread. Returns a handle to the thread for the purposes of
386 * joining it. The thread must be joined in order to clean up any
387 * resources associated with it. */
388 extern struct halide_thread *halide_spawn_thread(void (*f)(void *), void *closure);
389
390/** Join a thread. */
391 extern void halide_join_thread(struct halide_thread *);
392
393/** Get or set the number of threads used by Halide's thread pool. Set returns
394 * the old number.
395 *
396 * n < 0 : error condition
397 * n == 0 : use a reasonable system default (typically, number of cpus online).
398 * n == 1 : use exactly one thread; this will always enforce serial execution
399 * n > 1 : use a pool of exactly n threads.
400 *
401 * (Note that this is only guaranteed when using the default implementations
402 * of halide_do_par_for(); custom implementations may completely ignore values
403 * passed to halide_set_num_threads().)
404 */
405// @{
406 extern int halide_get_num_threads();
407 extern int halide_set_num_threads(int n);
408// @}
409
410/** Halide calls these functions to allocate and free memory. To
411 * replace in AOT code, use the halide_set_custom_malloc and
412 * halide_set_custom_free, or (on platforms that support weak
413 * linking), simply define these functions yourself. In JIT-compiled
414 * code use Func::set_custom_allocator.
415 *
416 * If you override them, and find yourself wanting to call the default
417 * implementation from within your override, use
418 * halide_default_malloc/free.
419 *
420 * Note that halide_malloc must return a pointer aligned to the
421 * maximum meaningful alignment for the platform for the purpose of
422 * vector loads and stores, *and* with an allocated size that is (at least)
423 * an integral multiple of that same alignment. The default implementation
424 * uses 32-byte alignment on arm and 64-byte alignment on x86. Additionally,
425 * it must be safe to read at least 8 bytes before the start and beyond the end.
426 */
427//@{
428 extern void *halide_malloc(void *user_context, size_t x);
429 extern void halide_free(void *user_context, void *ptr);
430 extern void *halide_default_malloc(void *user_context, size_t x);
431 extern void halide_default_free(void *user_context, void *ptr);
432 typedef void *(*halide_malloc_t)(void *, size_t);
433 typedef void (*halide_free_t)(void *, void *);
434 extern halide_malloc_t halide_set_custom_malloc(halide_malloc_t user_malloc);
435 extern halide_free_t halide_set_custom_free(halide_free_t user_free);
436//@}
437
438/** Halide calls these functions to interact with the underlying
439 * system runtime functions. To replace in AOT code on platforms that
440 * support weak linking, define these functions yourself, or use
441 * the halide_set_custom_load_library() and halide_set_custom_get_library_symbol()
442 * functions. In JIT-compiled code, use JITSharedRuntime::set_default_handlers().
443 *
444 * halide_load_library and halide_get_library_symbol are equivalent to
445 * dlopen and dlsym. halide_get_symbol(sym) is equivalent to
446 * dlsym(RTLD_DEFAULT, sym).
447 */
448//@{
449 extern void *halide_get_symbol(const char *name);
450 extern void *halide_load_library(const char *name);
451 extern void *halide_get_library_symbol(void *lib, const char *name);
452 extern void *halide_default_get_symbol(const char *name);
453 extern void *halide_default_load_library(const char *name);
454 extern void *halide_default_get_library_symbol(void *lib, const char *name);
455 typedef void *(*halide_get_symbol_t)(const char *name);
456 typedef void *(*halide_load_library_t)(const char *name);
457 typedef void *(*halide_get_library_symbol_t)(void *lib, const char *name);
458 extern halide_get_symbol_t halide_set_custom_get_symbol(halide_get_symbol_t user_get_symbol);
459 extern halide_load_library_t halide_set_custom_load_library(halide_load_library_t user_load_library);
460 extern halide_get_library_symbol_t halide_set_custom_get_library_symbol(halide_get_library_symbol_t user_get_library_symbol);
461//@}
462
463/** Called when debug_to_file is used inside %Halide code. See
464 * Func::debug_to_file for how this is called
465 *
466 * Cannot be replaced in JITted code at present.
467 */
468 extern int32_t halide_debug_to_file(void *user_context, const char *filename,
469 struct halide_buffer_t *buf);
470
471/** Types in the halide type system. They can be ints, unsigned ints,
472 * or floats (of various bit-widths), or a handle (which is always 64-bits).
473 * Note that the int/uint/float values do not imply a specific bit width
474 * (the bit width is expected to be encoded in a separate value).
475 */
476 typedef enum halide_type_code_t
477#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
478 : uint8_t
479#endif
480{
481 halide_type_int = 0, ///< signed integers
482 halide_type_uint = 1, ///< unsigned integers
483 halide_type_float = 2, ///< IEEE floating point numbers
484 halide_type_handle = 3, ///< opaque pointer type (void *)
485 halide_type_bfloat = 4, ///< floating point numbers in the bfloat format
486} halide_type_code_t;
487
488// Note that while __attribute__ can go before or after the declaration,
489// __declspec apparently is only allowed before.
490#ifndef HALIDE_ATTRIBUTE_ALIGN
491#ifdef _MSC_VER
492#define HALIDE_ATTRIBUTE_ALIGN(x) __declspec(align(x))
493#else
494#define HALIDE_ATTRIBUTE_ALIGN(x) __attribute__((aligned(x)))
495#endif
496#endif
497
498/** A runtime tag for a type in the halide type system. Can be ints,
499 * unsigned ints, or floats of various bit-widths (the 'bits'
500 * field). Can also be vectors of the same (by setting the 'lanes'
501 * field to something larger than one). This struct should be
502 * exactly 32-bits in size. */
503 struct halide_type_t {
504 /** The basic type code: signed integer, unsigned integer, or floating point. */
505#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
506 HALIDE_ATTRIBUTE_ALIGN(1)
507 halide_type_code_t code; // halide_type_code_t
508#else
509 HALIDE_ATTRIBUTE_ALIGN(1)
510 uint8_t code; // halide_type_code_t
511#endif
512
513 /** The number of bits of precision of a single scalar value of this type. */
514 HALIDE_ATTRIBUTE_ALIGN(1)
515 uint8_t bits;
516
517 /** How many elements in a vector. This is 1 for scalar types. */
518 HALIDE_ATTRIBUTE_ALIGN(2)
519 uint16_t lanes;
520
521#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
522 /** Construct a runtime representation of a Halide type from:
523 * code: The fundamental type from an enum.
524 * bits: The bit size of one element.
525 * lanes: The number of vector elements in the type. */
526 HALIDE_ALWAYS_INLINE constexpr halide_type_t(halide_type_code_t code, uint8_t bits, uint16_t lanes = 1)
527 : code(code), bits(bits), lanes(lanes) {
528 }
529
530 /** Default constructor is required e.g. to declare halide_trace_event
531 * instances. */
532 HALIDE_ALWAYS_INLINE constexpr halide_type_t()
533 : code((halide_type_code_t)0), bits(0), lanes(0) {
534 }
535
536 HALIDE_ALWAYS_INLINE constexpr halide_type_t with_lanes(uint16_t new_lanes) const {
537 return halide_type_t((halide_type_code_t)code, bits, new_lanes);
538 }
539
540 HALIDE_ALWAYS_INLINE constexpr halide_type_t element_of() const {
541 return with_lanes(1);
542 }
543 /** Compare two types for equality. */
544 HALIDE_ALWAYS_INLINE constexpr bool operator==(const halide_type_t &other) const {
545 return as_u32() == other.as_u32();
546 }
547
548 HALIDE_ALWAYS_INLINE constexpr bool operator!=(const halide_type_t &other) const {
549 return !(*this == other);
550 }
551
552 HALIDE_ALWAYS_INLINE constexpr bool operator<(const halide_type_t &other) const {
553 return as_u32() < other.as_u32();
554 }
555
556 /** Size in bytes for a single element, even if width is not 1, of this type. */
557 HALIDE_ALWAYS_INLINE constexpr int bytes() const {
558 return (bits + 7) / 8;
559 }
560
561 HALIDE_ALWAYS_INLINE constexpr uint32_t as_u32() const {
562 // Note that this produces a result that is identical to memcpy'ing 'this'
563 // into a u32 (on a little-endian machine, anyway), and at -O1 or greater
564 // on Clang, the compiler knows this and optimizes this into a single 32-bit move.
565 // (At -O0 it will look awful.)
566 return static_cast<uint8_t>(code) |
567 (static_cast<uint16_t>(bits) << 8) |
568 (static_cast<uint32_t>(lanes) << 16);
569 }
570#endif
571};
572
573#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
574 static_assert(sizeof(halide_type_t) == sizeof(uint32_t), "size mismatch in halide_type_t");
575#endif
576
577 enum halide_trace_event_code_t { halide_trace_load = 0,
578 halide_trace_store = 1,
579 halide_trace_begin_realization = 2,
580 halide_trace_end_realization = 3,
581 halide_trace_produce = 4,
582 halide_trace_end_produce = 5,
583 halide_trace_consume = 6,
584 halide_trace_end_consume = 7,
585 halide_trace_begin_pipeline = 8,
586 halide_trace_end_pipeline = 9,
587 halide_trace_tag = 10 };
588
589 struct halide_trace_event_t {
590 /** The name of the Func or Pipeline that this event refers to */
591 const char *func;
592
593 /** If the event type is a load or a store, this points to the
594 * value being loaded or stored. Use the type field to safely cast
595 * this to a concrete pointer type and retrieve it. For other
596 * events this is null. */
597 void *value;
598
599 /** For loads and stores, an array which contains the location
600 * being accessed. For vector loads or stores it is an array of
601 * vectors of coordinates (the vector dimension is innermost).
602 *
603 * For realization or production-related events, this will contain
604 * the mins and extents of the region being accessed, in the order
605 * min0, extent0, min1, extent1, ...
606 *
607 * For pipeline-related events, this will be null.
608 */
609 int32_t *coordinates;
610
611 /** For halide_trace_tag, this points to a read-only null-terminated string
612 * of arbitrary text. For all other events, this will be null.
613 */
614 const char *trace_tag;
615
616 /** If the event type is a load or a store, this is the type of
617 * the data. Otherwise, the value is meaningless. */
618 struct halide_type_t type;
619
620 /** The type of event */
621 enum halide_trace_event_code_t event;
622
623 /* The ID of the parent event (see below for an explanation of
624 * event ancestry). */
625 int32_t parent_id;
626
627 /** If this was a load or store of a Tuple-valued Func, this is
628 * which tuple element was accessed. */
629 int32_t value_index;
630
631 /** The length of the coordinates array */
632 int32_t dimensions;
633};
634
635/** Called when Funcs are marked as trace_load, trace_store, or
636 * trace_realization. See Func::set_custom_trace. The default
637 * implementation either prints events via halide_print, or if
638 * HL_TRACE_FILE is defined, dumps the trace to that file in a
639 * sequence of trace packets. The header for a trace packet is defined
640 * below. If the trace is going to be large, you may want to make the
641 * file a named pipe, and then read from that pipe into gzip.
642 *
643 * halide_trace returns a unique ID which will be passed to future
644 * events that "belong" to the earlier event as the parent id. The
645 * ownership hierarchy looks like:
646 *
647 * begin_pipeline
648 * +--trace_tag (if any)
649 * +--trace_tag (if any)
650 * ...
651 * +--begin_realization
652 * | +--produce
653 * | | +--load/store
654 * | | +--end_produce
655 * | +--consume
656 * | | +--load
657 * | | +--end_consume
658 * | +--end_realization
659 * +--end_pipeline
660 *
661 * Threading means that ownership cannot be inferred from the ordering
662 * of events. There can be many active realizations of a given
663 * function, or many active productions for a single
664 * realization. Within a single production, the ordering of events is
665 * meaningful.
666 *
667 * Note that all trace_tag events (if any) will occur just after the begin_pipeline
668 * event, but before any begin_realization events. All trace_tags for a given Func
669 * will be emitted in the order added.
670 */
671// @}
672 extern int32_t halide_trace(void *user_context, const struct halide_trace_event_t *event);
673 extern int32_t halide_default_trace(void *user_context, const struct halide_trace_event_t *event);
674 typedef int32_t (*halide_trace_t)(void *user_context, const struct halide_trace_event_t *);
675 extern halide_trace_t halide_set_custom_trace(halide_trace_t trace);
676// @}
677
678/** The header of a packet in a binary trace. All fields are 32-bit. */
679 struct halide_trace_packet_t {
680 /** The total size of this packet in bytes. Always a multiple of
681 * four. Equivalently, the number of bytes until the next
682 * packet. */
683 uint32_t size;
684
685 /** The id of this packet (for the purpose of parent_id). */
686 int32_t id;
687
688 /** The remaining fields are equivalent to those in halide_trace_event_t */
689 // @{
690 struct halide_type_t type;
691 enum halide_trace_event_code_t event;
692 int32_t parent_id;
693 int32_t value_index;
694 int32_t dimensions;
695 // @}
696
697#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
698 /** Get the coordinates array, assuming this packet is laid out in
699 * memory as it was written. The coordinates array comes
700 * immediately after the packet header. */
701 HALIDE_ALWAYS_INLINE const int *coordinates() const {
702 return (const int *)(this + 1);
703 }
704
705 HALIDE_ALWAYS_INLINE int *coordinates() {
706 return (int *)(this + 1);
707 }
708
709 /** Get the value, assuming this packet is laid out in memory as
710 * it was written. The packet comes immediately after the coordinates
711 * array. */
712 HALIDE_ALWAYS_INLINE const void *value() const {
713 return (const void *)(coordinates() + dimensions);
714 }
715
716 HALIDE_ALWAYS_INLINE void *value() {
717 return (void *)(coordinates() + dimensions);
718 }
719
720 /** Get the func name, assuming this packet is laid out in memory
721 * as it was written. It comes after the value. */
722 HALIDE_ALWAYS_INLINE const char *func() const {
723 return (const char *)value() + type.lanes * type.bytes();
724 }
725
726 HALIDE_ALWAYS_INLINE char *func() {
727 return (char *)value() + type.lanes * type.bytes();
728 }
729
730 /** Get the trace_tag (if any), assuming this packet is laid out in memory
731 * as it was written. It comes after the func name. If there is no trace_tag,
732 * this will return a pointer to an empty string. */
733 HALIDE_ALWAYS_INLINE const char *trace_tag() const {
734 const char *f = func();
735 // strlen may not be available here
736 while (*f++) {
737 // nothing
738 }
739 return f;
740 }
741
742 HALIDE_ALWAYS_INLINE char *trace_tag() {
743 char *f = func();
744 // strlen may not be available here
745 while (*f++) {
746 // nothing
747 }
748 return f;
749 }
750#endif
751};
752
753/** Set the file descriptor that Halide should write binary trace
754 * events to. If called with 0 as the argument, Halide outputs trace
755 * information to stdout in a human-readable format. If never called,
756 * Halide checks the for existence of an environment variable called
757 * HL_TRACE_FILE and opens that file. If HL_TRACE_FILE is not defined,
758 * it outputs trace information to stdout in a human-readable
759 * format. */
760 extern void halide_set_trace_file(int fd);
761
762/** Halide calls this to retrieve the file descriptor to write binary
763 * trace events to. The default implementation returns the value set
764 * by halide_set_trace_file. Implement it yourself if you wish to use
765 * a custom file descriptor per user_context. Return zero from your
766 * implementation to tell Halide to print human-readable trace
767 * information to stdout. */
768 extern int halide_get_trace_file(void *user_context);
769
770/** If tracing is writing to a file. This call closes that file
771 * (flushing the trace). Returns zero on success. */
772 extern int halide_shutdown_trace(void);
773
774/** All Halide GPU or device backend implementations provide an
775 * interface to be used with halide_device_malloc, etc. This is
776 * accessed via the functions below.
777 */
778
779/** An opaque struct containing per-GPU API implementations of the
780 * device functions. */
781 struct halide_device_interface_impl_t;
782
783/** Each GPU API provides a halide_device_interface_t struct pointing
784 * to the code that manages device allocations. You can access these
785 * functions directly from the struct member function pointers, or by
786 * calling the functions declared below. Note that the global
787 * functions are not available when using Halide as a JIT compiler.
788 * If you are using raw halide_buffer_t in that context you must use
789 * the function pointers in the device_interface struct.
790 *
791 * The function pointers below are currently the same for every GPU
792 * API; only the impl field varies. These top-level functions do the
793 * bookkeeping that is common across all GPU APIs, and then dispatch
794 * to more API-specific functions via another set of function pointers
795 * hidden inside the impl field.
796 */
797 struct halide_device_interface_t {
798 int (*device_malloc)(void *user_context, struct halide_buffer_t *buf,
799 const struct halide_device_interface_t *device_interface);
800 int (*device_free)(void *user_context, struct halide_buffer_t *buf);
801 int (*device_sync)(void *user_context, struct halide_buffer_t *buf);
802 void (*device_release)(void *user_context,
803 const struct halide_device_interface_t *device_interface);
804 int (*copy_to_host)(void *user_context, struct halide_buffer_t *buf);
805 int (*copy_to_device)(void *user_context, struct halide_buffer_t *buf,
806 const struct halide_device_interface_t *device_interface);
807 int (*device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf,
808 const struct halide_device_interface_t *device_interface);
809 int (*device_and_host_free)(void *user_context, struct halide_buffer_t *buf);
810 int (*buffer_copy)(void *user_context, struct halide_buffer_t *src,
811 const struct halide_device_interface_t *dst_device_interface, struct halide_buffer_t *dst);
812 int (*device_crop)(void *user_context, const struct halide_buffer_t *src,
813 struct halide_buffer_t *dst);
814 int (*device_slice)(void *user_context, const struct halide_buffer_t *src,
815 int slice_dim, int slice_pos, struct halide_buffer_t *dst);
816 int (*device_release_crop)(void *user_context, struct halide_buffer_t *buf);
817 int (*wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle,
818 const struct halide_device_interface_t *device_interface);
819 int (*detach_native)(void *user_context, struct halide_buffer_t *buf);
820 int (*compute_capability)(void *user_context, int *major, int *minor);
821 const struct halide_device_interface_impl_t *impl;
822};
823
824/** Release all data associated with the given device interface, in
825 * particular all resources (memory, texture, context handles)
826 * allocated by Halide. Must be called explicitly when using AOT
827 * compilation. This is *not* thread-safe with respect to actively
828 * running Halide code. Ensure all pipelines are finished before
829 * calling this. */
830 extern void halide_device_release(void *user_context,
831 const struct halide_device_interface_t *device_interface);
832
833/** Copy image data from device memory to host memory. This must be called
834 * explicitly to copy back the results of a GPU-based filter. */
835 extern int halide_copy_to_host(void *user_context, struct halide_buffer_t *buf);
836
837/** Copy image data from host memory to device memory. This should not
838 * be called directly; Halide handles copying to the device
839 * automatically. If interface is NULL and the buf has a non-zero dev
840 * field, the device associated with the dev handle will be
841 * used. Otherwise if the dev field is 0 and interface is NULL, an
842 * error is returned. */
843 extern int halide_copy_to_device(void *user_context, struct halide_buffer_t *buf,
844 const struct halide_device_interface_t *device_interface);
845
846/** Copy data from one buffer to another. The buffers may have
847 * different shapes and sizes, but the destination buffer's shape must
848 * be contained within the source buffer's shape. That is, for each
849 * dimension, the min on the destination buffer must be greater than
850 * or equal to the min on the source buffer, and min+extent on the
851 * destination buffer must be less that or equal to min+extent on the
852 * source buffer. The source data is pulled from either device or
853 * host memory on the source, depending on the dirty flags. host is
854 * preferred if both are valid. The dst_device_interface parameter
855 * controls the destination memory space. NULL means host memory. */
856 extern int halide_buffer_copy(void *user_context, struct halide_buffer_t *src,
857 const struct halide_device_interface_t *dst_device_interface,
858 struct halide_buffer_t *dst);
859
860/** Give the destination buffer a device allocation which is an alias
861 * for the same coordinate range in the source buffer. Modifies the
862 * device, device_interface, and the device_dirty flag only. Only
863 * supported by some device APIs (others will return
864 * halide_error_code_device_crop_unsupported). Call
865 * halide_device_release_crop instead of halide_device_free to clean
866 * up resources associated with the cropped view. Do not free the
867 * device allocation on the source buffer while the destination buffer
868 * still lives. Note that the two buffers do not share dirty flags, so
869 * care must be taken to update them together as needed. Note that src
870 * and dst are required to have the same number of dimensions.
871 *
872 * Note also that (in theory) device interfaces which support cropping may
873 * still not support cropping a crop (instead, create a new crop of the parent
874 * buffer); in practice, no known implementation has this limitation, although
875 * it is possible that some future implementations may require it. */
876 extern int halide_device_crop(void *user_context,
877 const struct halide_buffer_t *src,
878 struct halide_buffer_t *dst);
879
880/** Give the destination buffer a device allocation which is an alias
881 * for a similar coordinate range in the source buffer, but with one dimension
882 * sliced away in the dst. Modifies the device, device_interface, and the
883 * device_dirty flag only. Only supported by some device APIs (others will return
884 * halide_error_code_device_crop_unsupported). Call
885 * halide_device_release_crop instead of halide_device_free to clean
886 * up resources associated with the sliced view. Do not free the
887 * device allocation on the source buffer while the destination buffer
888 * still lives. Note that the two buffers do not share dirty flags, so
889 * care must be taken to update them together as needed. Note that the dst buffer
890 * must have exactly one fewer dimension than the src buffer, and that slice_dim
891 * and slice_pos must be valid within src. */
892 extern int halide_device_slice(void *user_context,
893 const struct halide_buffer_t *src,
894 int slice_dim, int slice_pos,
895 struct halide_buffer_t *dst);
896
897/** Release any resources associated with a cropped/sliced view of another
898 * buffer. */
899 extern int halide_device_release_crop(void *user_context,
900 struct halide_buffer_t *buf);
901
902/** Wait for current GPU operations to complete. Calling this explicitly
903 * should rarely be necessary, except maybe for profiling. */
904 extern int halide_device_sync(void *user_context, struct halide_buffer_t *buf);
905
906/**
907 * Wait for current GPU operations to complete. Calling this explicitly
908 * should rarely be necessary, except maybe for profiling.
909 * This variation of the synchronizing is useful when a synchronization is desirable
910 * without specifying any buffer to synchronize on.
911 * Calling this with a null device_interface is always illegal.
912 */
913 extern int halide_device_sync_global(void *user_context,
914 const struct halide_device_interface_t *device_interface);
915
916/** Allocate device memory to back a halide_buffer_t. */
917 extern int halide_device_malloc(void *user_context, struct halide_buffer_t *buf,
918 const struct halide_device_interface_t *device_interface);
919
920/** Free device memory. */
921 extern int halide_device_free(void *user_context, struct halide_buffer_t *buf);
922
923/** Wrap or detach a native device handle, setting the device field
924 * and device_interface field as appropriate for the given GPU
925 * API. The meaning of the opaque handle is specific to the device
926 * interface, so if you know the device interface in use, call the
927 * more specific functions in the runtime headers for your specific
928 * device API instead (e.g. HalideRuntimeCuda.h). */
929// @{
930 extern int halide_device_wrap_native(void *user_context,
931 struct halide_buffer_t *buf,
932 uint64_t handle,
933 const struct halide_device_interface_t *device_interface);
934 extern int halide_device_detach_native(void *user_context, struct halide_buffer_t *buf);
935// @}
936
937/** Selects which gpu device to use. 0 is usually the display
938 * device. If never called, Halide uses the environment variable
939 * HL_GPU_DEVICE. If that variable is unset, Halide uses the last
940 * device. Set this to -1 to use the last device. */
941 extern void halide_set_gpu_device(int n);
942
943/** Halide calls this to get the desired halide gpu device
944 * setting. Implement this yourself to use a different gpu device per
945 * user_context. The default implementation returns the value set by
946 * halide_set_gpu_device, or the environment variable
947 * HL_GPU_DEVICE. */
948 extern int halide_get_gpu_device(void *user_context);
949
950/** Set the soft maximum amount of memory, in bytes, that the LRU
951 * cache will use to memoize Func results. This is not a strict
952 * maximum in that concurrency and simultaneous use of memoized
953 * reults larger than the cache size can both cause it to
954 * temporariliy be larger than the size specified here.
955 */
956 extern void halide_memoization_cache_set_size(int64_t size);
957
958/** Given a cache key for a memoized result, currently constructed
959 * from the Func name and top-level Func name plus the arguments of
960 * the computation, determine if the result is in the cache and
961 * return it if so. (The internals of the cache key should be
962 * considered opaque by this function.) If this routine returns true,
963 * it is a cache miss. Otherwise, it will return false and the
964 * buffers passed in will be filled, via copying, with memoized
965 * data. The last argument is a list if halide_buffer_t pointers which
966 * represents the outputs of the memoized Func. If the Func does not
967 * return a Tuple, there will only be one halide_buffer_t in the list. The
968 * tuple_count parameters determines the length of the list.
969 *
970 * The return values are:
971 * -1: Signals an error.
972 * 0: Success and cache hit.
973 * 1: Success and cache miss.
974 */
975 extern int halide_memoization_cache_lookup(void *user_context, const uint8_t *cache_key, int32_t size,
976 struct halide_buffer_t *realized_bounds,
977 int32_t tuple_count, struct halide_buffer_t **tuple_buffers);
978
979/** Given a cache key for a memoized result, currently constructed
980 * from the Func name and top-level Func name plus the arguments of
981 * the computation, store the result in the cache for futre access by
982 * halide_memoization_cache_lookup. (The internals of the cache key
983 * should be considered opaque by this function.) Data is copied out
984 * from the inputs and inputs are unmodified. The last argument is a
985 * list if halide_buffer_t pointers which represents the outputs of the
986 * memoized Func. If the Func does not return a Tuple, there will
987 * only be one halide_buffer_t in the list. The tuple_count parameters
988 * determines the length of the list.
989 *
990 * If there is a memory allocation failure, the store does not store
991 * the data into the cache.
992 *
993 * If has_eviction_key is true, the entry is marked with eviction_key to
994 * allow removing the key with halide_memoization_cache_evict.
995 */
996 extern int halide_memoization_cache_store(void *user_context, const uint8_t *cache_key, int32_t size,
997 struct halide_buffer_t *realized_bounds,
998 int32_t tuple_count,
999 struct halide_buffer_t **tuple_buffers,
1000 bool has_eviction_key, uint64_t eviction_key);
1001
1002/** Evict all cache entries that were tagged with the given
1003 * eviction_key in the memoize scheduling directive.
1004 */
1005 extern void halide_memoization_cache_evict(void *user_context, uint64_t eviction_key);
1006
1007/** If halide_memoization_cache_lookup succeeds,
1008 * halide_memoization_cache_release must be called to signal the
1009 * storage is no longer being used by the caller. It will be passed
1010 * the host pointer of one the buffers returned by
1011 * halide_memoization_cache_lookup. That is
1012 * halide_memoization_cache_release will be called multiple times for
1013 * the case where halide_memoization_cache_lookup is handling multiple
1014 * buffers. (This corresponds to memoizing a Tuple in Halide.) Note
1015 * that the host pointer must be sufficient to get to all information
1016 * the release operation needs. The default Halide cache impleemntation
1017 * accomplishes this by storing extra data before the start of the user
1018 * modifiable host storage.
1019 *
1020 * This call is like free and does not have a failure return.
1021 */
1022 extern void halide_memoization_cache_release(void *user_context, void *host);
1023
1024/** Free all memory and resources associated with the memoization cache.
1025 * Must be called at a time when no other threads are accessing the cache.
1026 */
1027 extern void halide_memoization_cache_cleanup(void);
1028
1029/** Verify that a given range of memory has been initialized; only used when Target::MSAN is enabled.
1030 *
1031 * The default implementation simply calls the LLVM-provided __msan_check_mem_is_initialized() function.
1032 *
1033 * The return value should always be zero.
1034 */
1035 extern int halide_msan_check_memory_is_initialized(void *user_context, const void *ptr, uint64_t len, const char *name);
1036
1037/** Verify that the data pointed to by the halide_buffer_t is initialized (but *not* the halide_buffer_t itself),
1038 * using halide_msan_check_memory_is_initialized() for checking.
1039 *
1040 * The default implementation takes pains to only check the active memory ranges
1041 * (skipping padding), and sorting into ranges to always check the smallest number of
1042 * ranges, in monotonically increasing memory order.
1043 *
1044 * Most client code should never need to replace the default implementation.
1045 *
1046 * The return value should always be zero.
1047 */
1048 extern int halide_msan_check_buffer_is_initialized(void *user_context, struct halide_buffer_t *buffer, const char *buf_name);
1049
1050/** Annotate that a given range of memory has been initialized;
1051 * only used when Target::MSAN is enabled.
1052 *
1053 * The default implementation simply calls the LLVM-provided __msan_unpoison() function.
1054 *
1055 * The return value should always be zero.
1056 */
1057 extern int halide_msan_annotate_memory_is_initialized(void *user_context, const void *ptr, uint64_t len);
1058
1059/** Mark the data pointed to by the halide_buffer_t as initialized (but *not* the halide_buffer_t itself),
1060 * using halide_msan_annotate_memory_is_initialized() for marking.
1061 *
1062 * The default implementation takes pains to only mark the active memory ranges
1063 * (skipping padding), and sorting into ranges to always mark the smallest number of
1064 * ranges, in monotonically increasing memory order.
1065 *
1066 * Most client code should never need to replace the default implementation.
1067 *
1068 * The return value should always be zero.
1069 */
1070 extern int halide_msan_annotate_buffer_is_initialized(void *user_context, struct halide_buffer_t *buffer);
1071 extern void halide_msan_annotate_buffer_is_initialized_as_destructor(void *user_context, void *buffer);
1072
1073/** The error codes that may be returned by a Halide pipeline. */
1074 enum halide_error_code_t {
1075 /** There was no error. This is the value returned by Halide on success. */
1076 halide_error_code_success = 0,
1077
1078 /** An uncategorized error occurred. Refer to the string passed to halide_error. */
1079 halide_error_code_generic_error = -1,
1080
1081 /** A Func was given an explicit bound via Func::bound, but this
1082 * was not large enough to encompass the region that is used of
1083 * the Func by the rest of the pipeline. */
1084 halide_error_code_explicit_bounds_too_small = -2,
1085
1086 /** The elem_size field of a halide_buffer_t does not match the size in
1087 * bytes of the type of that ImageParam. Probable type mismatch. */
1088 halide_error_code_bad_type = -3,
1089
1090 /** A pipeline would access memory outside of the halide_buffer_t passed
1091 * in. */
1092 halide_error_code_access_out_of_bounds = -4,
1093
1094 /** A halide_buffer_t was given that spans more than 2GB of memory. */
1095 halide_error_code_buffer_allocation_too_large = -5,
1096
1097 /** A halide_buffer_t was given with extents that multiply to a number
1098 * greater than 2^31-1 */
1099 halide_error_code_buffer_extents_too_large = -6,
1100
1101 /** Applying explicit constraints on the size of an input or
1102 * output buffer shrank the size of that buffer below what will be
1103 * accessed by the pipeline. */
1104 halide_error_code_constraints_make_required_region_smaller = -7,
1105
1106 /** A constraint on a size or stride of an input or output buffer
1107 * was not met by the halide_buffer_t passed in. */
1108 halide_error_code_constraint_violated = -8,
1109
1110 /** A scalar parameter passed in was smaller than its minimum
1111 * declared value. */
1112 halide_error_code_param_too_small = -9,
1113
1114 /** A scalar parameter passed in was greater than its minimum
1115 * declared value. */
1116 halide_error_code_param_too_large = -10,
1117
1118 /** A call to halide_malloc returned NULL. */
1119 halide_error_code_out_of_memory = -11,
1120
1121 /** A halide_buffer_t pointer passed in was NULL. */
1122 halide_error_code_buffer_argument_is_null = -12,
1123
1124 /** debug_to_file failed to open or write to the specified
1125 * file. */
1126 halide_error_code_debug_to_file_failed = -13,
1127
1128 /** The Halide runtime encountered an error while trying to copy
1129 * from device to host. Turn on -debug in your target string to
1130 * see more details. */
1131 halide_error_code_copy_to_host_failed = -14,
1132
1133 /** The Halide runtime encountered an error while trying to copy
1134 * from host to device. Turn on -debug in your target string to
1135 * see more details. */
1136 halide_error_code_copy_to_device_failed = -15,
1137
1138 /** The Halide runtime encountered an error while trying to
1139 * allocate memory on device. Turn on -debug in your target string
1140 * to see more details. */
1141 halide_error_code_device_malloc_failed = -16,
1142
1143 /** The Halide runtime encountered an error while trying to
1144 * synchronize with a device. Turn on -debug in your target string
1145 * to see more details. */
1146 halide_error_code_device_sync_failed = -17,
1147
1148 /** The Halide runtime encountered an error while trying to free a
1149 * device allocation. Turn on -debug in your target string to see
1150 * more details. */
1151 halide_error_code_device_free_failed = -18,
1152
1153 /** Buffer has a non-zero device but no device interface, which
1154 * violates a Halide invariant. */
1155 halide_error_code_no_device_interface = -19,
1156
1157 /** This part of the Halide runtime is unimplemented on this platform. */
1158 halide_error_code_unimplemented = -20,
1159
1160 /** A runtime symbol could not be loaded. */
1161 halide_error_code_symbol_not_found = -21,
1162
1163 /** There is a bug in the Halide compiler. */
1164 halide_error_code_internal_error = -22,
1165
1166 /** The Halide runtime encountered an error while trying to launch
1167 * a GPU kernel. Turn on -debug in your target string to see more
1168 * details. */
1169 halide_error_code_device_run_failed = -23,
1170
1171 /** The Halide runtime encountered a host pointer that violated
1172 * the alignment set for it by way of a call to
1173 * set_host_alignment */
1174 halide_error_code_unaligned_host_ptr = -24,
1175
1176 /** A fold_storage directive was used on a dimension that is not
1177 * accessed in a monotonically increasing or decreasing fashion. */
1178 halide_error_code_bad_fold = -25,
1179
1180 /** A fold_storage directive was used with a fold factor that was
1181 * too small to store all the values of a producer needed by the
1182 * consumer. */
1183 halide_error_code_fold_factor_too_small = -26,
1184
1185 /** User-specified require() expression was not satisfied. */
1186 halide_error_code_requirement_failed = -27,
1187
1188 /** At least one of the buffer's extents are negative. */
1189 halide_error_code_buffer_extents_negative = -28,
1190
1191 /** Call(s) to a GPU backend API failed. */
1192 halide_error_code_gpu_device_error = -29,
1193
1194 /** Failure recording trace packets for one of the halide_target_feature_trace features. */
1195 halide_error_code_trace_failed = -30,
1196
1197 /** A specialize_fail() schedule branch was selected at runtime. */
1198 halide_error_code_specialize_fail = -31,
1199
1200 /** The Halide runtime encountered an error while trying to wrap a
1201 * native device handle. Turn on -debug in your target string to
1202 * see more details. */
1203 halide_error_code_device_wrap_native_failed = -32,
1204
1205 /** The Halide runtime encountered an error while trying to detach
1206 * a native device handle. Turn on -debug in your target string
1207 * to see more details. */
1208 halide_error_code_device_detach_native_failed = -33,
1209
1210 /** The host field on an input or output was null, the device
1211 * field was not zero, and the pipeline tries to use the buffer on
1212 * the host. You may be passing a GPU-only buffer to a pipeline
1213 * which is scheduled to use it on the CPU. */
1214 halide_error_code_host_is_null = -34,
1215
1216 /** A folded buffer was passed to an extern stage, but the region
1217 * touched wraps around the fold boundary. */
1218 halide_error_code_bad_extern_fold = -35,
1219
1220 /** Buffer has a non-null device_interface but device is 0, which
1221 * violates a Halide invariant. */
1222 halide_error_code_device_interface_no_device = -36,
1223
1224 /** Buffer has both host and device dirty bits set, which violates
1225 * a Halide invariant. */
1226 halide_error_code_host_and_device_dirty = -37,
1227
1228 /** The halide_buffer_t * passed to a halide runtime routine is
1229 * nullptr and this is not allowed. */
1230 halide_error_code_buffer_is_null = -38,
1231
1232 /** The Halide runtime encountered an error while trying to copy
1233 * from one buffer to another. Turn on -debug in your target
1234 * string to see more details. */
1235 halide_error_code_device_buffer_copy_failed = -39,
1236
1237 /** Attempted to make cropped/sliced alias of a buffer with a device
1238 * field, but the device_interface does not support cropping. */
1239 halide_error_code_device_crop_unsupported = -40,
1240
1241 /** Cropping/slicing a buffer failed for some other reason. Turn on -debug
1242 * in your target string. */
1243 halide_error_code_device_crop_failed = -41,
1244
1245 /** An operation on a buffer required an allocation on a
1246 * particular device interface, but a device allocation already
1247 * existed on a different device interface. Free the old one
1248 * first. */
1249 halide_error_code_incompatible_device_interface = -42,
1250
1251 /** The dimensions field of a halide_buffer_t does not match the dimensions of that ImageParam. */
1252 halide_error_code_bad_dimensions = -43,
1253
1254 /** A buffer with the device_dirty flag set was passed to a
1255 * pipeline compiled with no device backends enabled, so it
1256 * doesn't know how to copy the data back from device memory to
1257 * host memory. Either call copy_to_host before calling the Halide
1258 * pipeline, or enable the appropriate device backend. */
1259 halide_error_code_device_dirty_with_no_device_support = -44,
1260
1261 /** An explicit storage bound provided is too small to store
1262 * all the values produced by the function. */
1263 halide_error_code_storage_bound_too_small = -45,
1264
1265 /** A factor used to split a loop was discovered to be zero or negative at
1266 * runtime. */
1267 halide_error_code_split_factor_not_positive = -46,
1268
1269 /** "vscale" value of Scalable Vector detected in runtime does not match
1270 * the vscale value used in compilation. */
1271 halide_error_code_vscale_invalid = -47,
1272
1273 /** Profiling failed for a pipeline invocation. */
1274 halide_error_code_cannot_profile_pipeline = -48,
1275};
1276
1277/** Halide calls the functions below on various error conditions. The
1278 * default implementations construct an error message, call
1279 * halide_error, then return the matching error code above. On
1280 * platforms that support weak linking, you can override these to
1281 * catch the errors individually. */
1282
1283/** A call into an extern stage for the purposes of bounds inference
1284 * failed. Returns the error code given by the extern stage. */
1285 extern int halide_error_bounds_inference_call_failed(void *user_context, const char *extern_stage_name, int result);
1286
1287/** A call to an extern stage failed. Returned the error code given by
1288 * the extern stage. */
1289 extern int halide_error_extern_stage_failed(void *user_context, const char *extern_stage_name, int result);
1290
1291/** Various other error conditions. See the enum above for a
1292 * description of each. */
1293// @{
1294 extern int halide_error_explicit_bounds_too_small(void *user_context, const char *func_name, const char *var_name,
1295 int min_bound, int max_bound, int min_required, int max_required);
1296 extern int halide_error_bad_type(void *user_context, const char *func_name,
1297 uint32_t type_given, uint32_t correct_type); // N.B. The last two args are the bit representation of a halide_type_t
1298 extern int halide_error_bad_dimensions(void *user_context, const char *func_name,
1299 int32_t dimensions_given, int32_t correct_dimensions);
1300 extern int halide_error_access_out_of_bounds(void *user_context, const char *func_name,
1301 int dimension, int min_touched, int max_touched,
1302 int min_valid, int max_valid);
1303 extern int halide_error_buffer_allocation_too_large(void *user_context, const char *buffer_name,
1304 uint64_t allocation_size, uint64_t max_size);
1305 extern int halide_error_buffer_extents_negative(void *user_context, const char *buffer_name, int dimension, int extent);
1306 extern int halide_error_buffer_extents_too_large(void *user_context, const char *buffer_name,
1307 int64_t actual_size, int64_t max_size);
1308 extern int halide_error_constraints_make_required_region_smaller(void *user_context, const char *buffer_name,
1309 int dimension,
1310 int constrained_min, int constrained_extent,
1311 int required_min, int required_extent);
1312 extern int halide_error_constraint_violated(void *user_context, const char *var, int val,
1313 const char *constrained_var, int constrained_val);
1314 extern int halide_error_param_too_small_i64(void *user_context, const char *param_name,
1315 int64_t val, int64_t min_val);
1316 extern int halide_error_param_too_small_u64(void *user_context, const char *param_name,
1317 uint64_t val, uint64_t min_val);
1318 extern int halide_error_param_too_small_f64(void *user_context, const char *param_name,
1319 double val, double min_val);
1320 extern int halide_error_param_too_large_i64(void *user_context, const char *param_name,
1321 int64_t val, int64_t max_val);
1322 extern int halide_error_param_too_large_u64(void *user_context, const char *param_name,
1323 uint64_t val, uint64_t max_val);
1324 extern int halide_error_param_too_large_f64(void *user_context, const char *param_name,
1325 double val, double max_val);
1326 extern int halide_error_out_of_memory(void *user_context);
1327 extern int halide_error_buffer_argument_is_null(void *user_context, const char *buffer_name);
1328 extern int halide_error_debug_to_file_failed(void *user_context, const char *func,
1329 const char *filename, int error_code);
1330 extern int halide_error_unaligned_host_ptr(void *user_context, const char *func_name, int alignment);
1331 extern int halide_error_host_is_null(void *user_context, const char *func_name);
1332 extern int halide_error_bad_fold(void *user_context, const char *func_name, const char *var_name,
1333 const char *loop_name);
1334 extern int halide_error_bad_extern_fold(void *user_context, const char *func_name,
1335 int dim, int min, int extent, int valid_min, int fold_factor);
1336
1337 extern int halide_error_fold_factor_too_small(void *user_context, const char *func_name, const char *var_name,
1338 int fold_factor, const char *loop_name, int required_extent);
1339 extern int halide_error_requirement_failed(void *user_context, const char *condition, const char *message);
1340 extern int halide_error_specialize_fail(void *user_context, const char *message);
1341 extern int halide_error_no_device_interface(void *user_context);
1342 extern int halide_error_device_interface_no_device(void *user_context);
1343 extern int halide_error_host_and_device_dirty(void *user_context);
1344 extern int halide_error_buffer_is_null(void *user_context, const char *routine);
1345 extern int halide_error_device_dirty_with_no_device_support(void *user_context, const char *buffer_name);
1346 extern int halide_error_storage_bound_too_small(void *user_context, const char *func_name, const char *var_name,
1347 int provided_size, int required_size);
1348 extern int halide_error_device_crop_failed(void *user_context);
1349 extern int halide_error_split_factor_not_positive(void *user_context, const char *func_name, const char *orig, const char *outer, const char *inner, const char *factor_str, int factor);
1350 extern int halide_error_vscale_invalid(void *user_context, const char *func_name, int runtime_vscale, int compiletime_vscale);
1351// @}
1352
1353/** Optional features a compilation Target can have.
1354 *
1355 * Be sure to keep this in sync with:
1356 * 1. the Feature enum in Target.h,
1357 * 2. the implementation of get_runtime_compatible_target in Target.cpp,
1358 * 3. PyEnums.cpp,
1359 * if you add a new feature.
1360 */
1361 typedef enum halide_target_feature_t {
1362 halide_target_feature_jit = 0, ///< Generate code that will run immediately inside the calling process.
1363 halide_target_feature_debug, ///< Turn on debug info and output for runtime code.
1364 halide_target_feature_enable_backtraces, ///< Preserve frame pointers and include unwind tables to support accurate backtraces for debugging and profiling.
1365 halide_target_feature_no_asserts, ///< Disable all runtime checks, for slightly tighter code.
1366 halide_target_feature_no_bounds_query, ///< Disable the bounds querying functionality.
1367
1368 halide_target_feature_sse41, ///< Use SSE 4.1 and earlier instructions. Only relevant on x86.
1369 halide_target_feature_avx, ///< Use AVX 1 instructions. Only relevant on x86.
1370 halide_target_feature_avx2, ///< Use AVX 2 instructions. Only relevant on x86.
1371 halide_target_feature_avxvnni, ///< Enable the AVX-VNNI features supported by AVX2 instructions. Supports 256-bit VNNI instructions without EVEX encoding.
1372 halide_target_feature_fma, ///< Enable x86 FMA instruction
1373 halide_target_feature_fma4, ///< Enable x86 (AMD) FMA4 instruction set
1374 halide_target_feature_f16c, ///< Enable x86 16-bit float support
1375
1376 halide_target_feature_armv7s, ///< Generate code for ARMv7s. Only relevant for 32-bit ARM.
1377 halide_target_feature_no_neon, ///< Avoid using NEON instructions. Only relevant for 32-bit ARM.
1378
1379 halide_target_feature_vsx, ///< Use VSX instructions. Only relevant on POWERPC.
1380 halide_target_feature_power_arch_2_07, ///< Use POWER ISA 2.07 new instructions. Only relevant on POWERPC.
1381
1382 halide_target_feature_cuda, ///< Enable the CUDA runtime. Defaults to compute capability 2.0 (Fermi)
1383 halide_target_feature_cuda_capability30, ///< Enable CUDA compute capability 3.0 (Kepler)
1384 halide_target_feature_cuda_capability32, ///< Enable CUDA compute capability 3.2 (Tegra K1)
1385 halide_target_feature_cuda_capability35, ///< Enable CUDA compute capability 3.5 (Kepler)
1386 halide_target_feature_cuda_capability50, ///< Enable CUDA compute capability 5.0 (Maxwell)
1387 halide_target_feature_cuda_capability61, ///< Enable CUDA compute capability 6.1 (Pascal)
1388 halide_target_feature_cuda_capability70, ///< Enable CUDA compute capability 7.0 (Volta)
1389 halide_target_feature_cuda_capability75, ///< Enable CUDA compute capability 7.5 (Turing)
1390 halide_target_feature_cuda_capability80, ///< Enable CUDA compute capability 8.0 (Ampere)
1391 halide_target_feature_cuda_capability86, ///< Enable CUDA compute capability 8.6 (Ampere)
1392
1393 halide_target_feature_opencl, ///< Enable the OpenCL runtime.
1394 halide_target_feature_cl_doubles, ///< Enable double support on OpenCL targets
1395 halide_target_feature_cl_atomic64, ///< Enable 64-bit atomics operations on OpenCL targets
1396
1397 halide_target_feature_user_context, ///< Generated code takes a user_context pointer as first argument
1398
1399 halide_target_feature_profile, ///< Launch a sampling profiler alongside the Halide pipeline that monitors and reports the runtime used by each Func
1400 halide_target_feature_no_runtime, ///< Do not include a copy of the Halide runtime in any generated object file or assembly
1401
1402 halide_target_feature_metal, ///< Enable the (Apple) Metal runtime.
1403
1404 halide_target_feature_c_plus_plus_mangling, ///< Generate C++ mangled names for result function, et al
1405
1406 halide_target_feature_large_buffers, ///< Enable 64-bit buffer indexing to support buffers > 2GB. Ignored if bits != 64.
1407
1408 halide_target_feature_hvx_128, ///< Enable HVX 128 byte mode.
1409 halide_target_feature_hvx_v62, ///< Enable Hexagon v62 architecture.
1410 halide_target_feature_fuzz_float_stores, ///< On every floating point store, set the last bit of the mantissa to zero. Pipelines for which the output is very different with this feature enabled may also produce very different output on different processors.
1411 halide_target_feature_soft_float_abi, ///< Enable soft float ABI. This only enables the soft float ABI calling convention, which does not necessarily use soft floats.
1412 halide_target_feature_msan, ///< Enable hooks for MSAN support.
1413 halide_target_feature_avx512, ///< Enable the base AVX512 subset supported by all AVX512 architectures. The specific feature sets are AVX-512F and AVX512-CD. See https://en.wikipedia.org/wiki/AVX-512 for a description of each AVX subset.
1414 halide_target_feature_avx512_knl, ///< Enable the AVX512 features supported by Knight's Landing chips, such as the Xeon Phi x200. This includes the base AVX512 set, and also AVX512-CD and AVX512-ER.
1415 halide_target_feature_avx512_skylake, ///< Enable the AVX512 features supported by Skylake Xeon server processors. This adds AVX512-VL, AVX512-BW, and AVX512-DQ to the base set. The main difference from the base AVX512 set is better support for small integer ops. Note that this does not include the Knight's Landing features. Note also that these features are not available on Skylake desktop and mobile processors.
1416 halide_target_feature_avx512_cannonlake, ///< Enable the AVX512 features expected to be supported by future Cannonlake processors. This includes all of the Skylake features, plus AVX512-IFMA and AVX512-VBMI.
1417 halide_target_feature_avx512_zen4, ///< Enable the AVX512 features supported by Zen4 processors. This include all of the Cannonlake features, plus AVX512-VNNI, AVX512-BF16, and more.
1418 halide_target_feature_avx512_zen5, ///< Enable the AVX512 features supported by Zen5 processors. This include all of the Cannonlake features, plus AVX512-VNNI, AVX512-BF16, AVX-VNNI and more.
1419 halide_target_feature_avx512_sapphirerapids, ///< Enable the AVX512 features supported by Sapphire Rapids processors. This include all of the Zen4 features, plus AVX-VNNI and AMX instructions.
1420 halide_target_feature_trace_loads, ///< Trace all loads done by the pipeline. Equivalent to calling Func::trace_loads on every non-inlined Func.
1421 halide_target_feature_trace_stores, ///< Trace all stores done by the pipeline. Equivalent to calling Func::trace_stores on every non-inlined Func.
1422 halide_target_feature_trace_realizations, ///< Trace all realizations done by the pipeline. Equivalent to calling Func::trace_realizations on every non-inlined Func.
1423 halide_target_feature_trace_pipeline, ///< Trace the pipeline.
1424 halide_target_feature_hvx_v65, ///< Enable Hexagon v65 architecture.
1425 halide_target_feature_hvx_v66, ///< Enable Hexagon v66 architecture.
1426 halide_target_feature_hvx_v68, ///< Enable Hexagon v68 architecture.
1427 halide_target_feature_cl_half, ///< Enable half support on OpenCL targets
1428 halide_target_feature_strict_float, ///< Turn off all non-IEEE floating-point optimization. Currently applies only to LLVM targets.
1429 halide_target_feature_tsan, ///< Enable hooks for TSAN support.
1430 halide_target_feature_asan, ///< Enable hooks for ASAN support.
1431 halide_target_feature_d3d12compute, ///< Enable Direct3D 12 Compute runtime.
1432 halide_target_feature_check_unsafe_promises, ///< Insert assertions for promises.
1433 halide_target_feature_hexagon_dma, ///< Enable Hexagon DMA buffers.
1434 halide_target_feature_embed_bitcode, ///< Emulate clang -fembed-bitcode flag.
1435 halide_target_feature_enable_llvm_loop_opt, ///< Enable loop vectorization + unrolling in LLVM. Overrides halide_target_feature_disable_llvm_loop_opt. (Ignored for non-LLVM targets.)
1436 halide_target_feature_wasm_mvponly, ///< Disable all extensions to WebAssembly codegen (including +sign-ext and +nontrapping-fptoint, which are on by default).
1437 halide_target_feature_wasm_simd128, ///< Enable +simd128 instructions for WebAssembly codegen.
1438 halide_target_feature_wasm_threads, ///< Enable use of threads in WebAssembly codegen. Requires the use of a wasm runtime that provides pthread-compatible wrappers (typically, Emscripten with the -pthreads flag). Unsupported under WASI.
1439 halide_target_feature_wasm_bulk_memory, ///< Enable +bulk-memory instructions for WebAssembly codegen.
1440 halide_target_feature_webgpu, ///< Enable the WebGPU runtime.
1441 halide_target_feature_sve, ///< Enable ARM Scalable Vector Extensions
1442 halide_target_feature_sve2, ///< Enable ARM Scalable Vector Extensions v2
1443 halide_target_feature_egl, ///< Force use of EGL support.
1444 halide_target_feature_arm_dot_prod, ///< Enable ARMv8.2-a dotprod extension (i.e. udot and sdot instructions)
1445 halide_target_feature_arm_fp16, ///< Enable ARMv8.2-a half-precision floating point data processing
1446 halide_llvm_large_code_model, ///< Use the LLVM large code model to compile
1447 halide_target_feature_rvv, ///< Enable RISCV "V" Vector Extension
1448 halide_target_feature_armv8a, ///< Enable ARMv8a instructions
1449 halide_target_feature_armv81a, ///< Enable ARMv8.1a instructions
1450 halide_target_feature_armv82a, ///< Enable ARMv8.2a instructions
1451 halide_target_feature_armv83a, ///< Enable ARMv8.3a instructions
1452 halide_target_feature_armv84a, ///< Enable ARMv8.4a instructions
1453 halide_target_feature_armv85a, ///< Enable ARMv8.5a instructions
1454 halide_target_feature_armv86a, ///< Enable ARMv8.6a instructions
1455 halide_target_feature_armv87a, ///< Enable ARMv8.7a instructions
1456 halide_target_feature_armv88a, ///< Enable ARMv8.8a instructions
1457 halide_target_feature_armv89a, ///< Enable ARMv8.9a instructions
1458 halide_target_feature_sanitizer_coverage, ///< Enable hooks for SanitizerCoverage support.
1459 halide_target_feature_profile_by_timer, ///< Alternative to halide_target_feature_profile using timer interrupt for systems without threads or applicartions that need to avoid them.
1460 halide_target_feature_spirv, ///< Enable SPIR-V code generation support.
1461 halide_target_feature_vulkan, ///< Enable Vulkan runtime support.
1462 halide_target_feature_vulkan_int8, ///< Enable Vulkan 8-bit integer support.
1463 halide_target_feature_vulkan_int16, ///< Enable Vulkan 16-bit integer support.
1464 halide_target_feature_vulkan_int64, ///< Enable Vulkan 64-bit integer support.
1465 halide_target_feature_vulkan_float16, ///< Enable Vulkan 16-bit float support.
1466 halide_target_feature_vulkan_float64, ///< Enable Vulkan 64-bit float support.
1467 halide_target_feature_vulkan_version10, ///< Enable Vulkan v1.0 runtime target support.
1468 halide_target_feature_vulkan_version12, ///< Enable Vulkan v1.2 runtime target support.
1469 halide_target_feature_vulkan_version13, ///< Enable Vulkan v1.3 runtime target support.
1470 halide_target_feature_semihosting, ///< Used together with Target::NoOS for the baremetal target built with semihosting library and run with semihosting mode where minimum I/O communication with a host PC is available.
1471 halide_target_feature_avx10_1, ///< Intel AVX10 version 1 support. vector_bits is used to indicate width.
1472 halide_target_feature_x86_apx, ///< Intel x86 APX support. Covers initial set of features released as APX: egpr,push2pop2,ppx,ndd .
1473 halide_target_feature_simulator, ///< Target is for a simulator environment. Currently only applies to iOS.
1474 halide_target_feature_end ///< A sentinel. Every target is considered to have this feature, and setting this feature does nothing.
1475} halide_target_feature_t;
1476
1477/** This function is called internally by Halide in some situations to determine
1478 * if the current execution environment can support the given set of
1479 * halide_target_feature_t flags. The implementation must do the following:
1480 *
1481 * -- If there are flags set in features that the function knows *cannot* be supported, return 0.
1482 * -- Otherwise, return 1.
1483 * -- Note that any flags set in features that the function doesn't know how to test should be ignored;
1484 * this implies that a return value of 1 means "not known to be bad" rather than "known to be good".
1485 *
1486 * In other words: a return value of 0 means "It is not safe to use code compiled with these features",
1487 * while a return value of 1 means "It is not obviously unsafe to use code compiled with these features".
1488 *
1489 * The default implementation simply calls halide_default_can_use_target_features.
1490 *
1491 * Note that `features` points to an array of `count` uint64_t; this array must contain enough
1492 * bits to represent all the currently known features. Any excess bits must be set to zero.
1493 */
1494// @{
1495 extern int halide_can_use_target_features(int count, const uint64_t *features);
1496 typedef int (*halide_can_use_target_features_t)(int count, const uint64_t *features);
1497 extern halide_can_use_target_features_t halide_set_custom_can_use_target_features(halide_can_use_target_features_t);
1498// @}
1499
1500/**
1501 * This is the default implementation of halide_can_use_target_features; it is provided
1502 * for convenience of user code that may wish to extend halide_can_use_target_features
1503 * but continue providing existing support, e.g.
1504 *
1505 * int halide_can_use_target_features(int count, const uint64_t *features) {
1506 * if (features[halide_target_somefeature >> 6] & (1LL << (halide_target_somefeature & 63))) {
1507 * if (!can_use_somefeature()) {
1508 * return 0;
1509 * }
1510 * }
1511 * return halide_default_can_use_target_features(count, features);
1512 * }
1513 */
1514 extern int halide_default_can_use_target_features(int count, const uint64_t *features);
1515
1516 typedef struct halide_dimension_t {
1517#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
1518 int32_t min = 0, extent = 0, stride = 0;
1519
1520 // Per-dimension flags. None are defined yet (This is reserved for future use).
1521 uint32_t flags = 0;
1522
1523 HALIDE_ALWAYS_INLINE halide_dimension_t() = default;
1524 HALIDE_ALWAYS_INLINE halide_dimension_t(int32_t m, int32_t e, int32_t s, uint32_t f = 0)
1525 : min(m), extent(e), stride(s), flags(f) {
1526 }
1527
1528 HALIDE_ALWAYS_INLINE bool operator==(const halide_dimension_t &other) const {
1529 return (min == other.min) &&
1530 (extent == other.extent) &&
1531 (stride == other.stride) &&
1532 (flags == other.flags);
1533 }
1534
1535 HALIDE_ALWAYS_INLINE bool operator!=(const halide_dimension_t &other) const {
1536 return !(*this == other);
1537 }
1538#else
1539 int32_t min, extent, stride;
1540
1541 // Per-dimension flags. None are defined yet (This is reserved for future use).
1542 uint32_t flags;
1543#endif
1544} halide_dimension_t;
1545
1546#ifdef __cplusplus
1547} // extern "C"
1548#endif
1549
1550#if __cplusplus > 201100L || _MSVC_LANG > 201100L || __STDC_VERSION__ > 202300L
1551// In C++, an underlying type is required to let the user define their own flag
1552// values, without those values being undefined behavior when passed around as
1553// this enum typedef.
1554#define BUFFER_FLAGS_UNDERLYING_TYPE : uint64_t
1555#else
1556#define BUFFER_FLAGS_UNDERLYING_TYPE
1557#endif
1558 typedef enum BUFFER_FLAGS_UNDERLYING_TYPE {
1559 halide_buffer_flag_host_dirty = 1,
1560 halide_buffer_flag_device_dirty = 2
1561} halide_buffer_flags;
1562#undef BUFFER_FLAGS_UNDERLYING_TYPE
1563
1564/**
1565 * The raw representation of an image passed around by generated
1566 * Halide code. It includes some stuff to track whether the image is
1567 * not actually in main memory, but instead on a device (like a
1568 * GPU). For a more convenient C++ wrapper, use Halide::Buffer<T>. */
1569 typedef struct halide_buffer_t {
1570 /** A device-handle for e.g. GPU memory used to back this buffer. */
1571 uint64_t device;
1572
1573 /** The interface used to interpret the above handle. */
1574 const struct halide_device_interface_t *device_interface;
1575
1576 /** A pointer to the start of the data in main memory. In terms of
1577 * the Halide coordinate system, this is the address of the min
1578 * coordinates (defined below). */
1579 uint8_t *host;
1580
1581 /** flags with various meanings. */
1582 uint64_t flags;
1583
1584 /** The type of each buffer element. */
1585 struct halide_type_t type;
1586
1587 /** The dimensionality of the buffer. */
1588 int32_t dimensions;
1589
1590 /** The shape of the buffer. Halide does not own this array - you
1591 * must manage the memory for it yourself. */
1592 halide_dimension_t *dim;
1593
1594 /** Pads the buffer up to a multiple of 8 bytes */
1595 void *padding;
1596
1597#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
1598 /** Convenience methods for accessing the flags */
1599 // @{
1600 HALIDE_ALWAYS_INLINE bool get_flag(halide_buffer_flags flag) const {
1601 return (flags & flag) != 0;
1602 }
1603
1604 HALIDE_ALWAYS_INLINE void set_flag(halide_buffer_flags flag, bool value) {
1605 if (value) {
1606 flags |= flag;
1607 } else {
1608 flags &= ~uint64_t(flag);
1609 }
1610 }
1611
1612 HALIDE_MUST_USE_RESULT HALIDE_ALWAYS_INLINE bool host_dirty() const {
1613 return get_flag(halide_buffer_flag_host_dirty);
1614 }
1615
1616 HALIDE_MUST_USE_RESULT HALIDE_ALWAYS_INLINE bool device_dirty() const {
1617 return get_flag(halide_buffer_flag_device_dirty);
1618 }
1619
1620 HALIDE_ALWAYS_INLINE void set_host_dirty(bool v = true) {
1621 set_flag(halide_buffer_flag_host_dirty, v);
1622 }
1623
1624 HALIDE_ALWAYS_INLINE void set_device_dirty(bool v = true) {
1625 set_flag(halide_buffer_flag_device_dirty, v);
1626 }
1627 // @}
1628
1629 /** The total number of elements this buffer represents. Equal to
1630 * the product of the extents */
1631 HALIDE_ALWAYS_INLINE size_t number_of_elements() const {
1632 size_t s = 1;
1633 for (int i = 0; i < dimensions; i++) {
1634 s *= dim[i].extent;
1635 }
1636 return s;
1637 }
1638
1639 /** Offset to the element with the lowest address.
1640 * If all strides are positive, equal to zero.
1641 * Offset is in elements, not bytes.
1642 * Unlike begin(), this is ok to call on an unallocated buffer. */
1643 HALIDE_ALWAYS_INLINE ptrdiff_t begin_offset() const {
1644 ptrdiff_t index = 0;
1645 for (int i = 0; i < dimensions; i++) {
1646 const int stride = dim[i].stride;
1647 if (stride < 0) {
1648 index += stride * (ptrdiff_t)(dim[i].extent - 1);
1649 }
1650 }
1651 return index;
1652 }
1653
1654 /** An offset to one beyond the element with the highest address.
1655 * Offset is in elements, not bytes.
1656 * Unlike end(), this is ok to call on an unallocated buffer. */
1657 HALIDE_ALWAYS_INLINE ptrdiff_t end_offset() const {
1658 ptrdiff_t index = 0;
1659 for (int i = 0; i < dimensions; i++) {
1660 const int stride = dim[i].stride;
1661 if (stride > 0) {
1662 index += stride * (ptrdiff_t)(dim[i].extent - 1);
1663 }
1664 }
1665 index += 1;
1666 return index;
1667 }
1668
1669 /** A pointer to the element with the lowest address.
1670 * If all strides are positive, equal to the host pointer.
1671 * Illegal to call on an unallocated buffer. */
1672 HALIDE_ALWAYS_INLINE uint8_t *begin() const {
1673 return host + begin_offset() * type.bytes();
1674 }
1675
1676 /** A pointer to one beyond the element with the highest address.
1677 * Illegal to call on an unallocated buffer. */
1678 HALIDE_ALWAYS_INLINE uint8_t *end() const {
1679 return host + end_offset() * type.bytes();
1680 }
1681
1682 /** The total number of bytes spanned by the data in memory. */
1683 HALIDE_ALWAYS_INLINE size_t size_in_bytes() const {
1684 return (size_t)(end_offset() - begin_offset()) * type.bytes();
1685 }
1686
1687 /** A pointer to the element at the given location. */
1688 HALIDE_ALWAYS_INLINE uint8_t *address_of(const int *pos) const {
1689 ptrdiff_t index = 0;
1690 for (int i = 0; i < dimensions; i++) {
1691 index += (ptrdiff_t)dim[i].stride * (pos[i] - dim[i].min);
1692 }
1693 return host + index * type.bytes();
1694 }
1695
1696 /** Attempt to call device_sync for the buffer. If the buffer
1697 * has no device_interface (or no device_sync), this is a quiet no-op.
1698 * Calling this explicitly should rarely be necessary, except for profiling. */
1699 HALIDE_ALWAYS_INLINE int device_sync(void *ctx = nullptr) {
1700 if (device_interface && device_interface->device_sync) {
1701 return device_interface->device_sync(ctx, this);
1702 }
1703 return 0;
1704 }
1705
1706 /** Check if an input buffer passed extern stage is a querying
1707 * bounds. Compared to doing the host pointer check directly,
1708 * this both adds clarity to code and will facilitate moving to
1709 * another representation for bounds query arguments. */
1710 HALIDE_ALWAYS_INLINE bool is_bounds_query() const {
1711 return host == nullptr && device == 0;
1712 }
1713
1714#endif
1715} halide_buffer_t;
1716
1717#ifdef __cplusplus
1718 extern "C" {
1719#endif
1720
1721#ifndef HALIDE_ATTRIBUTE_DEPRECATED
1722#ifdef HALIDE_ALLOW_DEPRECATED
1723#define HALIDE_ATTRIBUTE_DEPRECATED(x)
1724#else
1725#ifdef _MSC_VER
1726#define HALIDE_ATTRIBUTE_DEPRECATED(x) __declspec(deprecated(x))
1727#else
1728#define HALIDE_ATTRIBUTE_DEPRECATED(x) __attribute__((deprecated(x)))
1729#endif
1730#endif
1731#endif
1732
1733/** halide_scalar_value_t is a simple union able to represent all the well-known
1734 * scalar values in a filter argument. Note that it isn't tagged with a type;
1735 * you must ensure you know the proper type before accessing. Most user
1736 * code will never need to create instances of this struct; its primary use
1737 * is to hold def/min/max values in a halide_filter_argument_t. (Note that
1738 * this is conceptually just a union; it's wrapped in a struct to ensure
1739 * that it doesn't get anonymized by LLVM.)
1740 */
1741 struct halide_scalar_value_t {
1742 union {
1743 bool b;
1744 int8_t i8;
1745 int16_t i16;
1746 int32_t i32;
1747 int64_t i64;
1748 uint8_t u8;
1749 uint16_t u16;
1750 uint32_t u32;
1751 uint64_t u64;
1752 float f32;
1753 double f64;
1754 void *handle;
1755 } u;
1756#ifdef __cplusplus
1757 HALIDE_ALWAYS_INLINE halide_scalar_value_t() {
1758 u.u64 = 0;
1759 }
1760#endif
1761};
1762
1763 enum halide_argument_kind_t {
1764 halide_argument_kind_input_scalar = 0,
1765 halide_argument_kind_input_buffer = 1,
1766 halide_argument_kind_output_buffer = 2
1767};
1768
1769/*
1770 These structs must be robust across different compilers and settings; when
1771 modifying them, strive for the following rules:
1772
1773 1) All fields are explicitly sized. I.e. must use int32_t and not "int"
1774 2) All fields must land on an alignment boundary that is the same as their size
1775 3) Explicit padding is added to make that so
1776 4) The sizeof the struct is padded out to a multiple of the largest natural size thing in the struct
1777 5) don't forget that 32 and 64 bit pointers are different sizes
1778*/
1779
1780/**
1781 * Obsolete version of halide_filter_argument_t; only present in
1782 * code that wrote halide_filter_metadata_t version 0.
1783 */
1784 struct halide_filter_argument_t_v0 {
1785 const char *name;
1786 int32_t kind;
1787 int32_t dimensions;
1788 struct halide_type_t type;
1789 const struct halide_scalar_value_t *def, *min, *max;
1790};
1791
1792/**
1793 * halide_filter_argument_t is essentially a plain-C-struct equivalent to
1794 * Halide::Argument; most user code will never need to create one.
1795 */
1796 struct halide_filter_argument_t {
1797 const char *name; // name of the argument; will never be null or empty.
1798 int32_t kind; // actually halide_argument_kind_t
1799 int32_t dimensions; // always zero for scalar arguments
1800 struct halide_type_t type;
1801 // These pointers should always be null for buffer arguments,
1802 // and *may* be null for scalar arguments. (A null value means
1803 // there is no def/min/max/estimate specified for this argument.)
1804 const struct halide_scalar_value_t *scalar_def, *scalar_min, *scalar_max, *scalar_estimate;
1805 // This pointer should always be null for scalar arguments,
1806 // and *may* be null for buffer arguments. If not null, it should always
1807 // point to an array of dimensions*2 pointers, which will be the (min, extent)
1808 // estimates for each dimension of the buffer. (Note that any of the pointers
1809 // may be null as well.)
1810 int64_t const *const *buffer_estimates;
1811};
1812
1813 struct halide_filter_metadata_t {
1814#ifdef __cplusplus
1815 static const int32_t VERSION = 1;
1816#endif
1817
1818 /** version of this metadata; currently always 1. */
1819 int32_t version;
1820
1821 /** The number of entries in the arguments field. This is always >= 1. */
1822 int32_t num_arguments;
1823
1824 /** An array of the filters input and output arguments; this will never be
1825 * null. The order of arguments is not guaranteed (input and output arguments
1826 * may come in any order); however, it is guaranteed that all arguments
1827 * will have a unique name within a given filter. */
1828 const struct halide_filter_argument_t *arguments;
1829
1830 /** The Target for which the filter was compiled. This is always
1831 * a canonical Target string (ie a product of Target::to_string). */
1832 const char *target;
1833
1834 /** The function name of the filter. */
1835 const char *name;
1836};
1837
1838/** halide_register_argv_and_metadata() is a **user-defined** function that
1839 * must be provided in order to use the registration.cc files produced
1840 * by Generators when the 'registration' output is requested. Each registration.cc
1841 * file provides a static initializer that calls this function with the given
1842 * filter's argv-call variant, its metadata, and (optionally) and additional
1843 * textual data that the build system chooses to tack on for its own purposes.
1844 * Note that this will be called at static-initializer time (i.e., before
1845 * main() is called), and in an unpredictable order. Note that extra_key_value_pairs
1846 * may be nullptr; if it's not null, it's expected to be a null-terminated list
1847 * of strings, with an even number of entries. */
1848 void halide_register_argv_and_metadata(
1849 int (*filter_argv_call)(void **),
1850 const struct halide_filter_metadata_t *filter_metadata,
1851 const char *const *extra_key_value_pairs);
1852
1853/** The functions below here are relevant for pipelines compiled with
1854 * the -profile target flag, which runs a sampling profiler thread
1855 * alongside the pipeline. */
1856
1857/** Per-Func state tracked by the sampling profiler. */
1858 struct HALIDE_ATTRIBUTE_ALIGN(8) halide_profiler_func_stats {
1859 /** Total time taken evaluating this Func (in nanoseconds). */
1860 uint64_t time;
1861
1862 /** The current memory allocation of this Func. */
1863 uint64_t memory_current;
1864
1865 /** The peak memory allocation of this Func. */
1866 uint64_t memory_peak;
1867
1868 /** The total memory allocation of this Func. */
1869 uint64_t memory_total;
1870
1871 /** The peak stack allocation of this Func's threads. */
1872 uint64_t stack_peak;
1873
1874 /** The average number of thread pool worker threads active while computing this Func. */
1875 uint64_t active_threads_numerator, active_threads_denominator;
1876
1877 /** The name of this Func. A global constant string. */
1878 const char *name;
1879
1880 /** The total number of memory allocation of this Func. */
1881 int num_allocs;
1882};
1883
1884/** Per-pipeline state tracked by the sampling profiler. These exist
1885 * in a linked list. */
1886 struct HALIDE_ATTRIBUTE_ALIGN(8) halide_profiler_pipeline_stats {
1887 /** Total time spent in this pipeline (in nanoseconds) */
1888 uint64_t time;
1889
1890 /** The current memory allocation of funcs in this pipeline. */
1891 uint64_t memory_current;
1892
1893 /** The peak memory allocation of funcs in this pipeline. */
1894 uint64_t memory_peak;
1895
1896 /** The total memory allocation of funcs in this pipeline. */
1897 uint64_t memory_total;
1898
1899 /** The average number of thread pool worker threads doing useful
1900 * work while computing this pipeline. */
1901 uint64_t active_threads_numerator, active_threads_denominator;
1902
1903 /** The name of this pipeline. A global constant string. */
1904 const char *name;
1905
1906 /** An array containing states for each Func in this pipeline. */
1907 struct halide_profiler_func_stats *funcs;
1908
1909 /** The next pipeline_stats pointer. It's a void * because types
1910 * in the Halide runtime may not currently be recursive. */
1911 void *next;
1912
1913 /** The number of funcs in this pipeline. */
1914 int num_funcs;
1915
1916 /** The number of times this pipeline has been run. */
1917 int runs;
1918
1919 /** The total number of samples taken inside of this pipeline. */
1920 int samples;
1921
1922 /** The total number of memory allocation of funcs in this pipeline. */
1923 int num_allocs;
1924};
1925
1926/** Per-invocation-of-a-pipeline state. Lives on the stack of the Halide
1927 * code. Exists in a doubly-linked list to that it can be cleanly
1928 * removed. */
1929 struct HALIDE_ATTRIBUTE_ALIGN(8) halide_profiler_instance_state {
1930 /** Time billed to funcs in this instance by the sampling thread. */
1931 uint64_t billed_time;
1932
1933 /** Wall clock time of the start of the instance. */
1934 uint64_t start_time;
1935
1936 /** The current memory allocation of funcs in this instance. */
1937 uint64_t memory_current;
1938
1939 /** The peak memory allocation of funcs in this instance. */
1940 uint64_t memory_peak;
1941
1942 /** The total memory allocation of funcs in this instance. */
1943 uint64_t memory_total;
1944
1945 /** The average number of thread pool worker threads doing useful
1946 * work while computing this instance. */
1947 uint64_t active_threads_numerator, active_threads_denominator;
1948
1949 /** A pointer to the next running instance, so that the running instances
1950 * can exist in a linked list. */
1951 struct halide_profiler_instance_state *next;
1952
1953 /** A pointer to the address of the next pointer of the previous instance,
1954 * so that this can be removed from the linked list when the instance
1955 * terminates. */
1956 struct halide_profiler_instance_state **prev_next;
1957
1958 /** Information shared across all instances. The stats above are merged into
1959 * it when the instance is retired. */
1960 struct halide_profiler_pipeline_stats *pipeline_stats;
1961
1962 /** An array containing states for each Func in this instance of this pipeline. */
1963 struct halide_profiler_func_stats *funcs;
1964
1965 /** The id of the current running Func. Set by the pipeline, read
1966 * periodically by the profiler thread. */
1967 int current_func;
1968
1969 /** The number of threads currently doing work on this pipeline instance. */
1970 int active_threads;
1971
1972 /** The number of samples taken by this instance. */
1973 int samples;
1974
1975 /** The total number of memory allocation of funcs in this instance. */
1976 int num_allocs;
1977
1978 /** Whether or not this instance should count towards pipeline
1979 * statistics. */
1980 int should_collect_statistics;
1981};
1982
1983/** The global state of the profiler. */
1984 struct halide_profiler_state {
1985 /** Guards access to the fields below. If not locked, the sampling
1986 * profiler thread is free to modify things below (including
1987 * reordering the linked list of pipeline stats). */
1988 struct halide_mutex lock;
1989
1990 /** A linked list of stats gathered for each pipeline. */
1991 struct halide_profiler_pipeline_stats *pipelines;
1992
1993 /** Retrieve remote profiler state. Used so that the sampling
1994 * profiler can follow along with execution that occurs elsewhere,
1995 * e.g. on a DSP. If null, it reads from the int above instead. */
1996
1997 /** Sampling thread reference to be joined at shutdown. */
1998 struct halide_thread *sampling_thread;
1999
2000 /** The running instances of Halide pipelines. */
2001 struct halide_profiler_instance_state *instances;
2002
2003 /** If this callback is defined, the profiler asserts that there is a single
2004 * live instance, and then uses it to get the current func and number of
2005 * active threads insted of reading the fields in the instance. This is used
2006 * so that the profiler can follow along with execution that occurs
2007 * elsewhere (e.g. on an accelerator). */
2008 void (*get_remote_profiler_state)(int *func, int *active_workers);
2009
2010 /** The amount of time the profiler thread sleeps between samples in
2011 * microseconds. Defaults to 1000. To change it call
2012 * halide_profiler_get_state and mutate this field. */
2013 int sleep_time;
2014
2015 /** Set to 1 when you want the profiler to wait for all running instances to
2016 * finish and then stop gracefully. */
2017 int shutdown;
2018};
2019
2020/** Get a pointer to the global profiler state for programmatic
2021 * inspection. Lock it before using to pause the profiler. */
2022 extern struct halide_profiler_state *halide_profiler_get_state(void);
2023
2024/** Get a pointer to the pipeline state associated with pipeline_name.
2025 * This function grabs the global profiler state's lock on entry. */
2026 extern struct halide_profiler_pipeline_stats *halide_profiler_get_pipeline_state(const char *pipeline_name);
2027
2028/** Collects profiling information. Intended to be called from a timer
2029 * interrupt handler if timer based profiling is being used.
2030 * State argument is acquired via halide_profiler_get_pipeline_state.
2031 * prev_t argument is the previous time and can be used to set a more
2032 * accurate time interval if desired. */
2033 extern int halide_profiler_sample(struct halide_profiler_state *s, uint64_t *prev_t);
2034
2035/** Reset profiler state cheaply. May leave threads running or some memory
2036 * allocated but all accumulated statistics are reset. Blocks until all running
2037 * profiled Halide pipelines exit. */
2038 extern void halide_profiler_reset(void);
2039
2040/** Reset all profiler state. Blocks until all running profiled Halide
2041 * pipelines exit. */
2042 extern void halide_profiler_shutdown(void);
2043
2044/** Print out timing statistics for everything run since the last
2045 * reset. Also happens at process exit. */
2046 extern void halide_profiler_report(void *user_context);
2047
2048/** These routines are called to temporarily disable and then reenable
2049 * the profiler. */
2050//@{
2051 extern void halide_profiler_lock(struct halide_profiler_state *);
2052 extern void halide_profiler_unlock(struct halide_profiler_state *);
2053//@}
2054
2055/// \name "Float16" functions
2056/// These functions operate of bits (``uint16_t``) representing a half
2057/// precision floating point number (IEEE-754 2008 binary16).
2058//{@
2059
2060/** Read bits representing a half precision floating point number and return
2061 * the float that represents the same value */
2062 extern float halide_float16_bits_to_float(uint16_t);
2063
2064/** Read bits representing a half precision floating point number and return
2065 * the double that represents the same value */
2066 extern double halide_float16_bits_to_double(uint16_t);
2067
2068// TODO: Conversion functions to half
2069
2070//@}
2071
2072// Allocating and freeing device memory is often very slow. The
2073// methods below give Halide's runtime permission to hold onto device
2074// memory to service future requests instead of returning it to the
2075// underlying device API. The API does not manage an allocation pool,
2076// all it does is provide access to a shared counter that acts as a
2077// limit on the unused memory not yet returned to the underlying
2078// device API. It makes callbacks to participants when memory needs to
2079// be released because the limit is about to be exceeded (either
2080// because the limit has been reduced, or because the memory owned by
2081// some participant becomes unused).
2082
2083/** Tell Halide whether or not it is permitted to hold onto device
2084 * allocations to service future requests instead of returning them
2085 * eagerly to the underlying device API. Many device allocators are
2086 * quite slow, so it can be beneficial to set this to true. The
2087 * default value for now is false.
2088 *
2089 * Note that if enabled, the eviction policy is very simplistic. The
2090 * 32 most-recently used allocations are preserved, regardless of
2091 * their size. Additionally, if a call to cuMalloc results in an
2092 * out-of-memory error, the entire cache is flushed and the allocation
2093 * is retried. See https://github.com/halide/Halide/issues/4093
2094 *
2095 * If set to false, releases all unused device allocations back to the
2096 * underlying device APIs. For finer-grained control, see specific
2097 * methods in each device api runtime.
2098 *
2099 * Note that if the flag is set to true, this call *must* succeed and return
2100 * a value of halide_error_code_success (i.e., zero); if you replace
2101 * the implementation of this call in the runtime, you must honor this contract.
2102 * */
2103 extern int halide_reuse_device_allocations(void *user_context, bool);
2104
2105/** Determines whether on device_free the memory is returned
2106 * immediately to the device API, or placed on a free list for future
2107 * use. Override and switch based on the user_context for
2108 * finer-grained control. By default just returns the value most
2109 * recently set by the method above. */
2110 extern bool halide_can_reuse_device_allocations(void *user_context);
2111
2112 struct halide_device_allocation_pool {
2113 int (*release_unused)(void *user_context);
2114 struct halide_device_allocation_pool *next;
2115};
2116
2117/** Register a callback to be informed when
2118 * halide_reuse_device_allocations(false) is called, and all unused
2119 * device allocations must be released. The object passed should have
2120 * global lifetime, and its next field will be clobbered. */
2121 extern void halide_register_device_allocation_pool(struct halide_device_allocation_pool *);
2122
2123#ifdef __cplusplus
2124} // End extern "C"
2125#endif
2126
2127#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
2128
2129 namespace {
2130
2131 template<typename T>
2132 struct check_is_pointer {
2133 static constexpr bool value = false;
2134};
2135
2136 template<typename T>
2137 struct check_is_pointer<T *> {
2138 static constexpr bool value = true;
2139};
2140
2141} // namespace
2142
2143/** Construct the halide equivalent of a C type */
2144 template<typename T>
2145 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of() {
2146 // Create a compile-time error if T is not a pointer (without
2147 // using any includes - this code goes into the runtime).
2148 // (Note that we can't have uninitialized variables in constexpr functions,
2149 // even if those variables aren't used.)
2150 static_assert(check_is_pointer<T>::value, "Expected a pointer type here");
2151 return halide_type_t(halide_type_handle, 64);
2152}
2153
2154#ifdef HALIDE_CPP_COMPILER_HAS_FLOAT16
2155 template<>
2156 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<_Float16>() {
2157 return halide_type_t(halide_type_float, 16);
2158}
2159#endif
2160
2161 template<>
2162 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<float>() {
2163 return halide_type_t(halide_type_float, 32);
2164}
2165
2166 template<>
2167 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<double>() {
2168 return halide_type_t(halide_type_float, 64);
2169}
2170
2171 template<>
2172 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<bool>() {
2173 return halide_type_t(halide_type_uint, 1);
2174}
2175
2176 template<>
2177 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint8_t>() {
2178 return halide_type_t(halide_type_uint, 8);
2179}
2180
2181 template<>
2182 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint16_t>() {
2183 return halide_type_t(halide_type_uint, 16);
2184}
2185
2186 template<>
2187 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint32_t>() {
2188 return halide_type_t(halide_type_uint, 32);
2189}
2190
2191 template<>
2192 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<uint64_t>() {
2193 return halide_type_t(halide_type_uint, 64);
2194}
2195
2196 template<>
2197 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int8_t>() {
2198 return halide_type_t(halide_type_int, 8);
2199}
2200
2201 template<>
2202 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int16_t>() {
2203 return halide_type_t(halide_type_int, 16);
2204}
2205
2206 template<>
2207 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int32_t>() {
2208 return halide_type_t(halide_type_int, 32);
2209}
2210
2211 template<>
2212 HALIDE_ALWAYS_INLINE constexpr halide_type_t halide_type_of<int64_t>() {
2213 return halide_type_t(halide_type_int, 64);
2214}
2215
2216#ifndef COMPILING_HALIDE_RUNTIME
2217
2218// These structures are used by `function_info_header` files
2219// (generated by passing `-e function_info_header` to a Generator).
2220// The generated files contain documentation on the proper usage.
2221 namespace HalideFunctionInfo {
2222
2223 enum ArgumentKind { InputScalar = 0,
2224 InputBuffer = 1,
2225 OutputBuffer = 2 };
2226
2227 struct ArgumentInfo {
2228 std::string_view name;
2229 ArgumentKind kind;
2230 int32_t dimensions; // always zero for scalar arguments
2231 halide_type_t type;
2232};
2233
2234} // namespace HalideFunctionInfo
2235
2236#endif // COMPILING_HALIDE_RUNTIME
2237
2238#endif // (__cplusplus >= 201103L || _MSVC_LANG >= 201103L)
2239
2240#endif // HALIDE_HALIDERUNTIME_H
halide_set_error_handler
halide_error_handler_t halide_set_error_handler(halide_error_handler_t handler)
halide_set_custom_parallel_runtime
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)
Definition: thread_pool_common.h:828
halide_memoization_cache_lookup
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)
Given a cache key for a memoized result, currently constructed from the Func name and top-level Func ...
halide_error_bad_extern_fold
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)
halide_device_sync
int halide_device_sync(void *user_context, struct halide_buffer_t *buf)
Wait for current GPU operations to complete.
halide_default_do_task
int halide_default_do_task(void *user_context, halide_task_t f, int idx, uint8_t *closure)
Definition: thread_pool_common.h:641
halide_do_par_for
int halide_do_par_for(void *user_context, halide_task_t task, int min, int size, uint8_t *closure)
Definition: thread_pool_common.h:851
halide_load_library_t
void *(* halide_load_library_t)(const char *name)
Definition: HalideRuntime.h:456
halide_error_bad_fold
int halide_error_bad_fold(void *user_context, const char *func_name, const char *var_name, const char *loop_name)
halide_semaphore_release_t
int(* halide_semaphore_release_t)(struct halide_semaphore_t *, int)
Definition: HalideRuntime.h:256
halide_profiler_lock
void halide_profiler_lock(struct halide_profiler_state *)
These routines are called to temporarily disable and then reenable the profiler.
halide_cond_signal
void halide_cond_signal(struct halide_cond *cond)
Definition: synchronization_common.h:894
halide_default_get_library_symbol
void * halide_default_get_library_symbol(void *lib, const char *name)
halide_do_loop_task
int halide_do_loop_task(void *user_context, halide_loop_task_t f, int min, int extent, uint8_t *closure, void *task_parent)
Definition: thread_pool_common.h:856
halide_set_custom_load_library
halide_load_library_t halide_set_custom_load_library(halide_load_library_t user_load_library)
halide_device_crop
int halide_device_crop(void *user_context, const struct halide_buffer_t *src, struct halide_buffer_t *dst)
Give the destination buffer a device allocation which is an alias for the same coordinate range in th...
halide_semaphore_init
int halide_semaphore_init(struct halide_semaphore_t *, int n)
Definition: thread_pool_common.h:867
halide_set_custom_get_symbol
halide_get_symbol_t halide_set_custom_get_symbol(halide_get_symbol_t user_get_symbol)
halide_float16_bits_to_double
double halide_float16_bits_to_double(uint16_t)
Read bits representing a half precision floating point number and return the double that represents t...
halide_malloc
void * halide_malloc(void *user_context, size_t x)
Halide calls these functions to allocate and free memory.
halide_get_library_symbol_t
void *(* halide_get_library_symbol_t)(void *lib, const char *name)
Definition: HalideRuntime.h:457
halide_msan_annotate_buffer_is_initialized
int halide_msan_annotate_buffer_is_initialized(void *user_context, struct halide_buffer_t *buffer)
Mark the data pointed to by the halide_buffer_t as initialized (but not the halide_buffer_t itself),...
halide_default_print
void halide_default_print(void *user_context, const char *)
halide_target_feature_t
halide_target_feature_t
Optional features a compilation Target can have.
Definition: HalideRuntime.h:1361
halide_target_feature_large_buffers
@ halide_target_feature_large_buffers
Enable 64-bit buffer indexing to support buffers > 2GB. Ignored if bits != 64.
Definition: HalideRuntime.h:1406
halide_target_feature_fma
@ halide_target_feature_fma
Enable x86 FMA instruction.
Definition: HalideRuntime.h:1372
halide_target_feature_wasm_bulk_memory
@ halide_target_feature_wasm_bulk_memory
Enable +bulk-memory instructions for WebAssembly codegen.
Definition: HalideRuntime.h:1439
halide_target_feature_tsan
@ halide_target_feature_tsan
Enable hooks for TSAN support.
Definition: HalideRuntime.h:1429
halide_target_feature_msan
@ halide_target_feature_msan
Enable hooks for MSAN support.
Definition: HalideRuntime.h:1412
halide_target_feature_avx512_zen4
@ halide_target_feature_avx512_zen4
Enable the AVX512 features supported by Zen4 processors. This include all of the Cannonlake features,...
Definition: HalideRuntime.h:1417
halide_target_feature_wasm_threads
@ halide_target_feature_wasm_threads
Enable use of threads in WebAssembly codegen. Requires the use of a wasm runtime that provides pthrea...
Definition: HalideRuntime.h:1438
halide_target_feature_trace_loads
@ halide_target_feature_trace_loads
Trace all loads done by the pipeline. Equivalent to calling Func::trace_loads on every non-inlined Fu...
Definition: HalideRuntime.h:1420
halide_target_feature_enable_llvm_loop_opt
@ halide_target_feature_enable_llvm_loop_opt
Enable loop vectorization + unrolling in LLVM. Overrides halide_target_feature_disable_llvm_loop_opt....
Definition: HalideRuntime.h:1435
halide_target_feature_no_asserts
@ halide_target_feature_no_asserts
Disable all runtime checks, for slightly tighter code.
Definition: HalideRuntime.h:1365
halide_target_feature_cl_doubles
@ halide_target_feature_cl_doubles
Enable double support on OpenCL targets.
Definition: HalideRuntime.h:1394
halide_target_feature_rvv
@ halide_target_feature_rvv
Enable RISCV "V" Vector Extension.
Definition: HalideRuntime.h:1447
halide_target_feature_avx2
@ halide_target_feature_avx2
Use AVX 2 instructions. Only relevant on x86.
Definition: HalideRuntime.h:1370
halide_target_feature_trace_realizations
@ halide_target_feature_trace_realizations
Trace all realizations done by the pipeline. Equivalent to calling Func::trace_realizations on every ...
Definition: HalideRuntime.h:1422
halide_target_feature_c_plus_plus_mangling
@ halide_target_feature_c_plus_plus_mangling
Generate C++ mangled names for result function, et al.
Definition: HalideRuntime.h:1404
halide_target_feature_vulkan_float16
@ halide_target_feature_vulkan_float16
Enable Vulkan 16-bit float support.
Definition: HalideRuntime.h:1465
halide_target_feature_avx512_zen5
@ halide_target_feature_avx512_zen5
Enable the AVX512 features supported by Zen5 processors. This include all of the Cannonlake features,...
Definition: HalideRuntime.h:1418
halide_target_feature_no_runtime
@ halide_target_feature_no_runtime
Do not include a copy of the Halide runtime in any generated object file or assembly.
Definition: HalideRuntime.h:1400
halide_target_feature_hvx_v65
@ halide_target_feature_hvx_v65
Enable Hexagon v65 architecture.
Definition: HalideRuntime.h:1424
halide_target_feature_debug
@ halide_target_feature_debug
Turn on debug info and output for runtime code.
Definition: HalideRuntime.h:1363
halide_target_feature_embed_bitcode
@ halide_target_feature_embed_bitcode
Emulate clang -fembed-bitcode flag.
Definition: HalideRuntime.h:1434
halide_target_feature_armv86a
@ halide_target_feature_armv86a
Enable ARMv8.6a instructions.
Definition: HalideRuntime.h:1454
halide_target_feature_wasm_simd128
@ halide_target_feature_wasm_simd128
Enable +simd128 instructions for WebAssembly codegen.
Definition: HalideRuntime.h:1437
halide_target_feature_vulkan
@ halide_target_feature_vulkan
Enable Vulkan runtime support.
Definition: HalideRuntime.h:1461
halide_target_feature_end
@ halide_target_feature_end
A sentinel. Every target is considered to have this feature, and setting this feature does nothing.
Definition: HalideRuntime.h:1474
halide_target_feature_simulator
@ halide_target_feature_simulator
Target is for a simulator environment. Currently only applies to iOS.
Definition: HalideRuntime.h:1473
halide_llvm_large_code_model
@ halide_llvm_large_code_model
Use the LLVM large code model to compile.
Definition: HalideRuntime.h:1446
halide_target_feature_profile_by_timer
@ halide_target_feature_profile_by_timer
Alternative to halide_target_feature_profile using timer interrupt for systems without threads or app...
Definition: HalideRuntime.h:1459
halide_target_feature_semihosting
@ halide_target_feature_semihosting
Used together with Target::NoOS for the baremetal target built with semihosting library and run with ...
Definition: HalideRuntime.h:1470
halide_target_feature_soft_float_abi
@ halide_target_feature_soft_float_abi
Enable soft float ABI. This only enables the soft float ABI calling convention, which does not necess...
Definition: HalideRuntime.h:1411
halide_target_feature_sve2
@ halide_target_feature_sve2
Enable ARM Scalable Vector Extensions v2.
Definition: HalideRuntime.h:1442
halide_target_feature_d3d12compute
@ halide_target_feature_d3d12compute
Enable Direct3D 12 Compute runtime.
Definition: HalideRuntime.h:1431
halide_target_feature_cuda_capability86
@ halide_target_feature_cuda_capability86
Enable CUDA compute capability 8.6 (Ampere)
Definition: HalideRuntime.h:1391
halide_target_feature_armv89a
@ halide_target_feature_armv89a
Enable ARMv8.9a instructions.
Definition: HalideRuntime.h:1457
halide_target_feature_avx512_skylake
@ halide_target_feature_avx512_skylake
Enable the AVX512 features supported by Skylake Xeon server processors. This adds AVX512-VL,...
Definition: HalideRuntime.h:1415
halide_target_feature_avx512_cannonlake
@ halide_target_feature_avx512_cannonlake
Enable the AVX512 features expected to be supported by future Cannonlake processors....
Definition: HalideRuntime.h:1416
halide_target_feature_metal
@ halide_target_feature_metal
Enable the (Apple) Metal runtime.
Definition: HalideRuntime.h:1402
halide_target_feature_hvx_128
@ halide_target_feature_hvx_128
Enable HVX 128 byte mode.
Definition: HalideRuntime.h:1408
halide_target_feature_cuda_capability70
@ halide_target_feature_cuda_capability70
Enable CUDA compute capability 7.0 (Volta)
Definition: HalideRuntime.h:1388
halide_target_feature_fma4
@ halide_target_feature_fma4
Enable x86 (AMD) FMA4 instruction set.
Definition: HalideRuntime.h:1373
halide_target_feature_cuda_capability30
@ halide_target_feature_cuda_capability30
Enable CUDA compute capability 3.0 (Kepler)
Definition: HalideRuntime.h:1383
halide_target_feature_no_neon
@ halide_target_feature_no_neon
Avoid using NEON instructions. Only relevant for 32-bit ARM.
Definition: HalideRuntime.h:1377
halide_target_feature_cuda_capability61
@ halide_target_feature_cuda_capability61
Enable CUDA compute capability 6.1 (Pascal)
Definition: HalideRuntime.h:1387
halide_target_feature_armv7s
@ halide_target_feature_armv7s
Generate code for ARMv7s. Only relevant for 32-bit ARM.
Definition: HalideRuntime.h:1376
halide_target_feature_spirv
@ halide_target_feature_spirv
Enable SPIR-V code generation support.
Definition: HalideRuntime.h:1460
halide_target_feature_trace_pipeline
@ halide_target_feature_trace_pipeline
Trace the pipeline.
Definition: HalideRuntime.h:1423
halide_target_feature_armv88a
@ halide_target_feature_armv88a
Enable ARMv8.8a instructions.
Definition: HalideRuntime.h:1456
halide_target_feature_cl_atomic64
@ halide_target_feature_cl_atomic64
Enable 64-bit atomics operations on OpenCL targets.
Definition: HalideRuntime.h:1395
halide_target_feature_egl
@ halide_target_feature_egl
Force use of EGL support.
Definition: HalideRuntime.h:1443
halide_target_feature_hvx_v68
@ halide_target_feature_hvx_v68
Enable Hexagon v68 architecture.
Definition: HalideRuntime.h:1426
halide_target_feature_avx10_1
@ halide_target_feature_avx10_1
Intel AVX10 version 1 support. vector_bits is used to indicate width.
Definition: HalideRuntime.h:1471
halide_target_feature_avxvnni
@ halide_target_feature_avxvnni
Enable the AVX-VNNI features supported by AVX2 instructions. Supports 256-bit VNNI instructions witho...
Definition: HalideRuntime.h:1371
halide_target_feature_profile
@ halide_target_feature_profile
Launch a sampling profiler alongside the Halide pipeline that monitors and reports the runtime used b...
Definition: HalideRuntime.h:1399
halide_target_feature_strict_float
@ halide_target_feature_strict_float
Turn off all non-IEEE floating-point optimization. Currently applies only to LLVM targets.
Definition: HalideRuntime.h:1428
halide_target_feature_cuda_capability35
@ halide_target_feature_cuda_capability35
Enable CUDA compute capability 3.5 (Kepler)
Definition: HalideRuntime.h:1385
halide_target_feature_armv8a
@ halide_target_feature_armv8a
Enable ARMv8a instructions.
Definition: HalideRuntime.h:1448
halide_target_feature_asan
@ halide_target_feature_asan
Enable hooks for ASAN support.
Definition: HalideRuntime.h:1430
halide_target_feature_armv87a
@ halide_target_feature_armv87a
Enable ARMv8.7a instructions.
Definition: HalideRuntime.h:1455
halide_target_feature_cl_half
@ halide_target_feature_cl_half
Enable half support on OpenCL targets.
Definition: HalideRuntime.h:1427
halide_target_feature_vulkan_float64
@ halide_target_feature_vulkan_float64
Enable Vulkan 64-bit float support.
Definition: HalideRuntime.h:1466
halide_target_feature_arm_dot_prod
@ halide_target_feature_arm_dot_prod
Enable ARMv8.2-a dotprod extension (i.e. udot and sdot instructions)
Definition: HalideRuntime.h:1444
halide_target_feature_avx512_sapphirerapids
@ halide_target_feature_avx512_sapphirerapids
Enable the AVX512 features supported by Sapphire Rapids processors. This include all of the Zen4 feat...
Definition: HalideRuntime.h:1419
halide_target_feature_vulkan_version13
@ halide_target_feature_vulkan_version13
Enable Vulkan v1.3 runtime target support.
Definition: HalideRuntime.h:1469
halide_target_feature_vulkan_version12
@ halide_target_feature_vulkan_version12
Enable Vulkan v1.2 runtime target support.
Definition: HalideRuntime.h:1468
halide_target_feature_sse41
@ halide_target_feature_sse41
Use SSE 4.1 and earlier instructions. Only relevant on x86.
Definition: HalideRuntime.h:1368
halide_target_feature_power_arch_2_07
@ halide_target_feature_power_arch_2_07
Use POWER ISA 2.07 new instructions. Only relevant on POWERPC.
Definition: HalideRuntime.h:1380
halide_target_feature_opencl
@ halide_target_feature_opencl
Enable the OpenCL runtime.
Definition: HalideRuntime.h:1393
halide_target_feature_trace_stores
@ halide_target_feature_trace_stores
Trace all stores done by the pipeline. Equivalent to calling Func::trace_stores on every non-inlined ...
Definition: HalideRuntime.h:1421
halide_target_feature_hexagon_dma
@ halide_target_feature_hexagon_dma
Enable Hexagon DMA buffers.
Definition: HalideRuntime.h:1433
halide_target_feature_avx512
@ halide_target_feature_avx512
Enable the base AVX512 subset supported by all AVX512 architectures. The specific feature sets are AV...
Definition: HalideRuntime.h:1413
halide_target_feature_avx512_knl
@ halide_target_feature_avx512_knl
Enable the AVX512 features supported by Knight's Landing chips, such as the Xeon Phi x200....
Definition: HalideRuntime.h:1414
halide_target_feature_cuda_capability50
@ halide_target_feature_cuda_capability50
Enable CUDA compute capability 5.0 (Maxwell)
Definition: HalideRuntime.h:1386
halide_target_feature_arm_fp16
@ halide_target_feature_arm_fp16
Enable ARMv8.2-a half-precision floating point data processing.
Definition: HalideRuntime.h:1445
halide_target_feature_armv82a
@ halide_target_feature_armv82a
Enable ARMv8.2a instructions.
Definition: HalideRuntime.h:1450
halide_target_feature_hvx_v62
@ halide_target_feature_hvx_v62
Enable Hexagon v62 architecture.
Definition: HalideRuntime.h:1409
halide_target_feature_armv84a
@ halide_target_feature_armv84a
Enable ARMv8.4a instructions.
Definition: HalideRuntime.h:1452
halide_target_feature_cuda
@ halide_target_feature_cuda
Enable the CUDA runtime. Defaults to compute capability 2.0 (Fermi)
Definition: HalideRuntime.h:1382
halide_target_feature_armv81a
@ halide_target_feature_armv81a
Enable ARMv8.1a instructions.
Definition: HalideRuntime.h:1449
halide_target_feature_webgpu
@ halide_target_feature_webgpu
Enable the WebGPU runtime.
Definition: HalideRuntime.h:1440
halide_target_feature_sanitizer_coverage
@ halide_target_feature_sanitizer_coverage
Enable hooks for SanitizerCoverage support.
Definition: HalideRuntime.h:1458
halide_target_feature_cuda_capability80
@ halide_target_feature_cuda_capability80
Enable CUDA compute capability 8.0 (Ampere)
Definition: HalideRuntime.h:1390
halide_target_feature_wasm_mvponly
@ halide_target_feature_wasm_mvponly
Disable all extensions to WebAssembly codegen (including +sign-ext and +nontrapping-fptoint,...
Definition: HalideRuntime.h:1436
halide_target_feature_f16c
@ halide_target_feature_f16c
Enable x86 16-bit float support.
Definition: HalideRuntime.h:1374
halide_target_feature_vulkan_int16
@ halide_target_feature_vulkan_int16
Enable Vulkan 16-bit integer support.
Definition: HalideRuntime.h:1463
halide_target_feature_enable_backtraces
@ halide_target_feature_enable_backtraces
Preserve frame pointers and include unwind tables to support accurate backtraces for debugging and pr...
Definition: HalideRuntime.h:1364
halide_target_feature_cuda_capability32
@ halide_target_feature_cuda_capability32
Enable CUDA compute capability 3.2 (Tegra K1)
Definition: HalideRuntime.h:1384
halide_target_feature_armv85a
@ halide_target_feature_armv85a
Enable ARMv8.5a instructions.
Definition: HalideRuntime.h:1453
halide_target_feature_jit
@ halide_target_feature_jit
Generate code that will run immediately inside the calling process.
Definition: HalideRuntime.h:1362
halide_target_feature_avx
@ halide_target_feature_avx
Use AVX 1 instructions. Only relevant on x86.
Definition: HalideRuntime.h:1369
halide_target_feature_cuda_capability75
@ halide_target_feature_cuda_capability75
Enable CUDA compute capability 7.5 (Turing)
Definition: HalideRuntime.h:1389
halide_target_feature_check_unsafe_promises
@ halide_target_feature_check_unsafe_promises
Insert assertions for promises.
Definition: HalideRuntime.h:1432
halide_target_feature_vsx
@ halide_target_feature_vsx
Use VSX instructions. Only relevant on POWERPC.
Definition: HalideRuntime.h:1379
halide_target_feature_vulkan_int8
@ halide_target_feature_vulkan_int8
Enable Vulkan 8-bit integer support.
Definition: HalideRuntime.h:1462
halide_target_feature_armv83a
@ halide_target_feature_armv83a
Enable ARMv8.3a instructions.
Definition: HalideRuntime.h:1451
halide_target_feature_vulkan_int64
@ halide_target_feature_vulkan_int64
Enable Vulkan 64-bit integer support.
Definition: HalideRuntime.h:1464
halide_target_feature_user_context
@ halide_target_feature_user_context
Generated code takes a user_context pointer as first argument.
Definition: HalideRuntime.h:1397
halide_target_feature_no_bounds_query
@ halide_target_feature_no_bounds_query
Disable the bounds querying functionality.
Definition: HalideRuntime.h:1366
halide_target_feature_vulkan_version10
@ halide_target_feature_vulkan_version10
Enable Vulkan v1.0 runtime target support.
Definition: HalideRuntime.h:1467
halide_target_feature_fuzz_float_stores
@ halide_target_feature_fuzz_float_stores
On every floating point store, set the last bit of the mantissa to zero. Pipelines for which the outp...
Definition: HalideRuntime.h:1410
halide_target_feature_sve
@ halide_target_feature_sve
Enable ARM Scalable Vector Extensions.
Definition: HalideRuntime.h:1441
halide_target_feature_x86_apx
@ halide_target_feature_x86_apx
Intel x86 APX support. Covers initial set of features released as APX: egpr,push2pop2,...
Definition: HalideRuntime.h:1472
halide_target_feature_hvx_v66
@ halide_target_feature_hvx_v66
Enable Hexagon v66 architecture.
Definition: HalideRuntime.h:1425
halide_free
void halide_free(void *user_context, void *ptr)
halide_semaphore_try_acquire
bool halide_semaphore_try_acquire(struct halide_semaphore_t *, int n)
Definition: thread_pool_common.h:875
halide_default_semaphore_try_acquire
bool halide_default_semaphore_try_acquire(struct halide_semaphore_t *, int n)
Definition: thread_pool_common.h:794
halide_error_buffer_allocation_too_large
int halide_error_buffer_allocation_too_large(void *user_context, const char *buffer_name, uint64_t allocation_size, uint64_t max_size)
halide_cond_wait
void halide_cond_wait(struct halide_cond *cond, struct halide_mutex *mutex)
Definition: synchronization_common.h:900
halide_do_par_for_t
int(* halide_do_par_for_t)(void *, halide_task_t, int, int, uint8_t *)
Set a custom method for performing a parallel for loop.
Definition: HalideRuntime.h:238
halide_set_num_threads
int halide_set_num_threads(int n)
Definition: thread_pool_common.h:724
halide_copy_to_host
int halide_copy_to_host(void *user_context, struct halide_buffer_t *buf)
Copy image data from device memory to host memory.
halide_default_do_par_for
int halide_default_do_par_for(void *user_context, halide_task_t task, int min, int size, uint8_t *closure)
The default versions of the parallel runtime functions.
Definition: thread_pool_common.h:652
halide_msan_annotate_memory_is_initialized
int halide_msan_annotate_memory_is_initialized(void *user_context, const void *ptr, uint64_t len)
Annotate that a given range of memory has been initialized; only used when Target::MSAN is enabled.
halide_set_custom_print
halide_print_t halide_set_custom_print(halide_print_t print)
halide_profiler_get_state
struct halide_profiler_state * halide_profiler_get_state(void)
Get a pointer to the global profiler state for programmatic inspection.
halide_error_bad_dimensions
int halide_error_bad_dimensions(void *user_context, const char *func_name, int32_t dimensions_given, int32_t correct_dimensions)
halide_mutex_array_unlock
int halide_mutex_array_unlock(struct halide_mutex_array *array, int entry)
Definition: synchronization_common.h:944
halide_error_constraint_violated
int halide_error_constraint_violated(void *user_context, const char *var, int val, const char *constrained_var, int constrained_val)
halide_default_do_loop_task
int halide_default_do_loop_task(void *user_context, halide_loop_task_t f, int min, int extent, uint8_t *closure, void *task_parent)
Definition: thread_pool_common.h:646
halide_profiler_reset
void halide_profiler_reset(void)
Reset profiler state cheaply.
halide_task_t
int(* halide_task_t)(void *user_context, int task_number, uint8_t *closure)
Define halide_do_par_for to replace the default thread pool implementation.
Definition: HalideRuntime.h:229
halide_mutex_lock
void halide_mutex_lock(struct halide_mutex *mutex)
A basic set of mutex and condition variable functions, which call platform specific code for mutual e...
Definition: synchronization_common.h:876
halide_trace_event_code_t
halide_trace_event_code_t
Definition: HalideRuntime.h:577
halide_trace_consume
@ halide_trace_consume
Definition: HalideRuntime.h:583
halide_trace_load
@ halide_trace_load
Definition: HalideRuntime.h:577
halide_trace_tag
@ halide_trace_tag
Definition: HalideRuntime.h:587
halide_trace_store
@ halide_trace_store
Definition: HalideRuntime.h:578
halide_trace_begin_pipeline
@ halide_trace_begin_pipeline
Definition: HalideRuntime.h:585
halide_trace_end_pipeline
@ halide_trace_end_pipeline
Definition: HalideRuntime.h:586
halide_trace_end_produce
@ halide_trace_end_produce
Definition: HalideRuntime.h:582
halide_trace_produce
@ halide_trace_produce
Definition: HalideRuntime.h:581
halide_trace_end_consume
@ halide_trace_end_consume
Definition: HalideRuntime.h:584
halide_trace_end_realization
@ halide_trace_end_realization
Definition: HalideRuntime.h:580
halide_trace_begin_realization
@ halide_trace_begin_realization
Definition: HalideRuntime.h:579
halide_profiler_get_pipeline_state
struct halide_profiler_pipeline_stats * halide_profiler_get_pipeline_state(const char *pipeline_name)
Get a pointer to the pipeline state associated with pipeline_name.
halide_do_task
int halide_do_task(void *user_context, halide_task_t f, int idx, uint8_t *closure)
Definition: thread_pool_common.h:846
halide_set_custom_malloc
halide_malloc_t halide_set_custom_malloc(halide_malloc_t user_malloc)
halide_error_device_dirty_with_no_device_support
int halide_error_device_dirty_with_no_device_support(void *user_context, const char *buffer_name)
halide_default_semaphore_init
int halide_default_semaphore_init(struct halide_semaphore_t *, int n)
Definition: thread_pool_common.h:774
halide_msan_annotate_buffer_is_initialized_as_destructor
void halide_msan_annotate_buffer_is_initialized_as_destructor(void *user_context, void *buffer)
halide_get_library_symbol
void * halide_get_library_symbol(void *lib, const char *name)
halide_error_handler_t
void(* halide_error_handler_t)(void *, const char *)
Definition: HalideRuntime.h:184
halide_device_release
void halide_device_release(void *user_context, const struct halide_device_interface_t *device_interface)
Release all data associated with the given device interface, in particular all resources (memory,...
halide_error_bounds_inference_call_failed
int halide_error_bounds_inference_call_failed(void *user_context, const char *extern_stage_name, int result)
Halide calls the functions below on various error conditions.
BUFFER_FLAGS_UNDERLYING_TYPE
BUFFER_FLAGS_UNDERLYING_TYPE
Definition: HalideRuntime.h:1558
halide_buffer_flag_device_dirty
@ halide_buffer_flag_device_dirty
Definition: HalideRuntime.h:1560
halide_buffer_flag_host_dirty
@ halide_buffer_flag_host_dirty
Definition: HalideRuntime.h:1559
halide_error_buffer_extents_negative
int halide_error_buffer_extents_negative(void *user_context, const char *buffer_name, int dimension, int extent)
halide_error_buffer_is_null
int halide_error_buffer_is_null(void *user_context, const char *routine)
halide_mutex_unlock
void halide_mutex_unlock(struct halide_mutex *mutex)
Definition: synchronization_common.h:882
halide_error_constraints_make_required_region_smaller
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)
halide_error_out_of_memory
int halide_error_out_of_memory(void *user_context)
halide_get_symbol
void * halide_get_symbol(const char *name)
Halide calls these functions to interact with the underlying system runtime functions.
halide_debug_to_file
int32_t halide_debug_to_file(void *user_context, const char *filename, struct halide_buffer_t *buf)
Called when debug_to_file is used inside Halide code.
halide_error_no_device_interface
int halide_error_no_device_interface(void *user_context)
halide_spawn_thread
struct halide_thread * halide_spawn_thread(void(*f)(void *), void *closure)
Spawn a thread.
halide_error_debug_to_file_failed
int halide_error_debug_to_file_failed(void *user_context, const char *func, const char *filename, int error_code)
halide_dimension_t
struct halide_dimension_t halide_dimension_t
halide_error_requirement_failed
int halide_error_requirement_failed(void *user_context, const char *condition, const char *message)
halide_memoization_cache_release
void halide_memoization_cache_release(void *user_context, void *host)
If halide_memoization_cache_lookup succeeds, halide_memoization_cache_release must be called to signa...
halide_buffer_flags
enum BUFFER_FLAGS_UNDERLYING_TYPE halide_buffer_flags
halide_can_use_target_features_t
int(* halide_can_use_target_features_t)(int count, const uint64_t *features)
Definition: HalideRuntime.h:1496
halide_register_argv_and_metadata
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)
halide_register_argv_and_metadata() is a user-defined function that must be provided in order to use ...
halide_get_symbol_t
void *(* halide_get_symbol_t)(const char *name)
Definition: HalideRuntime.h:455
halide_error_param_too_large_f64
int halide_error_param_too_large_f64(void *user_context, const char *param_name, double val, double max_val)
halide_msan_check_memory_is_initialized
int halide_msan_check_memory_is_initialized(void *user_context, const void *ptr, uint64_t len, const char *name)
Verify that a given range of memory has been initialized; only used when Target::MSAN is enabled.
halide_do_loop_task_t
int(* halide_do_loop_task_t)(void *, halide_loop_task_t, int, int, uint8_t *, void *)
The version of do_task called for loop tasks.
Definition: HalideRuntime.h:339
halide_error_buffer_extents_too_large
int halide_error_buffer_extents_too_large(void *user_context, const char *buffer_name, int64_t actual_size, int64_t max_size)
halide_trace
int32_t halide_trace(void *user_context, const struct halide_trace_event_t *event)
Called when Funcs are marked as trace_load, trace_store, or trace_realization.
halide_error_extern_stage_failed
int halide_error_extern_stage_failed(void *user_context, const char *extern_stage_name, int result)
A call to an extern stage failed.
halide_set_custom_can_use_target_features
halide_can_use_target_features_t halide_set_custom_can_use_target_features(halide_can_use_target_features_t)
halide_error_host_is_null
int halide_error_host_is_null(void *user_context, const char *func_name)
halide_set_trace_file
void halide_set_trace_file(int fd)
Set the file descriptor that Halide should write binary trace events to.
halide_memoization_cache_store
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)
Given a cache key for a memoized result, currently constructed from the Func name and top-level Func ...
halide_buffer_copy
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)
Copy data from one buffer to another.
halide_error_vscale_invalid
int halide_error_vscale_invalid(void *user_context, const char *func_name, int runtime_vscale, int compiletime_vscale)
halide_error_fold_factor_too_small
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)
halide_error_param_too_small_f64
int halide_error_param_too_small_f64(void *user_context, const char *param_name, double val, double min_val)
halide_error_param_too_large_i64
int halide_error_param_too_large_i64(void *user_context, const char *param_name, int64_t val, int64_t max_val)
halide_error_param_too_small_u64
int halide_error_param_too_small_u64(void *user_context, const char *param_name, uint64_t val, uint64_t min_val)
halide_print_t
void(* halide_print_t)(void *, const char *)
Definition: HalideRuntime.h:170
halide_set_custom_trace
halide_trace_t halide_set_custom_trace(halide_trace_t trace)
halide_print
void halide_print(void *user_context, const char *)
Print a message to stderr.
halide_semaphore_try_acquire_t
bool(* halide_semaphore_try_acquire_t)(struct halide_semaphore_t *, int)
Definition: HalideRuntime.h:257
halide_profiler_report
void halide_profiler_report(void *user_context)
Print out timing statistics for everything run since the last reset.
halide_set_gpu_device
void halide_set_gpu_device(int n)
Selects which gpu device to use.
halide_mutex_array_destroy
void halide_mutex_array_destroy(void *user_context, void *array)
Definition: synchronization_common.h:933
halide_default_trace
int32_t halide_default_trace(void *user_context, const struct halide_trace_event_t *event)
halide_default_can_use_target_features
int halide_default_can_use_target_features(int count, const uint64_t *features)
This is the default implementation of halide_can_use_target_features; it is provided for convenience ...
halide_reuse_device_allocations
int halide_reuse_device_allocations(void *user_context, bool)
Tell Halide whether or not it is permitted to hold onto device allocations to service future requests...
halide_error_param_too_small_i64
int halide_error_param_too_small_i64(void *user_context, const char *param_name, int64_t val, int64_t min_val)
halide_type_code_t
halide_type_code_t
Types in the halide type system.
Definition: HalideRuntime.h:480
halide_type_float
@ halide_type_float
IEEE floating point numbers.
Definition: HalideRuntime.h:483
halide_type_handle
@ halide_type_handle
opaque pointer type (void *)
Definition: HalideRuntime.h:484
halide_type_bfloat
@ halide_type_bfloat
floating point numbers in the bfloat format
Definition: HalideRuntime.h:485
halide_type_int
@ halide_type_int
signed integers
Definition: HalideRuntime.h:481
halide_type_uint
@ halide_type_uint
unsigned integers
Definition: HalideRuntime.h:482
halide_device_malloc
int halide_device_malloc(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)
Allocate device memory to back a halide_buffer_t.
halide_can_reuse_device_allocations
bool halide_can_reuse_device_allocations(void *user_context)
Determines whether on device_free the memory is returned immediately to the device API,...
halide_mutex_array_lock
int halide_mutex_array_lock(struct halide_mutex_array *array, int entry)
Definition: synchronization_common.h:939
halide_free_t
void(* halide_free_t)(void *, void *)
Definition: HalideRuntime.h:433
halide_error_storage_bound_too_small
int halide_error_storage_bound_too_small(void *user_context, const char *func_name, const char *var_name, int provided_size, int required_size)
halide_loop_task_t
int(* halide_loop_task_t)(void *user_context, int min, int extent, uint8_t *closure, void *task_parent)
A task representing a serial for loop evaluated over some range.
Definition: HalideRuntime.h:263
halide_profiler_shutdown
void halide_profiler_shutdown(void)
Reset all profiler state.
halide_error_specialize_fail
int halide_error_specialize_fail(void *user_context, const char *message)
halide_error_device_interface_no_device
int halide_error_device_interface_no_device(void *user_context)
halide_error_host_and_device_dirty
int halide_error_host_and_device_dirty(void *user_context)
halide_error_access_out_of_bounds
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)
halide_error_explicit_bounds_too_small
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)
Various other error conditions.
halide_default_malloc
void * halide_default_malloc(void *user_context, size_t x)
halide_default_load_library
void * halide_default_load_library(const char *name)
halide_error_buffer_argument_is_null
int halide_error_buffer_argument_is_null(void *user_context, const char *buffer_name)
halide_default_semaphore_release
int halide_default_semaphore_release(struct halide_semaphore_t *, int n)
Definition: thread_pool_common.h:780
halide_default_error
void halide_default_error(void *user_context, const char *)
halide_device_slice
int halide_device_slice(void *user_context, const struct halide_buffer_t *src, int slice_dim, int slice_pos, struct halide_buffer_t *dst)
Give the destination buffer a device allocation which is an alias for a similar coordinate range in t...
halide_error_device_crop_failed
int halide_error_device_crop_failed(void *user_context)
halide_get_num_threads
int halide_get_num_threads()
Get or set the number of threads used by Halide's thread pool.
Definition: thread_pool_common.h:741
halide_default_free
void halide_default_free(void *user_context, void *ptr)
halide_shutdown_thread_pool
void halide_shutdown_thread_pool(void)
Definition: thread_pool_common.h:748
HALIDE_MUST_USE_RESULT
#define HALIDE_MUST_USE_RESULT
Definition: HalideRuntime.h:65
halide_memoization_cache_evict
void halide_memoization_cache_evict(void *user_context, uint64_t eviction_key)
Evict all cache entries that were tagged with the given eviction_key in the memoize scheduling direct...
halide_set_custom_do_par_for
halide_do_par_for_t halide_set_custom_do_par_for(halide_do_par_for_t do_par_for)
Definition: thread_pool_common.h:822
halide_join_thread
void halide_join_thread(struct halide_thread *)
Join a thread.
halide_error_code_t
halide_error_code_t
The error codes that may be returned by a Halide pipeline.
Definition: HalideRuntime.h:1074
halide_error_code_no_device_interface
@ halide_error_code_no_device_interface
Buffer has a non-zero device but no device interface, which violates a Halide invariant.
Definition: HalideRuntime.h:1155
halide_error_code_symbol_not_found
@ halide_error_code_symbol_not_found
A runtime symbol could not be loaded.
Definition: HalideRuntime.h:1161
halide_error_code_bad_fold
@ halide_error_code_bad_fold
A fold_storage directive was used on a dimension that is not accessed in a monotonically increasing o...
Definition: HalideRuntime.h:1178
halide_error_code_fold_factor_too_small
@ halide_error_code_fold_factor_too_small
A fold_storage directive was used with a fold factor that was too small to store all the values of a ...
Definition: HalideRuntime.h:1183
halide_error_code_split_factor_not_positive
@ halide_error_code_split_factor_not_positive
A factor used to split a loop was discovered to be zero or negative at runtime.
Definition: HalideRuntime.h:1267
halide_error_code_device_interface_no_device
@ halide_error_code_device_interface_no_device
Buffer has a non-null device_interface but device is 0, which violates a Halide invariant.
Definition: HalideRuntime.h:1222
halide_error_code_param_too_large
@ halide_error_code_param_too_large
A scalar parameter passed in was greater than its minimum declared value.
Definition: HalideRuntime.h:1116
halide_error_code_param_too_small
@ halide_error_code_param_too_small
A scalar parameter passed in was smaller than its minimum declared value.
Definition: HalideRuntime.h:1112
halide_error_code_access_out_of_bounds
@ halide_error_code_access_out_of_bounds
A pipeline would access memory outside of the halide_buffer_t passed in.
Definition: HalideRuntime.h:1092
halide_error_code_specialize_fail
@ halide_error_code_specialize_fail
A specialize_fail() schedule branch was selected at runtime.
Definition: HalideRuntime.h:1198
halide_error_code_unimplemented
@ halide_error_code_unimplemented
This part of the Halide runtime is unimplemented on this platform.
Definition: HalideRuntime.h:1158
halide_error_code_requirement_failed
@ halide_error_code_requirement_failed
User-specified require() expression was not satisfied.
Definition: HalideRuntime.h:1186
halide_error_code_bad_extern_fold
@ halide_error_code_bad_extern_fold
A folded buffer was passed to an extern stage, but the region touched wraps around the fold boundary.
Definition: HalideRuntime.h:1218
halide_error_code_incompatible_device_interface
@ halide_error_code_incompatible_device_interface
An operation on a buffer required an allocation on a particular device interface, but a device alloca...
Definition: HalideRuntime.h:1249
halide_error_code_internal_error
@ halide_error_code_internal_error
There is a bug in the Halide compiler.
Definition: HalideRuntime.h:1164
halide_error_code_buffer_extents_negative
@ halide_error_code_buffer_extents_negative
At least one of the buffer's extents are negative.
Definition: HalideRuntime.h:1189
halide_error_code_constraints_make_required_region_smaller
@ halide_error_code_constraints_make_required_region_smaller
Applying explicit constraints on the size of an input or output buffer shrank the size of that buffer...
Definition: HalideRuntime.h:1104
halide_error_code_copy_to_device_failed
@ halide_error_code_copy_to_device_failed
The Halide runtime encountered an error while trying to copy from host to device.
Definition: HalideRuntime.h:1136
halide_error_code_vscale_invalid
@ halide_error_code_vscale_invalid
"vscale" value of Scalable Vector detected in runtime does not match the vscale value used in compila...
Definition: HalideRuntime.h:1271
halide_error_code_generic_error
@ halide_error_code_generic_error
An uncategorized error occurred.
Definition: HalideRuntime.h:1079
halide_error_code_device_crop_failed
@ halide_error_code_device_crop_failed
Cropping/slicing a buffer failed for some other reason.
Definition: HalideRuntime.h:1243
halide_error_code_success
@ halide_error_code_success
There was no error.
Definition: HalideRuntime.h:1076
halide_error_code_copy_to_host_failed
@ halide_error_code_copy_to_host_failed
The Halide runtime encountered an error while trying to copy from device to host.
Definition: HalideRuntime.h:1131
halide_error_code_trace_failed
@ halide_error_code_trace_failed
Failure recording trace packets for one of the halide_target_feature_trace features.
Definition: HalideRuntime.h:1195
halide_error_code_device_sync_failed
@ halide_error_code_device_sync_failed
The Halide runtime encountered an error while trying to synchronize with a device.
Definition: HalideRuntime.h:1146
halide_error_code_buffer_argument_is_null
@ halide_error_code_buffer_argument_is_null
A halide_buffer_t pointer passed in was NULL.
Definition: HalideRuntime.h:1122
halide_error_code_bad_dimensions
@ halide_error_code_bad_dimensions
The dimensions field of a halide_buffer_t does not match the dimensions of that ImageParam.
Definition: HalideRuntime.h:1252
halide_error_code_device_malloc_failed
@ halide_error_code_device_malloc_failed
The Halide runtime encountered an error while trying to allocate memory on device.
Definition: HalideRuntime.h:1141
halide_error_code_host_and_device_dirty
@ halide_error_code_host_and_device_dirty
Buffer has both host and device dirty bits set, which violates a Halide invariant.
Definition: HalideRuntime.h:1226
halide_error_code_debug_to_file_failed
@ halide_error_code_debug_to_file_failed
debug_to_file failed to open or write to the specified file.
Definition: HalideRuntime.h:1126
halide_error_code_gpu_device_error
@ halide_error_code_gpu_device_error
Call(s) to a GPU backend API failed.
Definition: HalideRuntime.h:1192
halide_error_code_buffer_is_null
@ halide_error_code_buffer_is_null
The halide_buffer_t * passed to a halide runtime routine is nullptr and this is not allowed.
Definition: HalideRuntime.h:1230
halide_error_code_device_crop_unsupported
@ halide_error_code_device_crop_unsupported
Attempted to make cropped/sliced alias of a buffer with a device field, but the device_interface does...
Definition: HalideRuntime.h:1239
halide_error_code_device_buffer_copy_failed
@ halide_error_code_device_buffer_copy_failed
The Halide runtime encountered an error while trying to copy from one buffer to another.
Definition: HalideRuntime.h:1235
halide_error_code_device_free_failed
@ halide_error_code_device_free_failed
The Halide runtime encountered an error while trying to free a device allocation.
Definition: HalideRuntime.h:1151
halide_error_code_buffer_allocation_too_large
@ halide_error_code_buffer_allocation_too_large
A halide_buffer_t was given that spans more than 2GB of memory.
Definition: HalideRuntime.h:1095
halide_error_code_bad_type
@ halide_error_code_bad_type
The elem_size field of a halide_buffer_t does not match the size in bytes of the type of that ImagePa...
Definition: HalideRuntime.h:1088
halide_error_code_device_run_failed
@ halide_error_code_device_run_failed
The Halide runtime encountered an error while trying to launch a GPU kernel.
Definition: HalideRuntime.h:1169
halide_error_code_device_dirty_with_no_device_support
@ halide_error_code_device_dirty_with_no_device_support
A buffer with the device_dirty flag set was passed to a pipeline compiled with no device backends ena...
Definition: HalideRuntime.h:1259
halide_error_code_cannot_profile_pipeline
@ halide_error_code_cannot_profile_pipeline
Profiling failed for a pipeline invocation.
Definition: HalideRuntime.h:1274
halide_error_code_explicit_bounds_too_small
@ halide_error_code_explicit_bounds_too_small
A Func was given an explicit bound via Func::bound, but this was not large enough to encompass the re...
Definition: HalideRuntime.h:1084
halide_error_code_buffer_extents_too_large
@ halide_error_code_buffer_extents_too_large
A halide_buffer_t was given with extents that multiply to a number greater than 2^31-1.
Definition: HalideRuntime.h:1099
halide_error_code_device_detach_native_failed
@ halide_error_code_device_detach_native_failed
The Halide runtime encountered an error while trying to detach a native device handle.
Definition: HalideRuntime.h:1208
halide_error_code_storage_bound_too_small
@ halide_error_code_storage_bound_too_small
An explicit storage bound provided is too small to store all the values produced by the function.
Definition: HalideRuntime.h:1263
halide_error_code_out_of_memory
@ halide_error_code_out_of_memory
A call to halide_malloc returned NULL.
Definition: HalideRuntime.h:1119
halide_error_code_device_wrap_native_failed
@ halide_error_code_device_wrap_native_failed
The Halide runtime encountered an error while trying to wrap a native device handle.
Definition: HalideRuntime.h:1203
halide_error_code_constraint_violated
@ halide_error_code_constraint_violated
A constraint on a size or stride of an input or output buffer was not met by the halide_buffer_t pass...
Definition: HalideRuntime.h:1108
halide_error_code_unaligned_host_ptr
@ halide_error_code_unaligned_host_ptr
The Halide runtime encountered a host pointer that violated the alignment set for it by way of a call...
Definition: HalideRuntime.h:1174
halide_error_code_host_is_null
@ halide_error_code_host_is_null
The host field on an input or output was null, the device field was not zero, and the pipeline tries ...
Definition: HalideRuntime.h:1214
halide_load_library
void * halide_load_library(const char *name)
halide_memoization_cache_set_size
void halide_memoization_cache_set_size(int64_t size)
Set the soft maximum amount of memory, in bytes, that the LRU cache will use to memoize Func results.
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:49
halide_cond_broadcast
void halide_cond_broadcast(struct halide_cond *cond)
Definition: synchronization_common.h:888
halide_device_free
int halide_device_free(void *user_context, struct halide_buffer_t *buf)
Free device memory.
halide_profiler_unlock
void halide_profiler_unlock(struct halide_profiler_state *)
halide_memoization_cache_cleanup
void halide_memoization_cache_cleanup(void)
Free all memory and resources associated with the memoization cache.
halide_device_sync_global
int halide_device_sync_global(void *user_context, const struct halide_device_interface_t *device_interface)
Wait for current GPU operations to complete.
halide_error_param_too_large_u64
int halide_error_param_too_large_u64(void *user_context, const char *param_name, uint64_t val, uint64_t max_val)
halide_trace_t
int32_t(* halide_trace_t)(void *user_context, const struct halide_trace_event_t *)
Definition: HalideRuntime.h:674
halide_do_task_t
int(* halide_do_task_t)(void *, halide_task_t, int, uint8_t *)
If you use the default do_par_for, you can still set a custom handler to perform each individual task...
Definition: HalideRuntime.h:330
halide_set_custom_free
halide_free_t halide_set_custom_free(halide_free_t user_free)
halide_default_do_parallel_tasks
int halide_default_do_parallel_tasks(void *user_context, int num_tasks, struct halide_parallel_task_t *tasks, void *task_parent)
Definition: thread_pool_common.h:684
halide_mutex_array_create
struct halide_mutex_array * halide_mutex_array_create(uint64_t sz)
Definition: synchronization_common.h:913
halide_get_gpu_device
int halide_get_gpu_device(void *user_context)
Halide calls this to get the desired halide gpu device setting.
Definition: HalidePyTorchCudaHelpers.h:53
halide_semaphore_init_t
int(* halide_semaphore_init_t)(struct halide_semaphore_t *, int)
Definition: HalideRuntime.h:255
halide_set_custom_do_loop_task
halide_do_loop_task_t halide_set_custom_do_loop_task(halide_do_loop_task_t do_task)
Definition: thread_pool_common.h:816
halide_device_detach_native
int halide_device_detach_native(void *user_context, struct halide_buffer_t *buf)
halide_default_get_symbol
void * halide_default_get_symbol(const char *name)
halide_copy_to_device
int halide_copy_to_device(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)
Copy image data from host memory to device memory.
halide_set_custom_get_library_symbol
halide_get_library_symbol_t halide_set_custom_get_library_symbol(halide_get_library_symbol_t user_get_library_symbol)
halide_error
void halide_error(void *user_context, const char *)
Halide calls this function on runtime errors (for example bounds checking failures).
halide_device_release_crop
int halide_device_release_crop(void *user_context, struct halide_buffer_t *buf)
Release any resources associated with a cropped/sliced view of another buffer.
halide_can_use_target_features
int halide_can_use_target_features(int count, const uint64_t *features)
This function is called internally by Halide in some situations to determine if the current execution...
halide_error_split_factor_not_positive
int halide_error_split_factor_not_positive(void *user_context, const char *func_name, const char *orig, const char *outer, const char *inner, const char *factor_str, int factor)
halide_error_bad_type
int halide_error_bad_type(void *user_context, const char *func_name, uint32_t type_given, uint32_t correct_type)
halide_set_custom_do_task
halide_do_task_t halide_set_custom_do_task(halide_do_task_t do_task)
Definition: thread_pool_common.h:810
halide_do_parallel_tasks
int halide_do_parallel_tasks(void *user_context, int num_tasks, struct halide_parallel_task_t *tasks, void *task_parent)
Enqueue some number of the tasks described above and wait for them to complete.
Definition: thread_pool_common.h:861
halide_malloc_t
void *(* halide_malloc_t)(void *, size_t)
Definition: HalideRuntime.h:432
halide_device_wrap_native
int halide_device_wrap_native(void *user_context, struct halide_buffer_t *buf, uint64_t handle, const struct halide_device_interface_t *device_interface)
Wrap or detach a native device handle, setting the device field and device_interface field as appropr...
halide_get_trace_file
int halide_get_trace_file(void *user_context)
Halide calls this to retrieve the file descriptor to write binary trace events to.
halide_shutdown_trace
int halide_shutdown_trace(void)
If tracing is writing to a file.
halide_float16_bits_to_float
float halide_float16_bits_to_float(uint16_t)
Read bits representing a half precision floating point number and return the float that represents th...
halide_error_unaligned_host_ptr
int halide_error_unaligned_host_ptr(void *user_context, const char *func_name, int alignment)
halide_profiler_sample
int halide_profiler_sample(struct halide_profiler_state *s, uint64_t *prev_t)
Collects profiling information.
halide_register_device_allocation_pool
void halide_register_device_allocation_pool(struct halide_device_allocation_pool *)
Register a callback to be informed when halide_reuse_device_allocations(false) is called,...
HALIDE_ATTRIBUTE_ALIGN
#define HALIDE_ATTRIBUTE_ALIGN(x)
Definition: HalideRuntime.h:494
halide_msan_check_buffer_is_initialized
int halide_msan_check_buffer_is_initialized(void *user_context, struct halide_buffer_t *buffer, const char *buf_name)
Verify that the data pointed to by the halide_buffer_t is initialized (but not the halide_buffer_t it...
halide_do_parallel_tasks_t
int(* halide_do_parallel_tasks_t)(void *, int, struct halide_parallel_task_t *, void *task_parent)
Provide an entire custom tasking runtime via function pointers.
Definition: HalideRuntime.h:352
halide_argument_kind_t
halide_argument_kind_t
Definition: HalideRuntime.h:1763
halide_argument_kind_output_buffer
@ halide_argument_kind_output_buffer
Definition: HalideRuntime.h:1766
halide_argument_kind_input_scalar
@ halide_argument_kind_input_scalar
Definition: HalideRuntime.h:1764
halide_argument_kind_input_buffer
@ halide_argument_kind_input_buffer
Definition: HalideRuntime.h:1765
halide_semaphore_release
int halide_semaphore_release(struct halide_semaphore_t *, int n)
Definition: thread_pool_common.h:871
halide_buffer_t
struct halide_buffer_t halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Halide::Internal::begin
auto begin(reverse_adaptor< T > i)
Definition: Util.h:478
Halide::Internal::min
ConstantInterval min(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::operator<
bool operator<(const ConstantInterval &a, const ConstantInterval &b)
Halide::Internal::with_lanes
Expr with_lanes(const Expr &x, int lanes)
Rewrite the expression x to have lanes lanes.
Halide::Internal::end
auto end(reverse_adaptor< T > i)
Definition: Util.h:483
Halide::operator==
auto operator==(const Other &a, const GeneratorParam< T > &b) -> decltype(a==(T) b)
Equality comparison between GeneratorParam<T> and any type that supports operator== with T.
Definition: Generator.h:1131
Halide::operator!=
auto operator!=(const Other &a, const GeneratorParam< T > &b) -> decltype(a !=(T) b)
Inequality comparison between between GeneratorParam<T> and any type that supports operator!...
Definition: Generator.h:1144
Halide::print
Expr print(const std::vector< Expr > &values)
Create an Expr that prints out its value whenever it is evaluated.
runtime_internal.h
uint64_t
unsigned __INT64_TYPE__ uint64_t
Definition: runtime_internal.h:23
int64_t
signed __INT64_TYPE__ int64_t
Definition: runtime_internal.h:22
uintptr_t
__UINTPTR_TYPE__ uintptr_t
Definition: runtime_internal.h:75
int32_t
signed __INT32_TYPE__ int32_t
Definition: runtime_internal.h:24
uint8_t
unsigned __INT8_TYPE__ uint8_t
Definition: runtime_internal.h:29
ptrdiff_t
__PTRDIFF_TYPE__ ptrdiff_t
Definition: runtime_internal.h:32
uint16_t
unsigned __INT16_TYPE__ uint16_t
Definition: runtime_internal.h:27
size_t
__SIZE_TYPE__ size_t
Definition: runtime_internal.h:31
uint32_t
unsigned __INT32_TYPE__ uint32_t
Definition: runtime_internal.h:25
int16_t
signed __INT16_TYPE__ int16_t
Definition: runtime_internal.h:26
int8_t
signed __INT8_TYPE__ int8_t
Definition: runtime_internal.h:28
halide_buffer_t
The raw representation of an image passed around by generated Halide code.
Definition: HalideRuntime.h:1569
halide_buffer_t::padding
void * padding
Pads the buffer up to a multiple of 8 bytes.
Definition: HalideRuntime.h:1595
halide_buffer_t::dimensions
int32_t dimensions
The dimensionality of the buffer.
Definition: HalideRuntime.h:1588
halide_buffer_t::dim
halide_dimension_t * dim
The shape of the buffer.
Definition: HalideRuntime.h:1592
halide_buffer_t::device
uint64_t device
A device-handle for e.g.
Definition: HalideRuntime.h:1571
halide_buffer_t::host
uint8_t * host
A pointer to the start of the data in main memory.
Definition: HalideRuntime.h:1579
halide_buffer_t::type
struct halide_type_t type
The type of each buffer element.
Definition: HalideRuntime.h:1585
halide_buffer_t::device_interface
const struct halide_device_interface_t * device_interface
The interface used to interpret the above handle.
Definition: HalideRuntime.h:1574
halide_buffer_t::flags
uint64_t flags
flags with various meanings.
Definition: HalideRuntime.h:1582
halide_cond
Cross platform condition variable.
Definition: HalideRuntime.h:196
halide_cond::_private
uintptr_t _private[1]
Definition: HalideRuntime.h:197
halide_device_allocation_pool
Definition: HalideRuntime.h:2112
halide_device_allocation_pool::next
struct halide_device_allocation_pool * next
Definition: HalideRuntime.h:2114
halide_device_allocation_pool::release_unused
int(* release_unused)(void *user_context)
Definition: HalideRuntime.h:2113
halide_device_interface_impl_t
Definition: device_interface.h:8
halide_device_interface_t
Each GPU API provides a halide_device_interface_t struct pointing to the code that manages device all...
Definition: HalideRuntime.h:797
halide_device_interface_t::device_slice
int(* device_slice)(void *user_context, const struct halide_buffer_t *src, int slice_dim, int slice_pos, struct halide_buffer_t *dst)
Definition: HalideRuntime.h:814
halide_device_interface_t::device_and_host_malloc
int(* device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)
Definition: HalideRuntime.h:807
halide_device_interface_t::impl
const struct halide_device_interface_impl_t * impl
Definition: HalideRuntime.h:821
halide_device_interface_t::wrap_native
int(* wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle, const struct halide_device_interface_t *device_interface)
Definition: HalideRuntime.h:817
halide_device_interface_t::compute_capability
int(* compute_capability)(void *user_context, int *major, int *minor)
Definition: HalideRuntime.h:820
halide_device_interface_t::device_release_crop
int(* device_release_crop)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:816
halide_device_interface_t::device_crop
int(* device_crop)(void *user_context, const struct halide_buffer_t *src, struct halide_buffer_t *dst)
Definition: HalideRuntime.h:812
halide_device_interface_t::device_release
void(* device_release)(void *user_context, const struct halide_device_interface_t *device_interface)
Definition: HalideRuntime.h:802
halide_device_interface_t::copy_to_host
int(* copy_to_host)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:804
halide_device_interface_t::copy_to_device
int(* copy_to_device)(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)
Definition: HalideRuntime.h:805
halide_device_interface_t::device_free
int(* device_free)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:800
halide_device_interface_t::device_sync
int(* device_sync)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:801
halide_device_interface_t::detach_native
int(* detach_native)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:819
halide_device_interface_t::device_and_host_free
int(* device_and_host_free)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:809
halide_device_interface_t::device_malloc
int(* device_malloc)(void *user_context, struct halide_buffer_t *buf, const struct halide_device_interface_t *device_interface)
Definition: HalideRuntime.h:798
halide_device_interface_t::buffer_copy
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)
Definition: HalideRuntime.h:810
halide_dimension_t
Definition: HalideRuntime.h:1516
halide_dimension_t::min
int32_t min
Definition: HalideRuntime.h:1539
halide_dimension_t::flags
uint32_t flags
Definition: HalideRuntime.h:1542
halide_dimension_t::extent
int32_t extent
Definition: HalideRuntime.h:1539
halide_dimension_t::stride
int32_t stride
Definition: HalideRuntime.h:1539
halide_filter_argument_t_v0
Obsolete version of halide_filter_argument_t; only present in code that wrote halide_filter_metadata_...
Definition: HalideRuntime.h:1784
halide_filter_argument_t_v0::name
const char * name
Definition: HalideRuntime.h:1785
halide_filter_argument_t_v0::kind
int32_t kind
Definition: HalideRuntime.h:1786
halide_filter_argument_t_v0::dimensions
int32_t dimensions
Definition: HalideRuntime.h:1787
halide_filter_argument_t_v0::min
const struct halide_scalar_value_t * min
Definition: HalideRuntime.h:1789
halide_filter_argument_t_v0::def
const struct halide_scalar_value_t * def
Definition: HalideRuntime.h:1789
halide_filter_argument_t_v0::max
const struct halide_scalar_value_t * max
Definition: HalideRuntime.h:1789
halide_filter_argument_t_v0::type
struct halide_type_t type
Definition: HalideRuntime.h:1788
halide_filter_argument_t
halide_filter_argument_t is essentially a plain-C-struct equivalent to Halide::Argument; most user co...
Definition: HalideRuntime.h:1796
halide_filter_argument_t::scalar_estimate
const struct halide_scalar_value_t * scalar_estimate
Definition: HalideRuntime.h:1804
halide_filter_argument_t::scalar_max
const struct halide_scalar_value_t * scalar_max
Definition: HalideRuntime.h:1804
halide_filter_argument_t::buffer_estimates
int64_t const *const * buffer_estimates
Definition: HalideRuntime.h:1810
halide_filter_argument_t::kind
int32_t kind
Definition: HalideRuntime.h:1798
halide_filter_argument_t::scalar_def
const struct halide_scalar_value_t * scalar_def
Definition: HalideRuntime.h:1804
halide_filter_argument_t::type
struct halide_type_t type
Definition: HalideRuntime.h:1800
halide_filter_argument_t::scalar_min
const struct halide_scalar_value_t * scalar_min
Definition: HalideRuntime.h:1804
halide_filter_argument_t::dimensions
int32_t dimensions
Definition: HalideRuntime.h:1799
halide_filter_argument_t::name
const char * name
Definition: HalideRuntime.h:1797
halide_filter_metadata_t
Definition: HalideRuntime.h:1813
halide_filter_metadata_t::name
const char * name
The function name of the filter.
Definition: HalideRuntime.h:1835
halide_filter_metadata_t::version
int32_t version
version of this metadata; currently always 1.
Definition: HalideRuntime.h:1819
halide_filter_metadata_t::arguments
const struct halide_filter_argument_t * arguments
An array of the filters input and output arguments; this will never be null.
Definition: HalideRuntime.h:1828
halide_filter_metadata_t::num_arguments
int32_t num_arguments
The number of entries in the arguments field.
Definition: HalideRuntime.h:1822
halide_filter_metadata_t::target
const char * target
The Target for which the filter was compiled.
Definition: HalideRuntime.h:1832
halide_handle_traits
A type traits template to provide a halide_handle_cplusplus_type value from a C++ type.
Definition: Type.h:254
halide_mutex_array
Definition: synchronization_common.h:909
halide_mutex_array::array
struct halide_mutex * array
Definition: synchronization_common.h:910
halide_mutex
Cross-platform mutex.
Definition: HalideRuntime.h:191
halide_mutex::_private
uintptr_t _private[1]
Definition: HalideRuntime.h:192
halide_parallel_task_t
A parallel task to be passed to halide_do_parallel_tasks.
Definition: HalideRuntime.h:272
halide_parallel_task_t::semaphores
struct halide_semaphore_acquire_t * semaphores
Definition: HalideRuntime.h:285
halide_parallel_task_t::name
const char * name
Definition: HalideRuntime.h:281
halide_parallel_task_t::extent
int extent
Definition: HalideRuntime.h:290
halide_parallel_task_t::fn
halide_loop_task_t fn
Definition: HalideRuntime.h:275
halide_parallel_task_t::min_threads
int min_threads
Definition: HalideRuntime.h:309
halide_parallel_task_t::num_semaphores
int num_semaphores
Definition: HalideRuntime.h:286
halide_parallel_task_t::closure
uint8_t * closure
Definition: HalideRuntime.h:278
halide_parallel_task_t::min
int min
Definition: HalideRuntime.h:290
halide_parallel_task_t::serial
bool serial
Definition: HalideRuntime.h:314
halide_profiler_state
The global state of the profiler.
Definition: HalideRuntime.h:1984
halide_profiler_state::get_remote_profiler_state
void(* get_remote_profiler_state)(int *func, int *active_workers)
If this callback is defined, the profiler asserts that there is a single live instance,...
Definition: HalideRuntime.h:2008
halide_profiler_state::sampling_thread
struct halide_thread * sampling_thread
Retrieve remote profiler state.
Definition: HalideRuntime.h:1998
halide_profiler_state::sleep_time
int sleep_time
The amount of time the profiler thread sleeps between samples in microseconds.
Definition: HalideRuntime.h:2013
halide_profiler_state::pipelines
struct halide_profiler_pipeline_stats * pipelines
A linked list of stats gathered for each pipeline.
Definition: HalideRuntime.h:1991
halide_profiler_state::lock
struct halide_mutex lock
Guards access to the fields below.
Definition: HalideRuntime.h:1988
halide_profiler_state::instances
struct halide_profiler_instance_state * instances
The running instances of Halide pipelines.
Definition: HalideRuntime.h:2001
halide_profiler_state::shutdown
int shutdown
Set to 1 when you want the profiler to wait for all running instances to finish and then stop gracefu...
Definition: HalideRuntime.h:2017
halide_scalar_value_t
halide_scalar_value_t is a simple union able to represent all the well-known scalar values in a filte...
Definition: HalideRuntime.h:1741
halide_scalar_value_t::u
union halide_scalar_value_t::@2 u
halide_scalar_value_t::i8
int8_t i8
Definition: HalideRuntime.h:1744
halide_scalar_value_t::u32
uint32_t u32
Definition: HalideRuntime.h:1750
halide_scalar_value_t::u8
uint8_t u8
Definition: HalideRuntime.h:1748
halide_scalar_value_t::i16
int16_t i16
Definition: HalideRuntime.h:1745
halide_scalar_value_t::i64
int64_t i64
Definition: HalideRuntime.h:1747
halide_scalar_value_t::u64
uint64_t u64
Definition: HalideRuntime.h:1751
halide_scalar_value_t::f64
double f64
Definition: HalideRuntime.h:1753
halide_scalar_value_t::b
bool b
Definition: HalideRuntime.h:1743
halide_scalar_value_t::i32
int32_t i32
Definition: HalideRuntime.h:1746
halide_scalar_value_t::u16
uint16_t u16
Definition: HalideRuntime.h:1749
halide_scalar_value_t::f32
float f32
Definition: HalideRuntime.h:1752
halide_scalar_value_t::handle
void * handle
Definition: HalideRuntime.h:1754
halide_semaphore_acquire_t
A struct representing a semaphore and a number of items that must be acquired from it.
Definition: HalideRuntime.h:248
halide_semaphore_acquire_t::count
int count
Definition: HalideRuntime.h:250
halide_semaphore_acquire_t::semaphore
struct halide_semaphore_t * semaphore
Definition: HalideRuntime.h:249
halide_semaphore_t
An opaque struct representing a semaphore.
Definition: HalideRuntime.h:242
halide_semaphore_t::_private
uint64_t _private[2]
Definition: HalideRuntime.h:243
halide_trace_event_t
Definition: HalideRuntime.h:589
halide_trace_event_t::value
void * value
If the event type is a load or a store, this points to the value being loaded or stored.
Definition: HalideRuntime.h:597
halide_trace_event_t::coordinates
int32_t * coordinates
For loads and stores, an array which contains the location being accessed.
Definition: HalideRuntime.h:609
halide_trace_event_t::func
const char * func
The name of the Func or Pipeline that this event refers to.
Definition: HalideRuntime.h:591
halide_trace_event_t::trace_tag
const char * trace_tag
For halide_trace_tag, this points to a read-only null-terminated string of arbitrary text.
Definition: HalideRuntime.h:614
halide_trace_event_t::type
struct halide_type_t type
If the event type is a load or a store, this is the type of the data.
Definition: HalideRuntime.h:618
halide_trace_event_t::value_index
int32_t value_index
If this was a load or store of a Tuple-valued Func, this is which tuple element was accessed.
Definition: HalideRuntime.h:629
halide_trace_event_t::parent_id
int32_t parent_id
Definition: HalideRuntime.h:625
halide_trace_event_t::event
enum halide_trace_event_code_t event
The type of event.
Definition: HalideRuntime.h:621
halide_trace_event_t::dimensions
int32_t dimensions
The length of the coordinates array.
Definition: HalideRuntime.h:632
halide_trace_packet_t
The header of a packet in a binary trace.
Definition: HalideRuntime.h:679
halide_trace_packet_t::parent_id
int32_t parent_id
Definition: HalideRuntime.h:692
halide_trace_packet_t::value_index
int32_t value_index
Definition: HalideRuntime.h:693
halide_trace_packet_t::dimensions
int32_t dimensions
Definition: HalideRuntime.h:694
halide_trace_packet_t::size
uint32_t size
The total size of this packet in bytes.
Definition: HalideRuntime.h:683
halide_trace_packet_t::id
int32_t id
The id of this packet (for the purpose of parent_id).
Definition: HalideRuntime.h:686
halide_trace_packet_t::event
enum halide_trace_event_code_t event
Definition: HalideRuntime.h:691
halide_trace_packet_t::type
struct halide_type_t type
The remaining fields are equivalent to those in halide_trace_event_t.
Definition: HalideRuntime.h:690
halide_type_t
A runtime tag for a type in the halide type system.
Definition: HalideRuntime.h:503
halide_type_t::bits
uint8_t bits
The number of bits of precision of a single scalar value of this type.
Definition: HalideRuntime.h:515
halide_type_t::lanes
uint16_t lanes
How many elements in a vector.
Definition: HalideRuntime.h:519
halide_type_t::code
uint8_t code
The basic type code: signed integer, unsigned integer, or floating point.
Definition: HalideRuntime.h:510
error_code
int error_code
Definition: vulkan_resources.h:182
user_context
void * user_context
Definition: vulkan_resources.h:178