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
17 changes: 12 additions & 5 deletions mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,13 @@ def NVVM_FenceScClusterOp : NVVM_Op<"fence.sc.cluster"> {
let assemblyFormat = "attr-dict";
}

defvar MemOrderAcquireOrRelease =
ConfinedAttr<MemOrderKindAttr,
[EnumAttrIsOneOf<MemOrderKindAttr,
[MemOrderKindAcquire, MemOrderKindRelease]>]>;

def NVVM_FenceSyncRestrictOp : NVVM_Op<"fence.sync_restrict">,
Arguments<(ins MemOrderKindAttr:$order)> {
Arguments<(ins MemOrderAcquireOrRelease:$order)> {
let summary = "Uni-directional thread fence operation";
let description = [{
The `nvvm.fence.sync_restrict` Op restricts the class of memory
Expand All @@ -1322,8 +1327,6 @@ def NVVM_FenceSyncRestrictOp : NVVM_Op<"fence.sync_restrict">,
let llvmBuilder = [{
createIntrinsicCall(builder, getFenceSyncRestrictID($order));
}];

let hasVerifier = 1;
}

def NVVM_FenceMbarrierInitOp : NVVM_Op<"fence.mbarrier.init"> {
Expand Down Expand Up @@ -1360,8 +1363,12 @@ def ProxyKindAttr : EnumAttr<NVVM_Dialect, ProxyKind, "proxy_kind"> {
let assemblyFormat = "`<` $value `>`";
}

defvar ProxyKindNotTensormapOrGeneric =
ConfinedAttr<ProxyKindAttr,
[EnumAttrIsNoneOf<ProxyKindAttr, [ProxyTensorMap, ProxyGeneric]>]>;
Comment thread
durga4github marked this conversation as resolved.

def NVVM_FenceProxyOp : NVVM_Op<"fence.proxy">,
Arguments<(ins ProxyKindAttr:$kind,
Arguments<(ins ProxyKindNotTensormapOrGeneric:$kind,
OptionalAttr<SharedSpaceAttr>:$space)> {
let description = [{
Fence operation with proxy to establish an ordering between memory accesses
Expand Down Expand Up @@ -1439,7 +1446,7 @@ def NVVM_FenceProxyReleaseOp : NVVM_Op<"fence.proxy.release">,
}

def NVVM_FenceProxySyncRestrictOp : NVVM_Op<"fence.proxy.sync_restrict">,
Arguments<(ins MemOrderKindAttr:$order,
Arguments<(ins MemOrderAcquireOrRelease:$order,
DefaultValuedAttr<ProxyKindAttr, "ProxyKind::GENERIC">:$fromProxy,
DefaultValuedAttr<ProxyKindAttr, "ProxyKind::async">:$toProxy)> {
let summary = "Uni-directional proxy fence operation with sync_restrict";
Expand Down
31 changes: 31 additions & 0 deletions mlir/include/mlir/IR/EnumAttr.td
Original file line number Diff line number Diff line change
Expand Up @@ -750,4 +750,35 @@ class ConstantEnumCase<Attr attribute, string case>
"attribute must be one of 'EnumAttr' or 'EnumInfo'";
}

/// Attribute constraint restricting the enum attribute to a subset of allowed
/// cases. `enumAttr` is the `EnumAttr` attribute and `allowedCases` is a list
/// of `EnumCase`s that are permitted.
///
/// Example:
/// ```
/// ConfinedAttr<MyEnumAttr, [EnumAttrIsOneOf<MyEnumAttr, [CaseA, CaseB]>]>
/// ```
class EnumAttrIsOneOf<EnumAttr enumAttr, list<EnumCase> allowedCases>
Comment thread
durga4github marked this conversation as resolved.
: AttrConstraint<
Or<!foreach(case, allowedCases,
CPred<"::llvm::cast<" # enumAttr.cppNamespace # "::"
# enumAttr.cppClassName # ">($_self).getValue() == "
# enumAttr.enum.cppType # "::" # case.symbol>)>,
"whose value is one of {"
# !interleave(!foreach(case, allowedCases, case.str), ", ") # "}">;

/// Attribute constraint restricting the enum attribute to exclude a subset of
/// cases. `enumAttr` is the `EnumAttr` attribute and `disallowedCases` is a
/// list of `EnumCase`s that are not permitted.
///
/// Example:
/// ```
/// ConfinedAttr<MyEnumAttr, [EnumAttrIsNoneOf<MyEnumAttr, [CaseA, CaseB]>]>
/// ```
class EnumAttrIsNoneOf<EnumAttr enumAttr, list<EnumCase> disallowedCases>
: AttrConstraint<
Neg<EnumAttrIsOneOf<enumAttr, disallowedCases>.predicate>,
"whose value is none of {"
# !interleave(!foreach(case, disallowedCases, case.str), ", ") # "}">;

#endif // ENUMATTR_TD
15 changes: 0 additions & 15 deletions mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2731,18 +2731,7 @@ bool NVVM::WgmmaMmaAsyncOp::getAsmValues(
return true; // Has manual mapping
}

LogicalResult NVVM::FenceSyncRestrictOp::verify() {
if (getOrder() != NVVM::MemOrderKind::ACQUIRE &&
getOrder() != NVVM::MemOrderKind::RELEASE)
return emitOpError("only acquire and release semantics are supported");
return success();
}

LogicalResult NVVM::FenceProxyOp::verify() {
if (getKind() == NVVM::ProxyKind::TENSORMAP)
return emitOpError() << "tensormap proxy is not a supported proxy kind";
if (getKind() == NVVM::ProxyKind::GENERIC)
return emitOpError() << "generic proxy not a supported proxy kind";
if (getKind() == NVVM::ProxyKind::async_shared && !getSpace().has_value()) {
return emitOpError() << "async_shared fence requires space attribute";
}
Expand Down Expand Up @@ -2775,10 +2764,6 @@ LogicalResult NVVM::FenceProxyReleaseOp::verify() {
}

LogicalResult NVVM::FenceProxySyncRestrictOp::verify() {
if (getOrder() != NVVM::MemOrderKind::ACQUIRE &&
getOrder() != NVVM::MemOrderKind::RELEASE)
return emitOpError("only acquire and release semantics are supported");

if (getFromProxy() != NVVM::ProxyKind::GENERIC)
return emitOpError("only generic is support for from_proxy attribute");

Expand Down
10 changes: 5 additions & 5 deletions mlir/test/Target/LLVMIR/nvvm/fence-invalid.mlir
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
// RUN: mlir-translate --mlir-to-llvmir -verify-diagnostics -split-input-file %s

llvm.func @fence_sync_restrict() {
// expected-error @below {{only acquire and release semantics are supported}}
// expected-error @below {{attribute 'order' failed to satisfy constraint: NVVM Memory Ordering kind whose value is one of {acquire, release}}}
nvvm.fence.sync_restrict {order = #nvvm.mem_order<weak>}
llvm.return
}

// -----

llvm.func @fence_sync_restrict() {
// expected-error @below {{only acquire and release semantics are supported}}
// expected-error @below {{attribute 'order' failed to satisfy constraint: NVVM Memory Ordering kind whose value is one of {acquire, release}}}
nvvm.fence.sync_restrict {order = #nvvm.mem_order<mmio>}
llvm.return
}

// -----

llvm.func @fence_proxy() {
// expected-error @below {{tensormap proxy is not a supported proxy kind}}
// expected-error @below {{attribute 'kind' failed to satisfy constraint: Proxy kind whose value is none of {tensormap, generic}}}
nvvm.fence.proxy {kind = #nvvm.proxy_kind<tensormap>}
llvm.return
}

// -----

llvm.func @fence_proxy() {
// expected-error @below {{generic proxy not a supported proxy kind}}
// expected-error @below {{attribute 'kind' failed to satisfy constraint: Proxy kind whose value is none of {tensormap, generic}}}
nvvm.fence.proxy {kind = #nvvm.proxy_kind<generic>}
llvm.return
}
Expand Down Expand Up @@ -65,7 +65,7 @@ llvm.func @fence_proxy_release() {
// -----

llvm.func @fence_proxy_sync_restrict() {
// expected-error @below {{only acquire and release semantics are supported}}
// expected-error @below {{attribute 'order' failed to satisfy constraint: NVVM Memory Ordering kind whose value is one of {acquire, release}}}
nvvm.fence.proxy.sync_restrict {order = #nvvm.mem_order<mmio>}
llvm.return
}
Expand Down