-
Notifications
You must be signed in to change notification settings - Fork 115
Refactor data type elimination in the gpu #4539
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7569f31
Refactor data type elimination in the gpu
pfultz2 08e819d
Format
pfultz2 ee6ea05
update license year
causten f369a64
add standard license to new file
causten 3b8bf4a
Merge branch 'develop' into eliminate-data-type-for-gpu
pfultz2 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| /* | ||
| * 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 <migraphx/gpu/eliminate_data_type_for_gpu.hpp> | ||
| #include <migraphx/pass_manager.hpp> | ||
| #include <migraphx/eliminate_data_type.hpp> | ||
|
|
||
| namespace migraphx { | ||
| inline namespace MIGRAPHX_INLINE_NS { | ||
| namespace gpu { | ||
|
|
||
| static void insert_miopen_pooling(std::set<std::string>& u) | ||
| { | ||
| #if MIGRAPHX_USE_MIOPEN | ||
| u.insert("pooling"); | ||
| #endif | ||
| } | ||
|
|
||
| static void insert_gemm_conv(std::set<std::string>& u) | ||
| { | ||
| u.insert("convolution"); | ||
| u.insert("quant_convolution"); | ||
| u.insert("dot"); | ||
| u.insert("quant_dot"); | ||
| } | ||
|
|
||
| static eliminate_data_type for_device_functions() | ||
| { | ||
| std::set<shape::type_t> unsupported_types(shape::types().begin(), shape::types().end()); | ||
| unsupported_types.erase(shape::type_t::float_type); | ||
| unsupported_types.erase(shape::type_t::half_type); | ||
| unsupported_types.erase(shape::type_t::bool_type); | ||
| unsupported_types.erase(shape::type_t::int8_type); | ||
| unsupported_types.erase(shape::type_t::uint8_type); | ||
| unsupported_types.erase(shape::type_t::int32_type); | ||
| unsupported_types.erase(shape::type_t::bf16_type); | ||
| unsupported_types.erase(shape::type_t::tuple_type); | ||
|
|
||
| std::set<std::string> device_functions = { | ||
| "logsoftmax", | ||
| "nonzero", | ||
| "prefix_scan_sum", | ||
| "rnn_var_sl_shift_output", | ||
| "multinomial", | ||
| "argmax", | ||
| "argmin", | ||
| }; | ||
|
|
||
| return eliminate_data_type{unsupported_types, shape::type_t::float_type, device_functions}; | ||
| } | ||
|
|
||
| static eliminate_data_type for_fp8fnuz() | ||
| { | ||
| std::set<std::string> unsupported_ops = {}; | ||
|
|
||
| // disable dot & quant_dot if no hipblaslt | ||
| if(not hipblaslt_supported()) | ||
| { | ||
| unsupported_ops.insert("dot"); | ||
| unsupported_ops.insert("quant_dot"); | ||
| } | ||
|
|
||
| // MIOpen doesn't have support for fp8 pooling yet. | ||
| insert_miopen_pooling(unsupported_ops); | ||
|
|
||
| if(not gpu::gfx_has_fp8fnuz_intrinsics()) | ||
| { | ||
| insert_gemm_conv(unsupported_ops); | ||
| } | ||
| return eliminate_data_type{ | ||
| {shape::fp8e4m3fnuz_type, shape::fp8e5m2fnuz_type}, shape::float_type, unsupported_ops}; | ||
| } | ||
|
|
||
| static eliminate_data_type for_fp8ocp() | ||
| { | ||
| std::set<std::string> unsupported_ops = {}; | ||
|
|
||
| // disable dot & quant_dot if no hipblaslt | ||
| if(not hipblaslt_supported()) | ||
| { | ||
| unsupported_ops.insert("dot"); | ||
| unsupported_ops.insert("quant_dot"); | ||
| } | ||
|
|
||
| // MIOpen doesn't have support for fp8 pooling yet. | ||
| insert_miopen_pooling(unsupported_ops); | ||
|
|
||
| if(not gpu::gfx_has_fp8ocp_intrinsics()) | ||
| { | ||
| insert_gemm_conv(unsupported_ops); | ||
| } | ||
| return eliminate_data_type{ | ||
| {shape::fp8e4m3fn_type, shape::fp8e5m2_type}, shape::float_type, unsupported_ops}; | ||
| } | ||
|
|
||
| static eliminate_data_type for_gemm_conv() | ||
| { | ||
| std::set<std::string> unsupported_ops = {}; | ||
| insert_gemm_conv(unsupported_ops); | ||
|
|
||
| return eliminate_data_type{{ | ||
| shape::bool_type, | ||
| shape::uint16_type, | ||
| shape::int16_type, | ||
| shape::int64_type, | ||
| shape::uint64_type, | ||
| shape::double_type, | ||
| }, | ||
| shape::float_type, | ||
| unsupported_ops}; | ||
| } | ||
|
|
||
| void eliminate_data_type_for_gpu::apply(module_pass_manager& mpm) const | ||
| { | ||
| std::set<shape::type_t> unsupported_types; | ||
| // No BF-16 Support on Navi21 | ||
| if(not gpu::gfx_has_bf16_intrinsics()) | ||
| { | ||
| unsupported_types.insert(shape::type_t::bf16_type); | ||
| } | ||
| if(not unsupported_types.empty()) | ||
| mpm.run_pass(eliminate_data_type{unsupported_types, shape::type_t::float_type}); | ||
|
|
||
| // workaround for rocBLAS unsupported error when using uint8 in quant_dot, quant_convolution & | ||
| // pooling | ||
| mpm.run_pass(eliminate_data_type{ | ||
| {shape::uint8_type}, shape::float_type, {"quant_convolution", "quant_dot", "pooling"}}); | ||
|
|
||
| mpm.run_pass(for_device_functions()); | ||
|
|
||
| mpm.run_pass(for_fp8fnuz()); | ||
| mpm.run_pass(for_fp8ocp()); | ||
|
|
||
| mpm.run_pass(for_gemm_conv()); | ||
| } | ||
|
|
||
| } // namespace gpu | ||
| } // namespace MIGRAPHX_INLINE_NS | ||
| } // namespace migraphx | ||
46 changes: 46 additions & 0 deletions
46
src/targets/gpu/include/migraphx/gpu/eliminate_data_type_for_gpu.hpp
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,46 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
| #ifndef MIGRAPHX_GUARD_RTGLIB_ELIMINATE_DATA_TYPE_FOR_GPU_HPP | ||
| #define MIGRAPHX_GUARD_RTGLIB_ELIMINATE_DATA_TYPE_FOR_GPU_HPP | ||
|
|
||
| #include <migraphx/gpu/context.hpp> | ||
|
|
||
| namespace migraphx { | ||
| inline namespace MIGRAPHX_INLINE_NS { | ||
|
|
||
| struct module_pass_manager; | ||
|
|
||
| namespace gpu { | ||
|
|
||
| struct MIGRAPHX_GPU_EXPORT eliminate_data_type_for_gpu | ||
| { | ||
| std::string name() const { return "gpu::eliminate_data_type_for_gpu"; } | ||
| void apply(module_pass_manager& mpm) const; | ||
| }; | ||
|
|
||
| } // namespace gpu | ||
| } // namespace MIGRAPHX_INLINE_NS | ||
| } // namespace migraphx | ||
|
|
||
| #endif |
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
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.
The device_functions set is missing "scatter_none" and "topk" operations that were present in the original code. These operations were included in the unsupported_fp8fnuz_ops and unsupported_fp8ocp_ops sets in the old implementation but are not included in the new implementation. These should be added to maintain the same behavior as before.