diff --git a/python_bindings/src/PyFunc.cpp b/python_bindings/src/PyFunc.cpp index 3f08c2f97236..c7cb4961eb43 100644 --- a/python_bindings/src/PyFunc.cpp +++ b/python_bindings/src/PyFunc.cpp @@ -145,7 +145,7 @@ void define_func(py::module &m) { "realize", [](Func &f, std::vector> buffers, const Target &t) -> void { py::gil_scoped_release release; - f.realize(Realization(buffers), t); + f.realize(Realization(std::move(buffers)), t); }, py::arg("dst"), py::arg("target") = Target()) @@ -266,7 +266,7 @@ void define_func(py::module &m) { try { std::vector> v = dst.cast>>(); - f.infer_input_bounds(Realization(v), target); + f.infer_input_bounds(Realization(std::move(v)), target); return; } catch (...) { // fall thru diff --git a/python_bindings/src/PyPipeline.cpp b/python_bindings/src/PyPipeline.cpp index 961947da93e1..bb21e936e871 100644 --- a/python_bindings/src/PyPipeline.cpp +++ b/python_bindings/src/PyPipeline.cpp @@ -122,7 +122,7 @@ void define_pipeline(py::module &m) { .def( "realize", [](Pipeline &p, std::vector> buffers, const Target &t) -> void { py::gil_scoped_release release; - p.realize(Realization(buffers), t); + p.realize(Realization(std::move(buffers)), t); }, py::arg("dst"), py::arg("target") = Target()) @@ -139,7 +139,7 @@ void define_pipeline(py::module &m) { try { std::vector> v = dst.cast>>(); - p.infer_input_bounds(Realization(v), target); + p.infer_input_bounds(Realization(std::move(v)), target); return; } catch (...) { // fall thru diff --git a/src/Func.cpp b/src/Func.cpp index ebdcb44a8c84..1a5cdfd19aea 100644 --- a/src/Func.cpp +++ b/src/Func.cpp @@ -3157,7 +3157,7 @@ void Func::infer_input_bounds(JITUserContext *context, Buffer<> im(func.output_types()[i], nullptr, sizes); outputs[i] = std::move(im); } - Realization r(outputs); + Realization r(std::move(outputs)); infer_input_bounds(context, r, target, param_map); } diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index df41fd7c9a6a..1de83a09f989 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -729,7 +729,7 @@ Realization Pipeline::realize(JITUserContext *context, bufs.emplace_back(t, nullptr, sizes); } } - Realization r(bufs); + Realization r(std::move(bufs)); // Do an output bounds query if we can. Otherwise just assume the // output size is good. if (!target.has_feature(Target::NoBoundsQuery)) { @@ -1308,7 +1308,7 @@ void Pipeline::infer_input_bounds(JITUserContext *context, for (Type t : contents->outputs[0].output_types()) { bufs.emplace_back(t, sizes); } - Realization r(bufs); + Realization r(std::move(bufs)); infer_input_bounds(context, r, target, param_map); } diff --git a/src/Realization.cpp b/src/Realization.cpp index 9511d5a5a22f..e030fa0455d3 100644 --- a/src/Realization.cpp +++ b/src/Realization.cpp @@ -5,36 +5,30 @@ namespace Halide { -/** The number of images in the Realization. */ size_t Realization::size() const { return images.size(); } -/** Get a const reference to one of the images. */ const Buffer &Realization::operator[](size_t x) const { user_assert(x < images.size()) << "Realization access out of bounds\n"; return images[x]; } -/** Get a reference to one of the images. */ Buffer &Realization::operator[](size_t x) { user_assert(x < images.size()) << "Realization access out of bounds\n"; return images[x]; } -/** Construct a Realization that refers to the buffers in an - * existing vector of Buffer<> */ -Realization::Realization(std::vector> &e) +Realization::Realization(const std::vector> &e) : images(e) { - user_assert(!e.empty()) << "Realizations must have at least one element\n"; + user_assert(!images.empty()) << "Realizations must have at least one element\n"; +} + +Realization::Realization(std::vector> &&e) + : images(std::move(e)) { + user_assert(!images.empty()) << "Realizations must have at least one element\n"; } -/** Call device_sync() for all Buffers in the Realization. - * If one of the calls returns an error, subsequent Buffers won't have - * device_sync called; thus callers should consider a nonzero return - * code to mean that potentially all of the Buffers are in an indeterminate - * state of sync. - * Calling this explicitly should rarely be necessary, except for profiling. */ int Realization::device_sync(void *ctx) { for (auto &b : images) { int result = b.device_sync(ctx); diff --git a/src/Realization.h b/src/Realization.h index 29596d0b3218..f937535b4e57 100644 --- a/src/Realization.h +++ b/src/Realization.h @@ -49,7 +49,10 @@ class Realization { /** Construct a Realization that refers to the buffers in an * existing vector of Buffer<> */ - explicit Realization(std::vector> &e); + // @{ + explicit Realization(const std::vector> &e); + explicit Realization(std::vector> &&e); + // @} /** Call device_sync() for all Buffers in the Realization. * If one of the calls returns an error, subsequent Buffers won't have