HalideRuntime.h
浏览该文件的文档.
#ifndef HALIDE_HALIDERUNTIME_H
#define HALIDE_HALIDERUNTIME_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
// Note that you should not use "inline" along with HALIDE_ALWAYS_INLINE;
// it is not necessary, and may produce warnings for some build configurations.
#ifdef _MSC_VER
#define HALIDE_ALWAYS_INLINE __forceinline
#define HALIDE_NEVER_INLINE __declspec(noinline)
#else
#define HALIDE_ALWAYS_INLINE __attribute__((always_inline)) inline
#define HALIDE_NEVER_INLINE __attribute__((noinline))
#endif
// Forward-declare to suppress warnings if compiling as C.
struct halide_buffer_t;
typedef enum halide_type_code_t
{
halide_type_int = 0,
halide_type_uint = 1,
halide_type_float = 2,
halide_type_handle = 3
} halide_type_code_t;
// Note that while __attribute__ can go before or after the declaration,
// __declspec apparently is only allowed before.
#ifndef HALIDE_ATTRIBUTE_ALIGN
#ifdef _MSC_VER
#define HALIDE_ATTRIBUTE_ALIGN(x) __declspec(align(x))
#else
#define HALIDE_ATTRIBUTE_ALIGN(x) __attribute__((aligned(x)))
#endif
#endif
struct halide_type_t {
#if __cplusplus >= 201103L
HALIDE_ATTRIBUTE_ALIGN(1) halide_type_code_t code; // halide_type_code_t
#else
HALIDE_ATTRIBUTE_ALIGN(1) uint8_t code; // halide_type_code_t
#endif
HALIDE_ATTRIBUTE_ALIGN(1) uint8_t bits;
HALIDE_ATTRIBUTE_ALIGN(2) uint16_t lanes;
#ifdef __cplusplus
HALIDE_ALWAYS_INLINE halide_type_t(halide_type_code_t code, uint8_t bits, uint16_t lanes = 1)
: code(code), bits(bits), lanes(lanes) {
}
HALIDE_ALWAYS_INLINE halide_type_t() : code((halide_type_code_t)0), bits(0), lanes(0) {}
HALIDE_ALWAYS_INLINE bool operator==(const halide_type_t &other) const {
return (code == other.code &&
bits == other.bits &&
lanes == other.lanes);
}
HALIDE_ALWAYS_INLINE bool operator!=(const halide_type_t &other) const {
return !(*this == other);
}
HALIDE_ALWAYS_INLINE int bytes() const { return (bits + 7) / 8; }
#endif
};
struct halide_device_interface_impl_t;
struct halide_device_interface_t {
int (*device_malloc)(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
int (*device_free)(void *user_context, struct halide_buffer_t *buf);
int (*device_sync)(void *user_context, struct halide_buffer_t *buf);
void (*device_release)(void *user_context,
const struct halide_device_interface_t *device_interface);
int (*copy_to_host)(void *user_context, struct halide_buffer_t *buf);
int (*copy_to_device)(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
int (*device_and_host_malloc)(void *user_context, struct halide_buffer_t *buf,
const struct halide_device_interface_t *device_interface);
int (*device_and_host_free)(void *user_context, struct halide_buffer_t *buf);
int (*buffer_copy)(void *user_context, struct halide_buffer_t *src,
const struct halide_device_interface_t *dst_device_interface, struct halide_buffer_t *dst);
int (*device_crop)(void *user_context, const struct halide_buffer_t *src,
struct halide_buffer_t *dst);
int (*device_release_crop)(void *user_context, struct halide_buffer_t *buf);
int (*wrap_native)(void *user_context, struct halide_buffer_t *buf, uint64_t handle,
const struct halide_device_interface_t *device_interface);
int (*detach_native)(void *user_context, struct halide_buffer_t *buf);
const struct halide_device_interface_impl_t *impl;
};
typedef struct halide_dimension_t {
int32_t min, extent, stride;
// Per-dimension flags. None are defined yet (This is reserved for future use).
uint32_t flags;
#ifdef __cplusplus
HALIDE_ALWAYS_INLINE halide_dimension_t() : min(0), extent(0), stride(0), flags(0) {}
HALIDE_ALWAYS_INLINE halide_dimension_t(int32_t m, int32_t e, int32_t s, uint32_t f = 0) :
min(m), extent(e), stride(s), flags(f) {}
HALIDE_ALWAYS_INLINE bool operator==(const halide_dimension_t &other) const {
return (min == other.min) &&
(extent == other.extent) &&
(stride == other.stride) &&
(flags == other.flags);
}
HALIDE_ALWAYS_INLINE bool operator!=(const halide_dimension_t &other) const {
return !(*this == other);
}
#endif
} halide_dimension_t;
#ifdef __cplusplus
} // extern "C"
#endif
typedef enum {halide_buffer_flag_host_dirty = 1,
halide_buffer_flag_device_dirty = 2} halide_buffer_flags;
typedef struct halide_buffer_t {
uint64_t device;
const struct halide_device_interface_t *device_interface;
uint8_t* host;
uint64_t flags;
struct halide_type_t type;
int32_t dimensions;
halide_dimension_t *dim;
void *padding;
} halide_buffer_t;
#ifdef __cplusplus
namespace {
template<typename T> struct check_is_pointer;
template<typename T> struct check_is_pointer<T *> {};
}
template<typename T>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of() {
// Create a compile-time error if T is not a pointer (without
// using any includes - this code goes into the runtime).
check_is_pointer<T> check;
(void)check;
return halide_type_t(halide_type_handle, 64);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<float>() {
return halide_type_t(halide_type_float, 32);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<double>() {
return halide_type_t(halide_type_float, 64);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<bool>() {
return halide_type_t(halide_type_uint, 1);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<uint8_t>() {
return halide_type_t(halide_type_uint, 8);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<uint16_t>() {
return halide_type_t(halide_type_uint, 16);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<uint32_t>() {
return halide_type_t(halide_type_uint, 32);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<uint64_t>() {
return halide_type_t(halide_type_uint, 64);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<int8_t>() {
return halide_type_t(halide_type_int, 8);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<int16_t>() {
return halide_type_t(halide_type_int, 16);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<int32_t>() {
return halide_type_t(halide_type_int, 32);
}
template<>
HALIDE_ALWAYS_INLINE halide_type_t halide_type_of<int64_t>() {
return halide_type_t(halide_type_int, 64);
}
#endif
#endif // HALIDE_HALIDERUNTIME_H
halide_dimension_t
Definition: HalideRuntime.h:167
halide_buffer_flag_host_dirty
Definition: HalideRuntime.h:195
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:153
halide_dimension_t
struct halide_dimension_t halide_dimension_t
halide_device_interface_t::detach_native
int(* detach_native)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:163
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:161
halide_buffer_t::type
struct halide_type_t type
Definition: HalideRuntime.h:219
halide_device_interface_t::device_and_host_free
int(* device_and_host_free)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:155
halide_type_float
floating point numbers
Definition: HalideRuntime.h:63
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:144
halide_device_interface_t::device_release
void(* device_release)(void *user_context, const struct halide_device_interface_t *device_interface)
Definition: HalideRuntime.h:148
halide_dimension_t::extent
int32_t extent
Definition: HalideRuntime.h:168
halide_buffer_t::flags
uint64_t flags
Definition: HalideRuntime.h:216
halide_dimension_t::flags
uint32_t flags
Definition: HalideRuntime.h:171
halide_buffer_t::dim
halide_dimension_t * dim
Definition: HalideRuntime.h:226
halide_buffer_flag_device_dirty
Definition: HalideRuntime.h:196
halide_type_uint
unsigned integers
Definition: HalideRuntime.h:62
halide_device_interface_t::device_sync
int(* device_sync)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:147
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:151
halide_device_interface_t::device_release_crop
int(* device_release_crop)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:160
halide_buffer_t
struct halide_buffer_t halide_buffer_t
halide_device_interface_t
Definition: HalideRuntime.h:143
halide_type_handle
opaque pointer type (void *)
Definition: HalideRuntime.h:64
halide_buffer_t::dimensions
int32_t dimensions
Definition: HalideRuntime.h:222
halide_dimension_t::stride
int32_t stride
Definition: HalideRuntime.h:168
HALIDE_ALWAYS_INLINE
#define HALIDE_ALWAYS_INLINE
Definition: HalideRuntime.h:18
halide_type_t
Definition: HalideRuntime.h:82
halide_buffer_t::device_interface
const struct halide_device_interface_t * device_interface
Definition: HalideRuntime.h:208
halide_buffer_t::host
uint8_t * host
Definition: HalideRuntime.h:213
halide_device_interface_t::impl
const struct halide_device_interface_impl_t * impl
Definition: HalideRuntime.h:164
halide_dimension_t::min
int32_t min
Definition: HalideRuntime.h:168
halide_buffer_t::padding
void * padding
Definition: HalideRuntime.h:229
halide_type_code_t
halide_type_code_t
Definition: HalideRuntime.h:59
halide_device_interface_t::copy_to_host
int(* copy_to_host)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:150
halide_buffer_t::device
uint64_t device
Definition: HalideRuntime.h:205
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:156
halide_buffer_t
Definition: HalideRuntime.h:203
halide_type_t::HALIDE_ATTRIBUTE_ALIGN
HALIDE_ATTRIBUTE_ALIGN(1) uint8_t code
halide_buffer_flags
halide_buffer_flags
Definition: HalideRuntime.h:195
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:158
halide_type_int
signed integers
Definition: HalideRuntime.h:61
halide_device_interface_t::device_free
int(* device_free)(void *user_context, struct halide_buffer_t *buf)
Definition: HalideRuntime.h:146