#pragma once #include "common.h" #include "graph.h" #include "mutator.h" #include namespace infini { class SearchEngine { private: Runtime runtimeExec; Ref mutator; public: SearchEngine(Runtime _runtime, Ref _mutator) { runtimeExec = _runtime; mutator = _mutator; } ~SearchEngine() {} private: // Configurations size_t partitionThreshold = 3; // cut nodes whose #in + #out >= partitionThreshold size_t GRAPH_SIZE = 16; // num of best graphs. private: // Composed objects std::shared_ptr mutationEngine; public: std::shared_ptr getMutationEngine() { return mutationEngine; }; struct GroupEdge { int v, next; GroupEdge() = delete; }; struct Candidate { // a graph with perf std::shared_ptr graph; double perf = INFINITY; }; class MetaGraph { // a graph of subgraphs, for searching. public: MetaGraph() {} ~MetaGraph() {} struct Node { Graph graph; std::vector suc; std::vector pre; int type, cnt; }; std::vector nodes; }; Graph run(const Graph graph); // entrance of search engine. std::vector search(const Graph &graph); // search for a partition. private: std::vector partitionGraph(const Graph graph); std::shared_ptr buildMetaGraphWithGraph(const Graph graph); std::shared_ptr buildMetaGraphWithPlan(const std::shared_ptr metaGraph, const std::vector &plan); // search horizontal merges std::vector> searchMerge(std::shared_ptr &metaGraph); void searchMergeDfs(std::shared_ptr &metaGraph, std::vector &plan, std::vector &frontier, std::vector> &plans, std::unordered_set &planSet); std::vector searchMutation(const std::shared_ptr &metaGraph); void printMetaGraph(Ref metaGraph); /** * @brief Check whether a multi-brach graph can be merged into a single * branch. */ bool isMultiBranchMergable(const Graph graph); }; } // namespace infini