Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit b7ed6ff

Browse files
fabianmcgjoker-eph
andauthored
[mlir][gpu] Add metadata attributes for storing kernel metadata in GPU objects (#95292)
This patch adds the `#gpu.kernel_metadata` and `#gpu.kernel_table` attributes. The `#gpu.kernel_metadata` attribute allows storing metadata related to a compiled kernel, for example, the number of scalar registers used by the kernel. The attribute only has 2 required parameters, the name and function type. It also has 2 optional parameters, the arguments attributes and generic dictionary for storing all other metadata. The `#gpu.kernel_table` stores a table of `#gpu.kernel_metadata`, mapping the name of the kernel to the metadata. Finally, the function `ROCDL::getAMDHSAKernelsELFMetadata` was added to collect ELF metadata from a binary, and to test the class methods in both attributes. Example: ```mlir gpu.binary @binary [#gpu.object<#rocdl.target<chip = "gfx900">, kernels = #gpu.kernel_table<[ #gpu.kernel_metadata<"kernel0", (i32) -> (), metadata = {sgpr_count = 255}>, #gpu.kernel_metadata<"kernel1", (i32, f32) -> (), arg_attrs = [{llvm.read_only}, {}]> ]> , bin = "BLOB">] ``` The motivation behind these attributes is to provide useful information for things like tunning. --------- Co-authored-by: Mehdi Amini <[email protected]>
1 parent a951960 commit b7ed6ff

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

DialectGPU.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,21 @@ PYBIND11_MODULE(_mlirDialectsGPU, m) {
4848
.def_classmethod(
4949
"get",
5050
[](py::object cls, MlirAttribute target, uint32_t format,
51-
py::bytes object, std::optional<MlirAttribute> mlirObjectProps) {
51+
py::bytes object, std::optional<MlirAttribute> mlirObjectProps,
52+
std::optional<MlirAttribute> mlirKernelsAttr) {
5253
py::buffer_info info(py::buffer(object).request());
5354
MlirStringRef objectStrRef =
5455
mlirStringRefCreate(static_cast<char *>(info.ptr), info.size);
55-
return cls(mlirGPUObjectAttrGet(
56+
return cls(mlirGPUObjectAttrGetWithKernels(
5657
mlirAttributeGetContext(target), target, format, objectStrRef,
5758
mlirObjectProps.has_value() ? *mlirObjectProps
59+
: MlirAttribute{nullptr},
60+
mlirKernelsAttr.has_value() ? *mlirKernelsAttr
5861
: MlirAttribute{nullptr}));
5962
},
6063
"cls"_a, "target"_a, "format"_a, "object"_a,
61-
"properties"_a = py::none(), "Gets a gpu.object from parameters.")
64+
"properties"_a = py::none(), "kernels"_a = py::none(),
65+
"Gets a gpu.object from parameters.")
6266
.def_property_readonly(
6367
"target",
6468
[](MlirAttribute self) { return mlirGPUObjectAttrGetTarget(self); })
@@ -71,9 +75,16 @@ PYBIND11_MODULE(_mlirDialectsGPU, m) {
7175
MlirStringRef stringRef = mlirGPUObjectAttrGetObject(self);
7276
return py::bytes(stringRef.data, stringRef.length);
7377
})
74-
.def_property_readonly("properties", [](MlirAttribute self) {
75-
if (mlirGPUObjectAttrHasProperties(self))
76-
return py::cast(mlirGPUObjectAttrGetProperties(self));
78+
.def_property_readonly("properties",
79+
[](MlirAttribute self) {
80+
if (mlirGPUObjectAttrHasProperties(self))
81+
return py::cast(
82+
mlirGPUObjectAttrGetProperties(self));
83+
return py::none().cast<py::object>();
84+
})
85+
.def_property_readonly("kernels", [](MlirAttribute self) {
86+
if (mlirGPUObjectAttrHasKernels(self))
87+
return py::cast(mlirGPUObjectAttrGetKernels(self));
7788
return py::none().cast<py::object>();
7889
});
7990
}

0 commit comments

Comments
 (0)