forked from PaddlePaddle/Paddle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
175 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,9 @@ set(srcs | |
memory.cc | ||
instruction.cc | ||
graph_compiler.cc | ||
graph.cc | ||
node.cc | ||
pass.cc | ||
) | ||
|
||
if(WITH_CUDA) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "cinn/hlir/framework/graph.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace framework { | ||
|
||
Graph::Graph(frontend::Program prog) { | ||
std::unordered_map<std::string, std::vector<int>> res; | ||
int counter = 0; | ||
for (size_t i = 0; i < prog.size(); i++) { | ||
auto temp = prog[i]; | ||
Node* node_tmp = | ||
new Node(Operator::Get(temp->op_type), temp->op_type, temp->op_type + "_" + std::to_string(counter++)); | ||
std::shared_ptr<Node> node_ptr(node_tmp); | ||
node_tmp->attrs.attr_store = temp->attrs; | ||
for (frontend::Variable j : temp->inputs) { | ||
NodeData* input_data = this->RetriveNode(j->id)->as<NodeData>(); | ||
if (!input_data) { | ||
res[j->id] = j->shape; | ||
input_data = new NodeData(nullptr, 0, 0, j->id); | ||
input_data->LinkTo(node_tmp); | ||
this->RegisterNode(j->id, input_data); | ||
} else { | ||
input_data->LinkTo(node_tmp); | ||
} | ||
} | ||
for (frontend::Variable j : temp->outputs) { | ||
int out_idx = 0; | ||
NodeData* output_data = new NodeData(node_ptr, out_idx++, 0, j->id); | ||
node_tmp->LinkTo(output_data); | ||
this->RegisterNode(j->id, output_data); | ||
} | ||
this->RegisterNode(node_tmp->id(), node_tmp); | ||
} | ||
this->attrs["infer_shape"] = std::make_shared<std::any>(res); | ||
} | ||
|
||
} // namespace framework | ||
} // namespace hlir | ||
} // namespace cinn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "cinn/hlir/framework/node.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace framework { | ||
|
||
std::tuple<common::GraphEdge *, common::GraphEdge *> Node::LinkTo(NodeData *other) { | ||
return this->common::GraphNode::LinkTo(other->as<common::GraphNode>()); | ||
} | ||
|
||
std::tuple<common::GraphEdge *, common::GraphEdge *> NodeData::LinkTo(Node *other) { | ||
return this->common::GraphNode::LinkTo(other->as<common::GraphNode>()); | ||
} | ||
|
||
} // namespace framework | ||
} // namespace hlir | ||
} // namespace cinn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "cinn/hlir/framework/pass.h" | ||
|
||
namespace cinn { | ||
namespace hlir { | ||
namespace framework { | ||
|
||
void ApplyPasses(Graph* g, const std::vector<std::string>& passes) { | ||
std::vector<const PassFunctionRegister*> fpass; | ||
for (auto& name : passes) { | ||
auto* reg = Registry<PassFunctionRegister>::Global()->Find(name); | ||
CHECK(reg) << "Cannot find pass " << name << " in the registry"; | ||
fpass.push_back(reg); | ||
} | ||
for (auto* r : fpass) { | ||
for (auto& dep : r->graph_attr_dependency) { | ||
CHECK_NE(g->attrs.count(dep), 0) << "To apply pass [" << r->name << "], Graph's attribute [" << dep | ||
<< "] is required, but it is not available."; | ||
if (g->attrs.count(dep) == 0) { | ||
auto* pass_dep = FindPassDep(dep); | ||
CHECK(!pass_dep) << "And the attribute is provided by pass [" << pass_dep->name << "]."; | ||
} | ||
} | ||
r->body(g); | ||
} | ||
} | ||
|
||
const PassFunctionRegister* FindPassDep(const std::string& attr_name) { | ||
for (auto* r : Registry<PassFunctionRegister>::Global()->List()) { | ||
for (auto& s : r->graph_attr_targets) { | ||
if (s == attr_name) return r; | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
} // namespace framework | ||
} // namespace hlir | ||
} // namespace cinn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.