-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[MLIR][GPU] Add xevm-attach-target transform pass. #147372
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
f2fd80a
b82816a
62db26d
39b3471
17f139a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,88 @@ | ||||||
//===-- XeVMAttachTarget.cpp - DESC -----------------------------*- C++ -*-===// | ||||||
adam-smnk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// | ||||||
// This file is licensed under the Apache License v2.0 with LLVM Exceptions. | ||||||
// See https://llvm.org/LICENSE.txt for license information. | ||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||
// | ||||||
//===----------------------------------------------------------------------===// | ||||||
// | ||||||
// This file implements the `GpuXeVMAttachTarget` pass, attaching `#xevm.target` | ||||||
// attributes to GPU modules. | ||||||
// | ||||||
//===----------------------------------------------------------------------===// | ||||||
|
||||||
#include "mlir/Dialect/GPU/Transforms/Passes.h" | ||||||
|
||||||
#include "mlir/Dialect/GPU/IR/GPUDialect.h" | ||||||
#include "mlir/Dialect/LLVMIR/XeVMDialect.h" | ||||||
#include "mlir/IR/Builders.h" | ||||||
#include "mlir/Pass/Pass.h" | ||||||
#include "llvm/Support/Regex.h" | ||||||
|
||||||
namespace mlir { | ||||||
#define GEN_PASS_DEF_GPUXEVMATTACHTARGET | ||||||
#include "mlir/Dialect/GPU/Transforms/Passes.h.inc" | ||||||
} // namespace mlir | ||||||
|
||||||
using namespace mlir; | ||||||
using namespace mlir::xevm; | ||||||
|
||||||
namespace { | ||||||
struct XeVMAttachTarget | ||||||
: public mlir::impl::GpuXeVMAttachTargetBase<XeVMAttachTarget> { | ||||||
using Base::Base; | ||||||
|
||||||
DictionaryAttr getFlags(OpBuilder &builder) const; | ||||||
|
||||||
void runOnOperation() override; | ||||||
|
||||||
void getDependentDialects(DialectRegistry ®istry) const override { | ||||||
registry.insert<mlir::xevm::XeVMDialect>(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe no need to use explicit namespaces because they already imported? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed |
||||||
} | ||||||
}; | ||||||
} // namespace | ||||||
|
||||||
DictionaryAttr XeVMAttachTarget::getFlags(OpBuilder &builder) const { | ||||||
SmallVector<NamedAttribute, 3> flags; | ||||||
// Tokenize and set the optional command line options. | ||||||
if (!cmdOptions.empty()) { | ||||||
auto options = gpu::TargetOptions::tokenizeCmdOptions(cmdOptions); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please mention the type and avoid using Refer to LLVM coding manuals for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replaced |
||||||
if (!options.second.empty()) { | ||||||
llvm::SmallVector<mlir::Attribute> xevmOptionAttrs; | ||||||
for (const char *opt : options.second) { | ||||||
xevmOptionAttrs.emplace_back( | ||||||
mlir::StringAttr::get(builder.getContext(), StringRef(opt))); | ||||||
} | ||||||
flags.push_back(builder.getNamedAttr( | ||||||
"cmd-options", | ||||||
mlir::ArrayAttr::get(builder.getContext(), xevmOptionAttrs))); | ||||||
} | ||||||
} | ||||||
|
||||||
if (!flags.empty()) | ||||||
return builder.getDictionaryAttr(flags); | ||||||
return nullptr; | ||||||
} | ||||||
|
||||||
void XeVMAttachTarget::runOnOperation() { | ||||||
OpBuilder builder(&getContext()); | ||||||
ArrayRef<std::string> libs(linkLibs); | ||||||
SmallVector<StringRef> filesToLink(libs); | ||||||
auto target = builder.getAttr<mlir::xevm::XeVMTargetAttr>( | ||||||
adam-smnk marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
optLevel, triple, chip, getFlags(builder), | ||||||
filesToLink.empty() ? nullptr : builder.getStrArrayAttr(filesToLink)); | ||||||
llvm::Regex matcher(moduleMatcher); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the name is empty, do you just attach to all GPU modules? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't get your question. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think so. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now after updates, this should be the behavior here as well. |
||||||
// Check if the name of the module matches. | ||||||
auto gpuModule = cast<gpu::GPUModuleOp>(getOperation()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both NV and ROC similar methods iterate through regions and basic blocks, but your definition above specified There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both NV and ROC also assume that the attachment logic will only be applied to GPU modules:
as indicated by their pass description itself:
This PR decided to rely on the MLIR pass infrastructure for traversal. If you think we should follow nv/roc, please consider responding to the comment below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated logic to match nvvm, rocdl and other attach-target passes. |
||||||
if (!moduleMatcher.empty() && !matcher.match(gpuModule.getName())) | ||||||
return; | ||||||
// Create the target array. | ||||||
SmallVector<Attribute> targets; | ||||||
if (std::optional<ArrayAttr> attrs = gpuModule.getTargets()) | ||||||
targets.append(attrs->getValue().begin(), attrs->getValue().end()); | ||||||
targets.push_back(target); | ||||||
// Remove any duplicate targets. | ||||||
targets.erase(llvm::unique(targets), targets.end()); | ||||||
// Update the target attribute array. | ||||||
gpuModule.setTargetsAttr(builder.getArrayAttr(targets)); | ||||||
} |
Uh oh!
There was an error while loading. Please reload this page.