12 Commits

Author SHA1 Message Date
Guray Ozen
a5925eee5a [MLIR][NVVM] Fix register mapping in wgmma.mma_async
WgmmaMmaAsync Op generates `wgmma.mma_async` PTX instruction that uses the same registers as read and write with mapping. Therefore, the registers count needs to be increased 2 times for the following registers.

This works changes this:
```
llvm.inline_asm has_side_effects asm_dialect = att "{wgmma.mma_async... {$0, $1, $2, $3, $4}, $5, $6, p", "=f,=f,=f,=f,0,1,2,3,l,l"
```

Into this one below. The only different is the number of registers ($8 and $9) that comes after read/write.
```
llvm.inline_asm has_side_effects asm_dialect = att "{wgmma.mma_async... {$0, $1, $2, $3, $4}, $8, $9, p", "=f,=f,=f,=f,0,1,2,3,l,l"
```

Reviewed By: qcolombet

Differential Revision: https://reviews.llvm.org/D157843
2023-08-14 14:08:49 +02:00
Guray Ozen
5c3150e584 [MLIR][NVVM] Introduce WGMMA Types
This work introduces `WGMMATypes` attributes for the `WgmmaMmaSyncOp`. This op, having been recently added to MLIR, previously used `MMATypes`. However, there arises a disparity in supported types between `MmaOp` and `WgmmaMmaSyncOp`. To address this discrepancy more effectively, a new set of attributes is introduced.

Furthermore, this patch refines and optimizing the verification mechanisms of `WgmmaMmaSyncOp` Op.

It also adds support for f8 types, including `e4m3` and `e5m2`, within the `WgmmaMmaSyncOp`.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D157695
2023-08-12 12:47:45 +02:00
Matthias Springer
1fdbbd158d [mlir][Conversion] Implement ConvertToLLVMPatternInterface for FuncDialect
Also a new pass option `ConvertToLLVMPass` to populate only patterns from the specified dialects. This is needed because the existing test cases expect that only ops from certain dialects are lowered. (E.g., "arith-to-llvm" expects that only "arith" ops are lowered but not "func" ops.)

Differential Revision: https://reviews.llvm.org/D157627
2023-08-11 10:05:30 +02:00
Guray Ozen
18e161f9e1 [MLIR][NVVM] Introduction of the wgmma.mma_async Op
This work introduces the `wgmma.mma_async` Op along PTX generation using `BasicPtxBuilderOpInterface`. The Op is designed to execute the matrix multiply-and-accumulate operation across a warpgroup (128 threads). It's important to note that this operation works for devices with the sm_90a capability.

The matrix multiply-and-accumulate operation can take one of the following forms. In both cases, matrix D is referred to as the accumulator:
	D = A * B + D 	: Result is added to the accumulator matrix D.
	D = A * B 		: The input from the accumulator matrix D is not utilized.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D157370
2023-08-09 23:08:00 +02:00
Mehdi Amini
4529797a9d Add a generic "convert-to-llvm" pass delegating to an interface
The multiple -convert-XXX-to-llvm passes are really nice testing tools for
individual dialects, but the expectation is that a proper conversion should
assemble the conversion patterns using `populateXXXToLLVMConversionPatterns()
APIs. However most customers just chain the conversion passes by convenience.

This pass makes it composable more transparently to assemble the required
patterns for conversion to LLVM dialect by using an interface.
The Pass will scan the input and collect all the dialect present, and for
those who implement the `ConvertToLLVMPatternInterface` it will use it to
populate the conversion pattern, and possible the conversion target.

Since these conversions can involve intermediate dialects, or target other
dialects than LLVM (for example AVX or NVVM), this pass can't statically
declare the required `getDependentDialects()` before the pass pipeline
begins. This is worked around by using an extension in the dialectRegistry
that will be invoked for every new loaded dialects in the context. This
allows to lookup the interface ahead of time and use it to query the
dependent dialects.

Differential Revision: https://reviews.llvm.org/D157183
2023-08-07 18:46:08 -07:00
Guray Ozen
836dbb8522 [mlir][nvgpu] Add mbarrier.arrive.expect_tx and mbarrier.try_wait.parity
This work adds two Ops:
`mbarrier.arrive.expect_tx` performs expect_tx `mbarrier.barrier` returns `mbarrier.barrier.token`
`mbarrier.try_wait.parity` waits on `mbarrier.barrier` and `mbarrier.barrier.token`

`mbarrier.arrive.expect_tx` is one of the requirement to enable H100 TMA support.

Depends on D154074 D154076 D154059 D154060

Reviewed By: qcolombet

Differential Revision: https://reviews.llvm.org/D154094
2023-07-20 13:48:30 +02:00
Guray Ozen
bf62748342 [mlir][nvvm] Introduce Syncronization Ops for WGMMA
This work introduces : `wgmma.fence.aligned`, `wgmma.commit.group.sync.aligned` and `wgmma.wait.group.sync.aligned` Ops. They are used to syncronize warpgroup level matrix multiply-accumulate instructions, as known as WGMMA.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D155676
2023-07-19 11:45:04 +02:00
Guray Ozen
28555793b1 [mlir][nvvm] Add cp.async.bulk.tensor.shared.cluster.global
This work introduce `cp.async.bulk.tensor.shared.cluster.global` in NVVM dialect that executes load using TMA.

Depends on D155056

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D155060
2023-07-17 17:10:39 +02:00
Guray Ozen
ffbca7e9f3 [mlir][nvvm] Change return type of std::string of getPtx of PtxBuilder
getPtx used to return `const char*`. It is not flexible when one needs to build string in the function. This work changes return type.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D155056
2023-07-12 14:59:54 +02:00
Guray Ozen
221c5fb0a4 [mlir][nvvm] Fix test (NFC)
`ptxas` complains with . in the function name, so we delete. Also, it expects return i64.

Differential Revision: https://reviews.llvm.org/D155054
2023-07-12 14:37:13 +02:00
Guray Ozen
2c5739675c [mlir][nvgpu] Implement nvgpu.device_async_copy by NVVMToLLVM Pass
`nvgpu.device_async_copy` is lowered into `cp.async` PTX instruction. However, NVPTX backend does not support its all mode especially when zero padding is needed. Therefore, current MLIR implementation genereates inline assembly for that.

This work simplifies PTX generation for `nvgpu.device_async_copy`, and implements it by `NVVMToLLVM` Pass.

Depends on D154060

Reviewed By: nicolasvasilache, manishucsd

Differential Revision: https://reviews.llvm.org/D154345
2023-07-11 12:18:28 +02:00
Guray Ozen
dd080c7579 [mlir][nvvm] Add NVVMToLLVM Pass
It introduces an NVVMToLLVM Pass and a `BasicPtxBuilderOpInterface` interface. The Pass performs pattern matching on all the NVVM Ops that implement the BasicPtxBuilderOpInterface interface to generate LLVM Inline Assembly Ops.

The BasicPtxBuilderOpInterface interface is utilized in the convert-nvvm-to-llvm pass, which lowers Ops that support this interface to inline assembly Ops. The interface provides several methods that are used for this lowering.

The `getPtx` method returns PTX code. The `hasSideEffect` method is used to determine whether the op has any side effects on the memory. The `hasIntrinsic` method indicates whether the operation has intrinsic support in LLVM. This is particularly useful for Ops that don't have intrinsic support for each case. The `getAsmValues` method returns the arguments to be passed to the PTX code. The order of arguments starts with the results and they are used for write operations, followed by the operands and attributes.

Example:

If we have the following Op definition that returns PTX code through getPtx:
```tablegen
def NVVM_MBarrierArriveExpectTxOp : NVVM_Op<\"mbarrier.arrive.expect_tx\",
                    [DeclareOpInterfaceMethods<BasicPtxBuilderOpInterface>]>,
  Results<(outs LLVM_Type:$res)>, Arguments<(ins LLVM_i64ptr_any:$addr, I32:$txcount)> {
  ...
  let extraClassDefinition = [{
    const char* $cppClass::getPtx() { return \"mbarrier.arrive.expect_tx.b64 %0, [%1], %2;\"; }
  }\];
}
```

The NVVM Op will look like below:
```mlir
  %0 = nvvm.mbarrier.arrive.expect_tx %barrier, %txcount : !llvm.ptr, i32 -> i32
```

The `convert-nvvm-to-llvm` Pass generates the following PTX code, while keeping the order of arguments the same. The read/write modifiers are set based on the input and result types.
```mlir
  %0 = llvm.inline_asm has_side_effects asm_dialect = att "mbarrier.arrive.expect_tx.b64 %0, [%1], %2;", "=r,l,r" %arg0, %arg1 : (!llvm.ptr, i32) -> i32
```

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D154060
2023-07-11 12:14:24 +02:00