26 #ifdef Halide_STATIC_DEFINE
32 #define HALIDE_EXPORT __declspec(dllexport)
34 #define HALIDE_EXPORT __declspec(dllimport)
37 #define HALIDE_EXPORT __attribute__((visibility("default")))
42 #if defined(COMPILING_HALIDE) || defined(BUILDING_PYTHON)
43 #define HALIDE_NO_USER_CODE_INLINE
45 #define HALIDE_NO_USER_CODE_INLINE HALIDE_NEVER_INLINE
69 template<
typename DST,
typename SRC,
70 typename std::enable_if<std::is_floating_point<SRC>::value>::type * =
nullptr>
72 if (std::is_integral<DST>::value) {
86 template<
typename DST,
typename SRC,
87 typename std::enable_if<std::is_integral<SRC>::value>::type * =
nullptr>
89 if (std::is_integral<DST>::value) {
97 if (std::is_integral<SRC>::value && std::is_signed<DST>::value &&
sizeof(DST) <
sizeof(SRC)) {
98 using UnsignedSrc =
typename std::make_unsigned<SRC>::type;
99 return (DST)(s & (UnsignedSrc)(-1));
106 template<
typename DstType,
typename SrcType>
108 static_assert(
sizeof(SrcType) ==
sizeof(DstType),
"Types must be same size");
151 bool starts_with(
const std::string &str,
const std::string &prefix);
154 bool ends_with(
const std::string &str,
const std::string &suffix);
157 std::string
replace_all(
const std::string &str,
const std::string &find,
const std::string &replace);
160 std::vector<std::string>
split_string(
const std::string &source,
const std::string &delim);
165 template<
typename T,
typename Fn>
172 for (
size_t i = 1; i < vec.size(); i++) {
173 result = f(result, vec[i]);
180 template<
typename T,
typename Fn>
187 for (
size_t i = vec.size() - 1; i > 0; i--) {
188 result = f(vec[i - 1], result);
193 template<
typename... T>
196 template<
typename T1,
typename... Args>
197 struct meta_and<T1, Args...> : std::integral_constant<bool, T1::value && meta_and<Args...>::value> {};
199 template<
typename... T>
202 template<
typename T1,
typename... Args>
203 struct meta_or<T1, Args...> : std::integral_constant<bool, T1::value || meta_or<Args...>::value> {};
205 template<
typename To,
typename... Args>
232 std::string
file_make_temp(
const std::string &prefix,
const std::string &suffix);
307 const std::string temp_path;
308 bool do_unlink =
true;
355 #if __cplusplus >= 201402L
359 using std::integer_sequence;
369 template<
typename T, T... Ints>
371 static constexpr
size_t size() {
372 return sizeof...(Ints);
379 template<
typename T, T... Ints>
384 template<
typename T, T I, T N>
390 template<
typename T, T N>
395 template<
typename T, T N>
398 template<
size_t... Ints>
416 #define HALIDE_TIC Halide::Internal::halide_tic_impl(__FILE__, __LINE__)
417 #define HALIDE_TOC Halide::Internal::halide_toc_impl(__FILE__, __LINE__)
418 #ifdef COMPILING_HALIDE
419 #define TIC HALIDE_TIC
420 #define TOC HALIDE_TOC
426 template<
typename TO>
428 template<typename FROM, typename TO2 = TO, typename std::enable_if<!std::is_same<TO2, bool>::value>::type * =
nullptr>
429 inline constexpr
static TO2
value(
const FROM &from) {
430 return static_cast<TO2
>(from);
433 template<typename FROM, typename TO2 = TO, typename std::enable_if<std::is_same<TO2, bool>::value>::type * =
nullptr>
434 inline constexpr
static TO2
value(
const FROM &from) {
442 template<
typename TO>
444 template<typename FROM, typename TO2 = TO, typename std::enable_if<!std::is_convertible<FROM, TO>::value>::type * =
nullptr>
445 inline constexpr
static bool value(
const FROM &from) {
449 template<typename FROM, typename TO2 = TO, typename std::enable_if<std::is_convertible<FROM, TO>::value && std::is_arithmetic<TO>::value && std::is_arithmetic<FROM>::value && !std::is_same<TO, FROM>::value>::type * =
nullptr>
450 inline constexpr
static bool value(
const FROM &from) {
454 template<typename FROM, typename TO2 = TO, typename std::enable_if<std::is_convertible<FROM, TO>::value && !(std::is_arithmetic<TO>::value && std::is_arithmetic<FROM>::value && !std::is_same<TO, FROM>::value)>::type * =
nullptr>
455 inline constexpr
static bool value(
const FROM &from) {
This file declares the routines used by Halide internally in its runtime.
A simple utility class that creates a temporary file in its ctor and deletes that file in its dtor; t...
TemporaryFile(TemporaryFile &&)=delete
TemporaryFile & operator=(TemporaryFile &&)=delete
TemporaryFile(const TemporaryFile &)=delete
const std::string & pathname() const
TemporaryFile(const std::string &prefix, const std::string &suffix)
TemporaryFile & operator=(const TemporaryFile &)=delete
void assert_file_exists(const std::string &name)
assert-fail if the file doesn't exist.
void file_unlink(const std::string &name)
Wrapper for unlink().
std::string make_entity_name(void *stack_ptr, const std::string &type, char prefix)
Make a unique name for an object based on the name of the stack variable passed in.
bool ends_with(const std::string &str, const std::string &suffix)
Test if the first string ends with the second string.
std::vector< std::string > split_string(const std::string &source, const std::string &delim)
Split the source string using 'delim' as the divider.
void run_with_large_stack(const std::function< void()> &action)
Call the given action in a platform-specific context that provides at least 8MB of stack space.
void write_entire_file(const std::string &pathname, const void *source, size_t source_len)
Create or replace the contents of a file with a given pointer-and-length of memory.
std::string file_make_temp(const std::string &prefix, const std::string &suffix)
Create a unique file with a name of the form prefixXXXXXsuffix in an arbitrary (but writable) directo...
int get_llvm_version()
Return the LLVM_VERSION against which this libHalide is compiled.
void dir_rmdir(const std::string &name)
Wrapper for rmdir().
make_integer_sequence< size_t, N > make_index_sequence
void halide_toc_impl(const char *file, int line)
bool sub_would_overflow(int bits, int64_t a, int64_t b)
std::string get_env_variable(char const *env_var_name)
Get value of an environment variable.
bool add_would_overflow(int bits, int64_t a, int64_t b)
Routines to test if math would overflow for signed integers with the given number of bits.
std::string extract_namespaces(const std::string &name, std::vector< std::string > &namespaces)
Returns base name and fills in namespaces, outermost one first in vector.
void ensure_no_file_exists(const std::string &name)
Ensure that no file with this path exists.
DstType reinterpret_bits(const SrcType &src)
An aggressive form of reinterpret cast used for correct type-punning.
bool mul_would_overflow(int bits, int64_t a, int64_t b)
std::string replace_all(const std::string &str, const std::string &find, const std::string &replace)
Replace all matches of the second string in the first string with the last string.
FileStat file_stat(const std::string &name)
Wrapper for stat().
T fold_left(const std::vector< T > &vec, Fn f)
Perform a left fold of a vector.
std::string unique_name(char prefix)
Generate a unique name starting with the given prefix.
std::string running_program_name()
Get the name of the currently running executable.
DST safe_numeric_cast(SRC s)
Some numeric conversions are UB if the value won't fit in the result; safe_numeric_cast<>() is meant ...
void assert_no_file_exists(const std::string &name)
assert-fail if the file DOES exist.
std::string dir_make_temp()
Create a unique directory in an arbitrary (but writable) directory; this is typically somewhere insid...
integer_sequence< size_t, Ints... > index_sequence
std::string c_print_name(const std::string &name)
Emit a version of a string that is a valid identifier in C (.
std::vector< char > read_entire_file(const std::string &pathname)
Read the entire contents of a file into a vector<char>.
void halide_tic_impl(const char *file, int line)
bool starts_with(const std::string &str, const std::string &prefix)
Test if the first string starts with the second string.
typename make_integer_sequence_helper< T, 0, N >::type make_integer_sequence
T fold_right(const std::vector< T > &vec, Fn f)
Returns a right fold of a vector.
bool file_exists(const std::string &name)
Wrapper for access().
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Expr min(const FuncRef &a, const FuncRef &b)
Explicit overloads of min and max for FuncRef.
void load_plugin(const std::string &lib_name)
Load a plugin in the form of a dynamic library (e.g.
Expr max(const FuncRef &a, const FuncRef &b)
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
unsigned __INT32_TYPE__ uint32_t
void * memcpy(void *s1, const void *s2, size_t n)
constexpr static bool value(const FROM &from)
Helper class for saving/restoring variable values on the stack, to allow for early-exit that preserve...
ScopedValue(ScopedValue &&that) noexcept=default
ScopedValue(T &var, T new_value)
Preserve the old value, then set the var to a new value.
ScopedValue(T &var)
Preserve the old value, restored at dtor time.
ScopedValue(const ScopedValue &that)=delete
constexpr static TO2 value(const FROM &from)
static constexpr size_t size()
typename next_integer_sequence< typename make_integer_sequence_helper< T, I+1, N >::type >::type type