1 | /* |
---|---|
2 | * Licensed to the Apache Software Foundation (ASF) under one |
3 | * or more contributor license agreements. See the NOTICE file |
4 | * distributed with this work for additional information |
5 | * regarding copyright ownership. The ASF licenses this file |
6 | * to you under the Apache License, Version 2.0 (the |
7 | * "License"); you may not use this file except in compliance |
8 | * with the License. You may obtain a copy of the License at |
9 | * |
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
11 | * |
12 | * Unless required by applicable law or agreed to in writing, |
13 | * software distributed under the License is distributed on an |
14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
15 | * KIND, either express or implied. See the License for the |
16 | * specific language governing permissions and limitations |
17 | * under the License. |
18 | */ |
19 | |
20 | /*! |
21 | * \file src/relay/collage/dataflow_graph.cc |
22 | * \brief A representation of the dataflow for an overall Relay expression. |
23 | */ |
24 | |
25 | #include "./dataflow_graph.h" |
26 | |
27 | namespace tvm { |
28 | namespace relay { |
29 | namespace collage { |
30 | |
31 | DataflowGraph::DataflowGraph(Expr expr) : expr_(std::move(expr)) { |
32 | indexed_graph_ = CreateIndexedGraph(expr_); |
33 | downstream_map_.reserve(indexed_graph_->size()); |
34 | for (PostDfsIndex index = 0; index < indexed_graph_->size(); ++index) { |
35 | const Node* node = indexed_graph_->index_to_node(index); |
36 | std::unordered_set<const Node*> downstream_nodes; |
37 | node->AccumulateDownstreamNodes(&downstream_nodes); |
38 | IndexSet index_set(indexed_graph_->size()); |
39 | for (const Node* downstream_node : downstream_nodes) { |
40 | index_set.Add(downstream_node->index_); |
41 | } |
42 | downstream_map_.emplace_back(std::move(index_set)); |
43 | } |
44 | } |
45 | |
46 | } // namespace collage |
47 | } // namespace relay |
48 | } // namespace tvm |
49 |