From c91dfae8132ead0923bf71301ed8b424b07e81b0 Mon Sep 17 00:00:00 2001 From: Paul Date: Thu, 19 Sep 2024 13:43:27 -0500 Subject: [PATCH 1/3] Enable attention by default on mi300 --- src/targets/gpu/fuse_mlir.cpp | 7 +++++-- src/targets/gpu/include/migraphx/gpu/fuse_mlir.hpp | 1 - 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/targets/gpu/fuse_mlir.cpp b/src/targets/gpu/fuse_mlir.cpp index b541963380c..6d04216e824 100644 --- a/src/targets/gpu/fuse_mlir.cpp +++ b/src/targets/gpu/fuse_mlir.cpp @@ -125,11 +125,14 @@ static bool specific_op(std::string_view option, bool fallback = false) return contains(options, option); } -bool mlir_attention_enabled() +bool mlir_attention_enabled(context* ctx) { #ifdef MIGRAPHX_MLIR if(not mlir_enabled()) return false; + // Enable attention by default for mi300 + if(starts_with(ctx->get_current_device().get_gfx_name(), "gfx94")) + return true; return specific_op("attention"); #else return false; @@ -892,7 +895,7 @@ void fuse_mlir::apply(module_pass_manager& mpm) const }; // Attention offloads; default disabled - if(mlir_attention_enabled() or enable_extra) + if(mlir_attention_enabled(ctx) or enable_extra) { match::find_matches(mpm, find_mlir_attention_fused_ops{mlir_mode::all}); mpm.run_pass(dead_code_elimination{}); diff --git a/src/targets/gpu/include/migraphx/gpu/fuse_mlir.hpp b/src/targets/gpu/include/migraphx/gpu/fuse_mlir.hpp index c7ee06a564a..6a7966db892 100644 --- a/src/targets/gpu/include/migraphx/gpu/fuse_mlir.hpp +++ b/src/targets/gpu/include/migraphx/gpu/fuse_mlir.hpp @@ -34,7 +34,6 @@ struct module_pass_manager; namespace gpu { MIGRAPHX_GPU_EXPORT bool mlir_enabled(); -MIGRAPHX_GPU_EXPORT bool mlir_attention_enabled(); struct MIGRAPHX_GPU_EXPORT fuse_mlir { From 0b43d153026714588cf7a0dc8865407ddb029497 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 16 Oct 2024 15:45:27 -0700 Subject: [PATCH 2/3] Avoid null pointers --- src/targets/gpu/fuse_mlir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targets/gpu/fuse_mlir.cpp b/src/targets/gpu/fuse_mlir.cpp index 174ea2275c1..8db6be38c5e 100644 --- a/src/targets/gpu/fuse_mlir.cpp +++ b/src/targets/gpu/fuse_mlir.cpp @@ -131,7 +131,7 @@ bool mlir_attention_enabled(context* ctx) if(not mlir_enabled()) return false; // Enable attention by default for mi300 - if(starts_with(ctx->get_current_device().get_gfx_name(), "gfx94")) + if(ctx and starts_with(ctx->get_current_device().get_gfx_name(), "gfx94")) return true; return specific_op("attention"); #else From 95409973efd8d4d8956aa6f60a8663780ff0edb1 Mon Sep 17 00:00:00 2001 From: Paul Date: Wed, 16 Oct 2024 15:50:11 -0700 Subject: [PATCH 3/3] Fix tidy issue --- src/targets/gpu/fuse_mlir.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/targets/gpu/fuse_mlir.cpp b/src/targets/gpu/fuse_mlir.cpp index 8db6be38c5e..12cf8b8dcb9 100644 --- a/src/targets/gpu/fuse_mlir.cpp +++ b/src/targets/gpu/fuse_mlir.cpp @@ -131,7 +131,7 @@ bool mlir_attention_enabled(context* ctx) if(not mlir_enabled()) return false; // Enable attention by default for mi300 - if(ctx and starts_with(ctx->get_current_device().get_gfx_name(), "gfx94")) + if(ctx != nullptr and starts_with(ctx->get_current_device().get_gfx_name(), "gfx94")) return true; return specific_op("attention"); #else