Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Full documentation for MIGraphX is available at
* Added Torch-MIGraphX installation instructions.
* Added Operator Builders with supporting documentation.
* Added index range check to the Gather operator.
* Allow running in the driver a pass from a backend target using 'pass_name@target_name' for the pass name
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should go into the Develop Added section

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is that at?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the changelog on develop branch was updated, you should see it near the top of the file



### Changed
Expand Down
39 changes: 35 additions & 4 deletions src/driver/passes.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2025 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2026 Advanced Micro Devices, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -41,6 +41,7 @@
#include <migraphx/optimize_module.hpp>
#include <migraphx/promote_literals.hpp>
#include <migraphx/propagate_constant.hpp>
#include <migraphx/register_target.hpp>
#include <migraphx/rewrite_dot.hpp>
#include <migraphx/rewrite_gelu.hpp>
#include <migraphx/rewrite_pooling.hpp>
Expand All @@ -53,11 +54,21 @@

#include <migraphx/ranges.hpp>
#include <unordered_map>
#include <utility>

namespace migraphx {
namespace driver {
inline namespace MIGRAPHX_INLINE_NS {

struct pass_with_context : pass
{
pass_with_context(const pass& p, std::shared_ptr<context> pctx = nullptr)
: pass(p), ctx(std::move(pctx))
{
}
std::shared_ptr<context> ctx = nullptr;
};

static std::unordered_map<std::string, pass> create_passes_lookup()
{
std::unordered_map<std::string, pass> result;
Expand Down Expand Up @@ -97,15 +108,35 @@ static std::unordered_map<std::string, pass> create_passes_lookup()
return result;
}

static std::optional<pass> get_pass(const std::string& name)
{
static const std::unordered_map<std::string, pass> lookup = create_passes_lookup();
if(contains(lookup, name))
return lookup.at(name);
auto fields = split_string(name, '@');
if(fields.size() != 2)
return std::nullopt;
auto base_name = fields[0];
const auto& target_name = fields[1];
auto t = make_target(target_name);
auto ctx = std::make_shared<context>(t.get_context());
auto passes = t.get_passes(*ctx, {});
auto it = std::find_if(
passes.begin(), passes.end(), [&](const pass& p) { return p.name() == base_name; });
if(it == passes.end())
return std::nullopt;
return pass_with_context(*it, ctx);
}

std::vector<pass> get_passes(const std::vector<std::string>& names)
{
std::vector<pass> result;
static const std::unordered_map<std::string, pass> lookup = create_passes_lookup();
std::transform(
names.begin(), names.end(), std::back_inserter(result), [](const std::string& name) {
if(not contains(lookup, name))
auto p = get_pass(name);
if(not p)
MIGRAPHX_THROW("Unknown pass: " + name);
return lookup.at(name);
return *p;
});
return result;
}
Expand Down
Loading