1/**
2 * Copyright (c) Glow Contributors. See CONTRIBUTORS file.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef GLOW_PARTITIONER_PARTITIONERBASE_H
17#define GLOW_PARTITIONER_PARTITIONERBASE_H
18
19#include "glow/Partitioner/PartitionerTypes.h"
20#include "glow/Support/Error.h"
21
22namespace glow {
23
24using namespace runtime;
25/// Given a module, partitions each of the its functions into multiple ones
26/// based on memory constraints and minimizes the communication cost.
27class PartitionerBase {
28public:
29 virtual ~PartitionerBase() = default;
30
31 /// Decompose each function in a module. \p cctx is used in function
32 /// optimization. \returns the partition result.
33 virtual Expected<DAGListTy> partition(CompilationContext &cctx) = 0;
34
35 /// Dump the partition result \p partitions to a dot file with name \p
36 /// dotFilename. Since now all functions belong to a function family and they
37 /// have the same partition, we only dump the one function's partition.
38 void dumpDAG(llvm::StringRef dotFilename, const DAGListTy &partitions) const;
39
40protected:
41 /// Given the node-function mapping \p mapping, do the actual partitioning. If
42 /// \p saveDAG is true, the DAG will be generated. \returns the final
43 /// partitions or an empty partition (If \p saveDAG is false). Normally this
44 /// is done by cloning Nodes from each Function in \p funcs into other new
45 /// Functions representing each partition. However if \p skipCloning we skip
46 /// this cloning, as it is assumed that the Functions are already partitioned
47 /// correctly and so we do not need to clone their Nodes into new Functions.
48 /// \p nodeInfo represents any info mapped to Nodes, so when cloning Nodes we
49 /// need to update this map.
50 DAGListTy doPartitioning(llvm::StringRef funcName,
51 std::vector<Function *> funcs, Module *module,
52 NodeToFunctionMap &mapping, bool saveDAG,
53 BackendSpecificNodeInfo &nodeInfo,
54 bool skipCloning = false);
55};
56} // namespace glow
57#endif // GLOW_PARTITIONER_PARTITIONER_H
58