diff --git a/.clang-format b/.clang-format index 01be88ee661d..98fb81f149df 100644 --- a/.clang-format +++ b/.clang-format @@ -23,6 +23,7 @@ ContinuationIndentWidth: 4 IndentCaseLabels: false IndentWidth: 4 IndentWrappedFunctionNames: false +LambdaBodyIndentation: OuterScope MaxEmptyLinesToKeep: 1 NamespaceIndentation: None PackConstructorInitializers: BinPack diff --git a/apps/hannk/interpreter/allocation_planner.cpp b/apps/hannk/interpreter/allocation_planner.cpp index a037846bcb2b..54c1a1267b3c 100644 --- a/apps/hannk/interpreter/allocation_planner.cpp +++ b/apps/hannk/interpreter/allocation_planner.cpp @@ -77,14 +77,14 @@ void AllocationPlanner::commit() { std::sort(block_requirements_sorted.begin(), block_requirements_sorted.end(), [](BlockRequirements *a, BlockRequirements *b) -> bool { - // Sort in decreasing (well, really non-increasing) order by size. - if (a->size_needed != b->size_needed) { - return a->size_needed > b->size_needed; - } - - // If sizes are equal, sort by increasing time of first use. - return a->first_use < b->first_use; - }); + // Sort in decreasing (well, really non-increasing) order by size. + if (a->size_needed != b->size_needed) { + return a->size_needed > b->size_needed; + } + + // If sizes are equal, sort by increasing time of first use. + return a->first_use < b->first_use; + }); // This is a list that we keep sorted (by offset) as we go along. // It just points to entries in block_requirements_sorted, so it's crucial diff --git a/apps/hannk/util/model_runner.cpp b/apps/hannk/util/model_runner.cpp index 76bbbeeaa37e..df0a595756e1 100644 --- a/apps/hannk/util/model_runner.cpp +++ b/apps/hannk/util/model_runner.cpp @@ -519,75 +519,75 @@ int ModelRunner::parse_flags(int argc, char **argv, std::vector &fi fp.flag_handlers = FlagProcessor::FnMap{ {"benchmark", [this](const std::string &value) { - this->do_benchmark = std::stoi(value) != 0; - return 0; - }}, + this->do_benchmark = std::stoi(value) != 0; + return 0; + }}, {"compare", [this](const std::string &value) { - this->do_compare_results = std::stoi(value) != 0; - return 0; - }}, + this->do_compare_results = std::stoi(value) != 0; + return 0; + }}, {"csv", [this](const std::string &value) { - this->csv_output = std::stoi(value) != 0; - return 0; - }}, + this->csv_output = std::stoi(value) != 0; + return 0; + }}, {"enable", [this](const std::string &value) { - for (int i = 0; i < ModelRunner::kNumRuns; i++) { - this->do_run[i] = false; - } - for (char c : value) { - switch (c) { - case 'h': - this->do_run[ModelRunner::kHannk] = true; - break; + for (int i = 0; i < ModelRunner::kNumRuns; i++) { + this->do_run[i] = false; + } + for (char c : value) { + switch (c) { + case 'h': + this->do_run[ModelRunner::kHannk] = true; + break; #if HANNK_BUILD_TFLITE - case 't': - this->do_run[ModelRunner::kTfLite] = true; - break; - case 'x': - this->do_run[ModelRunner::kExternalDelegate] = true; - break; - case 'i': - this->do_run[ModelRunner::kInternalDelegate] = true; - break; + case 't': + this->do_run[ModelRunner::kTfLite] = true; + break; + case 'x': + this->do_run[ModelRunner::kExternalDelegate] = true; + break; + case 'i': + this->do_run[ModelRunner::kInternalDelegate] = true; + break; #else - case 't': - case 'x': - case 'i': - std::cerr << "Unsupported option to --enable (TFLite is not enabled in this build): " << c << "\n"; - return -1; - break; + case 't': + case 'x': + case 'i': + std::cerr << "Unsupported option to --enable (TFLite is not enabled in this build): " << c << "\n"; + return -1; + break; #endif - default: - std::cerr << "Unknown option to --enable: " << c << "\n"; - return -1; - } - } - return 0; - }}, + default: + std::cerr << "Unknown option to --enable: " << c << "\n"; + return -1; + } + } + return 0; + }}, {"external_delegate_path", [this](const std::string &value) { - this->external_delegate_path = value; - return 0; - }}, + this->external_delegate_path = value; + return 0; + }}, {"keep_going", [this](const std::string &value) { - this->keep_going = std::stoi(value) != 0; - return 0; - }}, + this->keep_going = std::stoi(value) != 0; + return 0; + }}, {"seed", [&seed](const std::string &value) { - seed = std::stoi(value); - return 0; - }}, + seed = std::stoi(value); + return 0; + }}, {"threads", [this](const std::string &value) { - this->threads = std::stoi(value); - return 0; - }}, + this->threads = std::stoi(value); + return 0; + }}, {"tolerance", [this](const std::string &value) { - this->tolerance = std::stof(value); - return 0; - }}, + this->tolerance = std::stof(value); + return 0; + }}, {"verbose", [this](const std::string &value) { - this->verbosity = std::stoi(value); - return 0; - }}, + this->verbosity = std::stoi(value); + return 0; + }}, }; int r = fp.process(argc, argv); diff --git a/python_bindings/src/halide/halide_/PyArgument.cpp b/python_bindings/src/halide/halide_/PyArgument.cpp index 995ad8700020..eb6dcc24c099 100644 --- a/python_bindings/src/halide/halide_/PyArgument.cpp +++ b/python_bindings/src/halide/halide_/PyArgument.cpp @@ -17,16 +17,16 @@ void define_argument(py::module &m) { py::class_(m, "Argument") .def(py::init<>()) .def(py::init([](const OutputImageParam &im) -> Argument { - return im; - }), + return im; + }), py::arg("im")) .def(py::init([](const ImageParam &im) -> Argument { - return im; - }), + return im; + }), py::arg("im")) .def(py::init([](const Param<> ¶m) -> Argument { - return param; - }), + return param; + }), py::arg("param")) .def(py::init>(), py::arg("buffer")) .def_readwrite("name", &Argument::name) diff --git a/python_bindings/src/halide/halide_/PyBinaryOperators.h b/python_bindings/src/halide/halide_/PyBinaryOperators.h index 9af15af1ddb5..b0204b6e57af 100644 --- a/python_bindings/src/halide/halide_/PyBinaryOperators.h +++ b/python_bindings/src/halide/halide_/PyBinaryOperators.h @@ -114,30 +114,30 @@ void add_binary_operators_with(PythonClass &class_instance) { using Promote = std::conditional_t< std::is_same_v, DoubleToExprCheck, other_t>; -#define BINARY_OP(op, method) \ +#define BINARY_OP(op, method) \ + do { \ + class_instance.def( \ + "__" #method "__", \ + [](const self_t &self, const other_t &other) { \ + auto result = self op Promote(other); \ + LOG_PY_BINARY_OP(self, #method, other, result); \ + return result; \ + }, \ + py::is_operator()); \ + } while (0) + +#define RBINARY_OP(op, method) \ do { \ class_instance.def( \ - "__" #method "__", \ + "__r" #method "__", \ [](const self_t &self, const other_t &other) { \ - auto result = self op Promote(other); \ - LOG_PY_BINARY_OP(self, #method, other, result); \ - return result; \ - }, \ + auto result = Promote(other) op self; \ + LOG_PY_BINARY_OP(self, "r" #method, other, result); \ + return result; \ + }, \ py::is_operator()); \ } while (0) -#define RBINARY_OP(op, method) \ - do { \ - class_instance.def( \ - "__r" #method "__", \ - [](const self_t &self, const other_t &other) { \ - auto result = Promote(other) op self; \ - LOG_PY_BINARY_OP(self, "r" #method, other, result); \ - return result; \ - }, \ - py::is_operator()); \ - } while (0) - #define BINARY_OPS(op, method) \ do { \ BINARY_OP(op, method); \ @@ -145,23 +145,23 @@ void add_binary_operators_with(PythonClass &class_instance) { } while (0) if constexpr (std::is_same_v) { -#define BINARY_OPS_UNEVAL(op, method, val) \ - do { \ - class_instance.def( \ - "__" #method "__", \ - [](const self_t &self, const other_t &other) -> std::variant { \ - if (self.function().has_pure_definition() || self.function().has_extern_definition()) { \ - auto result = Expr(self) op Promote(other); \ - LOG_PY_BINARY_OP(self, #method, other, result); \ - return result; \ - } else { \ - auto result = UnevaluatedFuncRefExpr{self, Promote(other), UnevaluatedFuncRefExpr::Op::val}; \ - LOG_PY_BINARY_OP_UNEVAL(self, #method, other, result); \ - return result; \ - } \ - }, \ - py::is_operator()); \ - RBINARY_OP(op, method); \ +#define BINARY_OPS_UNEVAL(op, method, val) \ + do { \ + class_instance.def( \ + "__" #method "__", \ + [](const self_t &self, const other_t &other) -> std::variant { \ + if (self.function().has_pure_definition() || self.function().has_extern_definition()) { \ + auto result = Expr(self) op Promote(other); \ + LOG_PY_BINARY_OP(self, #method, other, result); \ + return result; \ + } else { \ + auto result = UnevaluatedFuncRefExpr{self, Promote(other), UnevaluatedFuncRefExpr::Op::val}; \ + LOG_PY_BINARY_OP_UNEVAL(self, #method, other, result); \ + return result; \ + } \ + }, \ + py::is_operator()); \ + RBINARY_OP(op, method); \ } while (0) BINARY_OPS_UNEVAL(+, add, Add); @@ -222,9 +222,8 @@ void add_binary_operators(PythonClass &class_instance) { class_instance .def("__pow__", Halide::pow, py::is_operator()) .def("__rpow__", [](const Expr &self, const Expr &other) { - return Halide::pow(other, self); // - }, - py::is_operator()); + return Halide::pow(other, self); // + }, py::is_operator()); const auto logical_not_wrap = [](const self_t &self) -> decltype(!self) { return !self; diff --git a/python_bindings/src/halide/halide_/PyBoundaryConditions.cpp b/python_bindings/src/halide/halide_/PyBoundaryConditions.cpp index 3c3e1681fea4..58c4566ffc68 100644 --- a/python_bindings/src/halide/halide_/PyBoundaryConditions.cpp +++ b/python_bindings/src/halide/halide_/PyBoundaryConditions.cpp @@ -25,142 +25,127 @@ void define_boundary_conditions(py::module &m) { bc.def( "constant_exterior", [](const ImageParam &im, const Expr &exterior) -> Func { - return constant_exterior(im, exterior); - }, - py::arg("f"), py::arg("exterior")); + return constant_exterior(im, exterior); + }, py::arg("f"), py::arg("exterior")); bc.def( "constant_exterior", [](const Buffer<> &b, const Expr &exterior) -> Func { - return constant_exterior(b, exterior); - }, - py::arg("f"), py::arg("exterior")); + return constant_exterior(b, exterior); + }, py::arg("f"), py::arg("exterior")); bc.def( "constant_exterior", [](const py::object &target, const Expr &exterior, const Region &bounds) -> Func { - try { - return constant_exterior(target.cast(), exterior, bounds); - } catch (...) { - // fall thru - } - try { - return constant_exterior(to_func(target.cast>()), exterior, bounds); - } catch (...) { - // fall thru - } - throw py::value_error("Invalid arguments to constant_exterior"); - return Func(); - }, - py::arg("f"), py::arg("exterior"), py::arg("bounds")); + try { + return constant_exterior(target.cast(), exterior, bounds); + } catch (...) { + // fall thru + } + try { + return constant_exterior(to_func(target.cast>()), exterior, bounds); + } catch (...) { + // fall thru + } + throw py::value_error("Invalid arguments to constant_exterior"); + return Func(); + }, py::arg("f"), py::arg("exterior"), py::arg("bounds")); // ----- repeat_edge bc.def( "repeat_edge", [](const ImageParam &im) -> Func { - return repeat_edge(im); - }, - py::arg("f")); + return repeat_edge(im); + }, py::arg("f")); bc.def( "repeat_edge", [](const Buffer<> &b) -> Func { - return repeat_edge(b); - }, - py::arg("f")); + return repeat_edge(b); + }, py::arg("f")); bc.def( "repeat_edge", [](const py::object &target, const Region &bounds) -> Func { - try { - return repeat_edge(target.cast(), bounds); - } catch (...) { - // fall thru - } - try { - return repeat_edge(to_func(target.cast>()), bounds); - } catch (...) { - // fall thru - } - throw py::value_error("Invalid arguments to repeat_edge"); - return Func(); - }, - py::arg("f"), py::arg("bounds")); + try { + return repeat_edge(target.cast(), bounds); + } catch (...) { + // fall thru + } + try { + return repeat_edge(to_func(target.cast>()), bounds); + } catch (...) { + // fall thru + } + throw py::value_error("Invalid arguments to repeat_edge"); + return Func(); + }, py::arg("f"), py::arg("bounds")); // ----- repeat_image bc.def( "repeat_image", [](const ImageParam &im) -> Func { - return repeat_image(im); - }, - py::arg("f")); + return repeat_image(im); + }, py::arg("f")); bc.def( "repeat_image", [](const Buffer<> &b) -> Func { - return repeat_image(b); - }, - py::arg("f")); + return repeat_image(b); + }, py::arg("f")); bc.def( "repeat_image", [](const py::object &target, const Region &bounds) -> Func { - try { - return repeat_image(target.cast(), bounds); - } catch (...) { - // fall thru - } - try { - return repeat_image(to_func(target.cast>()), bounds); - } catch (...) { - // fall thru - } - throw py::value_error("Invalid arguments to repeat_image"); - return Func(); - }, - py::arg("f"), py::arg("bounds")); + try { + return repeat_image(target.cast(), bounds); + } catch (...) { + // fall thru + } + try { + return repeat_image(to_func(target.cast>()), bounds); + } catch (...) { + // fall thru + } + throw py::value_error("Invalid arguments to repeat_image"); + return Func(); + }, py::arg("f"), py::arg("bounds")); // ----- mirror_image bc.def( "mirror_image", [](const ImageParam &im) -> Func { - return mirror_image(im); - }, - py::arg("f")); + return mirror_image(im); + }, py::arg("f")); bc.def( "mirror_image", [](const Buffer<> &b) -> Func { - return mirror_image(b); - }, - py::arg("f")); + return mirror_image(b); + }, py::arg("f")); bc.def( "mirror_image", [](const py::object &target, const Region &bounds) -> Func { - try { - return mirror_image(target.cast(), bounds); - } catch (...) { - // fall thru - } - try { - return mirror_image(to_func(target.cast>()), bounds); - } catch (...) { - // fall thru - } - throw py::value_error("Invalid arguments to mirror_image"); - return Func(); - }, - py::arg("f"), py::arg("bounds")); + try { + return mirror_image(target.cast(), bounds); + } catch (...) { + // fall thru + } + try { + return mirror_image(to_func(target.cast>()), bounds); + } catch (...) { + // fall thru + } + throw py::value_error("Invalid arguments to mirror_image"); + return Func(); + }, py::arg("f"), py::arg("bounds")); // ----- mirror_interior bc.def( "mirror_interior", [](const ImageParam &im) -> Func { - return mirror_interior(im); - }, - py::arg("f")); + return mirror_interior(im); + }, py::arg("f")); bc.def( "mirror_interior", [](const Buffer<> &b) -> Func { - return mirror_interior(b); - }, - py::arg("f")); + return mirror_interior(b); + }, py::arg("f")); bc.def( "mirror_interior", [](const py::object &target, const Region &bounds) -> Func { - try { - return mirror_interior(target.cast(), bounds); - } catch (...) { - // fall thru - } - try { - return mirror_interior(to_func(target.cast>()), bounds); - } catch (...) { - // fall thru - } - throw py::value_error("Invalid arguments to mirror_interior"); - return Func(); - }, - py::arg("f"), py::arg("bounds")); + try { + return mirror_interior(target.cast(), bounds); + } catch (...) { + // fall thru + } + try { + return mirror_interior(to_func(target.cast>()), bounds); + } catch (...) { + // fall thru + } + throw py::value_error("Invalid arguments to mirror_interior"); + return Func(); + }, py::arg("f"), py::arg("bounds")); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyBuffer.cpp b/python_bindings/src/halide/halide_/PyBuffer.cpp index 90606677ca36..48f2eea3c7fa 100644 --- a/python_bindings/src/halide/halide_/PyBuffer.cpp +++ b/python_bindings/src/halide/halide_/PyBuffer.cpp @@ -353,8 +353,8 @@ void define_buffer(py::module &m) { // Note that this allows us to convert a Buffer<> to any buffer-like object in Python; // most notably, we can convert to an ndarray by calling numpy.array() .def_buffer([](Buffer<> &b) -> py::buffer_info { - return to_buffer_info(b, /*reverse_axes*/ true); - }) + return to_buffer_info(b, /*reverse_axes*/ true); + }) // This allows us to use any buffer-like python entity to create a Buffer<> // (most notably, an ndarray) @@ -362,30 +362,28 @@ void define_buffer(py::module &m) { .def(py::init_alias<>()) .def(py::init_alias &>()) .def(py::init([](Type type, const std::vector &sizes, const std::string &name) -> Buffer<> { - return Buffer<>(type, sizes, name); - }), + return Buffer<>(type, sizes, name); + }), py::arg("type"), py::arg("sizes"), py::arg("name") = "") .def(py::init([](Type type, const std::vector &sizes, const std::vector &storage_order, const std::string &name) -> Buffer<> { - return Buffer<>(type, sizes, storage_order, name); - }), + return Buffer<>(type, sizes, storage_order, name); + }), py::arg("type"), py::arg("sizes"), py::arg("storage_order"), py::arg("name") = "") // Note that this exists solely to allow you to create a Buffer with a null host ptr; // this is necessary for some bounds-query operations (e.g. Func::infer_input_bounds). .def_static( "make_bounds_query", [](Type type, const std::vector &sizes, const std::string &name) -> Buffer<> { - return Buffer<>(type, nullptr, sizes, name); - }, - py::arg("type"), py::arg("sizes"), py::arg("name") = "") + return Buffer<>(type, nullptr, sizes, name); + }, py::arg("type"), py::arg("sizes"), py::arg("name") = "") .def_static("make_scalar", static_cast (*)(Type, const std::string &)>(Buffer<>::make_scalar), py::arg("type"), py::arg("name") = "") .def_static("make_interleaved", static_cast (*)(Type, int, int, int, const std::string &)>(Buffer<>::make_interleaved), py::arg("type"), py::arg("width"), py::arg("height"), py::arg("channels"), py::arg("name") = "") .def_static( // "make_with_shape_of", [](const Buffer<> &buffer, const std::string &name) -> Buffer<> { - return Buffer<>::make_with_shape_of(buffer, nullptr, nullptr, name); // - }, - py::arg("src"), py::arg("name") = "") + return Buffer<>::make_with_shape_of(buffer, nullptr, nullptr, name); // + }, py::arg("src"), py::arg("name") = "") .def("set_name", &Buffer<>::set_name) .def("name", &Buffer<>::name) @@ -410,166 +408,152 @@ void define_buffer(py::module &m) { .def("set_host_dirty", // [](Buffer<> &b, bool dirty) -> void { - b.set_host_dirty(dirty); // - }, + b.set_host_dirty(dirty); // + }, py::arg("dirty") = true) .def("set_device_dirty", // [](Buffer<> &b, bool dirty) -> void { - b.set_device_dirty(dirty); // - }, - py::arg("dirty") = true) + b.set_device_dirty(dirty); // + }, py::arg("dirty") = true) .def("copy", &Buffer<>::copy) .def("copy_from", &Buffer<>::copy_from::AnyDims>) .def("reverse_axes", [](Buffer<> &b) -> Buffer<> { - const int d = b.dimensions(); - std::vector order; - order.reserve(b.dimensions()); - for (int i = 0; i < b.dimensions(); i++) { - order.push_back(d - i - 1); - } - return b.transposed(order); // - }) + const int d = b.dimensions(); + std::vector order; + order.reserve(b.dimensions()); + for (int i = 0; i < b.dimensions(); i++) { + order.push_back(d - i - 1); + } + return b.transposed(order); // + }) .def("add_dimension", static_cast::*)()>(&Buffer<>::add_dimension)) .def("allocate", [](Buffer<> &b) -> void { - b.allocate(nullptr, nullptr); // - }) - .def("deallocate", static_cast::*)()>(&Buffer<>::deallocate)) + b.allocate(nullptr, nullptr); // + }).def("deallocate", static_cast::*)()>(&Buffer<>::deallocate)) .def("device_deallocate", static_cast::*)()>(&Buffer<>::device_deallocate)) .def("crop", // [](Buffer<> &b, int d, int min, int extent) -> void { - b.crop(d, min, extent); // - }, - py::arg("dimension"), py::arg("min"), py::arg("extent")) + b.crop(d, min, extent); // + }, py::arg("dimension"), py::arg("min"), py::arg("extent")) .def("crop", // [](Buffer<> &b, const std::vector> &rect) -> void { - b.crop(rect); // - }, + b.crop(rect); // + }, py::arg("rect")) .def("cropped", // [](Buffer<> &b, int d, int min, int extent) -> Buffer<> { - return b.cropped(d, min, extent); // - }, - py::arg("dimension"), py::arg("min"), py::arg("extent")) + return b.cropped(d, min, extent); // + }, py::arg("dimension"), py::arg("min"), py::arg("extent")) .def("cropped", // [](Buffer<> &b, const std::vector> &rect) -> Buffer<> { - return b.cropped(rect); // - }, + return b.cropped(rect); // + }, py::arg("rect")) .def("embed", // [](Buffer<> &b, int d, int pos) -> void { - b.embed(d, pos); // - }, - py::arg("dimension"), py::arg("pos")) + b.embed(d, pos); // + }, py::arg("dimension"), py::arg("pos")) .def("embedded", // [](Buffer<> &b, int d, int pos) -> Buffer<> { - return b.embedded(d, pos); // - }, - py::arg("dimension"), py::arg("pos")) + return b.embedded(d, pos); // + }, py::arg("dimension"), py::arg("pos")) .def("embed", // [](Buffer<> &b, int d) -> void { - b.embed(d); // - }, + b.embed(d); // + }, py::arg("dimension")) .def("embedded", // [](Buffer<> &b, int d) -> Buffer<> { - return b.embedded(d); // - }, + return b.embedded(d); // + }, py::arg("dimension")) .def("slice", // [](Buffer<> &b, int d, int pos) -> void { - b.slice(d, pos); // - }, - py::arg("dimension"), py::arg("pos")) + b.slice(d, pos); // + }, py::arg("dimension"), py::arg("pos")) .def("sliced", // [](Buffer<> &b, int d, int pos) -> Buffer<> { - return b.sliced(d, pos); // - }, - py::arg("dimension"), py::arg("pos")) + return b.sliced(d, pos); // + }, py::arg("dimension"), py::arg("pos")) .def("slice", // [](Buffer<> &b, int d) -> void { - b.slice(d); // - }, + b.slice(d); // + }, py::arg("dimension")) .def("sliced", // [](Buffer<> &b, int d) -> Buffer<> { - return b.sliced(d); // - }, + return b.sliced(d); // + }, py::arg("dimension")) .def("translate", // [](Buffer<> &b, int d, int dx) -> void { - b.translate(d, dx); // - }, - py::arg("dimension"), py::arg("dx")) + b.translate(d, dx); // + }, py::arg("dimension"), py::arg("dx")) .def("translate", // [](Buffer<> &b, const std::vector &delta) -> void { - b.translate(delta); // - }, + b.translate(delta); // + }, py::arg("delta")) .def("translated", // [](Buffer<> &b, int d, int dx) -> Buffer<> { - return b.translated(d, dx); // - }, - py::arg("dimension"), py::arg("dx")) + return b.translated(d, dx); // + }, py::arg("dimension"), py::arg("dx")) .def("translated", // [](Buffer<> &b, const std::vector &delta) -> Buffer<> { - return b.translated(delta); // - }, + return b.translated(delta); // + }, py::arg("delta")) .def("transpose", // [](Buffer<> &b, int d1, int d2) -> void { - b.transpose(d1, d2); // - }, - py::arg("d1"), py::arg("d2")) + b.transpose(d1, d2); // + }, py::arg("d1"), py::arg("d2")) .def("transposed", // [](Buffer<> &b, int d1, int d2) -> Buffer<> { - return b.transposed(d1, d2); // - }, - py::arg("d1"), py::arg("d2")) + return b.transposed(d1, d2); // + }, py::arg("d1"), py::arg("d2")) .def("transpose", // [](Buffer<> &b, const std::vector &order) -> void { - b.transpose(order); // - }, + b.transpose(order); // + }, py::arg("order")) .def("transposed", // [](Buffer<> &b, const std::vector &order) -> Buffer<> { - return b.transposed(order); // - }, + return b.transposed(order); // + }, py::arg("order")) .def("dim", // [](Buffer<> &b, int dimension) -> BufferDimension { - return b.dim(dimension); // - }, - py::arg("dimension"), py::keep_alive<0, 1>() // Keep Buffer<> alive while Dimension exists + return b.dim(dimension); // + }, py::arg("dimension"), py::keep_alive<0, 1>() // Keep Buffer<> alive while Dimension exists ) .def("for_each_element", // [](Buffer<> &b, py::function f) -> void { - const int d = b.dimensions(); - std::vector pos_v(d, 0); - b.for_each_element([&f, &pos_v](const int *pos) -> void { - for (size_t i = 0; i < pos_v.size(); ++i) { - pos_v[i] = pos[i]; - } - f(pos_v); - }); // - }, - py::arg("f")) + const int d = b.dimensions(); + std::vector pos_v(d, 0); + b.for_each_element([&f, &pos_v](const int *pos) -> void { + for (size_t i = 0; i < pos_v.size(); ++i) { + pos_v[i] = pos[i]; + } + f(pos_v); + }); // + }, py::arg("f")) .def("fill", &call_fill, py::arg("value")) .def("all_equal", &call_all_equal, py::arg("value")) @@ -582,90 +566,85 @@ void define_buffer(py::module &m) { // }, py::arg("f")) .def("copy_to_host", [](Buffer<> &b) -> int { // - return b.copy_to_host(nullptr); - }) + return b.copy_to_host(nullptr); + }) .def("device_detach_native", [](Buffer<> &b) -> int { // - return b.device_detach_native(nullptr); - }) + return b.device_detach_native(nullptr); + }) .def("device_free", [](Buffer<> &b) -> int { // - return b.device_free(nullptr); - }) + return b.device_free(nullptr); + }) .def("device_sync", [](Buffer<> &b) -> int { // - return b.device_sync(nullptr); - }) + return b.device_sync(nullptr); + }) .def("copy_to_device", [](Buffer<> &b, const Target &target) -> int { // - return b.copy_to_device(to_jit_target(target)); - }, - py::arg("target") = Target()) + return b.copy_to_device(to_jit_target(target)); + }, py::arg("target") = Target()) .def("copy_to_device", [](Buffer<> &b, const DeviceAPI &d, const Target &target) -> int { // - return b.copy_to_device(d, to_jit_target(target)); - }, - py::arg("device_api"), py::arg("target") = Target()) + return b.copy_to_device(d, to_jit_target(target)); + }, py::arg("device_api"), py::arg("target") = Target()) .def("device_malloc", [](Buffer<> &b, const Target &target) -> int { // - return b.device_malloc(to_jit_target(target)); - }, - py::arg("target") = Target()) + return b.device_malloc(to_jit_target(target)); + }, py::arg("target") = Target()) .def("device_malloc", [](Buffer<> &b, const DeviceAPI &d, const Target &target) -> int { // - return b.device_malloc(d, to_jit_target(target)); - }, - py::arg("device_api"), py::arg("target") = Target()) + return b.device_malloc(d, to_jit_target(target)); + }, py::arg("device_api"), py::arg("target") = Target()) .def( // "set_min", // [](Buffer<> &b, const std::vector &mins) -> void { - if (mins.size() > (size_t)b.dimensions()) { - throw py::value_error("Too many arguments"); - } - b.set_min(mins); // - }, + if (mins.size() > (size_t)b.dimensions()) { + throw py::value_error("Too many arguments"); + } + b.set_min(mins); // + }, py::arg("mins")) .def( // "contains", [](Buffer<> &b, const std::vector &coords) -> bool { - if (coords.size() > (size_t)b.dimensions()) { - throw py::value_error("Too many arguments"); - } - return b.contains(coords); // - }, - py::arg("coords")) + if (coords.size() > (size_t)b.dimensions()) { + throw py::value_error("Too many arguments"); + } + return b.contains(coords); // + }, py::arg("coords")) .def("__getitem__", [](Buffer<> &buf, const int &pos) -> py::object { // - return buffer_getitem_operator(buf, {pos}); - }) + return buffer_getitem_operator(buf, {pos}); + }) .def("__getitem__", [](Buffer<> &buf, const std::vector &pos) -> py::object { // - return buffer_getitem_operator(buf, pos); - }) + return buffer_getitem_operator(buf, pos); + }) .def("__getitem__", [](Buffer<> &buf, const Expr &pos) -> Expr { // - return buf(std::vector{pos}); - }) + return buf(std::vector{pos}); + }) .def("__getitem__", [](Buffer<> &buf, const std::vector &pos) -> Expr { // - return buf(pos); - }) + return buf(pos); + }) .def("__setitem__", [](Buffer<> &buf, const int &pos, const py::object &value) -> py::object { // - return buffer_setitem_operator(buf, {pos}, value); - }) + return buffer_setitem_operator(buf, {pos}, value); + }) .def("__setitem__", [](Buffer<> &buf, const std::vector &pos, const py::object &value) -> py::object { // - return buffer_setitem_operator(buf, pos, value); - }) + return buffer_setitem_operator(buf, pos, value); + }) .def("__repr__", [](const Buffer<> &b) -> std::string { - std::ostringstream o; - if (b.defined()) { - o << ""; - } else { - o << ""; - } - return o.str(); // - }) + std::ostringstream o; + if (b.defined()) { + o << ""; + } else { + o << ""; + } + return o.str(); // + }) .def("_get_raw_halide_buffer_t", [](const Buffer<> &b) -> uintptr_t { - return reinterpret_cast(b.raw_buffer()); // - }); + return reinterpret_cast(b.raw_buffer()); // + }); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyDerivative.cpp b/python_bindings/src/halide/halide_/PyDerivative.cpp index 3308cdd91726..f1c843aa7d08 100644 --- a/python_bindings/src/halide/halide_/PyDerivative.cpp +++ b/python_bindings/src/halide/halide_/PyDerivative.cpp @@ -8,23 +8,23 @@ void define_derivative(py::module &m) { py::class_(m, "Derivative") .def( "__getitem__", [](const Derivative &d, const Func &func) { - return d(func); - }, + return d(func); + }, py::arg("func")) .def("__getitem__", // [](const Derivative &d, const Buffer<> &buffer) { - return d(buffer); // - }, + return d(buffer); // + }, py::arg("buffer")) .def("__getitem__", // [](const Derivative &d, const Param<> ¶m) { - return d(param); // - }, + return d(param); // + }, py::arg("param")) .def("__getitem__", // [](const Derivative &d, const std::tuple &args) { - return d(std::get<0>(args), std::get<1>(args)); // - }); + return d(std::get<0>(args), std::get<1>(args)); // + }); m.def("propagate_adjoints", static_cast(&propagate_adjoints)); diff --git a/python_bindings/src/halide/halide_/PyExpr.cpp b/python_bindings/src/halide/halide_/PyExpr.cpp index 473af42a2d8c..2132964ae830 100644 --- a/python_bindings/src/halide/halide_/PyExpr.cpp +++ b/python_bindings/src/halide/halide_/PyExpr.cpp @@ -23,8 +23,8 @@ void define_expr(py::module &m) { py::class_(m, "Expr") .def(py::init<>()) .def(py::init([](bool b) { - return Internal::make_bool(b); - })) + return Internal::make_bool(b); + })) // PyBind11 searches in declared order, // int should be tried before float conversion .def(py::init()) @@ -32,8 +32,8 @@ void define_expr(py::module &m) { // Python float is implemented by double // But Halide prohibits implicitly construct by double. .def(py::init([](double v) { - return double_to_expr_check(v); - })) + return double_to_expr_check(v); + })) .def(py::init()) // for implicitly_convertible @@ -50,19 +50,18 @@ void define_expr(py::module &m) { .def("type", &Expr::type) .def("defined", &Expr::defined) .def("__repr__", [](const Expr &e) -> std::string { - std::ostringstream o; - if (e.defined()) { - o << ""; - } else { - o << ""; - } - return o.str(); - }) - .def("__str__", [](const Expr &e) -> std::string { - std::ostringstream o; - o << e; - return o.str(); - }); + std::ostringstream o; + if (e.defined()) { + o << ""; + } else { + o << ""; + } + return o.str(); + }).def("__str__", [](const Expr &e) -> std::string { + std::ostringstream o; + o << e; + return o.str(); + }); add_binary_operators(expr_class); @@ -92,17 +91,17 @@ void define_expr(py::module &m) { py::class_(m, "Range") .def(py::init<>()) .def(py::init([](const Expr &min, const Expr &extent) -> Range { - return Range(min, extent); - })) + return Range(min, extent); + })) // Allow implicit conversion from py::tuple -> Range, iff py::tuple.size() == 2 .def(py::init([](const py::tuple &t) -> Range { - if (t.size() != 2) { - throw py::value_error("Halide::Range requires exactly two values"); - } - Expr min = t[0].cast(); - Expr extent = t[1].cast(); - return Range(min, extent); - })) + if (t.size() != 2) { + throw py::value_error("Halide::Range requires exactly two values"); + } + Expr min = t[0].cast(); + Expr extent = t[1].cast(); + return Range(min, extent); + })) .def_readwrite("min", &Range::min) .def_readwrite("extent", &Range::extent); diff --git a/python_bindings/src/halide/halide_/PyFunc.cpp b/python_bindings/src/halide/halide_/PyFunc.cpp index a1e222f5c8f0..4d085e5e0809 100644 --- a/python_bindings/src/halide/halide_/PyFunc.cpp +++ b/python_bindings/src/halide/halide_/PyFunc.cpp @@ -22,8 +22,8 @@ void define_get(py::class_ &func_class) { func_class .def("__getitem__", [](Func &func, const LHS &args) -> FuncRef { - return func(args); - }); + return func(args); + }); } template @@ -56,19 +56,19 @@ void define_set_func_ref(py::class_ &func_class) { func_class .def("__setitem__", [](Func &func, const FuncRef &lhs, const double &rhs) { - // Implicitly convert rhs to single precision. Issue warnings if - // we detect loss of precision. - float f = rhs; - if (Internal::reinterpret_bits(rhs) != - Internal::reinterpret_bits((double)f)) { - double diff = rhs - f; - std::ostringstream os; - os << "Loss of precision detected when casting " << rhs << " to a single precision float. The difference is " << diff << "."; - std::string msg = os.str(); - PyErr_WarnEx(nullptr, msg.c_str(), 1); - } - func(lhs) = Expr(f); - }); + // Implicitly convert rhs to single precision. Issue warnings if + // we detect loss of precision. + float f = rhs; + if (Internal::reinterpret_bits(rhs) != + Internal::reinterpret_bits((double)f)) { + double diff = rhs - f; + std::ostringstream os; + os << "Loss of precision detected when casting " << rhs << " to a single precision float. The difference is " << diff << "."; + std::string msg = os.str(); + PyErr_WarnEx(nullptr, msg.c_str(), 1); + } + func(lhs) = Expr(f); + }); } py::object realization_to_object(const Realization &r) { @@ -145,11 +145,11 @@ void define_func(py::module &m) { .def( "realize", [](Func &f, Buffer<> buffer, const Target &target) -> void { - py::gil_scoped_release release; + py::gil_scoped_release release; - PyJITUserContext juc; - f.realize(&juc, buffer, target); - }, + PyJITUserContext juc; + f.realize(&juc, buffer, target); + }, py::arg("dst"), py::arg("target") = Target()) // It's important to have this overload of realize() go first: @@ -161,26 +161,26 @@ void define_func(py::module &m) { .def( "realize", [](Func &f, const std::vector &sizes, const Target &target) -> py::object { - std::optional r; - { - py::gil_scoped_release release; - - PyJITUserContext juc; - r = f.realize(&juc, sizes, target); - } - return realization_to_object(*r); - }, + std::optional r; + { + py::gil_scoped_release release; + + PyJITUserContext juc; + r = f.realize(&juc, sizes, target); + } + return realization_to_object(*r); + }, py::arg("sizes") = std::vector{}, py::arg("target") = Target()) // This will actually allow a list-of-buffers as well as a tuple-of-buffers, but that's OK. .def( "realize", [](Func &f, std::vector> buffers, const Target &t) -> void { - py::gil_scoped_release release; + py::gil_scoped_release release; - PyJITUserContext juc; - f.realize(&juc, Realization(std::move(buffers)), t); - }, + PyJITUserContext juc; + f.realize(&juc, Realization(std::move(buffers)), t); + }, py::arg("dst"), py::arg("target") = Target()) .def("defined", &Func::defined) @@ -189,9 +189,8 @@ void define_func(py::module &m) { .def("args", &Func::args) .def("value", &Func::value) .def("values", [](Func &func) -> py::tuple { - return to_python_tuple(func.values()); - }) - .def("defined", &Func::defined) + return to_python_tuple(func.values()); + }).def("defined", &Func::defined) .def("outputs", &Func::outputs) .def("type", &Func::type) @@ -203,8 +202,8 @@ void define_func(py::module &m) { .def("reorder_storage", (Func & (Func::*)(const std::vector &)) & Func::reorder_storage, py::arg("dims")) .def("reorder_storage", [](Func &func, const py::args &args) -> Func & { - return func.reorder_storage(args_to_vector(args)); - }) + return func.reorder_storage(args_to_vector(args)); + }) .def("compute_at", (Func & (Func::*)(const Func &, const Var &)) & Func::compute_at, py::arg("f"), py::arg("var")) .def("compute_at", (Func & (Func::*)(const Func &, const RVar &)) & Func::compute_at, py::arg("f"), py::arg("rvar")) @@ -231,79 +230,64 @@ void define_func(py::module &m) { .def("compile_to", // [](Func &f, const std::map &output_files, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to(output_files, args, fn_name, to_aot_target(target)); // - }, - py::arg("outputs"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + f.compile_to(output_files, args, fn_name, to_aot_target(target)); // + }, py::arg("outputs"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_bitcode", // [](Func &f, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_bitcode(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + f.compile_to_bitcode(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_bitcode", // [](Func &f, const std::string &filename, const std::vector &args, const Target &target) { - f.compile_to_bitcode(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + f.compile_to_bitcode(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_llvm_assembly", // [](Func &f, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_llvm_assembly(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + f.compile_to_llvm_assembly(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_llvm_assembly", // [](Func &f, const std::string &filename, const std::vector &args, const Target &target) { - f.compile_to_llvm_assembly(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + f.compile_to_llvm_assembly(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_object", // [](Func &f, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_object(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + f.compile_to_object(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_object", // [](Func &f, const std::string &filename, const std::vector &args, const Target &target) { - f.compile_to_object(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + f.compile_to_object(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_header", // [](Func &f, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_header(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + f.compile_to_header(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_assembly", // [](Func &f, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_assembly(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + f.compile_to_assembly(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_assembly", // [](Func &f, const std::string &filename, const std::vector &args, const Target &target) { - f.compile_to_assembly(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + f.compile_to_assembly(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_c", // [](Func &f, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_c(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + f.compile_to_c(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_lowered_stmt", // [](Func &f, const std::string &filename, const std::vector &args, StmtOutputFormat fmt, const Target &target) { - f.compile_to_lowered_stmt(filename, args, fmt, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) + f.compile_to_lowered_stmt(filename, args, fmt, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) .def("compile_to_conceptual_stmt", // [](Func &f, const std::string &filename, const std::vector &args, StmtOutputFormat fmt, const Target &target) { - f.compile_to_conceptual_stmt(filename, args, fmt, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) + f.compile_to_conceptual_stmt(filename, args, fmt, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) .def("compile_to_file", // [](Func &f, const std::string &filename_prefix, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_file(filename_prefix, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + f.compile_to_file(filename_prefix, args, fn_name, to_aot_target(target)); // + }, py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_static_library", // [](Func &f, const std::string &filename_prefix, const std::vector &args, const std::string &fn_name, const Target &target) { - f.compile_to_static_library(filename_prefix, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + f.compile_to_static_library(filename_prefix, args, fn_name, to_aot_target(target)); // + }, py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_multitarget_static_library", &Func::compile_to_multitarget_static_library, py::arg("filename_prefix"), py::arg("arguments"), py::arg("targets")) .def("compile_to_multitarget_object_files", &Func::compile_to_multitarget_object_files, py::arg("filename_prefix"), py::arg("arguments"), py::arg("targets"), py::arg("suffixes")) @@ -311,21 +295,19 @@ void define_func(py::module &m) { // TODO: useless until Module is defined. .def("compile_to_module", // [](Func &f, const std::vector &args, const std::string &fn_name, const Target &target) -> Module { - return f.compile_to_module(args, fn_name, to_aot_target(target)); // - }, - py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + return f.compile_to_module(args, fn_name, to_aot_target(target)); // + }, py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_jit", // [](Func &f, const Target &target) { - f.compile_jit(to_jit_target(target)); // - }, + f.compile_jit(to_jit_target(target)); // + }, py::arg("target") = Target()) .def("compile_to_callable", // [](Func &f, const std::vector &args, const Target &target) { - return f.compile_to_callable(args, to_jit_target(target)); // - }, - py::arg("arguments"), py::arg("target") = Target()) + return f.compile_to_callable(args, to_jit_target(target)); // + }, py::arg("arguments"), py::arg("target") = Target()) .def("has_update_definition", &Func::has_update_definition) .def("num_update_definitions", &Func::num_update_definitions) @@ -336,9 +318,8 @@ void define_func(py::module &m) { .def("update_value", &Func::update_value, py::arg("idx") = 0) .def("update_values", // [](Func &func, int idx) -> py::tuple { - return to_python_tuple(func.update_values(idx)); // - }, - py::arg("idx") = 0) + return to_python_tuple(func.update_values(idx)); // + }, py::arg("idx") = 0) .def("rvars", &Func::rvars, py::arg("idx") = 0) .def("trace_loads", &Func::trace_loads) @@ -374,37 +355,36 @@ void define_func(py::module &m) { .def("infer_input_bounds", // [](Func &f, const py::object &dst, const Target &target) -> void { - const Target t = to_jit_target(target); - PyJITUserContext juc; - - // dst could be Buffer<>, vector, or vector - try { - Buffer<> b = dst.cast>(); - f.infer_input_bounds(&juc, b, t); - return; - } catch (...) { - // fall thru - } - - try { - std::vector> v = dst.cast>>(); - f.infer_input_bounds(&juc, Realization(std::move(v)), t); - return; - } catch (...) { - // fall thru - } - - try { - std::vector v = dst.cast>(); - f.infer_input_bounds(&juc, v, t); - return; - } catch (...) { - // fall thru - } - - throw py::value_error("Invalid arguments to infer_input_bounds"); // - }, - py::arg("dst"), py::arg("target") = Target()) + const Target t = to_jit_target(target); + PyJITUserContext juc; + + // dst could be Buffer<>, vector, or vector + try { + Buffer<> b = dst.cast>(); + f.infer_input_bounds(&juc, b, t); + return; + } catch (...) { + // fall thru + } + + try { + std::vector> v = dst.cast>>(); + f.infer_input_bounds(&juc, Realization(std::move(v)), t); + return; + } catch (...) { + // fall thru + } + + try { + std::vector v = dst.cast>(); + f.infer_input_bounds(&juc, v, t); + return; + } catch (...) { + // fall thru + } + + throw py::value_error("Invalid arguments to infer_input_bounds"); // + }, py::arg("dst"), py::arg("target") = Target()) .def("in_", static_cast(&Func::in), py::arg("f")) .def("in_", static_cast &fs)>(&Func::in), py::arg("fs")) @@ -431,10 +411,10 @@ void define_func(py::module &m) { .def("infer_arguments", &Func::infer_arguments) .def("__repr__", [](const Func &func) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); // - }); + std::ostringstream o; + o << ""; + return o.str(); // + }); py::implicitly_convertible(); @@ -485,15 +465,13 @@ void define_func(py::module &m) { m.def( "evaluate", [](const py::object &expr) -> py::object { - return evaluate_impl(expr, false); - }, - py::arg("expr")); + return evaluate_impl(expr, false); + }, py::arg("expr")); m.def( "evaluate_may_gpu", [](const py::object &expr) -> py::object { - return evaluate_impl(expr, true); - }, - py::arg("expr")); + return evaluate_impl(expr, true); + }, py::arg("expr")); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyGenerator.cpp b/python_bindings/src/halide/halide_/PyGenerator.cpp index 49af254b3da6..f26d0bcc5cbc 100644 --- a/python_bindings/src/halide/halide_/PyGenerator.cpp +++ b/python_bindings/src/halide/halide_/PyGenerator.cpp @@ -125,8 +125,8 @@ void define_generator(py::module &m) { py::class_(m, "ArgInfo") .def(py::init<>()) .def(py::init([](const std::string &name, ArgInfoDirection dir, ArgInfoKind kind, std::vector types, int dimensions) -> ArgInfo { - return ArgInfo{name, dir, kind, std::move(types), dimensions}; - }), + return ArgInfo{name, dir, kind, std::move(types), dimensions}; + }), py::arg("name"), py::arg("dir"), py::arg("kind"), py::arg("types"), py::arg("dimensions")) .def_readonly("name", &ArgInfo::name) .def_readonly("dir", &ArgInfo::dir) @@ -143,45 +143,43 @@ void define_generator(py::module &m) { .def("target", &GeneratorContext::target) .def("autoscheduler_params", &GeneratorContext::autoscheduler_params) .def("__enter__", [](const GeneratorContext &context) -> py::object { - auto _generatorcontext_enter = py::module_::import("halide").attr("_generatorcontext_enter"); - return _generatorcontext_enter(context); - }) - .def("__exit__", [](const GeneratorContext &context, const py::object &exc_type, const py::object &exc_value, const py::object &exc_traceback) -> bool { - auto _generatorcontext_exit = py::module_::import("halide").attr("_generatorcontext_exit"); - _generatorcontext_exit(context); - return false; - }) - .def("__repr__", [](const GeneratorContext &context) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }); + auto _generatorcontext_enter = py::module_::import("halide").attr("_generatorcontext_enter"); + return _generatorcontext_enter(context); + }).def("__exit__", [](const GeneratorContext &context, const py::object &exc_type, const py::object &exc_value, const py::object &exc_traceback) -> bool { + auto _generatorcontext_exit = py::module_::import("halide").attr("_generatorcontext_exit"); + _generatorcontext_exit(context); + return false; + }).def("__repr__", [](const GeneratorContext &context) -> std::string { + std::ostringstream o; + o << ""; + return o.str(); + }); m.def("_generate_filter_main", // [](const std::vector &arguments) -> void { - if (arguments.empty()) { - throw std::invalid_argument("No arguments provided to _generate_filter_main"); - } - - // POSIX requires argv to be mutable and null-terminated - std::vector argv; - argv.reserve(arguments.size() + 1); - for (const auto &s : arguments) { - argv.push_back(const_cast(s.c_str())); - } - argv.push_back(nullptr); - - const int result = Halide::Internal::generate_filter_main( - static_cast(argv.size()) - 1, argv.data(), PyGeneratorFactoryProvider()); - if (result != 0) { - // Some paths in generate_filter_main() will fail with user_error - // or similar (which throws an exception due to how libHalide is - // built for Python), but other paths just return an error code. - // For consistency, handle both by throwing a C++ exception, which - // PyBind11 turns into a Python exception. - throw std::runtime_error("Generator failed: " + std::to_string(result)); - } // - }, + if (arguments.empty()) { + throw std::invalid_argument("No arguments provided to _generate_filter_main"); + } + + // POSIX requires argv to be mutable and null-terminated + std::vector argv; + argv.reserve(arguments.size() + 1); + for (const auto &s : arguments) { + argv.push_back(const_cast(s.c_str())); + } + argv.push_back(nullptr); + + const int result = Halide::Internal::generate_filter_main( + static_cast(argv.size()) - 1, argv.data(), PyGeneratorFactoryProvider()); + if (result != 0) { + // Some paths in generate_filter_main() will fail with user_error + // or similar (which throws an exception due to how libHalide is + // built for Python), but other paths just return an error code. + // For consistency, handle both by throwing a C++ exception, which + // PyBind11 turns into a Python exception. + throw std::runtime_error("Generator failed: " + std::to_string(result)); + } // + }, py::arg("argv")); m.def("_unique_name", []() -> std::string { diff --git a/python_bindings/src/halide/halide_/PyIROperator.cpp b/python_bindings/src/halide/halide_/PyIROperator.cpp index 55e19786b7cf..db48b7539a3d 100644 --- a/python_bindings/src/halide/halide_/PyIROperator.cpp +++ b/python_bindings/src/halide/halide_/PyIROperator.cpp @@ -151,17 +151,15 @@ void define_operators(py::module &m) { m.def( "print_when", [](const Expr &condition, const py::args &args) -> Expr { - return print_when(condition, collect_print_args(args)); - }, - py::arg("condition")); + return print_when(condition, collect_print_args(args)); + }, py::arg("condition")); m.def( "require", [](const Expr &condition, const Expr &value, const py::args &args) -> Expr { - auto v = args_to_vector(args); - v.insert(v.begin(), value); - return require(condition, v); - }, - py::arg("condition"), py::arg("value")); + auto v = args_to_vector(args); + v.insert(v.begin(), value); + return require(condition, v); + }, py::arg("condition"), py::arg("value")); m.def("lerp", &lerp); m.def("popcount", &popcount); @@ -179,9 +177,8 @@ void define_operators(py::module &m) { m.def( "memoize_tag", [](const Expr &result, const py::args &cache_key_values) -> Expr { - return Internal::memoize_tag_helper(result, args_to_vector(cache_key_values)); - }, - py::arg("result")); + return Internal::memoize_tag_helper(result, args_to_vector(cache_key_values)); + }, py::arg("result")); m.def("likely", &likely); m.def("likely_if_innermost", &likely_if_innermost); diff --git a/python_bindings/src/halide/halide_/PyImageParam.cpp b/python_bindings/src/halide/halide_/PyImageParam.cpp index 330c94b5b74e..ee5a45ada015 100644 --- a/python_bindings/src/halide/halide_/PyImageParam.cpp +++ b/python_bindings/src/halide/halide_/PyImageParam.cpp @@ -43,18 +43,18 @@ void define_image_param(py::module &m) { .def("parameter", &OutputImageParam::parameter) .def("__repr__", [](const OutputImageParam &im) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }); + std::ostringstream o; + o << ""; + return o.str(); + }); auto image_param_class = py::class_(m, "ImageParam", output_image_param_class) @@ -65,32 +65,29 @@ void define_image_param(py::module &m) { .def("get", &ImageParam::get) .def("reset", &ImageParam::reset) .def("__getitem__", [](ImageParam &im, const Expr &args) -> Expr { - return im(args); - }) - .def("__getitem__", [](ImageParam &im, const std::vector &args) -> Expr { - return im(args); - }) - .def("__getitem__", [](ImageParam &im, const std::vector &args) -> Expr { - return im(args); - }) - .def("in_", static_cast(&ImageParam::in)) + return im(args); + }).def("__getitem__", [](ImageParam &im, const std::vector &args) -> Expr { + return im(args); + }).def("__getitem__", [](ImageParam &im, const std::vector &args) -> Expr { + return im(args); + }).def("in_", static_cast(&ImageParam::in)) .def("in_", static_cast &)>(&ImageParam::in)) .def("in_", static_cast(&ImageParam::in)) .def("trace_loads", &ImageParam::trace_loads) .def("__repr__", [](const ImageParam &im) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }); + std::ostringstream o; + o << ""; + return o.str(); + }); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyInlineReductions.cpp b/python_bindings/src/halide/halide_/PyInlineReductions.cpp index a56e7ce21e11..422536c0f22f 100644 --- a/python_bindings/src/halide/halide_/PyInlineReductions.cpp +++ b/python_bindings/src/halide/halide_/PyInlineReductions.cpp @@ -28,25 +28,21 @@ void define_inline_reductions(py::module &m) { m.def( "argmax", [](const Expr &e, const std::string &s) -> py::tuple { - return to_python_tuple(argmax(e, s)); - }, - py::arg("expr"), py::arg("name") = "argmax"); + return to_python_tuple(argmax(e, s)); + }, py::arg("expr"), py::arg("name") = "argmax"); m.def( "argmax", [](const RDom &r, const Expr &e, const std::string &s) -> py::tuple { - return to_python_tuple(argmax(r, e, s)); - }, - py::arg("rdom"), py::arg("expr"), py::arg("name") = "argmax"); + return to_python_tuple(argmax(r, e, s)); + }, py::arg("rdom"), py::arg("expr"), py::arg("name") = "argmax"); m.def( "argmin", [](const Expr &e, const std::string &s) -> py::tuple { - return to_python_tuple(argmin(e, s)); - }, - py::arg("expr"), py::arg("name") = "argmin"); + return to_python_tuple(argmin(e, s)); + }, py::arg("expr"), py::arg("name") = "argmin"); m.def( "argmin", [](const RDom &r, const Expr &e, const std::string &s) -> py::tuple { - return to_python_tuple(argmin(r, e, s)); - }, - py::arg("rdom"), py::arg("expr"), py::arg("name") = "argmin"); + return to_python_tuple(argmin(r, e, s)); + }, py::arg("rdom"), py::arg("expr"), py::arg("name") = "argmin"); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyLoopLevel.cpp b/python_bindings/src/halide/halide_/PyLoopLevel.cpp index b2db4b5d035d..7d45fb9b892c 100644 --- a/python_bindings/src/halide/halide_/PyLoopLevel.cpp +++ b/python_bindings/src/halide/halide_/PyLoopLevel.cpp @@ -16,12 +16,12 @@ void define_loop_level(py::module &m) { .def_static("inlined", &LoopLevel::inlined) .def_static("root", &LoopLevel::root) .def("__repr__", [](const LoopLevel &b) -> std::string { - std::ostringstream o; - // b.to_string() fails for locked LoopLevels. Just output something generic. - // o << ""; - o << ""; - return o.str(); - }); + std::ostringstream o; + // b.to_string() fails for locked LoopLevels. Just output something generic. + // o << ""; + o << ""; + return o.str(); + }); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyModule.cpp b/python_bindings/src/halide/halide_/PyModule.cpp index f9a0d98f837e..83180c05a7bf 100644 --- a/python_bindings/src/halide/halide_/PyModule.cpp +++ b/python_bindings/src/halide/halide_/PyModule.cpp @@ -17,8 +17,8 @@ void define_module(py::module &m) { .def_readwrite("schedule_source", &AutoSchedulerResults::schedule_source) .def_readwrite("featurization", &AutoSchedulerResults::featurization) .def("__repr__", [](const AutoSchedulerResults &o) -> std::string { - return ""; - }); + return ""; + }); auto module_class = py::class_(m, "Module") @@ -54,10 +54,10 @@ void define_module(py::module &m) { // .def("append", (void (Module::*)(const Internal::LoweredFunc &)) &Module::append, py::arg("function")) .def("__repr__", [](const Module &m) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }); + std::ostringstream o; + o << ""; + return o.str(); + }); m.def("link_modules", &link_modules, py::arg("name"), py::arg("modules")); m.def("compile_standalone_runtime", static_cast(&compile_standalone_runtime), py::arg("filename"), py::arg("target")); diff --git a/python_bindings/src/halide/halide_/PyParam.cpp b/python_bindings/src/halide/halide_/PyParam.cpp index 0294d918cb81..144a0d9da845 100644 --- a/python_bindings/src/halide/halide_/PyParam.cpp +++ b/python_bindings/src/halide/halide_/PyParam.cpp @@ -12,27 +12,26 @@ template void add_param_methods(py::class_> ¶m_class) { param_class .def(py::init([](const Type &type, TYPE value) { - Param<> param(type); - param.set(value); - return param; - }), + Param<> param(type); + param.set(value); + return param; + }), py::arg("type"), py::arg("value")) .def(py::init([](const Type &type, const std::string &name, TYPE value) { - Param<> param(type, name); - param.set(value); - return param; - }), + Param<> param(type, name); + param.set(value); + return param; + }), py::arg("type"), py::arg("name"), py::arg("value")) .def( "set", [](Param<> ¶m, TYPE value) -> void { - param.set(value); - }, + param.set(value); + }, py::arg("value")) .def("set_estimate", // [](Param<> ¶m, TYPE value) -> void { - param.set_estimate(value); // - }, - py::arg("value")); + param.set_estimate(value); // + }, py::arg("value")); } } // namespace @@ -53,15 +52,15 @@ void define_param(py::module &m) { .def("min_value", &Param<>::min_value) .def("max_value", &Param<>::max_value) .def("parameter", [](const Param<> ¶m) -> Parameter { - return param.parameter(); - }) + return param.parameter(); + }) .def("__repr__", [](const Param<> ¶m) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }); + std::ostringstream o; + o << ""; + return o.str(); + }); add_param_methods(param_class); add_param_methods(param_class); diff --git a/python_bindings/src/halide/halide_/PyParameter.cpp b/python_bindings/src/halide/halide_/PyParameter.cpp index 11f7f336ad03..747a4f6c9f0d 100644 --- a/python_bindings/src/halide/halide_/PyParameter.cpp +++ b/python_bindings/src/halide/halide_/PyParameter.cpp @@ -13,9 +13,8 @@ void add_scalar_methods(py::class_ ¶meter_class) { .def("scalar", &Parameter::scalar) .def( "set_scalar", [](Parameter ¶meter, TYPE value) -> void { - parameter.set_scalar(value); - }, - py::arg("value")); + parameter.set_scalar(value); + }, py::arg("value")); } } // namespace @@ -31,25 +30,23 @@ void define_parameter(py::module &m) { .def(py::init()) .def(py::init()) .def("_to_argument", [](const Parameter &p) -> Argument { - return Argument(p.name(), - p.is_buffer() ? Argument::InputBuffer : Argument::InputScalar, - p.type(), - p.dimensions(), - p.get_argument_estimates()); - }) - .def("__repr__", [](const Parameter &p) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }) - .def("type", &Parameter::type) + return Argument(p.name(), + p.is_buffer() ? Argument::InputBuffer : Argument::InputScalar, + p.type(), + p.dimensions(), + p.get_argument_estimates()); + }).def("__repr__", [](const Parameter &p) -> std::string { + std::ostringstream o; + o << ""; + return o.str(); + }).def("type", &Parameter::type) .def("dimensions", &Parameter::dimensions) .def("name", &Parameter::name) .def("is_buffer", &Parameter::is_buffer) diff --git a/python_bindings/src/halide/halide_/PyPipeline.cpp b/python_bindings/src/halide/halide_/PyPipeline.cpp index 35ee2e85e902..7b3f0a1dd413 100644 --- a/python_bindings/src/halide/halide_/PyPipeline.cpp +++ b/python_bindings/src/halide/halide_/PyPipeline.cpp @@ -46,23 +46,23 @@ void define_pipeline(py::module &m) { .def(py::init<>()) .def(py::init(), py::arg("name")) .def(py::init([](const std::string &name, const py::dict &extra) -> AutoschedulerParams { - // Manually convert the dict: - // we want to allow Python to pass in dicts that have non-string values for some keys; - // PyBind will reject these as a type failure. We'll stringify them here explicitly. - AutoschedulerParams asp(name); - for (auto item : extra) { - const std::string name = py::str(item.first).cast(); - const std::string value = py::str(item.second).cast(); - asp.extra[name] = value; - } - return asp; - }), + // Manually convert the dict: + // we want to allow Python to pass in dicts that have non-string values for some keys; + // PyBind will reject these as a type failure. We'll stringify them here explicitly. + AutoschedulerParams asp(name); + for (auto item : extra) { + const std::string name = py::str(item.first).cast(); + const std::string value = py::str(item.second).cast(); + asp.extra[name] = value; + } + return asp; + }), py::arg("target"), py::arg("autoscheduler_params")) .def_readwrite("name", &AutoschedulerParams::name) .def_readwrite("extra", &AutoschedulerParams::extra) .def("__repr__", [](const AutoSchedulerResults &o) -> std::string { - return ""; - }); + return ""; + }); auto pipeline_class = py::class_(m, "Pipeline") @@ -80,123 +80,105 @@ void define_pipeline(py::module &m) { .def( "compile_to", [](Pipeline &p, const std::map &output_files, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to(output_files, args, fn_name, to_aot_target(target)); - }, - py::arg("outputs"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + p.compile_to(output_files, args, fn_name, to_aot_target(target)); + }, py::arg("outputs"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_bitcode", // [](Pipeline &p, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_bitcode(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + p.compile_to_bitcode(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_bitcode", // [](Pipeline &p, const std::string &filename, const std::vector &args, const Target &target) { - p.compile_to_bitcode(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + p.compile_to_bitcode(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_llvm_assembly", // [](Pipeline &p, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_llvm_assembly(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + p.compile_to_llvm_assembly(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_llvm_assembly", // [](Pipeline &p, const std::string &filename, const std::vector &args, const Target &target) { - p.compile_to_llvm_assembly(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + p.compile_to_llvm_assembly(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_object", // [](Pipeline &p, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_object(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + p.compile_to_object(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_object", // [](Pipeline &p, const std::string &filename, const std::vector &args, const Target &target) { - p.compile_to_object(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + p.compile_to_object(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_header", // [](Pipeline &p, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_header(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + p.compile_to_header(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_assembly", // [](Pipeline &p, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_assembly(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) + p.compile_to_assembly(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target()) .def("compile_to_assembly", // [](Pipeline &p, const std::string &filename, const std::vector &args, const Target &target) { - p.compile_to_assembly(filename, args, "", to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) + p.compile_to_assembly(filename, args, "", to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("target") = Target()) .def("compile_to_c", // [](Pipeline &p, const std::string &filename, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_c(filename, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + p.compile_to_c(filename, args, fn_name, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_lowered_stmt", // [](Pipeline &p, const std::string &filename, const std::vector &args, StmtOutputFormat fmt, const Target &target) { - p.compile_to_lowered_stmt(filename, args, fmt, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) + p.compile_to_lowered_stmt(filename, args, fmt, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) .def("compile_to_conceptual_stmt", // [](Pipeline &p, const std::string &filename, const std::vector &args, StmtOutputFormat fmt, const Target &target) { - p.compile_to_conceptual_stmt(filename, args, fmt, to_aot_target(target)); // - }, - py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) + p.compile_to_conceptual_stmt(filename, args, fmt, to_aot_target(target)); // + }, py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) .def("compile_to_file", // [](Pipeline &p, const std::string &filename_prefix, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_file(filename_prefix, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + p.compile_to_file(filename_prefix, args, fn_name, to_aot_target(target)); // + }, py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_static_library", // [](Pipeline &p, const std::string &filename_prefix, const std::vector &args, const std::string &fn_name, const Target &target) { - p.compile_to_static_library(filename_prefix, args, fn_name, to_aot_target(target)); // - }, - py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) + p.compile_to_static_library(filename_prefix, args, fn_name, to_aot_target(target)); // + }, py::arg("filename_prefix"), py::arg("arguments"), py::arg("fn_name") = "", py::arg("target") = Target()) .def("compile_to_multitarget_static_library", &Pipeline::compile_to_multitarget_static_library, py::arg("filename_prefix"), py::arg("arguments"), py::arg("targets")) .def("compile_to_multitarget_object_files", &Pipeline::compile_to_multitarget_object_files, py::arg("filename_prefix"), py::arg("arguments"), py::arg("targets"), py::arg("suffixes")) .def("compile_to_module", // [](Pipeline &p, const std::vector &args, const std::string &fn_name, const Target &target, LinkageType linkage_type) -> Module { - return p.compile_to_module(args, fn_name, to_aot_target(target), linkage_type); // - }, - py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target(), py::arg("linkage") = LinkageType::ExternalPlusMetadata) + return p.compile_to_module(args, fn_name, to_aot_target(target), linkage_type); // + }, py::arg("arguments"), py::arg("fn_name"), py::arg("target") = Target(), py::arg("linkage") = LinkageType::ExternalPlusMetadata) .def("compile_jit", // [](Pipeline &p, const Target &target) { - p.compile_jit(to_jit_target(target)); // - }, + p.compile_jit(to_jit_target(target)); // + }, py::arg("target") = Target()) .def("compile_to_callable", // [](Pipeline &p, const std::vector &args, const Target &target) { - return p.compile_to_callable(args, to_jit_target(target)); // - }, - py::arg("arguments"), py::arg("target") = Target()) + return p.compile_to_callable(args, to_jit_target(target)); // + }, py::arg("arguments"), py::arg("target") = Target()) .def("realize", // [](Pipeline &p, Buffer<> buffer, const Target &target) -> void { - py::gil_scoped_release release; + py::gil_scoped_release release; - PyJITUserContext juc; - p.realize(&juc, Realization(std::move(buffer)), target); // - }, - py::arg("dst"), py::arg("target") = Target()) + PyJITUserContext juc; + p.realize(&juc, Realization(std::move(buffer)), target); // + }, py::arg("dst"), py::arg("target") = Target()) // It's important to have this overload of realize() go first: // passing an empty list [] is ambiguous in Python, and could match to @@ -206,105 +188,99 @@ void define_pipeline(py::module &m) { // be the first one chosen by the bindings in this case. .def("realize", // [](Pipeline &p, std::vector sizes, const Target &target) -> py::object { - std::optional r; - { - py::gil_scoped_release release; + std::optional r; + { + py::gil_scoped_release release; - PyJITUserContext juc; - r = p.realize(&juc, std::move(sizes), target); - } - return realization_to_object(*r); // - }, - py::arg("sizes") = std::vector{}, py::arg("target") = Target()) + PyJITUserContext juc; + r = p.realize(&juc, std::move(sizes), target); + } + return realization_to_object(*r); // + }, py::arg("sizes") = std::vector{}, py::arg("target") = Target()) // This will actually allow a list-of-buffers as well as a tuple-of-buffers, but that's OK. .def("realize", // [](Pipeline &p, std::vector> buffers, const Target &t) -> void { - py::gil_scoped_release release; + py::gil_scoped_release release; - PyJITUserContext juc; - p.realize(&juc, Realization(std::move(buffers)), t); // - }, - py::arg("dst"), py::arg("target") = Target()) + PyJITUserContext juc; + p.realize(&juc, Realization(std::move(buffers)), t); // + }, py::arg("dst"), py::arg("target") = Target()) .def("infer_input_bounds", // [](Pipeline &p, const py::object &dst, const Target &target) -> void { - const Target t = to_jit_target(target); - PyJITUserContext juc; - - // dst could be Buffer<>, vector, or vector - try { - Buffer<> b = dst.cast>(); - p.infer_input_bounds(&juc, b, t); - return; - } catch (...) { - // fall thru - } - - try { - std::vector> v = dst.cast>>(); - p.infer_input_bounds(&juc, Realization(std::move(v)), t); - return; - } catch (...) { - // fall thru - } - - try { - std::vector v = dst.cast>(); - p.infer_input_bounds(&juc, v, t); - return; - } catch (...) { - // fall thru - } - - throw py::value_error("Invalid arguments to infer_input_bounds"); // - }, - py::arg("dst"), py::arg("target") = Target()) + const Target t = to_jit_target(target); + PyJITUserContext juc; + + // dst could be Buffer<>, vector, or vector + try { + Buffer<> b = dst.cast>(); + p.infer_input_bounds(&juc, b, t); + return; + } catch (...) { + // fall thru + } + + try { + std::vector> v = dst.cast>>(); + p.infer_input_bounds(&juc, Realization(std::move(v)), t); + return; + } catch (...) { + // fall thru + } + + try { + std::vector v = dst.cast>(); + p.infer_input_bounds(&juc, v, t); + return; + } catch (...) { + // fall thru + } + + throw py::value_error("Invalid arguments to infer_input_bounds"); // + }, py::arg("dst"), py::arg("target") = Target()) .def("infer_arguments", [](Pipeline &p) -> std::vector { - return p.infer_arguments(); // - }) + return p.infer_arguments(); // + }) .def("defined", &Pipeline::defined) .def("invalidate_cache", &Pipeline::invalidate_cache) .def("add_requirement", // [](Pipeline &p, const Expr &condition, const py::args &error_args) -> void { - auto v = collect_print_args(error_args); - p.add_requirement(condition, v); // - }, - py::arg("condition")) + auto v = collect_print_args(error_args); + p.add_requirement(condition, v); // + }, py::arg("condition")) .def("__repr__", [](const Pipeline &p) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); // - }); + std::ostringstream o; + o << ""; + return o.str(); // + }); // TODO: These should really live in PyGenerator.cpp once that lands m.def( "create_callable_from_generator", [](const GeneratorContext &context, const std::string &name, const std::map &generator_params) -> Callable { - return create_callable_from_generator(context, name, generator_params); - }, - py::arg("context"), py::arg("name"), py::arg("generator_params") = std::map{}); + return create_callable_from_generator(context, name, generator_params); + }, py::arg("context"), py::arg("name"), py::arg("generator_params") = std::map{}); m.def( "create_callable_from_generator", [](const Target &target, const std::string &name, const std::map &generator_params) -> Callable { - return create_callable_from_generator(target, name, generator_params); - }, - py::arg("target"), py::arg("name"), py::arg("generator_params") = std::map{}); + return create_callable_from_generator(target, name, generator_params); + }, py::arg("target"), py::arg("name"), py::arg("generator_params") = std::map{}); } } // namespace PythonBindings diff --git a/python_bindings/src/halide/halide_/PyRDom.cpp b/python_bindings/src/halide/halide_/PyRDom.cpp index 39e42e3d9eac..c59bf8bebed3 100644 --- a/python_bindings/src/halide/halide_/PyRDom.cpp +++ b/python_bindings/src/halide/halide_/PyRDom.cpp @@ -16,10 +16,10 @@ void define_rvar(py::module &m) { .def("extent", &RVar::extent) .def("name", &RVar::name) .def("__repr__", [](const RVar &v) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }); + std::ostringstream o; + o << ""; + return o.str(); + }); py::implicitly_convertible(); @@ -71,20 +71,19 @@ void define_rdom(py::module &m) { .def("__iter__", [](const RDom &r) { return RDomIterator(r); }, py::keep_alive<0, 1>()) .def("where", &RDom::where, py::arg("predicate")) .def("__getitem__", [](RDom &r, const int i) -> RVar { - if (i < 0 || i >= r.dimensions()) { - throw pybind11::key_error(); - } - return r[i]; // - }) - .def_readonly("x", &RDom::x) + if (i < 0 || i >= r.dimensions()) { + throw pybind11::key_error(); + } + return r[i]; // + }).def_readonly("x", &RDom::x) .def_readonly("y", &RDom::y) .def_readonly("z", &RDom::z) .def_readonly("w", &RDom::w) .def("__repr__", [](const RDom &r) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); // - }); + std::ostringstream o; + o << ""; + return o.str(); // + }); add_binary_operators(rdom_class); } diff --git a/python_bindings/src/halide/halide_/PyScheduleMethods.h b/python_bindings/src/halide/halide_/PyScheduleMethods.h index 75475dc73f9d..9cb775bdd71a 100644 --- a/python_bindings/src/halide/halide_/PyScheduleMethods.h +++ b/python_bindings/src/halide/halide_/PyScheduleMethods.h @@ -55,8 +55,8 @@ HALIDE_NEVER_INLINE void add_schedule_methods(PythonClass &class_instance) { py::arg("previous"), py::arg("inners"), py::arg("factors"), py::arg("tail") = TailStrategy::Auto) .def("reorder", (T & (T::*)(const std::vector &)) & T::reorder, py::arg("vars")) .def("reorder", [](T &t, const py::args &args) -> T & { - return t.reorder(args_to_vector(args)); - }) + return t.reorder(args_to_vector(args)); + }) .def("parallel", (T & (T::*)(const VarOrRVar &)) & T::parallel, py::arg("var")) .def("parallel", (T & (T::*)(const VarOrRVar &, const Expr &, TailStrategy)) & T::parallel, py::arg("var"), py::arg("task_size"), py::arg("tail") = TailStrategy::Auto) @@ -104,9 +104,9 @@ HALIDE_NEVER_INLINE void add_schedule_methods(PythonClass &class_instance) { .def("prefetch", (T & (T::*)(const Func &, const VarOrRVar &, const VarOrRVar &, Expr, PrefetchBoundStrategy)) & T::prefetch, py::arg("func"), py::arg("at"), py::arg("from"), py::arg("offset") = 1, py::arg("strategy") = PrefetchBoundStrategy::GuardWithIf) .def("prefetch", // [](T &t, const ImageParam &image, const VarOrRVar &at, const VarOrRVar &from, const Expr &offset, PrefetchBoundStrategy strategy) -> T & { - // Templated function; specializing only on ImageParam for now - return t.template prefetch(image, at, from, offset, strategy); // - }, + // Templated function; specializing only on ImageParam for now + return t.template prefetch(image, at, from, offset, strategy); // + }, py::arg("image"), // py::arg("at"), // py::arg("from"), // diff --git a/python_bindings/src/halide/halide_/PySerialization.cpp b/python_bindings/src/halide/halide_/PySerialization.cpp index 2146cf4f7a7d..eef0c710a269 100644 --- a/python_bindings/src/halide/halide_/PySerialization.cpp +++ b/python_bindings/src/halide/halide_/PySerialization.cpp @@ -9,14 +9,14 @@ void define_serialization(py::module &m) { // Serialize pipeline functions m.def("serialize_pipeline", // [](const Pipeline &pipeline, const PathLike &filename, std::optional get_params) -> std::optional> { - if (get_params.value_or(false)) { - std::map params; - serialize_pipeline(pipeline, filename, params); - return params; - } - serialize_pipeline(pipeline, filename); - return {}; // - }, + if (get_params.value_or(false)) { + std::map params; + serialize_pipeline(pipeline, filename, params); + return params; + } + serialize_pipeline(pipeline, filename); + return {}; // + }, py::arg("pipeline"), // py::arg("filename"), // py::kw_only(), // @@ -25,16 +25,16 @@ void define_serialization(py::module &m) { m.def("serialize_pipeline", // [](const Pipeline &pipeline, std::optional get_params) -> std::variant>, py::bytes> { - std::vector data; - if (get_params.value_or(false)) { - std::map params; - serialize_pipeline(pipeline, data, params); - py::bytes bytes_data = py::bytes(reinterpret_cast(data.data()), data.size()); - return std::make_tuple(bytes_data, params); - } - serialize_pipeline(pipeline, data); - return py::bytes(reinterpret_cast(data.data()), data.size()); // - }, + std::vector data; + if (get_params.value_or(false)) { + std::map params; + serialize_pipeline(pipeline, data, params); + py::bytes bytes_data = py::bytes(reinterpret_cast(data.data()), data.size()); + return std::make_tuple(bytes_data, params); + } + serialize_pipeline(pipeline, data); + return py::bytes(reinterpret_cast(data.data()), data.size()); // + }, py::arg("pipeline"), // py::kw_only(), // py::arg("get_params") = std::nullopt, // @@ -43,20 +43,20 @@ void define_serialization(py::module &m) { // Deserialize pipeline functions m.def("deserialize_pipeline", // [](const py::bytes &data, const std::map &user_params) -> Pipeline { - // TODO: rework API in serialize_pipeline to take a std::span<> in C++20 - // https://github.com/halide/Halide/issues/8722 - std::string_view view{data}; - std::vector span{view.begin(), view.end()}; - return deserialize_pipeline(span, user_params); // - }, + // TODO: rework API in serialize_pipeline to take a std::span<> in C++20 + // https://github.com/halide/Halide/issues/8722 + std::string_view view{data}; + std::vector span{view.begin(), view.end()}; + return deserialize_pipeline(span, user_params); // + }, py::arg("data"), // py::arg("user_params") = std::map{}, // "Deserialize a Halide pipeline from bytes."); m.def("deserialize_pipeline", // [](const PathLike &filename, const std::map &user_params) -> Pipeline { - return deserialize_pipeline(filename, user_params); // - }, + return deserialize_pipeline(filename, user_params); // + }, py::arg("filename"), // py::arg("user_params") = std::map{}, // "Deserialize a Halide pipeline from a file. Accepts string or path-like objects."); @@ -64,19 +64,19 @@ void define_serialization(py::module &m) { // Deserialize parameters functions m.def("deserialize_parameters", // [](const py::bytes &data) -> std::map { - // TODO: rework API in serialize_pipeline to take a std::span<> in C++20 - // https://github.com/halide/Halide/issues/8722 - std::string_view view{data}; - std::vector span{view.begin(), view.end()}; - return deserialize_parameters(span); // - }, + // TODO: rework API in serialize_pipeline to take a std::span<> in C++20 + // https://github.com/halide/Halide/issues/8722 + std::string_view view{data}; + std::vector span{view.begin(), view.end()}; + return deserialize_parameters(span); // + }, py::arg("data"), // "Deserialize external parameters from serialized pipeline bytes."); m.def("deserialize_parameters", // [](const PathLike &filename) -> std::map { - return deserialize_parameters(filename); // - }, + return deserialize_parameters(filename); // + }, py::arg("filename"), // "Deserialize external parameters from a serialized pipeline file. Accepts string or path-like objects."); } diff --git a/python_bindings/src/halide/halide_/PyStage.cpp b/python_bindings/src/halide/halide_/PyStage.cpp index 9a9f6394d7cd..e75799b4fe7d 100644 --- a/python_bindings/src/halide/halide_/PyStage.cpp +++ b/python_bindings/src/halide/halide_/PyStage.cpp @@ -20,19 +20,19 @@ void define_stage(py::module &m) { py::arg("r"), py::arg("v")) .def("split_vars", [](const Stage &stage) -> py::list { - auto vars = stage.split_vars(); - py::list result; - // Return a mixed-type list of Var and RVar objects, instead of - // a list of VarOrRVar objects. - for (const auto &v : vars) { - if (v.is_rvar) { - result.append(py::cast(v.rvar)); - } else { - result.append(py::cast(v.var)); - } - } - return result; - }) + auto vars = stage.split_vars(); + py::list result; + // Return a mixed-type list of Var and RVar objects, instead of + // a list of VarOrRVar objects. + for (const auto &v : vars) { + if (v.is_rvar) { + result.append(py::cast(v.rvar)); + } else { + result.append(py::cast(v.var)); + } + } + return result; + }) .def("unscheduled", &Stage::unscheduled); diff --git a/python_bindings/src/halide/halide_/PyTuple.cpp b/python_bindings/src/halide/halide_/PyTuple.cpp index 934008e20d8c..9371a8d590f9 100644 --- a/python_bindings/src/halide/halide_/PyTuple.cpp +++ b/python_bindings/src/halide/halide_/PyTuple.cpp @@ -40,38 +40,37 @@ void define_tuple(py::module &m) { py::class_(m, "Tuple") // for implicitly_convertible .def(py::init([](const py::tuple &t) -> Tuple { - std::vector v; - v.reserve(t.size()); - for (const auto o : t) { - v.push_back(o.cast()); - } - return Tuple(v); - })) + std::vector v; + v.reserve(t.size()); + for (const auto o : t) { + v.push_back(o.cast()); + } + return Tuple(v); + })) .def(py::init([](const FuncRef &f) -> Tuple { - std::vector v; - v.reserve(f.size()); - if (f.size() == 1) { - v.push_back(f); - } else { - for (size_t i = 0; i < f.size(); ++i) { - v.push_back(f[(int)i]); - } - } - return Tuple(v); - })) + std::vector v; + v.reserve(f.size()); + if (f.size() == 1) { + v.push_back(f); + } else { + for (size_t i = 0; i < f.size(); ++i) { + v.push_back(f[(int)i]); + } + } + return Tuple(v); + })) .def(py::init([](const std::vector &v) -> Tuple { - return Tuple(v); - })) + return Tuple(v); + })) .def("__repr__", [](const Tuple &t) -> std::string { - std::ostringstream o; - o << ""; - return o.str(); - }) - .def("__str__", [](const Tuple &t) -> std::string { - std::ostringstream o; - o << t; - return o.str(); - }); + std::ostringstream o; + o << ""; + return o.str(); + }).def("__str__", [](const Tuple &t) -> std::string { + std::ostringstream o; + o << t; + return o.str(); + }); py::implicitly_convertible(); diff --git a/python_bindings/stub/PyStubImpl.cpp b/python_bindings/stub/PyStubImpl.cpp index 223935a8d3e1..8cf8c89739a8 100644 --- a/python_bindings/stub/PyStubImpl.cpp +++ b/python_bindings/stub/PyStubImpl.cpp @@ -253,8 +253,8 @@ py::object call_impl(const GeneratorFactory &factory, void pystub_init(pybind11::module &m, const GeneratorFactory &factory) { m.def( "call", [factory](const py::args &args, const py::kwargs &kwargs) -> py::object { - return call_impl(factory, args, kwargs); - }); + return call_impl(factory, args, kwargs); + }); } } // namespace diff --git a/src/Associativity.cpp b/src/Associativity.cpp index bd67f0245af6..6a1023893c40 100644 --- a/src/Associativity.cpp +++ b/src/Associativity.cpp @@ -104,12 +104,12 @@ bool associative_op_pattern_match(const Expr &e, if (expr_match(op, e, result)) { debug(5) << "Found associative ops for " << e << " -> " << op << ":\n" << [&] { - std::stringstream ss; - for (const auto &[var, val] : result) { - ss << " " << var << " -> " << val << "\n"; - } - return ss.str(); - }(); + std::stringstream ss; + for (const auto &[var, val] : result) { + ss << " " << var << " -> " << val << "\n"; + } + return ss.str(); + }(); for (size_t i = 0; i < x_names.size(); ++i) { const auto &iter = result.find("x" + std::to_string(i)); diff --git a/src/AutoScheduleUtils.cpp b/src/AutoScheduleUtils.cpp index d2227f831462..a743ad75f8be 100644 --- a/src/AutoScheduleUtils.cpp +++ b/src/AutoScheduleUtils.cpp @@ -184,10 +184,10 @@ Expr perform_inline(Expr e, const map &env, if (!order.empty()) { std::sort(calls.begin(), calls.end(), [&order](const string &lhs, const string &rhs) { - const auto &iter_lhs = std::find(order.begin(), order.end(), lhs); - const auto &iter_rhs = std::find(order.begin(), order.end(), rhs); - return iter_lhs > iter_rhs; - }); + const auto &iter_lhs = std::find(order.begin(), order.end(), lhs); + const auto &iter_rhs = std::find(order.begin(), order.end(), rhs); + return iter_lhs > iter_rhs; + }); } // Check if any of the calls are in the set of functions to be inlined. diff --git a/src/BoundsInference.cpp b/src/BoundsInference.cpp index 72f45360b3b5..4a26e854641a 100644 --- a/src/BoundsInference.cpp +++ b/src/BoundsInference.cpp @@ -39,19 +39,19 @@ bool depends_on_bounds_inference(const Expr &e) { visit_with( e, [&](auto *, const Variable *var) { - if (ends_with(var->name, ".max") || - ends_with(var->name, ".min")) { - result = true; - } // - }, + if (ends_with(var->name, ".max") || + ends_with(var->name, ".min")) { + result = true; + } // + }, [&](auto *self, const Call *op) { - if (op->name == Call::buffer_get_min || - op->name == Call::buffer_get_max) { - result = true; - } else { - self->visit_base(op); - } // - }); + if (op->name == Call::buffer_get_min || + op->name == Call::buffer_get_max) { + result = true; + } else { + self->visit_base(op); + } // + }); return result; } @@ -135,11 +135,11 @@ size_t find_fused_group_index(const Function &producing_func, const vector> &fused_groups) { const auto &iter = std::find_if(fused_groups.begin(), fused_groups.end(), [&producing_func](const vector &group) { - return std::any_of(group.begin(), group.end(), - [&producing_func](const Function &f) { - return (f.name() == producing_func.name()); - }); - }); + return std::any_of(group.begin(), group.end(), + [&producing_func](const Function &f) { + return (f.name() == producing_func.name()); + }); + }); internal_assert(iter != fused_groups.end()); return iter - fused_groups.begin(); } @@ -301,8 +301,8 @@ class BoundsInference : public IRMutator { Expr cond_val = std::accumulate( predicates.begin(), predicates.end(), val, [](const auto &acc, const auto &pred) { - return Call::make(acc.type(), Call::if_then_else, {likely(pred), acc}, Call::PureIntrinsic); - }); + return Call::make(acc.type(), Call::if_then_else, {likely(pred), acc}, Call::PureIntrinsic); + }); result[i].emplace_back(const_true(), cond_val); } } diff --git a/src/Closure.cpp b/src/Closure.cpp index 00566127e322..83a23ee08b2f 100644 --- a/src/Closure.cpp +++ b/src/Closure.cpp @@ -125,8 +125,8 @@ Expr Closure::pack_into_struct() const { // memory. We don't actually rely on this, it's just nice to have. std::stable_sort(elements.begin(), elements.end(), [&](const Expr &a, const Expr &b) { - return a.type().bytes() > b.type().bytes(); - }); + return a.type().bytes() > b.type().bytes(); + }); Expr result = Call::make(Handle(), Call::make_struct, elements, Call::Intrinsic); @@ -142,12 +142,12 @@ Stmt Closure::unpack_from_struct(const Expr &e, const Stmt &s) const { Expr prototype = mutate_with(packed, [](auto *self, const Expr &e) { - if (!e.as()) { - return make_zero(e.type()); - } else { - return self->mutate_base(e); - } - }); + if (!e.as()) { + return make_zero(e.type()); + } else { + return self->mutate_base(e); + } + }); string prototype_name = unique_name("closure_prototype"); Expr prototype_var = Variable::make(Handle(), prototype_name); diff --git a/src/CodeGen_LLVM.cpp b/src/CodeGen_LLVM.cpp index 300dfa096a1e..a8793e542fa3 100644 --- a/src/CodeGen_LLVM.cpp +++ b/src/CodeGen_LLVM.cpp @@ -1182,40 +1182,40 @@ void CodeGen_LLVM::optimize_module() { // See https://bugs.llvm.org/show_bug.cgi?id=45244 pb.registerOptimizerLastEPCallback( [&](ModulePassManager &mpm, OptimizationLevel, ThinOrFullLTOPhase) { - mpm.addPass(RelLookupTableConverterPass()); - }); + mpm.addPass(RelLookupTableConverterPass()); + }); } if (get_target().has_feature(Target::SanitizerCoverage)) { pb.registerOptimizerLastEPCallback( [&](ModulePassManager &mpm, OptimizationLevel, ThinOrFullLTOPhase) { - SanitizerCoverageOptions sanitizercoverage_options; - // Mirror what -fsanitize=fuzzer-no-link would enable. - // See https://github.com/halide/Halide/issues/6528 - sanitizercoverage_options.CoverageType = SanitizerCoverageOptions::SCK_Edge; - sanitizercoverage_options.IndirectCalls = true; - sanitizercoverage_options.TraceCmp = true; - sanitizercoverage_options.Inline8bitCounters = true; - sanitizercoverage_options.PCTable = true; - // Due to TLS differences, stack depth tracking is only enabled on Linux - if (get_target().os == Target::OS::Linux) { - sanitizercoverage_options.StackDepth = true; - } - mpm.addPass(SanitizerCoveragePass(sanitizercoverage_options)); - }); + SanitizerCoverageOptions sanitizercoverage_options; + // Mirror what -fsanitize=fuzzer-no-link would enable. + // See https://github.com/halide/Halide/issues/6528 + sanitizercoverage_options.CoverageType = SanitizerCoverageOptions::SCK_Edge; + sanitizercoverage_options.IndirectCalls = true; + sanitizercoverage_options.TraceCmp = true; + sanitizercoverage_options.Inline8bitCounters = true; + sanitizercoverage_options.PCTable = true; + // Due to TLS differences, stack depth tracking is only enabled on Linux + if (get_target().os == Target::OS::Linux) { + sanitizercoverage_options.StackDepth = true; + } + mpm.addPass(SanitizerCoveragePass(sanitizercoverage_options)); + }); } if (get_target().has_feature(Target::ASAN)) { pb.registerPipelineStartEPCallback( [](ModulePassManager &mpm, OptimizationLevel) { - AddressSanitizerOptions asan_options; // default values are good... - asan_options.UseAfterScope = true; // ...except this one - constexpr bool use_global_gc = false; - constexpr bool use_odr_indicator = true; - constexpr auto destructor_kind = AsanDtorKind::Global; - mpm.addPass(AddressSanitizerPass( - asan_options, use_global_gc, use_odr_indicator, destructor_kind)); - }); + AddressSanitizerOptions asan_options; // default values are good... + asan_options.UseAfterScope = true; // ...except this one + constexpr bool use_global_gc = false; + constexpr bool use_odr_indicator = true; + constexpr auto destructor_kind = AsanDtorKind::Global; + mpm.addPass(AddressSanitizerPass( + asan_options, use_global_gc, use_odr_indicator, destructor_kind)); + }); } // Target::MSAN handling is sprinkled throughout the codebase, @@ -1224,9 +1224,9 @@ void CodeGen_LLVM::optimize_module() { if (get_target().has_feature(Target::TSAN)) { pb.registerOptimizerLastEPCallback( [](ModulePassManager &mpm, OptimizationLevel, ThinOrFullLTOPhase) { - mpm.addPass( - createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); - }); + mpm.addPass( + createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); + }); } for (auto &function : *module) { diff --git a/src/Elf.cpp b/src/Elf.cpp index 05e40b1705a6..5af39416cd01 100644 --- a/src/Elf.cpp +++ b/src/Elf.cpp @@ -766,8 +766,8 @@ std::vector write_shared_object_internal(Object &obj, Linker *linker, cons std::vector> sorted_symbols(symbols.begin(), symbols.end()); std::sort(sorted_symbols.begin(), sorted_symbols.end(), [&](const auto &lhs, const auto &rhs) { - return lhs.first->get_name() < rhs.first->get_name(); - }); + return lhs.first->get_name() < rhs.first->get_name(); + }); std::map symbol_idxs; uint64_t local_count = 0; diff --git a/src/Function.cpp b/src/Function.cpp index 54fe96f785f2..fa6fbda4fc32 100644 --- a/src/Function.cpp +++ b/src/Function.cpp @@ -1259,25 +1259,25 @@ Function &Function::substitute_calls(const map &substi // Replace all calls to functions listed in 'substitutions' with their wrappers. auto m = LambdaMutator{ [&](auto *self, const Call *c) { - Expr expr = self->visit_base(c); - c = expr.as(); - internal_assert(c); - - if ((c->call_type == Call::Halide) && - c->func.defined() && - substitutions.count(c->func)) { - auto it = substitutions.find(c->func); - internal_assert(it != substitutions.end()) - << "Function not in environment: " << c->func->name << "\n"; - FunctionPtr subs = it->second; - debug(4) << "...Replace call to Func \"" << c->name << "\" with " - << "\"" << subs->name << "\"\n"; - expr = Call::make(c->type, subs->name, c->args, c->call_type, - subs, c->value_index, - c->image, c->param); - } - return expr; - }}; + Expr expr = self->visit_base(c); + c = expr.as(); + internal_assert(c); + + if ((c->call_type == Call::Halide) && + c->func.defined() && + substitutions.count(c->func)) { + auto it = substitutions.find(c->func); + internal_assert(it != substitutions.end()) + << "Function not in environment: " << c->func->name << "\n"; + FunctionPtr subs = it->second; + debug(4) << "...Replace call to Func \"" << c->name << "\" with " + << "\"" << subs->name << "\"\n"; + expr = Call::make(c->type, subs->name, c->args, c->call_type, + subs, c->value_index, + c->image, c->param); + } + return expr; + }}; contents->mutate(&m); return *this; diff --git a/src/FuseGPUThreadLoops.cpp b/src/FuseGPUThreadLoops.cpp index 88f9a542550f..7ac1eb53c35c 100644 --- a/src/FuseGPUThreadLoops.cpp +++ b/src/FuseGPUThreadLoops.cpp @@ -681,13 +681,13 @@ class ExtractSharedAndHeapAllocations : public IRMutator { // then sort based on the ascending order of the max liveness stage. sort(allocations.begin(), allocations.end(), [](const SharedAllocation &lhs, const SharedAllocation &rhs) { - if (lhs.liveness.min < rhs.liveness.min) { - return true; - } else if (lhs.liveness.min == rhs.liveness.min) { - return lhs.liveness.max < rhs.liveness.max; - } - return false; - }); + if (lhs.liveness.min < rhs.liveness.min) { + return true; + } else if (lhs.liveness.min == rhs.liveness.min) { + return lhs.liveness.max < rhs.liveness.max; + } + return false; + }); vector mem_allocs; vector free_spaces; // Contains index to free spaces in mem_allocs @@ -777,8 +777,8 @@ class ExtractSharedAndHeapAllocations : public IRMutator { // to the widest type. sort(mem_allocs.begin(), mem_allocs.end(), [](const AllocGroup &lhs, const AllocGroup &rhs) { - return lhs.widest_type.bytes() > rhs.widest_type.bytes(); - }); + return lhs.widest_type.bytes() > rhs.widest_type.bytes(); + }); for (const auto &alloc : mem_allocs) { Type t = may_merge_allocs_of_different_type ? UInt(8) : alloc.widest_type; diff --git a/src/HexagonOptimize.cpp b/src/HexagonOptimize.cpp index dfb49f9696b8..895e2b800c3e 100644 --- a/src/HexagonOptimize.cpp +++ b/src/HexagonOptimize.cpp @@ -521,8 +521,8 @@ class OptimizePatterns : public IRMutator { } std::stable_sort(mpys.begin(), mpys.end(), [](const MulExpr &m1, const MulExpr &m2) { - return m1.first.as()->slice_begin() < m2.first.as()->slice_begin(); - }); + return m1.first.as()->slice_begin() < m2.first.as()->slice_begin(); + }); return; } else if (const Load *first_load = mpys[0].first.as()) { const Ramp *first_ramp = first_load->index.as(); diff --git a/src/IROperator.cpp b/src/IROperator.cpp index c729539daa29..0c933ac381e1 100644 --- a/src/IROperator.cpp +++ b/src/IROperator.cpp @@ -1065,11 +1065,11 @@ T remove_intrinsics(const T &e, const std::initializer_list & return mutate_with( e, [&](auto *self, const Call *op) { - if (op->is_intrinsic(ops)) { - return self->mutate(op->args[0]); - } - return self->visit_base(op); - }); + if (op->is_intrinsic(ops)) { + return self->mutate(op->args[0]); + } + return self->visit_base(op); + }); } } // namespace diff --git a/src/InjectHostDevBufferCopies.cpp b/src/InjectHostDevBufferCopies.cpp index 4a899ee61fd6..6d67be0314a7 100644 --- a/src/InjectHostDevBufferCopies.cpp +++ b/src/InjectHostDevBufferCopies.cpp @@ -569,13 +569,13 @@ class InjectBufferCopies : public IRMutator { body = mutate_with( body, [&](auto *self, const Stmt &op) { - if (op.same_as(last_use)) { - internal_assert(!success); - success = true; - return Block::make(last_use, free_stmt); - } - return self->mutate_base(op); - }); + if (op.same_as(last_use)) { + internal_assert(!success); + success = true; + return Block::make(last_use, free_stmt); + } + return self->mutate_base(op); + }); internal_assert(success); return body; } diff --git a/src/LICM.cpp b/src/LICM.cpp index ca5fcec3bd8b..66fa3ccd9036 100644 --- a/src/LICM.cpp +++ b/src/LICM.cpp @@ -399,8 +399,8 @@ class GroupLoopInvariants : public IRMutator { // likely already in a good order, so don't mess with them. std::stable_sort(terms.begin(), terms.end(), [](const Term &a, const Term &b) { - return a.depth > b.depth; - }); + return a.depth > b.depth; + }); return terms; } diff --git a/src/OffloadGPULoops.cpp b/src/OffloadGPULoops.cpp index 11b8c3ccecf3..fac4f4a43927 100644 --- a/src/OffloadGPULoops.cpp +++ b/src/OffloadGPULoops.cpp @@ -152,20 +152,20 @@ class InjectGpuOffload : public IRMutator { // which passes the scalar args as a struct. sort(closure_args.begin(), closure_args.end(), [](const DeviceArgument &a, const DeviceArgument &b) { - if (a.is_buffer == b.is_buffer) { - return a.type.bits() > b.type.bits(); - } else { - // Ensure that buffer arguments come first: - // for some GPU systems, the - // legal indices for buffer args are much - // more restrictive than for scalar args, - // and scalar args can be 'grown' by - // LICM. Putting buffers first makes it much - // more likely we won't fail on some - // hardware. - return a.is_buffer > b.is_buffer; - } - }); + if (a.is_buffer == b.is_buffer) { + return a.type.bits() > b.type.bits(); + } else { + // Ensure that buffer arguments come first: + // for some GPU systems, the + // legal indices for buffer args are much + // more restrictive than for scalar args, + // and scalar args can be 'grown' by + // LICM. Putting buffers first makes it much + // more likely we won't fail on some + // hardware. + return a.is_buffer > b.is_buffer; + } + }); // compile the kernel string kernel_name = c_print_name(unique_name("kernel_" + loop->name)); diff --git a/src/RealizationOrder.cpp b/src/RealizationOrder.cpp index a7f4f8ab7dec..9475759b2c7b 100644 --- a/src/RealizationOrder.cpp +++ b/src/RealizationOrder.cpp @@ -188,8 +188,8 @@ void check_no_cyclic_compute_with(const map> &fused_pa } const auto &it = std::find_if(o_iter->second.begin(), o_iter->second.end(), [&pair](const FusedPair &other) { - return (pair.func_1 == other.func_2) && (pair.func_2 == other.func_1); - }); + return (pair.func_1 == other.func_2) && (pair.func_2 == other.func_1); + }); user_assert(it == o_iter->second.end()) << "Found cyclic dependencies between compute_with of " << pair.func_1 << " and " << pair.func_2 << "\n"; @@ -403,10 +403,10 @@ pair, vector>> realization_order( for (auto &group : group_order) { std::sort(group.begin(), group.end(), [&](const string &lhs, const string &rhs) { - const auto &iter_lhs = std::find(temp.begin(), temp.end(), lhs); - const auto &iter_rhs = std::find(temp.begin(), temp.end(), rhs); - return iter_lhs < iter_rhs; - }); + const auto &iter_lhs = std::find(temp.begin(), temp.end(), lhs); + const auto &iter_rhs = std::find(temp.begin(), temp.end(), rhs); + return iter_lhs < iter_rhs; + }); } // Collect the realization order of all functions within the pipeline. diff --git a/src/ScheduleFunctions.cpp b/src/ScheduleFunctions.cpp index 1a9e0858c4d6..ef423a9e9464 100644 --- a/src/ScheduleFunctions.cpp +++ b/src/ScheduleFunctions.cpp @@ -1435,8 +1435,8 @@ class InjectFunctionRealization : public IRMutator { { const auto &iter = std::find_if(dims.begin(), dims.end(), [&fuse_level](const Dim &d) { - return var_name_match(d.var, fuse_level.var().name()); - }); + return var_name_match(d.var, fuse_level.var().name()); + }); internal_assert(iter != dims.end()); start_fuse = (int)(iter - dims.begin()); } @@ -1502,8 +1502,8 @@ class InjectFunctionRealization : public IRMutator { if (!fuse_level.is_inlined() && !fuse_level.is_root()) { const auto &iter = std::find_if(dims.begin(), dims.end(), [&fuse_level](const Dim &d) { - return var_name_match(d.var, fuse_level.var().name()); - }); + return var_name_match(d.var, fuse_level.var().name()); + }); internal_assert(iter != dims.end()); start_fuse = (size_t)(iter - dims.begin()); } @@ -2453,8 +2453,8 @@ void validate_fused_group_schedule_helper(const string &fn, const auto &iter_1 = std::find_if(dims_1.begin(), dims_1.end(), [&p](const Dim &d) { - return var_name_match(d.var, p.var_name); - }); + return var_name_match(d.var, p.var_name); + }); user_assert(iter_1 != dims_1.end()) << "Invalid compute_with: cannot find " << p.var_name << " in " << p.func_1 << ".s" << p.stage_1 << "\n"; @@ -2462,8 +2462,8 @@ void validate_fused_group_schedule_helper(const string &fn, const auto &iter_2 = std::find_if(dims_2.begin(), dims_2.end(), [&p](const Dim &d) { - return var_name_match(d.var, p.var_name); - }); + return var_name_match(d.var, p.var_name); + }); user_assert(iter_2 != dims_2.end()) << "Invalid compute_with: cannot find " << p.var_name << " in " << p.func_2 << ".s" << p.stage_2 << "\n"; diff --git a/src/Simplify_Call.cpp b/src/Simplify_Call.cpp index 593d05530cbd..8f22d671a641 100644 --- a/src/Simplify_Call.cpp +++ b/src/Simplify_Call.cpp @@ -794,10 +794,10 @@ Expr Simplify::visit(const Call *op, ExprInfo *info) { {"ceil_f32", std::ceil}, {"floor_f32", std::floor}, {Call::get_intrinsic_name(Call::round), [](double a) -> double { - std::fesetround(FE_TONEAREST); - a = std::nearbyint(a); - return a; - }}, + std::fesetround(FE_TONEAREST); + a = std::nearbyint(a); + return a; + }}, {"trunc_f32", std::trunc}, }; auto it = pure_externs_truncation.find(op->name); diff --git a/src/SkipStages.cpp b/src/SkipStages.cpp index 7fa3e05dd99b..cf8715b39353 100644 --- a/src/SkipStages.cpp +++ b/src/SkipStages.cpp @@ -452,11 +452,11 @@ class SkipStages : public IRMutator { Expr relaxed = mutate_with(e, [&](auto *self, const Call *op) { - if (op->call_type == Call::Halide && op->name == func) { - return cast(op->type, var); - } - return self->visit_base(op); - }); + if (op->call_type == Call::Halide && op->name == func) { + return cast(op->type, var); + } + return self->visit_base(op); + }); return relax_over_var(relaxed, var_name); } @@ -843,25 +843,25 @@ Stmt skip_stages(const Stmt &stmt, // We want to run this pass starting at the skip stages marker return mutate_with(stmt, // [&](auto *self, const Block *op) { - const Evaluate *eval = op->first.as(); - const Call *call = eval ? eval->value.as() : nullptr; - if (call && call->is_intrinsic(Call::skip_stages_marker)) { - return run_pass(op->rest); - } else { - return self->visit_base(op); - } // - }, + const Evaluate *eval = op->first.as(); + const Call *call = eval ? eval->value.as() : nullptr; + if (call && call->is_intrinsic(Call::skip_stages_marker)) { + return run_pass(op->rest); + } else { + return self->visit_base(op); + } // + }, [&](auto *self, const Evaluate *eval) { - // It's technically possible that *nothing* - // follows the skip stages marker, if the - // pipeline is a no-op, in which case we just drop the marker. - if (const Call *call = eval->value.as(); - call && call->is_intrinsic(Call::skip_stages_marker)) { - return Evaluate::make(0); - } else { - return self->visit_base(eval); - } // - }); + // It's technically possible that *nothing* + // follows the skip stages marker, if the + // pipeline is a no-op, in which case we just drop the marker. + if (const Call *call = eval->value.as(); + call && call->is_intrinsic(Call::skip_stages_marker)) { + return Evaluate::make(0); + } else { + return self->visit_base(eval); + } // + }); } } // namespace Internal diff --git a/src/StageStridedLoads.cpp b/src/StageStridedLoads.cpp index 5073d6194522..4084fbf7c6be 100644 --- a/src/StageStridedLoads.cpp +++ b/src/StageStridedLoads.cpp @@ -219,27 +219,27 @@ const IRNode *innermost_containing_node(const IRNode *root, const std::setmutate_base(s); - if (old == 0 && seen > best) { - result = s.get(); - best = seen; - } - return s; // - }, + int old = seen; + self->mutate_base(s); + if (old == 0 && seen > best) { + result = s.get(); + best = seen; + } + return s; // + }, [&](auto *self, const Expr &e) { - int old = seen; - const Load *l = e.as(); - if (l && exprs.count(l)) { - seen++; - }; - self->mutate_base(e); - if (old == 0 && seen > best) { - result = e.get(); - best = seen; - } - return e; // - }); + int old = seen; + const Load *l = e.as(); + if (l && exprs.count(l)) { + seen++; + }; + self->mutate_base(e); + if (old == 0 && seen > best) { + result = e.get(); + best = seen; + } + return e; // + }); internal_assert(seen) << "None of the exprs were found\n"; return result; } @@ -252,32 +252,32 @@ bool can_hoist_shared_load(const IRNode *n, const std::string &buf, const Expr & bool result = true; visit_with(n, // [&](auto *self, const Let *let) { // - result &= !expr_uses_var(idx, let->name); - self->visit_base(let); - }, + result &= !expr_uses_var(idx, let->name); + self->visit_base(let); + }, [&](auto *self, const LetStmt *let) { // - result &= !expr_uses_var(idx, let->name); - self->visit_base(let); - }, + result &= !expr_uses_var(idx, let->name); + self->visit_base(let); + }, [&](auto *self, const For *loop) { // - result &= !expr_uses_var(idx, loop->name); - self->visit_base(loop); - }, + result &= !expr_uses_var(idx, loop->name); + self->visit_base(loop); + }, [&](auto *self, const Allocate *alloc) { // - result &= alloc->name != buf; - self->visit_base(alloc); - }, + result &= alloc->name != buf; + self->visit_base(alloc); + }, [&](auto *self, const Store *store) { // - result &= store->name != buf; - self->visit_base(store); - }, + result &= store->name != buf; + self->visit_base(store); + }, [&](auto *self, const AssertStmt *a) { // - // Extern stages always come with asserts, even when - // no_asserts is on (they get stripped later), so this also - // guards against writes to the buffer happening in an extern - // stage. copy_to_host/device calls also come with asserts. - result = false; - }); + // Extern stages always come with asserts, even when + // no_asserts is on (they get stripped later), so this also + // guards against writes to the buffer happening in an extern + // stage. copy_to_host/device calls also come with asserts. + result = false; + }); return result; } diff --git a/src/StorageFlattening.cpp b/src/StorageFlattening.cpp index 4fbf1fb1f036..cee4b38e8133 100644 --- a/src/StorageFlattening.cpp +++ b/src/StorageFlattening.cpp @@ -452,14 +452,14 @@ class HoistStorage : public IRMutator { Expr result = mutate_with( e, [&](auto *self, const Variable *var) -> Expr { - if (const Expr *value = scope.find(var->name)) { - // Mutate the expression, so lets can get replaced recursively. - Expr expr = self->mutate(*value); - debug(4) << "Fully expanded " << var->name << " -> " << expr << "\n"; - return expr; - } - return var; - }); + if (const Expr *value = scope.find(var->name)) { + // Mutate the expression, so lets can get replaced recursively. + Expr expr = self->mutate(*value); + debug(4) << "Fully expanded " << var->name << " -> " << expr << "\n"; + return expr; + } + return var; + }); debug(4) << "Expanded " << e << " into " << result << "\n"; return result; } diff --git a/src/Tracing.cpp b/src/Tracing.cpp index 0bc9086d8635..3556ccaad986 100644 --- a/src/Tracing.cpp +++ b/src/Tracing.cpp @@ -412,49 +412,49 @@ Stmt inject_tracing(Stmt s, const string &pipeline_name, bool trace_pipeline, const string &func_name, const vector &func_types // ) { - Expr space = Expr(" "); + Expr space = Expr(" "); - vector strings; - strings.emplace_back("func_type_and_dim:"); + vector strings; + strings.emplace_back("func_type_and_dim:"); + strings.push_back(space); + strings.emplace_back((int)func_types.size()); + for (const auto &func_type : func_types) { strings.push_back(space); - strings.emplace_back((int)func_types.size()); - for (const auto &func_type : func_types) { + strings.emplace_back((int)func_type.code()); + strings.push_back(space); + strings.emplace_back(func_type.bits()); + strings.push_back(space); + strings.emplace_back(func_type.lanes()); + } + auto it = bt.find(func_name); + internal_assert(it != bt.end()); + const Box &box = it->second; + strings.push_back(space); + strings.emplace_back((int)box.bounds.size()); + for (const Interval &i : box.bounds) { + internal_assert(i.min.defined() && i.max.defined()); + if (i.is_bounded()) { strings.push_back(space); - strings.emplace_back((int)func_type.code()); + strings.push_back(i.min); strings.push_back(space); - strings.emplace_back(func_type.bits()); + // Emit as (min, extent) rather than (min, max) + strings.push_back(i.max - i.min + Expr(1)); + } else { + // This should really only happen for unusual cases + // that we won't end up realizing, so we can just + // use any numeric values. strings.push_back(space); - strings.emplace_back(func_type.lanes()); - } - auto it = bt.find(func_name); - internal_assert(it != bt.end()); - const Box &box = it->second; - strings.push_back(space); - strings.emplace_back((int)box.bounds.size()); - for (const Interval &i : box.bounds) { - internal_assert(i.min.defined() && i.max.defined()); - if (i.is_bounded()) { - strings.push_back(space); - strings.push_back(i.min); - strings.push_back(space); - // Emit as (min, extent) rather than (min, max) - strings.push_back(i.max - i.min + Expr(1)); - } else { - // This should really only happen for unusual cases - // that we won't end up realizing, so we can just - // use any numeric values. - strings.push_back(space); - strings.emplace_back(0); - strings.push_back(space); - strings.emplace_back(0); - } + strings.emplace_back(0); + strings.push_back(space); + strings.emplace_back(0); } + } - builder.func = func_name; - builder.trace_tag_expr = - Call::make(type_of(), Call::stringify, strings, Call::PureIntrinsic); - return Block::make(Evaluate::make(builder.build()), std::move(s)); - }; + builder.func = func_name; + builder.trace_tag_expr = + Call::make(type_of(), Call::stringify, strings, Call::PureIntrinsic); + return Block::make(Evaluate::make(builder.build()), std::move(s)); + }; for (const auto &o : reverse_view(order)) { if (auto p = tracing.funcs_touched.find(o); p != tracing.funcs_touched.end()) { diff --git a/src/WasmExecutor.cpp b/src/WasmExecutor.cpp index 69fcfc16b139..b9b3e5284f5e 100644 --- a/src/WasmExecutor.cpp +++ b/src/WasmExecutor.cpp @@ -2341,11 +2341,10 @@ WasmModuleContents::WasmModuleContents( debug(2) << "Disassembly:\n" << [&] { - wabt::MemoryStream dis_stream; - module_desc.istream.Disassemble(&dis_stream); - return to_string(dis_stream); - }() - << "\n"; + wabt::MemoryStream dis_stream; + module_desc.istream.Disassemble(&dis_stream); + return to_string(dis_stream); + }() << "\n"; module = wabt::interp::Module::New(store, module_desc); diff --git a/src/autoschedulers/adams2019/AutoSchedule.cpp b/src/autoschedulers/adams2019/AutoSchedule.cpp index f1f1c0ba5ad8..97c7339f7e43 100644 --- a/src/autoschedulers/adams2019/AutoSchedule.cpp +++ b/src/autoschedulers/adams2019/AutoSchedule.cpp @@ -251,19 +251,19 @@ IntrusivePtr optimal_schedule_pass(FunctionDAG &dag, std::function &&)> enqueue_new_children = [&](IntrusivePtr &&s) { - // Each child should have one more decision made than its parent state. - internal_assert(s->num_decisions_made == s->parent->num_decisions_made + 1); + // Each child should have one more decision made than its parent state. + internal_assert(s->num_decisions_made == s->parent->num_decisions_made + 1); - int progress = s->num_decisions_made * params.beam_size + expanded; - size_t max_progress = dag.nodes.size() * params.beam_size * 2; + int progress = s->num_decisions_made * params.beam_size + expanded; + size_t max_progress = dag.nodes.size() * params.beam_size * 2; - // Update the progress bar - tick.set(double(progress) / max_progress); - s->penalized = false; + // Update the progress bar + tick.set(double(progress) / max_progress); + s->penalized = false; - // Add the state to the list of states to evaluate - q.emplace(std::move(s)); - }; + // Add the state to the list of states to evaluate + q.emplace(std::move(s)); + }; #ifdef HALIDE_AUTOSCHEDULER_ALLOW_CYOS string cyos_str = get_env_variable("HL_CYOS"); diff --git a/src/autoschedulers/adams2019/LoopNest.cpp b/src/autoschedulers/adams2019/LoopNest.cpp index 098273adc4ff..44a2ad8540a8 100644 --- a/src/autoschedulers/adams2019/LoopNest.cpp +++ b/src/autoschedulers/adams2019/LoopNest.cpp @@ -1869,8 +1869,8 @@ void LoopNest::apply(LoopLevel here, // TODO: 16 should be the number of vector registers in the architecture std::stable_sort(state.vars.begin(), state.vars.begin() + symbolic_loop.size(), [](const StageScheduleState::FuncVar &a, const StageScheduleState::FuncVar &b) { - return a.pure && !b.pure; - }); + return a.pure && !b.pure; + }); for (size_t i = 0; i < symbolic_loop.size(); i++) { if (state.vars[i].pure && state.vars[i].exists && state.vars[i].extent > 1) { diff --git a/src/autoschedulers/anderson2021/LoopNest.cpp b/src/autoschedulers/anderson2021/LoopNest.cpp index 833830683ba6..5077c5653420 100644 --- a/src/autoschedulers/anderson2021/LoopNest.cpp +++ b/src/autoschedulers/anderson2021/LoopNest.cpp @@ -4117,8 +4117,8 @@ void LoopNest::apply(LoopLevel here, // There's a hope we can fit anything compute-at this level into registers if we fully unroll std::stable_sort(state.vars.begin(), state.vars.begin() + symbolic_loop.size(), [](const StageScheduleState::FuncVar &a, const StageScheduleState::FuncVar &b) { - return a.pure && !b.pure; - }); + return a.pure && !b.pure; + }); for (size_t i = 0; i < symbolic_loop.size(); i++) { if (state.vars[i].pure && state.vars[i].exists && state.vars[i].extent > 1) { diff --git a/src/autoschedulers/mullapudi2016/AutoSchedule.cpp b/src/autoschedulers/mullapudi2016/AutoSchedule.cpp index 9005999bf1a8..19f7bd962407 100644 --- a/src/autoschedulers/mullapudi2016/AutoSchedule.cpp +++ b/src/autoschedulers/mullapudi2016/AutoSchedule.cpp @@ -1002,8 +1002,8 @@ class GPUTileHelper { const auto &y = vars.back(); const auto tail_strategy = std::any_of( vars.begin(), vars.end(), [](const auto &v) { - return v.strategy == TailStrategy::GuardWithIf; - }) ? + return v.strategy == TailStrategy::GuardWithIf; + }) ? TailStrategy::GuardWithIf : TailStrategy::Auto; @@ -1037,8 +1037,8 @@ class GPUTileHelper { const auto tail_strategy = std::any_of( vars.begin(), vars.end(), [](const auto &v) { - return v.strategy == TailStrategy::GuardWithIf; - }) ? + return v.strategy == TailStrategy::GuardWithIf; + }) ? TailStrategy::GuardWithIf : TailStrategy::Auto; @@ -1328,8 +1328,8 @@ class GPUTilingDedup { const auto findItem = [&](const VarOrRVar &v) { return std::find_if(ordering.begin(), ordering.end(), [v_name = v.name()](const VarOrRVar &item) { - return item.name() == v_name; - }); + return item.name() == v_name; + }); }; auto inner_iter = findItem(inner); @@ -3769,9 +3769,9 @@ void validate_no_partial_schedules(const Function &f, bool is_output) { const auto &iter = std::find_if(args.begin(), args.end(), [&d](const Expr &arg) { - const Variable *v = arg.as(); - return (d.var == v->name); - }); + const Variable *v = arg.as(); + return (d.var == v->name); + }); internal_assert(iter != args.end()); int current_index = iter - args.begin(); user_assert(current_index > last_index) diff --git a/src/runtime/webgpu.cpp b/src/runtime/webgpu.cpp index b57113db3d0e..b1ed90723d46 100644 --- a/src/runtime/webgpu.cpp +++ b/src/runtime/webgpu.cpp @@ -472,10 +472,10 @@ WEAK int halide_webgpu_device_sync(void *user_context, halide_buffer_t *) { wgpuQueueOnSubmittedWorkDone( context.queue, [](WGPUQueueWorkDoneStatus status, void *userdata) { - WorkDoneResult *result = (WorkDoneResult *)userdata; - result->status = status; - __atomic_clear(&result->complete, __ATOMIC_RELEASE); - }, + WorkDoneResult *result = (WorkDoneResult *)userdata; + result->status = status; + __atomic_clear(&result->complete, __ATOMIC_RELEASE); + }, &result); int error_code = error_scope.wait(); @@ -583,10 +583,10 @@ int do_copy_to_host(void *user_context, WgpuContext *context, uint8_t *dst, wgpuBufferMapAsync( context->staging_buffer, WGPUMapMode_Read, 0, num_bytes, [](WGPUBufferMapAsyncStatus status, void *userdata) { - BufferMapResult *result = (BufferMapResult *)userdata; - result->map_status = status; - __atomic_clear(&result->map_complete, __ATOMIC_RELEASE); - }, + BufferMapResult *result = (BufferMapResult *)userdata; + result->map_status = status; + __atomic_clear(&result->map_complete, __ATOMIC_RELEASE); + }, &result); while (__atomic_test_and_set(&result.map_complete, __ATOMIC_ACQUIRE)) { @@ -837,25 +837,25 @@ WEAK int halide_webgpu_initialize_kernels(void *user_context, void **state_ptr, if (!shader_cache.kernel_state_setup( user_context, state_ptr, context.device, shader_module, [&]() -> WGPUShaderModule { - ErrorScope error_scope(user_context, context.device); - - WGPUShaderModuleWGSLDescriptor wgsl_desc{}; - wgsl_desc.chain.next = nullptr; - wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; - wgsl_desc.code = src; - WGPUShaderModuleDescriptor desc{}; - desc.nextInChain = (const WGPUChainedStruct *)(&wgsl_desc); - desc.label = nullptr; - WGPUShaderModule shader_module = - wgpuDeviceCreateShaderModule(context.device, &desc); - - int error_code = error_scope.wait(); - if (error_code != halide_error_code_success) { - return nullptr; // from the lambda - } + ErrorScope error_scope(user_context, context.device); + + WGPUShaderModuleWGSLDescriptor wgsl_desc{}; + wgsl_desc.chain.next = nullptr; + wgsl_desc.chain.sType = WGPUSType_ShaderModuleWGSLDescriptor; + wgsl_desc.code = src; + WGPUShaderModuleDescriptor desc{}; + desc.nextInChain = (const WGPUChainedStruct *)(&wgsl_desc); + desc.label = nullptr; + WGPUShaderModule shader_module = + wgpuDeviceCreateShaderModule(context.device, &desc); + + int error_code = error_scope.wait(); + if (error_code != halide_error_code_success) { + return nullptr; // from the lambda + } - return shader_module; - })) { + return shader_module; + })) { return halide_error_code_generic_error; } halide_abort_if_false(user_context, shader_module != nullptr); diff --git a/test/common/check_call_graphs.h b/test/common/check_call_graphs.h index 3051dba85123..54a07cfb9815 100644 --- a/test/common/check_call_graphs.h +++ b/test/common/check_call_graphs.h @@ -74,13 +74,13 @@ inline int check_call_graphs(Halide::Pipeline p, CallGraphs &expected) { std::string expected_str = std::accumulate( expected_callees.begin(), expected_callees.end(), std::string{}, [](const std::string &a, const std::string &b) { - return a.empty() ? b : a + ", " + b; - }); + return a.empty() ? b : a + ", " + b; + }); std::string result_str = std::accumulate( result_callees.begin(), result_callees.end(), std::string{}, [](const std::string &a, const std::string &b) { - return a.empty() ? b : a + ", " + b; - }); + return a.empty() ? b : a + ", " + b; + }); printf("Expect callees of %s to be (%s); got (%s) instead\n", iter.first.c_str(), expected_str.c_str(), result_str.c_str()); diff --git a/test/correctness/halide_buffer.cpp b/test/correctness/halide_buffer.cpp index accaf6f6bb3e..392156aced65 100644 --- a/test/correctness/halide_buffer.cpp +++ b/test/correctness/halide_buffer.cpp @@ -276,8 +276,7 @@ int main(int argc, char **argv) { }); a.for_each_value([&](float &a, float b) { a = 2 * b; - }, - b); + }, b); if (counter != W * H * C) { printf("for_each_value didn't hit every element\n"); @@ -416,8 +415,7 @@ int main(int argc, char **argv) { a.for_each_value([&](int a_value, const int &b_value, int &c_value_ref) { counter += 1; c_value_ref = 1; - }, - b, c); + }, b, c); assert(counter == 5 * 4 * 3); assert(a.all_equal(0)); assert(b.all_equal(0)); @@ -427,8 +425,7 @@ int main(int argc, char **argv) { c.for_each_value([&](int &c_value_ref, const int &b_value, int a_value) { counter += 1; c_value_ref = 2; - }, - b, a); + }, b, a); assert(counter == 5 * 4 * 3); assert(a.all_equal(0)); assert(b.all_equal(0)); @@ -438,8 +435,7 @@ int main(int argc, char **argv) { a_const.for_each_value([&](int a_value, const int &b_value, int &c_value_ref) { counter += 1; c_value_ref = 1; - }, - b_const, c); + }, b_const, c); assert(counter == 5 * 4 * 3); assert(a.all_equal(0)); assert(b.all_equal(0)); @@ -449,8 +445,7 @@ int main(int argc, char **argv) { c.for_each_value([&](int &c_value_ref, const int &b_value, int a_value) { counter += 1; c_value_ref = 2; - }, - b_const, a_const); + }, b_const, a_const); assert(counter == 5 * 4 * 3); assert(a.all_equal(0)); assert(b.all_equal(0)); diff --git a/test/correctness/random_expr_generator.h b/test/correctness/random_expr_generator.h index afde4ab4bbcc..6349ab6d02cb 100644 --- a/test/correctness/random_expr_generator.h +++ b/test/correctness/random_expr_generator.h @@ -241,11 +241,11 @@ class RandomExpressionGenerator { // Select ops.push_back( [&]() -> Expr { - auto c = random_condition(rng, t, depth, true); - auto e1 = random_expr(rng, t, depth, overflow_undef); - auto e2 = random_expr(rng, t, depth, overflow_undef); - return select(c, e1, e2); - }); + auto c = random_condition(rng, t, depth, true); + auto e1 = random_expr(rng, t, depth, overflow_undef); + auto e2 = random_expr(rng, t, depth, overflow_undef); + return select(c, e1, e2); + }); } // Cast if (gen_cast) { diff --git a/test/correctness/storage_folding.cpp b/test/correctness/storage_folding.cpp index c413dc73bcbb..cf95acb73594 100644 --- a/test/correctness/storage_folding.cpp +++ b/test/correctness/storage_folding.cpp @@ -61,15 +61,15 @@ extern "C" HALIDE_EXPORT_SYMBOL int zigzag_buffer_copy(halide_buffer_t *in, hali // An intentionally nasty mapping from y coords of the output to y coords of the input: auto coord_map = [](int y) { - // Reverse the bottom 8 bits - int new_y = y & ~255; - for (int i = 0; i < 8; i++) { - if (y & (7 - i)) { - new_y |= (1 << i); - } + // Reverse the bottom 8 bits + int new_y = y & ~255; + for (int i = 0; i < 8; i++) { + if (y & (7 - i)) { + new_y |= (1 << i); } - return new_y; - }; + } + return new_y; + }; // Just manually take a min/max over all scanlines of the output int in_y_min = coord_map(out->dim[1].min); diff --git a/test/fuzz/bounds.cpp b/test/fuzz/bounds.cpp index 2a42df653fb5..1ae692097314 100644 --- a/test/fuzz/bounds.cpp +++ b/test/fuzz/bounds.cpp @@ -110,95 +110,95 @@ Expr random_expr(FuzzingContext &fuzz, Type t, int depth, bool overflow_undef) { std::function operations[] = { [&]() { - return random_leaf(fuzz, t); - }, + return random_leaf(fuzz, t); + }, [&]() { - auto c = random_condition(fuzz, t, depth, true); - auto e1 = random_expr(fuzz, t, depth, overflow_undef); - auto e2 = random_expr(fuzz, t, depth, overflow_undef); - // Don't use Select::make: we want to use select() here to - // ensure that the condition and values match types. - return select(c, e1, e2); - }, + auto c = random_condition(fuzz, t, depth, true); + auto e1 = random_expr(fuzz, t, depth, overflow_undef); + auto e2 = random_expr(fuzz, t, depth, overflow_undef); + // Don't use Select::make: we want to use select() here to + // ensure that the condition and values match types. + return select(c, e1, e2); + }, [&]() { - if (t.lanes() != 1) { - int lanes = get_random_divisor(fuzz, t); - auto e1 = random_expr(fuzz, t.with_lanes(t.lanes() / lanes), depth, overflow_undef); - return Broadcast::make(e1, lanes); - } - // If we got here, try again. - return random_expr(fuzz, t, depth, overflow_undef); - }, + if (t.lanes() != 1) { + int lanes = get_random_divisor(fuzz, t); + auto e1 = random_expr(fuzz, t.with_lanes(t.lanes() / lanes), depth, overflow_undef); + return Broadcast::make(e1, lanes); + } + // If we got here, try again. + return random_expr(fuzz, t, depth, overflow_undef); + }, [&]() { - if (t.lanes() != 1) { - int lanes = get_random_divisor(fuzz, t); - auto e1 = random_expr(fuzz, t.with_lanes(t.lanes() / lanes), depth, overflow_undef); - auto e2 = random_expr(fuzz, t.with_lanes(t.lanes() / lanes), depth, overflow_undef); - return Ramp::make(e1, e2, lanes); - } - // If we got here, try again. - return random_expr(fuzz, t, depth, overflow_undef); - }, + if (t.lanes() != 1) { + int lanes = get_random_divisor(fuzz, t); + auto e1 = random_expr(fuzz, t.with_lanes(t.lanes() / lanes), depth, overflow_undef); + auto e2 = random_expr(fuzz, t.with_lanes(t.lanes() / lanes), depth, overflow_undef); + return Ramp::make(e1, e2, lanes); + } + // If we got here, try again. + return random_expr(fuzz, t, depth, overflow_undef); + }, [&]() { - if (t.is_bool()) { - auto e1 = random_expr(fuzz, t, depth); - return Not::make(e1); - } - // If we got here, try again. - return random_expr(fuzz, t, depth, overflow_undef); - }, + if (t.is_bool()) { + auto e1 = random_expr(fuzz, t, depth); + return Not::make(e1); + } + // If we got here, try again. + return random_expr(fuzz, t, depth, overflow_undef); + }, [&]() { - if (t.is_bool()) { - return random_condition(fuzz, random_type(fuzz, t.lanes()), depth, false); - } - // If we got here, try again. - return random_expr(fuzz, t, depth, overflow_undef); - }, + if (t.is_bool()) { + return random_condition(fuzz, random_type(fuzz, t.lanes()), depth, false); + } + // If we got here, try again. + return random_expr(fuzz, t, depth, overflow_undef); + }, [&]() { - // Get a random type that isn't t or int32 (int32 can overflow and we don't care about that). - // Note also that the FuzzingContext doesn't actually promise to return a random distribution -- - // it can (e.g.) decide to just return 0 for all data, forever -- so this loop has no guarantee - // of eventually finding a different type. To remedy this, we'll just put a limit on the retries. - int count = 0; - Type subtype; - do { - subtype = random_type(fuzz, t.lanes()); - } while (++count < 10 && (subtype == t || (subtype.is_int() && subtype.bits() == 32))); - auto e1 = random_expr(fuzz, subtype, depth, overflow_undef); - return Cast::make(t, e1); - }, + // Get a random type that isn't t or int32 (int32 can overflow and we don't care about that). + // Note also that the FuzzingContext doesn't actually promise to return a random distribution -- + // it can (e.g.) decide to just return 0 for all data, forever -- so this loop has no guarantee + // of eventually finding a different type. To remedy this, we'll just put a limit on the retries. + int count = 0; + Type subtype; + do { + subtype = random_type(fuzz, t.lanes()); + } while (++count < 10 && (subtype == t || (subtype.is_int() && subtype.bits() == 32))); + auto e1 = random_expr(fuzz, subtype, depth, overflow_undef); + return Cast::make(t, e1); + }, [&]() { - static make_bin_op_fn make_bin_op[] = { - // Arithmetic operations. - Add::make, - Sub::make, - Mul::make, - Min::make, - Max::make, - Div::make, - Mod::make, - }; - make_bin_op_fn maker = fuzz.PickValueInArray(make_bin_op); - Expr a = random_expr(fuzz, t, depth, overflow_undef); - Expr b = random_expr(fuzz, t, depth, overflow_undef); - return maker(a, b); - }, + static make_bin_op_fn make_bin_op[] = { + // Arithmetic operations. + Add::make, + Sub::make, + Mul::make, + Min::make, + Max::make, + Div::make, + Mod::make, + }; + make_bin_op_fn maker = fuzz.PickValueInArray(make_bin_op); + Expr a = random_expr(fuzz, t, depth, overflow_undef); + Expr b = random_expr(fuzz, t, depth, overflow_undef); + return maker(a, b); + }, [&]() { - static make_bin_op_fn make_bin_op[] = { - // Binary operations. - And::make, - Or::make, - }; - // Boolean operations -- both sides must be cast to booleans, - // and then we must cast the result back to 't'. - make_bin_op_fn maker = fuzz.PickValueInArray(make_bin_op); - Expr a = random_expr(fuzz, t, depth, overflow_undef); - Expr b = random_expr(fuzz, t, depth, overflow_undef); - Type bool_with_lanes = Bool(t.lanes()); - a = cast(bool_with_lanes, a); - b = cast(bool_with_lanes, b); - return cast(t, maker(a, b)); - }, + static make_bin_op_fn make_bin_op[] = { + // Binary operations. + And::make, + Or::make, + }; + // Boolean operations -- both sides must be cast to booleans, + // and then we must cast the result back to 't'. + make_bin_op_fn maker = fuzz.PickValueInArray(make_bin_op); + Expr a = random_expr(fuzz, t, depth, overflow_undef); + Expr b = random_expr(fuzz, t, depth, overflow_undef); + Type bool_with_lanes = Bool(t.lanes()); + a = cast(bool_with_lanes, a); + b = cast(bool_with_lanes, b); + return cast(t, maker(a, b)); + }, }; return fuzz.PickValueInArray(operations)(); } diff --git a/test/fuzz/cse.cpp b/test/fuzz/cse.cpp index 0c15b74e8921..8d75875fb7b4 100644 --- a/test/fuzz/cse.cpp +++ b/test/fuzz/cse.cpp @@ -28,47 +28,47 @@ Expr random_expr(FuzzingContext &fuzz, int depth, vector> &exprs } std::function build_next_expr[] = { [&]() { - // Can't use Var() here because that would require i32 values, - // which we are avoiding here because we don't want to end - // up with signed_integer_overflow() - return Variable::make(Int(16), "x"); - }, + // Can't use Var() here because that would require i32 values, + // which we are avoiding here because we don't want to end + // up with signed_integer_overflow() + return Variable::make(Int(16), "x"); + }, [&]() { - return Variable::make(Int(16), "y"); - }, + return Variable::make(Int(16), "y"); + }, [&]() { - return Variable::make(Int(16), "z"); - }, + return Variable::make(Int(16), "z"); + }, [&]() { - Expr next = random_expr(fuzz, depth - 1, exprs); - next += random_expr(fuzz, depth - 1, exprs); - return next; - }, + Expr next = random_expr(fuzz, depth - 1, exprs); + next += random_expr(fuzz, depth - 1, exprs); + return next; + }, [&]() { - Expr a = random_expr(fuzz, depth - 2, exprs); - Expr b = random_expr(fuzz, depth - 2, exprs); - Expr c = random_expr(fuzz, depth - 2, exprs); - Expr d = random_expr(fuzz, depth - 2, exprs); - return select(a > b, c, d); - }, + Expr a = random_expr(fuzz, depth - 2, exprs); + Expr b = random_expr(fuzz, depth - 2, exprs); + Expr c = random_expr(fuzz, depth - 2, exprs); + Expr d = random_expr(fuzz, depth - 2, exprs); + return select(a > b, c, d); + }, [&]() { - Expr a = random_expr(fuzz, depth - 1, exprs); - Expr b = random_expr(fuzz, depth - 1, exprs); - return i16(Let::make("x", a, b)); - }, + Expr a = random_expr(fuzz, depth - 1, exprs); + Expr b = random_expr(fuzz, depth - 1, exprs); + return i16(Let::make("x", a, b)); + }, [&]() { - Expr a = random_expr(fuzz, depth - 1, exprs); - Expr b = random_expr(fuzz, depth - 1, exprs); - return i16(Let::make("y", a, b)); - }, + Expr a = random_expr(fuzz, depth - 1, exprs); + Expr b = random_expr(fuzz, depth - 1, exprs); + return i16(Let::make("y", a, b)); + }, [&]() { - Expr a = random_expr(fuzz, depth - 1, exprs); - Expr b = random_expr(fuzz, depth - 1, exprs); - return i16(Let::make("z", a, b)); - }, + Expr a = random_expr(fuzz, depth - 1, exprs); + Expr b = random_expr(fuzz, depth - 1, exprs); + return i16(Let::make("z", a, b)); + }, [&]() { - return i16(fuzz.ConsumeIntegralInRange(-5, 4)); - }, + return i16(fuzz.ConsumeIntegralInRange(-5, 4)); + }, }; Expr next = fuzz.PickValueInArray(build_next_expr)(); exprs.emplace_back(next, depth); diff --git a/test/generator/buffer_copy_aottest.cpp b/test/generator/buffer_copy_aottest.cpp index cd911f3ec44a..ae705ba0edba 100644 --- a/test/generator/buffer_copy_aottest.cpp +++ b/test/generator/buffer_copy_aottest.cpp @@ -33,8 +33,7 @@ int main(int argc, char **argv) { printf("Copying a crop failed\n"); exit(1); } - }, - in_crop); + }, in_crop); } #if (defined(TEST_CUDA) || defined(TEST_OPENCL)) @@ -66,8 +65,7 @@ int main(int argc, char **argv) { printf("Copying a crop failed\n"); exit(1); } - }, - in_crop); + }, in_crop); } // Test a buffer-copy to a host buffer from a device buffer. @@ -98,8 +96,7 @@ int main(int argc, char **argv) { printf("Copying a crop failed\n"); exit(1); } - }, - in_crop); + }, in_crop); } // Then a test of the pipeline that uses it in complicated ways diff --git a/test/generator/shuffler_aottest.cpp b/test/generator/shuffler_aottest.cpp index 4fe9b3037c2f..9bb0ca556f46 100644 --- a/test/generator/shuffler_aottest.cpp +++ b/test/generator/shuffler_aottest.cpp @@ -44,8 +44,7 @@ int main(int argc, char **argv) { config.max_time = config.min_time * 4; double best = benchmark([&]() { shuffler(input, output); - }, - config); + }, config); printf("Best time: %f\n", best); } diff --git a/test/performance/nested_vectorization_gemm.cpp b/test/performance/nested_vectorization_gemm.cpp index 660d3d7bbdf8..09c9417b69af 100644 --- a/test/performance/nested_vectorization_gemm.cpp +++ b/test/performance/nested_vectorization_gemm.cpp @@ -112,9 +112,9 @@ int main(int argc, char **argv) { times[use_nested_vectorization] = Tools::benchmark(20, 20, [&]() { - result.realize(out, target); - out.device_sync(); - }); + result.realize(out, target); + out.device_sync(); + }); } double speed_up = times[0] / times[1]; @@ -199,9 +199,9 @@ int main(int argc, char **argv) { times[use_nested_vectorization] = Tools::benchmark(10, 10, [&]() { - result.realize(out, target); - out.device_sync(); - }); + result.realize(out, target); + out.device_sync(); + }); } double speed_up = times[0] / times[1]; @@ -282,9 +282,9 @@ int main(int argc, char **argv) { times[use_nested_vectorization] = Tools::benchmark(10, 10, [&]() { - result.realize(out, target); - out.device_sync(); - }); + result.realize(out, target); + out.device_sync(); + }); } double speed_up = times[0] / times[1]; @@ -375,9 +375,9 @@ int main(int argc, char **argv) { times[use_nested_vectorization] = Tools::benchmark(10, 10, [&]() { - result.realize(out, target); - out.device_sync(); - }); + result.realize(out, target); + out.device_sync(); + }); } // We don't actually get any win from this on X86, as the diff --git a/test/performance/parallel_scenarios.cpp b/test/performance/parallel_scenarios.cpp index 8f7b31acf9c0..0b00e33857cb 100644 --- a/test/performance/parallel_scenarios.cpp +++ b/test/performance/parallel_scenarios.cpp @@ -59,12 +59,12 @@ int main(int argc, char **argv) { for (size_t t = 0; t < futures.size(); t++) { futures[t] = thread_pool.async( [&](size_t t) { - bench_one(); - auto t_start = now(); - while (to_ns(now() - t_start) < 1e7 || times[t].size() < min_samples / num_tasks) { - times[t].push_back(bench_one()); - } - }, + bench_one(); + auto t_start = now(); + while (to_ns(now() - t_start) < 1e7 || times[t].size() < min_samples / num_tasks) { + times[t].push_back(bench_one()); + } + }, t); } for (auto &f : futures) { diff --git a/test/performance/stack_vs_heap.cpp b/test/performance/stack_vs_heap.cpp index e5314f77897d..40ca6ef3a5c5 100644 --- a/test/performance/stack_vs_heap.cpp +++ b/test/performance/stack_vs_heap.cpp @@ -63,8 +63,8 @@ int main(int argc, char **argv) { Buffer out(sz, 1024); task_size.set(1); double t = 1e3 * Tools::benchmark(10, 1 + 100 / sz, [&]() { - g.realize(out); - }); + g.realize(out); + }); times[c] += t; } }