[pyscalehls] Use array_partition python API; [BindingsPython] Add MlirValue pybind adapter

This commit is contained in:
Hanchen Ye 2021-11-06 18:02:03 -05:00
parent 7d586d23ef
commit 491ba1c2e8
3 changed files with 36 additions and 3 deletions

View File

@ -222,6 +222,27 @@ template <> struct type_caster<MlirType> {
}
};
/// Casts object <-> MlirValue.
template <> struct type_caster<MlirValue> {
PYBIND11_TYPE_CASTER(MlirValue, _("MlirValue"));
bool load(handle src, bool) {
py::object capsule = mlirApiObjectToCapsule(src);
value = mlirPythonCapsuleToValue(capsule.ptr());
if (mlirValueIsNull(value)) {
return false;
}
return true;
}
static handle cast(MlirValue t, return_value_policy, handle) {
py::object capsule =
py::reinterpret_steal<py::object>(mlirPythonValueToCapsule(t));
return py::module::import(MAKE_MLIR_PYTHON_QUALNAME("ir"))
.attr("Value")
.attr(MLIR_PYTHON_CAPI_FACTORY_ATTR)(capsule)
.release();
}
};
} // namespace detail
} // namespace pybind11

View File

@ -6,7 +6,7 @@
// CHECK: float [[C:.*]][32][32]
// CHECK: #pragma HLS array_partition variable=[[A]] cyclic factor=2 dim=2
// CHECK: #pragma HLS array_partition variable=[[C]] cyclic factor=2 dim=1
// CHECK: #pragma HLS array_partition variable=[[C]] cyclic factor=2 dim=2
// CHECK: for (int [[k:.*]] = 0; [[k]] < 32; [[k]] += 1) {
// CHECK-NEXT: for (int [[i:.*]] = 0; [[i]] < 32; [[i]] += 1) {

View File

@ -50,7 +50,7 @@ def main():
pass
func.__class__ = builtin.FuncOp
# Collect all suitable loop bands in the function.
# Traverse all suitable loop bands in the function.
bands = scalehls.LoopBandList(func)
for band in bands:
# Attempt to perfectize the loop band.
@ -75,6 +75,18 @@ def main():
# Apply loop pipelining. All loops inside of the pipelined loop are fully unrolled.
scalehls.loop_pipelining(band, loc, 3) # targetII
# Traverse all arrays in the function.
arrays = scalehls.ArrayList(func)
for array in arrays:
type = array.type
type.__class__ = mlir.ir.MemRefType
if not type.has_rank:
pass
# Apply specified factors and partition kind to the array.
factors = np.ones(type.rank, dtype=int)
factors[-1] = 2
scalehls.array_partition(array, factors, "cyclic")
# Legalize the IR to make it emittable.
scalehls.legalize_to_hlscpp(
func, func.sym_name.value == opts.function)
@ -83,7 +95,7 @@ def main():
scalehls.memory_access_opt(func)
# Apply suitable array partition strategies through analyzing the array access pattern.
scalehls.auto_array_partition(func)
# scalehls.auto_array_partition(func)
# Emit optimized MLIR to HLS C++.
buf = io.StringIO()