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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
Full documentation for MIGraphX is available at
[https://rocmdocs.amd.com/projects/AMDMIGraphX/en/latest/](https://rocmdocs.amd.com/projects/AMDMIGraphX/en/latest/).

## Develop Branch

### Changed

* Refactored instruction output alias to return a vector of aliases (#4540).

## MIGraphX 2.15 for ROCm 7.2.0

### Added
Expand Down
7 changes: 5 additions & 2 deletions src/adjust_allocation.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 @@ -43,7 +43,10 @@ void adjust_allocation::apply(module& m) const
if(ins->get_operator().is_context_free())
continue;

auto alias_ins = instruction::get_output_alias(ins, true);
auto aliases = instruction::get_output_alias(ins, true);
if(aliases.size() != 1)
continue;
auto alias_ins = aliases.front();
if(alias_ins->name() != model.name() and alias_ins->name() != "@param")
continue;
// shape allocated is different from actual shape
Expand Down
16 changes: 3 additions & 13 deletions src/api/api.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 @@ -377,19 +377,9 @@ struct custom_operation
return op.compute(std::move(ctx), std::move(output_shape), std::move(inputs));
}

std::ptrdiff_t output_alias(std::vector<shape> inputs) const
std::vector<std::size_t> output_alias(std::vector<shape> inputs) const
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why not return vector of ptrdiff_t here? Reason for changing from signed to unsigned now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The index is always positive. We only used ptrdiff_t so we could write -1 as saying there wasnt an output alias, but that was a hack.

{
auto alias_vec = op.output_alias(std::move(inputs));
// TODO: For now, only support one output alias
if(alias_vec.empty())
{
return -1;
}
if(alias_vec.size() > 1)
{
MIGRAPHX_THROW("Currently, CustomOps in MIGraphX only supports one output_alias");
}
return alias_vec.front();
return op.output_alias(std::move(inputs));
}

bool runs_on_offload_target() const { return op.runs_on_offload_target(); }
Expand Down
22 changes: 13 additions & 9 deletions src/driver/perf.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 @@ -118,19 +118,23 @@ bool is_offload_copy_set(const program& p)
{
if(i.name() == "hip::copy_to_gpu")
{
auto copy_arg = instruction::get_output_alias(i.inputs().front(), true);
param_ins.erase(copy_arg);
auto copy_args = instruction::get_output_alias(i.inputs().front(), true);
for(auto copy_arg : copy_args)
param_ins.erase(copy_arg);
}
else if(i.name() == "@return")
{
auto return_args = i.inputs();
for(const auto& j : return_args)
{
auto alias_ins = instruction::get_output_alias(j, true);
if((alias_ins->name() == "@param" and param_ins.erase(alias_ins) == 0) or
(alias_ins->name() != "hip::copy_from_gpu"))
return std::all_of(return_args.begin(), return_args.end(), [&](const auto& j) {
auto aliases = instruction::get_output_alias(j, true);
return std::all_of(aliases.begin(), aliases.end(), [&](instruction_ref alias_ins) {
if(alias_ins->name() == "hip::copy_from_gpu")
return true;
if(alias_ins->name() == "@param")
return not contains(param_ins, alias_ins);
return false;
}
});
});
}
}
return param_ins.empty();
Expand Down
8 changes: 4 additions & 4 deletions src/driver/trim.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 @@ -37,11 +37,11 @@ inline namespace MIGRAPHX_INLINE_NS {

static instruction_ref capture_arg(std::unordered_set<instruction_ref>& s, instruction_ref ins)
{
auto alias = instruction::get_output_alias(ins, true);
if(alias != ins)
auto aliases = instruction::get_output_alias(ins, true);
if(aliases.size() == 1 and aliases.front() != ins)
{
s.insert(ins);
return capture_arg(s, alias);
return capture_arg(s, aliases.front());
}
if(contains({"reshape", "contiguous"}, ins->name()))
{
Expand Down
15 changes: 9 additions & 6 deletions src/eliminate_concat.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 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 @@ -70,11 +70,14 @@ void eliminate_concat::apply(module& m) const
// Where are the allocations for the tensors to be concatenated?
std::vector<instruction_ref> allocations;

std::transform(
ins->inputs().begin(),
std::prev(ins->inputs().end()),
std::back_inserter(allocations),
[&](instruction_ref x) { return instruction::get_output_alias(x, true); });
std::transform(ins->inputs().begin(),
std::prev(ins->inputs().end()),
std::back_inserter(allocations),
[&](instruction_ref x) {
auto aliases = instruction::get_output_alias(x, true);
// cppcheck-suppress returnDanglingLifetime
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should be suppressing this. Make this a separate issue to fix later and a TODO above it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is a false positive, there is not dangling lifetime so we have to suppress this. This is a bug in cppcheck.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add that to the comment to make that clear.

return aliases.front();
});

if(std::any_of(allocations.begin(), allocations.end(), [&](auto x) {
return x->name() != concat_opt.allocate();
Expand Down
4 changes: 2 additions & 2 deletions src/graphviz.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 @@ -114,7 +114,7 @@ std::string get_graph_color(const instruction_ref& ins)
const auto& attr = op.attributes();

bool context_free = is_context_free(op);
bool alias = op.output_alias(to_shapes(ins->inputs())) >= 0;
bool alias = not op.output_alias(to_shapes(ins->inputs())).empty();

if(ins->can_eval())
{
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/instruction.hpp
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 @@ -140,7 +140,7 @@ struct MIGRAPHX_EXPORT instruction

void finalize(context& ctx);

static instruction_ref get_output_alias(instruction_ref ins, bool shallow = false);
static std::vector<instruction_ref> get_output_alias(instruction_ref ins, bool shallow = false);

void set_normalized(bool value = true);
bool is_normalized() const;
Expand Down
11 changes: 6 additions & 5 deletions src/include/migraphx/liveness.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 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 @@ -53,11 +53,12 @@ void liveness(const module& m, F f)
auto add_live_variables = [&](const auto& inputs) {
for(auto input : inputs)
{
auto i = instruction::get_output_alias(input);
auto aliases = instruction::get_output_alias(input);
// Skip if variable comes from parent
if(not m.has_instruction(i))
continue;
live_set.insert(i);
std::copy_if(aliases.begin(),
aliases.end(),
std::inserter(live_set, live_set.end()),
[&](auto i) { return m.has_instruction(i); });
}
};
add_live_variables(ins->inputs());
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/as_shape.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 @@ -53,7 +53,7 @@ struct as_shape
{
return args.front().reshape(output_shape);
}
std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }
};

} // namespace op
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/broadcast.hpp
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 @@ -148,7 +148,7 @@ struct broadcast
{
return args[0].reshape(dyn_out.computed_shape);
}
std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }

value attributes() const { return {{"fillcolor", "#9ACD32" /* yellowgreen */}}; }
};
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/broadcast_for_dot.hpp
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 @@ -83,7 +83,7 @@ struct broadcast_for_dot
return args[0].reshape(dyn_out.computed_shape);
}

std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some comment as above, is there a reason why we've change this all to size_t? We're making this unsigned now instead of ptrdiff_t allowing for negative values


value attributes() const { return {{"fillcolor", "#9ACD32" /* yellowgreen */}}; }
};
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/capture.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 @@ -66,7 +66,7 @@ struct capture
return args.front();
}

std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }
};

} // namespace op
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/fill.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2023 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 @@ -60,7 +60,7 @@ struct fill
return args[1];
}

std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 1; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {1}; }
};

} // namespace op
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/get_tuple_elem.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 @@ -67,7 +67,7 @@ struct get_tuple_elem
return vec_args.at(index);
}

std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }
};

} // namespace op
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/identity.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2024 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 @@ -39,7 +39,7 @@ struct identity

value attributes() const { return {{"pointwise", true}, {"point_op", "${0}"}}; }

std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }
};

} // namespace op
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/load.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 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 @@ -58,7 +58,7 @@ struct load
return argument{s, args[0].data() + offset};
}
lifetime get_lifetime() const { return lifetime::borrow; }
std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }

friend std::ostream& operator<<(std::ostream& os, const load& op)
{
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/multibroadcast.hpp
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 @@ -115,7 +115,7 @@ struct multibroadcast
{
return args[0].reshape(dyn_out.computed_shape);
}
std::ptrdiff_t output_alias(const std::vector<shape>&) const { return 0; }
std::vector<std::size_t> output_alias(const std::vector<shape>&) const { return {0}; }
};

} // namespace op
Expand Down
Loading
Loading