Skip to content
Merged
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 src/targets/gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ add_library(migraphx_gpu
compile_pointwise.cpp
compiler.cpp
device_name.cpp
eliminate_data_type_for_gpu.cpp
fixed_pad.cpp
fuse_ck.cpp
fuse_mlir.cpp
Expand Down
159 changes: 159 additions & 0 deletions src/targets/gpu/eliminate_data_type_for_gpu.cpp
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",
Copy link

Copilot AI Jan 13, 2026

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.

Suggested change
"argmin",
"argmin",
"scatter_none",
"topk",

Copilot uses AI. Check for mistakes.
};

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
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
88 changes: 2 additions & 86 deletions src/targets/gpu/target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <migraphx/eliminate_allocation.hpp>
#include <migraphx/eliminate_concat.hpp>
#include <migraphx/eliminate_contiguous.hpp>
#include <migraphx/eliminate_data_type.hpp>
#include <migraphx/eliminate_identity.hpp>
#include <migraphx/eliminate_pad.hpp>
#include <migraphx/fp8_ocp_to_fnuz.hpp>
Expand Down Expand Up @@ -67,6 +66,7 @@
#include <migraphx/gpu/concat_gpu_opt.hpp>
#include <migraphx/gpu/context.hpp>
#include <migraphx/gpu/device_name.hpp>
#include <migraphx/gpu/eliminate_data_type_for_gpu.hpp>
#include <migraphx/gpu/fuse_ck.hpp>
#include <migraphx/gpu/fuse_mlir.hpp>
#include <migraphx/gpu/fuse_ops.hpp>
Expand Down Expand Up @@ -96,86 +96,6 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
auto& ctx = any_cast<context>(gctx);
ctx.set_exhaustive_tune_flag(options.exhaustive_tune);
ctx.load_problem_cache();
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::fp8e4m3fnuz_type);
unsupported_types.erase(shape::type_t::fp8e5m2fnuz_type);
unsupported_types.erase(shape::type_t::fp8e4m3fn_type);
unsupported_types.erase(shape::type_t::fp8e5m2_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::tuple_type);

// No BF-16 Support on Navi21
if(gpu::gfx_has_bf16_intrinsics())
{
unsupported_types.erase(shape::type_t::bf16_type);
}

// whiltelist supported Ops for the FP8 types
std::set<std::string> unsupported_fp8fnuz_ops = {};

// disable dot & quant_dot if no hipblaslt
if(not hipblaslt_supported())
{
unsupported_fp8fnuz_ops.insert("dot");
unsupported_fp8fnuz_ops.insert("quant_dot");
}

#if MIGRAPHX_USE_MIOPEN // MIOpen doesn't have support for fp8 pooling yet.
unsupported_fp8fnuz_ops.insert("pooling");
#endif
if(not gpu::gfx_has_fp8fnuz_intrinsics())
{
unsupported_fp8fnuz_ops.insert("dot");
unsupported_fp8fnuz_ops.insert("quant_dot");
unsupported_fp8fnuz_ops.insert("convolution");
unsupported_fp8fnuz_ops.insert("quant_convolution");
}
// add all device kernels
unsupported_fp8fnuz_ops.insert("logsoftmax");
unsupported_fp8fnuz_ops.insert("nonzero");
unsupported_fp8fnuz_ops.insert("prefix_scan_sum");
unsupported_fp8fnuz_ops.insert("scatter_none");
unsupported_fp8fnuz_ops.insert("topk");
unsupported_fp8fnuz_ops.insert("rnn_var_sl_shift_output");
unsupported_fp8fnuz_ops.insert("multinomial");
unsupported_fp8fnuz_ops.insert("argmax");
unsupported_fp8fnuz_ops.insert("argmin");

std::set<std::string> unsupported_fp8ocp_ops = {};

// disable dot & quant_dot if no hipblaslt
if(not hipblaslt_supported())
{
unsupported_fp8ocp_ops.insert("dot");
unsupported_fp8ocp_ops.insert("quant_dot");
}

#if MIGRAPHX_USE_MIOPEN
// MIOpen doesn't have support for fp8 pooling yet.
unsupported_fp8ocp_ops.insert("pooling");
#endif
if(not gpu::gfx_has_fp8ocp_intrinsics())
{
unsupported_fp8ocp_ops.insert("convolution");
unsupported_fp8ocp_ops.insert("quant_convolution");
unsupported_fp8ocp_ops.insert("dot");
unsupported_fp8ocp_ops.insert("quant_dot");
}
// add all device kernels
unsupported_fp8ocp_ops.insert("logsoftmax");
unsupported_fp8ocp_ops.insert("nonzero");
unsupported_fp8ocp_ops.insert("prefix_scan_sum");
unsupported_fp8ocp_ops.insert("scatter_none");
unsupported_fp8ocp_ops.insert("topk");
unsupported_fp8ocp_ops.insert("rnn_var_sl_shift_output");
unsupported_fp8ocp_ops.insert("multinomial");
unsupported_fp8ocp_ops.insert("argmax");
unsupported_fp8ocp_ops.insert("argmin");

// clang-format off
return
Expand All @@ -195,9 +115,7 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
dead_code_elimination{},
rewrite_rnn{},
dead_code_elimination{},
// workaround for rocBLAS unsupported error when using uint8 in quant_dot, quant_convolution & pooling
eliminate_data_type{{migraphx::shape::uint8_type}, shape::float_type, {"quant_convolution", "quant_dot", "pooling"}},
eliminate_data_type{unsupported_types, shape::type_t::float_type},
eliminate_data_type_for_gpu{},
simplify_reshapes{},
eliminate_identity{},
eliminate_pad{},
Expand All @@ -213,8 +131,6 @@ std::vector<pass> target::get_passes(migraphx::context& gctx, const compile_opti
dead_code_elimination{},
prefuse_ops{},
dead_code_elimination{},
eliminate_data_type{{migraphx::shape::fp8e4m3fnuz_type, migraphx::shape::fp8e5m2fnuz_type}, shape::float_type, unsupported_fp8fnuz_ops},
eliminate_data_type{{migraphx::shape::fp8e4m3fn_type, migraphx::shape::fp8e5m2_type}, shape::float_type, unsupported_fp8ocp_ops},
dead_code_elimination{},
rewrite_reduce{},
rewrite_topk{},
Expand Down
Loading