MLIR 22.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
328 static void bindDerived(ClassTy &c);
329};
330
331/// Integer Attribute subclass - IntegerAttr.
333 : public PyConcreteAttribute<PyIntegerAttribute> {
334public:
336 static constexpr const char *pyClassName = "IntegerAttr";
339
340 static void bindDerived(ClassTy &c);
341
342private:
343 static int64_t toPyInt(PyIntegerAttribute &self);
344};
345
346/// Bool Attribute subclass - BoolAttr.
348 : public PyConcreteAttribute<PyBoolAttribute> {
349public:
351 static constexpr const char *pyClassName = "BoolAttr";
353
354 static void bindDerived(ClassTy &c);
355};
356
358 : public PyConcreteAttribute<PySymbolRefAttribute> {
359public:
361 static constexpr const char *pyClassName = "SymbolRefAttr";
364
365 static PySymbolRefAttribute fromList(const std::vector<std::string> &symbols,
366 PyMlirContext &context);
367
368 static void bindDerived(ClassTy &c);
369};
370
372 : public PyConcreteAttribute<PyFlatSymbolRefAttribute> {
373public:
375 static constexpr const char *pyClassName = "FlatSymbolRefAttr";
378
379 static void bindDerived(ClassTy &c);
380};
381
383 : public PyConcreteAttribute<PyOpaqueAttribute> {
384public:
386 static constexpr const char *pyClassName = "OpaqueAttr";
390 static inline const MlirStringRef name = mlirOpaqueAttrGetName();
391
392 static void bindDerived(ClassTy &c);
393};
394
395// TODO: Support construction of string elements.
397 : public PyConcreteAttribute<PyDenseElementsAttribute> {
398public:
400 static constexpr const char *pyClassName = "DenseElementsAttr";
402
404 getFromList(const nanobind::list &attributes,
405 std::optional<PyType> explicitType,
406 DefaultingPyMlirContext contextWrapper);
407
409 getFromBuffer(const nb_buffer &array, bool signless,
410 const std::optional<PyType> &explicitType,
411 std::optional<std::vector<int64_t>> explicitShape,
412 DefaultingPyMlirContext contextWrapper);
413
414 static PyDenseElementsAttribute getSplat(const PyType &shapedType,
415 PyAttribute &elementAttr);
416
417 intptr_t dunderLen() const;
418
419 std::unique_ptr<nb_buffer_info> accessBuffer();
420
421 static void bindDerived(ClassTy &c);
422
423 static PyType_Slot slots[];
424
425private:
426 static int bf_getbuffer(PyObject *exporter, Py_buffer *view, int flags);
427 static void bf_releasebuffer(PyObject *, Py_buffer *buffer);
428
429 static bool isUnsignedIntegerFormat(std::string_view format);
430
431 static bool isSignedIntegerFormat(std::string_view format);
432
433 static MlirType
434 getShapedType(std::optional<MlirType> bulkLoadElementType,
435 std::optional<std::vector<int64_t>> explicitShape,
436 Py_buffer &view);
437
438 static MlirAttribute getAttributeFromBuffer(
439 Py_buffer &view, bool signless, std::optional<PyType> explicitType,
440 const std::optional<std::vector<int64_t>> &explicitShape,
441 MlirContext &context);
442
443 // There is a complication for boolean numpy arrays, as numpy represents
444 // them as 8 bits (1 byte) per boolean, whereas MLIR bitpacks them into 8
445 // booleans per byte.
446 static MlirAttribute getBitpackedAttributeFromBooleanBuffer(
447 Py_buffer &view, std::optional<std::vector<int64_t>> explicitShape,
448 MlirContext &context);
449
450 // This does the opposite transformation of
451 // `getBitpackedAttributeFromBooleanBuffer`
452 std::unique_ptr<nb_buffer_info>
453 getBooleanBufferFromBitpackedAttribute() const;
454
455 template <typename Type>
456 std::unique_ptr<nb_buffer_info>
457 bufferInfo(MlirType shapedType, const char *explicitFormat = nullptr) {
458 intptr_t rank = mlirShapedTypeGetRank(shapedType);
459 // Prepare the data for the buffer_info.
460 // Buffer is configured for read-only access below.
461 Type *data = static_cast<Type *>(
462 const_cast<void *>(mlirDenseElementsAttrGetRawData(*this)));
463 // Prepare the shape for the buffer_info.
465 for (intptr_t i = 0; i < rank; ++i)
466 shape.push_back(mlirShapedTypeGetDimSize(shapedType, i));
467 // Prepare the strides for the buffer_info.
469 if (mlirDenseElementsAttrIsSplat(*this)) {
470 // Splats are special, only the single value is stored.
471 strides.assign(rank, 0);
472 } else {
473 for (intptr_t i = 1; i < rank; ++i) {
474 intptr_t strideFactor = 1;
475 for (intptr_t j = i; j < rank; ++j)
476 strideFactor *= mlirShapedTypeGetDimSize(shapedType, j);
477 strides.push_back(sizeof(Type) * strideFactor);
478 }
479 strides.push_back(sizeof(Type));
480 }
481 const char *format;
482 if (explicitFormat) {
483 format = explicitFormat;
484 } else {
485 format = nb_format_descriptor<Type>::format();
486 }
487 return std::make_unique<nb_buffer_info>(
488 data, sizeof(Type), format, rank, std::move(shape), std::move(strides),
489 /*readonly=*/true);
490 }
491};
492
493/// Refinement of the PyDenseElementsAttribute for attributes containing
494/// integer (and boolean) values. Supports element access.
496 : public PyConcreteAttribute<PyDenseIntElementsAttribute,
497 PyDenseElementsAttribute> {
498public:
500 static constexpr const char *pyClassName = "DenseIntElementsAttr";
502
503 /// Returns the element at the given linear position. Asserts if the index
504 /// is out of range.
505 nanobind::int_ dunderGetItem(intptr_t pos) const;
506
507 static void bindDerived(ClassTy &c);
508};
509
511 : public PyConcreteAttribute<PyDenseResourceElementsAttribute> {
512public:
513 static constexpr IsAFunctionTy isaFunction =
515 static constexpr const char *pyClassName = "DenseResourceElementsAttr";
517 static inline const MlirStringRef name =
519
521 getFromBuffer(const nb_buffer &buffer, const std::string &name,
522 const PyType &type, std::optional<size_t> alignment,
523 bool isMutable, DefaultingPyMlirContext contextWrapper);
524
525 static void bindDerived(ClassTy &c);
526};
527
529 : public PyConcreteAttribute<PyDictAttribute> {
530public:
532 static constexpr const char *pyClassName = "DictAttr";
537
538 intptr_t dunderLen() const;
539
540 bool dunderContains(const std::string &name) const;
541
542 static void bindDerived(ClassTy &c);
543};
544
545/// Refinement of PyDenseElementsAttribute for attributes containing
546/// floating-point values. Supports element access.
548 : public PyConcreteAttribute<PyDenseFPElementsAttribute,
549 PyDenseElementsAttribute> {
550public:
552 static constexpr const char *pyClassName = "DenseFPElementsAttr";
554
555 nanobind::float_ dunderGetItem(intptr_t pos) const;
556
557 static void bindDerived(ClassTy &c);
558};
559
561 : public PyConcreteAttribute<PyTypeAttribute> {
562public:
564 static constexpr const char *pyClassName = "TypeAttr";
568 static inline const MlirStringRef name = mlirTypeAttrGetName();
569
570 static void bindDerived(ClassTy &c);
571};
572
573/// Unit Attribute subclass. Unit attributes don't have values.
575 : public PyConcreteAttribute<PyUnitAttribute> {
576public:
578 static constexpr const char *pyClassName = "UnitAttr";
582 static inline const MlirStringRef name = mlirUnitAttrGetName();
583
584 static void bindDerived(ClassTy &c);
585};
586
587/// Strided layout attribute subclass.
589 : public PyConcreteAttribute<PyStridedLayoutAttribute> {
590public:
592 static constexpr const char *pyClassName = "StridedLayoutAttr";
597
598 static void bindDerived(ClassTy &c);
599};
600
602} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
603} // namespace python
604} // namespace mlir
605
606#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:1008
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
Definition IRCore.h:1091
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
Definition IRCore.h:1065
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:875
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 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.