This repository was archived by the owner on Apr 23, 2021. It is now read-only.
-
Couldn't load subscription status.
- Fork 258
[ROCm] Adding ROCDL Dialect. #146
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| //===- ROCDLDialect.h - MLIR ROCDL IR dialect -------------------*- C++ -*-===// | ||
| // | ||
| // Copyright 2019 The MLIR Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ============================================================================= | ||
| // | ||
| // This file defines the ROCDL dialect in MLIR, containing ROCDL operations | ||
| // and ROCDL specific extensions to the LLVM type system. | ||
| // | ||
| // Unfortunately there does not exists a formal definition of ROCDL IR that be | ||
| // pointed to here. However the following links contain more information about | ||
| // ROCDL (ROCm-Device-Library) | ||
| // | ||
| // https://github.com/RadeonOpenCompute/ROCm-Device-Libs/blob/master/doc/OCML.md | ||
| // https://github.com/RadeonOpenCompute/ROCm-Device-Libs/blob/master/doc/OCKL.md | ||
| // https://llvm.org/docs/AMDGPUUsage.html | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ | ||
| #define MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ | ||
|
|
||
| #include "mlir/IR/Dialect.h" | ||
| #include "mlir/IR/OpDefinition.h" | ||
|
|
||
| namespace mlir { | ||
| namespace ROCDL { | ||
|
|
||
| ///// Ops ///// | ||
| #define GET_OP_CLASSES | ||
| #include "mlir/Dialect/LLVMIR/ROCDLOps.h.inc" | ||
|
|
||
| class ROCDLDialect : public Dialect { | ||
| public: | ||
| explicit ROCDLDialect(MLIRContext *context); | ||
|
|
||
| static StringRef getDialectNamespace() { return "rocdl"; } | ||
| }; | ||
|
|
||
| } // namespace ROCDL | ||
| } // namespace mlir | ||
|
|
||
| #endif /* MLIR_DIALECT_LLVMIR_ROCDLDIALECT_H_ */ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| //===-- ROCDLOps.td - ROCDL IR dialect op definition file --*- tablegen -*-===// | ||
| // | ||
| // Copyright 2019 The MLIR Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ============================================================================= | ||
| // | ||
| // This is the ROCDL IR operation definition file. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifdef ROCDLIR_OPS | ||
| #else | ||
| #define ROCDLIR_OPS | ||
|
|
||
| include "mlir/Dialect/LLVMIR/LLVMOpBase.td" | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ROCDL dialect definitions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| def ROCDL_Dialect : Dialect { | ||
| let name = "rocdl"; | ||
| let cppNamespace = "ROCDL"; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ROCDL op definitions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class ROCDL_Op<string mnemonic, list<OpTrait> traits = []> : | ||
| LLVM_OpBase<ROCDL_Dialect, mnemonic, traits> { | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ROCDL special register op definitions | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| class ROCDL_SpecialRegisterOp<string mnemonic, | ||
| list<OpTrait> traits = []> : | ||
| ROCDL_Op<mnemonic, !listconcat(traits, [NoSideEffect])>, | ||
| Results<(outs LLVM_Type:$res)>, Arguments<(ins)> { | ||
| string llvmBuilder = "$res = createIntrinsicCall(builder," | ||
| # "llvm::Intrinsic::amdgcn_" # !subst(".","_", mnemonic) # ");"; | ||
| let parser = [{ return parseROCDLOp(parser, result); }]; | ||
| let printer = [{ printROCDLOp(p, this->getOperation()); }]; | ||
| } | ||
|
|
||
| class ROCDL_DeviceFunctionOp<string mnemonic, string device_function, | ||
| int parameter, list<OpTrait> traits = []> : | ||
| ROCDL_Op<mnemonic, !listconcat(traits, [NoSideEffect])>, | ||
| Results<(outs LLVM_Type:$res)>, Arguments<(ins)> { | ||
| string llvmBuilder = "$res = createDeviceFunctionCall(builder, \"" | ||
| # device_function # "\", " # parameter # ");"; | ||
| let parser = [{ return parseROCDLOp(parser, result); }]; | ||
| let printer = [{ printROCDLOp(p, this->getOperation()); }]; | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Thread index and Block index | ||
|
|
||
| def ROCDL_ThreadIdXOp : ROCDL_SpecialRegisterOp<"workitem.id.x">; | ||
| def ROCDL_ThreadIdYOp : ROCDL_SpecialRegisterOp<"workitem.id.y">; | ||
| def ROCDL_ThreadIdZOp : ROCDL_SpecialRegisterOp<"workitem.id.z">; | ||
|
|
||
| def ROCDL_BlockIdXOp : ROCDL_SpecialRegisterOp<"workgroup.id.x">; | ||
| def ROCDL_BlockIdYOp : ROCDL_SpecialRegisterOp<"workgroup.id.y">; | ||
| def ROCDL_BlockIdZOp : ROCDL_SpecialRegisterOp<"workgroup.id.z">; | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Thread range and Block range | ||
|
|
||
| def ROCDL_BlockDimXOp : ROCDL_DeviceFunctionOp<"workgroup.dim.x", | ||
| "__ockl_get_local_size", 0>; | ||
|
|
||
| def ROCDL_BlockDimYOp : ROCDL_DeviceFunctionOp<"workgroup.dim.y", | ||
| "__ockl_get_local_size", 1>; | ||
|
|
||
| def ROCDL_BlockDimZOp : ROCDL_DeviceFunctionOp<"workgroup.dim.z", | ||
| "__ockl_get_local_size", 2>; | ||
|
|
||
| def ROCDL_GridDimXOp : ROCDL_DeviceFunctionOp<"grid.dim.x", | ||
| "__ockl_get_global_size", 0>; | ||
|
|
||
| def ROCDL_GridDimYOp : ROCDL_DeviceFunctionOp<"grid.dim.y", | ||
| "__ockl_get_global_size", 1>; | ||
|
|
||
| def ROCDL_GridDimZOp : ROCDL_DeviceFunctionOp<"grid.dim.z", | ||
| "__ockl_get_global_size", 2>; | ||
|
|
||
|
|
||
| #endif // ROCDLIR_OPS |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| //===- ROCDLIR.h - MLIR to LLVM + ROCDL IR conversion -----------*- C++ -*-===// | ||
| // | ||
| // Copyright 2019 The MLIR Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ============================================================================= | ||
| // | ||
| // This file declares the entry point for the MLIR to LLVM + ROCDL IR | ||
| // conversion. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef MLIR_TARGET_ROCDLIR_H | ||
| #define MLIR_TARGET_ROCDLIR_H | ||
|
|
||
| #include <memory> | ||
|
|
||
| // Forward-declare LLVM classses. | ||
| namespace llvm { | ||
| class Module; | ||
| } // namespace llvm | ||
|
|
||
| namespace mlir { | ||
| class ModuleOp; | ||
|
|
||
| /// Convert the given MLIR module into ROCDL IR. This conversion requires the | ||
| /// registration of the LLVM IR dialect and will extract the LLVM context | ||
| /// from the registered LLVM IR dialect. In case of error, report it | ||
| /// to the error handler registered with the MLIR context, if any (obtained from | ||
| /// the MLIR module), and return `nullptr`. | ||
| std::unique_ptr<llvm::Module> translateModuleToROCDLIR(ModuleOp m); | ||
|
|
||
| } // namespace mlir | ||
|
|
||
| #endif // MLIR_TARGET_ROCDLIR_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| //===- ROCDLDialect.cpp - ROCDL IR Ops and Dialect registration -----------===// | ||
| // | ||
| // Copyright 2019 The MLIR Authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // ============================================================================= | ||
| // | ||
| // This file defines the types and operation details for the ROCDL IR dialect in | ||
| // MLIR, and the LLVM IR dialect. It also registers the dialect. | ||
| // | ||
| // The ROCDL dialect only contains GPU specific additions on top of the general | ||
| // LLVM dialect. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "mlir/Dialect/LLVMIR/ROCDLDialect.h" | ||
|
|
||
| #include "mlir/Dialect/LLVMIR/LLVMDialect.h" | ||
| #include "mlir/IR/Builders.h" | ||
| #include "mlir/IR/MLIRContext.h" | ||
| #include "mlir/IR/Operation.h" | ||
| #include "mlir/IR/StandardTypes.h" | ||
| #include "llvm/AsmParser/Parser.h" | ||
| #include "llvm/IR/Attributes.h" | ||
| #include "llvm/IR/Function.h" | ||
| #include "llvm/IR/Type.h" | ||
| #include "llvm/Support/SourceMgr.h" | ||
|
|
||
| namespace mlir { | ||
| namespace ROCDL { | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // Printing/parsing for ROCDL ops | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| static void printROCDLOp(OpAsmPrinter &p, Operation *op) { | ||
| p << op->getName() << " "; | ||
| p.printOperands(op->getOperands()); | ||
| if (op->getNumResults() > 0) | ||
| interleaveComma(op->getResultTypes(), p << " : "); | ||
| } | ||
|
|
||
| // <operation> ::= `rocdl.XYZ` : type | ||
| static ParseResult parseROCDLOp(OpAsmParser &parser, OperationState &result) { | ||
| Type type; | ||
| return failure(parser.parseOptionalAttributeDict(result.attributes) || | ||
| parser.parseColonType(type) || | ||
| parser.addTypeToList(type, result.types)); | ||
| } | ||
|
|
||
| //===----------------------------------------------------------------------===// | ||
| // ROCDLDialect initialization, type parsing, and registration. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| // TODO(herhut): This should be the llvm.rocdl dialect once this is supported. | ||
deven-amd marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ROCDLDialect::ROCDLDialect(MLIRContext *context) : Dialect("rocdl", context) { | ||
| addOperations< | ||
| #define GET_OP_LIST | ||
| #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" | ||
| >(); | ||
|
|
||
| // Support unknown operations because not all ROCDL operations are registered. | ||
| allowUnknownOperations(); | ||
| } | ||
|
|
||
| #define GET_OP_CLASSES | ||
| #include "mlir/Dialect/LLVMIR/ROCDLOps.cpp.inc" | ||
|
|
||
| static DialectRegistration<ROCDLDialect> rocdlDialect; | ||
|
|
||
| } // namespace ROCDL | ||
| } // namespace mlir | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.