This is an archive of the discontinued LLVM Phabricator instance.

[mlir][nvvm] Add lowering of gpu.printf to nvvm
ClosedPublic

Authored by ThomasRaoux on Jan 5 2023, 6:14 AM.

Details

Summary

When converting to nvvm lowering gpu.printf to vprintf allows us to
support printing when running on cuda.

Diff Detail

Event Timeline

ThomasRaoux created this revision.Jan 5 2023, 6:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 5 2023, 6:14 AM
ThomasRaoux requested review of this revision.Jan 5 2023, 6:14 AM
herhut added a comment.Jan 5 2023, 9:55 AM

Nice. Just some comments.

mlir/lib/Conversion/GPUToNVVM/LowerGpuOpsToNVVMOps.cpp
255

nit: why not add this above?

mlir/test/Integration/GPU/CUDA/printf.mlir
17

Could you test this with multiple arguments that have different sizes? I wonder whether your struct packing approach fulfills the alignment requirements for arguments to the vprintf call.

F32 needs to be extended to f64. If you add a test you will see it fails.

mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
381

This same idiom (lines around 380 through 400) is repeated 3 times in this file, so might be useful to outline to helper function?

Since SymbolTable class can't be constructed in the middle of conversion, maybe it would be helpful if this type of function (e.g. getUniqueSymbolName) was added to the OpTrait::SymbolTable class in IR/SymbolTable.h, but maybe that's too heavy handed?

mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
408

F32 needs to be extended to f64 before pushing into struct. If you add a test, you will see it fails for f32 args currently.

Integers need to be extended to 32 bits, but this happens automatically based on my initial test.

mlir/test/Integration/GPU/CUDA/printf.mlir
17

F32 needs to be extended to f64 before pushing into struct. If you add a test, you will see it fails for f32 args currently.

christopherbate requested changes to this revision.Jan 5 2023, 10:14 AM
This revision now requires changes to proceed.Jan 5 2023, 10:14 AM

Address review comments.

ThomasRaoux marked 3 inline comments as done.Jan 5 2023, 1:24 PM
ThomasRaoux added inline comments.
mlir/lib/Conversion/GPUCommon/GPUOpsLowering.cpp
381

moved those in a local helper for now. I'm not sure how common this use case is.

408

Thanks for catching that! It wasn't working indeed. Added FExt for floats.

This revision is now accepted and ready to land.Jan 6 2023, 9:05 AM
This revision was automatically updated to reflect the committed changes.