Skip to content

Commit

Permalink
Expose BFloat in Python bindings (#8255)
Browse files Browse the repository at this point in the history
There are two parts to support for BFloat16 in Python:
1) Ability to define kernels and AOT compile them [fixed in this PR]
2) Ability to call kernels from Python

This fixes part 1, which is what I need for my use case.  Part 2 is
blocked on bfloat16 support in Python buffer protocols. See #6849 for
more details.
  • Loading branch information
jansel authored Jun 2, 2024
1 parent 7cf2951 commit 7ca95d8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions python_bindings/src/halide/halide_/PyType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ std::string halide_type_to_string(const Type &type) {
case halide_type_float:
stream << "float";
break;
case halide_type_bfloat:
stream << "bfloat";
break;
case halide_type_handle:
if (type.handle_type) {
stream << type.handle_type->inner_name.name;
Expand Down Expand Up @@ -67,6 +70,7 @@ void define_type(py::module &m) {
.def("is_vector", &Type::is_vector)
.def("is_scalar", &Type::is_scalar)
.def("is_float", &Type::is_float)
.def("is_bfloat", &Type::is_bfloat)
.def("is_int", &Type::is_int)
.def("is_uint", &Type::is_uint)
.def("is_handle", &Type::is_handle)
Expand Down Expand Up @@ -94,6 +98,7 @@ void define_type(py::module &m) {
m.def("Int", Int, py::arg("bits"), py::arg("lanes") = 1);
m.def("UInt", UInt, py::arg("bits"), py::arg("lanes") = 1);
m.def("Float", Float, py::arg("bits"), py::arg("lanes") = 1);
m.def("BFloat", BFloat, py::arg("bits"), py::arg("lanes") = 1);
m.def("Bool", Bool, py::arg("lanes") = 1);
m.def("Handle", make_handle, py::arg("lanes") = 1);

Expand Down

0 comments on commit 7ca95d8

Please sign in to comment.