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
69template<
typename DST,
typename SRC,
70 typename std::enable_if<std::is_floating_point<SRC>::value>::type * =
nullptr>
72 if (std::is_integral<DST>::value) {
86template<
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));
106template<
typename DstType,
typename SrcType>
108 static_assert(
sizeof(SrcType) ==
sizeof(DstType),
"Types must be same size");
110 memcpy(&dst, &src,
sizeof(SrcType));
151bool starts_with(
const std::string &str,
const std::string &prefix);
154bool ends_with(
const std::string &str,
const std::string &suffix);
157std::string
replace_all(
const std::string &str,
const std::string &find,
const std::string &replace);
160std::vector<std::string>
split_string(
const std::string &source,
const std::string &delim);
165template<
typename T,
typename Fn>
172 for (
size_t i = 1; i < vec.size(); i++) {
173 result = f(result, vec[i]);
180template<
typename T,
typename Fn>
187 for (
size_t i = vec.size() - 1; i > 0; i--) {
188 result = f(vec[i - 1], result);
193template<
typename... T>
196template<
typename T1,
typename... Args>
197struct meta_and<T1, Args...> : std::integral_constant<bool, T1::value && meta_and<Args...>::value> {};
199template<
typename... T>
202template<
typename T1,
typename... Args>
203struct meta_or<T1, Args...> : std::integral_constant<bool, T1::value || meta_or<Args...>::value> {};
205template<
typename To,
typename... Args>
307 const std::string temp_path;
308 bool do_unlink =
true;
361#define HALIDE_TIC Halide::Internal::halide_tic_impl(__FILE__, __LINE__)
362#define HALIDE_TOC Halide::Internal::halide_toc_impl(__FILE__, __LINE__)
363#ifdef COMPILING_HALIDE
364#define TIC HALIDE_TIC
365#define TOC HALIDE_TOC
373 template<typename FROM, typename TO2 = TO, typename std::enable_if<!std::is_same<TO2, bool>::value>::type * =
nullptr>
374 inline constexpr static TO2
value(
const FROM &from) {
375 return static_cast<TO2
>(from);
378 template<typename FROM, typename TO2 = TO, typename std::enable_if<std::is_same<TO2, bool>::value>::type * =
nullptr>
379 inline constexpr static TO2
value(
const FROM &from) {
389 template<typename FROM, typename TO2 = TO, typename std::enable_if<!std::is_convertible<FROM, TO>::value>::type * =
nullptr>
390 inline constexpr static bool value(
const FROM &from) {
394 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>
395 inline constexpr static bool value(
const FROM &from) {
399 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>
400 inline constexpr static bool value(
const FROM &from) {
409std::string
c_print_name(
const std::string &name,
bool prefix_underscore =
true);
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 & operator=(TemporaryFile &&)=delete
TemporaryFile(TemporaryFile &&)=delete
TemporaryFile & operator=(const TemporaryFile &)=delete
const std::string & pathname() const
TemporaryFile(const TemporaryFile &)=delete
TemporaryFile(const std::string &prefix, const std::string &suffix)
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.
void run_with_large_stack(const std::function< void()> &action)
Call the given action in a platform-specific context that provides at least the stack space returned ...
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::vector< char > read_entire_file(const std::string &pathname)
Read the entire contents of a file into a vector<char>.
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().
std::string c_print_name(const std::string &name, bool prefix_underscore=true)
Emit a version of a string that is a valid identifier in C (.
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().
std::vector< std::string > split_string(const std::string &source, const std::string &delim)
Split the source string using 'delim' as the divider.
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...
int popcount64(uint64_t x)
Portable versions of popcount, count-leading-zeros, and count-trailing-zeros.
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.
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.
constexpr size_t default_compiler_stack_size
The default amount of stack used for lowering and codegen.
size_t get_compiler_stack_size()
Return how much stack size the compiler should use for calls that go through run_with_large_stack bel...
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.
void set_compiler_stack_size(size_t)
Set how much stack the compiler should use for compilation in bytes.
Expr max(const FuncRef &a, const FuncRef &b)
unsigned __INT64_TYPE__ uint64_t
signed __INT64_TYPE__ int64_t
void * memcpy(void *s1, const void *s2, size_t n)
unsigned __INT32_TYPE__ uint32_t
static constexpr 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
static constexpr TO2 value(const FROM &from)