Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ctors for Realization #6675

Merged
merged 2 commits into from
Apr 5, 2022
Merged
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
4 changes: 2 additions & 2 deletions python_bindings/src/PyFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ void define_func(py::module &m) {
"realize",
[](Func &f, std::vector<Buffer<>> 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())

Expand Down Expand Up @@ -266,7 +266,7 @@ void define_func(py::module &m) {

try {
std::vector<Buffer<>> v = dst.cast<std::vector<Buffer<>>>();
f.infer_input_bounds(Realization(v), target);
f.infer_input_bounds(Realization(std::move(v)), target);
return;
} catch (...) {
// fall thru
Expand Down
4 changes: 2 additions & 2 deletions python_bindings/src/PyPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void define_pipeline(py::module &m) {
.def(
"realize", [](Pipeline &p, std::vector<Buffer<>> 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())

Expand All @@ -139,7 +139,7 @@ void define_pipeline(py::module &m) {

try {
std::vector<Buffer<>> v = dst.cast<std::vector<Buffer<>>>();
p.infer_input_bounds(Realization(v), target);
p.infer_input_bounds(Realization(std::move(v)), target);
return;
} catch (...) {
// fall thru
Expand Down
2 changes: 1 addition & 1 deletion src/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Pipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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);
}

Expand Down
20 changes: 7 additions & 13 deletions src/Realization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> &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<void> &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<Buffer<void>> &e)
Realization::Realization(const std::vector<Buffer<void>> &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<Buffer<void>> &&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);
Expand Down
5 changes: 4 additions & 1 deletion src/Realization.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ class Realization {

/** Construct a Realization that refers to the buffers in an
* existing vector of Buffer<> */
explicit Realization(std::vector<Buffer<void>> &e);
// @{
explicit Realization(const std::vector<Buffer<void>> &e);
explicit Realization(std::vector<Buffer<void>> &&e);
// @}

/** Call device_sync() for all Buffers in the Realization.
* If one of the calls returns an error, subsequent Buffers won't have
Expand Down