This is an archive of the discontinued LLVM Phabricator instance.

[mlir][sparse][gpu] add result type to spmv, spmm and sddmm gpu libgen path
ClosedPublic

Authored by K-Wu on May 26 2023, 2:46 PM.

Diff Detail

Event Timeline

K-Wu created this revision.May 26 2023, 2:46 PM
K-Wu updated this revision to Diff 526220.May 26 2023, 4:26 PM

rm redundant namespaces

K-Wu updated this revision to Diff 526228.May 26 2023, 5:59 PM

add computeType in tblgen

K-Wu updated this revision to Diff 526238.May 26 2023, 9:14 PM

working implementation though a bit ugly

K-Wu published this revision for review.May 26 2023, 9:15 PM
K-Wu added reviewers: aartbik, wrengr, bixia, Peiming.
Herald added a project: Restricted Project. · View Herald Transcript
K-Wu updated this revision to Diff 526289.May 27 2023, 1:34 PM

rebase origin/main and add sddmm

K-Wu retitled this revision from [mlir][sparse][gpu] add result type to spmv and spmm gpu libgen path to [mlir][sparse][gpu] add result type to spmv, spmm and sddmm gpu libgen path.May 27 2023, 1:35 PM
K-Wu updated this revision to Diff 526292.May 27 2023, 1:44 PM

fixed compile errors

aartbik added inline comments.May 27 2023, 1:53 PM
mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp
232–233

this can go now, right?

232–233

shall we do the same for index to be consistent?

K-Wu updated this revision to Diff 526294.May 27 2023, 4:00 PM

should be minor

K-Wu added inline comments.May 30 2023, 12:31 PM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1289

Seeking ways for easier-to-read literal comparison

K-Wu updated this revision to Diff 526752.May 30 2023, 12:57 PM

using the API Wren suggested

K-Wu updated this revision to Diff 526754.May 30 2023, 12:58 PM

rebase origin/main

Peiming added inline comments.May 30 2023, 1:00 PM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1289

You should be able to perform the compare without type conversion. It is essentially a pointer comparison and they will share the same underlying storage if they are equal.

wrengr added inline comments.May 30 2023, 1:13 PM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1287–1292

It would be cleaner to just call getConstantIntValue once and save the results. I've attached an edit to show what I mean. (Though really, there's not a whole lot of benefit to the dw_ variable, so you might as well just use *dw directly wherever needed)

Though really this whole pattern should be floated out to a helper function, including the parts that check *dw and return the corresponding FloatType— since the only difference between the version here and the version for mgpuCreateCOO is which op.getOperand is used.

1290

Since gpu::CreateDnMatOp::getMemref returns a TypedValue<MemRefType>, the TypedValue<MemRefType>::getType method will already return a MemRefType, therefore you don't need the llvm::cast

1296–1305

This is yet another place that uses the same function for converting a Value (which has LLVM::ConstantOp defining op) into the appropriate FloatType...

1331–1332

You can replace this with just computeTypeOptional.value_or(defaultType) https://en.cppreference.com/w/cpp/utility/optional/value_or

can you please add some examples to the ops.mlir for proper roundtrippnig

mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
1863

ah, good catch on this typo!

1891

I think it is more common in MLIR to put the result type at the end with a :

as in

... : f64

Peiming added inline comments.May 30 2023, 1:19 PM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1284–1285

I don't think you need it (same below for getDnxxx)

K-Wu updated this revision to Diff 526793.May 30 2023, 2:19 PM

simpler get element type func

K-Wu marked an inline comment as done.May 30 2023, 2:19 PM
K-Wu added inline comments.
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1289

I wish I could have known it earlier. Thank you!

K-Wu marked an inline comment as done.May 30 2023, 2:20 PM
K-Wu marked 2 inline comments as done.
K-Wu marked 2 inline comments as done.May 30 2023, 2:28 PM
K-Wu marked an inline comment as done.
K-Wu updated this revision to Diff 526797.May 30 2023, 2:30 PM

rm unnecessary MemRefType cast

K-Wu updated this revision to Diff 526842.May 30 2023, 4:19 PM

clean up the code a bit

K-Wu updated this revision to Diff 526846.May 30 2023, 4:42 PM

fix to pass tests

K-Wu marked 2 inline comments as done.May 30 2023, 4:49 PM
K-Wu updated this revision to Diff 526864.May 30 2023, 6:23 PM

upd format; add roundtrip test

K-Wu added inline comments.May 30 2023, 6:25 PM
mlir/test/Dialect/GPU/sparse-roundtrip.mlir
43

Hi @aartbik , I added a round-trip test where the new syntax : computeType is tested. Let me know what you think. Thanks!

K-Wu updated this revision to Diff 526899.May 30 2023, 10:04 PM

refactor index type as well

K-Wu marked an inline comment as done.May 30 2023, 10:05 PM
Peiming added inline comments.May 31 2023, 9:00 AM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1297

nit: maybe renaming to getConstInt32From?

1303–1304

No longer needed?

1311

nit: getConstInt32xxx

K-Wu updated this revision to Diff 527093.May 31 2023, 9:44 AM
K-Wu marked an inline comment as done.

addressing comments

K-Wu updated this revision to Diff 527094.May 31 2023, 9:44 AM

rebase origin/main

K-Wu marked 2 inline comments as done.May 31 2023, 9:44 AM
K-Wu added inline comments.
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
1303–1304

Good catch! Addressed in new commit

K-Wu added a comment.May 31 2023, 12:54 PM

Build 364523 failed due to upload failure and is not caused by the code/test itself

aartbik added inline comments.May 31 2023, 2:57 PM
mlir/include/mlir/Dialect/GPU/IR/GPUOps.td
1912

make this Examples

and add an op below that has a compute type set

1997

given the mix of return types and other types, an "into" feels a bit nicer for compute type.
also, do we perhaps simply want to make compute type non-optional and always show it?

mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
691

Start with capital C and end with period

mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp
304

this TODO is done, right?

K-Wu marked 3 inline comments as done.May 31 2023, 3:19 PM
K-Wu added inline comments.
mlir/lib/ExecutionEngine/CudaRuntimeWrappers.cpp
304

Good catch. Thanks!

K-Wu marked an inline comment as done.May 31 2023, 3:20 PM
K-Wu updated this revision to Diff 527210.May 31 2023, 3:22 PM

addressing comments

K-Wu marked an inline comment as done.May 31 2023, 3:22 PM
K-Wu updated this revision to Diff 527224.May 31 2023, 4:15 PM

fix compile errors

K-Wu updated this revision to Diff 527226.May 31 2023, 4:16 PM

rebase origin/main

Peiming added inline comments.Jun 1 2023, 9:19 AM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
694

Here and Below: Do you think it is better to copy the CUSPARSE macro to the file (but probably adding some prefix) so that it can be updated more easily later? Or does the current way already follows the same convention in the file?

K-Wu added inline comments.Jun 1 2023, 9:31 AM
mlir/lib/Conversion/GPUCommon/GPUToLLVMConversion.cpp
694

It is kind of the reverse. Here we map types to integers, but in the cuda header files these enum class definitions are essentially mapping types to an integer, I.e., assigning an integer to each enum item. You raise a good point that we need to have better way to keep in sync, though the CUDA headers seem to keep the mapping of already existing types the same when adding new types probably as a way to keep backward compatibility. I will need to think about how to do that in the future.

aartbik accepted this revision.Jun 1 2023, 10:03 AM
This revision is now accepted and ready to land.Jun 1 2023, 10:03 AM
K-Wu updated this revision to Diff 527476.Jun 1 2023, 10:06 AM

rebase origin/main

This revision was landed with ongoing or failed builds.Jun 1 2023, 10:17 AM
This revision was automatically updated to reflect the committed changes.