MLIR 23.0.0git
IRAttributes.h
Go to the documentation of this file.
1//===- IRAttributes.h - Exports builtin and standard attributes -----------===//
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
9#ifndef MLIR_BINDINGS_PYTHON_IRATTRIBUTES_H
10#define MLIR_BINDINGS_PYTHON_IRATTRIBUTES_H
11
12#include <optional>
13#include <string>
14#include <string_view>
15#include <utility>
16#include <vector>
17
19#include "mlir-c/BuiltinTypes.h"
24
25namespace mlir {
26namespace python {
28
30 void *ptr = nullptr;
31 Py_ssize_t itemsize = 0;
32 Py_ssize_t size = 0;
33 const char *format = nullptr;
34 Py_ssize_t ndim = 0;
35 std::vector<Py_ssize_t> shape;
36 std::vector<Py_ssize_t> strides;
37 bool readonly = false;
38
40 void *ptr, Py_ssize_t itemsize, const char *format, Py_ssize_t ndim,
41 std::vector<Py_ssize_t> shape_in, std::vector<Py_ssize_t> strides_in,
42 bool readonly = false,
43 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)> owned_view_in =
44 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)>(nullptr, nullptr));
45
46 explicit nb_buffer_info(Py_buffer *view)
47 : nb_buffer_info(view->buf, view->itemsize, view->format, view->ndim,
48 {view->shape, view->shape + view->ndim},
49 // TODO(phawkins): check for null strides
50 {view->strides, view->strides + view->ndim},
51 view->readonly != 0,
52 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)>(
53 view, PyBuffer_Release)) {}
54
55 nb_buffer_info(const nb_buffer_info &) = delete;
59
60private:
61 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)> owned_view;
62};
63
64class MLIR_PYTHON_API_EXPORTED nb_buffer : public nanobind::object {
65 NB_OBJECT_DEFAULT(nb_buffer, object, "Buffer", PyObject_CheckBuffer);
66
67 nb_buffer_info request() const;
68};
69
70template <typename T>
72
74 : public PyConcreteAttribute<PyAffineMapAttribute> {
75public:
77 static constexpr const char *pyClassName = "AffineMapAttr";
82
83 static void bindDerived(ClassTy &c);
84};
85
87 : public PyConcreteAttribute<PyIntegerSetAttribute> {
88public:
90 static constexpr const char *pyClassName = "IntegerSetAttr";
95
96 static void bindDerived(ClassTy &c);
97};
98
99template <typename T>
100static T pyTryCast(nanobind::handle object) {
101 try {
102 return nanobind::cast<T>(object);
103 } catch (std::exception &err) {
104 if (object.is_none()) {
105 std::string msg = std::string("Invalid attribute (None?) when attempting "
106 "to create an ArrayAttribute (") +
107 err.what() + ")";
108 throw std::runtime_error(msg.c_str());
109 }
110 std::string msg = std::string("Invalid attribute when attempting to "
111 "create an ArrayAttribute (") +
112 err.what() + ")";
113 throw std::runtime_error(msg.c_str());
114 }
115}
116
117/// A python-wrapped dense array attribute with an element type and a derived
118/// implementation class.
119template <typename EltTy, typename DerivedT>
121 : public PyConcreteAttribute<DerivedT> {
122public:
124
125 /// Iterator over the integer elements of a dense array.
127 public:
128 PyDenseArrayIterator(PyAttribute attr) : attr(std::move(attr)) {}
129
130 /// Return a copy of the iterator.
132
133 /// Return the next element.
134 EltTy dunderNext() {
135 // Throw if the index has reached the end.
136 if (nextIndex >= mlirDenseArrayGetNumElements(attr.get()))
137 throw nanobind::stop_iteration();
138 return DerivedT::getElement(attr.get(), nextIndex++);
139 }
140
141 /// Bind the iterator class.
142 static void bind(nanobind::module_ &m) {
143 nanobind::class_<PyDenseArrayIterator>(m, DerivedT::pyIteratorName)
144 .def("__iter__", &PyDenseArrayIterator::dunderIter)
145 .def("__next__", &PyDenseArrayIterator::dunderNext);
146 }
147
148 private:
149 /// The referenced dense array attribute.
150 PyAttribute attr;
151 /// The next index to read.
152 int nextIndex = 0;
153 };
154
155 /// Get the element at the given index.
156 EltTy getItem(intptr_t i) { return DerivedT::getElement(*this, i); }
157
158 /// Bind the attribute class.
160 // Bind the constructor.
161 if constexpr (std::is_same_v<EltTy, bool>) {
162 c.def_static(
163 "get",
164 [](const nanobind::sequence &py_values, DefaultingPyMlirContext ctx) {
165 std::vector<bool> values;
166 for (nanobind::handle py_value : py_values) {
167 int is_true = PyObject_IsTrue(py_value.ptr());
168 if (is_true < 0) {
169 throw nanobind::python_error();
170 }
171 values.push_back(is_true);
172 }
173 return getAttribute(values, ctx->getRef());
174 },
175 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
176 "Gets a uniqued dense array attribute");
177 } else {
178 c.def_static(
179 "get",
180 [](const std::vector<EltTy> &values, DefaultingPyMlirContext ctx) {
181 return getAttribute(values, ctx->getRef());
182 },
183 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
184 "Gets a uniqued dense array attribute");
185 }
186 // Bind the array methods.
187 c.def("__getitem__", [](DerivedT &arr, intptr_t i) {
188 if (i >= mlirDenseArrayGetNumElements(arr))
189 throw nanobind::index_error("DenseArray index out of range");
190 return arr.getItem(i);
191 });
192 c.def("__len__", [](const DerivedT &arr) {
194 });
195 c.def("__iter__",
196 [](const DerivedT &arr) { return PyDenseArrayIterator(arr); });
197 c.def("__add__", [](DerivedT &arr, const nanobind::sequence &extras) {
198 std::vector<EltTy> values;
199 intptr_t numOldElements = mlirDenseArrayGetNumElements(arr);
200 values.reserve(numOldElements + nanobind::len(extras));
201 for (intptr_t i = 0; i < numOldElements; ++i)
202 values.push_back(arr.getItem(i));
203 for (nanobind::handle attr : extras)
204 values.push_back(pyTryCast<EltTy>(attr));
205 return getAttribute(values, arr.getContext());
206 });
207 }
208
209private:
210 static DerivedT getAttribute(const std::vector<EltTy> &values,
211 PyMlirContextRef ctx) {
212 if constexpr (std::is_same_v<EltTy, bool>) {
213 std::vector<int> intValues(values.begin(), values.end());
214 MlirAttribute attr = DerivedT::getAttribute(ctx->get(), intValues.size(),
215 intValues.data());
216 return DerivedT(ctx, attr);
217 } else {
218 MlirAttribute attr =
219 DerivedT::getAttribute(ctx->get(), values.size(), values.data());
220 return DerivedT(ctx, attr);
221 }
222 }
223};
224
225/// Instantiate the python dense array classes.
227 : public PyDenseArrayAttribute<bool, PyDenseBoolArrayAttribute> {
229 static constexpr auto getAttribute = mlirDenseBoolArrayGet;
231 static constexpr const char *pyClassName = "DenseBoolArrayAttr";
232 static constexpr const char *pyIteratorName = "DenseBoolArrayIterator";
233 using PyDenseArrayAttribute::PyDenseArrayAttribute;
234};
236 : public PyDenseArrayAttribute<int8_t, PyDenseI8ArrayAttribute> {
238 static constexpr auto getAttribute = mlirDenseI8ArrayGet;
239 static constexpr auto getElement = mlirDenseI8ArrayGetElement;
240 static constexpr const char *pyClassName = "DenseI8ArrayAttr";
241 static constexpr const char *pyIteratorName = "DenseI8ArrayIterator";
242 using PyDenseArrayAttribute::PyDenseArrayAttribute;
243};
245 : public PyDenseArrayAttribute<int16_t, PyDenseI16ArrayAttribute> {
247 static constexpr auto getAttribute = mlirDenseI16ArrayGet;
249 static constexpr const char *pyClassName = "DenseI16ArrayAttr";
250 static constexpr const char *pyIteratorName = "DenseI16ArrayIterator";
251 using PyDenseArrayAttribute::PyDenseArrayAttribute;
252};
254 : public PyDenseArrayAttribute<int32_t, PyDenseI32ArrayAttribute> {
256 static constexpr auto getAttribute = mlirDenseI32ArrayGet;
258 static constexpr const char *pyClassName = "DenseI32ArrayAttr";
259 static constexpr const char *pyIteratorName = "DenseI32ArrayIterator";
260 using PyDenseArrayAttribute::PyDenseArrayAttribute;
261};
263 : public PyDenseArrayAttribute<int64_t, PyDenseI64ArrayAttribute> {
265 static constexpr auto getAttribute = mlirDenseI64ArrayGet;
267 static constexpr const char *pyClassName = "DenseI64ArrayAttr";
268 static constexpr const char *pyIteratorName = "DenseI64ArrayIterator";
269 using PyDenseArrayAttribute::PyDenseArrayAttribute;
270};
272 : public PyDenseArrayAttribute<float, PyDenseF32ArrayAttribute> {
274 static constexpr auto getAttribute = mlirDenseF32ArrayGet;
276 static constexpr const char *pyClassName = "DenseF32ArrayAttr";
277 static constexpr const char *pyIteratorName = "DenseF32ArrayIterator";
278 using PyDenseArrayAttribute::PyDenseArrayAttribute;
279};
281 : public PyDenseArrayAttribute<double, PyDenseF64ArrayAttribute> {
283 static constexpr auto getAttribute = mlirDenseF64ArrayGet;
285 static constexpr const char *pyClassName = "DenseF64ArrayAttr";
286 static constexpr const char *pyIteratorName = "DenseF64ArrayIterator";
287 using PyDenseArrayAttribute::PyDenseArrayAttribute;
288};
289
291 : public PyConcreteAttribute<PyArrayAttribute> {
292public:
294 static constexpr const char *pyClassName = "ArrayAttr";
298 static inline const MlirStringRef name = mlirArrayAttrGetName();
299
301 public:
302 PyArrayAttributeIterator(PyAttribute attr) : attr(std::move(attr)) {}
303
305
306 nanobind::typed<nanobind::object, PyAttribute> dunderNext();
307
308 static void bind(nanobind::module_ &m);
309
310 private:
311 PyAttribute attr;
312 int nextIndex = 0;
313 };
314
315 MlirAttribute getItem(intptr_t i) const;
316
317 static void bindDerived(ClassTy &c);
318};
319
320/// Float Point Attribute subclass - FloatAttr.
322 : public PyConcreteAttribute<PyFloatAttribute> {
323public:
325 static constexpr const char *pyClassName = "FloatAttr";
329 static inline const MlirStringRef name = mlirFloatAttrGetName();
330
331 static void bindDerived(ClassTy &c);
332};
333
334/// Integer Attribute subclass - IntegerAttr.
336 : public PyConcreteAttribute<PyIntegerAttribute> {
337public:
339 static constexpr const char *pyClassName = "IntegerAttr";
342
343 static void bindDerived(ClassTy &c);
344
345private:
346 static nanobind::int_ toPyInt(PyIntegerAttribute &self);
347};
348
349/// Bool Attribute subclass - BoolAttr.
351 : public PyConcreteAttribute<PyBoolAttribute> {
352public:
354 static constexpr const char *pyClassName = "BoolAttr";
356
357 static void bindDerived(ClassTy &c);
358};
359
361 : public PyConcreteAttribute<PySymbolRefAttribute> {
362public:
364 static constexpr const char *pyClassName = "SymbolRefAttr";
367
368 static PySymbolRefAttribute fromList(const std::vector<std::string> &symbols,
369 PyMlirContext &context);
370
371 static void bindDerived(ClassTy &c);
372};
373
375 : public PyConcreteAttribute<PyFlatSymbolRefAttribute> {
376public:
378 static constexpr const char *pyClassName = "FlatSymbolRefAttr";
381
382 static void bindDerived(ClassTy &c);
383};
384
386 : public PyConcreteAttribute<PyOpaqueAttribute> {
387public:
389 static constexpr const char *pyClassName = "OpaqueAttr";
393 static inline const MlirStringRef name = mlirOpaqueAttrGetName();
394
395 static void bindDerived(ClassTy &c);
396};
397
398// TODO: Support construction of string elements.
400 : public PyConcreteAttribute<PyDenseElementsAttribute> {
401public:
403 static constexpr const char *pyClassName = "DenseElementsAttr";
405
407 const nanobind::typed<nanobind::sequence, PyAttribute> &attributes,
408 std::optional<PyType> explicitType,
409 DefaultingPyMlirContext contextWrapper);
410
412 getFromBuffer(const nb_buffer &array, bool signless,
413 const std::optional<PyType> &explicitType,
414 std::optional<std::vector<int64_t>> explicitShape,
415 DefaultingPyMlirContext contextWrapper);
416
417 static PyDenseElementsAttribute getSplat(const PyType &shapedType,
418 PyAttribute &elementAttr);
419
420 intptr_t dunderLen() const;
421
422 std::unique_ptr<nb_buffer_info> accessBuffer();
423
424 static void bindDerived(ClassTy &c);
425
426 static PyType_Slot slots[];
427
428protected:
429 /// Registers get/get_splat factory methods with the concrete return
430 /// type in the nb::sig. Subclasses call this from their bindDerived
431 /// to override the return type in generated stubs.
432 template <typename ClassT>
433 static void bindFactoryMethods(ClassT &c, const char *pyClassName);
434
435private:
436 static int bf_getbuffer(PyObject *exporter, Py_buffer *view, int flags);
437 static void bf_releasebuffer(PyObject *, Py_buffer *buffer);
438
439 static bool isUnsignedIntegerFormat(std::string_view format);
440
441 static bool isSignedIntegerFormat(std::string_view format);
442
443 static MlirType
444 getShapedType(std::optional<MlirType> bulkLoadElementType,
445 std::optional<std::vector<int64_t>> explicitShape,
446 Py_buffer &view);
447
448 static MlirAttribute getAttributeFromBuffer(
449 Py_buffer &view, bool signless, std::optional<PyType> explicitType,
450 const std::optional<std::vector<int64_t>> &explicitShape,
451 MlirContext &context);
452
453 template <typename Type>
454 std::unique_ptr<nb_buffer_info>
455 bufferInfo(MlirType shapedType, const char *explicitFormat = nullptr) {
456 intptr_t rank = mlirShapedTypeGetRank(shapedType);
457 // Prepare the data for the buffer_info.
458 // Buffer is configured for read-only access below.
459 Type *data = static_cast<Type *>(
460 const_cast<void *>(mlirDenseElementsAttrGetRawData(*this)));
461 // Prepare the shape for the buffer_info.
462 std::vector<Py_ssize_t> shape;
463 for (intptr_t i = 0; i < rank; ++i)
464 shape.push_back(mlirShapedTypeGetDimSize(shapedType, i));
465 // Prepare the strides for the buffer_info.
466 std::vector<Py_ssize_t> strides;
467 if (mlirDenseElementsAttrIsSplat(*this)) {
468 // Splats are special, only the single value is stored.
469 strides.assign(rank, 0);
470 } else {
471 for (intptr_t i = 1; i < rank; ++i) {
472 intptr_t strideFactor = 1;
473 for (intptr_t j = i; j < rank; ++j)
474 strideFactor *= mlirShapedTypeGetDimSize(shapedType, j);
475 strides.push_back(sizeof(Type) * strideFactor);
476 }
477 strides.push_back(sizeof(Type));
478 }
479 const char *format;
480 if (explicitFormat) {
481 format = explicitFormat;
482 } else {
483 format = nb_format_descriptor<Type>::format();
484 }
485 return std::make_unique<nb_buffer_info>(
486 data, sizeof(Type), format, rank, std::move(shape), std::move(strides),
487 /*readonly=*/true);
488 }
489};
490
491/// Refinement of the PyDenseElementsAttribute for attributes containing
492/// integer (and boolean) values. Supports element access.
494 : public PyConcreteAttribute<PyDenseIntElementsAttribute,
495 PyDenseElementsAttribute> {
496public:
498 static constexpr const char *pyClassName = "DenseIntElementsAttr";
500
501 /// Returns the element at the given linear position. Asserts if the index
502 /// is out of range.
503 nanobind::int_ dunderGetItem(intptr_t pos) const;
504
505 static void bindDerived(ClassTy &c);
506};
507
509 : public PyConcreteAttribute<PyDenseResourceElementsAttribute> {
510public:
511 static constexpr IsAFunctionTy isaFunction =
513 static constexpr const char *pyClassName = "DenseResourceElementsAttr";
515 static inline const MlirStringRef name =
517
519 getFromBuffer(const nb_buffer &buffer, const std::string &name,
520 const PyType &type, std::optional<size_t> alignment,
521 bool isMutable, DefaultingPyMlirContext contextWrapper);
522
523 static void bindDerived(ClassTy &c);
524};
525
527 : public PyConcreteAttribute<PyDictAttribute> {
528public:
530 static constexpr const char *pyClassName = "DictAttr";
535
536 intptr_t dunderLen() const;
537
538 bool dunderContains(const std::string &name) const;
539
540 static void bindDerived(ClassTy &c);
541};
542
543/// Refinement of PyDenseElementsAttribute for attributes containing
544/// floating-point values. Supports element access.
546 : public PyConcreteAttribute<PyDenseFPElementsAttribute,
547 PyDenseElementsAttribute> {
548public:
550 static constexpr const char *pyClassName = "DenseFPElementsAttr";
552
553 nanobind::float_ dunderGetItem(intptr_t pos) const;
554
555 static void bindDerived(ClassTy &c);
556};
557
559 : public PyConcreteAttribute<PyTypeAttribute> {
560public:
562 static constexpr const char *pyClassName = "TypeAttr";
566 static inline const MlirStringRef name = mlirTypeAttrGetName();
567
568 static void bindDerived(ClassTy &c);
569};
570
571/// Unit Attribute subclass. Unit attributes don't have values.
573 : public PyConcreteAttribute<PyUnitAttribute> {
574public:
576 static constexpr const char *pyClassName = "UnitAttr";
580 static inline const MlirStringRef name = mlirUnitAttrGetName();
581
582 static void bindDerived(ClassTy &c);
583};
584
585/// Strided layout attribute subclass.
587 : public PyConcreteAttribute<PyStridedLayoutAttribute> {
588public:
590 static constexpr const char *pyClassName = "StridedLayoutAttr";
595
596 static void bindDerived(ClassTy &c);
597};
598
600 : public PyConcreteAttribute<PyDynamicAttribute> {
601public:
603 static constexpr const char *pyClassName = "DynamicAttr";
605
606 static void bindDerived(ClassTy &c);
607};
608
610} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
611} // namespace python
612} // namespace mlir
613
614#endif
static LogicalResult nextIndex(ArrayRef< int64_t > shape, MutableArrayRef< int64_t > index)
Walks over the indices of the elements of a tensor of a given shape by updating index in place to the...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
Used in function arguments when None should resolve to the current context manager set instance.
Definition IRCore.h:291
static constexpr GetTypeIDFunctionTy getTypeIdFunction
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1018
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
Definition IRCore.h:1100
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
Definition IRCore.h:1075
A python-wrapped dense array attribute with an element type and a derived implementation class.
static void bindDerived(typename PyConcreteAttribute< DerivedT >::ClassTy &c)
Bind the attribute class.
EltTy getItem(intptr_t i)
Get the element at the given index.
static void bindFactoryMethods(ClassT &c, const char *pyClassName)
Registers get/get_splat factory methods with the concrete return type in the nb::sig.
static PyDenseElementsAttribute getSplat(const PyType &shapedType, PyAttribute &elementAttr)
static PyDenseElementsAttribute getFromList(const nanobind::typed< nanobind::sequence, PyAttribute > &attributes, std::optional< PyType > explicitType, DefaultingPyMlirContext contextWrapper)
static PyDenseElementsAttribute getFromBuffer(const nb_buffer &array, bool signless, const std::optional< PyType > &explicitType, std::optional< std::vector< int64_t > > explicitShape, DefaultingPyMlirContext contextWrapper)
Refinement of PyDenseElementsAttribute for attributes containing floating-point values.
Refinement of the PyDenseElementsAttribute for attributes containing integer (and boolean) values.
nanobind::int_ dunderGetItem(intptr_t pos) const
Returns the element at the given linear position.
static PyDenseResourceElementsAttribute getFromBuffer(const nb_buffer &buffer, const std::string &name, const PyType &type, std::optional< size_t > alignment, bool isMutable, DefaultingPyMlirContext contextWrapper)
static constexpr GetTypeIDFunctionTy getTypeIdFunction
Float Point Attribute subclass - FloatAttr.
static constexpr GetTypeIDFunctionTy getTypeIdFunction
MlirContext get()
Accesses the underlying MlirContext.
Definition IRCore.h:224
static constexpr GetTypeIDFunctionTy getTypeIdFunction
static PySymbolRefAttribute fromList(const std::vector< std::string > &symbols, PyMlirContext &context)
static constexpr GetTypeIDFunctionTy getTypeIdFunction
Wrapper around the generic MlirType.
Definition IRCore.h:891
Unit Attribute subclass. Unit attributes don't have values.
static constexpr GetTypeIDFunctionTy getTypeIdFunction
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseFPElements(MlirAttribute attr)
MLIR_CAPI_EXPORTED int16_t mlirDenseI16ArrayGetElement(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAStridedLayout(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI64Array(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirStringRef mlirStridedLayoutAttrGetName(void)
MLIR_CAPI_EXPORTED MlirStringRef mlirTypeAttrGetName(void)
MLIR_CAPI_EXPORTED MlirStringRef mlirIntegerAttrGetName(void)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAUnit(MlirAttribute attr)
Checks whether the given attribute is a unit attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseElements(MlirAttribute attr)
Checks whether the given attribute is a dense elements attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAIntegerSet(MlirAttribute attr)
Checks whether the given attribute is an integer set attribute.
MLIR_CAPI_EXPORTED MlirStringRef mlirIntegerSetAttrGetName(void)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAAffineMap(MlirAttribute attr)
Checks whether the given attribute is an affine map attribute.
MLIR_CAPI_EXPORTED int32_t mlirDenseI32ArrayGetElement(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED double mlirDenseF64ArrayGetElement(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirStringRef mlirUnitAttrGetName(void)
MLIR_CAPI_EXPORTED MlirTypeID mlirStridedLayoutAttrGetTypeID(void)
Returns the typeID of a StridedLayout attribute.
MLIR_CAPI_EXPORTED const void * mlirDenseElementsAttrGetRawData(MlirAttribute attr)
Returns the raw data of the given dense elements attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseResourceElements(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAType(MlirAttribute attr)
Checks whether the given attribute is a type attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseIntElements(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAArray(MlirAttribute attr)
Checks whether the given attribute is an array attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr)
Checks whether the given attribute is an integer attribute.
MLIR_CAPI_EXPORTED MlirStringRef mlirArrayAttrGetName(void)
MLIR_CAPI_EXPORTED MlirStringRef mlirDictionaryAttrGetName(void)
MLIR_CAPI_EXPORTED int64_t mlirDenseI64ArrayGetElement(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerSetAttrGetTypeID(void)
Returns the typeID of an IntegerSet attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsABool(MlirAttribute attr)
Checks whether the given attribute is a bool attribute.
MLIR_CAPI_EXPORTED bool mlirDenseBoolArrayGetElement(MlirAttribute attr, intptr_t pos)
Get an element of a dense array.
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI64ArrayGet(MlirContext ctx, intptr_t size, int64_t const *values)
MLIR_CAPI_EXPORTED MlirTypeID mlirAffineMapAttrGetTypeID(void)
Returns the typeID of an AffineMap attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirArrayAttrGetTypeID(void)
Returns the typeID of an Array attribute.
MLIR_CAPI_EXPORTED float mlirDenseF32ArrayGetElement(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseF64ArrayGet(MlirContext ctx, intptr_t size, double const *values)
MLIR_CAPI_EXPORTED MlirStringRef mlirFloatAttrGetName(void)
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr)
Checks whether the given dense elements attribute contains a single replicated value (splat).
MLIR_CAPI_EXPORTED MlirStringRef mlirFlatSymbolRefAttrGetName(void)
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseBoolArray(MlirAttribute attr)
Checks whether the given attribute is a dense array attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirFloatAttrGetTypeID(void)
Returns the typeID of a Float attribute.
MLIR_CAPI_EXPORTED int8_t mlirDenseI8ArrayGetElement(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI32ArrayGet(MlirContext ctx, intptr_t size, int32_t const *values)
MLIR_CAPI_EXPORTED MlirTypeID mlirUnitAttrGetTypeID(void)
Returns the typeID of a Unit attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseF32ArrayGet(MlirContext ctx, intptr_t size, float const *values)
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseBoolArrayGet(MlirContext ctx, intptr_t size, int const *values)
Create a dense array attribute with the given elements.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAOpaque(MlirAttribute attr)
Checks whether the given attribute is an opaque attribute.
MLIR_CAPI_EXPORTED MlirStringRef mlirAffineMapAttrGetName(void)
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseF32Array(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsASymbolRef(MlirAttribute attr)
Checks whether the given attribute is a symbol reference attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADictionary(MlirAttribute attr)
Checks whether the given attribute is a dictionary attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI16ArrayGet(MlirContext ctx, intptr_t size, int16_t const *values)
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetName(void)
MLIR_CAPI_EXPORTED MlirTypeID mlirOpaqueAttrGetTypeID(void)
Returns the typeID of an Opaque attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseI8ArrayGet(MlirContext ctx, intptr_t size, int8_t const *values)
MLIR_CAPI_EXPORTED MlirStringRef mlirDenseResourceElementsAttrGetName(void)
MLIR_CAPI_EXPORTED intptr_t mlirDenseArrayGetNumElements(MlirAttribute attr)
Get the size of a dense array.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr)
Checks whether the given attribute is a floating point attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirTypeAttrGetTypeID(void)
Returns the typeID of a Type attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirDictionaryAttrGetTypeID(void)
Returns the typeID of a Dictionary attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI32Array(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI8Array(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsAFlatSymbolRef(MlirAttribute attr)
Checks whether the given attribute is a flat symbol reference attribute.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseI16Array(MlirAttribute attr)
MLIR_CAPI_EXPORTED bool mlirAttributeIsADenseF64Array(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolRefAttrGetName(void)
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDimSize(MlirType type, intptr_t dim)
Returns the dim-th dimension of the given ranked shaped type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetRank(MlirType type)
Returns the rank of the given ranked shaped type.
MLIR_CAPI_EXPORTED bool mlirAttributeIsADynamicAttr(MlirAttribute attr)
Check if the given attribute is a dynamic attribute.
#define MLIR_PYTHON_API_EXPORTED
Definition Support.h:49
PyObjectRef< PyMlirContext > PyMlirContextRef
Wrapper around MlirContext.
Definition IRCore.h:210
static T pyTryCast(nanobind::handle object)
MLIR_PYTHON_API_EXPORTED void populateIRAttributes(nanobind::module_ &m)
Include the generated interface declarations.
A pointer to a sized fragment of a string, not necessarily null-terminated.
Definition Support.h:78
nb_buffer_info & operator=(nb_buffer_info &&)=default
nb_buffer_info(void *ptr, Py_ssize_t itemsize, const char *format, Py_ssize_t ndim, std::vector< Py_ssize_t > shape_in, std::vector< Py_ssize_t > strides_in, bool readonly=false, std::unique_ptr< Py_buffer, void(*)(Py_buffer *)> owned_view_in=std::unique_ptr< Py_buffer, void(*)(Py_buffer *)>(nullptr, nullptr))
nb_buffer_info & operator=(const nb_buffer_info &)=delete
Eliminates variable at the specified position using Fourier-Motzkin variable elimination.