-
Notifications
You must be signed in to change notification settings - Fork 89
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
Parse ONNX Expand to broadcast_with_dims
#2799
Merged
Merged
Changes from all commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
b72ad09
initial
CharlieL7 0ef0d0b
fixes
CharlieL7 47a07c3
add dynamic_dimension.within_range()
CharlieL7 bc062ca
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX…
CharlieL7 8053390
some progress
CharlieL7 3b227ad
Merge branch 'develop' of github.com:ROCm/AMDMIGraphX into dot_broadcast
CharlieL7 f999ae4
ref tests
CharlieL7 be9b8c1
Progress 2
CharlieL7 b4b0490
Test updates and fixes
CharlieL7 39c127a
Merge branch 'develop' of github.com:ROCm/AMDMIGraphX into dot_broadcast
CharlieL7 a586090
Update more tests
CharlieL7 0978db3
Fix typo
CharlieL7 1b7c8ff
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX…
CharlieL7 55aa1d8
License update
CharlieL7 3068e0e
Merge branch 'dot_broadcast' of github.com:ROCmSoftwarePlatform/AMDMI…
CharlieL7 f052cdd
Fixes and review updates
CharlieL7 9806538
More updates/fixes
CharlieL7 ac190ce
Formatting and date
CharlieL7 3c0a75e
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX…
CharlieL7 357d9a3
Fix compile
CharlieL7 e43c298
Fix op names
CharlieL7 f595a06
Other CI fixes
CharlieL7 0d73237
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX…
CharlieL7 2391cb1
Merge branch 'develop' into dot_broadcast
CharlieL7 a686c8c
Merge branch 'develop' into dot_broadcast
CharlieL7 a7346f7
add op
CharlieL7 f545145
Progress
CharlieL7 a7261f5
start test
CharlieL7 f8c5597
Fix compute() and tests
CharlieL7 4ecd2b3
Add more tests
CharlieL7 38bf0e3
Formatting
CharlieL7 d67c1c4
Merge branch 'develop' of github.com:ROCmSoftwarePlatform/AMDMIGraphX…
CharlieL7 9537ef0
Revert resize_linear_non_const_test.cpp
CharlieL7 554e850
Revert docstring change for multibroadcast.hpp
CharlieL7 4c2643a
Merge branch 'expand_dyn_op' into broadcast_with_dims_matcher
bpickrel beeed3a
added simplify_dyn_ops matcher to substitute broadcast_with_dims op, …
bpickrel 96950d6
tidy changes
bpickrel 33d6bc3
Merge branch 'develop' of github.com:ROCm/AMDMIGraphX into expand_dyn_op
CharlieL7 d0b9381
formatting
CharlieL7 a6c057a
Fix tests and function call
CharlieL7 e03c4f5
licensing
CharlieL7 032674b
formatting
CharlieL7 5fc2121
tidy ignore line
CharlieL7 f46788b
Merge branch 'expand_dyn_op' into broadcast_with_dims_matcher
bpickrel ad7998d
Comments
bpickrel 165d23e
cosmetic variable name change
bpickrel 39b15ce
comment
bpickrel 371a873
remove duplicated tests
bpickrel 21f42b7
added a negative simplify_dyn_ops test
bpickrel e8ffc81
style; changed vector initialization
bpickrel c575299
update tests
CharlieL7 4d31064
Merge branch 'develop' of github.com:ROCm/AMDMIGraphX into expand_dyn_op
CharlieL7 3c019cf
Merge branch 'develop' into expand_dyn_op
causten f7800ac
Merge branch 'broadcast_with_dims_matcher' into expand_dyn_op
bpickrel 66e3f0e
correct data type in test
bpickrel 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 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 |
---|---|---|
|
@@ -140,6 +140,7 @@ register_migraphx_ops( | |
atan | ||
broadcast | ||
broadcast_for_dot | ||
broadcast_with_dims | ||
capture | ||
ceil | ||
clip | ||
|
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,84 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2015-2024 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. | ||
*/ | ||
#ifndef MIGRAPHX_GUARD_OPERATORS_BROADCAST_WITH_DIMS_HPP | ||
#define MIGRAPHX_GUARD_OPERATORS_BROADCAST_WITH_DIMS_HPP | ||
|
||
#include <migraphx/check_shapes.hpp> | ||
#include <migraphx/config.hpp> | ||
#include <migraphx/shape.hpp> | ||
#include <migraphx/argument.hpp> | ||
#include <migraphx/common.hpp> | ||
|
||
namespace migraphx { | ||
inline namespace MIGRAPHX_INLINE_NS { | ||
namespace op { | ||
|
||
/** | ||
* Broadcast the input tensor to the shape defined by the values of the second input. | ||
* Used as `broadcast_with_dims(input_tensor, dims)`, where dims is a vector of integer dimensions. | ||
* `input_tensor` must be broadcastable with `dims`, otherwise this operator with throw at compute. | ||
* This operator can be replaced with `multibroadcast(input_tensor)` if the `dims` vector is | ||
* constant. | ||
* | ||
* Example: | ||
* input_tensor shape: lens = {2, 3}, strides = {3, 1} | ||
* dims = [4, 1, 3] | ||
* output shape: lens = {4, 2, 3}, strides = {0, 3, 1} | ||
*/ | ||
struct broadcast_with_dims | ||
{ | ||
std::string name() const { return "broadcast_with_dims"; } | ||
|
||
shape compute_shape(const std::vector<shape>& inputs) const | ||
{ | ||
migraphx::check_shapes{inputs, *this, true}.has(2); | ||
// check that second input has a static shape | ||
(void)migraphx::check_shapes{inputs.begin() + 1, inputs.end(), *this, false}; | ||
// output tensor rank is greater of input_tensor rank or length of dims vector | ||
const auto& input_tensor_shape = inputs.at(0); | ||
const auto& dims_shape = inputs.at(1); | ||
size_t out_ndim = std::max(input_tensor_shape.ndim(), dims_shape.lens().at(0)); | ||
std::size_t max_int = std::numeric_limits<std::size_t>::max(); | ||
std::vector<shape::dynamic_dimension> dyn_dims(out_ndim, | ||
shape::dynamic_dimension{0, max_int}); | ||
return {input_tensor_shape.type(), dyn_dims}; | ||
} | ||
|
||
argument compute(const shape& output_shape, const std::vector<argument>& args) const | ||
{ | ||
auto s0 = args.at(0).get_shape(); | ||
const auto& in_lens = s0.lens(); | ||
std::vector<std::size_t> dims_input(output_shape.ndim()); | ||
args.at(1).visit([&](auto a) { dims_input.assign(a.begin(), a.end()); }); | ||
auto out_lens = compute_broadcasted_lens(in_lens, dims_input); | ||
auto out_shape = make_bcast_shape(s0, out_lens); | ||
return args[0].reshape(out_shape); | ||
} | ||
}; | ||
|
||
} // namespace op | ||
} // namespace MIGRAPHX_INLINE_NS | ||
} // namespace migraphx | ||
|
||
#endif |
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,19 @@ | ||
expand_dyn_test:q | ||
x | ||
dimsy"Expandexpand_dyn_testZ | ||
x | ||
Z | ||
dims | ||
|
||
b | ||
y | ||
B |
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
Oops, something went wrong.
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.
I like this example make this one of the tests so we can have a 1:1 with expected behavior