Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions mlir/include/mlir/Dialect/GPU/IR/CompilationInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ class TargetOptions {
/// Returns the default compilation target: `CompilationTarget::Fatbin`.
static CompilationTarget getDefaultCompilationTarget();

/// Returns a tokenization of the command line options.
static std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>>
tokenizeCmdOptions(const std::string &cmdOptions);

protected:
/// Derived classes must use this constructor to initialize `typeID` to the
/// appropiate value: ie. `TargetOptions(TypeID::get<DerivedClass>())`.
Expand Down
3 changes: 3 additions & 0 deletions mlir/include/mlir/Dialect/GPU/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ def GpuNVVMAttachTarget: Pass<"nvvm-attach-target", ""> {
Option<"ftzFlag", "ftz", "bool",
/*default=*/"false",
"Enable flush to zero for denormals.">,
Option<"nvvmOptions", "nvvm-options", "std::string",
/*default=*/ [{""}],
"Options passed to libnvvm">,
ListOption<"linkLibs", "l", "std::string",
"Extra bitcode libraries paths to link to.">,
];
Expand Down
7 changes: 6 additions & 1 deletion mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2564,7 +2564,7 @@ CompilationTarget TargetOptions::getDefaultCompilationTarget() {
}

std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>>
TargetOptions::tokenizeCmdOptions() const {
TargetOptions::tokenizeCmdOptions(const std::string &cmdOptions) {
std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>> options;
llvm::StringSaver stringSaver(options.first);
StringRef opts = cmdOptions;
Expand All @@ -2586,6 +2586,11 @@ TargetOptions::tokenizeCmdOptions() const {
return options;
}

std::pair<llvm::BumpPtrAllocator, SmallVector<const char *>>
TargetOptions::tokenizeCmdOptions() const {
return tokenizeCmdOptions(cmdOptions);
}

MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::gpu::TargetOptions)

#include "mlir/Dialect/GPU/IR/GPUOpInterfaces.cpp.inc"
Expand Down
15 changes: 14 additions & 1 deletion mlir/lib/Dialect/GPU/Transforms/NVVMAttachTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,27 @@ struct NVVMAttachTarget

DictionaryAttr NVVMAttachTarget::getFlags(OpBuilder &builder) const {
UnitAttr unitAttr = builder.getUnitAttr();
SmallVector<NamedAttribute, 2> flags;
SmallVector<NamedAttribute, 3> flags;
auto addFlag = [&](StringRef flag) {
flags.push_back(builder.getNamedAttr(flag, unitAttr));
};
if (fastFlag)
addFlag("fast");
if (ftzFlag)
addFlag("ftz");
if (!nvvmOptions.empty()) {
auto options = gpu::TargetOptions::tokenizeCmdOptions(nvvmOptions);
if (!options.second.empty()) {
llvm::SmallVector<mlir::Attribute> nvvmOptionAttrs;
for (const char *opt : options.second) {
nvvmOptionAttrs.emplace_back(
mlir::StringAttr::get(builder.getContext(), StringRef(opt)));
}
flags.push_back(builder.getNamedAttr(
"libNVVMOptions",
mlir::ArrayAttr::get(builder.getContext(), nvvmOptionAttrs)));
}
}
if (!flags.empty())
return builder.getDictionaryAttr(flags);
return nullptr;
Expand Down
15 changes: 15 additions & 0 deletions mlir/test/Dialect/GPU/nvvm-attach-target.mlir
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// RUN: mlir-opt %s --nvvm-attach-target="" | FileCheck %s
// RUN: mlir-opt %s --nvvm-attach-target="nvvm-options=-opt=1" | FileCheck %s -check-prefix=CHECK-OPTIONS

module attributes {gpu.container_module} {
// CHECK-LABEL:gpu.module @kernel_module1
// CHECK: [#nvvm.target]
// CHECK-OPTIONS:[#nvvm.target<flags = {libNVVMOptions = ["-opt=1"]}>]
gpu.module @kernel_module1 {
llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr,
%arg2: !llvm.ptr, %arg3: i64, %arg4: i64,
%arg5: i64) attributes {gpu.kernel} {
llvm.return
}
}
}