"examples/git@developer.sourcefind.cn:orangecat/ollama.git" did not exist on "4340f8eba4b3a0e5672a0c4837ac45a23c074fdf"
Commit e2db5e20 authored by Paul's avatar Paul
Browse files

Use matchers for fusion

parent 17129c88
#include <migraph/gpu/fuse_ops.hpp> #include <migraph/gpu/fuse_ops.hpp>
#include <migraph/iterator_for.hpp> #include <migraph/matcher.hpp>
#include <migraph/gpu/device/add_relu.hpp> #include <migraph/gpu/device/add_relu.hpp>
#include <migraph/instruction.hpp> #include <migraph/instruction.hpp>
...@@ -22,20 +22,24 @@ struct hip_add_relu ...@@ -22,20 +22,24 @@ struct hip_add_relu
} }
}; };
void fuse_ops::apply(program& p) const struct match_add_relu
{ {
for(auto ins : iterator_for(p)) auto matcher() const { return match::name("gpu::relu")(match::args(match::name("gpu::add").bind("add"))); }
{
if(ins->name() != "gpu::relu") void apply(program& p, match::matcher_result r) const
continue; {
auto add_ins = ins->inputs().front(); auto add_ins = r.instructions["add"];
if(add_ins->name() != "gpu::add") auto ins = r.result;
continue;
auto args = add_ins->inputs(); auto args = add_ins->inputs();
// Use the allocation from the relu operator // Use the allocation from the relu operator
args.back() = ins->inputs().back(); args.back() = ins->inputs().back();
p.replace_instruction(ins, hip_add_relu{}, args); p.replace_instruction(ins, hip_add_relu{}, args);
} }
};
void fuse_ops::apply(program& p) const
{
match::find_matches(p, match_add_relu{});
} }
} // namespace gpu } // namespace gpu
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment