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
18#include "mlir-c/BuiltinTypes.h"
23
24namespace mlir {
25namespace python {
27
29 void *ptr = nullptr;
30 ssize_t itemsize = 0;
31 ssize_t size = 0;
32 const char *format = nullptr;
33 ssize_t ndim = 0;
36 bool readonly = false;
37
39 void *ptr, ssize_t itemsize, const char *format, ssize_t ndim,
41 bool readonly = false,
42 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)> owned_view_in =
43 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)>(nullptr, nullptr));
44
45 explicit nb_buffer_info(Py_buffer *view)
46 : nb_buffer_info(view->buf, view->itemsize, view->format, view->ndim,
47 {view->shape, view->shape + view->ndim},
48 // TODO(phawkins): check for null strides
49 {view->strides, view->strides + view->ndim},
50 view->readonly != 0,
51 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)>(
52 view, PyBuffer_Release)) {}
53
54 nb_buffer_info(const nb_buffer_info &) = delete;
58
59private:
60 std::unique_ptr<Py_buffer, void (*)(Py_buffer *)> owned_view;
61};
62
63class MLIR_PYTHON_API_EXPORTED nb_buffer : public nanobind::object {
64 NB_OBJECT_DEFAULT(nb_buffer, object, "Buffer", PyObject_CheckBuffer);
65
66 nb_buffer_info request() const;
67};
68
69template <typename T>
71
73 : public PyConcreteAttribute<PyAffineMapAttribute> {
74public:
76 static constexpr const char *pyClassName = "AffineMapAttr";
81
82 static void bindDerived(ClassTy &c);
83};
84
86 : public PyConcreteAttribute<PyIntegerSetAttribute> {
87public:
89 static constexpr const char *pyClassName = "IntegerSetAttr";
94
95 static void bindDerived(ClassTy &c);
96};
97
98template <typename T>
99static T pyTryCast(nanobind::handle object) {
100 try {
101 return nanobind::cast<T>(object);
102 } catch (nanobind::cast_error &err) {
103 std::string msg = std::string("Invalid attribute when attempting to "
104 "create an ArrayAttribute (") +
105 err.what() + ")";
106 throw std::runtime_error(msg.c_str());
107 } catch (std::runtime_error &err) {
108 std::string msg = std::string("Invalid attribute (None?) when attempting "
109 "to create an ArrayAttribute (") +
110 err.what() + ")";
111 throw std::runtime_error(msg.c_str());
112 }
113}
114
115/// A python-wrapped dense array attribute with an element type and a derived
116/// implementation class.
117template <typename EltTy, typename DerivedT>
119 : public PyConcreteAttribute<DerivedT> {
120public:
122
123 /// Iterator over the integer elements of a dense array.
125 public:
126 PyDenseArrayIterator(PyAttribute attr) : attr(std::move(attr)) {}
127
128 /// Return a copy of the iterator.
130
131 /// Return the next element.
132 EltTy dunderNext() {
133 // Throw if the index has reached the end.
134 if (nextIndex >= mlirDenseArrayGetNumElements(attr.get()))
135 throw nanobind::stop_iteration();
136 return DerivedT::getElement(attr.get(), nextIndex++);
137 }
138
139 /// Bind the iterator class.
140 static void bind(nanobind::module_ &m) {
141 nanobind::class_<PyDenseArrayIterator>(m, DerivedT::pyIteratorName)
142 .def("__iter__", &PyDenseArrayIterator::dunderIter)
143 .def("__next__", &PyDenseArrayIterator::dunderNext);
144 }
145
146 private:
147 /// The referenced dense array attribute.
148 PyAttribute attr;
149 /// The next index to read.
150 int nextIndex = 0;
151 };
152
153 /// Get the element at the given index.
154 EltTy getItem(intptr_t i) { return DerivedT::getElement(*this, i); }
155
156 /// Bind the attribute class.
158 // Bind the constructor.
159 if constexpr (std::is_same_v<EltTy, bool>) {
160 c.def_static(
161 "get",
162 [](const nanobind::sequence &py_values, DefaultingPyMlirContext ctx) {
163 std::vector<bool> values;
164 for (nanobind::handle py_value : py_values) {
165 int is_true = PyObject_IsTrue(py_value.ptr());
166 if (is_true < 0) {
167 throw nanobind::python_error();
168 }
169 values.push_back(is_true);
170 }
171 return getAttribute(values, ctx->getRef());
172 },
173 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
174 "Gets a uniqued dense array attribute");
175 } else {
176 c.def_static(
177 "get",
178 [](const std::vector<EltTy> &values, DefaultingPyMlirContext ctx) {
179 return getAttribute(values, ctx->getRef());
180 },
181 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
182 "Gets a uniqued dense array attribute");
183 }
184 // Bind the array methods.
185 c.def("__getitem__", [](DerivedT &arr, intptr_t i) {
186 if (i >= mlirDenseArrayGetNumElements(arr))
187 throw nanobind::index_error("DenseArray index out of range");
188 return arr.getItem(i);
189 });
190 c.def("__len__", [](const DerivedT &arr) {
192 });
193 c.def("__iter__",
194 [](const DerivedT &arr) { return PyDenseArrayIterator(arr); });
195 c.def("__add__", [](DerivedT &arr, const nanobind::list &extras) {
196 std::vector<EltTy> values;
197 intptr_t numOldElements = mlirDenseArrayGetNumElements(arr);
198 values.reserve(numOldElements + nanobind::len(extras));
199 for (intptr_t i = 0; i < numOldElements; ++i)
200 values.push_back(arr.getItem(i));
201 for (nanobind::handle attr : extras)
202 values.push_back(pyTryCast<EltTy>(attr));
203 return getAttribute(values, arr.getContext());
204 });
205 }
206
207private:
208 static DerivedT getAttribute(const std::vector<EltTy> &values,
209 PyMlirContextRef ctx) {
210 if constexpr (std::is_same_v<EltTy, bool>) {
211 std::vector<int> intValues(values.begin(), values.end());
212 MlirAttribute attr = DerivedT::getAttribute(ctx->get(), intValues.size(),
213 intValues.data());
214 return DerivedT(ctx, attr);
215 } else {
216 MlirAttribute attr =
217 DerivedT::getAttribute(ctx->get(), values.size(), values.data());
218 return DerivedT(ctx, attr);
219 }
220 }
221};
222
223/// Instantiate the python dense array classes.
225 : public PyDenseArrayAttribute<bool, PyDenseBoolArrayAttribute> {
227 static constexpr auto getAttribute = mlirDenseBoolArrayGet;
229 static constexpr const char *pyClassName = "DenseBoolArrayAttr";
230 static constexpr const char *pyIteratorName = "DenseBoolArrayIterator";
231 using PyDenseArrayAttribute::PyDenseArrayAttribute;
232};
234 : public PyDenseArrayAttribute<int8_t, PyDenseI8ArrayAttribute> {
236 static constexpr auto getAttribute = mlirDenseI8ArrayGet;
237 static constexpr auto getElement = mlirDenseI8ArrayGetElement;
238 static constexpr const char *pyClassName = "DenseI8ArrayAttr";
239 static constexpr const char *pyIteratorName = "DenseI8ArrayIterator";
240 using PyDenseArrayAttribute::PyDenseArrayAttribute;
241};
243 : public PyDenseArrayAttribute<int16_t, PyDenseI16ArrayAttribute> {
245 static constexpr auto getAttribute = mlirDenseI16ArrayGet;
247 static constexpr const char *pyClassName = "DenseI16ArrayAttr";
248 static constexpr const char *pyIteratorName = "DenseI16ArrayIterator";
249 using PyDenseArrayAttribute::PyDenseArrayAttribute;
250};
252 : public PyDenseArrayAttribute<int32_t, PyDenseI32ArrayAttribute> {
254 static constexpr auto getAttribute = mlirDenseI32ArrayGet;
256 static constexpr const char *pyClassName = "DenseI32ArrayAttr";
257 static constexpr const char *pyIteratorName = "DenseI32ArrayIterator";
258 using PyDenseArrayAttribute::PyDenseArrayAttribute;
259};
261 : public PyDenseArrayAttribute<int64_t, PyDenseI64ArrayAttribute> {
263 static constexpr auto getAttribute = mlirDenseI64ArrayGet;
265 static constexpr const char *pyClassName = "DenseI64ArrayAttr";
266 static constexpr const char *pyIteratorName = "DenseI64ArrayIterator";
267 using PyDenseArrayAttribute::PyDenseArrayAttribute;
268};
270 : public PyDenseArrayAttribute<float, PyDenseF32ArrayAttribute> {
272 static constexpr auto getAttribute = mlirDenseF32ArrayGet;
274 static constexpr const char *pyClassName = "DenseF32ArrayAttr";
275 static constexpr const char *pyIteratorName = "DenseF32ArrayIterator";
276 using PyDenseArrayAttribute::PyDenseArrayAttribute;
277};
279 : public PyDenseArrayAttribute<double, PyDenseF64ArrayAttribute> {
281 static constexpr auto getAttribute = mlirDenseF64ArrayGet;
283 static constexpr const char *pyClassName = "DenseF64ArrayAttr";
284 static constexpr const char *pyIteratorName = "DenseF64ArrayIterator";
285 using PyDenseArrayAttribute::PyDenseArrayAttribute;
286};
287
289 : public PyConcreteAttribute<PyArrayAttribute> {
290public:
292 static constexpr const char *pyClassName = "ArrayAttr";
296 static inline const MlirStringRef name = mlirArrayAttrGetName();
297
299 public:
300 PyArrayAttributeIterator(PyAttribute attr) : attr(std::move(attr)) {}
301
303
304 nanobind::typed<nanobind::object, PyAttribute> dunderNext();
305
306 static void bind(nanobind::module_ &m);
307
308 private:
309 PyAttribute attr;
310 int nextIndex = 0;
311 };
312
313 MlirAttribute getItem(intptr_t i) const;
314
315 static void bindDerived(ClassTy &c);
316};
317
318/// Float Point Attribute subclass - FloatAttr.
320 : public PyConcreteAttribute<PyFloatAttribute> {
321public:
323 static constexpr const char *pyClassName = "FloatAttr";
327 static inline const MlirStringRef name = mlirFloatAttrGetName();
328
329 static void bindDerived(ClassTy &c);
330};
331
332/// Integer Attribute subclass - IntegerAttr.
334 : public PyConcreteAttribute<PyIntegerAttribute> {
335public:
337 static constexpr const char *pyClassName = "IntegerAttr";
340
341 static void bindDerived(ClassTy &c);
342
343private:
344 static nanobind::object toPyInt(PyIntegerAttribute &self);
345};
346
347/// Bool Attribute subclass - BoolAttr.
349 : public PyConcreteAttribute<PyBoolAttribute> {
350public:
352 static constexpr const char *pyClassName = "BoolAttr";
354
355 static void bindDerived(ClassTy &c);
356};
357
359 : public PyConcreteAttribute<PySymbolRefAttribute> {
360public:
362 static constexpr const char *pyClassName = "SymbolRefAttr";
365
366 static PySymbolRefAttribute fromList(const std::vector<std::string> &symbols,
367 PyMlirContext &context);
368
369 static void bindDerived(ClassTy &c);
370};
371
373 : public PyConcreteAttribute<PyFlatSymbolRefAttribute> {
374public:
376 static constexpr const char *pyClassName = "FlatSymbolRefAttr";
379
380 static void bindDerived(ClassTy &c);
381};
382
384 : public PyConcreteAttribute<PyOpaqueAttribute> {
385public:
387 static constexpr const char *pyClassName = "OpaqueAttr";
391 static inline const MlirStringRef name = mlirOpaqueAttrGetName();
392
393 static void bindDerived(ClassTy &c);
394};
395
396// TODO: Support construction of string elements.
398 : public PyConcreteAttribute<PyDenseElementsAttribute> {
399public:
401 static constexpr const char *pyClassName = "DenseElementsAttr";
403
405 getFromList(const nanobind::list &attributes,
406 std::optional<PyType> explicitType,
407 DefaultingPyMlirContext contextWrapper);
408
410 getFromBuffer(const nb_buffer &array, bool signless,
411 const std::optional<PyType> &explicitType,
412 std::optional<std::vector<int64_t>> explicitShape,
413 DefaultingPyMlirContext contextWrapper);
414
415 static PyDenseElementsAttribute getSplat(const PyType &shapedType,
416 PyAttribute &elementAttr);
417
418 intptr_t dunderLen() const;
419
420 std::unique_ptr<nb_buffer_info> accessBuffer();
421
422 static void bindDerived(ClassTy &c);
423
424 static PyType_Slot slots[];
425
426private:
427 static int bf_getbuffer(PyObject *exporter, Py_buffer *view, int flags);
428 static void bf_releasebuffer(PyObject *, Py_buffer *buffer);
429
430 static bool isUnsignedIntegerFormat(std::string_view format);
431
432 static bool isSignedIntegerFormat(std::string_view format);
433
434 static MlirType
435 getShapedType(std::optional<MlirType> bulkLoadElementType,
436 std::optional<std::vector<int64_t>> explicitShape,
437 Py_buffer &view);
438
439 static MlirAttribute getAttributeFromBuffer(
440 Py_buffer &view, bool signless, std::optional<PyType> explicitType,
441 const std::optional<std::vector<int64_t>> &explicitShape,
442 MlirContext &context);
443
444 // There is a complication for boolean numpy arrays, as numpy represents
445 // them as 8 bits (1 byte) per boolean, whereas MLIR bitpacks them into 8
446 // booleans per byte.
447 static MlirAttribute getBitpackedAttributeFromBooleanBuffer(
448 Py_buffer &view, std::optional<std::vector<int64_t>> explicitShape,
449 MlirContext &context);
450
451 // This does the opposite transformation of
452 // `getBitpackedAttributeFromBooleanBuffer`
453 std::unique_ptr<nb_buffer_info>
454 getBooleanBufferFromBitpackedAttribute() const;
455
456 template <typename Type>
457 std::unique_ptr<nb_buffer_info>
458 bufferInfo(MlirType shapedType, const char *explicitFormat = nullptr) {
459 intptr_t rank = mlirShapedTypeGetRank(shapedType);
460 // Prepare the data for the buffer_info.
461 // Buffer is configured for read-only access below.
462 Type *data = static_cast<Type *>(
463 const_cast<void *>(mlirDenseElementsAttrGetRawData(*this)));
464 // Prepare the shape for the buffer_info.
466 for (intptr_t i = 0; i < rank; ++i)
467 shape.push_back(mlirShapedTypeGetDimSize(shapedType, i));
468 // Prepare the strides for the buffer_info.
470 if (mlirDenseElementsAttrIsSplat(*this)) {
471 // Splats are special, only the single value is stored.
472 strides.assign(rank, 0);
473 } else {
474 for (intptr_t i = 1; i < rank; ++i) {
475 intptr_t strideFactor = 1;
476 for (intptr_t j = i; j < rank; ++j)
477 strideFactor *= mlirShapedTypeGetDimSize(shapedType, j);
478 strides.push_back(sizeof(Type) * strideFactor);
479 }
480 strides.push_back(sizeof(Type));
481 }
482 const char *format;
483 if (explicitFormat) {
484 format = explicitFormat;
485 } else {
486 format = nb_format_descriptor<Type>::format();
487 }
488 return std::make_unique<nb_buffer_info>(
489 data, sizeof(Type), format, rank, std::move(shape), std::move(strides),
490 /*readonly=*/true);
491 }
492};
493
494/// Refinement of the PyDenseElementsAttribute for attributes containing
495/// integer (and boolean) values. Supports element access.
497 : public PyConcreteAttribute<PyDenseIntElementsAttribute,
498 PyDenseElementsAttribute> {
499public:
501 static constexpr const char *pyClassName = "DenseIntElementsAttr";
503
504 /// Returns the element at the given linear position. Asserts if the index
505 /// is out of range.
506 nanobind::int_ dunderGetItem(intptr_t pos) const;
507
508 static void bindDerived(ClassTy &c);
509};
510
512 : public PyConcreteAttribute<PyDenseResourceElementsAttribute> {
513public:
514 static constexpr IsAFunctionTy isaFunction =
516 static constexpr const char *pyClassName = "DenseResourceElementsAttr";
518 static inline const MlirStringRef name =
520
522 getFromBuffer(const nb_buffer &buffer, const std::string &name,
523 const PyType &type, std::optional<size_t> alignment,
524 bool isMutable, DefaultingPyMlirContext contextWrapper);
525
526 static void bindDerived(ClassTy &c);
527};
528
530 : public PyConcreteAttribute<PyDictAttribute> {
531public:
533 static constexpr const char *pyClassName = "DictAttr";
538
539 intptr_t dunderLen() const;
540
541 bool dunderContains(const std::string &name) const;
542
543 static void bindDerived(ClassTy &c);
544};
545
546/// Refinement of PyDenseElementsAttribute for attributes containing
547/// floating-point values. Supports element access.
549 : public PyConcreteAttribute<PyDenseFPElementsAttribute,
550 PyDenseElementsAttribute> {
551public:
553 static constexpr const char *pyClassName = "DenseFPElementsAttr";
555
556 nanobind::float_ dunderGetItem(intptr_t pos) const;
557
558 static void bindDerived(ClassTy &c);
559};
560
562 : public PyConcreteAttribute<PyTypeAttribute> {
563public:
565 static constexpr const char *pyClassName = "TypeAttr";
569 static inline const MlirStringRef name = mlirTypeAttrGetName();
570
571 static void bindDerived(ClassTy &c);
572};
573
574/// Unit Attribute subclass. Unit attributes don't have values.
576 : public PyConcreteAttribute<PyUnitAttribute> {
577public:
579 static constexpr const char *pyClassName = "UnitAttr";
583 static inline const MlirStringRef name = mlirUnitAttrGetName();
584
585 static void bindDerived(ClassTy &c);
586};
587
588/// Strided layout attribute subclass.
590 : public PyConcreteAttribute<PyStridedLayoutAttribute> {
591public:
593 static constexpr const char *pyClassName = "StridedLayoutAttr";
598
599 static void bindDerived(ClassTy &c);
600};
601
603} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
604} // namespace python
605} // namespace mlir
606
607#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:280
static constexpr GetTypeIDFunctionTy getTypeIdFunction
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1009
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
Definition IRCore.h:1092
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
Definition IRCore.h:1066
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 PyDenseElementsAttribute getSplat(const PyType &shapedType, PyAttribute &elementAttr)
static PyDenseElementsAttribute getFromList(const nanobind::list &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:213
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:876
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.
#define MLIR_PYTHON_API_EXPORTED
Definition Support.h:49
PyObjectRef< PyMlirContext > PyMlirContextRef
Wrapper around MlirContext.
Definition IRCore.h:199
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:75
nb_buffer_info & operator=(nb_buffer_info &&)=default
nb_buffer_info(void *ptr, ssize_t itemsize, const char *format, ssize_t ndim, SmallVector< ssize_t, 4 > shape_in, SmallVector< ssize_t, 4 > 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.