29using namespace nanobind::literals;
38 R
"(Gets a DenseElementsAttr from a Python buffer or array.
40When `type` is not provided, then some limited type inferencing is done based
41on the buffer format. Support presently exists for 8/16/32/64 signed and
42unsigned integers and float16/float32/float64. DenseElementsAttrs of these
43types can also be converted back to a corresponding buffer.
45For conversions outside of these types, a `type=` must be explicitly provided
46and the buffer contents must be bit-castable to the MLIR internal
49 * Integer types: the buffer must be byte aligned to the next byte boundary.
50 * Floating point types: Must be bit-castable to the given floating point
52 * i1 (bool): Each boolean value is stored as a single byte (0 or 1).
54If a single element buffer is passed, then a splat will be created.
57 array: The array or buffer to convert.
58 signless: If inferring an appropriate MLIR type, use signless types for
59 integers (defaults True).
60 type: Skips inference of the MLIR element type and uses this instead. The
61 storage size must be consistent with the actual contents of the buffer.
62 shape: Overrides the shape of the buffer when constructing the MLIR
63 shaped type. This is needed when the physical and logical shape differ.
64 context: Explicit context, if not from context manager.
67 DenseElementsAttr on success.
70 ValueError: If the type of the buffer or array cannot be matched to an MLIR
71 type or if the buffer does not meet expectations.
75 R
"(Gets a DenseElementsAttr from a Python list of attributes.
77Note that it can be expensive to construct attributes individually.
78For a large number of elements, consider using a Python buffer or array instead.
81 attrs: A list of attributes.
82 type: The desired shape and type of the resulting DenseElementsAttr.
83 If not provided, the element type is determined based on the type
84 of the 0th attribute and the shape is `[len(attrs)]`.
85 context: Explicit context, if not from context manager.
88 DenseElementsAttr on success.
91 ValueError: If the type of the attributes does not match the type
92 specified by `shaped_type`.
96 R
"(Gets a DenseResourceElementsAttr from a Python buffer or array.
98This function does minimal validation or massaging of the data, and it is
99up to the caller to ensure that the buffer meets the characteristics
102The backing buffer and any user objects will be retained for the lifetime
103of the resource blob. This is typically bounded to the context but the
104resource can have a shorter lifespan depending on how it is used in
105subsequent processing.
108 buffer: The array or buffer to convert.
109 name: Name to provide to the resource (may be changed upon collision).
110 type: The explicit ShapedType to construct the attribute with.
111 context: Explicit context, if not from context manager.
114 DenseResourceElementsAttr on success.
117 ValueError: If the type of the buffer or array cannot be matched to an MLIR
118 type or if the buffer does not meet expectations.
123template <
typename Callable>
124class [[nodiscard]] scope_exit {
125 Callable ExitFunction;
129 template <
typename Fp>
130 explicit scope_exit(Fp &&F) : ExitFunction(std::forward<Fp>(F)) {}
132 scope_exit(scope_exit &&Rhs)
133 : ExitFunction(std::move(Rhs.ExitFunction)), Engaged(Rhs.Engaged) {
136 scope_exit(
const scope_exit &) =
delete;
137 scope_exit &operator=(scope_exit &&) =
delete;
138 scope_exit &operator=(
const scope_exit &) =
delete;
140 void release() { Engaged =
false; }
148template <
typename Callable>
149scope_exit(Callable) -> scope_exit<Callable>;
158 std::vector<Py_ssize_t> shape_in, std::vector<Py_ssize_t> strides_in,
160 std::unique_ptr<Py_buffer,
void (*)(Py_buffer *)> owned_view_in)
162 shape(std::move(shape_in)),
strides(std::move(strides_in)),
165 for (Py_ssize_t i = 0; i <
ndim; ++i) {
171 int flags = PyBUF_STRIDES | PyBUF_FORMAT;
172 auto *view =
new Py_buffer();
173 if (PyObject_GetBuffer(
ptr(), view, flags) != 0) {
175 throw nb::python_error();
182 static const char *
format() {
return "?"; }
186 static const char *
format() {
return "b"; }
190 static const char *
format() {
return "B"; }
194 static const char *
format() {
return "h"; }
198 static const char *
format() {
return "H"; }
202 static const char *
format() {
return "i"; }
206 static const char *
format() {
return "I"; }
210 static const char *
format() {
return "q"; }
214 static const char *
format() {
return "Q"; }
218 static const char *
format() {
return "f"; }
222 static const char *
format() {
return "d"; }
232 nb::arg(
"affine_map"),
"Gets an attribute wrapping an AffineMap.");
238 "Returns the value of the AffineMap attribute");
248 nb::arg(
"integer_set"),
"Gets an attribute wrapping an IntegerSet.");
251nb::typed<nb::object, PyAttribute>
254 if (PyArrayAttribute::PyArrayAttributeIterator::nextIndex >=
256 PyArrayAttribute::PyArrayAttributeIterator::attr.
get())) {
257 PyErr_SetNone(PyExc_StopIteration);
262 this->PyArrayAttribute::PyArrayAttributeIterator::attr
265 PyArrayAttribute::PyArrayAttributeIterator::attr.
get(),
266 PyArrayAttribute::PyArrayAttributeIterator::nextIndex++))
271 nb::class_<PyArrayAttributeIterator>(m,
"ArrayAttributeIterator")
283 [](nb::typed<nb::sequence, PyAttribute> attributes,
285 std::vector<MlirAttribute> mlirAttributes;
286 mlirAttributes.reserve(nb::len(attributes));
287 for (
auto attribute : attributes) {
291 context->
get(), mlirAttributes.size(), mlirAttributes.data());
294 nb::arg(
"attributes"), nb::arg(
"context") = nb::none(),
295 "Gets a uniqued Array attribute");
298 intptr_t i) -> nb::typed<nb::object, PyAttribute> {
300 throw nb::index_error(
"ArrayAttribute index out of range");
311 nb::typed<nb::sequence, PyAttribute> extras) {
312 std::vector<MlirAttribute> attributes;
314 attributes.reserve(numOldElements + nb::len(extras));
315 for (
intptr_t i = 0; i < numOldElements; ++i)
316 attributes.push_back(arr.
getItem(i));
317 for (nb::handle attr : extras)
320 arr.
getContext()->
get(), attributes.size(), attributes.data());
330 if (mlirAttributeIsNull(attr))
334 nb::arg(
"type"), nb::arg(
"value"), nb::arg(
"loc") = nb::none(),
335 "Gets an uniqued float point attribute associated to a type");
342 if (mlirAttributeIsNull(attr))
346 nb::arg(
"type"), nb::arg(
"value"), nb::arg(
"context") = nb::none(),
347 "Gets an uniqued float point attribute associated to a type");
355 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
356 "Gets an uniqued float point attribute associated to a f32 type");
364 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
365 "Gets an uniqued float point attribute associated to a f64 type");
367 "Returns the value of the float attribute");
369 "Converts the value of the float attribute to a Python float");
375 [](
PyType &type, nb::object value) {
378 int64_t intValue = nb::cast<int64_t>(value);
387 if (bitWidth <= 64) {
388 int64_t intValue = nb::cast<int64_t>(value);
394 unsigned numWords = std::ceil(
static_cast<double>(bitWidth) / 64);
395 std::vector<uint64_t> words(numWords, 0);
398 nb::object mask = nb::int_(0xFFFFFFFFFFFFFFFFULL);
399 nb::object shift = nb::int_(64);
400 nb::object current = value;
405 nb::object zero = nb::int_(0);
406 if (nb::cast<bool>(current < zero)) {
407 nb::object twoToTheBitWidth = nb::int_(1) << nb::int_(bitWidth);
408 current = current + twoToTheBitWidth;
412 for (
unsigned i = 0; i < numWords; ++i) {
413 words[i] = nb::cast<uint64_t>(current & mask);
414 current = current >> shift;
421 nb::arg(
"type"), nb::arg(
"value"),
422 "Gets an uniqued integer attribute associated to a type");
423 c.def_prop_ro(
"value", toPyInt,
"Returns the value of the integer attribute");
424 c.def(
"__int__", toPyInt,
425 "Converts the value of the integer attribute to a Python int");
426 c.def_prop_ro_static(
"static_typeid", [](nb::object & ) {
436 if (bitWidth <= 64) {
446 std::vector<uint64_t> words(numWords);
451 nb::object
result = nb::int_(0);
452 nb::object shift = nb::int_(64);
453 for (
unsigned i = numWords; i > 0; --i) {
461 bool signBitSet = (words[numWords - 1] >> ((bitWidth - 1) % 64)) & 1;
463 nb::object twoToTheBitWidth = nb::int_(1) << nb::int_(bitWidth);
468 return nb::cast<nb::int_>(
result);
478 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
479 "Gets an uniqued bool attribute");
481 "Returns the value of the bool attribute");
483 "Converts the value of the bool attribute to a Python bool");
490 throw std::runtime_error(
"SymbolRefAttr must be composed of at least "
493 std::vector<MlirAttribute> referenceAttrs;
494 for (
size_t i = 1; i < symbols.size(); ++i) {
495 referenceAttrs.push_back(
500 referenceAttrs.size(),
501 referenceAttrs.
data()));
507 [](
const std::vector<std::string> &symbols,
511 nb::arg(
"symbols"), nb::arg(
"context") = nb::none(),
512 "Gets a uniqued SymbolRef attribute from a list of symbol names");
517 std::vector<MlirStringRef> symbols;
518 symbols.reserve(numNested + 1);
520 for (
intptr_t i = 0; i < numNested; ++i) {
526 "Returns the value of the SymbolRef attribute as a list[str]");
537 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
538 "Gets a uniqued FlatSymbolRef attribute");
543 return nb::str(stringRef.
data, stringRef.
length);
545 "Returns the value of the FlatSymbolRef attribute as a string");
551 [](
const std::string &dialectNamespace,
const nb_buffer &buffer,
557 static_cast<char *
>(bufferInfo.
ptr), type);
560 nb::arg(
"dialect_namespace"), nb::arg(
"buffer"), nb::arg(
"type"),
561 nb::arg(
"context") = nb::none(),
563 nb::sig(
"def get(dialect_namespace: str, buffer: typing_extensions.Buffer, type: Type, context: Context | None = None) -> OpaqueAttr"),
565 "Gets an Opaque attribute.");
570 return nb::str(stringRef.
data, stringRef.
length);
572 "Returns the dialect namespace for the Opaque attribute as a string");
577 return nb::bytes(stringRef.
data, stringRef.
length);
579 "Returns the data for the Opaqued attributes as `bytes`");
583 const nb::typed<nb::sequence, PyAttribute> &attributes,
584 std::optional<PyType> explicitType,
586 const size_t numAttributes = nb::len(attributes);
587 if (numAttributes == 0)
588 throw nb::value_error(
"Attributes list must be non-empty.");
596 "Expected a static ShapedType for the shaped_type parameter: ",
597 nb::cast<std::string>(nb::repr(nb::cast(*explicitType))));
598 throw nb::value_error(message.c_str());
600 shapedType = *explicitType;
602 std::vector<int64_t>
shape = {
static_cast<int64_t>(numAttributes)};
609 std::vector<MlirAttribute> mlirAttributes;
610 mlirAttributes.reserve(numAttributes);
611 for (
const nb::handle &attribute : attributes) {
614 mlirAttributes.push_back(mlirAttribute);
618 "All attributes must be of the same type and match the type "
619 "parameter: expected=",
620 nb::cast<std::string>(nb::repr(nb::cast(shapedType))),
621 ", but got=", nb::cast<std::string>(nb::repr(nb::cast(attrType))));
622 throw nb::value_error(message.c_str());
627 shapedType, mlirAttributes.size(), mlirAttributes.data());
634 const std::optional<PyType> &explicitType,
635 std::optional<std::vector<int64_t>> explicitShape,
638 int flags = PyBUF_ND;
640 flags |= PyBUF_FORMAT;
643 if (PyObject_GetBuffer(array.ptr(), &view, flags) != 0) {
644 throw nb::python_error();
646 scope_exit freeBuffer([&]() { PyBuffer_Release(&view); });
648 MlirContext context = contextWrapper->
get();
649 MlirAttribute attr = getAttributeFromBuffer(
650 view, signless, explicitType, std::move(explicitShape), context);
651 if (mlirAttributeIsNull(attr)) {
652 throw std::invalid_argument(
653 "DenseElementsAttr could not be constructed from the given buffer. "
654 "This may mean that the Python buffer layout does not match that "
655 "MLIR expected layout and is a bug.");
663 auto contextWrapper =
667 std::string message =
"Illegal element type for DenseElementsAttr: ";
668 message.append(nb::cast<std::string>(nb::repr(nb::cast(elementAttr))));
669 throw nb::value_error(message.c_str());
673 std::string message =
674 "Expected a static ShapedType for the shaped_type parameter: ";
675 message.append(nb::cast<std::string>(nb::repr(nb::cast(shapedType))));
676 throw nb::value_error(message.c_str());
681 std::string message =
682 "Shaped element type and attribute type must be equal: shaped=";
683 message.append(nb::cast<std::string>(nb::repr(nb::cast(shapedType))));
684 message.append(
", element=");
685 message.append(nb::cast<std::string>(nb::repr(nb::cast(elementAttr))));
686 throw nb::value_error(message.c_str());
689 MlirAttribute elements =
705 return bufferInfo<float>(shapedType);
709 return bufferInfo<double>(shapedType);
713 return bufferInfo<uint16_t>(shapedType,
"e");
717 return bufferInfo<int64_t>(shapedType);
724 return bufferInfo<int32_t>(shapedType);
728 return bufferInfo<uint32_t>(shapedType);
735 return bufferInfo<int64_t>(shapedType);
739 return bufferInfo<uint64_t>(shapedType);
746 return bufferInfo<int8_t>(shapedType);
750 return bufferInfo<uint8_t>(shapedType);
757 return bufferInfo<int16_t>(shapedType);
761 return bufferInfo<uint16_t>(shapedType);
766 return bufferInfo<bool>(shapedType);
771 throw std::invalid_argument(
772 "unsupported data type for conversion to Python buffer");
775template <
typename ClassT>
778 std::string getSig1 =
780 "def get(array: typing_extensions.Buffer, signless: bool = True, type: Type | None = None, shape: Sequence[int] | None = None, context: Context | None = None) -> " +
783 std::string getSig2 =
785 "def get(attrs: Sequence[Attribute], type: Type | None = None, context: Context | None = None) -> " +
788 std::string getSplatSig =
790 "def get_splat(shaped_type: Type, element_attr: Attribute) -> " +
795 nb::arg(
"signless") =
true, nb::arg(
"type") = nb::none(),
796 nb::arg(
"shape") = nb::none(), nb::arg(
"context") = nb::none(),
799 nb::arg(
"attrs"), nb::arg(
"type") = nb::none(),
800 nb::arg(
"context") = nb::none(), nb::sig(getSig2.c_str()),
803 nb::arg(
"shaped_type"), nb::arg(
"element_attr"),
804 nb::sig(getSplatSig.c_str()),
806 " where all values are the same")
813 c.def_prop_ro(
"is_splat",
817 .def(
"get_splat_value",
819 -> nb::typed<nb::object, PyAttribute> {
821 throw nb::value_error(
822 "get_splat_value called on a non-splat attribute");
829bool PyDenseElementsAttribute::isUnsignedIntegerFormat(
830 std::string_view format) {
833 char code = format[0];
834 return code ==
'I' || code ==
'B' || code ==
'H' || code ==
'L' ||
838bool PyDenseElementsAttribute::isSignedIntegerFormat(std::string_view format) {
841 char code = format[0];
842 return code ==
'i' || code ==
'b' || code ==
'h' || code ==
'l' ||
846MlirType PyDenseElementsAttribute::getShapedType(
847 std::optional<MlirType> bulkLoadElementType,
848 std::optional<std::vector<int64_t>> explicitShape, Py_buffer &view) {
849 std::vector<int64_t>
shape;
851 shape.insert(
shape.end(), explicitShape->begin(), explicitShape->end());
853 shape.insert(
shape.end(), view.shape, view.shape + view.ndim);
858 throw std::invalid_argument(
"Shape can only be specified explicitly "
859 "when the type is not a shaped type.");
861 return *bulkLoadElementType;
865 *bulkLoadElementType, encodingAttr);
868MlirAttribute PyDenseElementsAttribute::getAttributeFromBuffer(
869 Py_buffer &view,
bool signless, std::optional<PyType> explicitType,
870 const std::optional<std::vector<int64_t>> &explicitShape,
871 MlirContext &context) {
876 std::optional<MlirType> bulkLoadElementType;
878 bulkLoadElementType = *explicitType;
880 std::string_view format(view.format);
883 assert(view.itemsize == 4 &&
"mismatched array itemsize");
885 }
else if (format ==
"d") {
887 assert(view.itemsize == 8 &&
"mismatched array itemsize");
889 }
else if (format ==
"e") {
891 assert(view.itemsize == 2 &&
"mismatched array itemsize");
893 }
else if (format ==
"?") {
896 }
else if (isSignedIntegerFormat(format)) {
897 if (view.itemsize == 4) {
901 }
else if (view.itemsize == 8) {
905 }
else if (view.itemsize == 1) {
909 }
else if (view.itemsize == 2) {
914 }
else if (isUnsignedIntegerFormat(format)) {
915 if (view.itemsize == 4) {
917 bulkLoadElementType = signless
920 }
else if (view.itemsize == 8) {
922 bulkLoadElementType = signless
925 }
else if (view.itemsize == 1) {
929 }
else if (view.itemsize == 2) {
931 bulkLoadElementType = signless
936 if (!bulkLoadElementType) {
937 throw std::invalid_argument(
938 std::string(
"unimplemented array format conversion from format: ") +
939 std::string(format));
943 MlirType type = getShapedType(bulkLoadElementType, explicitShape, view);
949 reinterpret_cast<void *
>(PyDenseElementsAttribute::bf_getbuffer)},
950 {Py_bf_releasebuffer,
951 reinterpret_cast<void *
>(PyDenseElementsAttribute::bf_releasebuffer)},
955 int PyDenseElementsAttribute::bf_getbuffer(PyObject *obj,
959 std::unique_ptr<nb_buffer_info> info;
961 auto *attr = nb::cast<PyDenseElementsAttribute *>(nb::handle(obj));
962 info = attr->accessBuffer();
963 }
catch (nb::python_error &e) {
965 nb::chain_error(PyExc_BufferError,
"Error converting attribute to buffer");
967 }
catch (std::exception &e) {
968 nb::chain_error(PyExc_BufferError,
969 "Error converting attribute to buffer: %s", e.what());
974 view->buf = info->ptr;
975 view->itemsize = info->itemsize;
976 view->len = info->itemsize;
977 for (
auto s : info->shape) {
980 view->readonly = info->readonly;
981 if ((flags & PyBUF_FORMAT) == PyBUF_FORMAT) {
982 view->format =
const_cast<char *
>(info->format);
984 if ((flags & PyBUF_STRIDES) == PyBUF_STRIDES) {
985 view->ndim =
static_cast<int>(info->ndim);
986 view->strides = info->strides.data();
987 view->shape = info->shape.data();
989 view->suboffsets =
nullptr;
990 view->internal = info.release();
995 void PyDenseElementsAttribute::bf_releasebuffer(PyObject *,
997 delete reinterpret_cast<nb_buffer_info *
>(view->internal);
1002 throw nb::index_error(
"attempt to access out of bounds element");
1011 "dense int elements attribute");
1055 throw nb::type_error(
"Unsupported integer type");
1066#if defined(Py_LIMITED_API) && Py_LIMITED_API < 0x030d0000
1071 PyObject *fn = PySys_GetObject(
"is_finalizing");
1074 PyObject *
result = PyObject_CallNoArgs(fn);
1079 int val = PyObject_IsTrue(
result);
1081 return val > 0 ? 1 : 0;
1083#elif PY_VERSION_HEX < 0x030d0000
1084#define Py_IsFinalizing _Py_IsFinalizing
1090 std::optional<size_t> alignment,
bool isMutable,
1093 throw std::invalid_argument(
1094 "Constructing a DenseResourceElementsAttr requires a ShapedType.");
1099 int flags = PyBUF_STRIDES;
1100 std::unique_ptr<Py_buffer> view = std::make_unique<Py_buffer>();
1101 if (PyObject_GetBuffer(buffer.ptr(), view.get(), flags) != 0) {
1102 throw nb::python_error();
1107 scope_exit freeBuffer([&]() {
1109 PyBuffer_Release(view.get());
1112 if (!PyBuffer_IsContiguous(view.get(),
'A')) {
1113 throw std::invalid_argument(
"Contiguous buffer is required.");
1117 size_t inferredAlignment;
1119 inferredAlignment = *alignment;
1120 else if (view->ndim == 0)
1121 inferredAlignment = view->itemsize;
1123 inferredAlignment = view->strides[view->ndim - 1];
1126 auto deleter = [](
void *userData,
const void *data,
size_t size,
1130 assert(Py_IsInitialized() &&
"expected interpreter to be initialized");
1131 Py_buffer *ownedView =
static_cast<Py_buffer *
>(userData);
1132 nb::gil_scoped_acquire gil;
1133 PyBuffer_Release(ownedView);
1137 size_t rawBufferSize = view->len;
1140 isMutable, deleter,
static_cast<void *
>(view.get()));
1141 if (mlirAttributeIsNull(attr)) {
1142 throw std::invalid_argument(
1143 "DenseResourceElementsAttr could not be constructed from the given "
1145 "This may mean that the Python buffer layout does not match that "
1146 "MLIR expected layout and is a bug.");
1155 nb::arg(
"array"), nb::arg(
"name"), nb::arg(
"type"),
1156 nb::arg(
"alignment") = nb::none(), nb::arg(
"is_mutable") =
false,
1157 nb::arg(
"context") = nb::none(),
1159 nb::sig(
"def get_from_buffer(array: typing_extensions.Buffer, name: str, type: Type, alignment: int | None = None, is_mutable: bool = False, context: Context | None = None) -> DenseResourceElementsAttr"),
1169 return !mlirAttributeIsNull(
1178 [](
const nb::typed<nb::dict, nb::str, PyAttribute> &attributes,
1180 std::vector<MlirNamedAttribute> mlirNamedAttributes;
1181 mlirNamedAttributes.reserve(attributes.size());
1182 for (std::pair<nb::handle, nb::handle> it : attributes) {
1183 auto &mlirAttr = nb::cast<PyAttribute &>(it.second);
1184 auto name = nb::cast<std::string>(it.first);
1190 MlirAttribute attr =
1192 mlirNamedAttributes.data());
1195 nb::arg(
"value") = nb::dict(), nb::arg(
"context") = nb::none(),
1196 "Gets an uniqued dict attribute");
1197 c.def(
"__getitem__",
1199 const std::string &
name) -> nb::typed<nb::object, PyAttribute> {
1200 MlirAttribute attr =
1202 if (mlirAttributeIsNull(attr))
1203 throw nb::key_error(
"attempt to access a non-existent attribute");
1207 if (index < 0 || index >= self.
dunderLen()) {
1208 throw nb::index_error(
"attempt to access out of bounds attribute");
1219 throw nb::index_error(
"attempt to access out of bounds element");
1235 throw nb::type_error(
"Unsupported floating-point type");
1250 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
1251 "Gets a uniqued Type attribute");
1266 nb::arg(
"context") = nb::none(),
"Create a Unit attribute.");
1272 [](
int64_t offset,
const std::vector<int64_t> &strides,
1275 ctx->
get(), offset, strides.size(), strides.data());
1278 nb::arg(
"offset"), nb::arg(
"strides"), nb::arg(
"context") = nb::none(),
1279 "Gets a strided layout attribute.");
1281 "get_fully_dynamic",
1284 std::vector<int64_t> strides(rank);
1285 std::fill(strides.begin(), strides.end(), dynamic);
1287 ctx->
get(), dynamic, strides.size(), strides.data());
1290 nb::arg(
"rank"), nb::arg(
"context") = nb::none(),
1291 "Gets a strided layout attribute with dynamic offset and strides of "
1299 "Returns the value of the float point attribute");
1304 std::vector<int64_t> strides(size);
1305 for (
intptr_t i = 0; i < size; i++) {
1310 "Returns the value of the float point attribute");
1329 std::string(
"Can't cast unknown element type DenseArrayAttr (") +
1330 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
")";
1331 throw nb::type_error(msg.c_str());
1340 std::string(
"Can't cast unknown element type DenseTypedElementsAttr (") +
1341 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
")";
1342 throw nb::type_error(msg.c_str());
1350 std::string msg = std::string(
"Can't cast unknown attribute type Attr (") +
1351 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
1353 throw nb::type_error(msg.c_str());
1361 std::string msg = std::string(
"Can't cast unknown SymbolRef attribute (") +
1362 nb::cast<std::string>(nb::repr(nb::cast(pyAttribute))) +
1364 throw nb::type_error(msg.c_str());
1371 MlirAttribute attr =
1375 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
1376 "Gets a uniqued string attribute");
1380 MlirAttribute attr =
1384 nb::arg(
"value"), nb::arg(
"context") = nb::none(),
1385 "Gets a uniqued string attribute");
1388 [](
PyType &type,
const std::string &value) {
1389 MlirAttribute attr =
1393 nb::arg(
"type"), nb::arg(
"value"),
1394 "Gets a uniqued string attribute associated to a type");
1399 return nb::str(stringRef.
data, stringRef.
length);
1401 "Returns the value of the string attribute");
1406 return nb::bytes(stringRef.
data, stringRef.
length);
1408 "Returns the value of the string attribute as `bytes`");
1411static MlirDynamicAttrDefinition
1414 size_t dotPos = fullAttrName.find(
'.');
1415 if (dotPos == std::string::npos) {
1416 throw nb::value_error(
"Expected full attribute name to be in the format "
1417 "'<dialectName>.<attributeName>'.");
1420 std::string dialectName = fullAttrName.substr(0, dotPos);
1421 std::string attrName = fullAttrName.substr(dotPos + 1);
1425 throw nb::value_error(
1426 (
"Dialect '" + dialectName +
"' is not an extensible dialect.")
1431 if (attrDef.ptr ==
nullptr) {
1432 throw nb::value_error((
"Dialect '" + dialectName +
1433 "' does not contain an attribute named '" +
1443 [](
const std::string &fullAttrName,
const std::vector<PyAttribute> &attrs,
1445 std::vector<MlirAttribute> mlirAttrs;
1446 mlirAttrs.reserve(attrs.size());
1447 for (
const auto &attr : attrs)
1448 mlirAttrs.push_back(attr.get());
1450 MlirDynamicAttrDefinition attrDef =
1452 MlirAttribute attr =
1456 nb::arg(
"full_attr_name"), nb::arg(
"attributes"),
1457 nb::arg(
"context") = nb::none(),
"Create a dynamic attribute.");
1462 std::vector<PyAttribute> params;
1463 params.reserve(numParams);
1464 for (
size_t i = 0; i < numParams; ++i)
1469 "Returns the parameters of the dynamic attribute as a list of "
1476 return std::string(dialectNamespace.
data, dialectNamespace.
length) +
"." +
1477 std::string(
name.data,
name.length);
1482 MlirDynamicAttrDefinition attrDef =
1486 nb::arg(
"full_attr_name"), nb::arg(
"context") = nb::none(),
1487 "Look up the TypeID for the given dynamic attribute name.");
1493 PyDenseBoolArrayAttribute::PyDenseArrayIterator::bind(m);
1495 PyDenseI8ArrayAttribute::PyDenseArrayIterator::bind(m);
1497 PyDenseI16ArrayAttribute::PyDenseArrayIterator::bind(m);
1499 PyDenseI32ArrayAttribute::PyDenseArrayIterator::bind(m);
1501 PyDenseI64ArrayAttribute::PyDenseArrayIterator::bind(m);
1503 PyDenseF32ArrayAttribute::PyDenseArrayIterator::bind(m);
1505 PyDenseF64ArrayAttribute::PyDenseArrayIterator::bind(m);
1517 nb::cast<nb::callable>(nb::cpp_function(
1525 nb::cast<nb::callable>(
static const char kDenseElementsAttrGetDocstring[]
static const char kDenseResourceElementsAttrGetFromBufferDocstring[]
static const char kDenseElementsAttrGetFromListDocstring[]
MlirContext mlirAttributeGetContext(MlirAttribute attribute)
MlirType mlirAttributeGetType(MlirAttribute attribute)
ReferrentTy * get() const
PyMlirContextRef & getContext()
Accesses the context reference.
Used in function arguments when None should resolve to the current context manager set instance.
Used in function arguments when None should resolve to the current context manager set instance.
static PyMlirContext & resolve()
static void bindDerived(ClassTy &c)
MlirAffineMap get() const
nanobind::typed< nanobind::object, PyAttribute > dunderNext()
PyArrayAttributeIterator & dunderIter()
static void bind(nanobind::module_ &m)
MlirAttribute getItem(intptr_t i) const
static void bindDerived(ClassTy &c)
Wrapper around the generic MlirAttribute.
PyAttribute(PyMlirContextRef contextRef, MlirAttribute attr)
MlirAttribute get() const
Bool Attribute subclass - BoolAttr.
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
static void bind(nanobind::module_ &m, PyType_Slot *slots=nullptr)
nanobind::class_< PyAffineMapAttribute, PyAttribute > ClassTy
static const MlirStringRef name
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)
std::unique_ptr< nb_buffer_info > accessBuffer()
static constexpr const char * pyClassName
intptr_t dunderLen() const
static PyDenseElementsAttribute getFromList(const nanobind::typed< nanobind::sequence, PyAttribute > &attributes, std::optional< PyType > explicitType, DefaultingPyMlirContext contextWrapper)
static PyType_Slot slots[]
static void bindDerived(ClassTy &c)
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.
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
nanobind::float_ dunderGetItem(intptr_t pos) const
static constexpr const char * pyClassName
Refinement of the PyDenseElementsAttribute for attributes containing integer (and boolean) values.
static void bindDerived(ClassTy &c)
nanobind::int_ dunderGetItem(intptr_t pos) const
Returns the element at the given linear position.
static constexpr IsAFunctionTy isaFunction
static constexpr const char * pyClassName
static PyDenseResourceElementsAttribute getFromBuffer(const nb_buffer &buffer, const std::string &name, const PyType &type, std::optional< size_t > alignment, bool isMutable, DefaultingPyMlirContext contextWrapper)
static void bindDerived(ClassTy &c)
static const MlirStringRef name
User-level object for accessing dialects with dotted syntax such as: ctx.dialect.std.
MlirDialect getDialectForKey(const std::string &key, bool attrError)
static void bindDerived(ClassTy &c)
intptr_t dunderLen() const
bool dunderContains(const std::string &name) const
static const MlirStringRef name
static void bindDerived(ClassTy &c)
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
Float Point Attribute subclass - FloatAttr.
static void bindDerived(ClassTy &c)
static PyGlobals & get()
Most code should get the globals via this static accessor.
void registerTypeCaster(MlirTypeID mlirTypeID, nanobind::callable typeCaster, bool replace=false)
Adds a user-friendly type caster.
Integer Attribute subclass - IntegerAttr.
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
static void bindDerived(ClassTy &c)
MlirIntegerSet get() const
static PyMlirContextRef forContext(MlirContext context)
Returns a context reference for the singleton PyMlirContext wrapper for the given context.
MlirContext get()
Accesses the underlying MlirContext.
PyMlirContextRef getRef()
Gets a strong reference to this context, which will ensure it is kept alive for the life of the refer...
Represents a Python MlirNamedAttr, carrying an optional owned name.
static void bindDerived(ClassTy &c)
Strided layout attribute subclass.
static void bindDerived(ClassTy &c)
static void bindDerived(ClassTy &c)
static void bindDerived(ClassTy &c)
static PySymbolRefAttribute fromList(const std::vector< std::string > &symbols, PyMlirContext &context)
static constexpr IsAFunctionTy isaFunction
static void bindDerived(ClassTy &c)
A TypeID provides an efficient and unique identifier for a specific C++ type.
Wrapper around the generic MlirType.
nanobind::typed< nanobind::object, PyType > maybeDownCast()
Unit Attribute subclass. Unit attributes don't have values.
static void bindDerived(ClassTy &c)
MLIR_CAPI_EXPORTED MlirAttribute mlirAffineMapAttrGet(MlirAffineMap map)
Creates an affine map attribute wrapping the given map.
MLIR_CAPI_EXPORTED MlirAttribute mlirOpaqueAttrGet(MlirContext ctx, MlirStringRef dialectNamespace, intptr_t dataLength, const char *data, MlirType type)
Creates an opaque attribute in the given context associated with the dialect identified by its namesp...
MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGetChecked(MlirLocation loc, MlirType type, double value)
Same as "mlirFloatAttrDoubleGet", but if the type is not valid for a construction of a FloatAttr,...
MLIR_CAPI_EXPORTED uint8_t mlirDenseElementsAttrGetUInt8Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetOffset(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAffineMap mlirAffineMapAttrGetValue(MlirAttribute attr)
Returns the affine map wrapped in the given affine map attribute.
MLIR_CAPI_EXPORTED int64_t mlirStridedLayoutAttrGetStride(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED int8_t mlirDenseElementsAttrGetInt8Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirAttribute mlirStridedLayoutAttrGet(MlirContext ctx, int64_t offset, intptr_t numStrides, const int64_t *strides)
MLIR_CAPI_EXPORTED unsigned mlirIntegerAttrGetValueNumWords(MlirAttribute attr)
Returns the number of 64-bit words that make up the integer attribute's underlying APInt value.
MLIR_CAPI_EXPORTED MlirAttribute mlirFlatSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol)
Creates a flat symbol reference attribute in the given context referencing a symbol identified by the...
MLIR_CAPI_EXPORTED uint64_t mlirDenseElementsAttrGetIndexValue(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirTypeID mlirIntegerAttrGetTypeID(void)
Returns the typeID of an Integer attribute.
MLIR_CAPI_EXPORTED int16_t mlirDenseElementsAttrGetInt16Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirStringRef mlirSymbolRefAttrGetRootReference(MlirAttribute attr)
Returns the string reference to the root referenced symbol.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAInteger(MlirAttribute attr)
Checks whether the given attribute is an integer attribute.
MLIR_CAPI_EXPORTED intptr_t mlirDictionaryAttrGetNumElements(MlirAttribute attr)
Returns the number of attributes contained in a dictionary attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerSetAttrGet(MlirIntegerSet set)
Creates an integer set attribute wrapping the given set.
MLIR_CAPI_EXPORTED uint16_t mlirDenseElementsAttrGetUInt16Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED uint64_t mlirDenseElementsAttrGetUInt64Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED bool mlirBoolAttrGetValue(MlirAttribute attr)
Returns the value stored in the given bool attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGet(MlirType type, int64_t value)
Creates an integer attribute of the given type with the given integer value.
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrGetBoolValue(MlirAttribute attr, intptr_t pos)
Returns the pos-th value (flat contiguous indexing) of a specific type contained by the given dense e...
MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGet(MlirContext ctx, intptr_t numElements, MlirNamedAttribute const *elements)
Creates a dictionary attribute containing the given list of elements in the provided context.
MLIR_CAPI_EXPORTED MlirAttribute mlirUnmanagedDenseResourceElementsAttrGet(MlirType shapedType, MlirStringRef name, void *data, size_t dataLength, size_t dataAlignment, bool dataIsMutable, void(*deleter)(void *userData, const void *data, size_t size, size_t align), void *userData)
Unlike the typed accessors below, constructs the attribute with a raw data buffer and no type/alignme...
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolRefAttrGetNestedReference(MlirAttribute attr, intptr_t pos)
Returns pos-th reference nested in the given symbol reference attribute.
MLIR_CAPI_EXPORTED void mlirIntegerAttrGetValueWords(MlirAttribute attr, uint64_t *words)
Copies the 64-bit words making up the integer attribute's APInt value into the provided buffer.
MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signless type and f...
MLIR_CAPI_EXPORTED intptr_t mlirSymbolRefAttrGetNumNestedReferences(MlirAttribute attr)
Returns the number of references nested in the given symbol reference attribute.
MLIR_CAPI_EXPORTED MlirType mlirTypeAttrGetValue(MlirAttribute attr)
Returns the type stored in the given type attribute.
MLIR_CAPI_EXPORTED bool mlirDenseElementsAttrIsSplat(MlirAttribute attr)
Checks whether the given dense elements attribute contains a single replicated value (splat).
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGet(MlirType shapedType, intptr_t numElements, MlirAttribute const *elements)
Creates a dense elements attribute with the given Shaped type and elements in the same context as the...
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetData(MlirAttribute attr)
Returns the raw data as a string reference.
MLIR_CAPI_EXPORTED MlirAttribute mlirAttributeGetNull(void)
Returns an empty attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirBoolAttrGet(MlirContext ctx, int value)
Creates a bool attribute in the given context with the given value.
MLIR_CAPI_EXPORTED MlirTypeID mlirDenseTypedElementsAttrGetTypeID(void)
Returns the typeID of a DenseTypedElements attribute.
MLIR_CAPI_EXPORTED int64_t mlirIntegerAttrGetValueSInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of signed type and fit...
MLIR_CAPI_EXPORTED int64_t mlirDenseElementsAttrGetInt64Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirDictionaryAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element of the given dictionary attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGetElement(MlirAttribute attr, intptr_t pos)
Returns pos-th element stored in the given array attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirDictionaryAttrGetElementByName(MlirAttribute attr, MlirStringRef name)
Returns the dictionary attribute element with the given name or NULL if the given name does not exist...
MLIR_CAPI_EXPORTED MlirTypeID mlirSymbolRefAttrGetTypeID(void)
Returns the typeID of an SymbolRef attribute.
MLIR_CAPI_EXPORTED MlirTypeID mlirDenseArrayAttrGetTypeID(void)
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrGetSplatValue(MlirAttribute attr)
Returns the single replicated value (splat) of a specific type contained by the given dense elements ...
MLIR_CAPI_EXPORTED float mlirDenseElementsAttrGetFloatValue(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED int64_t mlirElementsAttrGetNumElements(MlirAttribute attr)
Gets the total number of elements in the given elements attribute.
MLIR_CAPI_EXPORTED MlirStringRef mlirOpaqueAttrGetDialectNamespace(MlirAttribute attr)
Returns the namespace of the dialect with which the given opaque attribute is associated.
MLIR_CAPI_EXPORTED int32_t mlirDenseElementsAttrGetInt32Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirStringRef mlirStringAttrGetValue(MlirAttribute attr)
Returns the attribute values as a string reference.
MLIR_CAPI_EXPORTED double mlirFloatAttrGetValueDouble(MlirAttribute attr)
Returns the value stored in the given floating point attribute, interpreting the value as double.
MLIR_CAPI_EXPORTED uint64_t mlirIntegerAttrGetValueUInt(MlirAttribute attr)
Returns the value stored in the given integer attribute, assuming the value is of unsigned type and f...
MLIR_CAPI_EXPORTED MlirAttribute mlirUnitAttrGet(MlirContext ctx)
Creates a unit attribute in the given context.
MLIR_CAPI_EXPORTED double mlirDenseElementsAttrGetDoubleValue(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED intptr_t mlirStridedLayoutAttrGetNumStrides(MlirAttribute attr)
MLIR_CAPI_EXPORTED MlirAttribute mlirFloatAttrDoubleGet(MlirContext ctx, MlirType type, double value)
Creates a floating point attribute in the given context with the given double value and double-precis...
MLIR_CAPI_EXPORTED MlirAttribute mlirArrayAttrGet(MlirContext ctx, intptr_t numElements, MlirAttribute const *elements)
Creates an array element containing the given list of elements in the given context.
MLIR_CAPI_EXPORTED bool mlirAttributeIsAFloat(MlirAttribute attr)
Checks whether the given attribute is a floating point attribute.
MLIR_CAPI_EXPORTED MlirAttribute mlirSymbolRefAttrGet(MlirContext ctx, MlirStringRef symbol, intptr_t numReferences, MlirAttribute const *references)
Creates a symbol reference attribute in the given context referencing a symbol identified by the give...
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrSplatGet(MlirType shapedType, MlirAttribute element)
Creates a dense elements attribute with the given Shaped type containing a single replicated element ...
MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrGet(MlirContext ctx, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
MLIR_CAPI_EXPORTED MlirAttribute mlirTypeAttrGet(MlirType type)
Creates a type attribute wrapping the given type in the same context as the type.
MLIR_CAPI_EXPORTED intptr_t mlirArrayAttrGetNumElements(MlirAttribute attr)
Returns the number of elements stored in the given array attribute.
MLIR_CAPI_EXPORTED unsigned mlirIntegerAttrGetValueBitWidth(MlirAttribute attr)
Returns the bit width of the integer attribute's underlying APInt value.
MLIR_CAPI_EXPORTED MlirAttribute mlirDenseElementsAttrRawBufferGet(MlirType shapedType, size_t rawBufferSize, const void *rawBuffer)
Creates a dense elements attribute with the given Shaped type and elements populated from a packed,...
MLIR_CAPI_EXPORTED MlirAttribute mlirStringAttrTypedGet(MlirType type, MlirStringRef str)
Creates a string attribute in the given context containing the given string.
MLIR_CAPI_EXPORTED MlirAttribute mlirIntegerAttrGetFromWords(MlirType type, unsigned numWords, const uint64_t *words)
Creates an integer attribute of the given type from an array of 64-bit words.
MLIR_CAPI_EXPORTED MlirStringRef mlirFlatSymbolRefAttrGetValue(MlirAttribute attr)
Returns the referenced symbol as a string reference.
MLIR_CAPI_EXPORTED uint32_t mlirDenseElementsAttrGetUInt32Value(MlirAttribute attr, intptr_t pos)
MLIR_CAPI_EXPORTED MlirType mlirRankedTensorTypeGet(intptr_t rank, const int64_t *shape, MlirType elementType, MlirAttribute encoding)
Creates a tensor type of a fixed rank with the given shape, element type, and optional encoding in th...
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSignless(MlirType type)
Checks whether the given integer type is signless.
MLIR_CAPI_EXPORTED bool mlirTypeIsAInteger(MlirType type)
Checks whether the given type is an integer type.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeGet(MlirContext ctx, unsigned bitwidth)
Creates a signless integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsUnsigned(MlirType type)
Checks whether the given integer type is unsigned.
MLIR_CAPI_EXPORTED unsigned mlirIntegerTypeGetWidth(MlirType type)
Returns the bitwidth of an integer type.
MLIR_CAPI_EXPORTED MlirType mlirF64TypeGet(MlirContext ctx)
Creates a f64 type in the given context.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeSignedGet(MlirContext ctx, unsigned bitwidth)
Creates a signed integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED MlirType mlirF16TypeGet(MlirContext ctx)
Creates an f16 type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF64(MlirType type)
Checks whether the given type is an f64 type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF16(MlirType type)
Checks whether the given type is an f16 type.
MLIR_CAPI_EXPORTED bool mlirIntegerTypeIsSigned(MlirType type)
Checks whether the given integer type is signed.
MLIR_CAPI_EXPORTED MlirType mlirShapedTypeGetElementType(MlirType type)
Returns the element type of the shaped type.
MLIR_CAPI_EXPORTED bool mlirShapedTypeHasStaticShape(MlirType type)
Checks whether the given shaped type has a static shape.
MLIR_CAPI_EXPORTED MlirType mlirF32TypeGet(MlirContext ctx)
Creates an f32 type in the given context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAShaped(MlirType type)
Checks whether the given type is a Shaped type.
MLIR_CAPI_EXPORTED MlirType mlirIntegerTypeUnsignedGet(MlirContext ctx, unsigned bitwidth)
Creates an unsigned integer type of the given bitwidth in the context.
MLIR_CAPI_EXPORTED bool mlirTypeIsAF32(MlirType type)
Checks whether the given type is an f32 type.
MLIR_CAPI_EXPORTED bool mlirTypeIsAIndex(MlirType type)
Checks whether the given type is an index type.
MLIR_CAPI_EXPORTED int64_t mlirShapedTypeGetDynamicStrideOrOffset(void)
Returns the value indicating a dynamic stride or offset in a shaped type.
MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGetParam(MlirAttribute attr, intptr_t index)
Get the parameter at the given index in the provided dynamic attribute.
MLIR_CAPI_EXPORTED MlirDialect mlirDynamicAttrDefinitionGetDialect(MlirDynamicAttrDefinition attrDef)
Get the dialect that the given dynamic attribute definition belongs to.
MLIR_CAPI_EXPORTED MlirAttribute mlirDynamicAttrGet(MlirDynamicAttrDefinition attrDef, MlirAttribute *attrs, intptr_t numAttrs)
Get a dynamic attribute by instantiating the given attribute definition with the provided attributes.
MLIR_CAPI_EXPORTED bool mlirDialectIsAExtensibleDialect(MlirDialect dialect)
Check if the given dialect is an extensible dialect.
MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition mlirDynamicAttrGetAttrDef(MlirAttribute attr)
Get the attribute definition of the given dynamic attribute.
MLIR_CAPI_EXPORTED MlirDynamicAttrDefinition mlirExtensibleDialectLookupAttrDefinition(MlirDialect dialect, MlirStringRef attrName)
Look up a registered attribute definition by attribute name in the given dialect.
MLIR_CAPI_EXPORTED MlirTypeID mlirDynamicAttrDefinitionGetTypeID(MlirDynamicAttrDefinition attrDef)
Get the type ID of a dynamic attribute definition.
MLIR_CAPI_EXPORTED MlirStringRef mlirDynamicAttrDefinitionGetName(MlirDynamicAttrDefinition attrDef)
Get the name of the given dynamic attribute definition.
MLIR_CAPI_EXPORTED intptr_t mlirDynamicAttrGetNumParams(MlirAttribute attr)
Get the number of parameters in the given dynamic attribute.
MLIR_CAPI_EXPORTED MlirStringRef mlirDialectGetNamespace(MlirDialect dialect)
Returns the namespace of the given dialect.
MLIR_CAPI_EXPORTED MlirNamedAttribute mlirNamedAttributeGet(MlirIdentifier name, MlirAttribute attr)
Associates an attribute with the name. Takes ownership of neither.
MLIR_CAPI_EXPORTED MlirStringRef mlirIdentifierStr(MlirIdentifier ident)
Gets the string value of the identifier.
MLIR_CAPI_EXPORTED MlirContext mlirTypeGetContext(MlirType type)
Gets the context that a type was created with.
MLIR_CAPI_EXPORTED bool mlirTypeEqual(MlirType t1, MlirType t2)
Checks if two types are equal.
MLIR_CAPI_EXPORTED MlirIdentifier mlirIdentifierGet(MlirContext context, MlirStringRef str)
Gets an identifier with the given string value.
nb::object symbolRefOrFlatSymbolRefAttributeCaster(PyAttribute &pyAttribute)
nb::object integerOrBoolAttributeCaster(PyAttribute &pyAttribute)
MlirStringRef toMlirStringRef(const std::string &s)
static T pyTryCast(nanobind::handle object)
nb::object denseTypedElementsAttributeCaster(PyAttribute &pyAttribute)
nb::object denseArrayAttributeCaster(PyAttribute &pyAttribute)
static MlirDynamicAttrDefinition getDynamicAttrDef(const std::string &fullAttrName, DefaultingPyMlirContext context)
MLIR_PYTHON_API_EXPORTED void populateIRAttributes(nanobind::module_ &m)
Include the generated interface declarations.
std::string join(const Ts &...args)
Helper function to concatenate arguments into a std::string.
A pointer to a sized fragment of a string, not necessarily null-terminated.
const char * data
Pointer to the first symbol.
size_t length
Length of the fragment.
Custom exception that allows access to error diagnostic information.
Instantiate the python dense array classes.
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
static constexpr IsAFunctionTy isaFunction
RAII object that captures any error diagnostics emitted to the provided context.
std::vector< PyDiagnostic::DiagnosticInfo > take()
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))
std::vector< Py_ssize_t > shape
std::vector< Py_ssize_t > strides
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()
static const char * format()