-
Notifications
You must be signed in to change notification settings - Fork 131
Add dynamic shape support for TopK #4880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
klin2024
wants to merge
27
commits into
develop
Choose a base branch
from
topk_op_support_dynamic_input_fix
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
02ec17c
Support dynamic input for Topk op
b998457
fix debug version print and use internal allocation for dynamic output
3527d11
add bound check
171aec9
Update src/include/migraphx/op/topk.hpp
kazhang2 222a2dd
Update src/include/migraphx/dyn_output.hpp
kazhang2 33398d8
Update src/program.cpp
kazhang2 b067618
Update src/replace_allocate.cpp
kazhang2 36ad89d
Update src/targets/gpu/compile_ops.cpp
kazhang2 b55ae07
Update test/verify/test_topk_dynamic.cpp
kazhang2 df26e31
Update test/verify/test_topk_dynamic.cpp
kazhang2 89f31ba
Update src/targets/gpu/compile_ops.cpp
kazhang2 2624cec
Update src/targets/gpu/include/migraphx/gpu/hip.hpp
kazhang2 bf9e4e4
remove lifetime::global and s.any_of_dynamic check
e4073bd
fix license check
eedd15f
remove lifetime::global
49b757b
format change
3499f43
Update test/ref/topk.cpp
kazhang2 d5d0d3e
Update src/targets/gpu/lowering.cpp
kazhang2 68332cc
Update test/ref/topk.cpp
kazhang2 0ee21ec
Update test/ref/topk.cpp
kazhang2 3431d57
Update test/ref/topk.cpp
kazhang2 c360580
Update test/ref/topk.cpp
kazhang2 e6090e3
Update test/verify/test_topk_dynamic.cpp
kazhang2 688864a
Update src/targets/gpu/include/migraphx/gpu/hip.hpp
kazhang2 13b06cb
Merge branch 'develop' into topk_op_support_dynamic_input_fix
klin2024 a048213
Potential fix for pull request finding
kazhang2 0d08c50
Potential fix for pull request finding
kazhang2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -43,6 +43,8 @@ struct find_large_topk | |
| { | ||
| auto ins = r.result; | ||
| auto input = ins->inputs().front(); | ||
| if(input->get_shape().dynamic()) | ||
| return; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
| auto op = ins->get_operator().to_value(); | ||
| auto axis = op["axis"].to<std::int64_t>(); | ||
| auto k = op["k"].to<std::int64_t>(); | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| /* | ||
| * The MIT License (MIT) | ||
| * | ||
| * 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 | ||
| * in the Software without restriction, including without limitation the rights | ||
| * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| * copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| * THE SOFTWARE. | ||
| */ | ||
|
|
||
| #include "verify_program.hpp" | ||
| #include <migraphx/program.hpp> | ||
| #include <migraphx/generate.hpp> | ||
| #include <migraphx/make_op.hpp> | ||
|
|
||
| // Test k > n with dynamic shapes: k=100 placeholder but runtime input has fewer elements | ||
| template <std::size_t N> | ||
| struct test_topk_dynamic : verify_program<test_topk_dynamic<N>> | ||
| { | ||
| migraphx::program create_program() const | ||
| { | ||
| migraphx::program p; | ||
| auto* mm = p.get_main_module(); | ||
| std::vector<migraphx::shape::dynamic_dimension> dds = {{1, 100}}; | ||
| migraphx::shape s{migraphx::shape::float_type, dds}; | ||
| auto data = mm->add_parameter("data", s); | ||
| auto r = mm->add_instruction( | ||
| migraphx::make_op("topk", {{"axis", 0}, {"k", 100}, {"largest", 1}}), data); | ||
| auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), r); | ||
| auto r1 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), r); | ||
| mm->add_return({r0, r1}); | ||
| return p; | ||
| } | ||
|
|
||
| std::unordered_map<std::string, migraphx::shape> get_test_dims() const | ||
| { | ||
| return {{"data", migraphx::shape{migraphx::shape::float_type, {N}}}}; | ||
| } | ||
| }; | ||
|
|
||
| template struct test_topk_dynamic<10>; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than a placeholder value of max_len make the
kattribute intopkastd::optional<int64_t>. This would be more obvious what is meant.