junrushao1994 commented on a change in pull request #9789:
URL: https://github.com/apache/tvm/pull/9789#discussion_r777055569
##########
File path: src/meta_schedule/utils.h
##########
@@ -233,6 +242,73 @@ inline std::string Concat(const Array<String>& strs, const
std::string& delim) {
return os.str();
}
+/*!
+ * \brief A helper data structure that replays a trace and collects failure
counts
+ * for each postprocessor
+ */
+struct ThreadedTraceApply {
+ /*! \brief Constructor */
+ explicit ThreadedTraceApply(const Array<Postproc>& postprocs)
+ : n_(postprocs.size()), items_(new Item[n_]) {
+ for (int i = 0; i < n_; ++i) {
+ items_[i].postproc = postprocs[i];
+ items_[i].fail_counter = 0;
+ }
+ }
+
+ /*! \brief Destructor */
+ ~ThreadedTraceApply() { delete[] items_; }
+
+ /*!
+ * \brief Apply the trace and postprocessors to an IRModule
+ * \param mod The IRModule to be applied
+ * \param trace The trace to apply to the IRModule
+ * \param rand_state The random seed
+ * \return The schedule created, or NullOpt if any postprocessor fails
+ */
+ Optional<tir::Schedule> Apply(const IRModule& mod, const tir::Trace& trace,
+ TRandState* rand_state) {
+ tir::Schedule sch =
+ tir::Schedule::Traced(mod,
+ /*rand_state=*/ForkSeed(rand_state),
+ /*debug_mode=*/0,
+
/*error_render_level=*/tir::ScheduleErrorRenderLevel::kNone);
+ trace->ApplyToSchedule(sch, /*remove_postproc=*/true);
+ sch->EnterPostproc();
+ for (int i = 0; i < n_; ++i) {
+ Item& item = items_[i];
+ if (!item.postproc->Apply(sch)) {
+ ++item.fail_counter;
+ return NullOpt;
+ }
+ }
+ return sch;
+ }
+
+ /*! \brief Returns a string summarizing the failures on each postprocessor */
+ std::string SummarizeFailures() const {
+ std::ostringstream os;
+ for (int i = 0; i < n_; ++i) {
+ const Item& item = items_[i];
+ os << "Postproc #" << i << " [" << item.postproc //
+ << "]: " << item.fail_counter.load() << " failure(s)";
+ if (i != n_ - 1) {
+ os << "\n";
+ }
+ }
+ return os.str();
+ }
+
+ private:
+ struct Item {
+ Postproc postproc{nullptr};
+ std::atomic<int> fail_counter{0};
+ };
+
+ int n_;
+ Item* items_;
Review comment:
doc?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]