-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Narrowing/widening the Func along a dimension
As discussed, this implements an utility to make it easier to write code that wants to essentially operate either on smaller chunks than the whole type, or operate on several consecutive elements as a large element. The bigger picture is that it is desirable to perform load widening in such situations, and while this doesn't do that, at least having a common interface should be a step in that direction. I've took liberty to add/expose some QoL variable-bit-lenth operations in IROperator, while there. I believe, this has sufficient test coverage now. While implmeneting, i stumbled&fixed #6782 Refs. #6756
- Loading branch information
Showing
15 changed files
with
1,070 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include "PyFuncTypeChanging.h" | ||
|
||
namespace Halide { | ||
namespace PythonBindings { | ||
|
||
namespace { | ||
|
||
inline Func to_func(const Buffer<> &b) { | ||
return lambda(_, b(_)); | ||
} | ||
|
||
} // namespace | ||
|
||
void define_func_type_changing(py::module &m) { | ||
using namespace FuncTypeChanging; | ||
|
||
py::module bc = m.def_submodule("FuncTypeChanging"); | ||
|
||
py::enum_<ChunkOrder>(bc, "ArgumentKind") | ||
.value("LowestFirst", ChunkOrder::LowestFirst) | ||
.value("HighestFirst", ChunkOrder::HighestFirst) | ||
.value("Default", ChunkOrder::Default); | ||
|
||
bc.def( | ||
"change_type", | ||
[](const ImageParam &im, const Type &dst_type, const Var &dim, | ||
const std::string &name, ChunkOrder chunk_order) -> Func { | ||
return change_type(im, dst_type, dim, name, chunk_order); | ||
}, | ||
py::arg("f"), py::arg("dst_type"), py::arg("dim"), py::arg("name"), | ||
py::arg("chunk_order")); | ||
|
||
bc.def( | ||
"change_type", | ||
[](const Buffer<> &b, const Type &dst_type, const Var &dim, | ||
const std::string &name, ChunkOrder chunk_order) -> Func { | ||
return change_type(b, dst_type, dim, name, chunk_order); | ||
}, | ||
py::arg("f"), py::arg("dst_type"), py::arg("dim"), py::arg("name"), | ||
py::arg("chunk_order")); | ||
|
||
bc.def( | ||
"change_type", | ||
[](const py::object &target, const Type &dst_type, const Var &dim, | ||
const std::string &name, ChunkOrder chunk_order) -> Func { | ||
try { | ||
return change_type(target.cast<Func>(), dst_type, dim, name, | ||
chunk_order); | ||
} catch (...) { | ||
// fall thru | ||
} | ||
try { | ||
return change_type(to_func(target.cast<Buffer<>>()), dst_type, | ||
dim, name, chunk_order); | ||
} catch (...) { | ||
// fall thru | ||
} | ||
throw py::value_error("Invalid arguments to change_type"); | ||
return Func(); | ||
}, | ||
py::arg("f"), py::arg("dst_type"), py::arg("dim"), py::arg("name"), | ||
py::arg("chunk_order")); | ||
} | ||
|
||
} // namespace PythonBindings | ||
} // namespace Halide |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef HALIDE_PYTHON_BINDINGS_PYFUNCTYPECHANGING_H | ||
#define HALIDE_PYTHON_BINDINGS_PYFUNCTYPECHANGING_H | ||
|
||
#include "PyHalide.h" | ||
|
||
namespace Halide { | ||
namespace PythonBindings { | ||
|
||
void define_func_type_changing(py::module &m); | ||
|
||
} // namespace PythonBindings | ||
} // namespace Halide | ||
|
||
#endif // HALIDE_PYTHON_BINDINGS_PYFUNCTYPECHANGING_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef HALIDE_FUNC_EXTRAS_H | ||
#define HALIDE_FUNC_EXTRAS_H | ||
|
||
#include "Func.h" | ||
#include "Lambda.h" | ||
|
||
namespace Halide { | ||
|
||
namespace Internal { | ||
|
||
inline const Func &func_like_to_func(const Func &func) { | ||
return func; | ||
} | ||
|
||
template<typename T> | ||
inline HALIDE_NO_USER_CODE_INLINE Func func_like_to_func(const T &func_like) { | ||
return lambda(_, func_like(_)); | ||
} | ||
|
||
} // namespace Internal | ||
|
||
} // namespace Halide | ||
|
||
#endif |
Oops, something went wrong.