summaryrefslogtreecommitdiffstats
path: root/mlir/lib/Dialect/LLVMIR
diff options
context:
space:
mode:
authorDeven Desai <36858332+deven-amd@users.noreply.github.com>2019-09-26 23:49:51 -0700
committerA. Unique TensorFlower <gardener@tensorflow.org>2019-09-27 00:22:32 -0700
commitfee40fef5c37fee2b398d4d6ec28958bf5c0c0f5 (patch)
treee87354a12e4a24d998d8d7592e5bdeb06880c573 /mlir/lib/Dialect/LLVMIR
parent7385d8789560a392971c60426c7d17569551bd32 (diff)
downloadbcm5719-llvm-fee40fef5c37fee2b398d4d6ec28958bf5c0c0f5.tar.gz
bcm5719-llvm-fee40fef5c37fee2b398d4d6ec28958bf5c0c0f5.zip
[ROCm] Adding ROCDL Dialect.
This commit introduces the ROCDL Dialect (i.e. the ROCDL ops + the code to lower those ROCDL ops to LLWM intrinsics/functions). Think of ROCDL Dialect as analogous to the NVVM Dialect, but for AMD GPUs. This patch contains just the essentials needed to get a simple example up and running. We expect to make further additions to the ROCDL Dialect. This is the first of 3 commits, the follow-up will be: * add a pass that lowers GPU Dialect to ROCDL Dialect * add a "mlir-rocm-runner" utility Closes tensorflow/mlir#146 COPYBARA_INTEGRATE_REVIEW=https://github.com/tensorflow/mlir/pull/146 from deven-amd:deven-rocdl-dialect e78e8005c75a78912631116c78dc844fcc4b0de9 PiperOrigin-RevId: 271511259
Diffstat (limited to 'mlir/lib/Dialect/LLVMIR')
-rw-r--r--mlir/lib/Dialect/LLVMIR/CMakeLists.txt9
-rw-r--r--mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp82
2 files changed, 91 insertions, 0 deletions
diff --git a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
index 4469e7606d3..40bcb572e56 100644
--- a/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
+++ b/mlir/lib/Dialect/LLVMIR/CMakeLists.txt
@@ -15,3 +15,12 @@ add_llvm_library(MLIRNVVMIR
)
add_dependencies(MLIRNVVMIR MLIRNVVMOpsIncGen MLIRNVVMConversionsIncGen LLVMAsmParser LLVMCore LLVMSupport)
target_link_libraries(MLIRNVVMIR LLVMAsmParser LLVMCore LLVMSupport)
+
+add_llvm_library(MLIRROCDLIR
+ IR/ROCDLDialect.cpp
+
+ ADDITIONAL_HEADER_DIRS
+ ${MLIR_MAIN_INCLUDE_DIR}/mlir/Dialect/LLVMIR
+ )
+add_dependencies(MLIRROCDLIR MLIRROCDLOpsIncGen MLIRROCDLConversionsIncGen LLVMAsmParser LLVMCore LLVMSupport)
+target_link_libraries(MLIRROCDLIR LLVMAsmParser LLVMCore LLVMSupport)
diff --git a/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
new file mode 100644
index 00000000000..075e01d1dfc
--- /dev/null
+++ b/mlir/lib/Dialect/LLVMIR/IR/ROCDLDialect.cpp
@@ -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.
+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
OpenPOWER on IntegriCloud