Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/hannk/interpreter/ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -584,22 +584,22 @@ double dequantize_scalar(const Tensor *t) {
int zero = q.zero.empty() ? 0 : q.zero.front();

const auto &buf = t->buffer();
switch (buf.type().element_of().as_u32()) {
case halide_type_of<uint8_t>().as_u32():
switch (buf.type()) {
case halide_type_of<uint8_t>():
return (as_scalar<uint8_t>(buf) - zero) * scale;
case halide_type_of<int8_t>().as_u32():
case halide_type_of<int8_t>():
return (as_scalar<int8_t>(buf) - zero) * scale;
case halide_type_of<uint16_t>().as_u32():
case halide_type_of<uint16_t>():
return (as_scalar<uint16_t>(buf) - zero) * scale;
case halide_type_of<int16_t>().as_u32():
case halide_type_of<int16_t>():
return (as_scalar<int16_t>(buf) - zero) * scale;
case halide_type_of<uint32_t>().as_u32():
case halide_type_of<uint32_t>():
return (as_scalar<uint32_t>(buf) - zero) * scale;
case halide_type_of<int32_t>().as_u32():
case halide_type_of<int32_t>():
return (as_scalar<int32_t>(buf) - zero) * scale;
case halide_type_of<float>().as_u32():
case halide_type_of<float>():
return (as_scalar<float>(buf) - zero) * scale;
case halide_type_of<double>().as_u32():
case halide_type_of<double>():
return (as_scalar<double>(buf) - zero) * scale;
default:
HLOG(FATAL) << "Unsupported type " << buf.type();
Expand Down Expand Up @@ -765,7 +765,7 @@ halide_type_t ConvOp::filter_type() const {
return metadata->arguments[2].type;
} else {
HLOG(FATAL) << "Unsupported type " << output()->type() << "\n";
return halide_type_t(halide_type_int, 0, 0);
return halide_type_t(halide_type_int, 0);
}
}

Expand Down
6 changes: 3 additions & 3 deletions apps/hannk/util/buffer_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ template<template<typename> class Functor, typename... Args>
auto dynamic_type_dispatch(const halide_type_t &type, Args &&...args)
-> decltype(std::declval<Functor<uint8_t>>()(std::forward<Args>(args)...)) {

#define HANDLE_CASE(CODE, BITS, TYPE) \
case halide_type_t(CODE, BITS).as_u32(): \
#define HANDLE_CASE(CODE, BITS, TYPE) \
case halide_type_t(CODE, BITS): \
return Functor<TYPE>()(std::forward<Args>(args)...);

switch (type.element_of().as_u32()) {
switch (type) {
// HANDLE_CASE(halide_type_float, 16, float) // TODO
HANDLE_CASE(halide_type_float, 32, float)
HANDLE_CASE(halide_type_float, 64, double)
Expand Down
14 changes: 0 additions & 14 deletions apps/hannk/util/error_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,6 @@

namespace hannk {

std::ostream &operator<<(std::ostream &stream, const halide_type_t &type) {
if (type.code == halide_type_uint && type.bits == 1) {
stream << "bool";
} else {
static const char *const names[5] = {"int", "uint", "float", "handle", "bfloat"};
assert(type.code >= 0 && type.code < size(names));
stream << names[type.code] << (int)type.bits;
}
if (type.lanes > 1) {
stream << "x" << (int)type.lanes;
}
return stream;
}

std::ostream &operator<<(std::ostream &s, const halide_dimension_t &dim) {
return s << "{" << dim.min << ", " << dim.extent << ", " << dim.stride << "}";
}
Expand Down
1 change: 0 additions & 1 deletion apps/hannk/util/error_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ constexpr size_t size(T (&)[N]) {
return N;
}

std::ostream &operator<<(std::ostream &stream, const halide_type_t &type);
std::ostream &operator<<(std::ostream &s, const halide_dimension_t &dim);

template<typename T>
Expand Down
2 changes: 1 addition & 1 deletion python_bindings/src/halide/halide_/PyBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Halide::Runtime::Buffer<T, Dims, InClassDimStorage> pybufferinfo_to_halidebuffer
const int dst_axis = reverse_axes ? (info.ndim - i - 1) : i;
dims[dst_axis] = {0, (int32_t)info.shape[i], (int32_t)elem_stride};
}
return Halide::Runtime::Buffer<T, Dims, InClassDimStorage>(t, info.ptr, (int)info.ndim, dims);
return Halide::Runtime::Buffer<T, Dims, InClassDimStorage>(t.to_abi(), info.ptr, (int)info.ndim, dims);
}

} // namespace PythonBindings
Expand Down
6 changes: 3 additions & 3 deletions python_bindings/src/halide/halide_/PyCallable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ class PyCallable {
argv[slot] = &scalar_storage[slot];

#define HALIDE_HANDLE_TYPE_DISPATCH(CODE, BITS, TYPE, FIELD) \
case halide_type_t(CODE, BITS).as_u32(): \
case halide_type_t(CODE, BITS): \
scalar_storage[slot].u.FIELD = cast_to<TYPE>(value); \
cci[slot] = Callable::make_scalar_qcci(halide_type_t(CODE, BITS)); \
break;

switch (((halide_type_t)c_arg.type).element_of().as_u32()) {
switch (c_arg.type.to_abi()) {
HALIDE_HANDLE_TYPE_DISPATCH(halide_type_float, 32, float, f32)
HALIDE_HANDLE_TYPE_DISPATCH(halide_type_float, 64, double, f64)
HALIDE_HANDLE_TYPE_DISPATCH(halide_type_int, 8, int8_t, i8)
Expand All @@ -137,7 +137,7 @@ class PyCallable {
HALIDE_HANDLE_TYPE_DISPATCH(halide_type_uint, 64, uint64_t, u64)
HALIDE_HANDLE_TYPE_DISPATCH(halide_type_handle, 64, uint64_t, u64) // Handle types are always uint64, regardless of pointer size
default:
_halide_user_assert(0) << "Unsupported type in Callable argument list: " << c_arg.type << "\n";
_halide_user_error << "Unsupported type in Callable argument list: " << c_arg.type << "\n";
}

#undef HALIDE_HANDLE_TYPE_DISPATCH
Expand Down
4 changes: 2 additions & 2 deletions python_bindings/src/halide/halide_/PyType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ std::string halide_type_to_string(const Type &type) {
stream << "bfloat";
break;
case halide_type_handle:
if (type.handle_type) {
stream << type.handle_type->inner_name.name;
if (type.handle_type()) {
stream << type.handle_type()->inner_name.name;
} else {
stream << "handle";
}
Expand Down
2 changes: 1 addition & 1 deletion src/AddImageChecks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ Stmt add_image_checks_inner(Stmt s,
{
string type_name = name + ".type";
Expr type_var = Variable::make(UInt(32), type_name, image, param, rdom);
uint32_t correct_type_bits = ((halide_type_t)type).as_u32();
uint32_t correct_type_bits = type.to_abi();
Expr correct_type_expr = make_const(UInt(32), correct_type_bits);
Expr error = Call::make(Int(32), "halide_error_bad_type",
{error_name, type_var, correct_type_expr},
Expand Down
20 changes: 10 additions & 10 deletions src/Buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class Buffer {
typename = std::enable_if_t<Internal::all_ints_and_optional_name<Args...>::value>>
explicit Buffer(Type t,
int first, Args... rest)
: Buffer(Runtime::Buffer<T, Dims>(t, Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
Internal::get_name_from_end_of_parameter_pack(rest...)) {
}

Expand All @@ -229,14 +229,14 @@ class Buffer {
explicit Buffer(Type t,
const std::vector<int> &sizes,
const std::string &name = "")
: Buffer(Runtime::Buffer<T, Dims>(t, sizes), name) {
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), sizes), name) {
}

explicit Buffer(Type t,
const std::vector<int> &sizes,
const std::vector<int> &storage_order,
const std::string &name = "")
: Buffer(Runtime::Buffer<T, Dims>(t, sizes, storage_order), name) {
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), sizes, storage_order), name) {
}

explicit Buffer(const std::vector<int> &sizes,
Expand All @@ -261,7 +261,7 @@ class Buffer {
explicit Buffer(Type t,
Internal::add_const_if_T_is_const<T, void> *data,
int first, Args &&...rest)
: Buffer(Runtime::Buffer<T, Dims>(t, data, Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), data, Internal::get_shape_from_start_of_parameter_pack(first, rest...)),
Internal::get_name_from_end_of_parameter_pack(rest...)) {
}

Expand All @@ -271,7 +271,7 @@ class Buffer {
Internal::add_const_if_T_is_const<T, void> *data,
const std::vector<int> &sizes,
const std::string &name = "")
: Buffer(Runtime::Buffer<T, Dims>(t, data, sizes, name)) {
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), data, sizes, name)) {
}

template<typename... Args,
Expand All @@ -292,15 +292,15 @@ class Buffer {
Internal::add_const_if_T_is_const<T, void> *data,
const std::vector<int> &sizes,
const std::string &name = "")
: Buffer(Runtime::Buffer<T, Dims>(t, data, sizes), name) {
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), data, sizes), name) {
}

explicit Buffer(Type t,
Internal::add_const_if_T_is_const<T, void> *data,
int d,
const halide_dimension_t *shape,
const std::string &name = "")
: Buffer(Runtime::Buffer<T, Dims>(t, data, d, shape), name) {
: Buffer(Runtime::Buffer<T, Dims>(t.to_abi(), data, d, shape), name) {
}

explicit Buffer(T *data,
Expand All @@ -315,7 +315,7 @@ class Buffer {
}

static Buffer<> make_scalar(Type t, const std::string &name = "") {
return Buffer<>(Runtime::Buffer<>::make_scalar(t), name);
return Buffer<>(Runtime::Buffer<>::make_scalar(t.to_abi()), name);
}

static Buffer<T, Dims> make_scalar(T *data, const std::string &name = "") {
Expand All @@ -327,7 +327,7 @@ class Buffer {
}

static Buffer<> make_interleaved(Type t, int width, int height, int channels, const std::string &name = "") {
return Buffer<>(Runtime::Buffer<>::make_interleaved(t, width, height, channels), name);
return Buffer<>(Runtime::Buffer<>::make_interleaved(t.to_abi(), width, height, channels), name);
}

static Buffer<T, Dims> make_interleaved(T *data, int width, int height, int channels, const std::string &name = "") {
Expand All @@ -337,7 +337,7 @@ class Buffer {
static Buffer<Internal::add_const_if_T_is_const<T, void>>
make_interleaved(Type t, T *data, int width, int height, int channels, const std::string &name = "") {
using T2 = Internal::add_const_if_T_is_const<T, void>;
return Buffer<T2, Dims>(Runtime::Buffer<T2, Dims>::make_interleaved(t, data, width, height, channels), name);
return Buffer<T2, Dims>(Runtime::Buffer<T2, Dims>::make_interleaved(t.to_abi(), data, width, height, channels), name);
}

template<typename T2, int D2>
Expand Down
50 changes: 25 additions & 25 deletions src/CPlusPlusMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@ struct QualsState {

if (finished ||
(!is_pointer && !last_is_pointer &&
type.handle_type->reference_type == halide_handle_cplusplus_type::NotReference)) {
type.handle_type()->reference_type == halide_handle_cplusplus_type::NotReference)) {
finished = true;
return;
}

result = one_qualifier_set(last_is_const, last_is_volatile, last_is_restrict, last_is_pointer, base_mode) + result;
if (last_is_pointer && (is_pointer || type.handle_type->reference_type != halide_handle_cplusplus_type::NotReference)) {
if (last_is_pointer && (is_pointer || type.handle_type()->reference_type != halide_handle_cplusplus_type::NotReference)) {
result = one_qualifier_set(last_is_const, last_is_volatile, last_is_restrict, false, base_mode) + result;
}

Expand All @@ -174,9 +174,9 @@ struct QualsState {
result = one_qualifier_set(false, false, false, last_is_pointer, base_mode) + result;
}

if (type.handle_type->reference_type == halide_handle_cplusplus_type::LValueReference) {
if (type.handle_type()->reference_type == halide_handle_cplusplus_type::LValueReference) {
result = "A" + base_mode + result; // Or is it "R"?
} else if (type.handle_type->reference_type == halide_handle_cplusplus_type::RValueReference) {
} else if (type.handle_type()->reference_type == halide_handle_cplusplus_type::RValueReference) {
result = "$$Q" + base_mode + result;
}
}
Expand All @@ -188,7 +188,7 @@ struct QualsState {

std::string mangle_indirection_and_cvr_quals(const Type &type, const Target &target) {
QualsState state(type, (target.bits == 64) ? "E" : "");
for (uint8_t modifier : type.handle_type->cpp_type_modifiers) {
for (uint8_t modifier : type.handle_type()->cpp_type_modifiers) {
state.handle_modifier(modifier);
}
state.final();
Expand All @@ -200,28 +200,28 @@ MangledNamePart mangle_inner_name(const Type &type, const Target &target, Previo
MangledNamePart result("");

std::string quals = mangle_indirection_and_cvr_quals(type, target);
if (type.handle_type->inner_name.cpp_type_type == halide_cplusplus_type_name::Simple) {
return quals + simple_type_to_mangle_char(type.handle_type->inner_name.name, target);
if (type.handle_type()->inner_name.cpp_type_type == halide_cplusplus_type_name::Simple) {
return quals + simple_type_to_mangle_char(type.handle_type()->inner_name.name, target);
} else {
std::string code;
if (type.handle_type->inner_name.cpp_type_type == halide_cplusplus_type_name::Struct) {
if (type.handle_type()->inner_name.cpp_type_type == halide_cplusplus_type_name::Struct) {
code = "U";
} else if (type.handle_type->inner_name.cpp_type_type == halide_cplusplus_type_name::Class) {
} else if (type.handle_type()->inner_name.cpp_type_type == halide_cplusplus_type_name::Class) {
code = "V";
} else if (type.handle_type->inner_name.cpp_type_type == halide_cplusplus_type_name::Union) {
} else if (type.handle_type()->inner_name.cpp_type_type == halide_cplusplus_type_name::Union) {
code = "T";
} else if (type.handle_type->inner_name.cpp_type_type == halide_cplusplus_type_name::Enum) {
} else if (type.handle_type()->inner_name.cpp_type_type == halide_cplusplus_type_name::Enum) {
code = "W4";
}
result.full_name = quals + code + type.handle_type->inner_name.name + "@";
result.with_substitutions = quals + code + prev_decls.check_and_enter_name(type.handle_type->inner_name.name);
result.full_name = quals + code + type.handle_type()->inner_name.name + "@";
result.with_substitutions = quals + code + prev_decls.check_and_enter_name(type.handle_type()->inner_name.name);

for (const auto &enclosing_type : reverse_view(type.handle_type->enclosing_types)) {
for (const auto &enclosing_type : reverse_view(type.handle_type()->enclosing_types)) {
result.full_name += enclosing_type.name + "@";
result.with_substitutions += prev_decls.check_and_enter_name(enclosing_type.name);
}

for (const auto &ns : reverse_view(type.handle_type->namespaces)) {
for (const auto &ns : reverse_view(type.handle_type()->namespaces)) {
result.full_name += ns + "@";
result.with_substitutions += prev_decls.check_and_enter_name(ns);
}
Expand Down Expand Up @@ -273,7 +273,7 @@ MangledNamePart mangle_type(const Type &type, const Target &target, PreviousDecl
internal_error << "Unexpected floating-point type size: " << type.bits() << ".\n";
return "";
} else if (type.is_handle()) {
return mangle_inner_name((type.handle_type != nullptr) ? type : non_null_void_star_type(),
return mangle_inner_name((type.handle_type() != nullptr) ? type : non_null_void_star_type(),
target, prev_decls);
}
internal_error << "Unexpected kind of type. Code: " << type.code() << "\n";
Expand Down Expand Up @@ -427,11 +427,11 @@ struct PrevPrefixes {

MangledNamePart apply_indirection_and_cvr_quals(const Type &type, MangledNamePart &name_part,
PrevPrefixes &prevs) {
for (uint8_t modifier : type.handle_type->cpp_type_modifiers) {
for (uint8_t modifier : type.handle_type()->cpp_type_modifiers) {
// Qualifiers on a value type are simply not encoded.
// E.g. "int f(const int)" mangles the same as "int f(int)".
if (!(modifier & halide_handle_cplusplus_type::Pointer) &&
type.handle_type->reference_type == halide_handle_cplusplus_type::NotReference) {
type.handle_type()->reference_type == halide_handle_cplusplus_type::NotReference) {
break;
}

Expand All @@ -458,9 +458,9 @@ MangledNamePart apply_indirection_and_cvr_quals(const Type &type, MangledNamePar
}
}

if (type.handle_type->reference_type == halide_handle_cplusplus_type::LValueReference) {
if (type.handle_type()->reference_type == halide_handle_cplusplus_type::LValueReference) {
prevs.prepend_name_part("R", name_part);
} else if (type.handle_type->reference_type == halide_handle_cplusplus_type::RValueReference) {
} else if (type.handle_type()->reference_type == halide_handle_cplusplus_type::RValueReference) {
prevs.prepend_name_part("O", name_part);
}

Expand Down Expand Up @@ -515,12 +515,12 @@ MangledNamePart mangle_qualified_name(const std::string &name, const std::vector
}

std::string mangle_inner_name(const Type &type, const Target &target, PrevPrefixes &prevs) {
if (type.handle_type->inner_name.cpp_type_type == halide_cplusplus_type_name::Simple) {
MangledNamePart result = simple_type_to_mangle_char(type.handle_type->inner_name.name, target);
if (type.handle_type()->inner_name.cpp_type_type == halide_cplusplus_type_name::Simple) {
MangledNamePart result = simple_type_to_mangle_char(type.handle_type()->inner_name.name, target);
return apply_indirection_and_cvr_quals(type, result, prevs).full_name;
} else {
MangledNamePart mangled = mangle_qualified_name(type.handle_type->inner_name.name, type.handle_type->namespaces,
type.handle_type->enclosing_types, true, prevs);
MangledNamePart mangled = mangle_qualified_name(type.handle_type()->inner_name.name, type.handle_type()->namespaces,
type.handle_type()->enclosing_types, true, prevs);
return apply_indirection_and_cvr_quals(type, mangled, prevs).full_name;
}
}
Expand Down Expand Up @@ -585,7 +585,7 @@ std::string mangle_type(const Type &type, const Target &target, PrevPrefixes &pr
internal_error << "Unexpected floating-point type size: " << type.bits() << ".\n";
return "";
} else if (type.is_handle()) {
return mangle_inner_name((type.handle_type != nullptr) ? type : non_null_void_star_type(),
return mangle_inner_name((type.handle_type() != nullptr) ? type : non_null_void_star_type(),
target, prevs);
}
internal_error << "Unexpected kind of type. Code: " << type.code() << "\n";
Expand Down
4 changes: 2 additions & 2 deletions src/Callable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Callable::Callable(const std::string &name,
for (const Argument &a : contents->jit_cache.arguments) {
const auto qcci = (a.name == "__user_context") ?
Callable::make_ucon_qcci() :
(a.is_scalar() ? Callable::make_scalar_qcci(a.type) : Callable::make_buffer_qcci());
(a.is_scalar() ? Callable::make_scalar_qcci(a.type.to_abi()) : Callable::make_buffer_qcci());
contents->quick_call_check_info.push_back(qcci);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ Callable::FailureFn Callable::check_fcci(size_t argc, const FullCallCheckInfo *a
if (contents->full_call_check_info.empty()) {
contents->full_call_check_info.reserve(contents->jit_cache.arguments.size());
for (const Argument &a : contents->jit_cache.arguments) {
const auto fcci = a.is_scalar() ? Callable::make_scalar_fcci(a.type) : Callable::make_buffer_fcci(a.type, a.dimensions);
const auto fcci = a.is_scalar() ? Callable::make_scalar_fcci(a.type.to_abi()) : Callable::make_buffer_fcci(a.type.to_abi(), a.dimensions);
contents->full_call_check_info.push_back(fcci);
}
}
Expand Down
Loading
Loading