llvm-project/mlir/lib/Bindings/Python/DialectNVGPU.cpp
Maksim Levental ee3338d135
[mlir][Python] port in-tree dialect extensions to use MLIRPythonSupport (#174156)
This PR ports all in-tree dialect extensions to use the
`PyConcreteType`, `PyConcreteAttribute` CRTPs instead of
`mlir_pure_subclass`. After this PR we can soft deprecate
`mlir_pure_subclass`. Also API signatures are updated to use `Py*`
instead of `Mlir*` so that type "inference" and hints are improved.
2026-01-05 10:23:22 -08:00

56 lines
2.0 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";
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);
}