In this PR, I added a C API for each (upstream) MLIR type to retrieve
its type name (for example, `IntegerType` -> `mlirIntegerTypeGetName()`
-> `"builtin.integer"`), and exposed a corresponding `type_name` class
attribute in the Python bindings (e.g., `IntegerType.type_name` ->
`"builtin.integer"`). This can be used in various places to avoid
hard-coded strings, such as eliminating the manual string in
`irdl.base("!builtin.integer")`.
Note that parts of this PR (mainly mechanical changes) were produced via
GitHub Copilot and GPT-5.2. I have manually reviewed the changes and
verified them with tests to ensure correctness.
58 lines
2.1 KiB
C++
58 lines
2.1 KiB
C++
//===--- DialectNVGPU.cpp - Pybind module for NVGPU dialect API support ---===//
|
|
//
|
|
// Part of the LLVM Project, 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir-c/Dialect/NVGPU.h"
|
|
#include "mlir-c/IR.h"
|
|
#include "mlir/Bindings/Python/IRCore.h"
|
|
#include "mlir/Bindings/Python/Nanobind.h"
|
|
#include "mlir/Bindings/Python/NanobindAdaptors.h"
|
|
|
|
namespace nb = nanobind;
|
|
using namespace llvm;
|
|
using namespace mlir::python::nanobind_adaptors;
|
|
|
|
namespace mlir {
|
|
namespace python {
|
|
namespace MLIR_BINDINGS_PYTHON_DOMAIN {
|
|
namespace nvgpu {
|
|
struct TensorMapDescriptorType : PyConcreteType<TensorMapDescriptorType> {
|
|
static constexpr IsAFunctionTy isaFunction =
|
|
mlirTypeIsANVGPUTensorMapDescriptorType;
|
|
static constexpr const char *pyClassName = "TensorMapDescriptorType";
|
|
static inline const MlirStringRef name =
|
|
mlirNVGPUTensorMapDescriptorTypeGetName();
|
|
using Base::Base;
|
|
|
|
static void bindDerived(ClassTy &c) {
|
|
c.def_static(
|
|
"get",
|
|
[](const PyType &tensorMemrefType, int swizzle, int l2promo,
|
|
int oobFill, int interleave, DefaultingPyMlirContext context) {
|
|
return TensorMapDescriptorType(
|
|
context->getRef(), mlirNVGPUTensorMapDescriptorTypeGet(
|
|
context.get()->get(), tensorMemrefType,
|
|
swizzle, l2promo, oobFill, interleave));
|
|
},
|
|
"Gets an instance of TensorMapDescriptorType in the same context",
|
|
nb::arg("tensor_type"), nb::arg("swizzle"), nb::arg("l2promo"),
|
|
nb::arg("oob_fill"), nb::arg("interleave"),
|
|
nb::arg("context").none() = nb::none());
|
|
}
|
|
};
|
|
} // namespace nvgpu
|
|
} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
|
|
} // namespace python
|
|
} // namespace mlir
|
|
|
|
NB_MODULE(_mlirDialectsNVGPU, m) {
|
|
m.doc() = "MLIR NVGPU dialect.";
|
|
|
|
mlir::python::MLIR_BINDINGS_PYTHON_DOMAIN::nvgpu::TensorMapDescriptorType::
|
|
bind(m);
|
|
}
|