MLIR 22.0.0git
DialectGPU.cpp
Go to the documentation of this file.
1//===- DialectGPU.cpp - Pybind module for the GPU passes ------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===---------------------------------------------------------------------===//
8
10#include "mlir-c/IR.h"
11#include "mlir-c/Support.h"
14
15namespace nb = nanobind;
16using namespace nanobind::literals;
17
18using namespace mlir;
19using namespace mlir::python;
21
22// -----------------------------------------------------------------------------
23// Module initialization.
24// -----------------------------------------------------------------------------
25
26NB_MODULE(_mlirDialectsGPU, m) {
27 m.doc() = "MLIR GPU Dialect";
28 //===-------------------------------------------------------------------===//
29 // AsyncTokenType
30 //===-------------------------------------------------------------------===//
31
32 auto mlirGPUAsyncTokenType =
34
35 mlirGPUAsyncTokenType.def_classmethod(
36 "get",
37 [](const nb::object &cls, MlirContext ctx) {
38 return cls(mlirGPUAsyncTokenTypeGet(ctx));
39 },
40 "Gets an instance of AsyncTokenType in the same context", nb::arg("cls"),
41 nb::arg("ctx") = nb::none());
42
43 //===-------------------------------------------------------------------===//
44 // ObjectAttr
45 //===-------------------------------------------------------------------===//
46
49 "get",
50 [](const nb::object &cls, MlirAttribute target, uint32_t format,
51 const nb::bytes &object,
52 std::optional<MlirAttribute> mlirObjectProps,
53 std::optional<MlirAttribute> mlirKernelsAttr) {
55 static_cast<char *>(const_cast<void *>(object.data())),
56 object.size());
58 mlirAttributeGetContext(target), target, format, objectStrRef,
59 mlirObjectProps.has_value() ? *mlirObjectProps
60 : MlirAttribute{nullptr},
61 mlirKernelsAttr.has_value() ? *mlirKernelsAttr
62 : MlirAttribute{nullptr}));
63 },
64 "cls"_a, "target"_a, "format"_a, "object"_a,
65 "properties"_a = nb::none(), "kernels"_a = nb::none(),
66 "Gets a gpu.object from parameters.")
67 .def_property_readonly(
68 "target",
69 [](MlirAttribute self) { return mlirGPUObjectAttrGetTarget(self); })
70 .def_property_readonly(
71 "format",
72 [](MlirAttribute self) { return mlirGPUObjectAttrGetFormat(self); })
73 .def_property_readonly(
74 "object",
75 [](MlirAttribute self) {
77 return nb::bytes(stringRef.data, stringRef.length);
78 })
79 .def_property_readonly("properties",
80 [](MlirAttribute self) -> nb::object {
82 return nb::cast(
84 return nb::none();
85 })
86 .def_property_readonly("kernels", [](MlirAttribute self) -> nb::object {
88 return nb::cast(mlirGPUObjectAttrGetKernels(self));
89 return nb::none();
90 });
91}
NB_MODULE(_mlirDialectsGPU, m)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAGPUObjectAttr(MlirAttribute attr)
Definition GPU.cpp:34
MLIR_CAPI_EXPORTED MlirAttribute mlirGPUObjectAttrGetTarget(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:70
MLIR_CAPI_EXPORTED MlirAttribute mlirGPUObjectAttrGetProperties(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:95
MLIR_CAPI_EXPORTED bool mlirGPUObjectAttrHasProperties(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:89
MLIR_CAPI_EXPORTED MlirAttribute mlirGPUObjectAttrGetKernels(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:107
MLIR_CAPI_EXPORTED MlirAttribute mlirGPUObjectAttrGetWithKernels(MlirContext mlirCtx, MlirAttribute target, uint32_t format, MlirStringRef objectStrRef, MlirAttribute mlirObjectProps, MlirAttribute mlirKernelsAttr)
Definition GPU.cpp:51
MLIR_CAPI_EXPORTED bool mlirGPUObjectAttrHasKernels(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:101
MLIR_CAPI_EXPORTED MlirType mlirGPUAsyncTokenTypeGet(MlirContext ctx)
Definition GPU.cpp:26
MLIR_CAPI_EXPORTED bool mlirTypeIsAGPUAsyncTokenType(MlirType type)
Definition GPU.cpp:22
MLIR_CAPI_EXPORTED uint32_t mlirGPUObjectAttrGetFormat(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:76
MLIR_CAPI_EXPORTED MlirStringRef mlirGPUObjectAttrGetObject(MlirAttribute mlirObjectAttr)
Definition GPU.cpp:82
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
Definition IR.cpp:1275
Creates a custom subclass of mlir.ir.Attribute, implementing a casting constructor and type checking ...
Creates a custom subclass of mlir.ir.Type, implementing a casting constructor and type checking metho...
pure_subclass & def_classmethod(const char *name, Func &&f, const Extra &...extra)
static MlirStringRef mlirStringRefCreate(const char *str, size_t length)
Constructs a string reference from the pointer and length.
Definition Support.h:82
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:73
const char * data
Pointer to the first symbol.
Definition Support.h:74
size_t length
Length of the fragment.
Definition Support.h:75