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 (nanobind::cast_error &err) {
104 std::string msg = std::string("Invalid attribute when attempting to "
105 "create an ArrayAttribute (") +
106 err.what() + ")";
107 throw std::runtime_error(msg.c_str());
108 } catch (std::runtime_error &err) {
109 std::string msg = std::string("Invalid attribute (None?) when attempting "
110 "to create an ArrayAttribute (") +
111 err.what() + ")";
112 throw std::runtime_error(msg.c_str());
113 }
114}
115
116/// A python-wrapped dense array attribute with an element type and a derived
117/// implementation class.
118template <typename EltTy, typename DerivedT>
120 : public PyConcreteAttribute<DerivedT> {
121public:
123
124 /// Iterator over the integer elements of a dense array.
126 public:
127 PyDenseArrayIterator(PyAttribute attr) : attr(std::move(attr)) {}
128
129 /// Return a copy of the iterator.
131
132 /// Return the next element.
133 EltTy dunderNext() {
134 // Throw if the index has reached the end.
135 if (nextIndex >= mlirDenseArrayGetNumElements(attr.get()))
136 throw nanobind::stop_iteration();
137 return DerivedT::getElement(attr.get(), nextIndex++);
138 }
139
140 /// Bind the iterator class.
141 static void bind(nanobind::module_ &m) {
142 nanobind::class_<PyDenseArrayIterator>(m, DerivedT::pyIteratorName)
143 .def("__iter__", &PyDenseArrayIterator::dunderIter)
144 .def("__next__", &PyDenseArrayIterator::dunderNext);
145 }
146
147 private:
148 /// The referenced dense array attribute.
149 PyAttribute attr;
150 /// The next index to read.
151 int nextIndex = 0;
152 };
153
154 /// Get the element at the given index.
155 EltTy getItem(intptr_t i) { return DerivedT::getElement(*this, i); }
156
157 /// Bind the attribute class.
159 // Bind the constructor.
160 if constexpr (std::is_same_v<EltTy, bool>) {
161 c.def_static(
162 "get",
163 [](const nanobind::sequence &py_values, DefaultingPyMlirContext ctx) {
164 std::vector<bool> values;
165 for (nanobind::handle py_value : py_values) {
166 int is_true = PyObject_IsTrue(py_value.ptr());
167 if (is_true < 0) {
168 throw nanobind::python_error();
169 }
170 values.push_back(is_true);
171 }
172 return getAttribute(values, ctx->getRef());
173 },
174 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
175 "Gets a uniqued dense array attribute");
176 } else {
177 c.def_static(
178 "get",
179 [](const std::vector<EltTy> &values, DefaultingPyMlirContext ctx) {
180 return getAttribute(values, ctx->getRef());
181 },
182 nanobind::arg("values"), nanobind::arg("context") = nanobind::none(),
183 "Gets a uniqued dense array attribute");
184 }
185 // Bind the array methods.
186 c.def("__getitem__", [](DerivedT &arr, intptr_t i) {
187 if (i >= mlirDenseArrayGetNumElements(arr))
188 throw nanobind::index_error("DenseArray index out of range");
189 return arr.getItem(i);
190 });
191 c.def("__len__", [](const DerivedT &arr) {
193 });
194 c.def("__iter__",
195 [](const DerivedT &arr) { return PyDenseArrayIterator(arr); });
196 c.def("__add__", [](DerivedT &arr, const nanobind::list &extras) {
197 std::vector<EltTy> values;
198 intptr_t numOldElements = mlirDenseArrayGetNumElements(arr);
199 values.reserve(numOldElements + nanobind::len(extras));
200 for (intptr_t i = 0; i < numOldElements; ++i)
201 values.push_back(arr.getItem(i));
202 for (nanobind::handle attr : extras)
203 values.push_back(pyTryCast<EltTy>(attr));
204 return getAttribute(values, arr.getContext());
205 });
206 }
207
208private:
209 static DerivedT getAttribute(const std::vector<EltTy> &values,
210 PyMlirContextRef ctx) {
211 if constexpr (std::is_same_v<EltTy, bool>) {
212 std::vector<int> intValues(values.begin(), values.end());
213 MlirAttribute attr = DerivedT::getAttribute(ctx->get(), intValues.size(),
214 intValues.data());
215 return DerivedT(ctx, attr);
216 } else {
217 MlirAttribute attr =
218 DerivedT::getAttribute(ctx->get(), values.size(), values.data());
219 return DerivedT(ctx, attr);
220 }
221 }
222};
223
224/// Instantiate the python dense array classes.
226 : public PyDenseArrayAttribute<bool, PyDenseBoolArrayAttribute> {
228 static constexpr auto getAttribute = mlirDenseBoolArrayGet;
230 static constexpr const char *pyClassName = "DenseBoolArrayAttr";
231 static constexpr const char *pyIteratorName = "DenseBoolArrayIterator";
232 using PyDenseArrayAttribute::PyDenseArrayAttribute;
233};
235 : public PyDenseArrayAttribute<int8_t, PyDenseI8ArrayAttribute> {
237 static constexpr auto getAttribute = mlirDenseI8ArrayGet;
238 static constexpr auto getElement = mlirDenseI8ArrayGetElement;
239 static constexpr const char *pyClassName = "DenseI8ArrayAttr";
240 static constexpr const char *pyIteratorName = "DenseI8ArrayIterator";
241 using PyDenseArrayAttribute::PyDenseArrayAttribute;
242};
244 : public PyDenseArrayAttribute<int16_t, PyDenseI16ArrayAttribute> {
246 static constexpr auto getAttribute = mlirDenseI16ArrayGet;
248 static constexpr const char *pyClassName = "DenseI16ArrayAttr";
249 static constexpr const char *pyIteratorName = "DenseI16ArrayIterator";
250 using PyDenseArrayAttribute::PyDenseArrayAttribute;
251};
253 : public PyDenseArrayAttribute<int32_t, PyDenseI32ArrayAttribute> {
255 static constexpr auto getAttribute = mlirDenseI32ArrayGet;
257 static constexpr const char *pyClassName = "DenseI32ArrayAttr";
258 static constexpr const char *pyIteratorName = "DenseI32ArrayIterator";
259 using PyDenseArrayAttribute::PyDenseArrayAttribute;
260};
262 : public PyDenseArrayAttribute<int64_t, PyDenseI64ArrayAttribute> {
264 static constexpr auto getAttribute = mlirDenseI64ArrayGet;
266 static constexpr const char *pyClassName = "DenseI64ArrayAttr";
267 static constexpr const char *pyIteratorName = "DenseI64ArrayIterator";
268 using PyDenseArrayAttribute::PyDenseArrayAttribute;
269};
271 : public PyDenseArrayAttribute<float, PyDenseF32ArrayAttribute> {
273 static constexpr auto getAttribute = mlirDenseF32ArrayGet;
275 static constexpr const char *pyClassName = "DenseF32ArrayAttr";
276 static constexpr const char *pyIteratorName = "DenseF32ArrayIterator";
277 using PyDenseArrayAttribute::PyDenseArrayAttribute;
278};
280 : public PyDenseArrayAttribute<double, PyDenseF64ArrayAttribute> {
282 static constexpr auto getAttribute = mlirDenseF64ArrayGet;
284 static constexpr const char *pyClassName = "DenseF64ArrayAttr";
285 static constexpr const char *pyIteratorName = "DenseF64ArrayIterator";
286 using PyDenseArrayAttribute::PyDenseArrayAttribute;
287};
288
290 : public PyConcreteAttribute<PyArrayAttribute> {
291public:
293 static constexpr const char *pyClassName = "ArrayAttr";
297 static inline const MlirStringRef name = mlirArrayAttrGetName();
298
300 public:
301 PyArrayAttributeIterator(PyAttribute attr) : attr(std::move(attr)) {}
302
304
305 nanobind::typed<nanobind::object, PyAttribute> dunderNext();
306
307 static void bind(nanobind::module_ &m);
308
309 private:
310 PyAttribute attr;
311 int nextIndex = 0;
312 };
313
314 MlirAttribute getItem(intptr_t i) const;
315
316 static void bindDerived(ClassTy &c);
317};
318
319/// Float Point Attribute subclass - FloatAttr.
321 : public PyConcreteAttribute<PyFloatAttribute> {
322public:
324 static constexpr const char *pyClassName = "FloatAttr";
328 static inline const MlirStringRef name = mlirFloatAttrGetName();
329
330 static void bindDerived(ClassTy &c);
331};
332
333/// Integer Attribute subclass - IntegerAttr.
335 : public PyConcreteAttribute<PyIntegerAttribute> {
336public:
338 static constexpr const char *pyClassName = "IntegerAttr";
341
342 static void bindDerived(ClassTy &c);
343
344private:
345 static nanobind::object toPyInt(PyIntegerAttribute &self);
346};
347
348/// Bool Attribute subclass - BoolAttr.
350 : public PyConcreteAttribute<PyBoolAttribute> {
351public:
353 static constexpr const char *pyClassName = "BoolAttr";
355
356 static void bindDerived(ClassTy &c);
357};
358
360 : public PyConcreteAttribute<PySymbolRefAttribute> {
361public:
363 static constexpr const char *pyClassName = "SymbolRefAttr";
366
367 static PySymbolRefAttribute fromList(const std::vector<std::string> &symbols,
368 PyMlirContext &context);
369
370 static void bindDerived(ClassTy &c);
371};
372
374 : public PyConcreteAttribute<PyFlatSymbolRefAttribute> {
375public:
377 static constexpr const char *pyClassName = "FlatSymbolRefAttr";
380
381 static void bindDerived(ClassTy &c);
382};
383
385 : public PyConcreteAttribute<PyOpaqueAttribute> {
386public:
388 static constexpr const char *pyClassName = "OpaqueAttr";
392 static inline const MlirStringRef name = mlirOpaqueAttrGetName();
393
394 static void bindDerived(ClassTy &c);
395};
396
397// TODO: Support construction of string elements.
399 : public PyConcreteAttribute<PyDenseElementsAttribute> {
400public:
402 static constexpr const char *pyClassName = "DenseElementsAttr";
404
406 getFromList(const nanobind::list &attributes,
407 std::optional<PyType> explicitType,
408 DefaultingPyMlirContext contextWrapper);
409
411 getFromBuffer(const nb_buffer &array, bool signless,
412 const std::optional<PyType> &explicitType,
413 std::optional<std::vector<int64_t>> explicitShape,
414 DefaultingPyMlirContext contextWrapper);
415
416 static PyDenseElementsAttribute getSplat(const PyType &shapedType,
417 PyAttribute &elementAttr);
418
419 intptr_t dunderLen() const;
420
421 std::unique_ptr<nb_buffer_info> accessBuffer();
422
423 static void bindDerived(ClassTy &c);
424
425 static PyType_Slot slots[];
426
427private:
428 static int bf_getbuffer(PyObject *exporter, Py_buffer *view, int flags);
429 static void bf_releasebuffer(PyObject *, Py_buffer *buffer);
430
431 static bool isUnsignedIntegerFormat(std::string_view format);
432
433 static bool isSignedIntegerFormat(std::string_view format);
434
435 static MlirType
436 getShapedType(std::optional<MlirType> bulkLoadElementType,
437 std::optional<std::vector<int64_t>> explicitShape,
438 Py_buffer &view);
439
440 static MlirAttribute getAttributeFromBuffer(
441 Py_buffer &view, bool signless, std::optional<PyType> explicitType,
442 const std::optional<std::vector<int64_t>> &explicitShape,
443 MlirContext &context);
444
445 template <typename Type>
446 std::unique_ptr<nb_buffer_info>
447 bufferInfo(MlirType shapedType, const char *explicitFormat = nullptr) {
448 intptr_t rank = mlirShapedTypeGetRank(shapedType);
449 // Prepare the data for the buffer_info.
450 // Buffer is configured for read-only access below.
451 Type *data = static_cast<Type *>(
452 const_cast<void *>(mlirDenseElementsAttrGetRawData(*this)));
453 // Prepare the shape for the buffer_info.
454 std::vector<Py_ssize_t> shape;
455 for (intptr_t i = 0; i < rank; ++i)
456 shape.push_back(mlirShapedTypeGetDimSize(shapedType, i));
457 // Prepare the strides for the buffer_info.
458 std::vector<Py_ssize_t> strides;
459 if (mlirDenseElementsAttrIsSplat(*this)) {
460 // Splats are special, only the single value is stored.
461 strides.assign(rank, 0);
462 } else {
463 for (intptr_t i = 1; i < rank; ++i) {
464 intptr_t strideFactor = 1;
465 for (intptr_t j = i; j < rank; ++j)
466 strideFactor *= mlirShapedTypeGetDimSize(shapedType, j);
467 strides.push_back(sizeof(Type) * strideFactor);
468 }
469 strides.push_back(sizeof(Type));
470 }
471 const char *format;
472 if (explicitFormat) {
473 format = explicitFormat;
474 } else {
475 format = nb_format_descriptor<Type>::format();
476 }
477 return std::make_unique<nb_buffer_info>(
478 data, sizeof(Type), format, rank, std::move(shape), std::move(strides),
479 /*readonly=*/true);
480 }
481};
482
483/// Refinement of the PyDenseElementsAttribute for attributes containing
484/// integer (and boolean) values. Supports element access.
486 : public PyConcreteAttribute<PyDenseIntElementsAttribute,
487 PyDenseElementsAttribute> {
488public:
490 static constexpr const char *pyClassName = "DenseIntElementsAttr";
492
493 /// Returns the element at the given linear position. Asserts if the index
494 /// is out of range.
495 nanobind::int_ dunderGetItem(intptr_t pos) const;
496
497 static void bindDerived(ClassTy &c);
498};
499
501 : public PyConcreteAttribute<PyDenseResourceElementsAttribute> {
502public:
503 static constexpr IsAFunctionTy isaFunction =
505 static constexpr const char *pyClassName = "DenseResourceElementsAttr";
507 static inline const MlirStringRef name =
509
511 getFromBuffer(const nb_buffer &buffer, const std::string &name,
512 const PyType &type, std::optional<size_t> alignment,
513 bool isMutable, DefaultingPyMlirContext contextWrapper);
514
515 static void bindDerived(ClassTy &c);
516};
517
519 : public PyConcreteAttribute<PyDictAttribute> {
520public:
522 static constexpr const char *pyClassName = "DictAttr";
527
528 intptr_t dunderLen() const;
529
530 bool dunderContains(const std::string &name) const;
531
532 static void bindDerived(ClassTy &c);
533};
534
535/// Refinement of PyDenseElementsAttribute for attributes containing
536/// floating-point values. Supports element access.
538 : public PyConcreteAttribute<PyDenseFPElementsAttribute,
539 PyDenseElementsAttribute> {
540public:
542 static constexpr const char *pyClassName = "DenseFPElementsAttr";
544
545 nanobind::float_ dunderGetItem(intptr_t pos) const;
546
547 static void bindDerived(ClassTy &c);
548};
549
551 : public PyConcreteAttribute<PyTypeAttribute> {
552public:
554 static constexpr const char *pyClassName = "TypeAttr";
558 static inline const MlirStringRef name = mlirTypeAttrGetName();
559
560 static void bindDerived(ClassTy &c);
561};
562
563/// Unit Attribute subclass. Unit attributes don't have values.
565 : public PyConcreteAttribute<PyUnitAttribute> {
566public:
568 static constexpr const char *pyClassName = "UnitAttr";
572 static inline const MlirStringRef name = mlirUnitAttrGetName();
573
574 static void bindDerived(ClassTy &c);
575};
576
577/// Strided layout attribute subclass.
579 : public PyConcreteAttribute<PyStridedLayoutAttribute> {
580public:
582 static constexpr const char *pyClassName = "StridedLayoutAttr";
587
588 static void bindDerived(ClassTy &c);
589};
590
592} // namespace MLIR_BINDINGS_PYTHON_DOMAIN
593} // namespace python
594} // namespace mlir
595
596#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:279
static constexpr GetTypeIDFunctionTy getTypeIdFunction
Wrapper around the generic MlirAttribute.
Definition IRCore.h:1006
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
Definition IRCore.h:1088
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
Definition IRCore.h:1063
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:212
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 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:198
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.