-
Notifications
You must be signed in to change notification settings - Fork 258
[ROCm] Add ROCDL Dialect. #63
Conversation
|
|
||
| #include "mlir/IR/Dialect.h" | ||
| #include "mlir/IR/OpDefinition.h" | ||
| namespace mlir { |
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.
Add a newline after the includes.
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.
Will revise.
|
|
||
| class ROCDLDialect : public Dialect { | ||
| public: | ||
| explicit ROCDLDialect(MLIRContext *context); |
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.
You'll likely want to provide a static 'getDialectNamespace' utility. This is used by several template mechanisms:
static StringRef getDialectNamespace() { return "..."; }
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.
Will revise.
|
|
||
| #include "llvm/ADT/StringSwitch.h" | ||
|
|
||
| namespace mlir { |
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.
Drop the outer 'mlir' namespace.
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.
Will revise.
|
|
||
| } // anonymous namespace | ||
|
|
||
| FunctionPassBase *createLowerGpuOpsToROCDLOpsPass() { |
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.
This function should be qualified with mlir:: and not within a namespace.
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.
Will revise.
| #include "llvm/Support/SourceMgr.h" | ||
|
|
||
| namespace mlir { | ||
| namespace ROCDL { |
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.
Don't place these within namespaces, prefer explicit qualification + using directives.
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.
Will revise.
| using namespace mlir; | ||
|
|
||
| namespace { | ||
| static llvm::Value *createIntrinsicCall(llvm::IRBuilder<> &builder, |
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.
static methods should be in the top-level namespace.
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.
Will revise.
| // RUN: mlir-opt %s | FileCheck %s | ||
|
|
||
| func @rocdl_special_regs() -> !llvm.i32 { | ||
| // CHECK: %0 = rocdl.workitem.id.x : !llvm.i32 |
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.
Don't check SSA value names directly in tests:
https://github.com/tensorflow/mlir/blob/master/g3doc/TestingGuide.md
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.
@River707 I was following examples depicted at:
https://github.com/tensorflow/mlir/blob/master/test/LLVMIR/nvvm.mlir
How do you recommend to revise the unit test?
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.
For here, it should be enough to just drop the SSA value names, e.g. "%0", from the CHECK lines. The CHECK should as constrained as possible and only focus on testing what is important. The SSA value names here are not related to what you are trying to check, i.e. the custom syntax of the ops.
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.
Thanks. Will revise.
| // RUN: mlir-translate -mlir-to-rocdlir %s | FileCheck %s | ||
|
|
||
| func @rocdl_special_regs() -> !llvm.i32 { | ||
| // CHECK: %1 = call i32 @llvm.amdgcn.workitem.id.x() |
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.
Same here.
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.
Will revise.
|
Make sure to squash all of your changes into one commit. |
|
@River707 Thanks for your quick review! Pretty much all the issues you pointed out are in |
|
Is your question if you should file a PR to cleanup the NVVM dialect? If so that would be awesome, it needs to be cleaned up as well. |
| // ============================================================================= | ||
| // | ||
| // This file implements a pass to generate ROCDLIR operations for higher-level | ||
| // GPU operations. |
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.
This seems like independent from the definition of the dialect, you should be able to split this in a followup PR
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.
ok will split this PR into smaller pieces and file this module as a separate PR.
| // ============================================================================= | ||
| // | ||
| // This file implements a translation between the MLIR LLVM + ROCDL dialects and | ||
| // LLVM IR with ROCDL intrinsics and metadata. |
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.
This seems like another component that I rather review in a separate followup PR from the introduction of the dialect itself.
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.
ok will split this PR into smaller pieces and file this module as a separate PR.
| } | ||
|
|
||
| // This function has the "amdgpu_kernel" calling convention after conversion. | ||
| // CHECK: amdgpu_kernel |
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.
Nit (not super important here, but you may write more tests in the future): in general we separate multiple functions testing with CHECK-LABEL: directives, this helps understand failures when the test fail (and makes FileCheck a bit more robust).
| // limitations under the License. | ||
| // ============================================================================= | ||
| // | ||
| // This file defines the ROCDL IR dialect in MLIR, containing ROCDL operations and |
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.
Nit: this line needs to be wrapped.
| include "mlir/LLVMIR/LLVMOpBase.td" | ||
|
|
||
| def ROCDL_Dialect : Dialect { | ||
| let name = "rocdl"; |
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.
Adding a description regarding this dialect would be nice.
| } | ||
|
|
||
| class ROCDL_Op<string mnemonic, list<OpTrait> traits = []> : | ||
| LLVM_OpBase<ROCDL_Dialect, mnemonic, traits> { |
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.
No need to have the empty {}.
| def ROCDL_BlockIdYOp : ROCDL_SpecialRegisterOp<"workgroup.id.y">; | ||
| def ROCDL_BlockIdZOp : ROCDL_SpecialRegisterOp<"workgroup.id.z">; | ||
|
|
||
| class ROCDL_DeviceFunctionOp<string mnemonic, string device_function, int parameter, |
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.
Nit: can we format this class a bit nicer (proper line wrapping, etc.)?
| // limitations under the License. | ||
| // ============================================================================= | ||
| // | ||
| // This file declares the entry point for the MLIR to LLVM + ROCDL IR conversion. |
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.
Nit: need wrapping here.
| // XOp, YOp and ZOp are assumed to return an `llvm.i32` value. Depending on | ||
| // `indexBitwidth`, sign-extend or truncate the resulting value to match the | ||
| // bitwidth expected by the consumers of the value. | ||
| template <typename XOp, typename YOp, typename ZOp, class Op> |
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.
This file need to be clang-formated.
| newOp = builder.create<ZOp>(loc, LLVM::LLVMType::getInt32Ty(dialect)); | ||
| break; | ||
| default: | ||
| operation.emitError("Illegal dimension: " + operation.dimension()); |
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.
The convention is to start error messages with lowercase letters.
| parser->parseColonType(type)) | ||
| return failure(); | ||
|
|
||
| result->addTypes(type); |
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 think we can do return parser->addTypeToList(type, state->types); here.
|
Hey @whchung, any update? |
|
Closing for now since there hasn't been any activity for a month. Feel free to re-open as needed! |
|
@joker-eph sorry I was focusing on internal tools based on |
|
Good to hear! No hurry, I just closed to keep our open pull-requests count lower as we try to keep an eye on all the active ones. |
Add supporting logic to lower MLIR module into ROCm-Device-Libs (ROCDL) IR.
Follow-up to #57.