MLIR 24.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 nanobind::typed<nanobind::object, EltTy> dunderNext() {
135 // Set StopIteration if the index has reached the end. Signaling
136 // exhaustion via the Python error indicator rather than a C++ exception
137 // avoids the cost of stack unwinding on every iteration.
138 if (nextIndex >= mlirDenseArrayGetNumElements(attr.get())) {
139 PyErr_SetNone(PyExc_StopIteration);
140 // python functions should return NULL after setting any exception
141 return nanobind::object();
142 }
143 return nanobind::cast(DerivedT::getElement(attr.get(), nextIndex++));
144 }
145
146 /// Bind the iterator class.
147 static void bind(nanobind::module_ &m) {
148 nanobind::class_<PyDenseArrayIterator>(m, DerivedT::pyIteratorName)
149 .def("__iter__", &PyDenseArrayIterator::dunderIter)
150 .def("__next__", &PyDenseArrayIterator::dunderNext);
151 }
152
153 private:
154 /// The referenced dense array attribute.
155 PyAttribute attr;
156 /// The next index to read.
157 int nextIndex = 0;
158 };
159
160 /// Get the element at the given index.
161 EltTy getItem(intptr_t i) { return DerivedT::getElement(*this, i); }
162
163 /// Bind the attribute class.
165 // Bind the constructor.
166 if constexpr (std::is_same_v<EltTy, bool>) {
167 c.def_static(
168 "get",
169 [](const nanobind::sequence &py_values, DefaultingPyMlirContext ctx) {
170 std::vector<bool> values;
171 for (nanobind::handle py_value : py_values) {
172 int is_true = PyObject_IsTrue(py_value.ptr());
173 if (is_true < 0) {
174 throw nanobind::python_error();
175 }
176 values.push_back(is_true);
177 }
178 return getAttribute(values, ctx->getRef());
179 },
180 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
181 "Gets a uniqued dense array attribute");
182 } else {
183 c.def_static(
184 "get",
185 [](const std::vector<EltTy> &values, DefaultingPyMlirContext ctx) {
186 return getAttribute(values, ctx->getRef());
187 },
188 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
189 "Gets a uniqued dense array attribute");
190 }
191 // Bind the array methods.
192 c.def("__getitem__", [](DerivedT &arr, intptr_t i) {
193 if (i >= mlirDenseArrayGetNumElements(arr))
194 throw nanobind::index_error("DenseArray index out of range");
195 return arr.getItem(i);
196 });
197 c.def("__len__", [](const DerivedT &arr) {
199 });
200 c.def("__iter__",
201 [](const DerivedT &arr) { return PyDenseArrayIterator(arr); });
202 c.def("__add__", [](DerivedT &arr, const nanobind::sequence &extras) {
203 std::vector<EltTy> values;
204 intptr_t numOldElements = mlirDenseArrayGetNumElements(arr);
205 values.reserve(numOldElements + nanobind::len(extras));
206 for (intptr_t i = 0; i < numOldElements; ++i)
207 values.push_back(arr.getItem(i));
208 for (nanobind::handle attr : extras)
209 values.push_back(pyTryCast<EltTy>(attr));
210 return getAttribute(values, arr.getContext());
211 });
212 }
213
214private:
215 static DerivedT getAttribute(const std::vector<EltTy> &values,
216 PyMlirContextRef ctx) {
217 if constexpr (std::is_same_v<EltTy, bool>) {
218 std::vector<int> intValues(values.begin(), values.end());
219 MlirAttribute attr = DerivedT::getAttribute(ctx->get(), intValues.size(),
220 intValues.data());
221 return DerivedT(ctx, attr);
222 } else {
223 MlirAttribute attr =
224 DerivedT::getAttribute(ctx->get(), values.size(), values.data());
225 return DerivedT(ctx, attr);
226 }
227 }
228};
229
230/// Instantiate the python dense array classes.
232 : public PyDenseArrayAttribute<bool, PyDenseBoolArrayAttribute> {
234 static constexpr auto getAttribute = mlirDenseBoolArrayGet;
236 static constexpr const char *pyClassName = "DenseBoolArrayAttr";
237 static constexpr const char *pyIteratorName = "DenseBoolArrayIterator";
238 using PyDenseArrayAttribute::PyDenseArrayAttribute;
239};
241 : public PyDenseArrayAttribute<int8_t, PyDenseI8ArrayAttribute> {
243 static constexpr auto getAttribute = mlirDenseI8ArrayGet;
244 static constexpr auto getElement = mlirDenseI8ArrayGetElement;
245 static constexpr const char *pyClassName = "DenseI8ArrayAttr";
246 static constexpr const char *pyIteratorName = "DenseI8ArrayIterator";
247 using PyDenseArrayAttribute::PyDenseArrayAttribute;
248};
250 : public PyDenseArrayAttribute<int16_t, PyDenseI16ArrayAttribute> {
252 static constexpr auto getAttribute = mlirDenseI16ArrayGet;
254 static constexpr const char *pyClassName = "DenseI16ArrayAttr";
255 static constexpr const char *pyIteratorName = "DenseI16ArrayIterator";
256 using PyDenseArrayAttribute::PyDenseArrayAttribute;
257};
259 : public PyDenseArrayAttribute<int32_t, PyDenseI32ArrayAttribute> {
261 static constexpr auto getAttribute = mlirDenseI32ArrayGet;
263 static constexpr const char *pyClassName = "DenseI32ArrayAttr";
264 static constexpr const char *pyIteratorName = "DenseI32ArrayIterator";
265 using PyDenseArrayAttribute::PyDenseArrayAttribute;
266};
268 : public PyDenseArrayAttribute<int64_t, PyDenseI64ArrayAttribute> {
270 static constexpr auto getAttribute = mlirDenseI64ArrayGet;
272 static constexpr const char *pyClassName = "DenseI64ArrayAttr";
273 static constexpr const char *pyIteratorName = "DenseI64ArrayIterator";
274 using PyDenseArrayAttribute::PyDenseArrayAttribute;
275};
277 : public PyDenseArrayAttribute<float, PyDenseF32ArrayAttribute> {
279 static constexpr auto getAttribute = mlirDenseF32ArrayGet;
281 static constexpr const char *pyClassName = "DenseF32ArrayAttr";
282 static constexpr const char *pyIteratorName = "DenseF32ArrayIterator";
283 using PyDenseArrayAttribute::PyDenseArrayAttribute;
284};
286 : public PyDenseArrayAttribute<double, PyDenseF64ArrayAttribute> {
288 static constexpr auto getAttribute = mlirDenseF64ArrayGet;
290 static constexpr const char *pyClassName = "DenseF64ArrayAttr";
291 static constexpr const char *pyIteratorName = "DenseF64ArrayIterator";
292 using PyDenseArrayAttribute::PyDenseArrayAttribute;
293};
294
296 : public PyConcreteAttribute<PyArrayAttribute> {
297public:
299 static constexpr const char *pyClassName = "ArrayAttr";
303 static inline const MlirStringRef name = mlirArrayAttrGetName();
304
306 public:
307 PyArrayAttributeIterator(PyAttribute attr) : attr(std::move(attr)) {}
308
310
311 nanobind::typed<nanobind::object, PyAttribute> dunderNext();
312
313 static void bind(nanobind::module_ &m);
314
315 private:
316 PyAttribute attr;
317 int nextIndex = 0;
318 };
319
320 MlirAttribute getItem(intptr_t i) const;
321
322 static void bindDerived(ClassTy &c);
323};
324
325/// Float Point Attribute subclass - FloatAttr.
327 : public PyConcreteAttribute<PyFloatAttribute> {
328public:
330 static constexpr const char *pyClassName = "FloatAttr";
334 static inline const MlirStringRef name = mlirFloatAttrGetName();
335
336 static void bindDerived(ClassTy &c);
337};
338
339/// Integer Attribute subclass - IntegerAttr.
341 : public PyConcreteAttribute<PyIntegerAttribute> {
342public:
344 static constexpr const char *pyClassName = "IntegerAttr";
347
348 static void bindDerived(ClassTy &c);
349
350private:
351 static nanobind::int_ toPyInt(PyIntegerAttribute &self);
352};
353
354/// Bool Attribute subclass - BoolAttr.
356 : public PyConcreteAttribute<PyBoolAttribute> {
357public:
359 static constexpr const char *pyClassName = "BoolAttr";
361
362 static void bindDerived(ClassTy &c);
363};
364
366 : public PyConcreteAttribute<PySymbolRefAttribute> {
367public:
369 static constexpr const char *pyClassName = "SymbolRefAttr";
372
373 static PySymbolRefAttribute fromList(const std::vector<std::string> &symbols,
374 PyMlirContext &context);
375
376 static void bindDerived(ClassTy &c);
377};
378
380 : public PyConcreteAttribute<PyFlatSymbolRefAttribute> {
381public:
383 static constexpr const char *pyClassName = "FlatSymbolRefAttr";
386
387 static void bindDerived(ClassTy &c);
388};
389
391 : public PyConcreteAttribute<PyOpaqueAttribute> {
392public:
394 static constexpr const char *pyClassName = "OpaqueAttr";
398 static inline const MlirStringRef name = mlirOpaqueAttrGetName();
399
400 static void bindDerived(ClassTy &c);
401};
402
403// TODO: Support construction of string elements.
405 : public PyConcreteAttribute<PyDenseElementsAttribute> {
406public:
408 static constexpr const char *pyClassName = "DenseElementsAttr";
410
412 const nanobind::typed<nanobind::sequence, PyAttribute> &attributes,
413 std::optional<PyType> explicitType,
414 DefaultingPyMlirContext contextWrapper);
415
417 getFromBuffer(const nb_buffer &array, bool signless,
418 const std::optional<PyType> &explicitType,
419 std::optional<std::vector<int64_t>> explicitShape,
420 DefaultingPyMlirContext contextWrapper);
421
422 static PyDenseElementsAttribute getSplat(const PyType &shapedType,
423 PyAttribute &elementAttr);
424
425 intptr_t dunderLen() const;
426
427 std::unique_ptr<nb_buffer_info> accessBuffer();
428
429 static void bindDerived(ClassTy &c);
430
431 static PyType_Slot slots[];
432
433protected:
434 /// Registers get/get_splat factory methods with the concrete return
435 /// type in the nb::sig. Subclasses call this from their bindDerived
436 /// to override the return type in generated stubs.
437 template <typename ClassT>
438 static void bindFactoryMethods(ClassT &c, const char *pyClassName);
439
440private:
441 static int bf_getbuffer(PyObject *exporter, Py_buffer *view, int flags);
442 static void bf_releasebuffer(PyObject *, Py_buffer *buffer);
443
444 static bool isUnsignedIntegerFormat(std::string_view format);
445
446 static bool isSignedIntegerFormat(std::string_view format);
447
448 static MlirType
449 getShapedType(std::optional<MlirType> bulkLoadElementType,
450 std::optional<std::vector<int64_t>> explicitShape,
451 Py_buffer &view);
452
453 static MlirAttribute getAttributeFromBuffer(
454 Py_buffer &view, bool signless, std::optional<PyType> explicitType,
455 const std::optional<std::vector<int64_t>> &explicitShape,
456 MlirContext &context);
457
458 template <typename Type>
459 std::unique_ptr<nb_buffer_info>
460 bufferInfo(MlirType shapedType, const char *explicitFormat = nullptr) {
461 intptr_t rank = mlirShapedTypeGetRank(shapedType);
462 // Prepare the data for the buffer_info.
463 // Buffer is configured for read-only access below.
464 Type *data = static_cast<Type *>(
465 const_cast<void *>(mlirDenseElementsAttrGetRawData(*this)));
466 // Prepare the shape for the buffer_info.
467 std::vector<Py_ssize_t> shape;
468 for (intptr_t i = 0; i < rank; ++i)
469 shape.push_back(mlirShapedTypeGetDimSize(shapedType, i));
470 // Prepare the strides for the buffer_info.
471 std::vector<Py_ssize_t> strides;
472 if (mlirDenseElementsAttrIsSplat(*this)) {
473 // Splats are special, only the single value is stored.
474 strides.assign(rank, 0);
475 } else {
476 for (intptr_t i = 1; i < rank; ++i) {
477 intptr_t strideFactor = 1;
478 for (intptr_t j = i; j < rank; ++j)
479 strideFactor *= mlirShapedTypeGetDimSize(shapedType, j);
480 strides.push_back(sizeof(Type) * strideFactor);
481 }
482 strides.push_back(sizeof(Type));
483 }
484 const char *format;
485 if (explicitFormat) {
486 format = explicitFormat;
487 } else {
488 format = nb_format_descriptor<Type>::format();
489 }
490 return std::make_unique<nb_buffer_info>(
491 data, sizeof(Type), format, rank, std::move(shape), std::move(strides),
492 /*readonly=*/true);
493 }
494};
495
496/// Refinement of the PyDenseElementsAttribute for attributes containing
497/// integer (and boolean) values. Supports element access.
499 : public PyConcreteAttribute<PyDenseIntElementsAttribute,
500 PyDenseElementsAttribute> {
501public:
503 static constexpr const char *pyClassName = "DenseIntElementsAttr";
505
506 /// Returns the element at the given linear position. Asserts if the index
507 /// is out of range.
508 nanobind::int_ dunderGetItem(intptr_t pos) const;
509
510 static void bindDerived(ClassTy &c);
511};
512
514 : public PyConcreteAttribute<PyDenseResourceElementsAttribute> {
515public:
516 static constexpr IsAFunctionTy isaFunction =
518 static constexpr const char *pyClassName = "DenseResourceElementsAttr";
520 static inline const MlirStringRef name =
522
524 getFromBuffer(const nb_buffer &buffer, const std::string &name,
525 const PyType &type, std::optional<size_t> alignment,
526 bool isMutable, DefaultingPyMlirContext contextWrapper);
527
528 static void bindDerived(ClassTy &c);
529};
530
532 : public PyConcreteAttribute<PyDictAttribute> {
533public:
535 static constexpr const char *pyClassName = "DictAttr";
540
541 intptr_t dunderLen() const;
542
543 bool dunderContains(const std::string &name) const;
544
545 static void bindDerived(ClassTy &c);
546};
547
548/// Refinement of PyDenseElementsAttribute for attributes containing
549/// floating-point values. Supports element access.
551 : public PyConcreteAttribute<PyDenseFPElementsAttribute,
552 PyDenseElementsAttribute> {
553public:
555 static constexpr const char *pyClassName = "DenseFPElementsAttr";
557
558 nanobind::float_ dunderGetItem(intptr_t pos) const;
559
560 static void bindDerived(ClassTy &c);
561};
562
564 : public PyConcreteAttribute<PyTypeAttribute> {
565public:
567 static constexpr const char *pyClassName = "TypeAttr";
571 static inline const MlirStringRef name = mlirTypeAttrGetName();
572
573 static void bindDerived(ClassTy &c);
574};
575
576/// Unit Attribute subclass. Unit attributes don't have values.
578 : public PyConcreteAttribute<PyUnitAttribute> {
579public:
581 static constexpr const char *pyClassName = "UnitAttr";
585 static inline const MlirStringRef name = mlirUnitAttrGetName();
586
587 static void bindDerived(ClassTy &c);
588};
589
590/// Strided layout attribute subclass.
592 : public PyConcreteAttribute<PyStridedLayoutAttribute> {
593public:
595 static constexpr const char *pyClassName = "StridedLayoutAttr";
600
601 static void bindDerived(ClassTy &c);
602};
603
605 : public PyConcreteAttribute<PyDynamicAttribute> {
606public:
608 static constexpr const char *pyClassName = "DynamicAttr";
610
611 static void bindDerived(ClassTy &c);
612};
613
615} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
616} // namespace python
617} // namespace mlir
618
619#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:1028
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
Definition IRCore.h:1110
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
Definition IRCore.h:1085
nanobind::typed< nanobind::object, EltTy > dunderNext()
Return the next element.
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:901
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.