Skip to content

Commit d62fa8d

Browse files
committed
Adding the ELF section to the NVVMTargetAttr, to propagate to the gpu.binary Op
1 parent e0f3410 commit d62fa8d

File tree

6 files changed

+25
-6
lines changed

6 files changed

+25
-6
lines changed

mlir/include/mlir/Dialect/GPU/Transforms/Passes.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ def GpuNVVMAttachTarget: Pass<"nvvm-attach-target", ""> {
139139
Option<"ftzFlag", "ftz", "bool",
140140
/*default=*/"false",
141141
"Enable flush to zero for denormals.">,
142+
Option<"elfSection", "section", "std::string",
143+
/*default=*/"\"\"",
144+
"ELF section where the module needs to be created.">,
142145
ListOption<"linkLibs", "l", "std::string",
143146
"Extra bitcode libraries paths to link to.">,
144147
];

mlir/include/mlir/Dialect/LLVMIR/NVVMOps.td

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2266,20 +2266,22 @@ def NVVM_TargettAttr : NVVM_Attr<"NVVMTarget", "target"> {
22662266
StringRefParameter<"Target triple.", "\"nvptx64-nvidia-cuda\"">:$triple,
22672267
StringRefParameter<"Target chip.", "\"sm_50\"">:$chip,
22682268
StringRefParameter<"Target chip features.", "\"+ptx60\"">:$features,
2269+
OptionalParameter<"StringAttr", "ELF section.">:$section,
22692270
OptionalParameter<"DictionaryAttr", "Target specific flags.">:$flags,
22702271
OptionalParameter<"ArrayAttr", "Files to link to the LLVM module.">:$link
22712272
);
22722273
let assemblyFormat = [{
2273-
(`<` struct($O, $triple, $chip, $features, $flags, $link)^ `>`)?
2274+
(`<` struct($O, $triple, $chip, $features, $section, $flags, $link)^ `>`)?
22742275
}];
22752276
let builders = [
22762277
AttrBuilder<(ins CArg<"int", "2">:$optLevel,
22772278
CArg<"StringRef", "\"nvptx64-nvidia-cuda\"">:$triple,
22782279
CArg<"StringRef", "\"sm_50\"">:$chip,
22792280
CArg<"StringRef", "\"+ptx60\"">:$features,
2281+
CArg<"StringAttr", "nullptr">:$section,
22802282
CArg<"DictionaryAttr", "nullptr">:$targetFlags,
22812283
CArg<"ArrayAttr", "nullptr">:$linkFiles), [{
2282-
return Base::get($_ctxt, optLevel, triple, chip, features, targetFlags, linkFiles);
2284+
return Base::get($_ctxt, optLevel, triple, chip, features, section, targetFlags, linkFiles);
22832285
}]>
22842286
];
22852287
let skipDefaultBuilders = 1;

mlir/lib/Dialect/GPU/Transforms/NVVMAttachTarget.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ void NVVMAttachTarget::runOnOperation() {
6363
ArrayRef<std::string> libs(linkLibs);
6464
SmallVector<StringRef> filesToLink(libs);
6565
auto target = builder.getAttr<NVVMTargetAttr>(
66-
optLevel, triple, chip, features, getFlags(builder),
66+
optLevel, triple, chip, features,
67+
elfSection.empty() ? nullptr : builder.getStringAttr(elfSection),
68+
getFlags(builder),
6769
filesToLink.empty() ? nullptr : builder.getStrArrayAttr(filesToLink));
6870
llvm::Regex matcher(moduleMatcher);
6971
for (Region &region : getOperation()->getRegions())

mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ LogicalResult NVVMDialect::verifyRegionArgAttribute(Operation *op,
11851185
LogicalResult
11861186
NVVMTargetAttr::verify(function_ref<InFlightDiagnostic()> emitError,
11871187
int optLevel, StringRef triple, StringRef chip,
1188-
StringRef features, DictionaryAttr flags,
1188+
StringRef features, StringAttr elfSection, DictionaryAttr flags,
11891189
ArrayAttr files) {
11901190
if (optLevel < 0 || optLevel > 3) {
11911191
emitError() << "The optimization level must be a number between 0 and 3.";

mlir/lib/Target/LLVM/NVVM/Target.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,18 @@ NVVMTargetAttrImpl::createObject(Attribute attribute, Operation *module,
664664
gpu::CompilationTarget format = options.getCompilationTarget();
665665
DictionaryAttr objectProps;
666666
Builder builder(attribute.getContext());
667+
SmallVector<NamedAttribute, 2> properties;
667668
if (format == gpu::CompilationTarget::Assembly)
668-
objectProps = builder.getDictionaryAttr(
669-
{builder.getNamedAttr("O", builder.getI32IntegerAttr(target.getO()))});
669+
properties.push_back(
670+
builder.getNamedAttr("O", builder.getI32IntegerAttr(target.getO())));
671+
672+
if (StringAttr section = target.getSection())
673+
properties.push_back(
674+
builder.getNamedAttr("section", section));
675+
676+
if (!properties.empty())
677+
objectProps = builder.getDictionaryAttr(properties);
678+
670679
return builder.getAttr<gpu::ObjectAttr>(
671680
attribute, format,
672681
builder.getStringAttr(StringRef(object.data(), object.size())),

mlir/test/Dialect/LLVMIR/attach-targets.mlir

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
// RUN: mlir-opt %s --nvvm-attach-target='module=nvvm.* O=3 chip=sm_90' --rocdl-attach-target='module=rocdl.* O=3 chip=gfx90a' | FileCheck %s
22
// RUN: mlir-opt %s --nvvm-attach-target='module=options.* O=1 chip=sm_70 fast=true ftz=true' --rocdl-attach-target='module=options.* l=file1.bc,file2.bc wave64=false finite-only=true' | FileCheck %s --check-prefix=CHECK_OPTS
3+
// RUN: mlir-opt %s --nvvm-attach-target='module=nvvm.* section=__fatbin' | FileCheck %s --check-prefix=CHECK_SECTION
34

45
module attributes {gpu.container_module} {
56
// Verify the target is appended.
67
// CHECK: @nvvm_module_1 [#nvvm.target<O = 3, chip = "sm_90">] {
8+
// CHECK_SECTION: @nvvm_module_1 [#nvvm.target<section = "__fatbin">]
79
gpu.module @nvvm_module_1 {
810
}
911
// Verify the target is appended.
1012
// CHECK: @nvvm_module_2 [#nvvm.target<chip = "sm_60">, #nvvm.target<O = 3, chip = "sm_90">] {
13+
// CHECK_SECTION: gpu.module @nvvm_module_2 [#nvvm.target<chip = "sm_60">, #nvvm.target<section = "__fatbin">]
1114
gpu.module @nvvm_module_2 [#nvvm.target<chip = "sm_60">] {
1215
}
1316
// Verify the target is not added multiple times.

0 commit comments

Comments
 (0)