Skip to content

Commit 8527ee1

Browse files
committed
added tests and passthrough discardable attrs
1 parent 5d7a281 commit 8527ee1

File tree

7 files changed

+42
-9
lines changed

7 files changed

+42
-9
lines changed

mlir/include/mlir/Dialect/GPU/IR/GPUDialect.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ class SparseSpGEMMOpHandleType
202202

203203
static constexpr StringLiteral name = "gpu.sparse.spgemmop_handle";
204204
};
205-
206205
} // namespace gpu
207206
} // namespace mlir
208207

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -598,13 +598,16 @@ NVVMTargetAttrImpl::createObject(Attribute attribute, Operation *module,
598598
const gpu::TargetOptions &options) const {
599599
auto target = cast<NVVMTargetAttr>(attribute);
600600
gpu::CompilationTarget format = options.getCompilationTarget();
601-
DictionaryAttr objectProps;
601+
DictionaryAttr objectProps = module->getDiscardableAttrDictionary();
602602
Builder builder(attribute.getContext());
603-
if (format == gpu::CompilationTarget::Assembly)
604-
objectProps = builder.getDictionaryAttr(
605-
{builder.getNamedAttr("O", builder.getI32IntegerAttr(target.getO()))});
603+
if (format == gpu::CompilationTarget::Assembly) {
604+
SmallVector<NamedAttribute, 1> attrs(objectProps.getValue());
605+
attrs.push_back(
606+
builder.getNamedAttr("O", builder.getI32IntegerAttr(target.getO())));
607+
objectProps = builder.getDictionaryAttr(attrs);
608+
}
606609
return builder.getAttr<gpu::ObjectAttr>(
607610
attribute, format,
608611
builder.getStringAttr(StringRef(object.data(), object.size())),
609-
objectProps);
612+
objectProps.empty() ? nullptr : objectProps);
610613
}

mlir/lib/Target/LLVM/ROCDL/Target.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,10 +477,12 @@ ROCDLTargetAttrImpl::createObject(Attribute attribute, Operation *module,
477477
const SmallVector<char, 0> &object,
478478
const gpu::TargetOptions &options) const {
479479
gpu::CompilationTarget format = options.getCompilationTarget();
480+
DictionaryAttr objectProps = module->getDiscardableAttrDictionary();
480481
Builder builder(attribute.getContext());
481482
return builder.getAttr<gpu::ObjectAttr>(
482483
attribute,
483484
format > gpu::CompilationTarget::Binary ? gpu::CompilationTarget::Binary
484485
: format,
485-
builder.getStringAttr(StringRef(object.data(), object.size())), nullptr);
486+
builder.getStringAttr(StringRef(object.data(), object.size())),
487+
objectProps.empty() ? nullptr : objectProps);
486488
}

mlir/lib/Target/SPIRV/Target.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ SPIRVTargetAttrImpl::createObject(Attribute attribute, Operation *module,
9393
const SmallVector<char, 0> &object,
9494
const gpu::TargetOptions &options) const {
9595
gpu::CompilationTarget format = options.getCompilationTarget();
96-
DictionaryAttr objectProps;
96+
DictionaryAttr objectProps = module->getDiscardableAttrDictionary();
9797
Builder builder(attribute.getContext());
9898
return builder.getAttr<gpu::ObjectAttr>(
9999
attribute, format,
100100
builder.getStringAttr(StringRef(object.data(), object.size())),
101-
objectProps);
101+
objectProps.empty() ? nullptr : objectProps);
102102
}

mlir/test/Dialect/GPU/module-to-binary-nvvm.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,14 @@ module attributes {gpu.container_module} {
3434
llvm.return
3535
}
3636
}
37+
38+
// CHECK-LABEL:gpu.binary @kernel_module4
39+
// CHECK-ISA:[#gpu.object<#nvvm.target<flags = {fast}>, properties = {O = 2 : i32, gpu.reg_count = 255 : i32}, assembly = "{{.*}}">]
40+
gpu.module @kernel_module4 [#nvvm.target<flags = {fast}>] attributes {gpu.reg_count = 255 : i32} {
41+
llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr,
42+
%arg2: !llvm.ptr, %arg3: i64, %arg4: i64,
43+
%arg5: i64) attributes {gpu.kernel} {
44+
llvm.return
45+
}
46+
}
3747
}

mlir/test/Dialect/GPU/module-to-binary-rocdl.mlir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,14 @@ module attributes {gpu.container_module} {
2222
llvm.return
2323
}
2424
}
25+
26+
// CHECK-LABEL:gpu.binary @kernel_module3
27+
// CHECK-ISA:[#gpu.object<#rocdl.target<flags = {fast}>, properties = {gpu.reg_count = 255 : i32}, assembly = "{{.*}}">]
28+
gpu.module @kernel_module3 [#rocdl.target<flags = {fast}>] attributes {gpu.reg_count = 255 : i32} {
29+
llvm.func @kernel(%arg0: i32, %arg1: !llvm.ptr,
30+
%arg2: !llvm.ptr, %arg3: i64, %arg4: i64,
31+
%arg5: i64) attributes {gpu.kernel} {
32+
llvm.return
33+
}
34+
}
2535
}

mlir/test/Dialect/GPU/module-to-binary-spirv.mlir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,13 @@ module attributes {gpu.container_module} {
1010
}
1111
}
1212
}
13+
// CHECK-LABEL:gpu.binary @kernel_module1
14+
// CHECK:[#gpu.object<#spirv.target_env<#spirv.vce<v1.0, [Int64, Int16, Kernel, Addresses], []>, #spirv.resource_limits<>>, properties = {gpu.reg_count = 255 : i32}, "{{.*}}">]
15+
gpu.module @kernel_module1 [#spirv.target_env<#spirv.vce<v1.0, [Int64, Int16, Kernel, Addresses], []>, #spirv.resource_limits<>>] attributes {gpu.reg_count = 255 : i32} {
16+
spirv.module @__spv__kernel_module Physical64 OpenCL requires #spirv.vce<v1.0, [Int64, Int16, Kernel, Addresses], []> attributes {spirv.target_env = #spirv.target_env<#spirv.vce<v1.0, [Addresses, Float16Buffer, Int64, Int16, Int8, Kernel, Linkage, Vector16, GenericPointer, Groups, Float16, Float64, AtomicFloat32AddEXT, ExpectAssumeKHR], [SPV_EXT_shader_atomic_float_add, SPV_KHR_expect_assume, SPV_AMD_shader_ballot]>, api=OpenCL, #spirv.resource_limits<>>} {
17+
spirv.func @test_kernel(%arg0: !spirv.ptr<!spirv.array<200 x i16>, CrossWorkgroup>, %arg1: !spirv.ptr<!spirv.array<200 x i16>, CrossWorkgroup>, %arg2: !spirv.ptr<!spirv.array<200 x i16>, CrossWorkgroup>) "None" attributes {workgroup_attributions = 0 : i64} {
18+
spirv.Return
19+
}
20+
}
21+
}
1322
}

0 commit comments

Comments
 (0)