-
Notifications
You must be signed in to change notification settings - Fork 14.8k
[mlir][amdgpu] Introduce assume_subgroup_uniform
op
#152740
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
Closed
Closed
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,12 +9,13 @@ | |||||
#ifndef AMDGPU | ||||||
#define AMDGPU | ||||||
|
||||||
include "mlir/IR/EnumAttr.td" | ||||||
include "mlir/IR/OpBase.td" | ||||||
include "mlir/IR/Properties.td" | ||||||
include "mlir/Interfaces/InferIntRangeInterface.td" | ||||||
include "mlir/Interfaces/InferTypeOpInterface.td" | ||||||
include "mlir/Interfaces/SideEffectInterfaces.td" | ||||||
include "mlir/Interfaces/ViewLikeInterface.td" | ||||||
include "mlir/IR/EnumAttr.td" | ||||||
include "mlir/IR/Properties.td" | ||||||
include "mlir/IR/OpBase.td" | ||||||
|
||||||
def AMDGPU_Dialect : Dialect { | ||||||
let name = "amdgpu"; | ||||||
|
@@ -635,6 +636,37 @@ def AMDGPU_DPPOp : AMDGPU_Op<"dpp", | |||||
let hasVerifier = 1; | ||||||
} | ||||||
|
||||||
def AMDGPU_AssumeSubgroupUniformOp : AMDGPU_Op<"assume_subgroup_uniform", | ||||||
[NoMemoryEffect, AllTypesMatch<["result", "src"]>, | ||||||
DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>, | ||||||
DeclareOpInterfaceMethods<ConditionallySpeculatable, ["getSpeculatability"]>] # | ||||||
ElementwiseMappable.traits>, | ||||||
Arguments<(ins AnyType:$src, | ||||||
DefaultValuedAttr<UnitAttr, "false">:$all_lanes)> { | ||||||
let summary = "Assumes value is unform across the lanes in subgroup"; | ||||||
let description = [{ | ||||||
This op is a compiler hint to help backend put values into scalar registers. | ||||||
|
||||||
If `src` value is uniform across all the active subgroup lanes it is | ||||||
returned unchanged, otherwise result is poison. | ||||||
|
||||||
If `all_lanes` is set, the value is assumed to be uniform across all the | ||||||
subgroup lanes, this can allow to speculate it out of control flow, which | ||||||
may change the current active lanes, i.e: | ||||||
``` | ||||||
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.
Suggested change
|
||||||
// %value must be uniform at this point | ||||||
%value = ... | ||||||
scf.if lane_id < 13 { | ||||||
%uniform = amdgpu.assume_subgroup_uniform all_lanes %value | ||||||
} | ||||||
``` | ||||||
}]; | ||||||
let results = (outs AnyType:$result); | ||||||
let assemblyFormat = [{ | ||||||
(`all_lanes` $all_lanes^)? $src attr-dict `:` type($result) | ||||||
}]; | ||||||
} | ||||||
|
||||||
def AMDGPU_SwizzleBitModeOp : AMDGPU_Op<"swizzle_bitmode", | ||||||
[Pure, AllTypesMatch<["result", "src"]>]>, | ||||||
Arguments<(ins AnyIntegerOrFloatOr1DVector:$src, | ||||||
|
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
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,13 @@ | ||
// RUN: mlir-opt --arith-int-range-narrowing="int-bitwidths-supported=32" --split-input-file %s | FileCheck %s | ||
|
||
// CHECK-LABEL: func @narrow | ||
// CHECK: %[[SRC:.*]] = test.with_bounds {smax = 10 : index, smin = 0 : index, umax = 10 : index, umin = 0 : index} : index | ||
// CHECK: %[[CAST1:.*]] = arith.index_castui %[[SRC]] : index to i32 | ||
// CHECK: %[[VAL:.*]] = amdgpu.assume_subgroup_uniform %[[CAST1]] : i32 | ||
// CHECK: %[[CAST2:.*]] = arith.index_castui %[[VAL]] : i32 to index | ||
// CHECK: return %[[CAST2]] : index | ||
func.func @narrow() -> index { | ||
%0 = test.with_bounds { umin = 0 : index, umax = 10 : index, smin = 0 : index, smax = 10 : index } : index | ||
%1 = amdgpu.assume_subgroup_uniform %0 : index | ||
return %1: index | ||
} |
21 changes: 21 additions & 0 deletions
21
mlir/test/Dialect/AMDGPU/subgroup-uniform-speculability.mlir
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,21 @@ | ||
// RUN: mlir-opt %s --loop-invariant-code-motion | FileCheck %s | ||
|
||
func.func private @side_effect(%arg0 : f32, %arg1 : f32) | ||
|
||
// CHECK-LABEL: func @assume_subgroup_uniform_hoisting | ||
// CHECK-SAME: (%[[ARG:.*]]: f32) | ||
func.func @assume_subgroup_uniform_hoisting(%arg0 : f32) { | ||
%c0 = arith.constant 0 : index | ||
%c1 = arith.constant 1 : index | ||
%c10 = arith.constant 10 : index | ||
// CHECK: %[[V1:.*]] = amdgpu.assume_subgroup_uniform all_lanes %[[ARG]] : f32 | ||
// CHECK: scf.for | ||
// CHECK: %[[V0:.*]] = amdgpu.assume_subgroup_uniform %[[ARG]] : f32 | ||
// CHECK: func.call @side_effect(%[[V0]], %[[V1]]) | ||
scf.for %i = %c0 to %c10 step %c1 { | ||
%0 = amdgpu.assume_subgroup_uniform %arg0 : f32 | ||
%1 = amdgpu.assume_subgroup_uniform all_lanes %arg0 : f32 | ||
func.call @side_effect(%0, %1) : (f32, f32) -> () | ||
} | ||
func.return | ||
} |
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 don't understand why this isn't the only allowed scenario? If it does not have to be uniform, I think we should call it
get_first_lane