diff --git a/Abid_ReadME.txt b/Abid_ReadME.txt deleted file mode 100644 --- a/Abid_ReadME.txt +++ /dev/null @@ -1,87 +0,0 @@ -Start date : May 4th, 2021 ---------------------------- - -How to install LLVM on Mac: -1) There is a problem in installing with libcxxabi and libcxx. So, on my Mac, I installed it with out these two projects. However, I need to understand why it was not building on Mac with the LLVM. It works on Shilie' MacBook - -2) The configuration that works for me: - -cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../llvm -DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld;openmp" -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_INSTALL_PREFIX=/Users/abidmalik/Programming/MLIR_target/llvm-project/myInstall -DCMAKE_CXX_FLAGS="-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ -std=c++14" - -ninja all for builfing -ninja install for installing - -I am not sure about the -DCMAKE_CXX_FLAGS="-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ -std=c++14" flag as I played with it to overcome the problem with libcxxabi and libcxx. I will try to build that same with this flag. - -The build works without the aformentioned flag as well. - -Python3 is required -if there is a problem on Mac about the python instalation check the following website -https://mattbanderson.com/so-you-hosed-your-mac-os-python-install/ - - -May 5th, 2021 --------------- --DCMAKE_CXX_FLAGS="-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ -std=c++14" - -Python 3.* is needed. -On my Mac, the default was Python 2.7. You can alias python = 'Python3' to make the python3 as your default. -** Still need to check why libcxxabi and libcxx could not build on my Mac. However, we donot need them for my MLIR OpenMP dialect work - -May 7th, 2021 --------------- - -When I cmake: The following error was raised: - - -No rule to make target /usr/lib/libz.dylib', needed by `lib/libzip.5.3.dylib'. Stop. - -The solution was found on the following link - -https://stackoverflow.com/questions/62719000/can-not-find-libz-dylib-when-build-libzip-by-homebrew-in-mac-os-10-16-big-sur - -I reinstall the libbz with brew and also use the DZLIB_LIBRARY_RELEASE flag to the library. It works and error was not there. - - -Also an interesting link for building LLVM - -https://lists.llvm.org/pipermail/llvm-dev/2019-September/135333.html - -May 8th, 2021 -============== - -For LLVM_9 , the following configuration work - -cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../llvm -DLLVM_ENABLE_PROJECTS="mlir;clang;clang-tools-extra;lld;openmp" -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_INSTALL_PREFIX=/Users/abidmalik/Programming/LLVM_9/llvm-project/INSATLL -DCMAKE_CXX_FLAGS="-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ -std=c++14" - - -I am not pointing anything. for libz.dylib which is needed for LLVM_11. - -Question: Any reason why? Is it related to the LLVM version? Need to check with the LLVM community. - - - -May 17th, 2021 -=============== - -Build the MLIR with - - -cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=ON ../llvm -DLLVM_ENABLE_PROJECTS=mlir -DLLVM_TARGETS_TO_BUILD="X86;NVPTX;AMDGPU" -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DCMAKE_INSTALL_PREFIX=/Users/abidmalik/Programming/MLIR_target/llvm-project/INSTALL/ -DCMAKE_CXX_FLAGS="-I/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/ -std=c++14" - - -and then - -cmake --build . --target check-mlir - -Now all tests are passing - - -May 18th, 2021 -=============== - -FYI, - -TableGen syntax sometimes can be obscure; reading the generated content can be a very helpful way to understand and debug issues. -To build mlir-tblgen, run cmake --build . --target mlir-tblgen in your build directory and find the mlir-tblgen binary in the bin/ subdirectory. -All the supported generators can be found via mlir-tblgen --help. For example, --gen-op-decls and --gen-op-defs as explained in Generated C++ code . diff --git a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td --- a/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td +++ b/mlir/include/mlir/Dialect/OpenMP/OpenMPOps.td @@ -97,7 +97,7 @@ ]; let parser = [{ return parseParallelOp(parser, result); }]; let printer = [{ return printParallelOp(p, *this); }]; - let verifier = [{ return ::verifyParallelOp(*this); }]; + let verifier = [{ return verifyParallelOp(*this); }]; } def TerminatorOp : OpenMP_Op<"terminator", [Terminator]> { @@ -257,6 +257,58 @@ let assemblyFormat = [{ ( `(` $varList^ `:` type($varList) `)` )? attr-dict}]; } +//===----------------------------------------------------------------------===// +// 2.14.5 target construct +//===----------------------------------------------------------------------===// + +def TargetOp : OpenMP_Op<"target",[AttrSizedOperandSegments]> { + let summary = "target construct"; + let description = [{ + The target construct includes a region of code which is to be executed + on a device. + + The optional $if_expr parameter specifies a boolean result of a + conditional check. If this value is 1 or is not provided then the target + region runs on a device, if it is 0 then the target region is executed on the + host device. + + The optional $device parameter specifies the device number for the target region. + + The optional $thread_limit specifies the limit on the number of threads + + The optional $nowait elliminates the implicit barrier so the parent task can make progress + even if the target task is not yet completed. + + TODO: private, map, is_device_ptr, firstprivate, depend, defaultmap, in_reduction + + }]; + + let arguments = (ins Optional:$if_expr, + Optional:$device, + Optional:$thread_limit, + UnitAttr:$nowait); + + let regions = (region AnyRegion:$region); + + let builders = [ + OpBuilder<(ins "IntegerAttr":$if_expr, + "IntegerAttr":$device, + "IntegerAttr":$thread_limit, + "UnitAttr":$nowait)> + ]; + + let extraClassDeclaration = [{ + static StringRef getIfKeyword() { return "if";} + static StringRef getThreadLimitKeyword() { return "thread_limit";} + static StringRef getDeviceKeyword() { return "device";} + static StringRef getNoWaitKeyword() { return "nowait";} + // TODO: the remaining optional clauses + }]; + + let parser = [{ return parseTargetOp(parser, result); }]; + let printer = [{ return printTargetOp(p, *this); }]; +} + //===----------------------------------------------------------------------===// // 2.16 master Construct diff --git a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp --- a/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp +++ b/mlir/lib/Dialect/OpenMP/IR/OpenMPDialect.cpp @@ -23,7 +23,6 @@ #include #include "mlir/Dialect/OpenMP/OpenMPOpsEnums.cpp.inc" - using namespace mlir; using namespace mlir::omp; @@ -168,7 +167,6 @@ if (auto bind = op.proc_bind_val()) p << " proc_bind(" << bind << ")"; - p.printRegion(op.getRegion()); } @@ -783,5 +781,109 @@ } } +//===----------------------------------------------------------------------===// +// TargetOp +//===----------------------------------------------------------------------===// + +/// Parse a target operation. +/// +/// operation ::= `omp.target' clause-list +/// clause-list ::= clause | clause clause-list +/// clause ::= if | thread_limit | device | nowait +/// if ::= `if` `(` ssa-id `)` +/// thread_limit ::= `thread_limit` `(` ssa-id-and-type `)` +/// device ::= `device` `(`ssa-id-and-type `)` +/// nowait ::= `nowait` +/// TODO: other clauses +/// TODO: Will update as soon as the other clauses will be finalized + +static ParseResult parseTargetOp(OpAsmParser &parser, OperationState &result) { + + std::pair ifCond; + std::pair deviceNum; + std::pair threadLimit; + + // std::array segments{0, 0, 0}; + + SmallVector segments{0, 0, 0}; + + StringRef keyword; + const StringRef opName = result.name.getStringRef(); + + const int ifClausePos = 0; + const int deviceNumPos = 1; + const int threadLimitPos = 2; + + while (succeeded(parser.parseOptionalKeyword(&keyword))) { + if (keyword == TargetOp::getIfKeyword()) { + // Fail if there was already another if condition. + if (segments[ifClausePos]) + return allowedOnce(parser, TargetOp::getIfKeyword(), opName); + if (parser.parseLParen() || parser.parseOperand(ifCond.first) || + parser.parseColonType(ifCond.second) || parser.parseRParen()) + return failure(); + segments[ifClausePos] = 1; + } else if (keyword == TargetOp::getThreadLimitKeyword()) { + // Fail if there was already another thread_limit clause. + if (segments[threadLimitPos]) + return allowedOnce(parser, TargetOp::getThreadLimitKeyword(), opName); + if (parser.parseLParen() || parser.parseOperand(threadLimit.first) || + parser.parseColonType(threadLimit.second) || parser.parseRParen()) + return failure(); + segments[threadLimitPos] = 1; + } else if (keyword == TargetOp::getDeviceKeyword()) { + // Fail if there was already another device clause. + if (segments[deviceNumPos]) + return allowedOnce(parser, TargetOp::getDeviceKeyword(), opName); + if (parser.parseLParen() || parser.parseOperand(deviceNum.first) || + parser.parseColonType(deviceNum.second) || parser.parseRParen()) + return failure(); + segments[deviceNumPos] = 1; + } else if (keyword == TargetOp::getNoWaitKeyword()) { + auto attr = UnitAttr::get(parser.getBuilder().getContext()); + result.addAttribute(TargetOp::getNoWaitKeyword(), attr); + } + } + + if (segments[ifClausePos] && + parser.resolveOperand(ifCond.first, ifCond.second, result.operands)) + return failure(); + + if (segments[threadLimitPos] && + parser.resolveOperand(threadLimit.first, threadLimit.second, + result.operands)) + return failure(); + + if (segments[deviceNumPos] && + parser.resolveOperand(deviceNum.first, deviceNum.second, result.operands)) + return failure(); + + result.addAttribute("operand_segment_sizes", + parser.getBuilder().getI32VectorAttr(segments)); + + Region *body = result.addRegion(); + SmallVector regionArgs; + SmallVector regionArgTypes; + if (parser.parseRegion(*body, regionArgs, regionArgTypes)) + return failure(); + + return success(); +} + +// Print if, device, thread_limit, and nowait +static void printTargetOp(OpAsmPrinter &p, TargetOp op) { + p << "omp.target"; + if (auto ifCond = op.if_expr()) + p << " if (" << ifCond << " : " << ifCond.getType() << ")"; + if (auto threads = op.thread_limit()) + p << " thread_limit (" << threads << " : " << threads.getType() << ")"; + if (auto devices = op.device()) + p << " device (" << devices << " : " << devices.getType() << ")"; + if (op.nowait()) + p << " nowait"; + + p.printRegion(op.getRegion()); +} + #define GET_OP_CLASSES #include "mlir/Dialect/OpenMP/OpenMPOps.cpp.inc" diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -91,7 +91,7 @@ func @omp_parallel_pretty(%data_var : memref, %if_cond : i1, %num_threads : si32, %allocator : si32) -> () { // CHECK: omp.parallel omp.parallel { - omp.terminator + omp.terminator } // CHECK: omp.parallel num_threads(%{{.*}} : si32) @@ -163,7 +163,7 @@ omp.yield }) {operand_segment_sizes = dense<[1,1,1,1,0,0,0,0,0]> : vector<9xi32>, nowait, schedule_val = "Auto"} : (index, index, index, memref) -> () - + return } @@ -278,3 +278,37 @@ return } + +// CHECK-LABEL: omp_target_pretty +func @omp_target_pretty( %if_cond : i1, %device : si32, %thread_limit : si32) -> () { + + // CHECK: omp.target + omp.target { + omp.terminator + } + + // CHECK: omp.target device + omp.target device(%device : si32) { + omp.terminator + } + + // CHECK: omp.target if + omp.target if(%if_cond: i1) { + omp.terminator + } + + // CHECK: omp.target nowait + omp.target nowait { + omp.terminator + } + + // CHECK: omp.target thread_limit + omp.target thread_limit(%thread_limit : si32) { + omp.terminator + } + + // CHECK: omp.barrier + omp.barrier + + return +}